ruby_on_ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (493) hide show
  1. data/.gitignore +18 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE +22 -0
  5. data/README.md +66 -0
  6. data/Rakefile +1 -0
  7. data/lib/ruby_on_ruby.rb +5 -0
  8. data/lib/ruby_on_ruby/console.rb +7 -0
  9. data/lib/ruby_on_ruby/context.rb +33 -0
  10. data/lib/ruby_on_ruby/file_loader.rb +31 -0
  11. data/lib/ruby_on_ruby/ruby_stream.rb +27 -0
  12. data/lib/ruby_on_ruby/version.rb +3 -0
  13. data/lib/rubyonruby.rb +1 -0
  14. data/ruby_in_ruby.gemspec +19 -0
  15. data/vendor/javascripts/emscripted-ruby/lib/.document +106 -0
  16. data/vendor/javascripts/emscripted-ruby/lib/English.rb +155 -0
  17. data/vendor/javascripts/emscripted-ruby/lib/Env.rb +18 -0
  18. data/vendor/javascripts/emscripted-ruby/lib/README +96 -0
  19. data/vendor/javascripts/emscripted-ruby/lib/abbrev.rb +103 -0
  20. data/vendor/javascripts/emscripted-ruby/lib/base64.rb +133 -0
  21. data/vendor/javascripts/emscripted-ruby/lib/benchmark.rb +572 -0
  22. data/vendor/javascripts/emscripted-ruby/lib/cgi-lib.rb +272 -0
  23. data/vendor/javascripts/emscripted-ruby/lib/cgi.rb +2308 -0
  24. data/vendor/javascripts/emscripted-ruby/lib/cgi/.document +2 -0
  25. data/vendor/javascripts/emscripted-ruby/lib/cgi/session.rb +498 -0
  26. data/vendor/javascripts/emscripted-ruby/lib/cgi/session/pstore.rb +111 -0
  27. data/vendor/javascripts/emscripted-ruby/lib/complex.rb +663 -0
  28. data/vendor/javascripts/emscripted-ruby/lib/csv.rb +992 -0
  29. data/vendor/javascripts/emscripted-ruby/lib/date.rb +1767 -0
  30. data/vendor/javascripts/emscripted-ruby/lib/date/format.rb +1190 -0
  31. data/vendor/javascripts/emscripted-ruby/lib/date2.rb +5 -0
  32. data/vendor/javascripts/emscripted-ruby/lib/debug.rb +947 -0
  33. data/vendor/javascripts/emscripted-ruby/lib/delegate.rb +337 -0
  34. data/vendor/javascripts/emscripted-ruby/lib/drb.rb +2 -0
  35. data/vendor/javascripts/emscripted-ruby/lib/drb/acl.rb +146 -0
  36. data/vendor/javascripts/emscripted-ruby/lib/drb/drb.rb +1782 -0
  37. data/vendor/javascripts/emscripted-ruby/lib/drb/eq.rb +16 -0
  38. data/vendor/javascripts/emscripted-ruby/lib/drb/extserv.rb +64 -0
  39. data/vendor/javascripts/emscripted-ruby/lib/drb/extservm.rb +89 -0
  40. data/vendor/javascripts/emscripted-ruby/lib/drb/gw.rb +122 -0
  41. data/vendor/javascripts/emscripted-ruby/lib/drb/invokemethod.rb +36 -0
  42. data/vendor/javascripts/emscripted-ruby/lib/drb/observer.rb +22 -0
  43. data/vendor/javascripts/emscripted-ruby/lib/drb/ssl.rb +190 -0
  44. data/vendor/javascripts/emscripted-ruby/lib/drb/timeridconv.rb +91 -0
  45. data/vendor/javascripts/emscripted-ruby/lib/drb/unix.rb +108 -0
  46. data/vendor/javascripts/emscripted-ruby/lib/e2mmap.rb +195 -0
  47. data/vendor/javascripts/emscripted-ruby/lib/erb.rb +880 -0
  48. data/vendor/javascripts/emscripted-ruby/lib/eregex.rb +37 -0
  49. data/vendor/javascripts/emscripted-ruby/lib/fileutils.rb +1591 -0
  50. data/vendor/javascripts/emscripted-ruby/lib/finalize.rb +193 -0
  51. data/vendor/javascripts/emscripted-ruby/lib/find.rb +79 -0
  52. data/vendor/javascripts/emscripted-ruby/lib/forwardable.rb +218 -0
  53. data/vendor/javascripts/emscripted-ruby/lib/ftools.rb +261 -0
  54. data/vendor/javascripts/emscripted-ruby/lib/generator.rb +418 -0
  55. data/vendor/javascripts/emscripted-ruby/lib/getoptlong.rb +621 -0
  56. data/vendor/javascripts/emscripted-ruby/lib/getopts.rb +127 -0
  57. data/vendor/javascripts/emscripted-ruby/lib/gserver.rb +253 -0
  58. data/vendor/javascripts/emscripted-ruby/lib/importenv.rb +33 -0
  59. data/vendor/javascripts/emscripted-ruby/lib/ipaddr.rb +814 -0
  60. data/vendor/javascripts/emscripted-ruby/lib/irb.rb +346 -0
  61. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/chws.rb +33 -0
  62. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/fork.rb +39 -0
  63. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/help.rb +34 -0
  64. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/load.rb +67 -0
  65. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/nop.rb +39 -0
  66. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/pushws.rb +39 -0
  67. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/subirb.rb +43 -0
  68. data/vendor/javascripts/emscripted-ruby/lib/irb/completion.rb +205 -0
  69. data/vendor/javascripts/emscripted-ruby/lib/irb/context.rb +255 -0
  70. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/change-ws.rb +62 -0
  71. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/history.rb +110 -0
  72. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/loader.rb +120 -0
  73. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/math-mode.rb +37 -0
  74. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/multi-irb.rb +241 -0
  75. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/save-history.rb +85 -0
  76. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/tracer.rb +61 -0
  77. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/use-loader.rb +65 -0
  78. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/workspaces.rb +56 -0
  79. data/vendor/javascripts/emscripted-ruby/lib/irb/extend-command.rb +264 -0
  80. data/vendor/javascripts/emscripted-ruby/lib/irb/frame.rb +67 -0
  81. data/vendor/javascripts/emscripted-ruby/lib/irb/help.rb +33 -0
  82. data/vendor/javascripts/emscripted-ruby/lib/irb/init.rb +259 -0
  83. data/vendor/javascripts/emscripted-ruby/lib/irb/input-method.rb +120 -0
  84. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/error.rb +30 -0
  85. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/help-message +35 -0
  86. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/ja/error.rb +27 -0
  87. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/ja/help-message +36 -0
  88. data/vendor/javascripts/emscripted-ruby/lib/irb/locale.rb +184 -0
  89. data/vendor/javascripts/emscripted-ruby/lib/irb/notifier.rb +145 -0
  90. data/vendor/javascripts/emscripted-ruby/lib/irb/output-method.rb +85 -0
  91. data/vendor/javascripts/emscripted-ruby/lib/irb/ruby-lex.rb +1149 -0
  92. data/vendor/javascripts/emscripted-ruby/lib/irb/ruby-token.rb +273 -0
  93. data/vendor/javascripts/emscripted-ruby/lib/irb/slex.rb +285 -0
  94. data/vendor/javascripts/emscripted-ruby/lib/irb/version.rb +16 -0
  95. data/vendor/javascripts/emscripted-ruby/lib/irb/workspace.rb +107 -0
  96. data/vendor/javascripts/emscripted-ruby/lib/irb/ws-for-case-2.rb +15 -0
  97. data/vendor/javascripts/emscripted-ruby/lib/irb/xmp.rb +86 -0
  98. data/vendor/javascripts/emscripted-ruby/lib/jcode.rb +220 -0
  99. data/vendor/javascripts/emscripted-ruby/lib/logger.rb +703 -0
  100. data/vendor/javascripts/emscripted-ruby/lib/mailread.rb +62 -0
  101. data/vendor/javascripts/emscripted-ruby/lib/mathn.rb +308 -0
  102. data/vendor/javascripts/emscripted-ruby/lib/matrix.rb +1278 -0
  103. data/vendor/javascripts/emscripted-ruby/lib/mkmf.rb +1811 -0
  104. data/vendor/javascripts/emscripted-ruby/lib/monitor.rb +352 -0
  105. data/vendor/javascripts/emscripted-ruby/lib/mutex_m.rb +122 -0
  106. data/vendor/javascripts/emscripted-ruby/lib/net/ftp.rb +927 -0
  107. data/vendor/javascripts/emscripted-ruby/lib/net/http.rb +2277 -0
  108. data/vendor/javascripts/emscripted-ruby/lib/net/https.rb +173 -0
  109. data/vendor/javascripts/emscripted-ruby/lib/net/imap.rb +3371 -0
  110. data/vendor/javascripts/emscripted-ruby/lib/net/pop.rb +999 -0
  111. data/vendor/javascripts/emscripted-ruby/lib/net/protocol.rb +392 -0
  112. data/vendor/javascripts/emscripted-ruby/lib/net/smtp.rb +1014 -0
  113. data/vendor/javascripts/emscripted-ruby/lib/net/telnet.rb +756 -0
  114. data/vendor/javascripts/emscripted-ruby/lib/observer.rb +192 -0
  115. data/vendor/javascripts/emscripted-ruby/lib/open-uri.rb +678 -0
  116. data/vendor/javascripts/emscripted-ruby/lib/open3.rb +101 -0
  117. data/vendor/javascripts/emscripted-ruby/lib/optparse.rb +1790 -0
  118. data/vendor/javascripts/emscripted-ruby/lib/optparse/date.rb +17 -0
  119. data/vendor/javascripts/emscripted-ruby/lib/optparse/shellwords.rb +6 -0
  120. data/vendor/javascripts/emscripted-ruby/lib/optparse/time.rb +10 -0
  121. data/vendor/javascripts/emscripted-ruby/lib/optparse/uri.rb +6 -0
  122. data/vendor/javascripts/emscripted-ruby/lib/optparse/version.rb +70 -0
  123. data/vendor/javascripts/emscripted-ruby/lib/ostruct.rb +146 -0
  124. data/vendor/javascripts/emscripted-ruby/lib/parsearg.rb +87 -0
  125. data/vendor/javascripts/emscripted-ruby/lib/parsedate.rb +53 -0
  126. data/vendor/javascripts/emscripted-ruby/lib/pathname.rb +1062 -0
  127. data/vendor/javascripts/emscripted-ruby/lib/ping.rb +64 -0
  128. data/vendor/javascripts/emscripted-ruby/lib/pp.rb +654 -0
  129. data/vendor/javascripts/emscripted-ruby/lib/prettyprint.rb +896 -0
  130. data/vendor/javascripts/emscripted-ruby/lib/profile.rb +6 -0
  131. data/vendor/javascripts/emscripted-ruby/lib/profiler.rb +59 -0
  132. data/vendor/javascripts/emscripted-ruby/lib/pstore.rb +395 -0
  133. data/vendor/javascripts/emscripted-ruby/lib/racc/parser.rb +442 -0
  134. data/vendor/javascripts/emscripted-ruby/lib/rational.rb +564 -0
  135. data/vendor/javascripts/emscripted-ruby/lib/readbytes.rb +41 -0
  136. data/vendor/javascripts/emscripted-ruby/lib/resolv-replace.rb +62 -0
  137. data/vendor/javascripts/emscripted-ruby/lib/resolv.rb +2210 -0
  138. data/vendor/javascripts/emscripted-ruby/lib/rexml/attlistdecl.rb +62 -0
  139. data/vendor/javascripts/emscripted-ruby/lib/rexml/attribute.rb +185 -0
  140. data/vendor/javascripts/emscripted-ruby/lib/rexml/cdata.rb +67 -0
  141. data/vendor/javascripts/emscripted-ruby/lib/rexml/child.rb +96 -0
  142. data/vendor/javascripts/emscripted-ruby/lib/rexml/comment.rb +80 -0
  143. data/vendor/javascripts/emscripted-ruby/lib/rexml/doctype.rb +271 -0
  144. data/vendor/javascripts/emscripted-ruby/lib/rexml/document.rb +208 -0
  145. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/attlistdecl.rb +10 -0
  146. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/dtd.rb +51 -0
  147. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/elementdecl.rb +17 -0
  148. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/entitydecl.rb +56 -0
  149. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/notationdecl.rb +39 -0
  150. data/vendor/javascripts/emscripted-ruby/lib/rexml/element.rb +1227 -0
  151. data/vendor/javascripts/emscripted-ruby/lib/rexml/encoding.rb +71 -0
  152. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/CP-1252.rb +103 -0
  153. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/EUC-JP.rb +35 -0
  154. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ICONV.rb +22 -0
  155. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ISO-8859-1.rb +7 -0
  156. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ISO-8859-15.rb +72 -0
  157. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
  158. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
  159. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UNILE.rb +34 -0
  160. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/US-ASCII.rb +30 -0
  161. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UTF-16.rb +35 -0
  162. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UTF-8.rb +18 -0
  163. data/vendor/javascripts/emscripted-ruby/lib/rexml/entity.rb +165 -0
  164. data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/default.rb +109 -0
  165. data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/pretty.rb +137 -0
  166. data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/transitive.rb +56 -0
  167. data/vendor/javascripts/emscripted-ruby/lib/rexml/functions.rb +382 -0
  168. data/vendor/javascripts/emscripted-ruby/lib/rexml/instruction.rb +70 -0
  169. data/vendor/javascripts/emscripted-ruby/lib/rexml/light/node.rb +196 -0
  170. data/vendor/javascripts/emscripted-ruby/lib/rexml/namespace.rb +47 -0
  171. data/vendor/javascripts/emscripted-ruby/lib/rexml/node.rb +75 -0
  172. data/vendor/javascripts/emscripted-ruby/lib/rexml/output.rb +24 -0
  173. data/vendor/javascripts/emscripted-ruby/lib/rexml/parent.rb +166 -0
  174. data/vendor/javascripts/emscripted-ruby/lib/rexml/parseexception.rb +51 -0
  175. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/baseparser.rb +503 -0
  176. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/lightparser.rb +60 -0
  177. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/pullparser.rb +196 -0
  178. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/sax2parser.rb +238 -0
  179. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/streamparser.rb +46 -0
  180. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/treeparser.rb +97 -0
  181. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/ultralightparser.rb +56 -0
  182. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/xpathparser.rb +698 -0
  183. data/vendor/javascripts/emscripted-ruby/lib/rexml/quickpath.rb +266 -0
  184. data/vendor/javascripts/emscripted-ruby/lib/rexml/rexml.rb +32 -0
  185. data/vendor/javascripts/emscripted-ruby/lib/rexml/sax2listener.rb +97 -0
  186. data/vendor/javascripts/emscripted-ruby/lib/rexml/source.rb +251 -0
  187. data/vendor/javascripts/emscripted-ruby/lib/rexml/streamlistener.rb +92 -0
  188. data/vendor/javascripts/emscripted-ruby/lib/rexml/syncenumerator.rb +33 -0
  189. data/vendor/javascripts/emscripted-ruby/lib/rexml/text.rb +344 -0
  190. data/vendor/javascripts/emscripted-ruby/lib/rexml/undefinednamespaceexception.rb +8 -0
  191. data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/relaxng.rb +559 -0
  192. data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/validation.rb +155 -0
  193. data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/validationexception.rb +9 -0
  194. data/vendor/javascripts/emscripted-ruby/lib/rexml/xmldecl.rb +119 -0
  195. data/vendor/javascripts/emscripted-ruby/lib/rexml/xmltokens.rb +18 -0
  196. data/vendor/javascripts/emscripted-ruby/lib/rexml/xpath.rb +66 -0
  197. data/vendor/javascripts/emscripted-ruby/lib/rexml/xpath_parser.rb +792 -0
  198. data/vendor/javascripts/emscripted-ruby/lib/rinda/rinda.rb +283 -0
  199. data/vendor/javascripts/emscripted-ruby/lib/rinda/ring.rb +271 -0
  200. data/vendor/javascripts/emscripted-ruby/lib/rinda/tuplespace.rb +642 -0
  201. data/vendor/javascripts/emscripted-ruby/lib/rss.rb +19 -0
  202. data/vendor/javascripts/emscripted-ruby/lib/rss/0.9.rb +428 -0
  203. data/vendor/javascripts/emscripted-ruby/lib/rss/1.0.rb +452 -0
  204. data/vendor/javascripts/emscripted-ruby/lib/rss/2.0.rb +111 -0
  205. data/vendor/javascripts/emscripted-ruby/lib/rss/atom.rb +749 -0
  206. data/vendor/javascripts/emscripted-ruby/lib/rss/content.rb +31 -0
  207. data/vendor/javascripts/emscripted-ruby/lib/rss/content/1.0.rb +10 -0
  208. data/vendor/javascripts/emscripted-ruby/lib/rss/content/2.0.rb +12 -0
  209. data/vendor/javascripts/emscripted-ruby/lib/rss/converter.rb +162 -0
  210. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore.rb +161 -0
  211. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/1.0.rb +13 -0
  212. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/2.0.rb +13 -0
  213. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/atom.rb +17 -0
  214. data/vendor/javascripts/emscripted-ruby/lib/rss/image.rb +193 -0
  215. data/vendor/javascripts/emscripted-ruby/lib/rss/itunes.rb +410 -0
  216. data/vendor/javascripts/emscripted-ruby/lib/rss/maker.rb +44 -0
  217. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/0.9.rb +467 -0
  218. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/1.0.rb +434 -0
  219. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/2.0.rb +223 -0
  220. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/atom.rb +172 -0
  221. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/base.rb +868 -0
  222. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/content.rb +21 -0
  223. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/dublincore.rb +124 -0
  224. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/entry.rb +163 -0
  225. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/feed.rb +429 -0
  226. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/image.rb +111 -0
  227. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/itunes.rb +242 -0
  228. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/slash.rb +33 -0
  229. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/syndication.rb +18 -0
  230. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/taxonomy.rb +118 -0
  231. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/trackback.rb +61 -0
  232. data/vendor/javascripts/emscripted-ruby/lib/rss/parser.rb +541 -0
  233. data/vendor/javascripts/emscripted-ruby/lib/rss/rexmlparser.rb +54 -0
  234. data/vendor/javascripts/emscripted-ruby/lib/rss/rss.rb +1312 -0
  235. data/vendor/javascripts/emscripted-ruby/lib/rss/slash.rb +49 -0
  236. data/vendor/javascripts/emscripted-ruby/lib/rss/syndication.rb +67 -0
  237. data/vendor/javascripts/emscripted-ruby/lib/rss/taxonomy.rb +145 -0
  238. data/vendor/javascripts/emscripted-ruby/lib/rss/trackback.rb +288 -0
  239. data/vendor/javascripts/emscripted-ruby/lib/rss/utils.rb +111 -0
  240. data/vendor/javascripts/emscripted-ruby/lib/rss/xml-stylesheet.rb +105 -0
  241. data/vendor/javascripts/emscripted-ruby/lib/rss/xml.rb +71 -0
  242. data/vendor/javascripts/emscripted-ruby/lib/rss/xmlparser.rb +93 -0
  243. data/vendor/javascripts/emscripted-ruby/lib/rss/xmlscanner.rb +121 -0
  244. data/vendor/javascripts/emscripted-ruby/lib/rubyunit.rb +6 -0
  245. data/vendor/javascripts/emscripted-ruby/lib/runit/assert.rb +73 -0
  246. data/vendor/javascripts/emscripted-ruby/lib/runit/cui/testrunner.rb +51 -0
  247. data/vendor/javascripts/emscripted-ruby/lib/runit/error.rb +9 -0
  248. data/vendor/javascripts/emscripted-ruby/lib/runit/testcase.rb +45 -0
  249. data/vendor/javascripts/emscripted-ruby/lib/runit/testresult.rb +44 -0
  250. data/vendor/javascripts/emscripted-ruby/lib/runit/testsuite.rb +26 -0
  251. data/vendor/javascripts/emscripted-ruby/lib/runit/topublic.rb +8 -0
  252. data/vendor/javascripts/emscripted-ruby/lib/scanf.rb +702 -0
  253. data/vendor/javascripts/emscripted-ruby/lib/securerandom.rb +137 -0
  254. data/vendor/javascripts/emscripted-ruby/lib/set.rb +1233 -0
  255. data/vendor/javascripts/emscripted-ruby/lib/shell.rb +269 -0
  256. data/vendor/javascripts/emscripted-ruby/lib/shell/builtin-command.rb +154 -0
  257. data/vendor/javascripts/emscripted-ruby/lib/shell/command-processor.rb +592 -0
  258. data/vendor/javascripts/emscripted-ruby/lib/shell/error.rb +26 -0
  259. data/vendor/javascripts/emscripted-ruby/lib/shell/filter.rb +110 -0
  260. data/vendor/javascripts/emscripted-ruby/lib/shell/process-controller.rb +260 -0
  261. data/vendor/javascripts/emscripted-ruby/lib/shell/system-command.rb +168 -0
  262. data/vendor/javascripts/emscripted-ruby/lib/shell/version.rb +16 -0
  263. data/vendor/javascripts/emscripted-ruby/lib/shellwords.rb +172 -0
  264. data/vendor/javascripts/emscripted-ruby/lib/singleton.rb +360 -0
  265. data/vendor/javascripts/emscripted-ruby/lib/soap/attachment.rb +107 -0
  266. data/vendor/javascripts/emscripted-ruby/lib/soap/baseData.rb +942 -0
  267. data/vendor/javascripts/emscripted-ruby/lib/soap/element.rb +258 -0
  268. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/aspDotNetHandler.rb +213 -0
  269. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/handler.rb +100 -0
  270. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/literalHandler.rb +226 -0
  271. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/soapHandler.rb +582 -0
  272. data/vendor/javascripts/emscripted-ruby/lib/soap/generator.rb +268 -0
  273. data/vendor/javascripts/emscripted-ruby/lib/soap/header/handler.rb +57 -0
  274. data/vendor/javascripts/emscripted-ruby/lib/soap/header/handlerset.rb +70 -0
  275. data/vendor/javascripts/emscripted-ruby/lib/soap/header/simplehandler.rb +44 -0
  276. data/vendor/javascripts/emscripted-ruby/lib/soap/httpconfigloader.rb +119 -0
  277. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping.rb +10 -0
  278. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/factory.rb +355 -0
  279. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/mapping.rb +381 -0
  280. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/registry.rb +541 -0
  281. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/rubytypeFactory.rb +475 -0
  282. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/typeMap.rb +50 -0
  283. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/wsdlencodedregistry.rb +280 -0
  284. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/wsdlliteralregistry.rb +418 -0
  285. data/vendor/javascripts/emscripted-ruby/lib/soap/marshal.rb +59 -0
  286. data/vendor/javascripts/emscripted-ruby/lib/soap/mimemessage.rb +240 -0
  287. data/vendor/javascripts/emscripted-ruby/lib/soap/netHttpClient.rb +190 -0
  288. data/vendor/javascripts/emscripted-ruby/lib/soap/parser.rb +251 -0
  289. data/vendor/javascripts/emscripted-ruby/lib/soap/processor.rb +66 -0
  290. data/vendor/javascripts/emscripted-ruby/lib/soap/property.rb +333 -0
  291. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/cgistub.rb +206 -0
  292. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/driver.rb +254 -0
  293. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/element.rb +325 -0
  294. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/httpserver.rb +129 -0
  295. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/proxy.rb +497 -0
  296. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/router.rb +594 -0
  297. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/rpc.rb +25 -0
  298. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/soaplet.rb +162 -0
  299. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/standaloneServer.rb +43 -0
  300. data/vendor/javascripts/emscripted-ruby/lib/soap/soap.rb +140 -0
  301. data/vendor/javascripts/emscripted-ruby/lib/soap/streamHandler.rb +229 -0
  302. data/vendor/javascripts/emscripted-ruby/lib/soap/wsdlDriver.rb +575 -0
  303. data/vendor/javascripts/emscripted-ruby/lib/sync.rb +311 -0
  304. data/vendor/javascripts/emscripted-ruby/lib/tempfile.rb +209 -0
  305. data/vendor/javascripts/emscripted-ruby/lib/test/unit.rb +280 -0
  306. data/vendor/javascripts/emscripted-ruby/lib/test/unit/assertionfailederror.rb +14 -0
  307. data/vendor/javascripts/emscripted-ruby/lib/test/unit/assertions.rb +622 -0
  308. data/vendor/javascripts/emscripted-ruby/lib/test/unit/autorunner.rb +220 -0
  309. data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector.rb +43 -0
  310. data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector/dir.rb +107 -0
  311. data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector/objectspace.rb +34 -0
  312. data/vendor/javascripts/emscripted-ruby/lib/test/unit/error.rb +56 -0
  313. data/vendor/javascripts/emscripted-ruby/lib/test/unit/failure.rb +51 -0
  314. data/vendor/javascripts/emscripted-ruby/lib/test/unit/testcase.rb +160 -0
  315. data/vendor/javascripts/emscripted-ruby/lib/test/unit/testresult.rb +80 -0
  316. data/vendor/javascripts/emscripted-ruby/lib/test/unit/testsuite.rb +76 -0
  317. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/console/testrunner.rb +127 -0
  318. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/fox/testrunner.rb +268 -0
  319. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/gtk/testrunner.rb +416 -0
  320. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/gtk2/testrunner.rb +465 -0
  321. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/testrunnermediator.rb +68 -0
  322. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/testrunnerutilities.rb +46 -0
  323. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/tk/testrunner.rb +260 -0
  324. data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/backtracefilter.rb +40 -0
  325. data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/observable.rb +90 -0
  326. data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/procwrapper.rb +48 -0
  327. data/vendor/javascripts/emscripted-ruby/lib/thread.rb +479 -0
  328. data/vendor/javascripts/emscripted-ruby/lib/thwait.rb +169 -0
  329. data/vendor/javascripts/emscripted-ruby/lib/time.rb +797 -0
  330. data/vendor/javascripts/emscripted-ruby/lib/timeout.rb +122 -0
  331. data/vendor/javascripts/emscripted-ruby/lib/tmpdir.rb +130 -0
  332. data/vendor/javascripts/emscripted-ruby/lib/tracer.rb +167 -0
  333. data/vendor/javascripts/emscripted-ruby/lib/tsort.rb +290 -0
  334. data/vendor/javascripts/emscripted-ruby/lib/un.rb +235 -0
  335. data/vendor/javascripts/emscripted-ruby/lib/uri.rb +29 -0
  336. data/vendor/javascripts/emscripted-ruby/lib/uri/common.rb +611 -0
  337. data/vendor/javascripts/emscripted-ruby/lib/uri/ftp.rb +198 -0
  338. data/vendor/javascripts/emscripted-ruby/lib/uri/generic.rb +1122 -0
  339. data/vendor/javascripts/emscripted-ruby/lib/uri/http.rb +100 -0
  340. data/vendor/javascripts/emscripted-ruby/lib/uri/https.rb +20 -0
  341. data/vendor/javascripts/emscripted-ruby/lib/uri/ldap.rb +190 -0
  342. data/vendor/javascripts/emscripted-ruby/lib/uri/ldaps.rb +12 -0
  343. data/vendor/javascripts/emscripted-ruby/lib/uri/mailto.rb +266 -0
  344. data/vendor/javascripts/emscripted-ruby/lib/weakref.rb +100 -0
  345. data/vendor/javascripts/emscripted-ruby/lib/webrick.rb +29 -0
  346. data/vendor/javascripts/emscripted-ruby/lib/webrick/accesslog.rb +67 -0
  347. data/vendor/javascripts/emscripted-ruby/lib/webrick/cgi.rb +257 -0
  348. data/vendor/javascripts/emscripted-ruby/lib/webrick/compat.rb +15 -0
  349. data/vendor/javascripts/emscripted-ruby/lib/webrick/config.rb +97 -0
  350. data/vendor/javascripts/emscripted-ruby/lib/webrick/cookie.rb +110 -0
  351. data/vendor/javascripts/emscripted-ruby/lib/webrick/htmlutils.rb +25 -0
  352. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth.rb +45 -0
  353. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/authenticator.rb +79 -0
  354. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/basicauth.rb +65 -0
  355. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/digestauth.rb +343 -0
  356. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htdigest.rb +91 -0
  357. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htgroup.rb +61 -0
  358. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htpasswd.rb +83 -0
  359. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/userdb.rb +29 -0
  360. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpproxy.rb +254 -0
  361. data/vendor/javascripts/emscripted-ruby/lib/webrick/httprequest.rb +365 -0
  362. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpresponse.rb +327 -0
  363. data/vendor/javascripts/emscripted-ruby/lib/webrick/https.rb +63 -0
  364. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpserver.rb +210 -0
  365. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet.rb +22 -0
  366. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/abstract.rb +71 -0
  367. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  368. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/cgihandler.rb +108 -0
  369. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/erbhandler.rb +54 -0
  370. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/filehandler.rb +435 -0
  371. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/prochandler.rb +33 -0
  372. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpstatus.rb +126 -0
  373. data/vendor/javascripts/emscripted-ruby/lib/webrick/httputils.rb +399 -0
  374. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpversion.rb +49 -0
  375. data/vendor/javascripts/emscripted-ruby/lib/webrick/log.rb +88 -0
  376. data/vendor/javascripts/emscripted-ruby/lib/webrick/server.rb +200 -0
  377. data/vendor/javascripts/emscripted-ruby/lib/webrick/ssl.rb +126 -0
  378. data/vendor/javascripts/emscripted-ruby/lib/webrick/utils.rb +100 -0
  379. data/vendor/javascripts/emscripted-ruby/lib/webrick/version.rb +13 -0
  380. data/vendor/javascripts/emscripted-ruby/lib/wsdl/binding.rb +65 -0
  381. data/vendor/javascripts/emscripted-ruby/lib/wsdl/data.rb +64 -0
  382. data/vendor/javascripts/emscripted-ruby/lib/wsdl/definitions.rb +250 -0
  383. data/vendor/javascripts/emscripted-ruby/lib/wsdl/documentation.rb +32 -0
  384. data/vendor/javascripts/emscripted-ruby/lib/wsdl/import.rb +80 -0
  385. data/vendor/javascripts/emscripted-ruby/lib/wsdl/importer.rb +38 -0
  386. data/vendor/javascripts/emscripted-ruby/lib/wsdl/info.rb +39 -0
  387. data/vendor/javascripts/emscripted-ruby/lib/wsdl/message.rb +54 -0
  388. data/vendor/javascripts/emscripted-ruby/lib/wsdl/operation.rb +130 -0
  389. data/vendor/javascripts/emscripted-ruby/lib/wsdl/operationBinding.rb +108 -0
  390. data/vendor/javascripts/emscripted-ruby/lib/wsdl/param.rb +85 -0
  391. data/vendor/javascripts/emscripted-ruby/lib/wsdl/parser.rb +163 -0
  392. data/vendor/javascripts/emscripted-ruby/lib/wsdl/part.rb +52 -0
  393. data/vendor/javascripts/emscripted-ruby/lib/wsdl/port.rb +84 -0
  394. data/vendor/javascripts/emscripted-ruby/lib/wsdl/portType.rb +73 -0
  395. data/vendor/javascripts/emscripted-ruby/lib/wsdl/service.rb +61 -0
  396. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/address.rb +40 -0
  397. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/binding.rb +49 -0
  398. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/body.rb +56 -0
  399. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/cgiStubCreator.rb +76 -0
  400. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/classDefCreator.rb +314 -0
  401. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/classDefCreatorSupport.rb +126 -0
  402. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/clientSkeltonCreator.rb +78 -0
  403. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/complexType.rb +161 -0
  404. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/data.rb +42 -0
  405. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/definitions.rb +149 -0
  406. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/driverCreator.rb +95 -0
  407. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/element.rb +28 -0
  408. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/fault.rb +56 -0
  409. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/header.rb +86 -0
  410. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/headerfault.rb +56 -0
  411. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/mappingRegistryCreator.rb +92 -0
  412. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/methodDefCreator.rb +228 -0
  413. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/operation.rb +122 -0
  414. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/servantSkeltonCreator.rb +67 -0
  415. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/standaloneServerStubCreator.rb +85 -0
  416. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/wsdl2ruby.rb +176 -0
  417. data/vendor/javascripts/emscripted-ruby/lib/wsdl/types.rb +43 -0
  418. data/vendor/javascripts/emscripted-ruby/lib/wsdl/wsdl.rb +23 -0
  419. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/all.rb +69 -0
  420. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/annotation.rb +34 -0
  421. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/any.rb +56 -0
  422. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/attribute.rb +127 -0
  423. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/choice.rb +69 -0
  424. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/complexContent.rb +92 -0
  425. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/complexType.rb +139 -0
  426. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/content.rb +96 -0
  427. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/data.rb +80 -0
  428. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/element.rb +154 -0
  429. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/enumeration.rb +36 -0
  430. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/import.rb +65 -0
  431. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/importer.rb +87 -0
  432. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/include.rb +54 -0
  433. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/length.rb +35 -0
  434. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/parser.rb +166 -0
  435. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/pattern.rb +36 -0
  436. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/schema.rb +143 -0
  437. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/sequence.rb +69 -0
  438. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleContent.rb +65 -0
  439. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleExtension.rb +54 -0
  440. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleRestriction.rb +73 -0
  441. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleType.rb +73 -0
  442. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/unique.rb +34 -0
  443. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/xsd2ruby.rb +107 -0
  444. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/.document +1 -0
  445. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/README.txt +31 -0
  446. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/base64.rb +81 -0
  447. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/client.rb +624 -0
  448. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/config.rb +40 -0
  449. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/create.rb +290 -0
  450. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/datetime.rb +142 -0
  451. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/httpserver.rb +178 -0
  452. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/marshal.rb +76 -0
  453. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/parser.rb +813 -0
  454. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/server.rb +780 -0
  455. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/utils.rb +165 -0
  456. data/vendor/javascripts/emscripted-ruby/lib/xsd/charset.rb +187 -0
  457. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen.rb +12 -0
  458. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/classdef.rb +203 -0
  459. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/commentdef.rb +34 -0
  460. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/gensupport.rb +166 -0
  461. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/methoddef.rb +63 -0
  462. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/moduledef.rb +191 -0
  463. data/vendor/javascripts/emscripted-ruby/lib/xsd/datatypes.rb +1269 -0
  464. data/vendor/javascripts/emscripted-ruby/lib/xsd/datatypes1999.rb +20 -0
  465. data/vendor/javascripts/emscripted-ruby/lib/xsd/iconvcharset.rb +33 -0
  466. data/vendor/javascripts/emscripted-ruby/lib/xsd/mapping.rb +42 -0
  467. data/vendor/javascripts/emscripted-ruby/lib/xsd/namedelements.rb +95 -0
  468. data/vendor/javascripts/emscripted-ruby/lib/xsd/ns.rb +140 -0
  469. data/vendor/javascripts/emscripted-ruby/lib/xsd/qname.rb +78 -0
  470. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser.rb +61 -0
  471. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/parser.rb +96 -0
  472. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/rexmlparser.rb +54 -0
  473. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/xmlparser.rb +50 -0
  474. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/xmlscanner.rb +147 -0
  475. data/vendor/javascripts/emscripted-ruby/lib/yaml.rb +440 -0
  476. data/vendor/javascripts/emscripted-ruby/lib/yaml/baseemitter.rb +247 -0
  477. data/vendor/javascripts/emscripted-ruby/lib/yaml/basenode.rb +216 -0
  478. data/vendor/javascripts/emscripted-ruby/lib/yaml/constants.rb +45 -0
  479. data/vendor/javascripts/emscripted-ruby/lib/yaml/dbm.rb +111 -0
  480. data/vendor/javascripts/emscripted-ruby/lib/yaml/encoding.rb +33 -0
  481. data/vendor/javascripts/emscripted-ruby/lib/yaml/error.rb +34 -0
  482. data/vendor/javascripts/emscripted-ruby/lib/yaml/loader.rb +14 -0
  483. data/vendor/javascripts/emscripted-ruby/lib/yaml/rubytypes.rb +408 -0
  484. data/vendor/javascripts/emscripted-ruby/lib/yaml/store.rb +43 -0
  485. data/vendor/javascripts/emscripted-ruby/lib/yaml/stream.rb +40 -0
  486. data/vendor/javascripts/emscripted-ruby/lib/yaml/stringio.rb +83 -0
  487. data/vendor/javascripts/emscripted-ruby/lib/yaml/syck.rb +19 -0
  488. data/vendor/javascripts/emscripted-ruby/lib/yaml/tag.rb +91 -0
  489. data/vendor/javascripts/emscripted-ruby/lib/yaml/types.rb +192 -0
  490. data/vendor/javascripts/emscripted-ruby/lib/yaml/yamlnode.rb +54 -0
  491. data/vendor/javascripts/emscripted-ruby/lib/yaml/ypath.rb +52 -0
  492. data/vendor/javascripts/emscripted-ruby/ruby.closure.js +7201 -0
  493. metadata +554 -0
@@ -0,0 +1,1782 @@
1
+ #
2
+ # = drb/drb.rb
3
+ #
4
+ # Distributed Ruby: _dRuby_ version 2.0.4
5
+ #
6
+ # Copyright (c) 1999-2003 Masatoshi SEKI. You can redistribute it and/or
7
+ # modify it under the same terms as Ruby.
8
+ #
9
+ # Author:: Masatoshi SEKI
10
+ #
11
+ # Documentation:: William Webber (william@williamwebber.com)
12
+ #
13
+ # == Overview
14
+ #
15
+ # dRuby is a distributed object system for Ruby. It allows an object in one
16
+ # Ruby process to invoke methods on an object in another Ruby process on the
17
+ # same or a different machine.
18
+ #
19
+ # The Ruby standard library contains the core classes of the dRuby package.
20
+ # However, the full package also includes access control lists and the
21
+ # Rinda tuple-space distributed task management system, as well as a
22
+ # large number of samples. The full dRuby package can be downloaded from
23
+ # the dRuby home page (see *References*).
24
+ #
25
+ # For an introduction and examples of usage see the documentation to the
26
+ # DRb module.
27
+ #
28
+ # == References
29
+ #
30
+ # [http://www2a.biglobe.ne.jp/~seki/ruby/druby.html]
31
+ # The dRuby home page, in Japanese. Contains the full dRuby package
32
+ # and links to other Japanese-language sources.
33
+ #
34
+ # [http://www2a.biglobe.ne.jp/~seki/ruby/druby.en.html]
35
+ # The English version of the dRuby home page.
36
+ #
37
+ # [http://www.chadfowler.com/ruby/drb.html]
38
+ # A quick tutorial introduction to using dRuby by Chad Fowler.
39
+ #
40
+ # [http://www.linux-mag.com/2002-09/ruby_05.html]
41
+ # A tutorial introduction to dRuby in Linux Magazine by Dave Thomas.
42
+ # Includes a discussion of Rinda.
43
+ #
44
+ # [http://www.eng.cse.dmu.ac.uk/~hgs/ruby/dRuby/]
45
+ # Links to English-language Ruby material collected by Hugh Sasse.
46
+ #
47
+ # [http://www.rubycentral.com/book/ospace.html]
48
+ # The chapter from *Programming* *Ruby* by Dave Thomas and Andy Hunt
49
+ # which discusses dRuby.
50
+ #
51
+ # [http://www.clio.ne.jp/home/web-i31s/Flotuard/Ruby/PRC2K_seki/dRuby.en.html]
52
+ # Translation of presentation on Ruby by Masatoshi Seki.
53
+
54
+ require 'socket'
55
+ require 'thread'
56
+ require 'fcntl'
57
+ require 'drb/eq'
58
+
59
+ #
60
+ # == Overview
61
+ #
62
+ # dRuby is a distributed object system for Ruby. It is written in
63
+ # pure Ruby and uses its own protocol. No add-in services are needed
64
+ # beyond those provided by the Ruby runtime, such as TCP sockets. It
65
+ # does not rely on or interoperate with other distributed object
66
+ # systems such as CORBA, RMI, or .NET.
67
+ #
68
+ # dRuby allows methods to be called in one Ruby process upon a Ruby
69
+ # object located in another Ruby process, even on another machine.
70
+ # References to objects can be passed between processes. Method
71
+ # arguments and return values are dumped and loaded in marshalled
72
+ # format. All of this is done transparently to both the caller of the
73
+ # remote method and the object that it is called upon.
74
+ #
75
+ # An object in a remote process is locally represented by a
76
+ # DRb::DRbObject instance. This acts as a sort of proxy for the
77
+ # remote object. Methods called upon this DRbObject instance are
78
+ # forwarded to its remote object. This is arranged dynamically at run
79
+ # time. There are no statically declared interfaces for remote
80
+ # objects, such as CORBA's IDL.
81
+ #
82
+ # dRuby calls made into a process are handled by a DRb::DRbServer
83
+ # instance within that process. This reconstitutes the method call,
84
+ # invokes it upon the specified local object, and returns the value to
85
+ # the remote caller. Any object can receive calls over dRuby. There
86
+ # is no need to implement a special interface, or mixin special
87
+ # functionality. Nor, in the general case, does an object need to
88
+ # explicitly register itself with a DRbServer in order to receive
89
+ # dRuby calls.
90
+ #
91
+ # One process wishing to make dRuby calls upon another process must
92
+ # somehow obtain an initial reference to an object in the remote
93
+ # process by some means other than as the return value of a remote
94
+ # method call, as there is initially no remote object reference it can
95
+ # invoke a method upon. This is done by attaching to the server by
96
+ # URI. Each DRbServer binds itself to a URI such as
97
+ # 'druby://example.com:8787'. A DRbServer can have an object attached
98
+ # to it that acts as the server's *front* *object*. A DRbObject can
99
+ # be explicitly created from the server's URI. This DRbObject's
100
+ # remote object will be the server's front object. This front object
101
+ # can then return references to other Ruby objects in the DRbServer's
102
+ # process.
103
+ #
104
+ # Method calls made over dRuby behave largely the same as normal Ruby
105
+ # method calls made within a process. Method calls with blocks are
106
+ # supported, as are raising exceptions. In addition to a method's
107
+ # standard errors, a dRuby call may also raise one of the
108
+ # dRuby-specific errors, all of which are subclasses of DRb::DRbError.
109
+ #
110
+ # Any type of object can be passed as an argument to a dRuby call or
111
+ # returned as its return value. By default, such objects are dumped
112
+ # or marshalled at the local end, then loaded or unmarshalled at the
113
+ # remote end. The remote end therefore receives a copy of the local
114
+ # object, not a distributed reference to it; methods invoked upon this
115
+ # copy are executed entirely in the remote process, not passed on to
116
+ # the local original. This has semantics similar to pass-by-value.
117
+ #
118
+ # However, if an object cannot be marshalled, a dRuby reference to it
119
+ # is passed or returned instead. This will turn up at the remote end
120
+ # as a DRbObject instance. All methods invoked upon this remote proxy
121
+ # are forwarded to the local object, as described in the discussion of
122
+ # DRbObjects. This has semantics similar to the normal Ruby
123
+ # pass-by-reference.
124
+ #
125
+ # The easiest way to signal that we want an otherwise marshallable
126
+ # object to be passed or returned as a DRbObject reference, rather
127
+ # than marshalled and sent as a copy, is to include the
128
+ # DRb::DRbUndumped mixin module.
129
+ #
130
+ # dRuby supports calling remote methods with blocks. As blocks (or
131
+ # rather the Proc objects that represent them) are not marshallable,
132
+ # the block executes in the local, not the remote, context. Each
133
+ # value yielded to the block is passed from the remote object to the
134
+ # local block, then the value returned by each block invocation is
135
+ # passed back to the remote execution context to be collected, before
136
+ # the collected values are finally returned to the local context as
137
+ # the return value of the method invocation.
138
+ #
139
+ # == Examples of usage
140
+ #
141
+ # For more dRuby samples, see the +samples+ directory in the full
142
+ # dRuby distribution.
143
+ #
144
+ # === dRuby in client/server mode
145
+ #
146
+ # This illustrates setting up a simple client-server drb
147
+ # system. Run the server and client code in different terminals,
148
+ # starting the server code first.
149
+ #
150
+ # ==== Server code
151
+ #
152
+ # require 'drb/drb'
153
+ #
154
+ # # The URI for the server to connect to
155
+ # URI="druby://localhost:8787"
156
+ #
157
+ # class TimeServer
158
+ #
159
+ # def get_current_time
160
+ # return Time.now
161
+ # end
162
+ #
163
+ # end
164
+ #
165
+ # # The object that handles requests on the server
166
+ # FRONT_OBJECT=TimeServer.new
167
+ #
168
+ # $SAFE = 1 # disable eval() and friends
169
+ #
170
+ # DRb.start_service(URI, FRONT_OBJECT)
171
+ # # Wait for the drb server thread to finish before exiting.
172
+ # DRb.thread.join
173
+ #
174
+ # ==== Client code
175
+ #
176
+ # require 'drb/drb'
177
+ #
178
+ # # The URI to connect to
179
+ # SERVER_URI="druby://localhost:8787"
180
+ #
181
+ # # Start a local DRbServer to handle callbacks.
182
+ # #
183
+ # # Not necessary for this small example, but will be required
184
+ # # as soon as we pass a non-marshallable object as an argument
185
+ # # to a dRuby call.
186
+ # DRb.start_service
187
+ #
188
+ # timeserver = DRbObject.new_with_uri(SERVER_URI)
189
+ # puts timeserver.get_current_time
190
+ #
191
+ # === Remote objects under dRuby
192
+ #
193
+ # This example illustrates returning a reference to an object
194
+ # from a dRuby call. The Logger instances live in the server
195
+ # process. References to them are returned to the client process,
196
+ # where methods can be invoked upon them. These methods are
197
+ # executed in the server process.
198
+ #
199
+ # ==== Server code
200
+ #
201
+ # require 'drb/drb'
202
+ #
203
+ # URI="druby://localhost:8787"
204
+ #
205
+ # class Logger
206
+ #
207
+ # # Make dRuby send Logger instances as dRuby references,
208
+ # # not copies.
209
+ # include DRb::DRbUndumped
210
+ #
211
+ # def initialize(n, fname)
212
+ # @name = n
213
+ # @filename = fname
214
+ # end
215
+ #
216
+ # def log(message)
217
+ # File.open(@filename, "a") do |f|
218
+ # f.puts("#{Time.now}: #{@name}: #{message}")
219
+ # end
220
+ # end
221
+ #
222
+ # end
223
+ #
224
+ # # We have a central object for creating and retrieving loggers.
225
+ # # This retains a local reference to all loggers created. This
226
+ # # is so an existing logger can be looked up by name, but also
227
+ # # to prevent loggers from being garbage collected. A dRuby
228
+ # # reference to an object is not sufficient to prevent it being
229
+ # # garbage collected!
230
+ # class LoggerFactory
231
+ #
232
+ # def initialize(bdir)
233
+ # @basedir = bdir
234
+ # @loggers = {}
235
+ # end
236
+ #
237
+ # def get_logger(name)
238
+ # if !@loggers.has_key? name
239
+ # # make the filename safe, then declare it to be so
240
+ # fname = name.gsub(/[.\/]/, "_").untaint
241
+ # @loggers[name] = Logger.new(name, @basedir + "/" + fname)
242
+ # end
243
+ # return @loggers[name]
244
+ # end
245
+ #
246
+ # end
247
+ #
248
+ # FRONT_OBJECT=LoggerFactory.new("/tmp/dlog")
249
+ #
250
+ # $SAFE = 1 # disable eval() and friends
251
+ #
252
+ # DRb.start_service(URI, FRONT_OBJECT)
253
+ # DRb.thread.join
254
+ #
255
+ # ==== Client code
256
+ #
257
+ # require 'drb/drb'
258
+ #
259
+ # SERVER_URI="druby://localhost:8787"
260
+ #
261
+ # DRb.start_service
262
+ #
263
+ # log_service=DRbObject.new_with_uri(SERVER_URI)
264
+ #
265
+ # ["loga", "logb", "logc"].each do |logname|
266
+ #
267
+ # logger=log_service.get_logger(logname)
268
+ #
269
+ # logger.log("Hello, world!")
270
+ # logger.log("Goodbye, world!")
271
+ # logger.log("=== EOT ===")
272
+ #
273
+ # end
274
+ #
275
+ # == Security
276
+ #
277
+ # As with all network services, security needs to be considered when
278
+ # using dRuby. By allowing external access to a Ruby object, you are
279
+ # not only allowing outside clients to call the methods you have
280
+ # defined for that object, but by default to execute arbitrary Ruby
281
+ # code on your server. Consider the following:
282
+ #
283
+ # # !!! UNSAFE CODE !!!
284
+ # ro = DRbObject::new_with_uri("druby://your.server.com:8989")
285
+ # class << ro
286
+ # undef :instance_eval # force call to be passed to remote object
287
+ # end
288
+ # ro.instance_eval("`rm -rf *`")
289
+ #
290
+ # The dangers posed by instance_eval and friends are such that a
291
+ # DRbServer should generally be run with $SAFE set to at least
292
+ # level 1. This will disable eval() and related calls on strings
293
+ # passed across the wire. The sample usage code given above follows
294
+ # this practice.
295
+ #
296
+ # A DRbServer can be configured with an access control list to
297
+ # selectively allow or deny access from specified IP addresses. The
298
+ # main druby distribution provides the ACL class for this purpose. In
299
+ # general, this mechanism should only be used alongside, rather than
300
+ # as a replacement for, a good firewall.
301
+ #
302
+ # == dRuby internals
303
+ #
304
+ # dRuby is implemented using three main components: a remote method
305
+ # call marshaller/unmarshaller; a transport protocol; and an
306
+ # ID-to-object mapper. The latter two can be directly, and the first
307
+ # indirectly, replaced, in order to provide different behaviour and
308
+ # capabilities.
309
+ #
310
+ # Marshalling and unmarshalling of remote method calls is performed by
311
+ # a DRb::DRbMessage instance. This uses the Marshal module to dump
312
+ # the method call before sending it over the transport layer, then
313
+ # reconstitute it at the other end. There is normally no need to
314
+ # replace this component, and no direct way is provided to do so.
315
+ # However, it is possible to implement an alternative marshalling
316
+ # scheme as part of an implementation of the transport layer.
317
+ #
318
+ # The transport layer is responsible for opening client and server
319
+ # network connections and forwarding dRuby request across them.
320
+ # Normally, it uses DRb::DRbMessage internally to manage marshalling
321
+ # and unmarshalling. The transport layer is managed by
322
+ # DRb::DRbProtocol. Multiple protocols can be installed in
323
+ # DRbProtocol at the one time; selection between them is determined by
324
+ # the scheme of a dRuby URI. The default transport protocol is
325
+ # selected by the scheme 'druby:', and implemented by
326
+ # DRb::DRbTCPSocket. This uses plain TCP/IP sockets for
327
+ # communication. An alternative protocol, using UNIX domain sockets,
328
+ # is implemented by DRb::DRbUNIXSocket in the file drb/unix.rb, and
329
+ # selected by the scheme 'drbunix:'. A sample implementation over
330
+ # HTTP can be found in the samples accompanying the main dRuby
331
+ # distribution.
332
+ #
333
+ # The ID-to-object mapping component maps dRuby object ids to the
334
+ # objects they refer to, and vice versa. The implementation to use
335
+ # can be specified as part of a DRb::DRbServer's configuration. The
336
+ # default implementation is provided by DRb::DRbIdConv. It uses an
337
+ # object's ObjectSpace id as its dRuby id. This means that the dRuby
338
+ # reference to that object only remains meaningful for the lifetime of
339
+ # the object's process and the lifetime of the object within that
340
+ # process. A modified implementation is provided by DRb::TimerIdConv
341
+ # in the file drb/timeridconv.rb. This implementation retains a local
342
+ # reference to all objects exported over dRuby for a configurable
343
+ # period of time (defaulting to ten minutes), to prevent them being
344
+ # garbage-collected within this time. Another sample implementation
345
+ # is provided in sample/name.rb in the main dRuby distribution. This
346
+ # allows objects to specify their own id or "name". A dRuby reference
347
+ # can be made persistent across processes by having each process
348
+ # register an object using the same dRuby name.
349
+ #
350
+ module DRb
351
+
352
+ # Superclass of all errors raised in the DRb module.
353
+ class DRbError < RuntimeError; end
354
+
355
+ # Error raised when an error occurs on the underlying communication
356
+ # protocol.
357
+ class DRbConnError < DRbError; end
358
+
359
+ # Class responsible for converting between an object and its id.
360
+ #
361
+ # This, the default implementation, uses an object's local ObjectSpace
362
+ # __id__ as its id. This means that an object's identification over
363
+ # drb remains valid only while that object instance remains alive
364
+ # within the server runtime.
365
+ #
366
+ # For alternative mechanisms, see DRb::TimerIdConv in rdb/timeridconv.rb
367
+ # and DRbNameIdConv in sample/name.rb in the full drb distribution.
368
+ class DRbIdConv
369
+
370
+ # Convert an object reference id to an object.
371
+ #
372
+ # This implementation looks up the reference id in the local object
373
+ # space and returns the object it refers to.
374
+ def to_obj(ref)
375
+ ObjectSpace._id2ref(ref)
376
+ end
377
+
378
+ # Convert an object into a reference id.
379
+ #
380
+ # This implementation returns the object's __id__ in the local
381
+ # object space.
382
+ def to_id(obj)
383
+ obj.nil? ? nil : obj.__id__
384
+ end
385
+ end
386
+
387
+ # Mixin module making an object undumpable or unmarshallable.
388
+ #
389
+ # If an object which includes this module is returned by method
390
+ # called over drb, then the object remains in the server space
391
+ # and a reference to the object is returned, rather than the
392
+ # object being marshalled and moved into the client space.
393
+ module DRbUndumped
394
+ def _dump(dummy) # :nodoc:
395
+ raise TypeError, 'can\'t dump'
396
+ end
397
+ end
398
+
399
+ # Error raised by the DRb module when an attempt is made to refer to
400
+ # the context's current drb server but the context does not have one.
401
+ # See #current_server.
402
+ class DRbServerNotFound < DRbError; end
403
+
404
+ # Error raised by the DRbProtocol module when it cannot find any
405
+ # protocol implementation support the scheme specified in a URI.
406
+ class DRbBadURI < DRbError; end
407
+
408
+ # Error raised by a dRuby protocol when it doesn't support the
409
+ # scheme specified in a URI. See DRb::DRbProtocol.
410
+ class DRbBadScheme < DRbError; end
411
+
412
+ # An exception wrapping a DRb::DRbUnknown object
413
+ class DRbUnknownError < DRbError
414
+
415
+ # Create a new DRbUnknownError for the DRb::DRbUnknown object +unknown+
416
+ def initialize(unknown)
417
+ @unknown = unknown
418
+ super(unknown.name)
419
+ end
420
+
421
+ # Get the wrapped DRb::DRbUnknown object.
422
+ attr_reader :unknown
423
+
424
+ def self._load(s) # :nodoc:
425
+ Marshal::load(s)
426
+ end
427
+
428
+ def _dump(lv) # :nodoc:
429
+ Marshal::dump(@unknown)
430
+ end
431
+ end
432
+
433
+ # An exception wrapping an error object
434
+ class DRbRemoteError < DRbError
435
+ def initialize(error)
436
+ @reason = error.class.to_s
437
+ super("#{error.message} (#{error.class})")
438
+ set_backtrace(error.backtrace)
439
+ end
440
+
441
+ # the class of the error, as a string.
442
+ attr_reader :reason
443
+ end
444
+
445
+ # Class wrapping a marshalled object whose type is unknown locally.
446
+ #
447
+ # If an object is returned by a method invoked over drb, but the
448
+ # class of the object is unknown in the client namespace, or
449
+ # the object is a constant unknown in the client namespace, then
450
+ # the still-marshalled object is returned wrapped in a DRbUnknown instance.
451
+ #
452
+ # If this object is passed as an argument to a method invoked over
453
+ # drb, then the wrapped object is passed instead.
454
+ #
455
+ # The class or constant name of the object can be read from the
456
+ # +name+ attribute. The marshalled object is held in the +buf+
457
+ # attribute.
458
+ class DRbUnknown
459
+
460
+ # Create a new DRbUnknown object.
461
+ #
462
+ # +buf+ is a string containing a marshalled object that could not
463
+ # be unmarshalled. +err+ is the error message that was raised
464
+ # when the unmarshalling failed. It is used to determine the
465
+ # name of the unmarshalled object.
466
+ def initialize(err, buf)
467
+ case err.to_s
468
+ when /uninitialized constant (\S+)/
469
+ @name = $1
470
+ when /undefined class\/module (\S+)/
471
+ @name = $1
472
+ else
473
+ @name = nil
474
+ end
475
+ @buf = buf
476
+ end
477
+
478
+ # The name of the unknown thing.
479
+ #
480
+ # Class name for unknown objects; variable name for unknown
481
+ # constants.
482
+ attr_reader :name
483
+
484
+ # Buffer contained the marshalled, unknown object.
485
+ attr_reader :buf
486
+
487
+ def self._load(s) # :nodoc:
488
+ begin
489
+ Marshal::load(s)
490
+ rescue NameError, ArgumentError
491
+ DRbUnknown.new($!, s)
492
+ end
493
+ end
494
+
495
+ def _dump(lv) # :nodoc:
496
+ @buf
497
+ end
498
+
499
+ # Attempt to load the wrapped marshalled object again.
500
+ #
501
+ # If the class of the object is now known locally, the object
502
+ # will be unmarshalled and returned. Otherwise, a new
503
+ # but identical DRbUnknown object will be returned.
504
+ def reload
505
+ self.class._load(@buf)
506
+ end
507
+
508
+ # Create a DRbUnknownError exception containing this object.
509
+ def exception
510
+ DRbUnknownError.new(self)
511
+ end
512
+ end
513
+
514
+ class DRbArray
515
+ def initialize(ary)
516
+ @ary = ary.collect { |obj|
517
+ if obj.kind_of? DRbUndumped
518
+ DRbObject.new(obj)
519
+ else
520
+ begin
521
+ Marshal.dump(obj)
522
+ obj
523
+ rescue
524
+ DRbObject.new(obj)
525
+ end
526
+ end
527
+ }
528
+ end
529
+
530
+ def self._load(s)
531
+ Marshal::load(s)
532
+ end
533
+
534
+ def _dump(lv)
535
+ Marshal.dump(@ary)
536
+ end
537
+ end
538
+
539
+ # Handler for sending and receiving drb messages.
540
+ #
541
+ # This takes care of the low-level marshalling and unmarshalling
542
+ # of drb requests and responses sent over the wire between server
543
+ # and client. This relieves the implementor of a new drb
544
+ # protocol layer with having to deal with these details.
545
+ #
546
+ # The user does not have to directly deal with this object in
547
+ # normal use.
548
+ class DRbMessage
549
+ def initialize(config) # :nodoc:
550
+ @load_limit = config[:load_limit]
551
+ @argc_limit = config[:argc_limit]
552
+ end
553
+
554
+ def dump(obj, error=false) # :nodoc:
555
+ obj = make_proxy(obj, error) if obj.kind_of? DRbUndumped
556
+ begin
557
+ str = Marshal::dump(obj)
558
+ rescue
559
+ str = Marshal::dump(make_proxy(obj, error))
560
+ end
561
+ [str.size].pack('N') + str
562
+ end
563
+
564
+ def load(soc) # :nodoc:
565
+ begin
566
+ sz = soc.read(4) # sizeof (N)
567
+ rescue
568
+ raise(DRbConnError, $!.message, $!.backtrace)
569
+ end
570
+ raise(DRbConnError, 'connection closed') if sz.nil?
571
+ raise(DRbConnError, 'premature header') if sz.size < 4
572
+ sz = sz.unpack('N')[0]
573
+ raise(DRbConnError, "too large packet #{sz}") if @load_limit < sz
574
+ begin
575
+ str = soc.read(sz)
576
+ rescue
577
+ raise(DRbConnError, $!.message, $!.backtrace)
578
+ end
579
+ raise(DRbConnError, 'connection closed') if str.nil?
580
+ raise(DRbConnError, 'premature marshal format(can\'t read)') if str.size < sz
581
+ DRb.mutex.synchronize do
582
+ begin
583
+ save = Thread.current[:drb_untaint]
584
+ Thread.current[:drb_untaint] = []
585
+ Marshal::load(str)
586
+ rescue NameError, ArgumentError
587
+ DRbUnknown.new($!, str)
588
+ ensure
589
+ Thread.current[:drb_untaint].each do |x|
590
+ x.untaint
591
+ end
592
+ Thread.current[:drb_untaint] = save
593
+ end
594
+ end
595
+ end
596
+
597
+ def send_request(stream, ref, msg_id, arg, b) # :nodoc:
598
+ ary = []
599
+ ary.push(dump(ref.__drbref))
600
+ ary.push(dump(msg_id.id2name))
601
+ ary.push(dump(arg.length))
602
+ arg.each do |e|
603
+ ary.push(dump(e))
604
+ end
605
+ ary.push(dump(b))
606
+ stream.write(ary.join(''))
607
+ rescue
608
+ raise(DRbConnError, $!.message, $!.backtrace)
609
+ end
610
+
611
+ def recv_request(stream) # :nodoc:
612
+ ref = load(stream)
613
+ ro = DRb.to_obj(ref)
614
+ msg = load(stream)
615
+ argc = load(stream)
616
+ raise ArgumentError, 'too many arguments' if @argc_limit < argc
617
+ argv = Array.new(argc, nil)
618
+ argc.times do |n|
619
+ argv[n] = load(stream)
620
+ end
621
+ block = load(stream)
622
+ return ro, msg, argv, block
623
+ end
624
+
625
+ def send_reply(stream, succ, result) # :nodoc:
626
+ stream.write(dump(succ) + dump(result, !succ))
627
+ rescue
628
+ raise(DRbConnError, $!.message, $!.backtrace)
629
+ end
630
+
631
+ def recv_reply(stream) # :nodoc:
632
+ succ = load(stream)
633
+ result = load(stream)
634
+ [succ, result]
635
+ end
636
+
637
+ private
638
+ def make_proxy(obj, error=false)
639
+ if error
640
+ DRbRemoteError.new(obj)
641
+ else
642
+ DRbObject.new(obj)
643
+ end
644
+ end
645
+ end
646
+
647
+ # Module managing the underlying network protocol(s) used by drb.
648
+ #
649
+ # By default, drb uses the DRbTCPSocket protocol. Other protocols
650
+ # can be defined. A protocol must define the following class methods:
651
+ #
652
+ # [open(uri, config)] Open a client connection to the server at +uri+,
653
+ # using configuration +config+. Return a protocol
654
+ # instance for this connection.
655
+ # [open_server(uri, config)] Open a server listening at +uri+,
656
+ # using configuration +config+. Return a
657
+ # protocol instance for this listener.
658
+ # [uri_option(uri, config)] Take a URI, possibly containing an option
659
+ # component (e.g. a trailing '?param=val'),
660
+ # and return a [uri, option] tuple.
661
+ #
662
+ # All of these methods should raise a DRbBadScheme error if the URI
663
+ # does not identify the protocol they support (e.g. "druby:" for
664
+ # the standard Ruby protocol). This is how the DRbProtocol module,
665
+ # given a URI, determines which protocol implementation serves that
666
+ # protocol.
667
+ #
668
+ # The protocol instance returned by #open_server must have the
669
+ # following methods:
670
+ #
671
+ # [accept] Accept a new connection to the server. Returns a protocol
672
+ # instance capable of communicating with the client.
673
+ # [close] Close the server connection.
674
+ # [uri] Get the URI for this server.
675
+ #
676
+ # The protocol instance returned by #open must have the following methods:
677
+ #
678
+ # [send_request (ref, msg_id, arg, b)]
679
+ # Send a request to +ref+ with the given message id and arguments.
680
+ # This is most easily implemented by calling DRbMessage.send_request,
681
+ # providing a stream that sits on top of the current protocol.
682
+ # [recv_reply]
683
+ # Receive a reply from the server and return it as a [success-boolean,
684
+ # reply-value] pair. This is most easily implemented by calling
685
+ # DRb.recv_reply, providing a stream that sits on top of the
686
+ # current protocol.
687
+ # [alive?]
688
+ # Is this connection still alive?
689
+ # [close]
690
+ # Close this connection.
691
+ #
692
+ # The protocol instance returned by #open_server().accept() must have
693
+ # the following methods:
694
+ #
695
+ # [recv_request]
696
+ # Receive a request from the client and return a [object, message,
697
+ # args, block] tuple. This is most easily implemented by calling
698
+ # DRbMessage.recv_request, providing a stream that sits on top of
699
+ # the current protocol.
700
+ # [send_reply(succ, result)]
701
+ # Send a reply to the client. This is most easily implemented
702
+ # by calling DRbMessage.send_reply, providing a stream that sits
703
+ # on top of the current protocol.
704
+ # [close]
705
+ # Close this connection.
706
+ #
707
+ # A new protocol is registered with the DRbProtocol module using
708
+ # the add_protocol method.
709
+ #
710
+ # For examples of other protocols, see DRbUNIXSocket in drb/unix.rb,
711
+ # and HTTP0 in sample/http0.rb and sample/http0serv.rb in the full
712
+ # drb distribution.
713
+ module DRbProtocol
714
+
715
+ # Add a new protocol to the DRbProtocol module.
716
+ def add_protocol(prot)
717
+ @protocol.push(prot)
718
+ end
719
+ module_function :add_protocol
720
+
721
+ # Open a client connection to +uri+ with the configuration +config+.
722
+ #
723
+ # The DRbProtocol module asks each registered protocol in turn to
724
+ # try to open the URI. Each protocol signals that it does not handle that
725
+ # URI by raising a DRbBadScheme error. If no protocol recognises the
726
+ # URI, then a DRbBadURI error is raised. If a protocol accepts the
727
+ # URI, but an error occurs in opening it, a DRbConnError is raised.
728
+ def open(uri, config, first=true)
729
+ @protocol.each do |prot|
730
+ begin
731
+ return prot.open(uri, config)
732
+ rescue DRbBadScheme
733
+ rescue DRbConnError
734
+ raise($!)
735
+ rescue
736
+ raise(DRbConnError, "#{uri} - #{$!.inspect}")
737
+ end
738
+ end
739
+ if first && (config[:auto_load] != false)
740
+ auto_load(uri, config)
741
+ return open(uri, config, false)
742
+ end
743
+ raise DRbBadURI, 'can\'t parse uri:' + uri
744
+ end
745
+ module_function :open
746
+
747
+ # Open a server listening for connections at +uri+ with
748
+ # configuration +config+.
749
+ #
750
+ # The DRbProtocol module asks each registered protocol in turn to
751
+ # try to open a server at the URI. Each protocol signals that it does
752
+ # not handle that URI by raising a DRbBadScheme error. If no protocol
753
+ # recognises the URI, then a DRbBadURI error is raised. If a protocol
754
+ # accepts the URI, but an error occurs in opening it, the underlying
755
+ # error is passed on to the caller.
756
+ def open_server(uri, config, first=true)
757
+ @protocol.each do |prot|
758
+ begin
759
+ return prot.open_server(uri, config)
760
+ rescue DRbBadScheme
761
+ end
762
+ end
763
+ if first && (config[:auto_load] != false)
764
+ auto_load(uri, config)
765
+ return open_server(uri, config, false)
766
+ end
767
+ raise DRbBadURI, 'can\'t parse uri:' + uri
768
+ end
769
+ module_function :open_server
770
+
771
+ # Parse +uri+ into a [uri, option] pair.
772
+ #
773
+ # The DRbProtocol module asks each registered protocol in turn to
774
+ # try to parse the URI. Each protocol signals that it does not handle that
775
+ # URI by raising a DRbBadScheme error. If no protocol recognises the
776
+ # URI, then a DRbBadURI error is raised.
777
+ def uri_option(uri, config, first=true)
778
+ @protocol.each do |prot|
779
+ begin
780
+ uri, opt = prot.uri_option(uri, config)
781
+ # opt = nil if opt == ''
782
+ return uri, opt
783
+ rescue DRbBadScheme
784
+ end
785
+ end
786
+ if first && (config[:auto_load] != false)
787
+ auto_load(uri, config)
788
+ return uri_option(uri, config, false)
789
+ end
790
+ raise DRbBadURI, 'can\'t parse uri:' + uri
791
+ end
792
+ module_function :uri_option
793
+
794
+ def auto_load(uri, config) # :nodoc:
795
+ if uri =~ /^drb([a-z0-9]+):/
796
+ require("drb/#{$1}") rescue nil
797
+ end
798
+ end
799
+ module_function :auto_load
800
+ end
801
+
802
+ # The default drb protocol.
803
+ #
804
+ # Communicates over a TCP socket.
805
+ class DRbTCPSocket
806
+ private
807
+ def self.parse_uri(uri)
808
+ if uri =~ /^druby:\/\/(.*?):(\d+)(\?(.*))?$/
809
+ host = $1
810
+ port = $2.to_i
811
+ option = $4
812
+ [host, port, option]
813
+ else
814
+ raise(DRbBadScheme, uri) unless uri =~ /^druby:/
815
+ raise(DRbBadURI, 'can\'t parse uri:' + uri)
816
+ end
817
+ end
818
+
819
+ public
820
+
821
+ # Open a client connection to +uri+ using configuration +config+.
822
+ def self.open(uri, config)
823
+ host, port, option = parse_uri(uri)
824
+ host.untaint
825
+ port.untaint
826
+ soc = TCPSocket.open(host, port)
827
+ self.new(uri, soc, config)
828
+ end
829
+
830
+ def self.getservername
831
+ host = Socket::gethostname
832
+ begin
833
+ Socket::gethostbyname(host)[0]
834
+ rescue
835
+ 'localhost'
836
+ end
837
+ end
838
+
839
+ def self.open_server_inaddr_any(host, port)
840
+ infos = Socket::getaddrinfo(host, nil,
841
+ Socket::AF_UNSPEC,
842
+ Socket::SOCK_STREAM,
843
+ 0,
844
+ Socket::AI_PASSIVE)
845
+ family = infos.collect { |af, *_| af }.uniq
846
+ case family
847
+ when ['AF_INET']
848
+ return TCPServer.open('0.0.0.0', port)
849
+ when ['AF_INET6']
850
+ return TCPServer.open('::', port)
851
+ else
852
+ return TCPServer.open(port)
853
+ end
854
+ end
855
+
856
+ # Open a server listening for connections at +uri+ using
857
+ # configuration +config+.
858
+ def self.open_server(uri, config)
859
+ uri = 'druby://:0' unless uri
860
+ host, port, opt = parse_uri(uri)
861
+ config = {:tcp_original_host => host}.update(config)
862
+ if host.size == 0
863
+ host = getservername
864
+ soc = open_server_inaddr_any(host, port)
865
+ else
866
+ soc = TCPServer.open(host, port)
867
+ end
868
+ port = soc.addr[1] if port == 0
869
+ config[:tcp_port] = port
870
+ uri = "druby://#{host}:#{port}"
871
+ self.new(uri, soc, config)
872
+ end
873
+
874
+ # Parse +uri+ into a [uri, option] pair.
875
+ def self.uri_option(uri, config)
876
+ host, port, option = parse_uri(uri)
877
+ return "druby://#{host}:#{port}", option
878
+ end
879
+
880
+ # Create a new DRbTCPSocket instance.
881
+ #
882
+ # +uri+ is the URI we are connected to.
883
+ # +soc+ is the tcp socket we are bound to. +config+ is our
884
+ # configuration.
885
+ def initialize(uri, soc, config={})
886
+ @uri = uri
887
+ @socket = soc
888
+ @config = config
889
+ @acl = config[:tcp_acl]
890
+ @msg = DRbMessage.new(config)
891
+ set_sockopt(@socket)
892
+ end
893
+
894
+ # Get the URI that we are connected to.
895
+ attr_reader :uri
896
+
897
+ # Get the address of our TCP peer (the other end of the socket
898
+ # we are bound to.
899
+ def peeraddr
900
+ @socket.peeraddr
901
+ end
902
+
903
+ # Get the socket.
904
+ def stream; @socket; end
905
+
906
+ # On the client side, send a request to the server.
907
+ def send_request(ref, msg_id, arg, b)
908
+ @msg.send_request(stream, ref, msg_id, arg, b)
909
+ end
910
+
911
+ # On the server side, receive a request from the client.
912
+ def recv_request
913
+ @msg.recv_request(stream)
914
+ end
915
+
916
+ # On the server side, send a reply to the client.
917
+ def send_reply(succ, result)
918
+ @msg.send_reply(stream, succ, result)
919
+ end
920
+
921
+ # On the client side, receive a reply from the server.
922
+ def recv_reply
923
+ @msg.recv_reply(stream)
924
+ end
925
+
926
+ public
927
+
928
+ # Close the connection.
929
+ #
930
+ # If this is an instance returned by #open_server, then this stops
931
+ # listening for new connections altogether. If this is an instance
932
+ # returned by #open or by #accept, then it closes this particular
933
+ # client-server session.
934
+ def close
935
+ if @socket
936
+ @socket.close
937
+ @socket = nil
938
+ end
939
+ end
940
+
941
+ # On the server side, for an instance returned by #open_server,
942
+ # accept a client connection and return a new instance to handle
943
+ # the server's side of this client-server session.
944
+ def accept
945
+ while true
946
+ s = @socket.accept
947
+ break if (@acl ? @acl.allow_socket?(s) : true)
948
+ s.close
949
+ end
950
+ if @config[:tcp_original_host].to_s.size == 0
951
+ uri = "druby://#{s.addr[3]}:#{@config[:tcp_port]}"
952
+ else
953
+ uri = @uri
954
+ end
955
+ self.class.new(uri, s, @config)
956
+ end
957
+
958
+ # Check to see if this connection is alive.
959
+ def alive?
960
+ return false unless @socket
961
+ if IO.select([@socket], nil, nil, 0)
962
+ close
963
+ return false
964
+ end
965
+ true
966
+ end
967
+
968
+ def set_sockopt(soc) # :nodoc:
969
+ soc.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
970
+ soc.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
971
+ end
972
+ end
973
+
974
+ module DRbProtocol
975
+ @protocol = [DRbTCPSocket] # default
976
+ end
977
+
978
+ class DRbURIOption # :nodoc: I don't understand the purpose of this class...
979
+ def initialize(option)
980
+ @option = option.to_s
981
+ end
982
+ attr :option
983
+ def to_s; @option; end
984
+
985
+ def ==(other)
986
+ return false unless DRbURIOption === other
987
+ @option == other.option
988
+ end
989
+
990
+ def hash
991
+ @option.hash
992
+ end
993
+
994
+ alias eql? ==
995
+ end
996
+
997
+ # Object wrapping a reference to a remote drb object.
998
+ #
999
+ # Method calls on this object are relayed to the remote
1000
+ # object that this object is a stub for.
1001
+ class DRbObject
1002
+
1003
+ # Unmarshall a marshalled DRbObject.
1004
+ #
1005
+ # If the referenced object is located within the local server, then
1006
+ # the object itself is returned. Otherwise, a new DRbObject is
1007
+ # created to act as a stub for the remote referenced object.
1008
+ def self._load(s)
1009
+ uri, ref = Marshal.load(s)
1010
+
1011
+ if DRb.here?(uri)
1012
+ obj = DRb.to_obj(ref)
1013
+ if ((! obj.tainted?) && Thread.current[:drb_untaint])
1014
+ Thread.current[:drb_untaint].push(obj)
1015
+ end
1016
+ return obj
1017
+ end
1018
+
1019
+ self.new_with(uri, ref)
1020
+ end
1021
+
1022
+ def self.new_with(uri, ref)
1023
+ it = self.allocate
1024
+ it.instance_variable_set('@uri', uri)
1025
+ it.instance_variable_set('@ref', ref)
1026
+ it
1027
+ end
1028
+
1029
+ # Create a new DRbObject from a URI alone.
1030
+ def self.new_with_uri(uri)
1031
+ self.new(nil, uri)
1032
+ end
1033
+
1034
+ # Marshall this object.
1035
+ #
1036
+ # The URI and ref of the object are marshalled.
1037
+ def _dump(lv)
1038
+ Marshal.dump([@uri, @ref])
1039
+ end
1040
+
1041
+ # Create a new remote object stub.
1042
+ #
1043
+ # +obj+ is the (local) object we want to create a stub for. Normally
1044
+ # this is +nil+. +uri+ is the URI of the remote object that this
1045
+ # will be a stub for.
1046
+ def initialize(obj, uri=nil)
1047
+ @uri = nil
1048
+ @ref = nil
1049
+ if obj.nil?
1050
+ return if uri.nil?
1051
+ @uri, option = DRbProtocol.uri_option(uri, DRb.config)
1052
+ @ref = DRbURIOption.new(option) unless option.nil?
1053
+ else
1054
+ @uri = uri ? uri : (DRb.uri rescue nil)
1055
+ @ref = obj ? DRb.to_id(obj) : nil
1056
+ end
1057
+ end
1058
+
1059
+ # Get the URI of the remote object.
1060
+ def __drburi
1061
+ @uri
1062
+ end
1063
+
1064
+ # Get the reference of the object, if local.
1065
+ def __drbref
1066
+ @ref
1067
+ end
1068
+
1069
+ undef :to_s
1070
+ undef :to_a if respond_to?(:to_a)
1071
+
1072
+ def respond_to?(msg_id, priv=false)
1073
+ case msg_id
1074
+ when :_dump
1075
+ true
1076
+ when :marshal_dump
1077
+ false
1078
+ else
1079
+ method_missing(:respond_to?, msg_id, priv)
1080
+ end
1081
+ end
1082
+
1083
+ # Routes method calls to the referenced object.
1084
+ def method_missing(msg_id, *a, &b)
1085
+ if DRb.here?(@uri)
1086
+ obj = DRb.to_obj(@ref)
1087
+ DRb.current_server.check_insecure_method(obj, msg_id)
1088
+ return obj.__send__(msg_id, *a, &b)
1089
+ end
1090
+
1091
+ succ, result = self.class.with_friend(@uri) do
1092
+ DRbConn.open(@uri) do |conn|
1093
+ conn.send_message(self, msg_id, a, b)
1094
+ end
1095
+ end
1096
+
1097
+ if succ
1098
+ return result
1099
+ elsif DRbUnknown === result
1100
+ raise result
1101
+ else
1102
+ bt = self.class.prepare_backtrace(@uri, result)
1103
+ result.set_backtrace(bt + caller)
1104
+ raise result
1105
+ end
1106
+ end
1107
+
1108
+ def self.with_friend(uri)
1109
+ friend = DRb.fetch_server(uri)
1110
+ return yield() unless friend
1111
+
1112
+ save = Thread.current['DRb']
1113
+ Thread.current['DRb'] = { 'server' => friend }
1114
+ return yield
1115
+ ensure
1116
+ Thread.current['DRb'] = save if friend
1117
+ end
1118
+
1119
+ def self.prepare_backtrace(uri, result)
1120
+ prefix = "(#{uri}) "
1121
+ bt = []
1122
+ result.backtrace.each do |x|
1123
+ break if /`__send__'$/ =~ x
1124
+ if /^\(druby:\/\// =~ x
1125
+ bt.push(x)
1126
+ else
1127
+ bt.push(prefix + x)
1128
+ end
1129
+ end
1130
+ bt
1131
+ end
1132
+
1133
+ def pretty_print(q) # :nodoc:
1134
+ q.pp_object(self)
1135
+ end
1136
+
1137
+ def pretty_print_cycle(q) # :nodoc:
1138
+ q.object_address_group(self) {
1139
+ q.breakable
1140
+ q.text '...'
1141
+ }
1142
+ end
1143
+ end
1144
+
1145
+ # Class handling the connection between a DRbObject and the
1146
+ # server the real object lives on.
1147
+ #
1148
+ # This class maintains a pool of connections, to reduce the
1149
+ # overhead of starting and closing down connections for each
1150
+ # method call.
1151
+ #
1152
+ # This class is used internally by DRbObject. The user does
1153
+ # not normally need to deal with it directly.
1154
+ class DRbConn
1155
+ POOL_SIZE = 16 # :nodoc:
1156
+ @mutex = Mutex.new
1157
+ @pool = []
1158
+
1159
+ def self.open(remote_uri) # :nodoc:
1160
+ begin
1161
+ conn = nil
1162
+
1163
+ @mutex.synchronize do
1164
+ #FIXME
1165
+ new_pool = []
1166
+ @pool.each do |c|
1167
+ if conn.nil? and c.uri == remote_uri
1168
+ conn = c if c.alive?
1169
+ else
1170
+ new_pool.push c
1171
+ end
1172
+ end
1173
+ @pool = new_pool
1174
+ end
1175
+
1176
+ conn = self.new(remote_uri) unless conn
1177
+ succ, result = yield(conn)
1178
+ return succ, result
1179
+
1180
+ ensure
1181
+ if conn
1182
+ if succ
1183
+ @mutex.synchronize do
1184
+ @pool.unshift(conn)
1185
+ @pool.pop.close while @pool.size > POOL_SIZE
1186
+ end
1187
+ else
1188
+ conn.close
1189
+ end
1190
+ end
1191
+ end
1192
+ end
1193
+
1194
+ def initialize(remote_uri) # :nodoc:
1195
+ @uri = remote_uri
1196
+ @protocol = DRbProtocol.open(remote_uri, DRb.config)
1197
+ end
1198
+ attr_reader :uri # :nodoc:
1199
+
1200
+ def send_message(ref, msg_id, arg, block) # :nodoc:
1201
+ @protocol.send_request(ref, msg_id, arg, block)
1202
+ @protocol.recv_reply
1203
+ end
1204
+
1205
+ def close # :nodoc:
1206
+ @protocol.close
1207
+ @protocol = nil
1208
+ end
1209
+
1210
+ def alive? # :nodoc:
1211
+ @protocol.alive?
1212
+ end
1213
+ end
1214
+
1215
+ # Class representing a drb server instance.
1216
+ #
1217
+ # A DRbServer must be running in the local process before any incoming
1218
+ # dRuby calls can be accepted, or any local objects can be passed as
1219
+ # dRuby references to remote processes, even if those local objects are
1220
+ # never actually called remotely. You do not need to start a DRbServer
1221
+ # in the local process if you are only making outgoing dRuby calls
1222
+ # passing marshalled parameters.
1223
+ #
1224
+ # Unless multiple servers are being used, the local DRbServer is normally
1225
+ # started by calling DRb.start_service.
1226
+ class DRbServer
1227
+ @@acl = nil
1228
+ @@idconv = DRbIdConv.new
1229
+ @@secondary_server = nil
1230
+ @@argc_limit = 256
1231
+ @@load_limit = 256 * 102400
1232
+ @@verbose = false
1233
+ @@safe_level = 0
1234
+
1235
+ # Set the default value for the :argc_limit option.
1236
+ #
1237
+ # See #new(). The initial default value is 256.
1238
+ def self.default_argc_limit(argc)
1239
+ @@argc_limit = argc
1240
+ end
1241
+
1242
+ # Set the default value for the :load_limit option.
1243
+ #
1244
+ # See #new(). The initial default value is 25 MB.
1245
+ def self.default_load_limit(sz)
1246
+ @@load_limit = sz
1247
+ end
1248
+
1249
+ # Set the default value for the :acl option.
1250
+ #
1251
+ # See #new(). The initial default value is nil.
1252
+ def self.default_acl(acl)
1253
+ @@acl = acl
1254
+ end
1255
+
1256
+ # Set the default value for the :id_conv option.
1257
+ #
1258
+ # See #new(). The initial default value is a DRbIdConv instance.
1259
+ def self.default_id_conv(idconv)
1260
+ @@idconv = idconv
1261
+ end
1262
+
1263
+ def self.default_safe_level(level)
1264
+ @@safe_level = level
1265
+ end
1266
+
1267
+ # Set the default value of the :verbose option.
1268
+ #
1269
+ # See #new(). The initial default value is false.
1270
+ def self.verbose=(on)
1271
+ @@verbose = on
1272
+ end
1273
+
1274
+ # Get the default value of the :verbose option.
1275
+ def self.verbose
1276
+ @@verbose
1277
+ end
1278
+
1279
+ def self.make_config(hash={}) # :nodoc:
1280
+ default_config = {
1281
+ :idconv => @@idconv,
1282
+ :verbose => @@verbose,
1283
+ :tcp_acl => @@acl,
1284
+ :load_limit => @@load_limit,
1285
+ :argc_limit => @@argc_limit,
1286
+ :safe_level => @@safe_level
1287
+ }
1288
+ default_config.update(hash)
1289
+ end
1290
+
1291
+ # Create a new DRbServer instance.
1292
+ #
1293
+ # +uri+ is the URI to bind to. This is normally of the form
1294
+ # 'druby://<hostname>:<port>' where <hostname> is a hostname of
1295
+ # the local machine. If nil, then the system's default hostname
1296
+ # will be bound to, on a port selected by the system; these value
1297
+ # can be retrieved from the +uri+ attribute. 'druby:' specifies
1298
+ # the default dRuby transport protocol: another protocol, such
1299
+ # as 'drbunix:', can be specified instead.
1300
+ #
1301
+ # +front+ is the front object for the server, that is, the object
1302
+ # to which remote method calls on the server will be passed. If
1303
+ # nil, then the server will not accept remote method calls.
1304
+ #
1305
+ # If +config_or_acl+ is a hash, it is the configuration to
1306
+ # use for this server. The following options are recognised:
1307
+ #
1308
+ # :idconv :: an id-to-object conversion object. This defaults
1309
+ # to an instance of the class DRb::DRbIdConv.
1310
+ # :verbose :: if true, all unsuccessful remote calls on objects
1311
+ # in the server will be logged to $stdout. false
1312
+ # by default.
1313
+ # :tcp_acl :: the access control list for this server. See
1314
+ # the ACL class from the main dRuby distribution.
1315
+ # :load_limit :: the maximum message size in bytes accepted by
1316
+ # the server. Defaults to 25 MB (26214400).
1317
+ # :argc_limit :: the maximum number of arguments to a remote
1318
+ # method accepted by the server. Defaults to
1319
+ # 256.
1320
+ #
1321
+ # The default values of these options can be modified on
1322
+ # a class-wide basis by the class methods #default_argc_limit,
1323
+ # #default_load_limit, #default_acl, #default_id_conv,
1324
+ # and #verbose=
1325
+ #
1326
+ # If +config_or_acl+ is not a hash, but is not nil, it is
1327
+ # assumed to be the access control list for this server.
1328
+ # See the :tcp_acl option for more details.
1329
+ #
1330
+ # If no other server is currently set as the primary server,
1331
+ # this will become the primary server.
1332
+ #
1333
+ # The server will immediately start running in its own thread.
1334
+ def initialize(uri=nil, front=nil, config_or_acl=nil)
1335
+ if Hash === config_or_acl
1336
+ config = config_or_acl.dup
1337
+ else
1338
+ acl = config_or_acl || @@acl
1339
+ config = {
1340
+ :tcp_acl => acl
1341
+ }
1342
+ end
1343
+
1344
+ @config = self.class.make_config(config)
1345
+
1346
+ @protocol = DRbProtocol.open_server(uri, @config)
1347
+ @uri = @protocol.uri
1348
+
1349
+ @front = front
1350
+ @idconv = @config[:idconv]
1351
+ @safe_level = @config[:safe_level]
1352
+
1353
+ @grp = ThreadGroup.new
1354
+ @thread = run
1355
+
1356
+ DRb.regist_server(self)
1357
+ end
1358
+
1359
+ # The URI of this DRbServer.
1360
+ attr_reader :uri
1361
+
1362
+ # The main thread of this DRbServer.
1363
+ #
1364
+ # This is the thread that listens for and accepts connections
1365
+ # from clients, not that handles each client's request-response
1366
+ # session.
1367
+ attr_reader :thread
1368
+
1369
+ # The front object of the DRbServer.
1370
+ #
1371
+ # This object receives remote method calls made on the server's
1372
+ # URI alone, with an object id.
1373
+ attr_reader :front
1374
+
1375
+ # The configuration of this DRbServer
1376
+ attr_reader :config
1377
+
1378
+ attr_reader :safe_level
1379
+
1380
+ # Set whether to operate in verbose mode.
1381
+ #
1382
+ # In verbose mode, failed calls are logged to stdout.
1383
+ def verbose=(v); @config[:verbose]=v; end
1384
+
1385
+ # Get whether the server is in verbose mode.
1386
+ #
1387
+ # In verbose mode, failed calls are logged to stdout.
1388
+ def verbose; @config[:verbose]; end
1389
+
1390
+ # Is this server alive?
1391
+ def alive?
1392
+ @thread.alive?
1393
+ end
1394
+
1395
+ # Stop this server.
1396
+ def stop_service
1397
+ DRb.remove_server(self)
1398
+ if Thread.current['DRb'] && Thread.current['DRb']['server'] == self
1399
+ Thread.current['DRb']['stop_service'] = true
1400
+ else
1401
+ @thread.kill
1402
+ end
1403
+ end
1404
+
1405
+ # Convert a dRuby reference to the local object it refers to.
1406
+ def to_obj(ref)
1407
+ return front if ref.nil?
1408
+ return front[ref.to_s] if DRbURIOption === ref
1409
+ @idconv.to_obj(ref)
1410
+ end
1411
+
1412
+ # Convert a local object to a dRuby reference.
1413
+ def to_id(obj)
1414
+ return nil if obj.__id__ == front.__id__
1415
+ @idconv.to_id(obj)
1416
+ end
1417
+
1418
+ private
1419
+ def kill_sub_thread
1420
+ Thread.new do
1421
+ grp = ThreadGroup.new
1422
+ grp.add(Thread.current)
1423
+ list = @grp.list
1424
+ while list.size > 0
1425
+ list.each do |th|
1426
+ th.kill if th.alive?
1427
+ end
1428
+ list = @grp.list
1429
+ end
1430
+ end
1431
+ end
1432
+
1433
+ def run
1434
+ Thread.start do
1435
+ begin
1436
+ while true
1437
+ main_loop
1438
+ end
1439
+ ensure
1440
+ @protocol.close if @protocol
1441
+ kill_sub_thread
1442
+ end
1443
+ end
1444
+ end
1445
+
1446
+ # List of insecure methods.
1447
+ #
1448
+ # These methods are not callable via dRuby.
1449
+ INSECURE_METHOD = [
1450
+ :__send__
1451
+ ]
1452
+
1453
+ # Has a method been included in the list of insecure methods?
1454
+ def insecure_method?(msg_id)
1455
+ INSECURE_METHOD.include?(msg_id)
1456
+ end
1457
+
1458
+ # Coerce an object to a string, providing our own representation if
1459
+ # to_s is not defined for the object.
1460
+ def any_to_s(obj)
1461
+ obj.to_s + ":#{obj.class}"
1462
+ rescue
1463
+ sprintf("#<%s:0x%lx>", obj.class, obj.__id__)
1464
+ end
1465
+
1466
+ # Check that a method is callable via dRuby.
1467
+ #
1468
+ # +obj+ is the object we want to invoke the method on. +msg_id+ is the
1469
+ # method name, as a Symbol.
1470
+ #
1471
+ # If the method is an insecure method (see #insecure_method?) a
1472
+ # SecurityError is thrown. If the method is private or undefined,
1473
+ # a NameError is thrown.
1474
+ def check_insecure_method(obj, msg_id)
1475
+ return true if Proc === obj && msg_id == :__drb_yield
1476
+ raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
1477
+ raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
1478
+
1479
+ if obj.private_methods.include?(msg_id.to_s)
1480
+ desc = any_to_s(obj)
1481
+ raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
1482
+ elsif obj.protected_methods.include?(msg_id.to_s)
1483
+ desc = any_to_s(obj)
1484
+ raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
1485
+ else
1486
+ true
1487
+ end
1488
+ end
1489
+ public :check_insecure_method
1490
+
1491
+ class InvokeMethod # :nodoc:
1492
+ def initialize(drb_server, client)
1493
+ @drb_server = drb_server
1494
+ @safe_level = drb_server.safe_level
1495
+ @client = client
1496
+ end
1497
+
1498
+ def perform
1499
+ @result = nil
1500
+ @succ = false
1501
+ setup_message
1502
+
1503
+ if $SAFE < @safe_level
1504
+ info = Thread.current['DRb']
1505
+ if @block
1506
+ @result = Thread.new {
1507
+ Thread.current['DRb'] = info
1508
+ $SAFE = @safe_level
1509
+ perform_with_block
1510
+ }.value
1511
+ else
1512
+ @result = Thread.new {
1513
+ Thread.current['DRb'] = info
1514
+ $SAFE = @safe_level
1515
+ perform_without_block
1516
+ }.value
1517
+ end
1518
+ else
1519
+ if @block
1520
+ @result = perform_with_block
1521
+ else
1522
+ @result = perform_without_block
1523
+ end
1524
+ end
1525
+ @succ = true
1526
+ if @msg_id == :to_ary && @result.class == Array
1527
+ @result = DRbArray.new(@result)
1528
+ end
1529
+ return @succ, @result
1530
+ rescue StandardError, ScriptError, Interrupt
1531
+ @result = $!
1532
+ return @succ, @result
1533
+ end
1534
+
1535
+ private
1536
+ def init_with_client
1537
+ obj, msg, argv, block = @client.recv_request
1538
+ @obj = obj
1539
+ @msg_id = msg.intern
1540
+ @argv = argv
1541
+ @block = block
1542
+ end
1543
+
1544
+ def check_insecure_method
1545
+ @drb_server.check_insecure_method(@obj, @msg_id)
1546
+ end
1547
+
1548
+ def setup_message
1549
+ init_with_client
1550
+ check_insecure_method
1551
+ end
1552
+
1553
+ def perform_without_block
1554
+ if Proc === @obj && @msg_id == :__drb_yield
1555
+ if @argv.size == 1
1556
+ ary = @argv
1557
+ else
1558
+ ary = [@argv]
1559
+ end
1560
+ ary.collect(&@obj)[0]
1561
+ else
1562
+ @obj.__send__(@msg_id, *@argv)
1563
+ end
1564
+ end
1565
+
1566
+ end
1567
+
1568
+ if RUBY_VERSION >= '1.8'
1569
+ require 'drb/invokemethod'
1570
+ class InvokeMethod
1571
+ include InvokeMethod18Mixin
1572
+ end
1573
+ else
1574
+ require 'drb/invokemethod16'
1575
+ class InvokeMethod
1576
+ include InvokeMethod16Mixin
1577
+ end
1578
+ end
1579
+
1580
+ # The main loop performed by a DRbServer's internal thread.
1581
+ #
1582
+ # Accepts a connection from a client, and starts up its own
1583
+ # thread to handle it. This thread loops, receiving requests
1584
+ # from the client, invoking them on a local object, and
1585
+ # returning responses, until the client closes the connection
1586
+ # or a local method call fails.
1587
+ def main_loop
1588
+ Thread.start(@protocol.accept) do |client|
1589
+ @grp.add Thread.current
1590
+ Thread.current['DRb'] = { 'client' => client ,
1591
+ 'server' => self }
1592
+ loop do
1593
+ begin
1594
+ succ = false
1595
+ invoke_method = InvokeMethod.new(self, client)
1596
+ succ, result = invoke_method.perform
1597
+ if !succ && verbose
1598
+ p result
1599
+ result.backtrace.each do |x|
1600
+ puts x
1601
+ end
1602
+ end
1603
+ client.send_reply(succ, result) rescue nil
1604
+ ensure
1605
+ client.close unless succ
1606
+ if Thread.current['DRb']['stop_service']
1607
+ Thread.new { stop_service }
1608
+ end
1609
+ break unless succ
1610
+ end
1611
+ end
1612
+ end
1613
+ end
1614
+ end
1615
+
1616
+ @primary_server = nil
1617
+
1618
+ # Start a dRuby server locally.
1619
+ #
1620
+ # The new dRuby server will become the primary server, even
1621
+ # if another server is currently the primary server.
1622
+ #
1623
+ # +uri+ is the URI for the server to bind to. If nil,
1624
+ # the server will bind to random port on the default local host
1625
+ # name and use the default dRuby protocol.
1626
+ #
1627
+ # +front+ is the server's front object. This may be nil.
1628
+ #
1629
+ # +config+ is the configuration for the new server. This may
1630
+ # be nil.
1631
+ #
1632
+ # See DRbServer::new.
1633
+ def start_service(uri=nil, front=nil, config=nil)
1634
+ @primary_server = DRbServer.new(uri, front, config)
1635
+ end
1636
+ module_function :start_service
1637
+
1638
+ # The primary local dRuby server.
1639
+ #
1640
+ # This is the server created by the #start_service call.
1641
+ attr_accessor :primary_server
1642
+ module_function :primary_server=, :primary_server
1643
+
1644
+ # Get the 'current' server.
1645
+ #
1646
+ # In the context of execution taking place within the main
1647
+ # thread of a dRuby server (typically, as a result of a remote
1648
+ # call on the server or one of its objects), the current
1649
+ # server is that server. Otherwise, the current server is
1650
+ # the primary server.
1651
+ #
1652
+ # If the above rule fails to find a server, a DRbServerNotFound
1653
+ # error is raised.
1654
+ def current_server
1655
+ drb = Thread.current['DRb']
1656
+ server = (drb && drb['server']) ? drb['server'] : @primary_server
1657
+ raise DRbServerNotFound unless server
1658
+ return server
1659
+ end
1660
+ module_function :current_server
1661
+
1662
+ # Stop the local dRuby server.
1663
+ #
1664
+ # This operates on the primary server. If there is no primary
1665
+ # server currently running, it is a noop.
1666
+ def stop_service
1667
+ @primary_server.stop_service if @primary_server
1668
+ @primary_server = nil
1669
+ end
1670
+ module_function :stop_service
1671
+
1672
+ # Get the URI defining the local dRuby space.
1673
+ #
1674
+ # This is the URI of the current server. See #current_server.
1675
+ def uri
1676
+ drb = Thread.current['DRb']
1677
+ client = (drb && drb['client'])
1678
+ if client
1679
+ uri = client.uri
1680
+ return uri if uri
1681
+ end
1682
+ current_server.uri
1683
+ end
1684
+ module_function :uri
1685
+
1686
+ # Is +uri+ the URI for the current local server?
1687
+ def here?(uri)
1688
+ (current_server.uri rescue nil) == uri
1689
+ end
1690
+ module_function :here?
1691
+
1692
+ # Get the configuration of the current server.
1693
+ #
1694
+ # If there is no current server, this returns the default configuration.
1695
+ # See #current_server and DRbServer::make_config.
1696
+ def config
1697
+ current_server.config
1698
+ rescue
1699
+ DRbServer.make_config
1700
+ end
1701
+ module_function :config
1702
+
1703
+ # Get the front object of the current server.
1704
+ #
1705
+ # This raises a DRbServerNotFound error if there is no current server.
1706
+ # See #current_server.
1707
+ def front
1708
+ current_server.front
1709
+ end
1710
+ module_function :front
1711
+
1712
+ # Convert a reference into an object using the current server.
1713
+ #
1714
+ # This raises a DRbServerNotFound error if there is no current server.
1715
+ # See #current_server.
1716
+ def to_obj(ref)
1717
+ current_server.to_obj(ref)
1718
+ end
1719
+
1720
+ # Get a reference id for an object using the current server.
1721
+ #
1722
+ # This raises a DRbServerNotFound error if there is no current server.
1723
+ # See #current_server.
1724
+ def to_id(obj)
1725
+ current_server.to_id(obj)
1726
+ end
1727
+ module_function :to_id
1728
+ module_function :to_obj
1729
+
1730
+ # Get the thread of the primary server.
1731
+ #
1732
+ # This returns nil if there is no primary server. See #primary_server.
1733
+ def thread
1734
+ @primary_server ? @primary_server.thread : nil
1735
+ end
1736
+ module_function :thread
1737
+
1738
+ # Set the default id conv object.
1739
+ #
1740
+ # See DRbServer#default_id_conv.
1741
+ def install_id_conv(idconv)
1742
+ DRbServer.default_id_conv(idconv)
1743
+ end
1744
+ module_function :install_id_conv
1745
+
1746
+ # Set the default acl.
1747
+ #
1748
+ # See DRb::DRbServer.default_acl.
1749
+ def install_acl(acl)
1750
+ DRbServer.default_acl(acl)
1751
+ end
1752
+ module_function :install_acl
1753
+
1754
+ @mutex = Mutex.new
1755
+ def mutex
1756
+ @mutex
1757
+ end
1758
+ module_function :mutex
1759
+
1760
+ @server = {}
1761
+ def regist_server(server)
1762
+ @server[server.uri] = server
1763
+ mutex.synchronize do
1764
+ @primary_server = server unless @primary_server
1765
+ end
1766
+ end
1767
+ module_function :regist_server
1768
+
1769
+ def remove_server(server)
1770
+ @server.delete(server.uri)
1771
+ end
1772
+ module_function :remove_server
1773
+
1774
+ def fetch_server(uri)
1775
+ @server[uri]
1776
+ end
1777
+ module_function :fetch_server
1778
+ end
1779
+
1780
+ DRbObject = DRb::DRbObject
1781
+ DRbUndumped = DRb::DRbUndumped
1782
+ DRbIdConv = DRb::DRbIdConv