shoesgem 0.1424.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (808) hide show
  1. data/LICENSE +30 -0
  2. data/README.rdoc +31 -0
  3. data/lib/shoes.rb +4 -0
  4. data/shoes/CHANGELOG.txt +21 -0
  5. data/shoes/COPYING.txt +30 -0
  6. data/shoes/README.txt +117 -0
  7. data/shoes/VERSION.txt +1 -0
  8. data/shoes/fonts/Coolvetica.ttf +0 -0
  9. data/shoes/fonts/Lacuna.ttf +0 -0
  10. data/shoes/freetype6.dll +0 -0
  11. data/shoes/lib/shoes/cache.rb +54 -0
  12. data/shoes/lib/shoes/data.rb +39 -0
  13. data/shoes/lib/shoes/help.rb +421 -0
  14. data/shoes/lib/shoes/image.rb +25 -0
  15. data/shoes/lib/shoes/inspect.rb +128 -0
  16. data/shoes/lib/shoes/log.rb +48 -0
  17. data/shoes/lib/shoes/minitar.rb +986 -0
  18. data/shoes/lib/shoes/override.rb +38 -0
  19. data/shoes/lib/shoes/pack.rb +503 -0
  20. data/shoes/lib/shoes/search.rb +46 -0
  21. data/shoes/lib/shoes/setup.rb +329 -0
  22. data/shoes/lib/shoes/shy.rb +131 -0
  23. data/shoes/lib/shoes/shybuilder.rb +44 -0
  24. data/shoes/lib/shoes.rb +522 -0
  25. data/shoes/libcairo-2.dll +0 -0
  26. data/shoes/libeay32.dll +0 -0
  27. data/shoes/libexpat-1.dll +0 -0
  28. data/shoes/libfontconfig-1.dll +0 -0
  29. data/shoes/libgio-2.0-0.dll +0 -0
  30. data/shoes/libglib-2.0-0.dll +0 -0
  31. data/shoes/libgmodule-2.0-0.dll +0 -0
  32. data/shoes/libgobject-2.0-0.dll +0 -0
  33. data/shoes/libgthread-2.0-0.dll +0 -0
  34. data/shoes/libiconv2.dll +0 -0
  35. data/shoes/libjpeg-8.dll +0 -0
  36. data/shoes/libpango-1.0-0.dll +0 -0
  37. data/shoes/libpangocairo-1.0-0.dll +0 -0
  38. data/shoes/libpangoft2-1.0-0.dll +0 -0
  39. data/shoes/libpangowin32-1.0-0.dll +0 -0
  40. data/shoes/libpng14-14.dll +0 -0
  41. data/shoes/libportaudio-2.dll +0 -0
  42. data/shoes/libshoes.dll +0 -0
  43. data/shoes/libssl32.dll +0 -0
  44. data/shoes/libungif4.dll +0 -0
  45. data/shoes/msvcrt-ruby191.dll +0 -0
  46. data/shoes/readline5.dll +0 -0
  47. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/fast_xs.so +0 -0
  48. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/blankslate.rb +63 -0
  49. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/builder.rb +216 -0
  50. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/elements.rb +510 -0
  51. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/htmlinfo.rb +691 -0
  52. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/inspect.rb +103 -0
  53. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/modules.rb +40 -0
  54. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/parse.rb +38 -0
  55. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/tag.rb +202 -0
  56. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/tags.rb +164 -0
  57. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/traverse.rb +838 -0
  58. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot/xchar.rb +94 -0
  59. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot.rb +26 -0
  60. data/shoes/ruby/gems/1.9.1/gems/hpricot-0.8.1/lib/hpricot_scan.so +0 -0
  61. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/add/core.rb +135 -0
  62. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/add/rails.rb +58 -0
  63. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/common.rb +354 -0
  64. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/ext/generator.so +0 -0
  65. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/ext/parser.so +0 -0
  66. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/ext.rb +13 -0
  67. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json/version.rb +9 -0
  68. data/shoes/ruby/gems/1.9.1/gems/json-shoes-1.1.3/lib/json.rb +8 -0
  69. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/constants.rb +49 -0
  70. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/database.rb +721 -0
  71. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/dl/api.rb +152 -0
  72. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/dl/driver.rb +307 -0
  73. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/native/driver.rb +219 -0
  74. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/errors.rb +68 -0
  75. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/pragmas.rb +271 -0
  76. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/resultset.rb +180 -0
  77. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/statement.rb +231 -0
  78. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/translator.rb +109 -0
  79. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/value.rb +57 -0
  80. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/version.rb +16 -0
  81. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3.rb +1 -0
  82. data/shoes/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3_api.so +0 -0
  83. data/shoes/ruby/gems/1.9.1/specifications/hpricot-0.8.1.gemspec +32 -0
  84. data/shoes/ruby/gems/1.9.1/specifications/json-shoes-1.1.3.gemspec +34 -0
  85. data/shoes/ruby/gems/1.9.1/specifications/sqlite3-ruby-1.2.5-x86-mswin32.gemspec +46 -0
  86. data/shoes/ruby/lib/English.rb +155 -0
  87. data/shoes/ruby/lib/Win32API.rb +28 -0
  88. data/shoes/ruby/lib/abbrev.rb +103 -0
  89. data/shoes/ruby/lib/base64.rb +91 -0
  90. data/shoes/ruby/lib/benchmark.rb +573 -0
  91. data/shoes/ruby/lib/bigdecimal/jacobian.rb +85 -0
  92. data/shoes/ruby/lib/bigdecimal/ludcmp.rb +86 -0
  93. data/shoes/ruby/lib/bigdecimal/math.rb +237 -0
  94. data/shoes/ruby/lib/bigdecimal/newton.rb +77 -0
  95. data/shoes/ruby/lib/bigdecimal/util.rb +53 -0
  96. data/shoes/ruby/lib/cgi/cookie.rb +144 -0
  97. data/shoes/ruby/lib/cgi/core.rb +786 -0
  98. data/shoes/ruby/lib/cgi/html.rb +1021 -0
  99. data/shoes/ruby/lib/cgi/session/pstore.rb +111 -0
  100. data/shoes/ruby/lib/cgi/session.rb +537 -0
  101. data/shoes/ruby/lib/cgi/util.rb +181 -0
  102. data/shoes/ruby/lib/cgi.rb +274 -0
  103. data/shoes/ruby/lib/cmath.rb +233 -0
  104. data/shoes/ruby/lib/complex.rb +24 -0
  105. data/shoes/ruby/lib/csv.rb +2320 -0
  106. data/shoes/ruby/lib/date/format.rb +1313 -0
  107. data/shoes/ruby/lib/date.rb +1834 -0
  108. data/shoes/ruby/lib/debug.rb +907 -0
  109. data/shoes/ruby/lib/delegate.rb +311 -0
  110. data/shoes/ruby/lib/digest/hmac.rb +274 -0
  111. data/shoes/ruby/lib/digest/sha2.rb +74 -0
  112. data/shoes/ruby/lib/digest.rb +50 -0
  113. data/shoes/ruby/lib/dl/callback.rb +69 -0
  114. data/shoes/ruby/lib/dl/cparser.rb +109 -0
  115. data/shoes/ruby/lib/dl/func.rb +153 -0
  116. data/shoes/ruby/lib/dl/import.rb +215 -0
  117. data/shoes/ruby/lib/dl/pack.rb +173 -0
  118. data/shoes/ruby/lib/dl/stack.rb +146 -0
  119. data/shoes/ruby/lib/dl/struct.rb +213 -0
  120. data/shoes/ruby/lib/dl/types.rb +40 -0
  121. data/shoes/ruby/lib/dl/value.rb +112 -0
  122. data/shoes/ruby/lib/drb/acl.rb +146 -0
  123. data/shoes/ruby/lib/drb/drb.rb +1778 -0
  124. data/shoes/ruby/lib/drb/eq.rb +16 -0
  125. data/shoes/ruby/lib/drb/extserv.rb +71 -0
  126. data/shoes/ruby/lib/drb/extservm.rb +85 -0
  127. data/shoes/ruby/lib/drb/gw.rb +122 -0
  128. data/shoes/ruby/lib/drb/invokemethod.rb +34 -0
  129. data/shoes/ruby/lib/drb/observer.rb +22 -0
  130. data/shoes/ruby/lib/drb/ssl.rb +190 -0
  131. data/shoes/ruby/lib/drb/timeridconv.rb +91 -0
  132. data/shoes/ruby/lib/drb/unix.rb +108 -0
  133. data/shoes/ruby/lib/drb.rb +2 -0
  134. data/shoes/ruby/lib/e2mmap.rb +172 -0
  135. data/shoes/ruby/lib/erb.rb +902 -0
  136. data/shoes/ruby/lib/fileutils.rb +1592 -0
  137. data/shoes/ruby/lib/find.rb +81 -0
  138. data/shoes/ruby/lib/forwardable.rb +270 -0
  139. data/shoes/ruby/lib/ftsearch/analysis/analyzer.rb +16 -0
  140. data/shoes/ruby/lib/ftsearch/analysis/simple_identifier_analyzer.rb +23 -0
  141. data/shoes/ruby/lib/ftsearch/analysis/whitespace_analyzer.rb +22 -0
  142. data/shoes/ruby/lib/ftsearch/document_map_reader.rb +106 -0
  143. data/shoes/ruby/lib/ftsearch/document_map_writer.rb +46 -0
  144. data/shoes/ruby/lib/ftsearch/field_infos.rb +46 -0
  145. data/shoes/ruby/lib/ftsearch/fragment_writer.rb +114 -0
  146. data/shoes/ruby/lib/ftsearch/fulltext_reader.rb +52 -0
  147. data/shoes/ruby/lib/ftsearch/fulltext_writer.rb +75 -0
  148. data/shoes/ruby/lib/ftsearch/suffix_array_reader.rb +275 -0
  149. data/shoes/ruby/lib/ftsearch/suffix_array_writer.rb +99 -0
  150. data/shoes/ruby/lib/ftsearch/util.rb +21 -0
  151. data/shoes/ruby/lib/getoptlong.rb +610 -0
  152. data/shoes/ruby/lib/gserver.rb +253 -0
  153. data/shoes/ruby/lib/i386-mingw32/bigdecimal.so +0 -0
  154. data/shoes/ruby/lib/i386-mingw32/binject.so +0 -0
  155. data/shoes/ruby/lib/i386-mingw32/bloops.so +0 -0
  156. data/shoes/ruby/lib/i386-mingw32/continuation.so +0 -0
  157. data/shoes/ruby/lib/i386-mingw32/coverage.so +0 -0
  158. data/shoes/ruby/lib/i386-mingw32/curses.so +0 -0
  159. data/shoes/ruby/lib/i386-mingw32/digest/bubblebabble.so +0 -0
  160. data/shoes/ruby/lib/i386-mingw32/digest/md5.so +0 -0
  161. data/shoes/ruby/lib/i386-mingw32/digest/rmd160.so +0 -0
  162. data/shoes/ruby/lib/i386-mingw32/digest/sha1.so +0 -0
  163. data/shoes/ruby/lib/i386-mingw32/digest/sha2.so +0 -0
  164. data/shoes/ruby/lib/i386-mingw32/digest.so +0 -0
  165. data/shoes/ruby/lib/i386-mingw32/dl.so +0 -0
  166. data/shoes/ruby/lib/i386-mingw32/enc/big5.so +0 -0
  167. data/shoes/ruby/lib/i386-mingw32/enc/cp949.so +0 -0
  168. data/shoes/ruby/lib/i386-mingw32/enc/emacs_mule.so +0 -0
  169. data/shoes/ruby/lib/i386-mingw32/enc/encdb.so +0 -0
  170. data/shoes/ruby/lib/i386-mingw32/enc/euc_jp.so +0 -0
  171. data/shoes/ruby/lib/i386-mingw32/enc/euc_kr.so +0 -0
  172. data/shoes/ruby/lib/i386-mingw32/enc/euc_tw.so +0 -0
  173. data/shoes/ruby/lib/i386-mingw32/enc/gb18030.so +0 -0
  174. data/shoes/ruby/lib/i386-mingw32/enc/gb2312.so +0 -0
  175. data/shoes/ruby/lib/i386-mingw32/enc/gbk.so +0 -0
  176. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_1.so +0 -0
  177. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_10.so +0 -0
  178. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_11.so +0 -0
  179. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_13.so +0 -0
  180. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_14.so +0 -0
  181. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_15.so +0 -0
  182. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_16.so +0 -0
  183. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_2.so +0 -0
  184. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_3.so +0 -0
  185. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_4.so +0 -0
  186. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_5.so +0 -0
  187. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_6.so +0 -0
  188. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_7.so +0 -0
  189. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_8.so +0 -0
  190. data/shoes/ruby/lib/i386-mingw32/enc/iso_8859_9.so +0 -0
  191. data/shoes/ruby/lib/i386-mingw32/enc/koi8_r.so +0 -0
  192. data/shoes/ruby/lib/i386-mingw32/enc/koi8_u.so +0 -0
  193. data/shoes/ruby/lib/i386-mingw32/enc/shift_jis.so +0 -0
  194. data/shoes/ruby/lib/i386-mingw32/enc/trans/big5.so +0 -0
  195. data/shoes/ruby/lib/i386-mingw32/enc/trans/chinese.so +0 -0
  196. data/shoes/ruby/lib/i386-mingw32/enc/trans/escape.so +0 -0
  197. data/shoes/ruby/lib/i386-mingw32/enc/trans/gb18030.so +0 -0
  198. data/shoes/ruby/lib/i386-mingw32/enc/trans/gbk.so +0 -0
  199. data/shoes/ruby/lib/i386-mingw32/enc/trans/iso2022.so +0 -0
  200. data/shoes/ruby/lib/i386-mingw32/enc/trans/japanese.so +0 -0
  201. data/shoes/ruby/lib/i386-mingw32/enc/trans/japanese_euc.so +0 -0
  202. data/shoes/ruby/lib/i386-mingw32/enc/trans/japanese_sjis.so +0 -0
  203. data/shoes/ruby/lib/i386-mingw32/enc/trans/korean.so +0 -0
  204. data/shoes/ruby/lib/i386-mingw32/enc/trans/single_byte.so +0 -0
  205. data/shoes/ruby/lib/i386-mingw32/enc/trans/transdb.so +0 -0
  206. data/shoes/ruby/lib/i386-mingw32/enc/trans/utf_16_32.so +0 -0
  207. data/shoes/ruby/lib/i386-mingw32/enc/utf_16be.so +0 -0
  208. data/shoes/ruby/lib/i386-mingw32/enc/utf_16le.so +0 -0
  209. data/shoes/ruby/lib/i386-mingw32/enc/utf_32be.so +0 -0
  210. data/shoes/ruby/lib/i386-mingw32/enc/utf_32le.so +0 -0
  211. data/shoes/ruby/lib/i386-mingw32/enc/windows_1251.so +0 -0
  212. data/shoes/ruby/lib/i386-mingw32/etc.so +0 -0
  213. data/shoes/ruby/lib/i386-mingw32/fcntl.so +0 -0
  214. data/shoes/ruby/lib/i386-mingw32/fiber.so +0 -0
  215. data/shoes/ruby/lib/i386-mingw32/ftsearchrt.so +0 -0
  216. data/shoes/ruby/lib/i386-mingw32/gdbm.so +0 -0
  217. data/shoes/ruby/lib/i386-mingw32/iconv.so +0 -0
  218. data/shoes/ruby/lib/i386-mingw32/io/wait.so +0 -0
  219. data/shoes/ruby/lib/i386-mingw32/json/ext/generator.so +0 -0
  220. data/shoes/ruby/lib/i386-mingw32/json/ext/parser.so +0 -0
  221. data/shoes/ruby/lib/i386-mingw32/mathn/complex.so +0 -0
  222. data/shoes/ruby/lib/i386-mingw32/mathn/rational.so +0 -0
  223. data/shoes/ruby/lib/i386-mingw32/nkf.so +0 -0
  224. data/shoes/ruby/lib/i386-mingw32/openssl.so +0 -0
  225. data/shoes/ruby/lib/i386-mingw32/racc/cparse.so +0 -0
  226. data/shoes/ruby/lib/i386-mingw32/rbconfig.rb +196 -0
  227. data/shoes/ruby/lib/i386-mingw32/readline.so +0 -0
  228. data/shoes/ruby/lib/i386-mingw32/ripper.so +0 -0
  229. data/shoes/ruby/lib/i386-mingw32/sdbm.so +0 -0
  230. data/shoes/ruby/lib/i386-mingw32/socket.so +0 -0
  231. data/shoes/ruby/lib/i386-mingw32/stringio.so +0 -0
  232. data/shoes/ruby/lib/i386-mingw32/strscan.so +0 -0
  233. data/shoes/ruby/lib/i386-mingw32/syck.so +0 -0
  234. data/shoes/ruby/lib/i386-mingw32/win32ole.so +0 -0
  235. data/shoes/ruby/lib/i386-mingw32/zlib.so +0 -0
  236. data/shoes/ruby/lib/io/nonblock.rb +23 -0
  237. data/shoes/ruby/lib/ipaddr.rb +813 -0
  238. data/shoes/ruby/lib/irb/cmd/chws.rb +32 -0
  239. data/shoes/ruby/lib/irb/cmd/fork.rb +38 -0
  240. data/shoes/ruby/lib/irb/cmd/help.rb +36 -0
  241. data/shoes/ruby/lib/irb/cmd/load.rb +66 -0
  242. data/shoes/ruby/lib/irb/cmd/nop.rb +38 -0
  243. data/shoes/ruby/lib/irb/cmd/pushws.rb +38 -0
  244. data/shoes/ruby/lib/irb/cmd/subirb.rb +42 -0
  245. data/shoes/ruby/lib/irb/completion.rb +207 -0
  246. data/shoes/ruby/lib/irb/context.rb +255 -0
  247. data/shoes/ruby/lib/irb/ext/change-ws.rb +61 -0
  248. data/shoes/ruby/lib/irb/ext/history.rb +109 -0
  249. data/shoes/ruby/lib/irb/ext/loader.rb +119 -0
  250. data/shoes/ruby/lib/irb/ext/math-mode.rb +36 -0
  251. data/shoes/ruby/lib/irb/ext/multi-irb.rb +240 -0
  252. data/shoes/ruby/lib/irb/ext/save-history.rb +100 -0
  253. data/shoes/ruby/lib/irb/ext/tracer.rb +60 -0
  254. data/shoes/ruby/lib/irb/ext/use-loader.rb +64 -0
  255. data/shoes/ruby/lib/irb/ext/workspaces.rb +55 -0
  256. data/shoes/ruby/lib/irb/extend-command.rb +272 -0
  257. data/shoes/ruby/lib/irb/frame.rb +66 -0
  258. data/shoes/ruby/lib/irb/help.rb +35 -0
  259. data/shoes/ruby/lib/irb/init.rb +288 -0
  260. data/shoes/ruby/lib/irb/input-method.rb +142 -0
  261. data/shoes/ruby/lib/irb/lc/error.rb +29 -0
  262. data/shoes/ruby/lib/irb/lc/help-message +38 -0
  263. data/shoes/ruby/lib/irb/lc/ja/encoding_aliases.rb +8 -0
  264. data/shoes/ruby/lib/irb/lc/ja/error.rb +27 -0
  265. data/shoes/ruby/lib/irb/lc/ja/help-message +39 -0
  266. data/shoes/ruby/lib/irb/locale.rb +195 -0
  267. data/shoes/ruby/lib/irb/magic-file.rb +36 -0
  268. data/shoes/ruby/lib/irb/notifier.rb +144 -0
  269. data/shoes/ruby/lib/irb/output-method.rb +69 -0
  270. data/shoes/ruby/lib/irb/ruby-lex.rb +1188 -0
  271. data/shoes/ruby/lib/irb/ruby-token.rb +270 -0
  272. data/shoes/ruby/lib/irb/slex.rb +282 -0
  273. data/shoes/ruby/lib/irb/src_encoding.rb +4 -0
  274. data/shoes/ruby/lib/irb/version.rb +15 -0
  275. data/shoes/ruby/lib/irb/workspace.rb +108 -0
  276. data/shoes/ruby/lib/irb/ws-for-case-2.rb +14 -0
  277. data/shoes/ruby/lib/irb/xmp.rb +97 -0
  278. data/shoes/ruby/lib/irb.rb +354 -0
  279. data/shoes/ruby/lib/json/add/core.rb +135 -0
  280. data/shoes/ruby/lib/json/add/rails.rb +58 -0
  281. data/shoes/ruby/lib/json/common.rb +354 -0
  282. data/shoes/ruby/lib/json/editor.rb +1371 -0
  283. data/shoes/ruby/lib/json/ext.rb +15 -0
  284. data/shoes/ruby/lib/json/version.rb +9 -0
  285. data/shoes/ruby/lib/json.rb +297 -0
  286. data/shoes/ruby/lib/kconv.rb +282 -0
  287. data/shoes/ruby/lib/logger.rb +732 -0
  288. data/shoes/ruby/lib/mathn.rb +206 -0
  289. data/shoes/ruby/lib/matrix.rb +1381 -0
  290. data/shoes/ruby/lib/minitest/autorun.rb +9 -0
  291. data/shoes/ruby/lib/minitest/mock.rb +37 -0
  292. data/shoes/ruby/lib/minitest/spec.rb +89 -0
  293. data/shoes/ruby/lib/minitest/unit.rb +497 -0
  294. data/shoes/ruby/lib/mkmf.rb +1958 -0
  295. data/shoes/ruby/lib/monitor.rb +265 -0
  296. data/shoes/ruby/lib/mutex_m.rb +91 -0
  297. data/shoes/ruby/lib/net/ftp.rb +981 -0
  298. data/shoes/ruby/lib/net/http.rb +2399 -0
  299. data/shoes/ruby/lib/net/https.rb +136 -0
  300. data/shoes/ruby/lib/net/imap.rb +3500 -0
  301. data/shoes/ruby/lib/net/pop.rb +1000 -0
  302. data/shoes/ruby/lib/net/protocol.rb +382 -0
  303. data/shoes/ruby/lib/net/smtp.rb +1014 -0
  304. data/shoes/ruby/lib/net/telnet.rb +759 -0
  305. data/shoes/ruby/lib/observer.rb +193 -0
  306. data/shoes/ruby/lib/open-uri.rb +832 -0
  307. data/shoes/ruby/lib/open3.rb +98 -0
  308. data/shoes/ruby/lib/openssl/bn.rb +35 -0
  309. data/shoes/ruby/lib/openssl/buffering.rb +242 -0
  310. data/shoes/ruby/lib/openssl/cipher.rb +65 -0
  311. data/shoes/ruby/lib/openssl/digest.rb +61 -0
  312. data/shoes/ruby/lib/openssl/ssl.rb +178 -0
  313. data/shoes/ruby/lib/openssl/x509.rb +155 -0
  314. data/shoes/ruby/lib/openssl.rb +24 -0
  315. data/shoes/ruby/lib/optparse/date.rb +17 -0
  316. data/shoes/ruby/lib/optparse/shellwords.rb +6 -0
  317. data/shoes/ruby/lib/optparse/time.rb +10 -0
  318. data/shoes/ruby/lib/optparse/uri.rb +6 -0
  319. data/shoes/ruby/lib/optparse/version.rb +70 -0
  320. data/shoes/ruby/lib/optparse.rb +1810 -0
  321. data/shoes/ruby/lib/ostruct.rb +145 -0
  322. data/shoes/ruby/lib/pathname.rb +1099 -0
  323. data/shoes/ruby/lib/pp.rb +532 -0
  324. data/shoes/ruby/lib/prettyprint.rb +896 -0
  325. data/shoes/ruby/lib/prime.rb +471 -0
  326. data/shoes/ruby/lib/profile.rb +10 -0
  327. data/shoes/ruby/lib/profiler.rb +59 -0
  328. data/shoes/ruby/lib/pstore.rb +543 -0
  329. data/shoes/ruby/lib/racc/parser.rb +441 -0
  330. data/shoes/ruby/lib/rake/classic_namespace.rb +8 -0
  331. data/shoes/ruby/lib/rake/clean.rb +33 -0
  332. data/shoes/ruby/lib/rake/gempackagetask.rb +97 -0
  333. data/shoes/ruby/lib/rake/loaders/makefile.rb +35 -0
  334. data/shoes/ruby/lib/rake/packagetask.rb +185 -0
  335. data/shoes/ruby/lib/rake/rake_test_loader.rb +5 -0
  336. data/shoes/ruby/lib/rake/rdoctask.rb +147 -0
  337. data/shoes/ruby/lib/rake/runtest.rb +23 -0
  338. data/shoes/ruby/lib/rake/tasklib.rb +23 -0
  339. data/shoes/ruby/lib/rake/testtask.rb +161 -0
  340. data/shoes/ruby/lib/rake/win32.rb +34 -0
  341. data/shoes/ruby/lib/rake.rb +2465 -0
  342. data/shoes/ruby/lib/rational.rb +19 -0
  343. data/shoes/ruby/lib/rbconfig/datadir.rb +24 -0
  344. data/shoes/ruby/lib/rdoc/code_objects.rb +1061 -0
  345. data/shoes/ruby/lib/rdoc/diagram.rb +340 -0
  346. data/shoes/ruby/lib/rdoc/dot.rb +249 -0
  347. data/shoes/ruby/lib/rdoc/generator/chm/chm.rb +100 -0
  348. data/shoes/ruby/lib/rdoc/generator/chm.rb +113 -0
  349. data/shoes/ruby/lib/rdoc/generator/html/common.rb +24 -0
  350. data/shoes/ruby/lib/rdoc/generator/html/frameless.rb +92 -0
  351. data/shoes/ruby/lib/rdoc/generator/html/hefss.rb +150 -0
  352. data/shoes/ruby/lib/rdoc/generator/html/html.rb +769 -0
  353. data/shoes/ruby/lib/rdoc/generator/html/kilmer.rb +151 -0
  354. data/shoes/ruby/lib/rdoc/generator/html/kilmerfactory.rb +427 -0
  355. data/shoes/ruby/lib/rdoc/generator/html/one_page_html.rb +122 -0
  356. data/shoes/ruby/lib/rdoc/generator/html.rb +445 -0
  357. data/shoes/ruby/lib/rdoc/generator/ri.rb +226 -0
  358. data/shoes/ruby/lib/rdoc/generator/texinfo/class.texinfo.erb +44 -0
  359. data/shoes/ruby/lib/rdoc/generator/texinfo/file.texinfo.erb +6 -0
  360. data/shoes/ruby/lib/rdoc/generator/texinfo/method.texinfo.erb +6 -0
  361. data/shoes/ruby/lib/rdoc/generator/texinfo/texinfo.erb +28 -0
  362. data/shoes/ruby/lib/rdoc/generator/texinfo.rb +81 -0
  363. data/shoes/ruby/lib/rdoc/generator/xml/rdf.rb +113 -0
  364. data/shoes/ruby/lib/rdoc/generator/xml/xml.rb +123 -0
  365. data/shoes/ruby/lib/rdoc/generator/xml.rb +117 -0
  366. data/shoes/ruby/lib/rdoc/generator.rb +1082 -0
  367. data/shoes/ruby/lib/rdoc/known_classes.rb +68 -0
  368. data/shoes/ruby/lib/rdoc/markup/attribute_manager.rb +265 -0
  369. data/shoes/ruby/lib/rdoc/markup/formatter.rb +14 -0
  370. data/shoes/ruby/lib/rdoc/markup/fragments.rb +337 -0
  371. data/shoes/ruby/lib/rdoc/markup/inline.rb +101 -0
  372. data/shoes/ruby/lib/rdoc/markup/lines.rb +152 -0
  373. data/shoes/ruby/lib/rdoc/markup/preprocess.rb +75 -0
  374. data/shoes/ruby/lib/rdoc/markup/to_flow.rb +185 -0
  375. data/shoes/ruby/lib/rdoc/markup/to_html.rb +403 -0
  376. data/shoes/ruby/lib/rdoc/markup/to_html_crossref.rb +148 -0
  377. data/shoes/ruby/lib/rdoc/markup/to_latex.rb +328 -0
  378. data/shoes/ruby/lib/rdoc/markup/to_test.rb +50 -0
  379. data/shoes/ruby/lib/rdoc/markup/to_texinfo.rb +69 -0
  380. data/shoes/ruby/lib/rdoc/markup.rb +378 -0
  381. data/shoes/ruby/lib/rdoc/options.rb +638 -0
  382. data/shoes/ruby/lib/rdoc/parser/c.rb +661 -0
  383. data/shoes/ruby/lib/rdoc/parser/f95.rb +1835 -0
  384. data/shoes/ruby/lib/rdoc/parser/perl.rb +165 -0
  385. data/shoes/ruby/lib/rdoc/parser/ruby.rb +2829 -0
  386. data/shoes/ruby/lib/rdoc/parser/simple.rb +38 -0
  387. data/shoes/ruby/lib/rdoc/parser.rb +142 -0
  388. data/shoes/ruby/lib/rdoc/rdoc.rb +293 -0
  389. data/shoes/ruby/lib/rdoc/ri/cache.rb +187 -0
  390. data/shoes/ruby/lib/rdoc/ri/descriptions.rb +156 -0
  391. data/shoes/ruby/lib/rdoc/ri/display.rb +392 -0
  392. data/shoes/ruby/lib/rdoc/ri/driver.rb +669 -0
  393. data/shoes/ruby/lib/rdoc/ri/formatter.rb +616 -0
  394. data/shoes/ruby/lib/rdoc/ri/paths.rb +99 -0
  395. data/shoes/ruby/lib/rdoc/ri/reader.rb +106 -0
  396. data/shoes/ruby/lib/rdoc/ri/util.rb +79 -0
  397. data/shoes/ruby/lib/rdoc/ri/writer.rb +68 -0
  398. data/shoes/ruby/lib/rdoc/ri.rb +8 -0
  399. data/shoes/ruby/lib/rdoc/stats.rb +115 -0
  400. data/shoes/ruby/lib/rdoc/template.rb +64 -0
  401. data/shoes/ruby/lib/rdoc/tokenstream.rb +33 -0
  402. data/shoes/ruby/lib/rdoc.rb +395 -0
  403. data/shoes/ruby/lib/resolv-replace.rb +63 -0
  404. data/shoes/ruby/lib/resolv.rb +2262 -0
  405. data/shoes/ruby/lib/rexml/attlistdecl.rb +62 -0
  406. data/shoes/ruby/lib/rexml/attribute.rb +188 -0
  407. data/shoes/ruby/lib/rexml/cdata.rb +67 -0
  408. data/shoes/ruby/lib/rexml/child.rb +96 -0
  409. data/shoes/ruby/lib/rexml/comment.rb +80 -0
  410. data/shoes/ruby/lib/rexml/doctype.rb +270 -0
  411. data/shoes/ruby/lib/rexml/document.rb +231 -0
  412. data/shoes/ruby/lib/rexml/dtd/attlistdecl.rb +10 -0
  413. data/shoes/ruby/lib/rexml/dtd/dtd.rb +51 -0
  414. data/shoes/ruby/lib/rexml/dtd/elementdecl.rb +17 -0
  415. data/shoes/ruby/lib/rexml/dtd/entitydecl.rb +56 -0
  416. data/shoes/ruby/lib/rexml/dtd/notationdecl.rb +39 -0
  417. data/shoes/ruby/lib/rexml/element.rb +1246 -0
  418. data/shoes/ruby/lib/rexml/encoding.rb +71 -0
  419. data/shoes/ruby/lib/rexml/encodings/CP-1252.rb +103 -0
  420. data/shoes/ruby/lib/rexml/encodings/EUC-JP.rb +35 -0
  421. data/shoes/ruby/lib/rexml/encodings/ICONV.rb +22 -0
  422. data/shoes/ruby/lib/rexml/encodings/ISO-8859-1.rb +7 -0
  423. data/shoes/ruby/lib/rexml/encodings/ISO-8859-15.rb +72 -0
  424. data/shoes/ruby/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
  425. data/shoes/ruby/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
  426. data/shoes/ruby/lib/rexml/encodings/UNILE.rb +34 -0
  427. data/shoes/ruby/lib/rexml/encodings/US-ASCII.rb +30 -0
  428. data/shoes/ruby/lib/rexml/encodings/UTF-16.rb +35 -0
  429. data/shoes/ruby/lib/rexml/encodings/UTF-8.rb +18 -0
  430. data/shoes/ruby/lib/rexml/entity.rb +166 -0
  431. data/shoes/ruby/lib/rexml/formatters/default.rb +109 -0
  432. data/shoes/ruby/lib/rexml/formatters/pretty.rb +139 -0
  433. data/shoes/ruby/lib/rexml/formatters/transitive.rb +58 -0
  434. data/shoes/ruby/lib/rexml/functions.rb +388 -0
  435. data/shoes/ruby/lib/rexml/instruction.rb +70 -0
  436. data/shoes/ruby/lib/rexml/light/node.rb +196 -0
  437. data/shoes/ruby/lib/rexml/namespace.rb +47 -0
  438. data/shoes/ruby/lib/rexml/node.rb +75 -0
  439. data/shoes/ruby/lib/rexml/output.rb +24 -0
  440. data/shoes/ruby/lib/rexml/parent.rb +166 -0
  441. data/shoes/ruby/lib/rexml/parseexception.rb +51 -0
  442. data/shoes/ruby/lib/rexml/parsers/baseparser.rb +530 -0
  443. data/shoes/ruby/lib/rexml/parsers/lightparser.rb +58 -0
  444. data/shoes/ruby/lib/rexml/parsers/pullparser.rb +196 -0
  445. data/shoes/ruby/lib/rexml/parsers/sax2parser.rb +247 -0
  446. data/shoes/ruby/lib/rexml/parsers/streamparser.rb +46 -0
  447. data/shoes/ruby/lib/rexml/parsers/treeparser.rb +100 -0
  448. data/shoes/ruby/lib/rexml/parsers/ultralightparser.rb +56 -0
  449. data/shoes/ruby/lib/rexml/parsers/xpathparser.rb +698 -0
  450. data/shoes/ruby/lib/rexml/quickpath.rb +263 -0
  451. data/shoes/ruby/lib/rexml/rexml.rb +31 -0
  452. data/shoes/ruby/lib/rexml/sax2listener.rb +97 -0
  453. data/shoes/ruby/lib/rexml/source.rb +258 -0
  454. data/shoes/ruby/lib/rexml/streamlistener.rb +92 -0
  455. data/shoes/ruby/lib/rexml/syncenumerator.rb +32 -0
  456. data/shoes/ruby/lib/rexml/text.rb +404 -0
  457. data/shoes/ruby/lib/rexml/undefinednamespaceexception.rb +8 -0
  458. data/shoes/ruby/lib/rexml/validation/relaxng.rb +559 -0
  459. data/shoes/ruby/lib/rexml/validation/validation.rb +155 -0
  460. data/shoes/ruby/lib/rexml/validation/validationexception.rb +9 -0
  461. data/shoes/ruby/lib/rexml/xmldecl.rb +119 -0
  462. data/shoes/ruby/lib/rexml/xmltokens.rb +18 -0
  463. data/shoes/ruby/lib/rexml/xpath.rb +77 -0
  464. data/shoes/ruby/lib/rexml/xpath_parser.rb +792 -0
  465. data/shoes/ruby/lib/rinda/rinda.rb +283 -0
  466. data/shoes/ruby/lib/rinda/ring.rb +271 -0
  467. data/shoes/ruby/lib/rinda/tuplespace.rb +642 -0
  468. data/shoes/ruby/lib/ripper/core.rb +70 -0
  469. data/shoes/ruby/lib/ripper/filter.rb +70 -0
  470. data/shoes/ruby/lib/ripper/lexer.rb +179 -0
  471. data/shoes/ruby/lib/ripper/sexp.rb +99 -0
  472. data/shoes/ruby/lib/ripper.rb +4 -0
  473. data/shoes/ruby/lib/rss/0.9.rb +427 -0
  474. data/shoes/ruby/lib/rss/1.0.rb +452 -0
  475. data/shoes/ruby/lib/rss/2.0.rb +111 -0
  476. data/shoes/ruby/lib/rss/atom.rb +748 -0
  477. data/shoes/ruby/lib/rss/content/1.0.rb +10 -0
  478. data/shoes/ruby/lib/rss/content/2.0.rb +12 -0
  479. data/shoes/ruby/lib/rss/content.rb +31 -0
  480. data/shoes/ruby/lib/rss/converter.rb +170 -0
  481. data/shoes/ruby/lib/rss/dublincore/1.0.rb +13 -0
  482. data/shoes/ruby/lib/rss/dublincore/2.0.rb +13 -0
  483. data/shoes/ruby/lib/rss/dublincore/atom.rb +17 -0
  484. data/shoes/ruby/lib/rss/dublincore.rb +161 -0
  485. data/shoes/ruby/lib/rss/image.rb +193 -0
  486. data/shoes/ruby/lib/rss/itunes.rb +410 -0
  487. data/shoes/ruby/lib/rss/maker/0.9.rb +467 -0
  488. data/shoes/ruby/lib/rss/maker/1.0.rb +434 -0
  489. data/shoes/ruby/lib/rss/maker/2.0.rb +223 -0
  490. data/shoes/ruby/lib/rss/maker/atom.rb +172 -0
  491. data/shoes/ruby/lib/rss/maker/base.rb +880 -0
  492. data/shoes/ruby/lib/rss/maker/content.rb +21 -0
  493. data/shoes/ruby/lib/rss/maker/dublincore.rb +124 -0
  494. data/shoes/ruby/lib/rss/maker/entry.rb +163 -0
  495. data/shoes/ruby/lib/rss/maker/feed.rb +430 -0
  496. data/shoes/ruby/lib/rss/maker/image.rb +111 -0
  497. data/shoes/ruby/lib/rss/maker/itunes.rb +242 -0
  498. data/shoes/ruby/lib/rss/maker/slash.rb +33 -0
  499. data/shoes/ruby/lib/rss/maker/syndication.rb +18 -0
  500. data/shoes/ruby/lib/rss/maker/taxonomy.rb +118 -0
  501. data/shoes/ruby/lib/rss/maker/trackback.rb +61 -0
  502. data/shoes/ruby/lib/rss/maker.rb +44 -0
  503. data/shoes/ruby/lib/rss/parser.rb +568 -0
  504. data/shoes/ruby/lib/rss/rexmlparser.rb +54 -0
  505. data/shoes/ruby/lib/rss/rss.rb +1313 -0
  506. data/shoes/ruby/lib/rss/slash.rb +49 -0
  507. data/shoes/ruby/lib/rss/syndication.rb +67 -0
  508. data/shoes/ruby/lib/rss/taxonomy.rb +145 -0
  509. data/shoes/ruby/lib/rss/trackback.rb +288 -0
  510. data/shoes/ruby/lib/rss/utils.rb +111 -0
  511. data/shoes/ruby/lib/rss/xml-stylesheet.rb +105 -0
  512. data/shoes/ruby/lib/rss/xml.rb +71 -0
  513. data/shoes/ruby/lib/rss/xmlparser.rb +93 -0
  514. data/shoes/ruby/lib/rss/xmlscanner.rb +121 -0
  515. data/shoes/ruby/lib/rss.rb +19 -0
  516. data/shoes/ruby/lib/rubygems/builder.rb +88 -0
  517. data/shoes/ruby/lib/rubygems/command.rb +406 -0
  518. data/shoes/ruby/lib/rubygems/command_manager.rb +146 -0
  519. data/shoes/ruby/lib/rubygems/commands/build_command.rb +53 -0
  520. data/shoes/ruby/lib/rubygems/commands/cert_command.rb +86 -0
  521. data/shoes/ruby/lib/rubygems/commands/check_command.rb +75 -0
  522. data/shoes/ruby/lib/rubygems/commands/cleanup_command.rb +91 -0
  523. data/shoes/ruby/lib/rubygems/commands/contents_command.rb +74 -0
  524. data/shoes/ruby/lib/rubygems/commands/dependency_command.rb +188 -0
  525. data/shoes/ruby/lib/rubygems/commands/environment_command.rb +128 -0
  526. data/shoes/ruby/lib/rubygems/commands/fetch_command.rb +62 -0
  527. data/shoes/ruby/lib/rubygems/commands/generate_index_command.rb +57 -0
  528. data/shoes/ruby/lib/rubygems/commands/help_command.rb +172 -0
  529. data/shoes/ruby/lib/rubygems/commands/install_command.rb +148 -0
  530. data/shoes/ruby/lib/rubygems/commands/list_command.rb +35 -0
  531. data/shoes/ruby/lib/rubygems/commands/lock_command.rb +110 -0
  532. data/shoes/ruby/lib/rubygems/commands/mirror_command.rb +111 -0
  533. data/shoes/ruby/lib/rubygems/commands/outdated_command.rb +33 -0
  534. data/shoes/ruby/lib/rubygems/commands/pristine_command.rb +93 -0
  535. data/shoes/ruby/lib/rubygems/commands/query_command.rb +233 -0
  536. data/shoes/ruby/lib/rubygems/commands/rdoc_command.rb +82 -0
  537. data/shoes/ruby/lib/rubygems/commands/search_command.rb +37 -0
  538. data/shoes/ruby/lib/rubygems/commands/server_command.rb +48 -0
  539. data/shoes/ruby/lib/rubygems/commands/sources_command.rb +152 -0
  540. data/shoes/ruby/lib/rubygems/commands/specification_command.rb +77 -0
  541. data/shoes/ruby/lib/rubygems/commands/stale_command.rb +27 -0
  542. data/shoes/ruby/lib/rubygems/commands/uninstall_command.rb +73 -0
  543. data/shoes/ruby/lib/rubygems/commands/unpack_command.rb +95 -0
  544. data/shoes/ruby/lib/rubygems/commands/update_command.rb +181 -0
  545. data/shoes/ruby/lib/rubygems/commands/which_command.rb +87 -0
  546. data/shoes/ruby/lib/rubygems/config_file.rb +266 -0
  547. data/shoes/ruby/lib/rubygems/custom_require.rb +46 -0
  548. data/shoes/ruby/lib/rubygems/defaults.rb +89 -0
  549. data/shoes/ruby/lib/rubygems/dependency.rb +119 -0
  550. data/shoes/ruby/lib/rubygems/dependency_installer.rb +258 -0
  551. data/shoes/ruby/lib/rubygems/dependency_list.rb +165 -0
  552. data/shoes/ruby/lib/rubygems/digest/digest_adapter.rb +40 -0
  553. data/shoes/ruby/lib/rubygems/digest/md5.rb +23 -0
  554. data/shoes/ruby/lib/rubygems/digest/sha1.rb +17 -0
  555. data/shoes/ruby/lib/rubygems/digest/sha2.rb +17 -0
  556. data/shoes/ruby/lib/rubygems/doc_manager.rb +214 -0
  557. data/shoes/ruby/lib/rubygems/exceptions.rb +84 -0
  558. data/shoes/ruby/lib/rubygems/ext/builder.rb +56 -0
  559. data/shoes/ruby/lib/rubygems/ext/configure_builder.rb +24 -0
  560. data/shoes/ruby/lib/rubygems/ext/ext_conf_builder.rb +23 -0
  561. data/shoes/ruby/lib/rubygems/ext/rake_builder.rb +27 -0
  562. data/shoes/ruby/lib/rubygems/ext.rb +18 -0
  563. data/shoes/ruby/lib/rubygems/format.rb +87 -0
  564. data/shoes/ruby/lib/rubygems/gem_openssl.rb +83 -0
  565. data/shoes/ruby/lib/rubygems/gem_path_searcher.rb +100 -0
  566. data/shoes/ruby/lib/rubygems/gem_runner.rb +58 -0
  567. data/shoes/ruby/lib/rubygems/indexer/abstract_index_builder.rb +88 -0
  568. data/shoes/ruby/lib/rubygems/indexer/latest_index_builder.rb +35 -0
  569. data/shoes/ruby/lib/rubygems/indexer/marshal_index_builder.rb +17 -0
  570. data/shoes/ruby/lib/rubygems/indexer/master_index_builder.rb +54 -0
  571. data/shoes/ruby/lib/rubygems/indexer/quick_index_builder.rb +50 -0
  572. data/shoes/ruby/lib/rubygems/indexer.rb +370 -0
  573. data/shoes/ruby/lib/rubygems/install_update_options.rb +113 -0
  574. data/shoes/ruby/lib/rubygems/installer.rb +578 -0
  575. data/shoes/ruby/lib/rubygems/local_remote_options.rb +134 -0
  576. data/shoes/ruby/lib/rubygems/old_format.rb +148 -0
  577. data/shoes/ruby/lib/rubygems/package/f_sync_dir.rb +24 -0
  578. data/shoes/ruby/lib/rubygems/package/tar_header.rb +245 -0
  579. data/shoes/ruby/lib/rubygems/package/tar_input.rb +219 -0
  580. data/shoes/ruby/lib/rubygems/package/tar_output.rb +143 -0
  581. data/shoes/ruby/lib/rubygems/package/tar_reader/entry.rb +99 -0
  582. data/shoes/ruby/lib/rubygems/package/tar_reader.rb +86 -0
  583. data/shoes/ruby/lib/rubygems/package/tar_writer.rb +180 -0
  584. data/shoes/ruby/lib/rubygems/package.rb +95 -0
  585. data/shoes/ruby/lib/rubygems/platform.rb +178 -0
  586. data/shoes/ruby/lib/rubygems/remote_fetcher.rb +344 -0
  587. data/shoes/ruby/lib/rubygems/require_paths_builder.rb +15 -0
  588. data/shoes/ruby/lib/rubygems/requirement.rb +163 -0
  589. data/shoes/ruby/lib/rubygems/rubygems_version.rb +6 -0
  590. data/shoes/ruby/lib/rubygems/security.rb +786 -0
  591. data/shoes/ruby/lib/rubygems/server.rb +629 -0
  592. data/shoes/ruby/lib/rubygems/source_index.rb +559 -0
  593. data/shoes/ruby/lib/rubygems/source_info_cache.rb +393 -0
  594. data/shoes/ruby/lib/rubygems/source_info_cache_entry.rb +56 -0
  595. data/shoes/ruby/lib/rubygems/spec_fetcher.rb +249 -0
  596. data/shoes/ruby/lib/rubygems/specification.rb +1262 -0
  597. data/shoes/ruby/lib/rubygems/test_utilities.rb +131 -0
  598. data/shoes/ruby/lib/rubygems/timer.rb +25 -0
  599. data/shoes/ruby/lib/rubygems/uninstaller.rb +242 -0
  600. data/shoes/ruby/lib/rubygems/user_interaction.rb +360 -0
  601. data/shoes/ruby/lib/rubygems/validator.rb +208 -0
  602. data/shoes/ruby/lib/rubygems/version.rb +167 -0
  603. data/shoes/ruby/lib/rubygems/version_option.rb +48 -0
  604. data/shoes/ruby/lib/rubygems.rb +888 -0
  605. data/shoes/ruby/lib/scanf.rb +703 -0
  606. data/shoes/ruby/lib/securerandom.rb +182 -0
  607. data/shoes/ruby/lib/set.rb +1274 -0
  608. data/shoes/ruby/lib/shell/builtin-command.rb +160 -0
  609. data/shoes/ruby/lib/shell/command-processor.rb +593 -0
  610. data/shoes/ruby/lib/shell/error.rb +25 -0
  611. data/shoes/ruby/lib/shell/filter.rb +109 -0
  612. data/shoes/ruby/lib/shell/process-controller.rb +319 -0
  613. data/shoes/ruby/lib/shell/system-command.rb +159 -0
  614. data/shoes/ruby/lib/shell/version.rb +15 -0
  615. data/shoes/ruby/lib/shell.rb +300 -0
  616. data/shoes/ruby/lib/shellwords.rb +156 -0
  617. data/shoes/ruby/lib/singleton.rb +313 -0
  618. data/shoes/ruby/lib/sync.rb +307 -0
  619. data/shoes/ruby/lib/tempfile.rb +218 -0
  620. data/shoes/ruby/lib/test/unit/assertions.rb +122 -0
  621. data/shoes/ruby/lib/test/unit/testcase.rb +12 -0
  622. data/shoes/ruby/lib/test/unit.rb +66 -0
  623. data/shoes/ruby/lib/thread.rb +367 -0
  624. data/shoes/ruby/lib/thwait.rb +168 -0
  625. data/shoes/ruby/lib/time.rb +869 -0
  626. data/shoes/ruby/lib/timeout.rb +108 -0
  627. data/shoes/ruby/lib/tmpdir.rb +138 -0
  628. data/shoes/ruby/lib/tracer.rb +166 -0
  629. data/shoes/ruby/lib/tsort.rb +290 -0
  630. data/shoes/ruby/lib/ubygems.rb +10 -0
  631. data/shoes/ruby/lib/un.rb +304 -0
  632. data/shoes/ruby/lib/uri/common.rb +727 -0
  633. data/shoes/ruby/lib/uri/ftp.rb +198 -0
  634. data/shoes/ruby/lib/uri/generic.rb +1128 -0
  635. data/shoes/ruby/lib/uri/http.rb +100 -0
  636. data/shoes/ruby/lib/uri/https.rb +20 -0
  637. data/shoes/ruby/lib/uri/ldap.rb +190 -0
  638. data/shoes/ruby/lib/uri/ldaps.rb +12 -0
  639. data/shoes/ruby/lib/uri/mailto.rb +266 -0
  640. data/shoes/ruby/lib/uri.rb +29 -0
  641. data/shoes/ruby/lib/weakref.rb +80 -0
  642. data/shoes/ruby/lib/webrick/accesslog.rb +75 -0
  643. data/shoes/ruby/lib/webrick/cgi.rb +260 -0
  644. data/shoes/ruby/lib/webrick/compat.rb +15 -0
  645. data/shoes/ruby/lib/webrick/config.rb +100 -0
  646. data/shoes/ruby/lib/webrick/cookie.rb +110 -0
  647. data/shoes/ruby/lib/webrick/htmlutils.rb +25 -0
  648. data/shoes/ruby/lib/webrick/httpauth/authenticator.rb +79 -0
  649. data/shoes/ruby/lib/webrick/httpauth/basicauth.rb +65 -0
  650. data/shoes/ruby/lib/webrick/httpauth/digestauth.rb +344 -0
  651. data/shoes/ruby/lib/webrick/httpauth/htdigest.rb +91 -0
  652. data/shoes/ruby/lib/webrick/httpauth/htgroup.rb +61 -0
  653. data/shoes/ruby/lib/webrick/httpauth/htpasswd.rb +83 -0
  654. data/shoes/ruby/lib/webrick/httpauth/userdb.rb +29 -0
  655. data/shoes/ruby/lib/webrick/httpauth.rb +45 -0
  656. data/shoes/ruby/lib/webrick/httpproxy.rb +288 -0
  657. data/shoes/ruby/lib/webrick/httprequest.rb +402 -0
  658. data/shoes/ruby/lib/webrick/httpresponse.rb +326 -0
  659. data/shoes/ruby/lib/webrick/https.rb +63 -0
  660. data/shoes/ruby/lib/webrick/httpserver.rb +217 -0
  661. data/shoes/ruby/lib/webrick/httpservlet/abstract.rb +70 -0
  662. data/shoes/ruby/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  663. data/shoes/ruby/lib/webrick/httpservlet/cgihandler.rb +110 -0
  664. data/shoes/ruby/lib/webrick/httpservlet/erbhandler.rb +54 -0
  665. data/shoes/ruby/lib/webrick/httpservlet/filehandler.rb +435 -0
  666. data/shoes/ruby/lib/webrick/httpservlet/prochandler.rb +33 -0
  667. data/shoes/ruby/lib/webrick/httpservlet.rb +22 -0
  668. data/shoes/ruby/lib/webrick/httpstatus.rb +132 -0
  669. data/shoes/ruby/lib/webrick/httputils.rb +392 -0
  670. data/shoes/ruby/lib/webrick/httpversion.rb +49 -0
  671. data/shoes/ruby/lib/webrick/log.rb +88 -0
  672. data/shoes/ruby/lib/webrick/server.rb +210 -0
  673. data/shoes/ruby/lib/webrick/ssl.rb +126 -0
  674. data/shoes/ruby/lib/webrick/utils.rb +175 -0
  675. data/shoes/ruby/lib/webrick/version.rb +13 -0
  676. data/shoes/ruby/lib/webrick.rb +29 -0
  677. data/shoes/ruby/lib/win32/registry.rb +832 -0
  678. data/shoes/ruby/lib/win32/resolv.rb +370 -0
  679. data/shoes/ruby/lib/win32/sspi.rb +330 -0
  680. data/shoes/ruby/lib/win32ole/property.rb +16 -0
  681. data/shoes/ruby/lib/xmlrpc/base64.rb +81 -0
  682. data/shoes/ruby/lib/xmlrpc/client.rb +625 -0
  683. data/shoes/ruby/lib/xmlrpc/config.rb +40 -0
  684. data/shoes/ruby/lib/xmlrpc/create.rb +290 -0
  685. data/shoes/ruby/lib/xmlrpc/datetime.rb +142 -0
  686. data/shoes/ruby/lib/xmlrpc/httpserver.rb +178 -0
  687. data/shoes/ruby/lib/xmlrpc/marshal.rb +76 -0
  688. data/shoes/ruby/lib/xmlrpc/parser.rb +813 -0
  689. data/shoes/ruby/lib/xmlrpc/server.rb +778 -0
  690. data/shoes/ruby/lib/xmlrpc/utils.rb +165 -0
  691. data/shoes/ruby/lib/yaml/baseemitter.rb +242 -0
  692. data/shoes/ruby/lib/yaml/basenode.rb +216 -0
  693. data/shoes/ruby/lib/yaml/constants.rb +45 -0
  694. data/shoes/ruby/lib/yaml/dbm.rb +111 -0
  695. data/shoes/ruby/lib/yaml/encoding.rb +33 -0
  696. data/shoes/ruby/lib/yaml/error.rb +34 -0
  697. data/shoes/ruby/lib/yaml/loader.rb +14 -0
  698. data/shoes/ruby/lib/yaml/rubytypes.rb +446 -0
  699. data/shoes/ruby/lib/yaml/store.rb +43 -0
  700. data/shoes/ruby/lib/yaml/stream.rb +40 -0
  701. data/shoes/ruby/lib/yaml/stringio.rb +83 -0
  702. data/shoes/ruby/lib/yaml/syck.rb +19 -0
  703. data/shoes/ruby/lib/yaml/tag.rb +91 -0
  704. data/shoes/ruby/lib/yaml/types.rb +192 -0
  705. data/shoes/ruby/lib/yaml/yamlnode.rb +54 -0
  706. data/shoes/ruby/lib/yaml/ypath.rb +52 -0
  707. data/shoes/ruby/lib/yaml.rb +440 -0
  708. data/shoes/samples/class-book.rb +43 -0
  709. data/shoes/samples/class-book.yaml +387 -0
  710. data/shoes/samples/expert-definr.rb +23 -0
  711. data/shoes/samples/expert-funnies.rb +51 -0
  712. data/shoes/samples/expert-irb.rb +112 -0
  713. data/shoes/samples/expert-minesweeper.rb +267 -0
  714. data/shoes/samples/expert-othello.rb +319 -0
  715. data/shoes/samples/expert-pong.rb +62 -0
  716. data/shoes/samples/expert-tankspank.rb +385 -0
  717. data/shoes/samples/good-arc.rb +37 -0
  718. data/shoes/samples/good-clock.rb +51 -0
  719. data/shoes/samples/good-follow.rb +26 -0
  720. data/shoes/samples/good-reminder.rb +174 -0
  721. data/shoes/samples/good-vjot.rb +56 -0
  722. data/shoes/samples/simple-accordion.rb +75 -0
  723. data/shoes/samples/simple-anim-shapes.rb +17 -0
  724. data/shoes/samples/simple-anim-text.rb +13 -0
  725. data/shoes/samples/simple-arc.rb +23 -0
  726. data/shoes/samples/simple-bounce.rb +24 -0
  727. data/shoes/samples/simple-calc.rb +70 -0
  728. data/shoes/samples/simple-control-sizes.rb +24 -0
  729. data/shoes/samples/simple-curve.rb +26 -0
  730. data/shoes/samples/simple-dialogs.rb +29 -0
  731. data/shoes/samples/simple-downloader.rb +27 -0
  732. data/shoes/samples/simple-draw.rb +13 -0
  733. data/shoes/samples/simple-editor.rb +28 -0
  734. data/shoes/samples/simple-form.rb +28 -0
  735. data/shoes/samples/simple-form.shy +0 -0
  736. data/shoes/samples/simple-mask.rb +21 -0
  737. data/shoes/samples/simple-menu.rb +31 -0
  738. data/shoes/samples/simple-menu1.rb +35 -0
  739. data/shoes/samples/simple-rubygems.rb +29 -0
  740. data/shoes/samples/simple-slide.rb +45 -0
  741. data/shoes/samples/simple-sphere.rb +28 -0
  742. data/shoes/samples/simple-timer.rb +13 -0
  743. data/shoes/samples/simple-video.rb +13 -0
  744. data/shoes/shoes +21 -0
  745. data/shoes/shoes.exe +0 -0
  746. data/shoes/shoes.exe.manifest +17 -0
  747. data/shoes/sqlite3.dll +0 -0
  748. data/shoes/static/Shoes.icns +0 -0
  749. data/shoes/static/Thumbs.db +0 -0
  750. data/shoes/static/app-icon.png +0 -0
  751. data/shoes/static/avatar.png +0 -0
  752. data/shoes/static/code_highlighter.js +188 -0
  753. data/shoes/static/code_highlighter_ruby.js +26 -0
  754. data/shoes/static/icon-debug.png +0 -0
  755. data/shoes/static/icon-error.png +0 -0
  756. data/shoes/static/icon-info.png +0 -0
  757. data/shoes/static/icon-warn.png +0 -0
  758. data/shoes/static/listbox_button1.png +0 -0
  759. data/shoes/static/listbox_button2.png +0 -0
  760. data/shoes/static/man-app.png +0 -0
  761. data/shoes/static/man-builds.png +0 -0
  762. data/shoes/static/man-editor-notepad.png +0 -0
  763. data/shoes/static/man-editor-osx.png +0 -0
  764. data/shoes/static/man-ele-background.png +0 -0
  765. data/shoes/static/man-ele-border.png +0 -0
  766. data/shoes/static/man-ele-button.png +0 -0
  767. data/shoes/static/man-ele-check.png +0 -0
  768. data/shoes/static/man-ele-editbox.png +0 -0
  769. data/shoes/static/man-ele-editline.png +0 -0
  770. data/shoes/static/man-ele-image.png +0 -0
  771. data/shoes/static/man-ele-listbox.png +0 -0
  772. data/shoes/static/man-ele-progress.png +0 -0
  773. data/shoes/static/man-ele-radio.png +0 -0
  774. data/shoes/static/man-ele-shape.png +0 -0
  775. data/shoes/static/man-ele-textblock.png +0 -0
  776. data/shoes/static/man-ele-video.png +0 -0
  777. data/shoes/static/man-intro-dmg.png +0 -0
  778. data/shoes/static/man-intro-exe.png +0 -0
  779. data/shoes/static/man-look-tiger.png +0 -0
  780. data/shoes/static/man-look-ubuntu.png +0 -0
  781. data/shoes/static/man-look-vista.png +0 -0
  782. data/shoes/static/man-run-osx.png +0 -0
  783. data/shoes/static/man-run-vista.png +0 -0
  784. data/shoes/static/man-run-xp.png +0 -0
  785. data/shoes/static/man-shot1.png +0 -0
  786. data/shoes/static/manual-en.txt +2783 -0
  787. data/shoes/static/manual-ja.txt +2780 -0
  788. data/shoes/static/manual.css +167 -0
  789. data/shoes/static/menu-corner1.png +0 -0
  790. data/shoes/static/menu-corner2.png +0 -0
  791. data/shoes/static/menu-gray.png +0 -0
  792. data/shoes/static/menu-left.png +0 -0
  793. data/shoes/static/menu-right.png +0 -0
  794. data/shoes/static/menu-top.png +0 -0
  795. data/shoes/static/shoes-dmg.jpg +0 -0
  796. data/shoes/static/shoes-icon-blue.png +0 -0
  797. data/shoes/static/shoes-icon.png +0 -0
  798. data/shoes/static/shoes-manual-apps.gif +0 -0
  799. data/shoes/static/stripe.png +0 -0
  800. data/shoes/static/stubs/blank.exe +0 -0
  801. data/shoes/static/stubs/blank.hfz +0 -0
  802. data/shoes/static/stubs/blank.run +375 -0
  803. data/shoes/static/stubs/cocoa-install +0 -0
  804. data/shoes/static/stubs/sh-install +48 -0
  805. data/shoes/static/tutor-back.png +0 -0
  806. data/shoes/zlib.dll +0 -0
  807. data/shoes/zlib1.dll +0 -0
  808. metadata +887 -0
@@ -0,0 +1,1778 @@
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
+ families = Hash[*infos.collect { |af, *_| af }.uniq.zip([]).flatten]
846
+ return TCPServer.open('0.0.0.0', port) if families.has_key?('AF_INET')
847
+ return TCPServer.open('::', port) if families.has_key?('AF_INET6')
848
+ return TCPServer.open(port)
849
+ end
850
+
851
+ # Open a server listening for connections at +uri+ using
852
+ # configuration +config+.
853
+ def self.open_server(uri, config)
854
+ uri = 'druby://:0' unless uri
855
+ host, port, opt = parse_uri(uri)
856
+ config = {:tcp_original_host => host}.update(config)
857
+ if host.size == 0
858
+ host = getservername
859
+ soc = open_server_inaddr_any(host, port)
860
+ else
861
+ soc = TCPServer.open(host, port)
862
+ end
863
+ port = soc.addr[1] if port == 0
864
+ config[:tcp_port] = port
865
+ uri = "druby://#{host}:#{port}"
866
+ self.new(uri, soc, config)
867
+ end
868
+
869
+ # Parse +uri+ into a [uri, option] pair.
870
+ def self.uri_option(uri, config)
871
+ host, port, option = parse_uri(uri)
872
+ return "druby://#{host}:#{port}", option
873
+ end
874
+
875
+ # Create a new DRbTCPSocket instance.
876
+ #
877
+ # +uri+ is the URI we are connected to.
878
+ # +soc+ is the tcp socket we are bound to. +config+ is our
879
+ # configuration.
880
+ def initialize(uri, soc, config={})
881
+ @uri = uri
882
+ @socket = soc
883
+ @config = config
884
+ @acl = config[:tcp_acl]
885
+ @msg = DRbMessage.new(config)
886
+ set_sockopt(@socket)
887
+ end
888
+
889
+ # Get the URI that we are connected to.
890
+ attr_reader :uri
891
+
892
+ # Get the address of our TCP peer (the other end of the socket
893
+ # we are bound to.
894
+ def peeraddr
895
+ @socket.peeraddr
896
+ end
897
+
898
+ # Get the socket.
899
+ def stream; @socket; end
900
+
901
+ # On the client side, send a request to the server.
902
+ def send_request(ref, msg_id, arg, b)
903
+ @msg.send_request(stream, ref, msg_id, arg, b)
904
+ end
905
+
906
+ # On the server side, receive a request from the client.
907
+ def recv_request
908
+ @msg.recv_request(stream)
909
+ end
910
+
911
+ # On the server side, send a reply to the client.
912
+ def send_reply(succ, result)
913
+ @msg.send_reply(stream, succ, result)
914
+ end
915
+
916
+ # On the client side, receive a reply from the server.
917
+ def recv_reply
918
+ @msg.recv_reply(stream)
919
+ end
920
+
921
+ public
922
+
923
+ # Close the connection.
924
+ #
925
+ # If this is an instance returned by #open_server, then this stops
926
+ # listening for new connections altogether. If this is an instance
927
+ # returned by #open or by #accept, then it closes this particular
928
+ # client-server session.
929
+ def close
930
+ if @socket
931
+ @socket.close
932
+ @socket = nil
933
+ end
934
+ end
935
+
936
+ # On the server side, for an instance returned by #open_server,
937
+ # accept a client connection and return a new instance to handle
938
+ # the server's side of this client-server session.
939
+ def accept
940
+ while true
941
+ s = @socket.accept
942
+ break if (@acl ? @acl.allow_socket?(s) : true)
943
+ s.close
944
+ end
945
+ if @config[:tcp_original_host].to_s.size == 0
946
+ uri = "druby://#{s.addr[3]}:#{@config[:tcp_port]}"
947
+ else
948
+ uri = @uri
949
+ end
950
+ self.class.new(uri, s, @config)
951
+ end
952
+
953
+ # Check to see if this connection is alive.
954
+ def alive?
955
+ return false unless @socket
956
+ if IO.select([@socket], nil, nil, 0)
957
+ close
958
+ return false
959
+ end
960
+ true
961
+ end
962
+
963
+ def set_sockopt(soc) # :nodoc:
964
+ soc.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
965
+ soc.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
966
+ end
967
+ end
968
+
969
+ module DRbProtocol
970
+ @protocol = [DRbTCPSocket] # default
971
+ end
972
+
973
+ class DRbURIOption # :nodoc: I don't understand the purpose of this class...
974
+ def initialize(option)
975
+ @option = option.to_s
976
+ end
977
+ attr :option
978
+ def to_s; @option; end
979
+
980
+ def ==(other)
981
+ return false unless DRbURIOption === other
982
+ @option == other.option
983
+ end
984
+
985
+ def hash
986
+ @option.hash
987
+ end
988
+
989
+ alias eql? ==
990
+ end
991
+
992
+ # Object wrapping a reference to a remote drb object.
993
+ #
994
+ # Method calls on this object are relayed to the remote
995
+ # object that this object is a stub for.
996
+ class DRbObject
997
+
998
+ # Unmarshall a marshalled DRbObject.
999
+ #
1000
+ # If the referenced object is located within the local server, then
1001
+ # the object itself is returned. Otherwise, a new DRbObject is
1002
+ # created to act as a stub for the remote referenced object.
1003
+ def self._load(s)
1004
+ uri, ref = Marshal.load(s)
1005
+
1006
+ if DRb.here?(uri)
1007
+ obj = DRb.to_obj(ref)
1008
+ if ((! obj.tainted?) && Thread.current[:drb_untaint])
1009
+ Thread.current[:drb_untaint].push(obj)
1010
+ end
1011
+ return obj
1012
+ end
1013
+
1014
+ self.new_with(uri, ref)
1015
+ end
1016
+
1017
+ def self.new_with(uri, ref)
1018
+ it = self.allocate
1019
+ it.instance_variable_set('@uri', uri)
1020
+ it.instance_variable_set('@ref', ref)
1021
+ it
1022
+ end
1023
+
1024
+ # Create a new DRbObject from a URI alone.
1025
+ def self.new_with_uri(uri)
1026
+ self.new(nil, uri)
1027
+ end
1028
+
1029
+ # Marshall this object.
1030
+ #
1031
+ # The URI and ref of the object are marshalled.
1032
+ def _dump(lv)
1033
+ Marshal.dump([@uri, @ref])
1034
+ end
1035
+
1036
+ # Create a new remote object stub.
1037
+ #
1038
+ # +obj+ is the (local) object we want to create a stub for. Normally
1039
+ # this is +nil+. +uri+ is the URI of the remote object that this
1040
+ # will be a stub for.
1041
+ def initialize(obj, uri=nil)
1042
+ @uri = nil
1043
+ @ref = nil
1044
+ if obj.nil?
1045
+ return if uri.nil?
1046
+ @uri, option = DRbProtocol.uri_option(uri, DRb.config)
1047
+ @ref = DRbURIOption.new(option) unless option.nil?
1048
+ else
1049
+ @uri = uri ? uri : (DRb.uri rescue nil)
1050
+ @ref = obj ? DRb.to_id(obj) : nil
1051
+ end
1052
+ end
1053
+
1054
+ # Get the URI of the remote object.
1055
+ def __drburi
1056
+ @uri
1057
+ end
1058
+
1059
+ # Get the reference of the object, if local.
1060
+ def __drbref
1061
+ @ref
1062
+ end
1063
+
1064
+ undef :to_s
1065
+ undef :to_a if respond_to?(:to_a)
1066
+
1067
+ def respond_to?(msg_id, priv=false)
1068
+ case msg_id
1069
+ when :_dump
1070
+ true
1071
+ when :marshal_dump
1072
+ false
1073
+ else
1074
+ method_missing(:respond_to?, msg_id, priv)
1075
+ end
1076
+ end
1077
+
1078
+ # Routes method calls to the referenced object.
1079
+ def method_missing(msg_id, *a, &b)
1080
+ if DRb.here?(@uri)
1081
+ obj = DRb.to_obj(@ref)
1082
+ DRb.current_server.check_insecure_method(obj, msg_id)
1083
+ return obj.__send__(msg_id, *a, &b)
1084
+ end
1085
+
1086
+ succ, result = self.class.with_friend(@uri) do
1087
+ DRbConn.open(@uri) do |conn|
1088
+ conn.send_message(self, msg_id, a, b)
1089
+ end
1090
+ end
1091
+
1092
+ if succ
1093
+ return result
1094
+ elsif DRbUnknown === result
1095
+ raise result
1096
+ else
1097
+ bt = self.class.prepare_backtrace(@uri, result)
1098
+ result.set_backtrace(bt + caller)
1099
+ raise result
1100
+ end
1101
+ end
1102
+
1103
+ def self.with_friend(uri)
1104
+ friend = DRb.fetch_server(uri)
1105
+ return yield() unless friend
1106
+
1107
+ save = Thread.current['DRb']
1108
+ Thread.current['DRb'] = { 'server' => friend }
1109
+ return yield
1110
+ ensure
1111
+ Thread.current['DRb'] = save if friend
1112
+ end
1113
+
1114
+ def self.prepare_backtrace(uri, result)
1115
+ prefix = "(#{uri}) "
1116
+ bt = []
1117
+ result.backtrace.each do |x|
1118
+ break if /`__send__'$/ =~ x
1119
+ if /^\(druby:\/\// =~ x
1120
+ bt.push(x)
1121
+ else
1122
+ bt.push(prefix + x)
1123
+ end
1124
+ end
1125
+ bt
1126
+ end
1127
+
1128
+ def pretty_print(q) # :nodoc:
1129
+ q.pp_object(self)
1130
+ end
1131
+
1132
+ def pretty_print_cycle(q) # :nodoc:
1133
+ q.object_address_group(self) {
1134
+ q.breakable
1135
+ q.text '...'
1136
+ }
1137
+ end
1138
+ end
1139
+
1140
+ # Class handling the connection between a DRbObject and the
1141
+ # server the real object lives on.
1142
+ #
1143
+ # This class maintains a pool of connections, to reduce the
1144
+ # overhead of starting and closing down connections for each
1145
+ # method call.
1146
+ #
1147
+ # This class is used internally by DRbObject. The user does
1148
+ # not normally need to deal with it directly.
1149
+ class DRbConn
1150
+ POOL_SIZE = 16 # :nodoc:
1151
+ @mutex = Mutex.new
1152
+ @pool = []
1153
+
1154
+ def self.open(remote_uri) # :nodoc:
1155
+ begin
1156
+ conn = nil
1157
+
1158
+ @mutex.synchronize do
1159
+ #FIXME
1160
+ new_pool = []
1161
+ @pool.each do |c|
1162
+ if conn.nil? and c.uri == remote_uri
1163
+ conn = c if c.alive?
1164
+ else
1165
+ new_pool.push c
1166
+ end
1167
+ end
1168
+ @pool = new_pool
1169
+ end
1170
+
1171
+ conn = self.new(remote_uri) unless conn
1172
+ succ, result = yield(conn)
1173
+ return succ, result
1174
+
1175
+ ensure
1176
+ if conn
1177
+ if succ
1178
+ @mutex.synchronize do
1179
+ @pool.unshift(conn)
1180
+ @pool.pop.close while @pool.size > POOL_SIZE
1181
+ end
1182
+ else
1183
+ conn.close
1184
+ end
1185
+ end
1186
+ end
1187
+ end
1188
+
1189
+ def initialize(remote_uri) # :nodoc:
1190
+ @uri = remote_uri
1191
+ @protocol = DRbProtocol.open(remote_uri, DRb.config)
1192
+ end
1193
+ attr_reader :uri # :nodoc:
1194
+
1195
+ def send_message(ref, msg_id, arg, block) # :nodoc:
1196
+ @protocol.send_request(ref, msg_id, arg, block)
1197
+ @protocol.recv_reply
1198
+ end
1199
+
1200
+ def close # :nodoc:
1201
+ @protocol.close
1202
+ @protocol = nil
1203
+ end
1204
+
1205
+ def alive? # :nodoc:
1206
+ return false unless @protocol
1207
+ @protocol.alive?
1208
+ end
1209
+ end
1210
+
1211
+ # Class representing a drb server instance.
1212
+ #
1213
+ # A DRbServer must be running in the local process before any incoming
1214
+ # dRuby calls can be accepted, or any local objects can be passed as
1215
+ # dRuby references to remote processes, even if those local objects are
1216
+ # never actually called remotely. You do not need to start a DRbServer
1217
+ # in the local process if you are only making outgoing dRuby calls
1218
+ # passing marshalled parameters.
1219
+ #
1220
+ # Unless multiple servers are being used, the local DRbServer is normally
1221
+ # started by calling DRb.start_service.
1222
+ class DRbServer
1223
+ @@acl = nil
1224
+ @@idconv = DRbIdConv.new
1225
+ @@secondary_server = nil
1226
+ @@argc_limit = 256
1227
+ @@load_limit = 256 * 102400
1228
+ @@verbose = false
1229
+ @@safe_level = 0
1230
+
1231
+ # Set the default value for the :argc_limit option.
1232
+ #
1233
+ # See #new(). The initial default value is 256.
1234
+ def self.default_argc_limit(argc)
1235
+ @@argc_limit = argc
1236
+ end
1237
+
1238
+ # Set the default value for the :load_limit option.
1239
+ #
1240
+ # See #new(). The initial default value is 25 MB.
1241
+ def self.default_load_limit(sz)
1242
+ @@load_limit = sz
1243
+ end
1244
+
1245
+ # Set the default value for the :acl option.
1246
+ #
1247
+ # See #new(). The initial default value is nil.
1248
+ def self.default_acl(acl)
1249
+ @@acl = acl
1250
+ end
1251
+
1252
+ # Set the default value for the :id_conv option.
1253
+ #
1254
+ # See #new(). The initial default value is a DRbIdConv instance.
1255
+ def self.default_id_conv(idconv)
1256
+ @@idconv = idconv
1257
+ end
1258
+
1259
+ def self.default_safe_level(level)
1260
+ @@safe_level = level
1261
+ end
1262
+
1263
+ # Set the default value of the :verbose option.
1264
+ #
1265
+ # See #new(). The initial default value is false.
1266
+ def self.verbose=(on)
1267
+ @@verbose = on
1268
+ end
1269
+
1270
+ # Get the default value of the :verbose option.
1271
+ def self.verbose
1272
+ @@verbose
1273
+ end
1274
+
1275
+ def self.make_config(hash={}) # :nodoc:
1276
+ default_config = {
1277
+ :idconv => @@idconv,
1278
+ :verbose => @@verbose,
1279
+ :tcp_acl => @@acl,
1280
+ :load_limit => @@load_limit,
1281
+ :argc_limit => @@argc_limit,
1282
+ :safe_level => @@safe_level
1283
+ }
1284
+ default_config.update(hash)
1285
+ end
1286
+
1287
+ # Create a new DRbServer instance.
1288
+ #
1289
+ # +uri+ is the URI to bind to. This is normally of the form
1290
+ # 'druby://<hostname>:<port>' where <hostname> is a hostname of
1291
+ # the local machine. If nil, then the system's default hostname
1292
+ # will be bound to, on a port selected by the system; these value
1293
+ # can be retrieved from the +uri+ attribute. 'druby:' specifies
1294
+ # the default dRuby transport protocol: another protocol, such
1295
+ # as 'drbunix:', can be specified instead.
1296
+ #
1297
+ # +front+ is the front object for the server, that is, the object
1298
+ # to which remote method calls on the server will be passed. If
1299
+ # nil, then the server will not accept remote method calls.
1300
+ #
1301
+ # If +config_or_acl+ is a hash, it is the configuration to
1302
+ # use for this server. The following options are recognised:
1303
+ #
1304
+ # :idconv :: an id-to-object conversion object. This defaults
1305
+ # to an instance of the class DRb::DRbIdConv.
1306
+ # :verbose :: if true, all unsuccessful remote calls on objects
1307
+ # in the server will be logged to $stdout. false
1308
+ # by default.
1309
+ # :tcp_acl :: the access control list for this server. See
1310
+ # the ACL class from the main dRuby distribution.
1311
+ # :load_limit :: the maximum message size in bytes accepted by
1312
+ # the server. Defaults to 25 MB (26214400).
1313
+ # :argc_limit :: the maximum number of arguments to a remote
1314
+ # method accepted by the server. Defaults to
1315
+ # 256.
1316
+ #
1317
+ # The default values of these options can be modified on
1318
+ # a class-wide basis by the class methods #default_argc_limit,
1319
+ # #default_load_limit, #default_acl, #default_id_conv,
1320
+ # and #verbose=
1321
+ #
1322
+ # If +config_or_acl+ is not a hash, but is not nil, it is
1323
+ # assumed to be the access control list for this server.
1324
+ # See the :tcp_acl option for more details.
1325
+ #
1326
+ # If no other server is currently set as the primary server,
1327
+ # this will become the primary server.
1328
+ #
1329
+ # The server will immediately start running in its own thread.
1330
+ def initialize(uri=nil, front=nil, config_or_acl=nil)
1331
+ if Hash === config_or_acl
1332
+ config = config_or_acl.dup
1333
+ else
1334
+ acl = config_or_acl || @@acl
1335
+ config = {
1336
+ :tcp_acl => acl
1337
+ }
1338
+ end
1339
+
1340
+ @config = self.class.make_config(config)
1341
+
1342
+ @protocol = DRbProtocol.open_server(uri, @config)
1343
+ @uri = @protocol.uri
1344
+
1345
+ @front = front
1346
+ @idconv = @config[:idconv]
1347
+ @safe_level = @config[:safe_level]
1348
+
1349
+ @grp = ThreadGroup.new
1350
+ @thread = run
1351
+
1352
+ DRb.regist_server(self)
1353
+ end
1354
+
1355
+ # The URI of this DRbServer.
1356
+ attr_reader :uri
1357
+
1358
+ # The main thread of this DRbServer.
1359
+ #
1360
+ # This is the thread that listens for and accepts connections
1361
+ # from clients, not that handles each client's request-response
1362
+ # session.
1363
+ attr_reader :thread
1364
+
1365
+ # The front object of the DRbServer.
1366
+ #
1367
+ # This object receives remote method calls made on the server's
1368
+ # URI alone, with an object id.
1369
+ attr_reader :front
1370
+
1371
+ # The configuration of this DRbServer
1372
+ attr_reader :config
1373
+
1374
+ attr_reader :safe_level
1375
+
1376
+ # Set whether to operate in verbose mode.
1377
+ #
1378
+ # In verbose mode, failed calls are logged to stdout.
1379
+ def verbose=(v); @config[:verbose]=v; end
1380
+
1381
+ # Get whether the server is in verbose mode.
1382
+ #
1383
+ # In verbose mode, failed calls are logged to stdout.
1384
+ def verbose; @config[:verbose]; end
1385
+
1386
+ # Is this server alive?
1387
+ def alive?
1388
+ @thread.alive?
1389
+ end
1390
+
1391
+ # Stop this server.
1392
+ def stop_service
1393
+ DRb.remove_server(self)
1394
+ if Thread.current['DRb'] && Thread.current['DRb']['server'] == self
1395
+ Thread.current['DRb']['stop_service'] = true
1396
+ else
1397
+ @thread.kill
1398
+ end
1399
+ end
1400
+
1401
+ # Convert a dRuby reference to the local object it refers to.
1402
+ def to_obj(ref)
1403
+ return front if ref.nil?
1404
+ return front[ref.to_s] if DRbURIOption === ref
1405
+ @idconv.to_obj(ref)
1406
+ end
1407
+
1408
+ # Convert a local object to a dRuby reference.
1409
+ def to_id(obj)
1410
+ return nil if obj.__id__ == front.__id__
1411
+ @idconv.to_id(obj)
1412
+ end
1413
+
1414
+ private
1415
+ def kill_sub_thread
1416
+ Thread.new do
1417
+ grp = ThreadGroup.new
1418
+ grp.add(Thread.current)
1419
+ list = @grp.list
1420
+ while list.size > 0
1421
+ list.each do |th|
1422
+ th.kill if th.alive?
1423
+ end
1424
+ list = @grp.list
1425
+ end
1426
+ end
1427
+ end
1428
+
1429
+ def run
1430
+ Thread.start do
1431
+ begin
1432
+ while true
1433
+ main_loop
1434
+ end
1435
+ ensure
1436
+ @protocol.close if @protocol
1437
+ kill_sub_thread
1438
+ end
1439
+ end
1440
+ end
1441
+
1442
+ # List of insecure methods.
1443
+ #
1444
+ # These methods are not callable via dRuby.
1445
+ INSECURE_METHOD = [
1446
+ :__send__
1447
+ ]
1448
+
1449
+ # Has a method been included in the list of insecure methods?
1450
+ def insecure_method?(msg_id)
1451
+ INSECURE_METHOD.include?(msg_id)
1452
+ end
1453
+
1454
+ # Coerce an object to a string, providing our own representation if
1455
+ # to_s is not defined for the object.
1456
+ def any_to_s(obj)
1457
+ obj.to_s + ":#{obj.class}"
1458
+ rescue
1459
+ sprintf("#<%s:0x%lx>", obj.class, obj.__id__)
1460
+ end
1461
+
1462
+ # Check that a method is callable via dRuby.
1463
+ #
1464
+ # +obj+ is the object we want to invoke the method on. +msg_id+ is the
1465
+ # method name, as a Symbol.
1466
+ #
1467
+ # If the method is an insecure method (see #insecure_method?) a
1468
+ # SecurityError is thrown. If the method is private or undefined,
1469
+ # a NameError is thrown.
1470
+ def check_insecure_method(obj, msg_id)
1471
+ return true if Proc === obj && msg_id == :__drb_yield
1472
+ raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
1473
+ raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
1474
+
1475
+ if obj.private_methods.include?(msg_id)
1476
+ desc = any_to_s(obj)
1477
+ raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
1478
+ elsif obj.protected_methods.include?(msg_id)
1479
+ desc = any_to_s(obj)
1480
+ raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
1481
+ else
1482
+ true
1483
+ end
1484
+ end
1485
+ public :check_insecure_method
1486
+
1487
+ class InvokeMethod # :nodoc:
1488
+ def initialize(drb_server, client)
1489
+ @drb_server = drb_server
1490
+ @safe_level = drb_server.safe_level
1491
+ @client = client
1492
+ end
1493
+
1494
+ def perform
1495
+ @result = nil
1496
+ @succ = false
1497
+ setup_message
1498
+
1499
+ if $SAFE < @safe_level
1500
+ info = Thread.current['DRb']
1501
+ if @block
1502
+ @result = Thread.new {
1503
+ Thread.current['DRb'] = info
1504
+ $SAFE = @safe_level
1505
+ perform_with_block
1506
+ }.value
1507
+ else
1508
+ @result = Thread.new {
1509
+ Thread.current['DRb'] = info
1510
+ $SAFE = @safe_level
1511
+ perform_without_block
1512
+ }.value
1513
+ end
1514
+ else
1515
+ if @block
1516
+ @result = perform_with_block
1517
+ else
1518
+ @result = perform_without_block
1519
+ end
1520
+ end
1521
+ @succ = true
1522
+ if @msg_id == :to_ary && @result.class == Array
1523
+ @result = DRbArray.new(@result)
1524
+ end
1525
+ return @succ, @result
1526
+ rescue StandardError, ScriptError, Interrupt
1527
+ @result = $!
1528
+ return @succ, @result
1529
+ end
1530
+
1531
+ private
1532
+ def init_with_client
1533
+ obj, msg, argv, block = @client.recv_request
1534
+ @obj = obj
1535
+ @msg_id = msg.intern
1536
+ @argv = argv
1537
+ @block = block
1538
+ end
1539
+
1540
+ def check_insecure_method
1541
+ @drb_server.check_insecure_method(@obj, @msg_id)
1542
+ end
1543
+
1544
+ def setup_message
1545
+ init_with_client
1546
+ check_insecure_method
1547
+ end
1548
+
1549
+ def perform_without_block
1550
+ if Proc === @obj && @msg_id == :__drb_yield
1551
+ if @argv.size == 1
1552
+ ary = @argv
1553
+ else
1554
+ ary = [@argv]
1555
+ end
1556
+ ary.collect(&@obj)[0]
1557
+ else
1558
+ @obj.__send__(@msg_id, *@argv)
1559
+ end
1560
+ end
1561
+
1562
+ end
1563
+
1564
+ if RUBY_VERSION >= '1.8'
1565
+ require 'drb/invokemethod'
1566
+ class InvokeMethod
1567
+ include InvokeMethod18Mixin
1568
+ end
1569
+ else
1570
+ require 'drb/invokemethod16'
1571
+ class InvokeMethod
1572
+ include InvokeMethod16Mixin
1573
+ end
1574
+ end
1575
+
1576
+ # The main loop performed by a DRbServer's internal thread.
1577
+ #
1578
+ # Accepts a connection from a client, and starts up its own
1579
+ # thread to handle it. This thread loops, receiving requests
1580
+ # from the client, invoking them on a local object, and
1581
+ # returning responses, until the client closes the connection
1582
+ # or a local method call fails.
1583
+ def main_loop
1584
+ Thread.start(@protocol.accept) do |client|
1585
+ @grp.add Thread.current
1586
+ Thread.current['DRb'] = { 'client' => client ,
1587
+ 'server' => self }
1588
+ loop do
1589
+ begin
1590
+ succ = false
1591
+ invoke_method = InvokeMethod.new(self, client)
1592
+ succ, result = invoke_method.perform
1593
+ if !succ && verbose
1594
+ p result
1595
+ result.backtrace.each do |x|
1596
+ puts x
1597
+ end
1598
+ end
1599
+ client.send_reply(succ, result) rescue nil
1600
+ ensure
1601
+ client.close unless succ
1602
+ if Thread.current['DRb']['stop_service']
1603
+ Thread.new { stop_service }
1604
+ end
1605
+ break unless succ
1606
+ end
1607
+ end
1608
+ end
1609
+ end
1610
+ end
1611
+
1612
+ @primary_server = nil
1613
+
1614
+ # Start a dRuby server locally.
1615
+ #
1616
+ # The new dRuby server will become the primary server, even
1617
+ # if another server is currently the primary server.
1618
+ #
1619
+ # +uri+ is the URI for the server to bind to. If nil,
1620
+ # the server will bind to random port on the default local host
1621
+ # name and use the default dRuby protocol.
1622
+ #
1623
+ # +front+ is the server's front object. This may be nil.
1624
+ #
1625
+ # +config+ is the configuration for the new server. This may
1626
+ # be nil.
1627
+ #
1628
+ # See DRbServer::new.
1629
+ def start_service(uri=nil, front=nil, config=nil)
1630
+ @primary_server = DRbServer.new(uri, front, config)
1631
+ end
1632
+ module_function :start_service
1633
+
1634
+ # The primary local dRuby server.
1635
+ #
1636
+ # This is the server created by the #start_service call.
1637
+ attr_accessor :primary_server
1638
+ module_function :primary_server=, :primary_server
1639
+
1640
+ # Get the 'current' server.
1641
+ #
1642
+ # In the context of execution taking place within the main
1643
+ # thread of a dRuby server (typically, as a result of a remote
1644
+ # call on the server or one of its objects), the current
1645
+ # server is that server. Otherwise, the current server is
1646
+ # the primary server.
1647
+ #
1648
+ # If the above rule fails to find a server, a DRbServerNotFound
1649
+ # error is raised.
1650
+ def current_server
1651
+ drb = Thread.current['DRb']
1652
+ server = (drb && drb['server']) ? drb['server'] : @primary_server
1653
+ raise DRbServerNotFound unless server
1654
+ return server
1655
+ end
1656
+ module_function :current_server
1657
+
1658
+ # Stop the local dRuby server.
1659
+ #
1660
+ # This operates on the primary server. If there is no primary
1661
+ # server currently running, it is a noop.
1662
+ def stop_service
1663
+ @primary_server.stop_service if @primary_server
1664
+ @primary_server = nil
1665
+ end
1666
+ module_function :stop_service
1667
+
1668
+ # Get the URI defining the local dRuby space.
1669
+ #
1670
+ # This is the URI of the current server. See #current_server.
1671
+ def uri
1672
+ drb = Thread.current['DRb']
1673
+ client = (drb && drb['client'])
1674
+ if client
1675
+ uri = client.uri
1676
+ return uri if uri
1677
+ end
1678
+ current_server.uri
1679
+ end
1680
+ module_function :uri
1681
+
1682
+ # Is +uri+ the URI for the current local server?
1683
+ def here?(uri)
1684
+ (current_server.uri rescue nil) == uri
1685
+ end
1686
+ module_function :here?
1687
+
1688
+ # Get the configuration of the current server.
1689
+ #
1690
+ # If there is no current server, this returns the default configuration.
1691
+ # See #current_server and DRbServer::make_config.
1692
+ def config
1693
+ current_server.config
1694
+ rescue
1695
+ DRbServer.make_config
1696
+ end
1697
+ module_function :config
1698
+
1699
+ # Get the front object of the current server.
1700
+ #
1701
+ # This raises a DRbServerNotFound error if there is no current server.
1702
+ # See #current_server.
1703
+ def front
1704
+ current_server.front
1705
+ end
1706
+ module_function :front
1707
+
1708
+ # Convert a reference into an object using the current server.
1709
+ #
1710
+ # This raises a DRbServerNotFound error if there is no current server.
1711
+ # See #current_server.
1712
+ def to_obj(ref)
1713
+ current_server.to_obj(ref)
1714
+ end
1715
+
1716
+ # Get a reference id for an object using the current server.
1717
+ #
1718
+ # This raises a DRbServerNotFound error if there is no current server.
1719
+ # See #current_server.
1720
+ def to_id(obj)
1721
+ current_server.to_id(obj)
1722
+ end
1723
+ module_function :to_id
1724
+ module_function :to_obj
1725
+
1726
+ # Get the thread of the primary server.
1727
+ #
1728
+ # This returns nil if there is no primary server. See #primary_server.
1729
+ def thread
1730
+ @primary_server ? @primary_server.thread : nil
1731
+ end
1732
+ module_function :thread
1733
+
1734
+ # Set the default id conv object.
1735
+ #
1736
+ # See DRbServer#default_id_conv.
1737
+ def install_id_conv(idconv)
1738
+ DRbServer.default_id_conv(idconv)
1739
+ end
1740
+ module_function :install_id_conv
1741
+
1742
+ # Set the default acl.
1743
+ #
1744
+ # See DRb::DRbServer.default_acl.
1745
+ def install_acl(acl)
1746
+ DRbServer.default_acl(acl)
1747
+ end
1748
+ module_function :install_acl
1749
+
1750
+ @mutex = Mutex.new
1751
+ def mutex
1752
+ @mutex
1753
+ end
1754
+ module_function :mutex
1755
+
1756
+ @server = {}
1757
+ def regist_server(server)
1758
+ @server[server.uri] = server
1759
+ mutex.synchronize do
1760
+ @primary_server = server unless @primary_server
1761
+ end
1762
+ end
1763
+ module_function :regist_server
1764
+
1765
+ def remove_server(server)
1766
+ @server.delete(server.uri)
1767
+ end
1768
+ module_function :remove_server
1769
+
1770
+ def fetch_server(uri)
1771
+ @server[uri]
1772
+ end
1773
+ module_function :fetch_server
1774
+ end
1775
+
1776
+ DRbObject = DRb::DRbObject
1777
+ DRbUndumped = DRb::DRbUndumped
1778
+ DRbIdConv = DRb::DRbIdConv