sidekick-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +52 -0
  6. data/VERSION +1 -0
  7. data/lib/ext/README +1 -0
  8. data/lib/ext/bunny-0.6.0/LICENSE +20 -0
  9. data/lib/ext/bunny-0.6.0/README.rdoc +66 -0
  10. data/lib/ext/bunny-0.6.0/Rakefile +24 -0
  11. data/lib/ext/bunny-0.6.0/bunny.gemspec +65 -0
  12. data/lib/ext/bunny-0.6.0/examples/simple_08.rb +30 -0
  13. data/lib/ext/bunny-0.6.0/examples/simple_09.rb +30 -0
  14. data/lib/ext/bunny-0.6.0/examples/simple_ack_08.rb +33 -0
  15. data/lib/ext/bunny-0.6.0/examples/simple_ack_09.rb +33 -0
  16. data/lib/ext/bunny-0.6.0/examples/simple_consumer_08.rb +53 -0
  17. data/lib/ext/bunny-0.6.0/examples/simple_consumer_09.rb +53 -0
  18. data/lib/ext/bunny-0.6.0/examples/simple_fanout_08.rb +39 -0
  19. data/lib/ext/bunny-0.6.0/examples/simple_fanout_09.rb +39 -0
  20. data/lib/ext/bunny-0.6.0/examples/simple_headers_08.rb +40 -0
  21. data/lib/ext/bunny-0.6.0/examples/simple_headers_09.rb +40 -0
  22. data/lib/ext/bunny-0.6.0/examples/simple_publisher_08.rb +27 -0
  23. data/lib/ext/bunny-0.6.0/examples/simple_publisher_09.rb +27 -0
  24. data/lib/ext/bunny-0.6.0/examples/simple_topic_08.rb +59 -0
  25. data/lib/ext/bunny-0.6.0/examples/simple_topic_09.rb +59 -0
  26. data/lib/ext/bunny-0.6.0/lib/bunny/channel08.rb +39 -0
  27. data/lib/ext/bunny-0.6.0/lib/bunny/channel09.rb +39 -0
  28. data/lib/ext/bunny-0.6.0/lib/bunny/client08.rb +494 -0
  29. data/lib/ext/bunny-0.6.0/lib/bunny/client09.rb +460 -0
  30. data/lib/ext/bunny-0.6.0/lib/bunny/exchange08.rb +175 -0
  31. data/lib/ext/bunny-0.6.0/lib/bunny/exchange09.rb +177 -0
  32. data/lib/ext/bunny-0.6.0/lib/bunny/queue08.rb +389 -0
  33. data/lib/ext/bunny-0.6.0/lib/bunny/queue09.rb +395 -0
  34. data/lib/ext/bunny-0.6.0/lib/bunny/subscription08.rb +85 -0
  35. data/lib/ext/bunny-0.6.0/lib/bunny/subscription09.rb +85 -0
  36. data/lib/ext/bunny-0.6.0/lib/bunny.rb +87 -0
  37. data/lib/ext/bunny-0.6.0/lib/qrack/channel.rb +18 -0
  38. data/lib/ext/bunny-0.6.0/lib/qrack/client.rb +204 -0
  39. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol08.rb +132 -0
  40. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb +133 -0
  41. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/spec08.rb +823 -0
  42. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/spec09.rb +521 -0
  43. data/lib/ext/bunny-0.6.0/lib/qrack/qrack08.rb +23 -0
  44. data/lib/ext/bunny-0.6.0/lib/qrack/qrack09.rb +23 -0
  45. data/lib/ext/bunny-0.6.0/lib/qrack/queue.rb +53 -0
  46. data/lib/ext/bunny-0.6.0/lib/qrack/subscription.rb +102 -0
  47. data/lib/ext/bunny-0.6.0/lib/qrack/transport/buffer08.rb +276 -0
  48. data/lib/ext/bunny-0.6.0/lib/qrack/transport/buffer09.rb +276 -0
  49. data/lib/ext/bunny-0.6.0/lib/qrack/transport/frame08.rb +112 -0
  50. data/lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb +94 -0
  51. data/lib/ext/bunny-0.6.0/spec/spec_08/bunny_spec.rb +65 -0
  52. data/lib/ext/bunny-0.6.0/spec/spec_08/connection_spec.rb +12 -0
  53. data/lib/ext/bunny-0.6.0/spec/spec_08/exchange_spec.rb +162 -0
  54. data/lib/ext/bunny-0.6.0/spec/spec_08/queue_spec.rb +206 -0
  55. data/lib/ext/bunny-0.6.0/spec/spec_09/bunny_spec.rb +65 -0
  56. data/lib/ext/bunny-0.6.0/spec/spec_09/connection_spec.rb +12 -0
  57. data/lib/ext/bunny-0.6.0/spec/spec_09/exchange_spec.rb +162 -0
  58. data/lib/ext/bunny-0.6.0/spec/spec_09/queue_spec.rb +205 -0
  59. data/lib/ext/eventmachine-0.12.10/.gitignore +14 -0
  60. data/lib/ext/eventmachine-0.12.10/README +82 -0
  61. data/lib/ext/eventmachine-0.12.10/Rakefile +374 -0
  62. data/lib/ext/eventmachine-0.12.10/docs/COPYING +60 -0
  63. data/lib/ext/eventmachine-0.12.10/docs/ChangeLog +211 -0
  64. data/lib/ext/eventmachine-0.12.10/docs/DEFERRABLES +133 -0
  65. data/lib/ext/eventmachine-0.12.10/docs/EPOLL +141 -0
  66. data/lib/ext/eventmachine-0.12.10/docs/GNU +281 -0
  67. data/lib/ext/eventmachine-0.12.10/docs/INSTALL +13 -0
  68. data/lib/ext/eventmachine-0.12.10/docs/KEYBOARD +38 -0
  69. data/lib/ext/eventmachine-0.12.10/docs/LEGAL +25 -0
  70. data/lib/ext/eventmachine-0.12.10/docs/LIGHTWEIGHT_CONCURRENCY +70 -0
  71. data/lib/ext/eventmachine-0.12.10/docs/PURE_RUBY +75 -0
  72. data/lib/ext/eventmachine-0.12.10/docs/RELEASE_NOTES +94 -0
  73. data/lib/ext/eventmachine-0.12.10/docs/SMTP +2 -0
  74. data/lib/ext/eventmachine-0.12.10/docs/SPAWNED_PROCESSES +89 -0
  75. data/lib/ext/eventmachine-0.12.10/docs/TODO +8 -0
  76. data/lib/ext/eventmachine-0.12.10/eventmachine.gemspec +40 -0
  77. data/lib/ext/eventmachine-0.12.10/examples/ex_channel.rb +43 -0
  78. data/lib/ext/eventmachine-0.12.10/examples/ex_queue.rb +2 -0
  79. data/lib/ext/eventmachine-0.12.10/examples/helper.rb +2 -0
  80. data/lib/ext/eventmachine-0.12.10/ext/binder.cpp +125 -0
  81. data/lib/ext/eventmachine-0.12.10/ext/binder.h +46 -0
  82. data/lib/ext/eventmachine-0.12.10/ext/cmain.cpp +827 -0
  83. data/lib/ext/eventmachine-0.12.10/ext/cplusplus.cpp +202 -0
  84. data/lib/ext/eventmachine-0.12.10/ext/ed.cpp +1893 -0
  85. data/lib/ext/eventmachine-0.12.10/ext/ed.h +424 -0
  86. data/lib/ext/eventmachine-0.12.10/ext/em.cpp +2282 -0
  87. data/lib/ext/eventmachine-0.12.10/ext/em.h +232 -0
  88. data/lib/ext/eventmachine-0.12.10/ext/emwin.cpp +300 -0
  89. data/lib/ext/eventmachine-0.12.10/ext/emwin.h +94 -0
  90. data/lib/ext/eventmachine-0.12.10/ext/epoll.cpp +26 -0
  91. data/lib/ext/eventmachine-0.12.10/ext/epoll.h +25 -0
  92. data/lib/ext/eventmachine-0.12.10/ext/eventmachine.h +122 -0
  93. data/lib/ext/eventmachine-0.12.10/ext/eventmachine_cpp.h +96 -0
  94. data/lib/ext/eventmachine-0.12.10/ext/extconf.rb +148 -0
  95. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/extconf.rb +83 -0
  96. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.cpp +214 -0
  97. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.h +59 -0
  98. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/rubymain.cpp +127 -0
  99. data/lib/ext/eventmachine-0.12.10/ext/files.cpp +94 -0
  100. data/lib/ext/eventmachine-0.12.10/ext/files.h +65 -0
  101. data/lib/ext/eventmachine-0.12.10/ext/kb.cpp +81 -0
  102. data/lib/ext/eventmachine-0.12.10/ext/page.cpp +107 -0
  103. data/lib/ext/eventmachine-0.12.10/ext/page.h +51 -0
  104. data/lib/ext/eventmachine-0.12.10/ext/pipe.cpp +349 -0
  105. data/lib/ext/eventmachine-0.12.10/ext/project.h +151 -0
  106. data/lib/ext/eventmachine-0.12.10/ext/rubymain.cpp +1166 -0
  107. data/lib/ext/eventmachine-0.12.10/ext/sigs.cpp +89 -0
  108. data/lib/ext/eventmachine-0.12.10/ext/sigs.h +32 -0
  109. data/lib/ext/eventmachine-0.12.10/ext/ssl.cpp +460 -0
  110. data/lib/ext/eventmachine-0.12.10/ext/ssl.h +94 -0
  111. data/lib/ext/eventmachine-0.12.10/java/.classpath +8 -0
  112. data/lib/ext/eventmachine-0.12.10/java/.project +17 -0
  113. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactor.java +570 -0
  114. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  115. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
  116. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
  117. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
  118. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Application.java +194 -0
  119. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Connection.java +74 -0
  120. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/ConnectionFactory.java +37 -0
  121. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +46 -0
  122. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/PeriodicTimer.java +38 -0
  123. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Timer.java +54 -0
  124. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -0
  125. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -0
  126. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  127. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  128. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestServers.java +75 -0
  129. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -0
  130. data/lib/ext/eventmachine-0.12.10/lib/em/buftok.rb +138 -0
  131. data/lib/ext/eventmachine-0.12.10/lib/em/callback.rb +26 -0
  132. data/lib/ext/eventmachine-0.12.10/lib/em/channel.rb +57 -0
  133. data/lib/ext/eventmachine-0.12.10/lib/em/connection.rb +564 -0
  134. data/lib/ext/eventmachine-0.12.10/lib/em/deferrable.rb +192 -0
  135. data/lib/ext/eventmachine-0.12.10/lib/em/file_watch.rb +54 -0
  136. data/lib/ext/eventmachine-0.12.10/lib/em/future.rb +61 -0
  137. data/lib/ext/eventmachine-0.12.10/lib/em/messages.rb +66 -0
  138. data/lib/ext/eventmachine-0.12.10/lib/em/process_watch.rb +44 -0
  139. data/lib/ext/eventmachine-0.12.10/lib/em/processes.rb +119 -0
  140. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/header_and_content.rb +138 -0
  141. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient.rb +263 -0
  142. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient2.rb +590 -0
  143. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/line_and_text.rb +125 -0
  144. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/linetext2.rb +161 -0
  145. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/memcache.rb +323 -0
  146. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/object_protocol.rb +45 -0
  147. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/postgres3.rb +247 -0
  148. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/saslauth.rb +175 -0
  149. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpclient.rb +357 -0
  150. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpserver.rb +547 -0
  151. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/socks4.rb +66 -0
  152. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/stomp.rb +200 -0
  153. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/tcptest.rb +53 -0
  154. data/lib/ext/eventmachine-0.12.10/lib/em/protocols.rb +36 -0
  155. data/lib/ext/eventmachine-0.12.10/lib/em/queue.rb +61 -0
  156. data/lib/ext/eventmachine-0.12.10/lib/em/spawnable.rb +85 -0
  157. data/lib/ext/eventmachine-0.12.10/lib/em/streamer.rb +130 -0
  158. data/lib/ext/eventmachine-0.12.10/lib/em/timers.rb +56 -0
  159. data/lib/ext/eventmachine-0.12.10/lib/em/version.rb +3 -0
  160. data/lib/ext/eventmachine-0.12.10/lib/eventmachine.rb +1592 -0
  161. data/lib/ext/eventmachine-0.12.10/lib/evma/callback.rb +32 -0
  162. data/lib/ext/eventmachine-0.12.10/lib/evma/container.rb +75 -0
  163. data/lib/ext/eventmachine-0.12.10/lib/evma/factory.rb +77 -0
  164. data/lib/ext/eventmachine-0.12.10/lib/evma/protocol.rb +87 -0
  165. data/lib/ext/eventmachine-0.12.10/lib/evma/reactor.rb +48 -0
  166. data/lib/ext/eventmachine-0.12.10/lib/evma.rb +32 -0
  167. data/lib/ext/eventmachine-0.12.10/lib/jeventmachine.rb +257 -0
  168. data/lib/ext/eventmachine-0.12.10/lib/pr_eventmachine.rb +1022 -0
  169. data/lib/ext/eventmachine-0.12.10/setup.rb +1585 -0
  170. data/lib/ext/eventmachine-0.12.10/tasks/cpp.rake_example +77 -0
  171. data/lib/ext/eventmachine-0.12.10/tests/client.crt +31 -0
  172. data/lib/ext/eventmachine-0.12.10/tests/client.key +51 -0
  173. data/lib/ext/eventmachine-0.12.10/tests/test_attach.rb +126 -0
  174. data/lib/ext/eventmachine-0.12.10/tests/test_basic.rb +284 -0
  175. data/lib/ext/eventmachine-0.12.10/tests/test_channel.rb +63 -0
  176. data/lib/ext/eventmachine-0.12.10/tests/test_connection_count.rb +35 -0
  177. data/lib/ext/eventmachine-0.12.10/tests/test_defer.rb +47 -0
  178. data/lib/ext/eventmachine-0.12.10/tests/test_epoll.rb +160 -0
  179. data/lib/ext/eventmachine-0.12.10/tests/test_error_handler.rb +35 -0
  180. data/lib/ext/eventmachine-0.12.10/tests/test_errors.rb +82 -0
  181. data/lib/ext/eventmachine-0.12.10/tests/test_exc.rb +55 -0
  182. data/lib/ext/eventmachine-0.12.10/tests/test_file_watch.rb +49 -0
  183. data/lib/ext/eventmachine-0.12.10/tests/test_futures.rb +198 -0
  184. data/lib/ext/eventmachine-0.12.10/tests/test_get_sock_opt.rb +30 -0
  185. data/lib/ext/eventmachine-0.12.10/tests/test_handler_check.rb +37 -0
  186. data/lib/ext/eventmachine-0.12.10/tests/test_hc.rb +218 -0
  187. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb +218 -0
  188. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb +153 -0
  189. data/lib/ext/eventmachine-0.12.10/tests/test_inactivity_timeout.rb +50 -0
  190. data/lib/ext/eventmachine-0.12.10/tests/test_kb.rb +60 -0
  191. data/lib/ext/eventmachine-0.12.10/tests/test_ltp.rb +182 -0
  192. data/lib/ext/eventmachine-0.12.10/tests/test_ltp2.rb +317 -0
  193. data/lib/ext/eventmachine-0.12.10/tests/test_next_tick.rb +133 -0
  194. data/lib/ext/eventmachine-0.12.10/tests/test_object_protocol.rb +37 -0
  195. data/lib/ext/eventmachine-0.12.10/tests/test_pause.rb +70 -0
  196. data/lib/ext/eventmachine-0.12.10/tests/test_pending_connect_timeout.rb +48 -0
  197. data/lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb +48 -0
  198. data/lib/ext/eventmachine-0.12.10/tests/test_processes.rb +128 -0
  199. data/lib/ext/eventmachine-0.12.10/tests/test_proxy_connection.rb +92 -0
  200. data/lib/ext/eventmachine-0.12.10/tests/test_pure.rb +125 -0
  201. data/lib/ext/eventmachine-0.12.10/tests/test_queue.rb +44 -0
  202. data/lib/ext/eventmachine-0.12.10/tests/test_running.rb +42 -0
  203. data/lib/ext/eventmachine-0.12.10/tests/test_sasl.rb +72 -0
  204. data/lib/ext/eventmachine-0.12.10/tests/test_send_file.rb +242 -0
  205. data/lib/ext/eventmachine-0.12.10/tests/test_servers.rb +76 -0
  206. data/lib/ext/eventmachine-0.12.10/tests/test_smtpclient.rb +83 -0
  207. data/lib/ext/eventmachine-0.12.10/tests/test_smtpserver.rb +85 -0
  208. data/lib/ext/eventmachine-0.12.10/tests/test_spawn.rb +322 -0
  209. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_args.rb +79 -0
  210. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_methods.rb +50 -0
  211. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_verify.rb +82 -0
  212. data/lib/ext/eventmachine-0.12.10/tests/test_timers.rb +162 -0
  213. data/lib/ext/eventmachine-0.12.10/tests/test_ud.rb +36 -0
  214. data/lib/ext/eventmachine-0.12.10/tests/testem.rb +31 -0
  215. data/lib/ext/eventmachine-0.12.10/web/whatis +7 -0
  216. data/lib/ext/misc/README +1 -0
  217. data/lib/ext/misc/indifferent_access.rb +131 -0
  218. data/lib/ext/uuidtools-2.1.1/CHANGELOG +56 -0
  219. data/lib/ext/uuidtools-2.1.1/LICENSE +20 -0
  220. data/lib/ext/uuidtools-2.1.1/README +13 -0
  221. data/lib/ext/uuidtools-2.1.1/Rakefile +48 -0
  222. data/lib/ext/uuidtools-2.1.1/lib/compat/securerandom.rb +202 -0
  223. data/lib/ext/uuidtools-2.1.1/lib/uuidtools/version.rb +35 -0
  224. data/lib/ext/uuidtools-2.1.1/lib/uuidtools.rb +618 -0
  225. data/lib/ext/uuidtools-2.1.1/spec/spec.opts +1 -0
  226. data/lib/ext/uuidtools-2.1.1/spec/spec_helper.rb +7 -0
  227. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/mac_address_spec.rb +15 -0
  228. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/utility_spec.rb +21 -0
  229. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/uuid_creation_spec.rb +121 -0
  230. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/uuid_parsing_spec.rb +127 -0
  231. data/lib/ext/uuidtools-2.1.1/tasks/benchmark.rake +38 -0
  232. data/lib/ext/uuidtools-2.1.1/tasks/clobber.rake +2 -0
  233. data/lib/ext/uuidtools-2.1.1/tasks/gem.rake +68 -0
  234. data/lib/ext/uuidtools-2.1.1/tasks/git.rake +40 -0
  235. data/lib/ext/uuidtools-2.1.1/tasks/metrics.rake +22 -0
  236. data/lib/ext/uuidtools-2.1.1/tasks/rdoc.rake +29 -0
  237. data/lib/ext/uuidtools-2.1.1/tasks/rubyforge.rake +89 -0
  238. data/lib/ext/uuidtools-2.1.1/tasks/spec.rake +64 -0
  239. data/lib/ext/uuidtools-2.1.1/website/index.html +95 -0
  240. data/lib/sidekick/client/sidekick_client.rb +46 -0
  241. data/lib/sidekick/shared/sidekick_logger.rb +14 -0
  242. data/lib/sidekick/shared/sidekick_queue_publisher.rb +91 -0
  243. data/lib/sidekick-client.rb +7 -0
  244. data/sidekick-client.gemspec +289 -0
  245. data/test/helper.rb +10 -0
  246. data/test/test_sidekick-client.rb +7 -0
  247. metadata +311 -0
@@ -0,0 +1,45 @@
1
+ module EventMachine
2
+ module Protocols
3
+ # ObjectProtocol allows for easy communication using marshaled ruby objects
4
+ #
5
+ # module RubyServer
6
+ # include EM::P::ObjectProtocol
7
+ #
8
+ # def receive_object obj
9
+ # send_object({'you said' => obj})
10
+ # end
11
+ # end
12
+ #
13
+ module ObjectProtocol
14
+ # By default returns Marshal, override to return JSON or YAML, or any
15
+ # other serializer/deserializer responding to #dump and #load.
16
+ def serializer
17
+ Marshal
18
+ end
19
+
20
+ def receive_data data # :nodoc:
21
+ (@buf ||= '') << data
22
+
23
+ while @buf.size >= 4
24
+ if @buf.size >= 4+(size=@buf.unpack('N').first)
25
+ @buf.slice!(0,4)
26
+ receive_object serializer.load(@buf.slice!(0,size))
27
+ else
28
+ break
29
+ end
30
+ end
31
+ end
32
+
33
+ # Invoked with ruby objects received over the network
34
+ def receive_object obj
35
+ # stub
36
+ end
37
+
38
+ # Sends a ruby object over the network
39
+ def send_object obj
40
+ data = serializer.dump(obj)
41
+ send_data [data.respond_to?(:bytesize) ? data.bytesize : data.size, data].pack('Na*')
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,247 @@
1
+ #--
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 15 November 2006
6
+ #
7
+ # See EventMachine and EventMachine::Connection for documentation and
8
+ # usage examples.
9
+ #
10
+ #----------------------------------------------------------------------------
11
+ #
12
+ # Copyright (C) 2006-08 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU General Public License
17
+ # as published by the Free Software Foundation; either version 2 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #---------------------------------------------------------------------------
23
+ #
24
+ #
25
+ #
26
+
27
+ require 'readbytes'
28
+ require 'postgres-pr/message'
29
+ require 'postgres-pr/connection'
30
+ require 'stringio'
31
+
32
+ class StringIO # :nodoc:
33
+ # Reads exactly +n+ bytes.
34
+ #
35
+ # If the data read is nil an EOFError is raised.
36
+ #
37
+ # If the data read is too short a TruncatedDataError is raised and the read
38
+ # data is obtainable via its #data method.
39
+ def readbytes(n)
40
+ str = read(n)
41
+ if str == nil
42
+ raise EOFError, "End of file reached"
43
+ end
44
+ if str.size < n
45
+ raise TruncatedDataError.new("data truncated", str)
46
+ end
47
+ str
48
+ end
49
+ alias read_exactly_n_bytes readbytes
50
+ end
51
+
52
+
53
+ module EventMachine
54
+ module Protocols
55
+ # PROVISIONAL IMPLEMENTATION of an evented Postgres client.
56
+ # This implements version 3 of the Postgres wire protocol, which will work
57
+ # with any Postgres version from roughly 7.4 onward.
58
+ #
59
+ # Objective: we want to access Postgres databases without requiring threads.
60
+ # Until now this has been a problem because the Postgres client implementations
61
+ # have all made use of blocking I/O calls, which is incompatible with a
62
+ # thread-free evented model.
63
+ #
64
+ # But rather than re-implement the Postgres Wire3 protocol, we're taking advantage
65
+ # of the existing postgres-pr library, which was originally written by Michael
66
+ # Neumann but (at this writing) appears to be no longer maintained. Still, it's
67
+ # in basically a production-ready state, and the wire protocol isn't that complicated
68
+ # anyway.
69
+ #
70
+ # We need to monkeypatch StringIO because it lacks the #readbytes method needed
71
+ # by postgres-pr.
72
+ #
73
+ # We're tucking in a bunch of require statements that may not be present in garden-variety
74
+ # EM installations. Until we find a good way to only require these if a program
75
+ # requires postgres, this file will need to be required explicitly.
76
+ #
77
+ # The StringIO monkeypatch is lifted verbatim from the standard library readbytes.rb,
78
+ # which adds method #readbytes directly to class IO. But StringIO is not a subclass of IO.
79
+ #
80
+ # We cloned the handling of postgres messages from lib/postgres-pr/connection.rb
81
+ # in the postgres-pr library, and modified it for event-handling.
82
+ #
83
+ # TODO: The password handling in dispatch_conn_message is totally incomplete.
84
+ #
85
+ #
86
+ # We return Deferrables from the user-level operations surfaced by this interface.
87
+ # Experimentally, we're using the pattern of always returning a boolean value as the
88
+ # first argument of a deferrable callback to indicate success or failure. This is
89
+ # instead of the traditional pattern of calling Deferrable#succeed or #fail, and
90
+ # requiring the user to define both a callback and an errback function.
91
+ #
92
+ # === Usage
93
+ # EM.run {
94
+ # db = EM.connect_unix_domain( "/tmp/.s.PGSQL.5432", EM::P::Postgres3 )
95
+ # db.connect( dbname, username, psw ).callback do |status|
96
+ # if status
97
+ # db.query( "select * from some_table" ).callback do |status, result, errors|
98
+ # if status
99
+ # result.rows.each do |row|
100
+ # p row
101
+ # end
102
+ # end
103
+ # end
104
+ # end
105
+ # end
106
+ # }
107
+ class Postgres3 < EventMachine::Connection
108
+ include PostgresPR
109
+
110
+ def initialize
111
+ @data = ""
112
+ @params = {}
113
+ end
114
+
115
+ def connect db, user, psw=nil
116
+ d = EM::DefaultDeferrable.new
117
+ d.timeout 15
118
+
119
+ if @pending_query || @pending_conn
120
+ d.succeed false, "Operation already in progress"
121
+ else
122
+ @pending_conn = d
123
+ prms = {"user"=>user, "database"=>db}
124
+ @user = user
125
+ if psw
126
+ @password = psw
127
+ #prms["password"] = psw
128
+ end
129
+ send_data PostgresPR::StartupMessage.new( 3 << 16, prms ).dump
130
+ end
131
+
132
+ d
133
+ end
134
+
135
+ def query sql
136
+ d = EM::DefaultDeferrable.new
137
+ d.timeout 15
138
+
139
+ if @pending_query || @pending_conn
140
+ d.succeed false, "Operation already in progress"
141
+ else
142
+ @r = PostgresPR::Connection::Result.new
143
+ @e = []
144
+ @pending_query = d
145
+ send_data PostgresPR::Query.dump(sql)
146
+ end
147
+
148
+ d
149
+ end
150
+
151
+
152
+ def receive_data data
153
+ @data << data
154
+ while @data.length >= 5
155
+ pktlen = @data[1...5].unpack("N").first
156
+ if @data.length >= (1 + pktlen)
157
+ pkt = @data.slice!(0...(1+pktlen))
158
+ m = StringIO.open( pkt, "r" ) {|io| PostgresPR::Message.read( io ) }
159
+ if @pending_conn
160
+ dispatch_conn_message m
161
+ elsif @pending_query
162
+ dispatch_query_message m
163
+ else
164
+ raise "Unexpected message from database"
165
+ end
166
+ else
167
+ break # very important, break out of the while
168
+ end
169
+ end
170
+ end
171
+
172
+
173
+ def unbind
174
+ if o = (@pending_query || @pending_conn)
175
+ o.succeed false, "lost connection"
176
+ end
177
+ end
178
+
179
+ # Cloned and modified from the postgres-pr.
180
+ def dispatch_conn_message msg
181
+ case msg
182
+ when AuthentificationClearTextPassword
183
+ raise ArgumentError, "no password specified" if @password.nil?
184
+ send_data PasswordMessage.new(@password).dump
185
+
186
+ when AuthentificationCryptPassword
187
+ raise ArgumentError, "no password specified" if @password.nil?
188
+ send_data PasswordMessage.new(@password.crypt(msg.salt)).dump
189
+
190
+ when AuthentificationMD5Password
191
+ raise ArgumentError, "no password specified" if @password.nil?
192
+ require 'digest/md5'
193
+
194
+ m = Digest::MD5.hexdigest(@password + @user)
195
+ m = Digest::MD5.hexdigest(m + msg.salt)
196
+ m = 'md5' + m
197
+ send_data PasswordMessage.new(m).dump
198
+
199
+ when AuthentificationKerberosV4, AuthentificationKerberosV5, AuthentificationSCMCredential
200
+ raise "unsupported authentification"
201
+
202
+ when AuthentificationOk
203
+ when ErrorResponse
204
+ raise msg.field_values.join("\t")
205
+ when NoticeResponse
206
+ @notice_processor.call(msg) if @notice_processor
207
+ when ParameterStatus
208
+ @params[msg.key] = msg.value
209
+ when BackendKeyData
210
+ # TODO
211
+ #p msg
212
+ when ReadyForQuery
213
+ # TODO: use transaction status
214
+ pc,@pending_conn = @pending_conn,nil
215
+ pc.succeed true
216
+ else
217
+ raise "unhandled message type"
218
+ end
219
+ end
220
+
221
+ # Cloned and modified from the postgres-pr.
222
+ def dispatch_query_message msg
223
+ case msg
224
+ when DataRow
225
+ @r.rows << msg.columns
226
+ when CommandComplete
227
+ @r.cmd_tag = msg.cmd_tag
228
+ when ReadyForQuery
229
+ pq,@pending_query = @pending_query,nil
230
+ pq.succeed true, @r, @e
231
+ when RowDescription
232
+ @r.fields = msg.fields
233
+ when CopyInResponse
234
+ when CopyOutResponse
235
+ when EmptyQueryResponse
236
+ when ErrorResponse
237
+ # TODO
238
+ @e << msg
239
+ when NoticeResponse
240
+ @notice_processor.call(msg) if @notice_processor
241
+ else
242
+ # TODO
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
@@ -0,0 +1,175 @@
1
+ #--
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 15 November 2006
6
+ #
7
+ # See EventMachine and EventMachine::Connection for documentation and
8
+ # usage examples.
9
+ #
10
+ #----------------------------------------------------------------------------
11
+ #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU General Public License
17
+ # as published by the Free Software Foundation; either version 2 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #---------------------------------------------------------------------------
23
+ #
24
+ #
25
+ #
26
+
27
+ module EventMachine
28
+ module Protocols
29
+
30
+ # Implements SASL authd.
31
+ # This is a very, very simple protocol that mimics the one used
32
+ # by saslauthd and pwcheck, two outboard daemons included in the
33
+ # standard SASL library distro.
34
+ # The only thing this is really suitable for is SASL PLAIN
35
+ # (user+password) authentication, but the SASL libs that are
36
+ # linked into standard servers (like imapd and sendmail) implement
37
+ # the other ones.
38
+ #
39
+ # SASL-auth is intended for reasonably fast operation inside a
40
+ # single machine, so it has no transport-security (although there
41
+ # have been multi-machine extensions incorporating transport-layer
42
+ # encryption).
43
+ #
44
+ # The standard saslauthd module generally runs privileged and does
45
+ # its work by referring to the system-account files.
46
+ #
47
+ # This feature was added to EventMachine to enable the development
48
+ # of custom authentication/authorization engines for standard servers.
49
+ #
50
+ # To use SASLauth, include it in a class that subclasses EM::Connection,
51
+ # and reimplement the validate method.
52
+ #
53
+ # The typical way to incorporate this module into an authentication
54
+ # daemon would be to set it as the handler for a UNIX-domain socket.
55
+ # The code might look like this:
56
+ #
57
+ # EM.start_unix_domain_server( "/var/run/saslauthd/mux", MyHandler )
58
+ # File.chmod( 0777, "/var/run/saslauthd/mux")
59
+ #
60
+ # The chmod is probably needed to ensure that unprivileged clients can
61
+ # access the UNIX-domain socket.
62
+ #
63
+ # It's also a very good idea to drop superuser privileges (if any), after
64
+ # the UNIX-domain socket has been opened.
65
+ #--
66
+ # Implementation details: assume the client can send us pipelined requests,
67
+ # and that the client will close the connection.
68
+ #
69
+ # The client sends us four values, each encoded as a two-byte length field in
70
+ # network order followed by the specified number of octets.
71
+ # The fields specify the username, password, service name (such as imap),
72
+ # and the "realm" name. We send back the barest minimum reply, a single
73
+ # field also encoded as a two-octet length in network order, followed by
74
+ # either "NO" or "OK" - simplicity itself.
75
+ #
76
+ # We enforce a maximum field size just as a sanity check.
77
+ # We do NOT automatically time out the connection.
78
+ #
79
+ # The code we use to parse out the values is ugly and probably slow.
80
+ # Improvements welcome.
81
+ #
82
+ module SASLauth
83
+
84
+ MaxFieldSize = 128*1024
85
+ def post_init
86
+ super
87
+ @sasl_data = ""
88
+ @sasl_values = []
89
+ end
90
+
91
+ def receive_data data
92
+ @sasl_data << data
93
+ while @sasl_data.length >= 2
94
+ len = (@sasl_data[0,2].unpack("n")).first
95
+ raise "SASL Max Field Length exceeded" if len > MaxFieldSize
96
+ if @sasl_data.length >= (len + 2)
97
+ @sasl_values << @sasl_data[2,len]
98
+ @sasl_data.slice!(0...(2+len))
99
+ if @sasl_values.length == 4
100
+ send_data( validate(*@sasl_values) ? "\0\002OK" : "\0\002NO" )
101
+ @sasl_values.clear
102
+ end
103
+ else
104
+ break
105
+ end
106
+ end
107
+ end
108
+
109
+ def validate username, psw, sysname, realm
110
+ p username
111
+ p psw
112
+ p sysname
113
+ p realm
114
+ true
115
+ end
116
+ end
117
+
118
+ # Implements the SASL authd client protocol.
119
+ # This is a very, very simple protocol that mimics the one used
120
+ # by saslauthd and pwcheck, two outboard daemons included in the
121
+ # standard SASL library distro.
122
+ # The only thing this is really suitable for is SASL PLAIN
123
+ # (user+password) authentication, but the SASL libs that are
124
+ # linked into standard servers (like imapd and sendmail) implement
125
+ # the other ones.
126
+ #
127
+ # You can use this module directly as a handler for EM Connections,
128
+ # or include it in a module or handler class of your own.
129
+ #
130
+ # First connect to a SASL server (it's probably a TCP server, or more
131
+ # likely a Unix-domain socket). Then call the #validate? method,
132
+ # passing at least a username and a password. #validate? returns
133
+ # a Deferrable which will either succeed or fail, depending
134
+ # on the status of the authentication operation.
135
+ #
136
+ module SASLauthclient
137
+ MaxFieldSize = 128*1024
138
+
139
+ def validate? username, psw, sysname=nil, realm=nil
140
+
141
+ str = [username, psw, sysname, realm].map {|m|
142
+ [(m || "").length, (m || "")]
143
+ }.flatten.pack( "nA*" * 4 )
144
+ send_data str
145
+
146
+ d = EM::DefaultDeferrable.new
147
+ @queries.unshift d
148
+ d
149
+ end
150
+
151
+ def post_init
152
+ @sasl_data = ""
153
+ @queries = []
154
+ end
155
+
156
+ def receive_data data
157
+ @sasl_data << data
158
+
159
+ while @sasl_data.length > 2
160
+ len = (@sasl_data[0,2].unpack("n")).first
161
+ raise "SASL Max Field Length exceeded" if len > MaxFieldSize
162
+ if @sasl_data.length >= (len + 2)
163
+ val = @sasl_data[2,len]
164
+ @sasl_data.slice!(0...(2+len))
165
+ q = @queries.pop
166
+ (val == "NO") ? q.fail : q.succeed
167
+ else
168
+ break
169
+ end
170
+ end
171
+ end
172
+ end
173
+
174
+ end
175
+ end