mack-notifier 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. data/lib/gems.rb +13 -0
  2. data/lib/gems/tmail-1.2.3.1/ext/Makefile +20 -0
  3. data/lib/gems/tmail-1.2.3.1/ext/tmailscanner/tmail/MANIFEST +4 -0
  4. data/lib/gems/tmail-1.2.3.1/ext/tmailscanner/tmail/depend +1 -0
  5. data/lib/gems/tmail-1.2.3.1/ext/tmailscanner/tmail/extconf.rb +33 -0
  6. data/lib/gems/tmail-1.2.3.1/ext/tmailscanner/tmail/tmailscanner.c +583 -0
  7. data/lib/gems/tmail-1.2.3.1/lib/tmail.rb +5 -0
  8. data/lib/gems/tmail-1.2.3.1/lib/tmail/Makefile +18 -0
  9. data/lib/gems/tmail-1.2.3.1/lib/tmail/address.rb +426 -0
  10. data/lib/gems/tmail-1.2.3.1/lib/tmail/attachments.rb +46 -0
  11. data/lib/gems/tmail-1.2.3.1/lib/tmail/base64.rb +46 -0
  12. data/lib/gems/tmail-1.2.3.1/lib/tmail/compat.rb +41 -0
  13. data/lib/gems/tmail-1.2.3.1/lib/tmail/config.rb +67 -0
  14. data/lib/gems/tmail-1.2.3.1/lib/tmail/core_extensions.rb +63 -0
  15. data/lib/gems/tmail-1.2.3.1/lib/tmail/encode.rb +581 -0
  16. data/lib/gems/tmail-1.2.3.1/lib/tmail/header.rb +960 -0
  17. data/lib/gems/tmail-1.2.3.1/lib/tmail/index.rb +9 -0
  18. data/lib/gems/tmail-1.2.3.1/lib/tmail/interface.rb +1125 -0
  19. data/lib/gems/tmail-1.2.3.1/lib/tmail/loader.rb +3 -0
  20. data/lib/gems/tmail-1.2.3.1/lib/tmail/mail.rb +578 -0
  21. data/lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb +495 -0
  22. data/lib/gems/tmail-1.2.3.1/lib/tmail/main.rb +6 -0
  23. data/lib/gems/tmail-1.2.3.1/lib/tmail/mbox.rb +3 -0
  24. data/lib/gems/tmail-1.2.3.1/lib/tmail/net.rb +248 -0
  25. data/lib/gems/tmail-1.2.3.1/lib/tmail/obsolete.rb +132 -0
  26. data/lib/gems/tmail-1.2.3.1/lib/tmail/parser.rb +1476 -0
  27. data/lib/gems/tmail-1.2.3.1/lib/tmail/parser.y +381 -0
  28. data/lib/gems/tmail-1.2.3.1/lib/tmail/port.rb +379 -0
  29. data/lib/gems/tmail-1.2.3.1/lib/tmail/quoting.rb +118 -0
  30. data/lib/gems/tmail-1.2.3.1/lib/tmail/require_arch.rb +58 -0
  31. data/lib/gems/tmail-1.2.3.1/lib/tmail/scanner.rb +49 -0
  32. data/lib/gems/tmail-1.2.3.1/lib/tmail/scanner_r.rb +261 -0
  33. data/lib/gems/tmail-1.2.3.1/lib/tmail/stringio.rb +280 -0
  34. data/lib/gems/tmail-1.2.3.1/lib/tmail/utils.rb +337 -0
  35. data/lib/gems/tmail-1.2.3.1/lib/tmail/version.rb +39 -0
  36. data/lib/gems/tmail-1.2.3.1/meta/MANIFEST +128 -0
  37. data/lib/gems/tmail-1.2.3.1/meta/VERSION +1 -0
  38. data/lib/gems/tmail-1.2.3.1/meta/project.yaml +30 -0
  39. data/lib/gems/tmail-1.2.3.1/meta/unixname +1 -0
  40. data/lib/gems/validatable-1.6.7/README +118 -0
  41. data/lib/gems/validatable-1.6.7/lib/child_validation.rb +15 -0
  42. data/lib/gems/validatable-1.6.7/lib/errors.rb +74 -0
  43. data/lib/gems/validatable-1.6.7/lib/included_validation.rb +9 -0
  44. data/lib/gems/validatable-1.6.7/lib/macros.rb +283 -0
  45. data/lib/gems/validatable-1.6.7/lib/object_extension.rb +21 -0
  46. data/lib/gems/validatable-1.6.7/lib/requireable.rb +26 -0
  47. data/lib/gems/validatable-1.6.7/lib/understandable.rb +31 -0
  48. data/lib/gems/validatable-1.6.7/lib/validatable.rb +19 -0
  49. data/lib/gems/validatable-1.6.7/lib/validatable_class_methods.rb +85 -0
  50. data/lib/gems/validatable-1.6.7/lib/validatable_instance_methods.rb +106 -0
  51. data/lib/gems/validatable-1.6.7/lib/validations/validates_acceptance_of.rb +11 -0
  52. data/lib/gems/validatable-1.6.7/lib/validations/validates_confirmation_of.rb +15 -0
  53. data/lib/gems/validatable-1.6.7/lib/validations/validates_each.rb +14 -0
  54. data/lib/gems/validatable-1.6.7/lib/validations/validates_format_of.rb +13 -0
  55. data/lib/gems/validatable-1.6.7/lib/validations/validates_length_of.rb +25 -0
  56. data/lib/gems/validatable-1.6.7/lib/validations/validates_numericality_of.rb +16 -0
  57. data/lib/gems/validatable-1.6.7/lib/validations/validates_presence_of.rb +13 -0
  58. data/lib/gems/validatable-1.6.7/lib/validations/validates_true_for.rb +13 -0
  59. data/lib/gems/validatable-1.6.7/lib/validations/validation_base.rb +88 -0
  60. data/lib/gems/validatable-1.6.7/rakefile.rb +50 -0
  61. data/lib/gems/validatable-1.6.7/test/all_tests.rb +1 -0
  62. data/lib/gems/validatable-1.6.7/test/functional/validatable_test.rb +437 -0
  63. data/lib/gems/validatable-1.6.7/test/functional/validates_acceptance_of_test.rb +16 -0
  64. data/lib/gems/validatable-1.6.7/test/functional/validates_confirmation_of_test.rb +56 -0
  65. data/lib/gems/validatable-1.6.7/test/functional/validates_each_test.rb +14 -0
  66. data/lib/gems/validatable-1.6.7/test/functional/validates_format_of_test.rb +34 -0
  67. data/lib/gems/validatable-1.6.7/test/functional/validates_length_of_test.rb +64 -0
  68. data/lib/gems/validatable-1.6.7/test/functional/validates_numericality_of_test.rb +57 -0
  69. data/lib/gems/validatable-1.6.7/test/functional/validates_presence_of_test.rb +16 -0
  70. data/lib/gems/validatable-1.6.7/test/functional/validates_true_for_test.rb +27 -0
  71. data/lib/gems/validatable-1.6.7/test/test_helper.rb +33 -0
  72. data/lib/gems/validatable-1.6.7/test/unit/errors_test.rb +64 -0
  73. data/lib/gems/validatable-1.6.7/test/unit/understandable_test.rb +19 -0
  74. data/lib/gems/validatable-1.6.7/test/unit/validatable_test.rb +38 -0
  75. data/lib/gems/validatable-1.6.7/test/unit/validates_acceptance_of_test.rb +21 -0
  76. data/lib/gems/validatable-1.6.7/test/unit/validates_confirmation_of_test.rb +64 -0
  77. data/lib/gems/validatable-1.6.7/test/unit/validates_format_of_test.rb +34 -0
  78. data/lib/gems/validatable-1.6.7/test/unit/validates_length_of_test.rb +75 -0
  79. data/lib/gems/validatable-1.6.7/test/unit/validates_numericality_of_test.rb +52 -0
  80. data/lib/gems/validatable-1.6.7/test/unit/validates_presence_of_test.rb +25 -0
  81. data/lib/gems/validatable-1.6.7/test/unit/validates_true_for_test.rb +29 -0
  82. data/lib/gems/validatable-1.6.7/test/unit/validation_base_test.rb +52 -0
  83. data/lib/gems/xmpp4r-0.4/CHANGELOG +83 -0
  84. data/lib/gems/xmpp4r-0.4/COPYING +340 -0
  85. data/lib/gems/xmpp4r-0.4/LICENSE +59 -0
  86. data/lib/gems/xmpp4r-0.4/README.rdoc +110 -0
  87. data/lib/gems/xmpp4r-0.4/README_ruby19.txt +43 -0
  88. data/lib/gems/xmpp4r-0.4/Rakefile +262 -0
  89. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/adventure/README +56 -0
  90. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
  91. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
  92. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
  93. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
  94. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/adventure/world.rb +424 -0
  95. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
  96. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/fileserve.rb +346 -0
  97. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
  98. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
  99. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/migrate.rb +88 -0
  100. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
  101. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
  102. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
  103. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/recvfile.rb +84 -0
  104. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +129 -0
  105. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
  106. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
  107. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
  108. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
  109. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
  110. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/versionpoll.rb +90 -0
  111. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/xmpping.rb +146 -0
  112. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +14 -0
  113. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
  114. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/client.rb +70 -0
  115. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/component.rb +11 -0
  116. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/echo.rb +37 -0
  117. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
  118. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/mass_sender.rb +68 -0
  119. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +12 -0
  120. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/mucinfo.rb +41 -0
  121. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +82 -0
  122. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/register.rb +42 -0
  123. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
  124. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/roster.rb +44 -0
  125. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
  126. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
  127. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/rosterwatch.rb +171 -0
  128. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/send_vcard.rb +67 -0
  129. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
  130. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
  131. data/lib/gems/xmpp4r-0.4/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
  132. data/lib/gems/xmpp4r-0.4/lib/xmpp4r.rb +116 -0
  133. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/base64.rb +32 -0
  134. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams.rb +15 -0
  135. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/filetransfer.rb +319 -0
  136. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/ibb/base.rb +257 -0
  137. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +31 -0
  138. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/ibb/target.rb +47 -0
  139. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +152 -0
  140. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +86 -0
  141. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +198 -0
  142. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +65 -0
  143. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +73 -0
  144. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb.orig +62 -0
  145. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/iq/bytestreams.rb +170 -0
  146. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/bytestreams/iq/si.rb +206 -0
  147. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/callbacks.rb +124 -0
  148. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/caps.rb +1 -0
  149. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/caps/c.rb +53 -0
  150. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/caps/helper/generator.rb +160 -0
  151. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/caps/helper/helper.rb +87 -0
  152. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/client.rb +317 -0
  153. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/command/helper/responder.rb +53 -0
  154. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/command/iq/command.rb +154 -0
  155. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/component.rb +103 -0
  156. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/connection.rb +219 -0
  157. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/dataforms.rb +5 -0
  158. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/dataforms/x/data.rb +297 -0
  159. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/debuglog.rb +42 -0
  160. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/delay.rb +5 -0
  161. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/delay/x/delay.rb +99 -0
  162. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/discovery.rb +7 -0
  163. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/discovery/helper/responder.rb +165 -0
  164. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/discovery/iq/discoinfo.rb +211 -0
  165. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/discovery/iq/discoitems.rb +147 -0
  166. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/errors.rb +281 -0
  167. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/feature_negotiation.rb +5 -0
  168. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/feature_negotiation/iq/feature.rb +28 -0
  169. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/framework/base.rb +55 -0
  170. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/framework/bot.rb +148 -0
  171. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/httpbinding.rb +5 -0
  172. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/httpbinding/client.rb +285 -0
  173. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/idgenerator.rb +37 -0
  174. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/iq.rb +221 -0
  175. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/jid.rb +167 -0
  176. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/message.rb +148 -0
  177. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc.rb +14 -0
  178. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc/helper/mucbrowser.rb +92 -0
  179. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc/helper/mucclient.rb +462 -0
  180. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc/helper/simplemucclient.rb +332 -0
  181. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
  182. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
  183. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc/iq/mucowner.rb +15 -0
  184. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc/item.rb +143 -0
  185. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc/x/muc.rb +70 -0
  186. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc/x/mucuserinvite.rb +60 -0
  187. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/muc/x/mucuseritem.rb +36 -0
  188. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/presence.rb +232 -0
  189. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub.rb +8 -0
  190. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
  191. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/children/event.rb +49 -0
  192. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/children/item.rb +35 -0
  193. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/children/items.rb +44 -0
  194. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
  195. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/children/publish.rb +24 -0
  196. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/children/subscription.rb +62 -0
  197. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
  198. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/children/unsubscribe.rb +48 -0
  199. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodebrowser.rb +130 -0
  200. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/nodehelper.rb +156 -0
  201. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/helper/servicehelper.rb +417 -0
  202. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
  203. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/query.rb +15 -0
  204. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/rexmladdons.rb +151 -0
  205. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/roster.rb +7 -0
  206. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/roster/helper/roster.rb +519 -0
  207. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/roster/iq/roster.rb +215 -0
  208. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/roster/x/roster.rb +138 -0
  209. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/rpc.rb +2 -0
  210. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/rpc/helper/client.rb +123 -0
  211. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/rpc/helper/server.rb +74 -0
  212. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +67 -0
  213. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/rpc/iq/rpc.rb +23 -0
  214. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/sasl.rb +237 -0
  215. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/semaphore.rb +38 -0
  216. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/stream.rb +497 -0
  217. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/streamparser.rb +77 -0
  218. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/tune.rb +2 -0
  219. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/helper/helper.rb +58 -0
  220. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/tune/tune.rb +113 -0
  221. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/vcard.rb +6 -0
  222. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/vcard/helper/vcard.rb +84 -0
  223. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/vcard/iq/vcard.rb +109 -0
  224. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/version.rb +7 -0
  225. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/version/helper/responder.rb +72 -0
  226. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
  227. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/version/iq/version.rb +105 -0
  228. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/x.rb +37 -0
  229. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/xhtml.rb +1 -0
  230. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/xhtml/html.rb +115 -0
  231. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/xmpp4r.rb +18 -0
  232. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/xmppelement.rb +168 -0
  233. data/lib/gems/xmpp4r-0.4/lib/xmpp4r/xmppstanza.rb +162 -0
  234. data/lib/gems/xmpp4r-0.4/setup.rb +1586 -0
  235. data/lib/gems/xmpp4r-0.4/test/bytestreams/tc_ibb.rb +186 -0
  236. data/lib/gems/xmpp4r-0.4/test/bytestreams/tc_socks5bytestreams.rb +113 -0
  237. data/lib/gems/xmpp4r-0.4/test/caps/tc_helper.rb +156 -0
  238. data/lib/gems/xmpp4r-0.4/test/dataforms/tc_data.rb +81 -0
  239. data/lib/gems/xmpp4r-0.4/test/delay/tc_xdelay.rb +51 -0
  240. data/lib/gems/xmpp4r-0.4/test/discovery/tc_responder.rb +91 -0
  241. data/lib/gems/xmpp4r-0.4/test/lib/assert_equal_xml.rb +14 -0
  242. data/lib/gems/xmpp4r-0.4/test/lib/clienttester.rb +120 -0
  243. data/lib/gems/xmpp4r-0.4/test/muc/tc_muc_mucclient.rb +830 -0
  244. data/lib/gems/xmpp4r-0.4/test/muc/tc_muc_simplemucclient.rb +114 -0
  245. data/lib/gems/xmpp4r-0.4/test/muc/tc_mucowner.rb +50 -0
  246. data/lib/gems/xmpp4r-0.4/test/pubsub/tc_helper.rb +662 -0
  247. data/lib/gems/xmpp4r-0.4/test/pubsub/tc_nodeconfig.rb +54 -0
  248. data/lib/gems/xmpp4r-0.4/test/pubsub/tc_subscriptionconfig.rb +41 -0
  249. data/lib/gems/xmpp4r-0.4/test/roster/tc_helper.rb +514 -0
  250. data/lib/gems/xmpp4r-0.4/test/roster/tc_iqqueryroster.rb +173 -0
  251. data/lib/gems/xmpp4r-0.4/test/roster/tc_xroster.rb +73 -0
  252. data/lib/gems/xmpp4r-0.4/test/rpc/tc_helper.rb +96 -0
  253. data/lib/gems/xmpp4r-0.4/test/tc_callbacks.rb +129 -0
  254. data/lib/gems/xmpp4r-0.4/test/tc_class_names.rb +146 -0
  255. data/lib/gems/xmpp4r-0.4/test/tc_client.rb +30 -0
  256. data/lib/gems/xmpp4r-0.4/test/tc_errors.rb +146 -0
  257. data/lib/gems/xmpp4r-0.4/test/tc_idgenerator.rb +30 -0
  258. data/lib/gems/xmpp4r-0.4/test/tc_iq.rb +113 -0
  259. data/lib/gems/xmpp4r-0.4/test/tc_iqquery.rb +31 -0
  260. data/lib/gems/xmpp4r-0.4/test/tc_jid.rb +204 -0
  261. data/lib/gems/xmpp4r-0.4/test/tc_message.rb +116 -0
  262. data/lib/gems/xmpp4r-0.4/test/tc_presence.rb +150 -0
  263. data/lib/gems/xmpp4r-0.4/test/tc_rexml.rb +139 -0
  264. data/lib/gems/xmpp4r-0.4/test/tc_stream.rb +229 -0
  265. data/lib/gems/xmpp4r-0.4/test/tc_streamComponent.rb +95 -0
  266. data/lib/gems/xmpp4r-0.4/test/tc_streamError.rb +131 -0
  267. data/lib/gems/xmpp4r-0.4/test/tc_streamSend.rb +59 -0
  268. data/lib/gems/xmpp4r-0.4/test/tc_streamparser.rb +112 -0
  269. data/lib/gems/xmpp4r-0.4/test/tc_xmppstanza.rb +135 -0
  270. data/lib/gems/xmpp4r-0.4/test/ts_xmpp4r.rb +53 -0
  271. data/lib/gems/xmpp4r-0.4/test/tune/tc_helper_recv.rb +84 -0
  272. data/lib/gems/xmpp4r-0.4/test/tune/tc_helper_send.rb +74 -0
  273. data/lib/gems/xmpp4r-0.4/test/tune/tc_tune.rb +79 -0
  274. data/lib/gems/xmpp4r-0.4/test/vcard/tc_helper.rb +49 -0
  275. data/lib/gems/xmpp4r-0.4/test/vcard/tc_iqvcard.rb +62 -0
  276. data/lib/gems/xmpp4r-0.4/test/version/tc_helper.rb +60 -0
  277. data/lib/gems/xmpp4r-0.4/test/version/tc_iqqueryversion.rb +97 -0
  278. data/lib/gems/xmpp4r-0.4/test/xhtml/tc_html.rb +41 -0
  279. data/lib/gems/xmpp4r-0.4/tools/gen_requires.bash +31 -0
  280. data/lib/gems/xmpp4r-0.4/tools/xmpp4r-gemspec-test.rb +11 -0
  281. data/lib/gems/xmpp4r-0.4/xmpp4r.gemspec +291 -0
  282. data/lib/gems/xmpp4r-simple-0.8.8/CHANGELOG +73 -0
  283. data/lib/gems/xmpp4r-simple-0.8.8/COPYING +281 -0
  284. data/lib/gems/xmpp4r-simple-0.8.8/README +59 -0
  285. data/lib/gems/xmpp4r-simple-0.8.8/lib/xmpp4r-simple.rb +492 -0
  286. data/lib/gems/xmpp4r-simple-0.8.8/test/test_xmpp4r_simple.rb +242 -0
  287. data/lib/mack-notifier.rb +1 -3
  288. metadata +398 -46
@@ -0,0 +1,32 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ begin
6
+ require 'base64'
7
+ rescue LoadError
8
+ ##
9
+ # Ruby 1.9 has dropped the Base64 module,
10
+ # this is a replacement
11
+ #
12
+ # We could replace all call by Array#pack('m')
13
+ # and String#unpack('m'), but this module
14
+ # improves readability.
15
+ module Base64
16
+ ##
17
+ # Encode a String
18
+ # data:: [String] Binary
19
+ # result:: [String] Binary in Base64
20
+ def self.encode64(data)
21
+ [data].pack('m')
22
+ end
23
+
24
+ ##
25
+ # Decode a Base64-encoded String
26
+ # data64:: [String] Binary in Base64
27
+ # result:: [String] Binary
28
+ def self.decode64(data64)
29
+ data64.unpack('m').first
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ require 'xmpp4r/bytestreams/iq/si.rb'
6
+ require 'xmpp4r/bytestreams/iq/bytestreams.rb'
7
+ require 'xmpp4r/bytestreams/helper/ibb/base.rb'
8
+ require 'xmpp4r/bytestreams/helper/ibb/initiator.rb'
9
+ require 'xmpp4r/bytestreams/helper/ibb/target.rb'
10
+ require 'xmpp4r/bytestreams/helper/filetransfer.rb'
11
+ require 'xmpp4r/bytestreams/helper/socks5bytestreams/base.rb'
12
+ require 'xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb'
13
+ require 'xmpp4r/bytestreams/helper/socks5bytestreams/server.rb'
14
+ require 'xmpp4r/bytestreams/helper/socks5bytestreams/target.rb'
15
+ require 'xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb'
@@ -0,0 +1,319 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ require 'xmpp4r/callbacks'
6
+ require 'xmpp4r/bytestreams/iq/si'
7
+ require 'xmpp4r/dataforms/x/data'
8
+ require 'xmpp4r/bytestreams/helper/ibb/base'
9
+ require 'xmpp4r/bytestreams/helper/socks5bytestreams/base'
10
+
11
+ module Jabber
12
+ module FileTransfer
13
+ ##
14
+ # The TransferSource is an interface (Mix-in)
15
+ # which sources for FileTransfer#offer should include
16
+ module TransferSource
17
+ ##
18
+ # Filename of the offered file
19
+ def filename
20
+ end
21
+ ##
22
+ # Mime-type of the offered file, can be nil
23
+ def mime
24
+ end
25
+ ##
26
+ # Size of the offered file
27
+ def size
28
+ end
29
+ ##
30
+ # MD5-Sum of the offered file, can be nil
31
+ def md5
32
+ end
33
+ ##
34
+ # Date of the offered file, can be nil
35
+ def date
36
+ end
37
+ ##
38
+ # Read a chunk from the source
39
+ #
40
+ # If this is a ranged transfer, it should
41
+ # implement length checking
42
+ # length:: [Fixnum]
43
+ def read(length=nil)
44
+ end
45
+ ##
46
+ # Seek in the source for ranged transfers
47
+ def seek(position)
48
+ end
49
+ ##
50
+ # Set the amount of data to send for ranged transfers
51
+ def length=(l)
52
+ end
53
+ ##
54
+ # Does implement the methods seek and length= ?
55
+ #
56
+ # FileTransfer will only then offer a ranged transfer.
57
+ # result:: [false] or [true]
58
+ def can_range?
59
+ false
60
+ end
61
+ end
62
+
63
+ ##
64
+ # Simple implementation of TransferSource
65
+ # for sending simple files
66
+ # (supports ranged transfers)
67
+ class FileSource
68
+ include TransferSource
69
+
70
+ def initialize(filename)
71
+ @file = File.new(filename)
72
+ @filename = filename
73
+ @bytes_read = 0
74
+ @length = nil
75
+ end
76
+
77
+ def filename
78
+ File::basename @filename
79
+ end
80
+
81
+ ##
82
+ # Everything is 'application/octet-stream'
83
+ def mime
84
+ 'application/octet-stream'
85
+ end
86
+
87
+ def size
88
+ File.size @filename
89
+ end
90
+
91
+ def date
92
+ @file.mtime
93
+ end
94
+
95
+ ##
96
+ # Because it can_range?, this method implements length checking
97
+ def read(length=512)
98
+ if @length
99
+ return nil if @bytes_read >= @length # Already read everything requested
100
+ if @bytes_read + length > @length # Will we read more than requested?
101
+ length = @length - @bytes_read # Truncate it!
102
+ end
103
+ end
104
+
105
+ buf = @file.read(length)
106
+ @bytes_read += buf.size if buf
107
+ buf
108
+ end
109
+
110
+ def seek(position)
111
+ @file.seek(position)
112
+ end
113
+
114
+ def length=(l)
115
+ @length = l
116
+ end
117
+
118
+ def can_range?
119
+ true
120
+ end
121
+ end
122
+
123
+ ##
124
+ # The FileTransfer helper provides the ability to respond
125
+ # to incoming and to offer outgoing file-transfers.
126
+ class Helper
127
+ ##
128
+ # Set this if you want to use this helper in a Component
129
+ attr_accessor :my_jid
130
+ ##
131
+ # Set this to false if you don't want to use SOCKS5Bytestreams
132
+ attr_accessor :allow_bytestreams
133
+ ##
134
+ # Set this to false if you don't want to use IBB
135
+ attr_accessor :allow_ibb
136
+
137
+ ##
138
+ # Create a new FileTransfer instance
139
+ def initialize(stream)
140
+ @stream = stream
141
+ @my_jid = nil
142
+ @allow_bytestreams = true
143
+ @allow_ibb = true
144
+
145
+ @incoming_cbs = CallbackList.new
146
+
147
+ @stream.add_iq_callback(150, self) { |iq|
148
+ if iq.type == :set
149
+ file = iq.first_element('si/file')
150
+ field = nil
151
+ iq.each_element('si/feature/x') { |e| field = e.field('stream-method') }
152
+
153
+ if file and field
154
+ @incoming_cbs.process(iq, file)
155
+ true
156
+ else
157
+ false
158
+ end
159
+ else
160
+ false
161
+ end
162
+ }
163
+ end
164
+
165
+ ##
166
+ # Add a callback which will be invoked upon an incoming file-transfer
167
+ #
168
+ # block takes two arguments:
169
+ # * Iq
170
+ # * Bytestreams::IqSiFile in the Iq
171
+ # You may then invoke accept or decline
172
+ def add_incoming_callback(priority = 0, ref = nil, &block)
173
+ @incoming_cbs.add(priority, ref, block)
174
+ end
175
+
176
+ ##
177
+ # Accept an incoming file-transfer,
178
+ # to be used in a block given to add_incoming_callback
179
+ #
180
+ # offset and length will be ignored if there is no
181
+ # 'si/file/range' in iq.
182
+ # iq:: [Iq] of file-transfer we want to accept
183
+ # offset:: [Fixnum] or [nil]
184
+ # length:: [Fixnum] or [nil]
185
+ # result:: [Bytestreams::SOCKS5BytestreamsTarget] or [Bytestreams::IBBTarget] or [nil] if no valid stream-method
186
+ def accept(iq, offset=nil, length=nil)
187
+ oldsi = iq.first_element('si')
188
+
189
+ answer = iq.answer(false)
190
+ answer.type = :result
191
+
192
+ si = answer.add(Bytestreams::IqSi.new)
193
+ if (offset or length) and oldsi.file.range
194
+ si.add(Bytestreams::IqSiFile.new)
195
+ si.file.add(Bytestreams::IqSiFileRange.new(offset, length))
196
+ end
197
+ si.add(FeatureNegotiation::IqFeature.new.import(oldsi.feature))
198
+ si.feature.x.type = :submit
199
+ stream_method = si.feature.x.field('stream-method')
200
+
201
+ if stream_method.options.keys.include?(Bytestreams::NS_BYTESTREAMS) and @allow_bytestreams
202
+ stream_method.values = [Bytestreams::NS_BYTESTREAMS]
203
+ stream_method.options = []
204
+ @stream.send(answer)
205
+
206
+ Bytestreams::SOCKS5BytestreamsTarget.new(@stream, oldsi.id, iq.from, iq.to)
207
+ elsif stream_method.options.keys.include?(Bytestreams::IBB::NS_IBB) and @allow_ibb
208
+ stream_method.values = [Bytestreams::IBB::NS_IBB]
209
+ stream_method.options = []
210
+ @stream.send(answer)
211
+
212
+ Bytestreams::IBBTarget.new(@stream, oldsi.id, iq.from, iq.to)
213
+ else
214
+ eanswer = iq.answer(false)
215
+ eanswer.type = :error
216
+ eanswer.add(ErrorResponse.new('bad-request')).type = :cancel
217
+ eanswer.error.add(REXML::Element.new('no-valid-streams')).add_namespace('http://jabber.org/protocol/si')
218
+ @stream.send(eanswer)
219
+
220
+ nil
221
+ end
222
+ end
223
+
224
+ ##
225
+ # Decline an incoming file-transfer,
226
+ # to be used in a block given to add_incoming_callback
227
+ # iq:: [Iq] of file-transfer we want to decline
228
+ def decline(iq)
229
+ answer = iq.answer(false)
230
+ answer.type = :error
231
+ error = answer.add(ErrorResponse.new('forbidden', 'Offer declined'))
232
+ error.type = :cancel
233
+ @stream.send(answer)
234
+ end
235
+
236
+ ##
237
+ # Offer a file to somebody
238
+ #
239
+ # Will wait for a response from the peer
240
+ #
241
+ # The result is a stream which you can configure, or nil
242
+ # if the peer responded with an invalid stream-method.
243
+ #
244
+ # May raise an ServerError
245
+ # jid:: [JID] to send the file to
246
+ # source:: File-transfer source, implementing the FileSource interface
247
+ # desc:: [String] or [nil] Optional file description
248
+ # from:: [String] or [nil] Optional jid for components
249
+ # result:: [Bytestreams::SOCKS5BytestreamsInitiator] or [Bytestreams::IBBInitiator] or [nil]
250
+ def offer(jid, source, desc=nil, from=nil)
251
+ from = from || @my_jid || @stream.jid
252
+ session_id = Jabber::IdGenerator.instance.generate_id
253
+
254
+ offered_methods = {}
255
+ if @allow_bytestreams
256
+ offered_methods[Bytestreams::NS_BYTESTREAMS] = nil
257
+ end
258
+ if @allow_ibb
259
+ offered_methods[Bytestreams::IBB::NS_IBB] = nil
260
+ end
261
+
262
+ iq = Iq.new(:set, jid)
263
+ iq.from = from
264
+ si = iq.add(Bytestreams::IqSi.new(session_id, Bytestreams::PROFILE_FILETRANSFER, source.mime))
265
+
266
+ file = si.add(Bytestreams::IqSiFile.new(source.filename, source.size))
267
+ file.hash = source.md5
268
+ file.date = source.date
269
+ file.description = desc if desc
270
+ file.add(Bytestreams::IqSiFileRange.new) if source.can_range?
271
+
272
+ feature = si.add(REXML::Element.new('feature'))
273
+ feature.add_namespace 'http://jabber.org/protocol/feature-neg'
274
+ x = feature.add(Dataforms::XData.new(:form))
275
+ stream_method_field = x.add(Dataforms::XDataField.new('stream-method', :list_single))
276
+ stream_method_field.options = offered_methods
277
+
278
+ begin
279
+ stream_method = nil
280
+ response = nil
281
+ @stream.send_with_id(iq) do |r|
282
+ response = r
283
+ si = response.first_element('si')
284
+ if si and si.feature and si.feature.x
285
+ stream_method = si.feature.x.field('stream-method').values.first
286
+
287
+ if si.file and si.file.range
288
+ if source.can_range?
289
+ source.seek(si.file.range.offset) if si.file.range.offset
290
+ source.length = si.file.range.length if si.file.range.length
291
+ else
292
+ source.read(si.file.range.offset)
293
+ end
294
+ end
295
+ end
296
+ end
297
+ rescue ServerError => e
298
+ if e.error.code == 403 # Declined
299
+ return false
300
+ else
301
+ raise e
302
+ end
303
+ end
304
+
305
+ if stream_method == Bytestreams::NS_BYTESTREAMS and @allow_bytestreams
306
+ Bytestreams::SOCKS5BytestreamsInitiator.new(@stream, session_id, from, jid)
307
+ elsif stream_method == Bytestreams::IBB::NS_IBB and @allow_ibb
308
+ Bytestreams::IBBInitiator.new(@stream, session_id, from, jid)
309
+ else # Target responded with a stream_method we didn't offer
310
+ eanswer = response.answer
311
+ eanswer.type = :error
312
+ eanswer.add ErrorResponse.new('bad-request')
313
+ @stream.send(eanswer)
314
+ nil
315
+ end
316
+ end
317
+ end
318
+ end
319
+ end
@@ -0,0 +1,257 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ require 'xmpp4r/base64'
6
+
7
+ module Jabber
8
+ module Bytestreams
9
+ ##
10
+ # In-Band Bytestreams (JEP-0047) implementation
11
+ #
12
+ # Don't use directly, use IBBInitiator and IBBTarget
13
+ #
14
+ # In-Band Bytestreams should only be used when transferring
15
+ # very small amounts of binary data, because it is slow and
16
+ # increases server load drastically.
17
+ #
18
+ # Note that the constructor takes a lot of arguments. In-Band
19
+ # Bytestreams do not specify a way to initiate the stream,
20
+ # this should be done via Stream Initiation.
21
+ class IBB
22
+ NS_IBB = 'http://jabber.org/protocol/ibb'
23
+
24
+ ##
25
+ # Create a new bytestream
26
+ #
27
+ # Will register a <message/> callback to intercept data
28
+ # of this stream. This data will be buffered, you can retrieve
29
+ # it with receive
30
+ def initialize(stream, session_id, my_jid, peer_jid)
31
+ @stream = stream
32
+ @session_id = session_id
33
+ @my_jid = (my_jid.kind_of?(String) ? JID.new(my_jid) : my_jid)
34
+ @peer_jid = (peer_jid.kind_of?(String) ? JID.new(peer_jid) : peer_jid)
35
+
36
+ @active = false
37
+ @seq_send = 0
38
+ @seq_recv = 0
39
+ @queue = []
40
+ @queue_lock = Mutex.new
41
+ @pending = Semaphore.new
42
+ @sendbuf = ''
43
+ @sendbuf_lock = Mutex.new
44
+
45
+ @block_size = 4096 # Recommended by JEP0047
46
+ end
47
+
48
+ def active?
49
+ @active
50
+ end
51
+
52
+ ##
53
+ # Send data
54
+ #
55
+ # Data is buffered to match block_size in each packet.
56
+ # If you need the data to be sent immediately, use
57
+ # flush afterwards.
58
+ # buf:: [String]
59
+ def write(buf)
60
+ @sendbuf_lock.synchronize {
61
+ @sendbuf += buf
62
+
63
+ while @sendbuf.size >= @block_size
64
+ send_data(@sendbuf[0..@block_size-1])
65
+ @sendbuf = @sendbuf[@block_size..-1].to_s
66
+ end
67
+ }
68
+ end
69
+
70
+ ##
71
+ # Empty the send-buffer by sending remaining data
72
+ def flush
73
+ @sendbuf_lock.synchronize {
74
+ while @sendbuf.size > 0
75
+ send_data(@sendbuf[0..@block_size-1])
76
+ @sendbuf = @sendbuf[@block_size..-1].to_s
77
+ end
78
+ }
79
+ end
80
+
81
+ ##
82
+ # Receive data
83
+ #
84
+ # Will wait until the Message with the next sequence number
85
+ # is in the stanza queue.
86
+ def read
87
+ if active?
88
+ res = nil
89
+
90
+ while res.nil?
91
+ @queue_lock.synchronize {
92
+ @queue.each { |item|
93
+ # Find next data
94
+ if item.type == :data and item.seq == @seq_recv.to_s
95
+ res = item
96
+ break
97
+ # No data? Find close
98
+ elsif item.type == :close and res.nil?
99
+ res = item
100
+ end
101
+ }
102
+
103
+ @queue.delete_if { |item| item == res }
104
+ }
105
+
106
+ # No data? Wait for next to arrive...
107
+ @pending.wait unless res
108
+ end
109
+
110
+ if res.type == :data
111
+ @seq_recv += 1
112
+ @seq_recv = 0 if @seq_recv > 65535
113
+ res.data
114
+ elsif res.type == :close
115
+ deactivate
116
+ nil # Closed
117
+ end
118
+ else
119
+ nil
120
+ end
121
+ end
122
+
123
+ ##
124
+ # Close the stream
125
+ #
126
+ # Waits for acknowledge from peer,
127
+ # may throw ServerError
128
+ def close
129
+ if active?
130
+ flush
131
+ deactivate
132
+
133
+ iq = Iq.new(:set, @peer_jid)
134
+ close = iq.add REXML::Element.new('close')
135
+ close.add_namespace IBB::NS_IBB
136
+ close.attributes['sid'] = @session_id
137
+
138
+ @stream.send_with_id(iq)
139
+ end
140
+ end
141
+
142
+ private
143
+
144
+ ##
145
+ # Send data directly
146
+ # data:: [String]
147
+ def send_data(databuf)
148
+ if active?
149
+ msg = Message.new
150
+ msg.from = @my_jid
151
+ msg.to = @peer_jid
152
+
153
+ data = msg.add REXML::Element.new('data')
154
+ data.add_namespace NS_IBB
155
+ data.attributes['sid'] = @session_id
156
+ data.attributes['seq'] = @seq_send.to_s
157
+ data.text = Base64::encode64(databuf)
158
+
159
+ # TODO: Implement AMP correctly
160
+ amp = msg.add REXML::Element.new('amp')
161
+ amp.add_namespace 'http://jabber.org/protocol/amp'
162
+ deliver_at = amp.add REXML::Element.new('rule')
163
+ deliver_at.attributes['condition'] = 'deliver-at'
164
+ deliver_at.attributes['value'] = 'stored'
165
+ deliver_at.attributes['action'] = 'error'
166
+ match_resource = amp.add REXML::Element.new('rule')
167
+ match_resource.attributes['condition'] = 'match-resource'
168
+ match_resource.attributes['value'] = 'exact'
169
+ match_resource.attributes['action'] = 'error'
170
+
171
+ @stream.send(msg)
172
+
173
+ @seq_send += 1
174
+ @seq_send = 0 if @seq_send > 65535
175
+ else
176
+ raise 'Attempt to send data when not activated'
177
+ end
178
+ end
179
+
180
+ def activate
181
+ unless active?
182
+ @stream.add_message_callback(200, self) { |msg|
183
+ data = msg.first_element('data')
184
+ if msg.from == @peer_jid and msg.to == @my_jid and data and data.attributes['sid'] == @session_id
185
+ if msg.type == nil
186
+ @queue_lock.synchronize {
187
+ @queue.push IBBQueueItem.new(:data, data.attributes['seq'], data.text.to_s)
188
+ @pending.run
189
+ }
190
+ elsif msg.type == :error
191
+ @queue_lock.synchronize {
192
+ @queue << IBBQueueItem.new(:close)
193
+ @pending.run
194
+ }
195
+ end
196
+ true
197
+ else
198
+ false
199
+ end
200
+ }
201
+
202
+ @stream.add_iq_callback(200, self) { |iq|
203
+ close = iq.first_element('close')
204
+ if iq.type == :set and close and close.attributes['sid'] == @session_id
205
+ answer = iq.answer(false)
206
+ answer.type = :result
207
+ @stream.send(answer)
208
+
209
+ @queue_lock.synchronize {
210
+ @queue << IBBQueueItem.new(:close)
211
+ @pending.run
212
+ }
213
+ true
214
+ else
215
+ false
216
+ end
217
+ }
218
+
219
+ @active = true
220
+ end
221
+ end
222
+
223
+ def deactivate
224
+ if active?
225
+ @stream.delete_message_callback(self)
226
+ @stream.delete_iq_callback(self)
227
+
228
+ @active = false
229
+ end
230
+ end
231
+ end
232
+
233
+ ##
234
+ # Represents an item in the internal data queue
235
+ class IBBQueueItem
236
+ attr_reader :type, :seq
237
+ def initialize(type, seq=nil, data_text='')
238
+ unless [:data, :close].include? type
239
+ raise "Unknown IBBQueueItem type: #{type}"
240
+ end
241
+
242
+ @type = type
243
+ @seq = seq
244
+ @data = data_text
245
+ end
246
+
247
+ ##
248
+ # Return the Base64-*decoded* data
249
+ #
250
+ # There's no need to catch Exceptions here,
251
+ # as none are thrown.
252
+ def data
253
+ Base64::decode64(@data)
254
+ end
255
+ end
256
+ end
257
+ end