xmpp4r 0.3.2 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/{ChangeLog → CHANGELOG} +33 -0
  2. data/LICENSE +9 -9
  3. data/README.rdoc +110 -0
  4. data/README_ruby19.txt +43 -0
  5. data/Rakefile +235 -74
  6. data/data/doc/xmpp4r/examples/advanced/adventure/README +0 -1
  7. data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +1 -1
  8. data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +12 -12
  9. data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +10 -11
  10. data/data/doc/xmpp4r/examples/advanced/fileserve.rb +11 -11
  11. data/data/doc/xmpp4r/examples/advanced/getonline.rb +7 -7
  12. data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +3 -3
  13. data/data/doc/xmpp4r/examples/advanced/migrate.rb +21 -22
  14. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +22 -22
  15. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
  16. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
  17. data/data/doc/xmpp4r/examples/advanced/recvfile.rb +0 -1
  18. data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +2 -3
  19. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +3 -3
  20. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +10 -10
  21. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +2 -2
  22. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +12 -12
  23. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +2 -3
  24. data/data/doc/xmpp4r/examples/basic/change_password.rb +3 -3
  25. data/data/doc/xmpp4r/examples/basic/client.rb +5 -3
  26. data/data/doc/xmpp4r/examples/basic/component.rb +1 -1
  27. data/data/doc/xmpp4r/examples/basic/{echo_threaded.rb → echo.rb} +8 -7
  28. data/data/doc/xmpp4r/examples/basic/jabbersend.rb +5 -5
  29. data/data/doc/xmpp4r/examples/basic/mass_sender.rb +11 -11
  30. data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +0 -1
  31. data/data/doc/xmpp4r/examples/basic/mucinfo.rb +3 -1
  32. data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +0 -1
  33. data/data/doc/xmpp4r/examples/basic/register.rb +21 -4
  34. data/data/doc/xmpp4r/examples/basic/roster.rb +7 -5
  35. data/data/doc/xmpp4r/examples/basic/rosterprint.rb +0 -0
  36. data/data/doc/xmpp4r/examples/basic/rosterrename.rb +2 -2
  37. data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +6 -7
  38. data/data/doc/xmpp4r/examples/basic/send_vcard.rb +3 -4
  39. data/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
  40. data/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
  41. data/data/doc/xmpp4r/examples/basic/versionbot.rb +1 -1
  42. data/lib/xmpp4r.rb +4 -4
  43. data/lib/xmpp4r/base64.rb +32 -0
  44. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +10 -11
  45. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +6 -8
  46. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +3 -6
  47. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +0 -1
  48. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +8 -11
  49. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +4 -7
  50. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +7 -3
  51. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +10 -5
  52. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +14 -4
  53. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb.orig +62 -0
  54. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +0 -1
  55. data/lib/xmpp4r/callbacks.rb +5 -5
  56. data/lib/xmpp4r/caps.rb +1 -0
  57. data/lib/xmpp4r/caps/c.rb +53 -0
  58. data/lib/xmpp4r/caps/helper/generator.rb +160 -0
  59. data/lib/xmpp4r/caps/helper/helper.rb +87 -0
  60. data/lib/xmpp4r/client.rb +111 -40
  61. data/lib/xmpp4r/command/iq/command.rb +1 -1
  62. data/lib/xmpp4r/component.rb +8 -8
  63. data/lib/xmpp4r/connection.rb +25 -9
  64. data/lib/xmpp4r/dataforms/x/data.rb +17 -5
  65. data/lib/xmpp4r/debuglog.rb +13 -5
  66. data/lib/xmpp4r/delay/x/delay.rb +1 -1
  67. data/lib/xmpp4r/discovery.rb +3 -2
  68. data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
  69. data/lib/xmpp4r/discovery/iq/discoinfo.rb +11 -12
  70. data/lib/xmpp4r/discovery/iq/discoitems.rb +12 -4
  71. data/lib/xmpp4r/{error.rb → errors.rb} +66 -10
  72. data/lib/xmpp4r/framework/base.rb +55 -0
  73. data/lib/xmpp4r/framework/bot.rb +148 -0
  74. data/lib/xmpp4r/httpbinding/client.rb +1 -1
  75. data/lib/xmpp4r/idgenerator.rb +1 -1
  76. data/lib/xmpp4r/iq.rb +34 -23
  77. data/lib/xmpp4r/jid.rb +2 -2
  78. data/lib/xmpp4r/message.rb +1 -1
  79. data/lib/xmpp4r/muc.rb +2 -0
  80. data/lib/xmpp4r/muc/helper/mucbrowser.rb +4 -19
  81. data/lib/xmpp4r/muc/helper/mucclient.rb +54 -23
  82. data/lib/xmpp4r/muc/helper/simplemucclient.rb +107 -1
  83. data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
  84. data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
  85. data/lib/xmpp4r/muc/iq/mucowner.rb +5 -1
  86. data/lib/xmpp4r/muc/item.rb +143 -0
  87. data/lib/xmpp4r/muc/x/mucuserinvite.rb +2 -2
  88. data/lib/xmpp4r/muc/x/mucuseritem.rb +3 -117
  89. data/lib/xmpp4r/presence.rb +2 -1
  90. data/lib/xmpp4r/pubsub.rb +7 -0
  91. data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
  92. data/lib/xmpp4r/pubsub/{stanzas → children}/event.rb +13 -13
  93. data/lib/xmpp4r/pubsub/{stanzas → children}/item.rb +9 -1
  94. data/lib/xmpp4r/pubsub/{stanzas → children}/items.rb +10 -1
  95. data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
  96. data/lib/xmpp4r/pubsub/children/publish.rb +24 -0
  97. data/lib/xmpp4r/pubsub/{stanzas → children}/subscription.rb +16 -12
  98. data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
  99. data/lib/xmpp4r/pubsub/children/unsubscribe.rb +48 -0
  100. data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +49 -93
  101. data/lib/xmpp4r/pubsub/helper/nodehelper.rb +39 -36
  102. data/lib/xmpp4r/pubsub/helper/servicehelper.rb +253 -162
  103. data/lib/xmpp4r/pubsub/iq/pubsub.rb +1 -1
  104. data/lib/xmpp4r/rexmladdons.rb +56 -28
  105. data/lib/xmpp4r/roster.rb +0 -1
  106. data/lib/xmpp4r/roster/helper/roster.rb +26 -15
  107. data/lib/xmpp4r/roster/iq/roster.rb +19 -19
  108. data/lib/xmpp4r/roster/x/roster.rb +10 -10
  109. data/lib/xmpp4r/rpc/helper/client.rb +17 -8
  110. data/lib/xmpp4r/rpc/helper/server.rb +1 -2
  111. data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +14 -4
  112. data/lib/xmpp4r/rpc/iq/rpc.rb +0 -1
  113. data/lib/xmpp4r/sasl.rb +27 -6
  114. data/lib/xmpp4r/stream.rb +39 -44
  115. data/lib/xmpp4r/streamparser.rb +4 -4
  116. data/lib/xmpp4r/tune.rb +2 -0
  117. data/lib/xmpp4r/tune/helper/helper.rb +58 -0
  118. data/lib/xmpp4r/tune/tune.rb +113 -0
  119. data/lib/xmpp4r/vcard.rb +0 -1
  120. data/lib/xmpp4r/vcard/helper/vcard.rb +1 -3
  121. data/lib/xmpp4r/vcard/iq/vcard.rb +14 -0
  122. data/lib/xmpp4r/version/iq/version.rb +0 -1
  123. data/lib/xmpp4r/x.rb +1 -1
  124. data/lib/xmpp4r/xhtml.rb +1 -0
  125. data/lib/xmpp4r/xhtml/html.rb +115 -0
  126. data/lib/xmpp4r/xmpp4r.rb +7 -5
  127. data/lib/xmpp4r/xmppelement.rb +21 -5
  128. data/lib/xmpp4r/xmppstanza.rb +6 -6
  129. data/setup.rb +4 -4
  130. data/test/bytestreams/tc_ibb.rb +2 -2
  131. data/test/bytestreams/tc_socks5bytestreams.rb +12 -2
  132. data/test/caps/tc_helper.rb +156 -0
  133. data/test/dataforms/tc_data.rb +0 -0
  134. data/test/delay/tc_xdelay.rb +2 -2
  135. data/test/discovery/tc_responder.rb +91 -0
  136. data/test/lib/assert_equal_xml.rb +14 -0
  137. data/test/lib/clienttester.rb +31 -24
  138. data/test/muc/tc_muc_mucclient.rb +249 -13
  139. data/test/muc/tc_muc_simplemucclient.rb +41 -2
  140. data/test/muc/tc_mucowner.rb +0 -0
  141. data/test/pubsub/tc_helper.rb +486 -51
  142. data/test/pubsub/tc_nodeconfig.rb +54 -0
  143. data/test/pubsub/tc_subscriptionconfig.rb +41 -0
  144. data/test/roster/tc_helper.rb +6 -7
  145. data/test/roster/tc_iqqueryroster.rb +16 -16
  146. data/test/roster/tc_xroster.rb +1 -1
  147. data/test/rpc/tc_helper.rb +15 -3
  148. data/test/tc_callbacks.rb +7 -7
  149. data/test/tc_class_names.rb +15 -6
  150. data/test/tc_client.rb +3 -3
  151. data/test/{tc_error.rb → tc_errors.rb} +54 -12
  152. data/test/tc_idgenerator.rb +0 -0
  153. data/test/tc_iq.rb +32 -29
  154. data/test/tc_iqquery.rb +2 -2
  155. data/test/tc_jid.rb +44 -42
  156. data/test/tc_message.rb +13 -12
  157. data/test/tc_presence.rb +25 -24
  158. data/test/tc_rexml.rb +81 -2
  159. data/test/tc_stream.rb +15 -13
  160. data/test/tc_streamComponent.rb +6 -5
  161. data/test/tc_streamError.rb +21 -15
  162. data/test/tc_streamSend.rb +9 -9
  163. data/test/tc_streamparser.rb +112 -0
  164. data/test/tc_xmppstanza.rb +19 -9
  165. data/test/ts_xmpp4r.rb +10 -1
  166. data/test/tune/tc_helper_recv.rb +84 -0
  167. data/test/tune/tc_helper_send.rb +74 -0
  168. data/test/tune/tc_tune.rb +79 -0
  169. data/test/vcard/tc_helper.rb +2 -2
  170. data/test/vcard/tc_iqvcard.rb +13 -3
  171. data/test/version/tc_helper.rb +2 -2
  172. data/test/version/tc_iqqueryversion.rb +10 -10
  173. data/test/xhtml/tc_html.rb +41 -0
  174. data/tools/gen_requires.bash +29 -8
  175. data/tools/xmpp4r-gemspec-test.rb +11 -0
  176. data/xmpp4r.gemspec +291 -0
  177. metadata +277 -218
  178. data/README +0 -28
  179. data/UPDATING +0 -40
  180. data/data/doc/xmpp4r/examples/buggy/jabber2jabber/jabber2jabber.rb +0 -18
  181. data/data/doc/xmpp4r/examples/buggy/miniedgarr_cgi.rb +0 -192
  182. data/data/doc/xmpp4r/examples/buggy/miniedgarr_watch.rb +0 -82
  183. data/lib/xmpp4r/authenticationfailure.rb +0 -13
  184. data/lib/xmpp4r/errorexception.rb +0 -32
  185. data/tools/doctoweb.bash +0 -30
@@ -0,0 +1,148 @@
1
+ require 'xmpp4r/framework/base'
2
+
3
+ require 'xmpp4r'
4
+ require 'xmpp4r/roster'
5
+ require 'xmpp4r/caps/c'
6
+ require 'xmpp4r/discovery'
7
+ require 'xmpp4r/xhtml'
8
+
9
+ module Jabber
10
+ module Framework
11
+ ##
12
+ # Abstract handler methods that *may* be implemented by a deriving class:
13
+ # * on_message(text)
14
+ # * on_message_xhtml(html_body, text)
15
+ class Bot < Base
16
+ helper :roster, Roster::Helper
17
+ helper(:disco_default) { |cl|
18
+ Discovery::Responder.new(cl,
19
+ nil,
20
+ [Jabber::Discovery::Identity.new('client', 'XMPP4R Bot', 'bot')]
21
+ )
22
+ }
23
+ helper(:disco_caps) { |cl|
24
+ Discovery::Responder.new(cl,
25
+ "http://home.gna.org/xmpp4r/#{Jabber::XMPP4R_VERSION}",
26
+ [Jabber::Discovery::Identity.new('client', 'XMPP4R Bot', 'bot')]
27
+ )
28
+ }
29
+
30
+ def initialize(jid, password)
31
+ cl = Jabber::Client.new(jid)
32
+ cl.connect
33
+ cl.auth(password)
34
+
35
+ super(cl)
36
+
37
+ roster.add_subscription_request_callback do |item,presence|
38
+ if accept_subscription_from?(presence.from.strip)
39
+ roster.accept_subscription(presence.from.strip)
40
+ else
41
+ roster.decline_subscription(presence.from.strip)
42
+ end
43
+ end
44
+
45
+ @pep_notifications = []
46
+ cl.add_message_callback do |msg|
47
+ if msg.type != :error and msg.body
48
+ if (html = msg.first_element('html')) and respond_to? :on_message_xhtml
49
+ on_message_xhtml(html.body, msg.body)
50
+ elsif respond_to? :on_message
51
+ on_message(msg.body)
52
+ end
53
+ elsif msg.type != :error and (event = msg.first_element('event'))
54
+ event.each_element('items') do |items|
55
+ node = items.attributes['node']
56
+ items.each_element('item') do |item|
57
+ @pep_notifications.each { |notification_node,callback|
58
+ if node == notification_node
59
+ callback.call(msg.from, item)
60
+ end
61
+ }
62
+ end
63
+ end
64
+ else
65
+ false
66
+ end
67
+ end
68
+
69
+ add_cap('presence')
70
+ add_cap(Caps::NS_CAPS)
71
+ add_cap('message') if respond_to? :on_message
72
+ add_cap(XHTML::NS_XHTML_IM) if respond_to? :on_message_xhtml
73
+
74
+ @presence_show = nil
75
+ @presence_status = nil
76
+ end
77
+
78
+ ##
79
+ # Add feature namespace to Capabilities Discovery
80
+ def add_cap(capability)
81
+ disco_default.add_feature(capability)
82
+ disco_caps.add_feature(capability)
83
+ end
84
+
85
+ ##
86
+ # Front-end for Roster::Helper#add_subscription_request_callback
87
+ #
88
+ # Can be overwritten, must return true or false
89
+ def accept_subscription_from?(jid)
90
+ true
91
+ end
92
+
93
+ ##
94
+ # Send a simple text chat message
95
+ def send_message(to, text)
96
+ msg = Message.new
97
+ msg.type = :chat
98
+ msg.to = to
99
+ msg.body = text
100
+ @stream.send(msg)
101
+ end
102
+
103
+ ##
104
+ # Send an XHTML chat message
105
+ # text:: [String] alternate plain text body, generated from xhtml_contents if nil
106
+ def send_message_xhtml(to, xhtml_contents, text=nil)
107
+ msg = Message.new
108
+ msg.type = :chat
109
+ msg.to = to
110
+ html = msg.add(XHTML::HTML.new(xhtml_contents))
111
+ msg.body = text ? text : html.to_text
112
+ @stream.send(msg)
113
+ end
114
+
115
+ ##
116
+ # Set and send a Presence
117
+ def set_presence(show=nil, status=nil)
118
+ @presence_show = show
119
+ @presence_status = status
120
+ send_presence
121
+ end
122
+
123
+ private
124
+
125
+ def send_presence
126
+ roster.wait_for_roster
127
+
128
+ # TODO: vcard photo hash
129
+ if @presence_show == :unavailable
130
+ presence = Presence.new(nil, @presence_status)
131
+ presence.type = :unavailable
132
+ else
133
+ presence = Presence.new(@presence_show, @presence_status)
134
+ end
135
+ presence.add(disco_caps.generate_caps)
136
+ @stream.send(presence)
137
+ end
138
+
139
+ public
140
+
141
+ def add_pep_notification(node, &callback)
142
+ add_cap("#{node}+notify")
143
+ @pep_notifications << [node, callback]
144
+ end
145
+ end
146
+
147
+ end
148
+ end
@@ -231,7 +231,7 @@ module Jabber
231
231
  close; @exception_block.call(e, self, :parser)
232
232
  end
233
233
  else
234
- puts "Exception caught when parsing HTTP response!"
234
+ Jabber::debuglog "Exception caught when parsing HTTP response!"
235
235
  close
236
236
  raise
237
237
  end
@@ -30,7 +30,7 @@ module Jabber
30
30
  def generate_id
31
31
  @last_id += 1
32
32
  timefrac = Time.new.to_f.to_s.split(/\./, 2).last[-3..-1]
33
-
33
+
34
34
  "#{@last_id}#{timefrac}"
35
35
  end
36
36
  end
@@ -79,7 +79,7 @@ module Jabber
79
79
  ##
80
80
  # Returns the iq's query child, or nil
81
81
  # result:: [IqQuery]
82
- def query
82
+ def query
83
83
  first_element('query')
84
84
  end
85
85
 
@@ -129,8 +129,8 @@ module Jabber
129
129
  # Create a new Iq stanza with an unspecified query child
130
130
  # (<query/> has no namespace)
131
131
  def Iq.new_query(type = nil, to = nil)
132
- iq = Iq::new(type, to)
133
- query = IqQuery::new
132
+ iq = Iq.new(type, to)
133
+ query = IqQuery.new
134
134
  iq.add(query)
135
135
  iq
136
136
  end
@@ -138,12 +138,12 @@ module Jabber
138
138
  ##
139
139
  # Create a new jabber:iq:auth set Stanza.
140
140
  def Iq.new_authset(jid, password)
141
- iq = Iq::new(:set)
142
- query = IqQuery::new
141
+ iq = Iq.new(:set)
142
+ query = IqQuery.new
143
143
  query.add_namespace('jabber:iq:auth')
144
- query.add(REXML::Element::new('username').add_text(jid.node))
145
- query.add(REXML::Element::new('password').add_text(password))
146
- query.add(REXML::Element::new('resource').add_text(jid.resource)) if not jid.resource.nil?
144
+ query.add(REXML::Element.new('username').add_text(jid.node))
145
+ query.add(REXML::Element.new('password').add_text(password))
146
+ query.add(REXML::Element.new('resource').add_text(jid.resource)) if not jid.resource.nil?
147
147
  iq.add(query)
148
148
  iq
149
149
  end
@@ -151,12 +151,12 @@ module Jabber
151
151
  ##
152
152
  # Create a new jabber:iq:auth set Stanza for Digest authentication
153
153
  def Iq.new_authset_digest(jid, session_id, password)
154
- iq = Iq::new(:set)
155
- query = IqQuery::new
154
+ iq = Iq.new(:set)
155
+ query = IqQuery.new
156
156
  query.add_namespace('jabber:iq:auth')
157
- query.add(REXML::Element::new('username').add_text(jid.node))
158
- query.add(REXML::Element::new('digest').add_text(Digest::SHA1.hexdigest(session_id + password)))
159
- query.add(REXML::Element::new('resource').add_text(jid.resource)) if not jid.resource.nil?
157
+ query.add(REXML::Element.new('username').add_text(jid.node))
158
+ query.add(REXML::Element.new('digest').add_text(Digest::SHA1.hexdigest(session_id + password)))
159
+ query.add(REXML::Element.new('resource').add_text(jid.resource)) if not jid.resource.nil?
160
160
  iq.add(query)
161
161
  iq
162
162
  end
@@ -166,11 +166,22 @@ module Jabber
166
166
  # username:: [String] (Element will be ommited if unset)
167
167
  # password:: [String] (Element will be ommited if unset)
168
168
  def Iq.new_register(username=nil, password=nil)
169
- iq = Iq::new(:set)
170
- query = IqQuery::new
169
+ iq = Iq.new(:set)
170
+ query = IqQuery.new
171
+ query.add_namespace('jabber:iq:register')
172
+ query.add(REXML::Element.new('username').add_text(username)) if username
173
+ query.add(REXML::Element.new('password').add_text(password)) if password
174
+ iq.add(query)
175
+ iq
176
+ end
177
+
178
+ ##
179
+ # Create a new jabber:iq:register get stanza for retrieval
180
+ # of accepted registration information
181
+ def Iq.new_registerget
182
+ iq = Iq.new(:get)
183
+ query = IqQuery.new
171
184
  query.add_namespace('jabber:iq:register')
172
- query.add(REXML::Element::new('username').add_text(username)) if username
173
- query.add(REXML::Element::new('password').add_text(password)) if password
174
185
  iq.add(query)
175
186
  iq
176
187
  end
@@ -180,8 +191,8 @@ module Jabber
180
191
  #
181
192
  # IqQueryRoster is unused here because possibly not require'd
182
193
  def Iq.new_rosterget
183
- iq = Iq::new(:get)
184
- query = IqQuery::new
194
+ iq = Iq.new(:get)
195
+ query = IqQuery.new
185
196
  query.add_namespace('jabber:iq:roster')
186
197
  iq.add(query)
187
198
  iq
@@ -190,8 +201,8 @@ module Jabber
190
201
  ##
191
202
  # Create a new jabber:iq:roster get Stanza.
192
203
  def Iq.new_browseget
193
- iq = Iq::new(:get)
194
- query = IqQuery::new
204
+ iq = Iq.new(:get)
205
+ query = IqQuery.new
195
206
  query.add_namespace('jabber:iq:browse')
196
207
  iq.add(query)
197
208
  iq
@@ -200,8 +211,8 @@ module Jabber
200
211
  ##
201
212
  # Create a new jabber:iq:roster set Stanza.
202
213
  def Iq.new_rosterset
203
- iq = Iq::new(:set)
204
- query = IqQuery::new
214
+ iq = Iq.new(:set)
215
+ query = IqQuery.new
205
216
  query.add_namespace('jabber:iq:roster')
206
217
  iq.add(query)
207
218
  iq
@@ -4,7 +4,7 @@
4
4
 
5
5
  module Jabber
6
6
  ##
7
- # The JID class represents a Jabber Identifier as described by
7
+ # The JID class represents a Jabber Identifier as described by
8
8
  # RFC3920 section 3.1.
9
9
  #
10
10
  # Note that you can use JIDs also for Sorting, Hash keys, ...
@@ -63,7 +63,7 @@ module Jabber
63
63
  # Returns a new JID with resource removed.
64
64
  # return:: [JID]
65
65
  def strip
66
- JID::new(@node, @domain)
66
+ JID.new(@node, @domain)
67
67
  end
68
68
  alias_method :bare, :strip
69
69
 
@@ -26,7 +26,7 @@ module Jabber
26
26
  set_to(to)
27
27
  end
28
28
  if !body.nil?
29
- add_element(REXML::Element::new("body").add_text(body))
29
+ add_element(REXML::Element.new("body").add_text(body))
30
30
  end
31
31
  end
32
32
 
@@ -7,6 +7,8 @@ require 'xmpp4r/muc/x/muc'
7
7
  require 'xmpp4r/muc/x/mucuserinvite'
8
8
  require 'xmpp4r/muc/x/mucuseritem'
9
9
  require 'xmpp4r/muc/iq/mucowner'
10
+ require 'xmpp4r/muc/iq/mucadmin'
11
+ require 'xmpp4r/muc/iq/mucadminitem'
10
12
  require 'xmpp4r/muc/helper/mucbrowser'
11
13
  require 'xmpp4r/muc/helper/mucclient'
12
14
  require 'xmpp4r/muc/helper/simplemucclient'
@@ -30,7 +30,7 @@ module Jabber
30
30
  # does not exist or does not support Service Discovery!
31
31
  # nil just means that this is not a MUC-compliant service.
32
32
  #
33
- # Throws an ErrorException when receiving
33
+ # Throws an ServerError when receiving
34
34
  # <tt><iq type='error'/></tt>
35
35
  # jid:: [JID] Target entity (set only domain!)
36
36
  # return:: [String] or [nil]
@@ -78,25 +78,11 @@ module Jabber
78
78
  iq.add(Discovery::IqQueryDiscoItems.new)
79
79
 
80
80
  rooms = {}
81
- err = nil
82
81
 
83
82
  @stream.send_with_id(iq) do |answer|
84
-
85
- if answer.type == :result
86
- answer.query.each_element('item') { |item|
87
- rooms[item.jid] = item.iname
88
- }
89
- true
90
- elsif answer.type == :error
91
- err = answer.error
92
- true
93
- else
94
- false
95
- end
96
- end
97
-
98
- if err
99
- raise "Error getting MUC rooms: #{err.error}, #{err.text}"
83
+ answer.query.each_element('item') { |item|
84
+ rooms[item.jid] = item.iname
85
+ }
100
86
  end
101
87
 
102
88
  rooms
@@ -104,4 +90,3 @@ module Jabber
104
90
  end
105
91
  end
106
92
  end
107
-
@@ -3,6 +3,9 @@
3
3
  # Website::http://home.gna.org/xmpp4r/
4
4
 
5
5
  require 'xmpp4r/muc/x/muc'
6
+ require 'xmpp4r/muc/iq/mucowner'
7
+ require 'xmpp4r/muc/iq/mucadmin'
8
+ require 'xmpp4r/dataforms'
6
9
 
7
10
  module Jabber
8
11
  module MUC
@@ -61,7 +64,7 @@ module Jabber
61
64
  #
62
65
  # This registers its own callbacks on the stream
63
66
  # provided to initialize and sends initial presence
64
- # to the room. May throw ErrorException if joining
67
+ # to the room. May throw ServerError if joining
65
68
  # fails.
66
69
  # jid:: [JID] room@component/nick
67
70
  # password:: [String] Optional password
@@ -70,7 +73,7 @@ module Jabber
70
73
  if active?
71
74
  raise "MUCClient already active"
72
75
  end
73
-
76
+
74
77
  @jid = (jid.kind_of?(JID) ? jid : JID.new(jid))
75
78
  activate
76
79
 
@@ -109,7 +112,7 @@ module Jabber
109
112
 
110
113
  if error
111
114
  deactivate
112
- raise ErrorException.new(error)
115
+ raise ServerError.new(error)
113
116
  end
114
117
 
115
118
  self
@@ -175,12 +178,12 @@ module Jabber
175
178
  # transient JID, one indicating availability of the new
176
179
  # transient JID.
177
180
  #
178
- # If the service denies nick-change, ErrorException will be raisen.
181
+ # If the service denies nick-change, ServerError will be raised.
179
182
  def nick=(new_nick)
180
183
  unless active?
181
184
  raise "MUCClient not active"
182
185
  end
183
-
186
+
184
187
  new_jid = JID.new(@jid.node, @jid.domain, new_nick)
185
188
 
186
189
  # Joining
@@ -219,7 +222,7 @@ module Jabber
219
222
  }
220
223
 
221
224
  if error
222
- raise ErrorException.new(error)
225
+ raise ServerError.new(error)
223
226
  end
224
227
 
225
228
  # Apply new JID
@@ -247,7 +250,7 @@ module Jabber
247
250
  stanza.type = to ? :chat : :groupchat
248
251
  end
249
252
  stanza.from = @my_jid
250
- stanza.to = JID::new(jid.node, jid.domain, to)
253
+ stanza.to = JID.new(jid.node, jid.domain, to)
251
254
  @stream.send(stanza)
252
255
  end
253
256
 
@@ -388,30 +391,42 @@ module Jabber
388
391
  @affiliation == :owner
389
392
  end
390
393
 
394
+ ##
395
+ # Use this method to configure a MUC room of which you are the owner.
396
+ #
397
+ # options:: [Hash] where keys are the features of the room you wish
398
+ # to configure. See http://www.xmpp.org/extensions/xep-0045.html#registrar-formtype-owner
391
399
  def configure(options={})
400
+ get_room_configuration
401
+ submit_room_configuration(options)
402
+ end
403
+
404
+ def get_room_configuration
392
405
  raise 'You are not the owner' unless owner?
393
-
394
- iq = Iq.new(:get, jid)
395
- iq.to = @jid
396
- iq.from = @my_jid
406
+
407
+ iq = Iq.new(:get, jid.strip)
408
+ iq.from = my_jid
397
409
  iq.add(IqQueryMUCOwner.new)
398
410
 
399
411
  fields = []
400
-
401
- answer = @stream.send_with_id(iq)
402
- raise "Configuration not possible for this room" unless answer.query && answer.query.x(XData)
403
412
 
404
- answer.query.x(XData).fields.each { |field|
405
- if (var = field.attributes['var'])
406
- fields << var
413
+ @stream.send_with_id(iq) do |answer|
414
+ raise "Configuration not possible for this room" unless answer.query && answer.query.x(Dataforms::XData)
415
+
416
+ answer.query.x(Dataforms::XData).fields.each do |field|
417
+ if (var = field.attributes['var'])
418
+ fields << var
419
+ end
407
420
  end
408
- }
421
+ end
422
+
423
+ fields
424
+ end
409
425
 
410
-
426
+ def submit_room_configuration(options)
411
427
  # fill out the reply form
412
- iq = Iq.new(:set, jid)
413
- iq.to = @jid
414
- iq.from = @my_jid
428
+ iq = Iq.new(:set, jid.strip)
429
+ iq.from = my_jid
415
430
  query = IqQueryMUCOwner.new
416
431
  form = Dataforms::XData.new
417
432
  form.type = :submit
@@ -422,7 +437,23 @@ module Jabber
422
437
  form.add(field)
423
438
  end
424
439
  query.add(form)
425
- iq.add(query)
440
+ iq.add(query)
441
+
442
+ @stream.send_with_id(iq)
443
+ end
444
+
445
+ ##
446
+ # Push a list of new affiliations to the room
447
+ # items:: [Array] of, or single [IqQueryMUCAdminItem]
448
+ def send_affiliations(items)
449
+ iq = Iq.new(:set, jid.strip)
450
+ iq.from = my_jid
451
+ iq.add(IqQueryMUCAdmin.new)
452
+
453
+ items = [item] unless items.kind_of? Array
454
+ items.each { |item|
455
+ iq.query.add(item)
456
+ }
426
457
 
427
458
  @stream.send_with_id(iq)
428
459
  end