1 # A simple IPC server for executing arbitrary Ruby program.
2 # The protocol is based on Assuan protocol of GnuPG.
3 # http://www.gnupg.org/(en)/related_software/libassuan/index.html
17 return @buf << unescape($')
21 d = "dispatch_#{c.downcase}"
22 if respond_to?(d, true)
27 puts("ERR 103 Unknown command\r\n")
32 def dispatch_cancel(c, r)
33 puts("ERR 100 Not implemented\r\n")
36 def dispatch_bye(c, r)
37 puts("ERR 100 Not implemented\r\n")
40 def dispatch_auth(c, r)
41 puts("ERR 100 Not implemented\r\n")
44 def dispatch_reset(c, r)
45 puts("ERR 100 Not implemented\r\n")
48 def dispatch_end(c, r)
52 def dispatch_help(c, r)
53 puts("ERR 100 Not implemented\r\n")
56 def dispatch_quit(c, r)
57 puts("ERR 100 Not implemented\r\n")
60 def dispatch_eval(c, r)
61 r = deq_data if r.empty?
71 puts("ERR #{$?.exitstatus}\r\n")
81 s.gsub(/[%\r\n]/) {|m| '%%%02X' % m[0]}
85 s.gsub(/%([0-9A-Z][0-9A-Z])/, ['\1'].pack('H*'))
90 r = [d.length, 998].min # 998 = 1000 - CRLF
92 r -= 2 if d[i] =~ /[%\r\n]/
94 puts("D #{escape(d[0 ... r])}\r\n")
100 @que.enq(@buf.string)