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
@@ -16,8 +16,8 @@ module Jabber
16
16
  end
17
17
 
18
18
  ##
19
- # Retrive the nodes
20
- # Throws an ErrorException when receiving
19
+ # Retrieve the nodes
20
+ # Throws an ServerError when receiving
21
21
  # <tt><iq type='error'/></tt>
22
22
  # jid:: [JID] Target entity (set only domain!)
23
23
  # return:: [Array] of [String] or [nil]
@@ -26,26 +26,17 @@ module Jabber
26
26
  iq.from = @stream.jid
27
27
  iq.add(Discovery::IqQueryDiscoItems.new)
28
28
  nodes = []
29
- err = nil
30
- @stream.send_with_id(iq) { |answer|
31
- if answer.type == :result
32
- answer.query.each_element('item') { |item|
33
- nodes.push(item.node)
34
- }
35
- true
36
- elsif answer.type == :error
37
- err = answer.error
38
- true
39
- else
40
- false
41
- end
42
- }
43
- return nodes
29
+ @stream.send_with_id(iq) do |answer|
30
+ answer.query.each_element('item') { |item|
31
+ nodes.push(item.node)
32
+ }
33
+ end
34
+ nodes
44
35
  end
45
36
 
46
37
  ##
47
- # Retrive the nodes with names
48
- # Throws an ErrorExeption when reciving
38
+ # Retrieve the nodes with names
39
+ # Throws a ServerError when receiving
49
40
  # <tt><iq type='error'/></tt>
50
41
  # jid:: [Jabber::JID] Target entity (set only domain!)
51
42
  # return:: [Array] of [Hash] with keys 'node' => [String] and 'name' => [String] or [nil]
@@ -54,27 +45,18 @@ module Jabber
54
45
  iq.from = @stream.jid
55
46
  iq.add(Discovery::IqQueryDiscoItems.new)
56
47
  nodes = []
57
- err = nil
58
48
  @stream.send_with_id(iq) { |answer|
59
- if answer.type == :result
60
- answer.query.each_element('item') { |item|
61
- nodes.push( {'node' => item.node,'name' => item.iname } )
62
- }
63
- true
64
- elsif answer.type == :error
65
- err = answer.error
66
- true
67
- else
68
- false
69
- end
70
- }
71
- return nodes
49
+ answer.query.each_element('item') do |item|
50
+ nodes.push( {'node' => item.node,'name' => item.iname } )
51
+ }
52
+ end
53
+ nodes
72
54
  end
73
55
 
74
56
 
75
57
  ##
76
- # Retrive the items from a node
77
- # Throws an ErrorExeption when reciving
58
+ # Retrieve the items from a node
59
+ # Throws an ServerError when receiving
78
60
  # <tt><iq type='error'/></tt>
79
61
  # jid:: [Jabber::JID] Target entity (set only domain!)
80
62
  # node:: [String]
@@ -82,25 +64,17 @@ module Jabber
82
64
  def items(jid,node)
83
65
  iq = Iq.new(:get,jid)
84
66
  iq.from = @stream.jid
85
- discoitems = Discovery::IqQueryDiscoItems.new
86
- discoitems.node = node
67
+ discoitems = Discovery::IqQueryDiscoItems.new
68
+ discoitems.node = node
87
69
  iq.add(discoitems)
88
70
  items = []
89
71
  err = nil
90
- @stream.send_with_id(iq) { |answer|
91
- if answer.type == :result
92
- answer.query.each_element('item') { |item|
93
- items.push( {'jid' => item.jid,'name' => item.iname } )
94
- }
95
- true
96
- elsif answer.type == :error
97
- err = answer.error
98
- true
99
- else
100
- false
101
- end
102
- }
103
- return items
72
+ @stream.send_with_id(iq) do |answer|
73
+ answer.query.each_element('item') { |item|
74
+ items.push( {'jid' => item.jid,'name' => item.iname } )
75
+ }
76
+ end
77
+ items
104
78
  end
105
79
 
106
80
  ##
@@ -109,64 +83,46 @@ module Jabber
109
83
  # node:: [String]
110
84
  # return:: [Hash] with possible keys type:: [String] ,category:: [String],features:: [Array] of feature, nodeinformation:: [Jabber::XData]
111
85
  # check http://www.xmpp.org/extensions/xep-0060.html#entity for more infos
112
-
113
- # this is only for a xep <-> nodebrowser.rb understanding
114
- alias get_metadata get_info
115
-
116
86
  def get_info(jid,node)
117
87
  iq = Iq.new(:get,jid)
118
- iq.from = @stream.jid
119
- discoinfo = Discovery::IqQueryDiscoInfo.new
120
- discoinfo.node = node
121
- iq.add(discoinfo)
122
- info = {}
123
- @stream.send_with_id(iq) { |answer|
124
- if answer.type == :result
125
-
126
- identity = answer.query.identity
127
- info['type'] = identity.type
128
- info['category'] = identity.category
129
-
130
- info['features'] = answer.query.features
131
-
132
- # i think its not needed - if you think so then delete it
133
- # answer.query.each_element('identity') { |identity|
134
- # info['type'] = identity.type
135
- # info['category'] = identity.category
136
- # }
137
- #
138
- # features = []
139
- # answer.query.each_element('feature') { |feature|
140
- # features.push(feature)
141
- # }
142
- # info['features'] = features
143
- #
144
- answer.query.each_element('x') { |x|
145
- info['nodeinformation'] = x
146
- }
147
- end
148
- }
149
- return info
88
+ iq.from = @stream.jid
89
+ discoinfo = Discovery::IqQueryDiscoInfo.new
90
+ discoinfo.node = node
91
+ iq.add(discoinfo)
92
+ info = {}
93
+ @stream.send_with_id(iq) do |answer|
94
+ identity = answer.query.identity
95
+ info['type'] = identity.type
96
+ info['category'] = identity.category
97
+ info['features'] = answer.query.features
98
+
99
+ answer.query.each_element('x') { |x|
100
+ info['nodeinformation'] = x
101
+ }
102
+ end
103
+ info
150
104
  end
151
-
105
+ # this is only for a xep <-> nodebrowser.rb understanding
106
+ alias get_metadata get_info
107
+
152
108
  ##
153
109
  # get type of node
154
110
  # jid:: [Jabber::JID]
155
111
  # node:: [String]
156
- #
112
+ #
157
113
  def type(jid,node)
158
114
  info = get_info(jid,node)
159
- return info['type']
115
+ return info['type']
160
116
  end
161
-
117
+
162
118
  ##
163
119
  # get category of node
164
120
  # jid:: [Jabber::JID]
165
121
  # node:: [String]
166
- #
122
+ #
167
123
  def category(jid,node)
168
124
  info = get_info(jid,node)
169
- return info['category']
125
+ return info['category']
170
126
  end
171
127
 
172
128
  end #class
@@ -2,10 +2,9 @@
2
2
  # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
3
  # Website::http://home.gna.org/xmpp4r/
4
4
  #
5
- # For a documentation of the retunvalues please look into the
6
- # documentation of [Jabber::PubSub::ServiceHelper]
5
+ # For documentation of the return values please see [Jabber::PubSub::ServiceHelper]
7
6
  # This class is only a wrapper around [Jabber::PubSub::ServiceHelper]
8
- #
7
+ #
9
8
 
10
9
 
11
10
  require 'xmpp4r/pubsub/helper/servicehelper'
@@ -17,52 +16,56 @@ module Jabber
17
16
 
18
17
  attr_reader :nodename
19
18
  attr_reader :name
20
- attr_reader :jiod
19
+ attr_reader :jid
21
20
  attr_reader :my_subscriptions
22
21
  ##
23
- # creates a new node
22
+ # creates a new node
24
23
  # new(client,service,nodename)
25
24
  # stream:: [Jabber::Stream]
26
25
  # jid:: [String] (jid of the pubsub service)
27
26
  # nodename:: [String]
28
- def initialize(stream,jid,nodename=nil,create_if_not_exist=true)
27
+ def initialize(stream, jid, nodename = nil, create_if_not_exist = true)
29
28
  super(stream,jid)
30
29
  @nodename = nodename
31
- @jid = jid
32
- @stream = client
33
-
34
- get_subscriptions
35
-
36
- if create_if_not_exist and not node_exist?
37
- # if no nodename is given a instant node will created
38
- # (if the service supports instant nodes)
39
- @nodename = create_node
40
- end
30
+ @jid = jid
31
+ @stream = stream
32
+
33
+ if create_if_not_exist and not node_exist?
34
+ # if no nodename is given a instant node will created
35
+ # (if the service supports instant nodes)
36
+ @nodename = create_node
37
+ else
38
+ get_subscriptions
39
+ end
41
40
  end
42
41
 
43
42
  ##
44
43
  # creates the node
45
44
  # create(configuration=nil)
46
45
  # configuration:: [Jabber::XData]
47
- def create_node(configuration=nil)
48
- create(@nodename,configuration)
46
+ def create_node(configuration = Jabber::PubSub::NodeConfig.new)
47
+ unless node_exist?
48
+ super(@nodename,configuration)
49
+ else
50
+ false
51
+ end
49
52
  end
50
-
53
+
51
54
  ##
52
55
  # get the configuration of the node
53
56
  # get_configuration(configuration=nil)
54
57
  # configuration:: [Jabber::XData]
55
- def get_configuration(subid=nil)
56
- get_options(@nodename,subid)
58
+ def get_configuration(subid = nil)
59
+ get_options(@nodename, subid)
57
60
  end
58
-
61
+
59
62
  ##
60
63
  # set the configuration of the node
61
64
  # set_configuration(configuration=nil)
62
65
  # configuration:: [Jabber::XData]
63
66
  # subid:: [String] default is nil
64
- def set_configuration(configuration,subid=nil)
65
- set_options(@nodename,configuration,subid)
67
+ def set_configuration(configuration,subid = nil)
68
+ set_options(@nodename, configuration, subid)
66
69
  end
67
70
 
68
71
  ##
@@ -73,22 +76,22 @@ module Jabber
73
76
  end
74
77
 
75
78
  ##
76
- # publishing content on this node
79
+ # publishing content on this node
77
80
  # publish_content(items)
78
81
  # items:: [REXML::Element]
79
82
  def publish_content(items)
80
- publish(@nodename,items)
83
+ publish_item_to(@nodename,items)
81
84
  end
82
85
 
83
86
  ##
84
- # gets all items from the node
87
+ # gets all items from the node
85
88
  # get_all_items
86
89
  def get_all_items
87
90
  items(@nodename)
88
91
  end
89
92
 
90
93
  ##
91
- # get a count of items
94
+ # get a count of items
92
95
  # get_items(count)
93
96
  # count:: [Fixnum]
94
97
  def get_items(count)
@@ -106,7 +109,7 @@ module Jabber
106
109
  # get all subscriptions on this node
107
110
  # get_subscriptions
108
111
  def get_subscriptions
109
- subscriptions(@nodename)
112
+ get_subscriptions_from(@nodename)
110
113
  end
111
114
 
112
115
  ##
@@ -120,8 +123,8 @@ module Jabber
120
123
  # subscribe to this node
121
124
  # do_subscribe
122
125
  def do_subscribe
123
- subscribe(@nodename)
124
- get_subscriptions
126
+ subscribe_to(@nodename)
127
+ get_subscriptions
125
128
  end
126
129
 
127
130
  ##
@@ -131,23 +134,23 @@ module Jabber
131
134
  def do_unsubscribe(subid)
132
135
  unsubscribe(@nodename,subid)
133
136
  end
134
-
137
+
135
138
  ##
136
139
  # purge all items from this node
137
140
  # purge_items
138
141
  def purge_items
139
142
  purge(@nodename)
140
143
  end
141
-
144
+
142
145
  private
143
-
146
+
144
147
  def node_exist?
145
148
  nodebrowser = PubSub::NodeBrowser.new(@stream)
146
- nodebrowser.nodes.include?(nodename)
149
+ nodebrowser.nodes(@jid).include?(@nodename)
147
150
  end
148
151
  def disco_info
149
152
  end
150
153
 
151
154
  end #class
152
155
  end #module
153
- end #module
156
+ end #module
@@ -2,14 +2,49 @@
2
2
  # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
3
  # Website::http://home.gna.org/xmpp4r/
4
4
  #
5
- # It's recommented to read the XEP-0066 before you use this Helper.
5
+ # It's recommented to read the XEP-0060 before you use this Helper. (Maybe its
6
+ # better not use the helper for now ) ;)
7
+ # The whole code is getting better, but may still contain bugs - be careful!
8
+ #
9
+ # Maybe the following structure is good
10
+ # ( taken from the xep-0060 )
11
+ #
12
+ # entity usecases
13
+ # retrieve all subscriptions
14
+ # retrieve all affiliations
15
+ # NOTE: the disco stuff will done by the nodebrowserhelper
16
+ # subscriber usecases
17
+ # subscribe
18
+ # unsubscribe
19
+ # configure subscription options
20
+ # retrieve items from a node
21
+ # publisher usecases
22
+ # publish a item to a node
23
+ # delete a item from a node
24
+ # owner usecases
25
+ # create a node
26
+ # configure a node
27
+ # request default configuration options
28
+ # delete a node
29
+ # purge all node items
30
+ # manage subscription requests
31
+ # process pending subscriptions
32
+ # manage subscriptions
33
+ # manage affiliations
34
+ #
35
+ # collection nodes
36
+ #
37
+ # If someone want to implement something i think its better to do this in
38
+ # this order because everyone who reads the xep-0060 do know where to search in the file
6
39
  #
7
-
8
40
  require 'xmpp4r/pubsub/iq/pubsub'
9
- require 'xmpp4r/pubsub/stanzas/event'
10
- require 'xmpp4r/pubsub/stanzas/item'
11
- require 'xmpp4r/pubsub/stanzas/items'
12
- require 'xmpp4r/pubsub/stanzas/subscription'
41
+ require 'xmpp4r/pubsub/children/event'
42
+ require 'xmpp4r/pubsub/children/item'
43
+ require 'xmpp4r/pubsub/children/items'
44
+ require 'xmpp4r/pubsub/children/subscription'
45
+ require 'xmpp4r/pubsub/children/unsubscribe'
46
+ require 'xmpp4r/pubsub/children/node_config'
47
+ require 'xmpp4r/pubsub/children/subscription_config'
13
48
  require 'xmpp4r/dataforms'
14
49
 
15
50
  module Jabber
@@ -20,71 +55,114 @@ module Jabber
20
55
 
21
56
  ##
22
57
  # Creates a new representation of a pubsub service
23
- # client:: [Jabber::Stream]
58
+ # stream:: [Jabber::Stream]
24
59
  # pubsubjid:: [String] or [Jabber::JID]
25
- def initialize(client, pubsubjid)
26
- @client = client
60
+ def initialize(stream, pubsubjid)
61
+ @stream = stream
27
62
  @pubsubjid = pubsubjid
28
63
  @event_cbs = CallbackList.new
29
- @client.add_message_callback(200,self) { |message|
64
+ @stream.add_message_callback(200,self) { |message|
30
65
  handle_message(message)
31
66
  }
32
67
  end
33
68
 
34
69
  ##
35
- # Create a new node on the pubsub service
36
- # node:: [String] you node name - otherwise you get a automaticly generated one (in most cases)
37
- # configure:: [Jabber::XMLStanza] if you want to configure you node (default nil)
38
- # return:: [String]
39
- def create(node=nil, configure=nil)
40
- rnode = nil
41
- iq = basic_pubsub_query(:set)
42
- iq.pubsub.add(REXML::Element.new('create')).attributes['node'] = node
43
- if configure
44
- confele = REXML::Element.new('configure')
45
-
46
- if configure.type_of?(XMLStanza)
47
- confele << configure
70
+ # get all subscriptions on a pubsub component
71
+ # return:: [Hash] of [PubSub::Subscription]
72
+ def get_subscriptions_from_all_nodes
73
+ iq = basic_pubsub_query(:get)
74
+ entities = iq.pubsub.add(REXML::Element.new('subscriptions'))
75
+ res = nil
76
+ @stream.send_with_id(iq) { |reply|
77
+ if reply.pubsub.first_element('subscriptions')
78
+ res = []
79
+ reply.pubsub.first_element('subscriptions').each_element('subscription') { |subscription|
80
+ res << Jabber::PubSub::Subscription.import(subscription)
81
+ }
48
82
  end
49
- iq.pubsub.add(confele)
50
- end
83
+ }
51
84
 
52
- @client.send_with_id(iq) do |reply|
53
- if (create = reply.first_element('pubsub/create'))
54
- rnode = create.attributes['node']
85
+ res
86
+ end
87
+ ##
88
+ # subscribe to a node
89
+ # node:: [String]
90
+ # return:: [Hash] of { attributename => value }
91
+ def subscribe_to(node)
92
+ iq = basic_pubsub_query(:set)
93
+ sub = REXML::Element.new('subscribe')
94
+ sub.attributes['node'] = node
95
+ sub.attributes['jid'] = @stream.jid.strip.to_s
96
+ iq.pubsub.add(sub)
97
+ res = nil
98
+ @stream.send_with_id(iq) do |reply|
99
+ pubsubanswer = reply.pubsub
100
+ if pubsubanswer.first_element('subscription')
101
+ res = PubSub::Subscription.import(pubsubanswer.first_element('subscription'))
55
102
  end
56
- true
57
- end
58
-
59
- rnode
103
+ end # @stream.send_with_id(iq)
104
+ res
60
105
  end
61
106
 
62
107
  ##
63
- # Delete a pubsub node
108
+ # Unsubscribe from a node with an optional subscription id
109
+ #
110
+ # May raise ServerError
64
111
  # node:: [String]
112
+ # subid:: [String] or nil (not supported)
65
113
  # return:: true
66
- def delete(node)
67
- iq = basic_pubsub_query(:set,true)
68
- iq.pubsub.add(REXML::Element.new('delete')).attributes['node'] = node
69
- @client.send_with_id(iq) { |reply|
114
+ def unsubscribe_from(node, subid=nil)
115
+ iq = basic_pubsub_query(:set)
116
+ unsub = PubSub::Unsubscribe.new
117
+ unsub.node = node
118
+ unsub.jid = @stream.jid.strip
119
+ iq.pubsub.add(unsub)
120
+ ret = false
121
+ @stream.send_with_id(iq) { |reply|
122
+ ret = reply.kind_of?(Jabber::Iq) and reply.type == :result
123
+ } # @stream.send_with_id(iq)
124
+ ret
125
+ end
126
+
127
+ ##
128
+ # gets all items from a pubsub node
129
+ # node:: [String]
130
+ # count:: [Fixnum]
131
+ # return:: [Hash] { id => [Jabber::PubSub::Item] }
132
+ def get_items_from(node, count=nil)
133
+ iq = basic_pubsub_query(:get)
134
+ items = Jabber::PubSub::Items.new
135
+ items.node = node
136
+ iq.pubsub.add(items)
137
+ res = nil
138
+ @stream.send_with_id(iq) { |reply|
139
+ if reply.kind_of?(Iq) and reply.pubsub and reply.pubsub.first_element('items')
140
+ res = {}
141
+ reply.pubsub.first_element('items').each_element('item') do |item|
142
+ res[item.attributes['id']] = item.children.first if item.children.first
143
+ end
144
+ end
70
145
  true
71
146
  }
147
+ res
72
148
  end
73
149
 
74
150
  ##
75
- # NOTE: this method sends only one item per publish request because some services may not
76
- # allow batch processing
77
- # maybe this will changed in the future
151
+ # NOTE: this method sends only one item per publish request because some services
152
+ # may not allow batch processing. Maybe this will changed in the future?
78
153
  # node:: [String]
79
154
  # item:: [Jabber::PubSub::Item]
80
155
  # return:: true
81
- def publish(node,item)
156
+ # it automatically generates an id for the item
157
+ def publish_item_to(node,item)
82
158
  iq = basic_pubsub_query(:set)
83
- publish = iq.pubsub.add(REXML::Element.new('publish'))
159
+ publish = iq.pubsub.add(REXML::Element.new('publish'))
84
160
  publish.attributes['node'] = node
161
+
85
162
  if item.kind_of?(Jabber::PubSub::Item)
163
+ item.id = Jabber::IdGenerator.generate_id
86
164
  publish.add(item)
87
- @client.send_with_id(iq) { |reply| true }
165
+ @stream.send_with_id(iq)
88
166
  end
89
167
  end
90
168
 
@@ -93,48 +171,117 @@ module Jabber
93
171
  # item:: [REXML::Element]
94
172
  # id:: [String]
95
173
  # return:: true
96
- def publish_with_id(node,item,id)
174
+ def publish_item_with_id_to(node,item,id)
175
+ iq = basic_pubsub_query(:set)
176
+ publish = iq.pubsub.add(REXML::Element.new('publish'))
177
+ publish.attributes['node'] = node
178
+
97
179
  if item.kind_of?(REXML::Element)
98
180
  xmlitem = Jabber::PubSub::Item.new
99
181
  xmlitem.id = id
100
- xmlitem.add(item)
101
- publish(node,xmlitem)
182
+ xmlitem.import(item)
183
+ publish.add(xmlitem)
102
184
  else
103
185
  raise "given item is not a proper xml document or Jabber::PubSub::Item"
104
186
  end
187
+ @stream.send_with_id(iq)
105
188
  end
106
189
 
107
190
  ##
108
- # gets all items from a pubsub node
191
+ # purges all items on a persistent node
109
192
  # node:: [String]
110
- # count:: [Fixnum]
111
- # return:: [Hash] { id => [Jabber::PubSub::Item] }
112
- def items(node,count=nil)
113
- iq = basic_pubsub_query(:get)
114
- items = Jabber::PubSub::Items.new
115
- items.node = node
116
- iq.pubsub.add(items)
117
- res = nil
118
- @client.send_with_id(iq) { |reply|
119
- if reply.kind_of?(Iq) and reply.pubsub and reply.pubsub.first_element('items')
120
- res = {}
121
- reply.pubsub.first_element('items').each_element('item') do |item|
122
- res[item.attributes['id']] = item.children.first if item.children.first
123
- end
193
+ # return:: true
194
+ def purge_items_from(node)
195
+ iq = basic_pubsub_query(:set)
196
+ purge = REXML::Element.new('purge')
197
+ purge.attributes['node'] = node
198
+ iq.pubsub.add(purge)
199
+ @stream.send_with_id(iq)
200
+ end
201
+
202
+ ##
203
+ # Create a new node on the pubsub service
204
+ # node:: [String] the node name - otherwise you get a automatically generated one (in most cases)
205
+ # configure:: [Jabber::PubSub::NodeConfig] if you want to configure your node (default nil)
206
+ # return:: [String]
207
+ def create_node(node = nil, configure = Jabber::PubSub::NodeConfig.new)
208
+ rnode = nil
209
+ iq = basic_pubsub_query(:set)
210
+ iq.pubsub.add(REXML::Element.new('create')).attributes['node'] = node
211
+ if configure
212
+ if configure.kind_of?(Jabber::PubSub::NodeConfig)
213
+ iq.pubsub.add(configure)
124
214
  end
125
- true
126
- }
127
- res
215
+ end
216
+
217
+ @stream.send_with_id(iq) do |reply|
218
+ if reply.kind_of?(Jabber::Iq) and reply.type == :result
219
+ rnode = node
220
+ end
221
+ end
222
+
223
+ rnode
224
+ end
225
+
226
+ ##
227
+ # Create a new collection node on the pubsub service
228
+ # node:: [String] the node name - otherwise you get an automatically generated one (in most cases)
229
+ # configure:: [Jabber::PubSub::NodeConfig] if you want to configure your node (default nil)
230
+ # return:: [String]
231
+ def create_collection_node(node = nil, configure = Jabber::PubSub::NodeConfig.new)
232
+ if configure.options['pubsub#node_type'] && configure.options['pubsub#node_type'] != 'collection'
233
+ raise Jabber::ArgumentError, "Invalid node_type specified in node configuration. Either do not specify one, or use 'collection'"
234
+ end
235
+ configure.options = configure.options.merge({'pubsub#node_type' => 'collection'})
236
+ create_node(node, configure)
128
237
  end
129
238
 
239
+ ##
240
+ # get configuration from a node
241
+ # node:: [String]
242
+ # return:: [Jabber::PubSub::Configure]
243
+ def get_config_from(node)
244
+ iq = basic_pubsub_query(:get, true)
245
+ iq.pubsub.add(Jabber::PubSub::OwnerNodeConfig.new(node))
246
+ ret = nil
247
+ @stream.send_with_id(iq) do |reply|
248
+ ret = reply.pubsub.first_element('configure')
249
+ end
250
+ ret
251
+ end
252
+
253
+ ##
254
+ # set configuration for a node
255
+ # node:: [String]
256
+ # options:: [Jabber::PubSub::NodeConfig]
257
+ # return:: true on success
258
+ def set_config_for(node, config)
259
+ iq = basic_pubsub_query( :set )
260
+ iq.pubsub.add(config.form)
261
+ @stream.send_with_id(iq)
262
+ end
263
+
264
+ ##
265
+ # Delete a pubsub node
266
+ # node:: [String]
267
+ # return:: true
268
+ def delete_node(node)
269
+ iq = basic_pubsub_query(:set,true)
270
+ iq.pubsub.add(REXML::Element.new('delete')).attributes['node'] = node
271
+ @stream.send_with_id(iq)
272
+ end
273
+
274
+
130
275
  ##
131
276
  # shows the affiliations on a pubsub service
277
+ # node:: [String]
132
278
  # return:: [Hash] of { node => symbol }
133
- def affiliations
279
+ def get_affiliations(node = nil)
134
280
  iq = basic_pubsub_query(:get)
135
- iq.pubsub.add(REXML::Element.new('affiliations'))
281
+ affiliations = iq.pubsub.add(REXML::Element.new('affiliations'))
282
+ affiliations.attributes['node'] = node
136
283
  res = nil
137
- @client.send_with_id(iq) { |reply|
284
+ @stream.send_with_id(iq) { |reply|
138
285
  if reply.pubsub.first_element('affiliations')
139
286
  res = {}
140
287
  reply.pubsub.first_element('affiliations').each_element('affiliation') do |affiliation|
@@ -156,19 +303,21 @@ module Jabber
156
303
 
157
304
  ##
158
305
  # shows all subscriptions on the given node
159
- # node:: [String], or nil for all
160
- # return:: [Array] of [REXML::Element]
161
- def subscriptions(node=nil)
306
+ # node:: [String]
307
+ # return:: [Array] of [Jabber::Pubsub::Subscription]
308
+ def get_subscriptions_from(node)
162
309
  iq = basic_pubsub_query(:get)
163
310
  entities = iq.pubsub.add(REXML::Element.new('subscriptions'))
164
311
  entities.attributes['node'] = node
165
312
  res = nil
166
- @client.send_with_id(iq) { |reply|
313
+ @stream.send_with_id(iq) { |reply|
167
314
  if reply.pubsub.first_element('subscriptions')
168
315
  res = []
169
- reply.pubsub.first_element('subscriptions').each_element('subscription') { |subscription|
170
- res << REXML::Element.new(subscription)
171
- }
316
+ if reply.pubsub.first_element('subscriptions').attributes['node'] == node
317
+ reply.pubsub.first_element('subscriptions').each_element('subscription') { |subscription|
318
+ res << PubSub::Subscription.import(subscription)
319
+ }
320
+ end
172
321
  end
173
322
  true
174
323
  }
@@ -179,107 +328,49 @@ module Jabber
179
328
  # shows all jids of subscribers of a node
180
329
  # node:: [String]
181
330
  # return:: [Array] of [String]
182
- def subscribers(node)
331
+ def get_subscribers_from(node)
183
332
  res = []
184
- subscriptions(node).each { |sub|
185
- res << sub.attributes['jid']
333
+ get_subscriptions_from(node).each { |sub|
334
+ res << sub.jid
186
335
  }
187
336
  res
188
337
  end
189
338
 
190
- ##
191
- # subscribe to a node
192
- # node:: [String]
193
- # return:: [Hash] of { attributename => value }
194
- def subscribe(node)
195
- iq = basic_pubsub_query(:set)
196
- sub = REXML::Element.new('subscribe')
197
- sub.attributes['node'] = node
198
- sub.attributes['jid'] = @client.jid.strip
199
- iq.pubsub.add(sub)
200
- res = {}
201
- @client.send_with_id(iq) do |reply|
202
- pubsubanswer = reply.pubsub
203
- if pubsubanswer.first_element('subscription')
204
- pubsubanswer.each_element('subscription') { |element|
205
- element.attributes.each { |name,value| res[name] = value }
206
- }
207
- end
208
- true
209
- end # @client.send_with_id(iq)
210
- res
211
- end
212
339
 
213
340
  ##
214
- # Unsubscibe from a node with an optional subscription id
215
- #
216
- # May raise ErrorException
341
+ # get options from a subscription
217
342
  # node:: [String]
343
+ # jid:: [Jabber::JID] or [String]
218
344
  # subid:: [String] or nil
219
- # return:: true
220
- def unsubscribe(node,subid=nil)
221
- iq = basic_pubsub_query(:set)
222
- unsub = REXML::Element.new('unsubscribe')
223
- unsub.attributes['node'] = node
224
- unsub.attributes['jid'] = @client.jid.strip
225
- unsub.attributes['subid'] = subid
226
- iq.pubsub.add(unsub)
227
- @client.send_with_id(iq) { |reply| true } # @client.send_with_id(iq)
228
- end
229
-
230
- ##
231
- # get options of a node
232
- # node:: [String]
233
- # subid:: [String] or nil
234
- # return:: [Jabber::XData]
235
- def get_options(node,subid=nil)
345
+ # return:: [Jabber::PubSub::OwnerConfigure]
346
+ def get_options_from(node, jid, subid = nil)
236
347
  iq = basic_pubsub_query(:get)
237
- opt = REXML::Element.new('options')
238
- opt.attributes['node'] = node
239
- opt.attributes['jid'] = @client.jid.strip
240
- opt.attributes['subid'] = subid
241
- iq.pubsub.add(opt)
348
+ iq.pubsub.add(Jabber::PubSub::SubscriptionConfig.new(node, jid.kind_of?(String) ? Jabber::JID.new(jid).strip: jid.strip, subid))
242
349
  ret = nil
243
- @client.send_with_id(iq) { |reply|
244
- reply.pubsub.options.first_element('x') { |xdata|
245
-
246
- ret = xdata if xdata.kind_of?(Jabber::XData)
247
-
248
- }
249
- true
250
- }
251
- return ret
350
+ @stream.send_with_id(iq) do |reply|
351
+ ret = reply.pubsub.first_element('options')
352
+ end
353
+ ret
252
354
  end
253
355
 
254
356
  ##
255
- # set options for a node
357
+ # set options for a subscription
256
358
  # node:: [String]
257
- # options:: [Jabber::XData]
359
+ # jid:: [Jabber::JID] or [String]
360
+ # options:: [Jabber::PubSub::SubscriptionConfig} specifying configuration options
258
361
  # subid:: [String] or nil
259
362
  # return:: true
260
- def set_options(node,options,subid=nil)
261
- iq = basic_pubsub_query(:set)
262
- opt = REXML::Element.new('options')
263
- opt.attributes['node'] = node
264
- opt.attributes['jid'] = @client.jid.strip
265
- opt.attributes['subid'] = subid
266
- iq.pubsub.add(opt)
267
- iq.pubsub.options.add(options)
268
- @client.send_with_id(iq) { |reply| true }
269
- end
270
-
271
- ##
272
- # purges all items on a persist node
273
- # node:: [String]
274
- # return:: true
275
- def purge(node)
363
+ def set_options_for(node, jid, options, subid = nil)
276
364
  iq = basic_pubsub_query(:set)
277
- purge = REXML::Element.new('purge')
278
- purge.attributes['node'] = node
279
- iq.pubsub.add(purge)
280
- @client.send_with_id(iq) { |reply| true }
281
- end
365
+ iq.pubsub.add(Jabber::PubSub::SubscriptionConfig.new(node, jid.kind_of?(String) ? Jabber::JID.new(jid).strip: jid.strip, options, subid))
366
+ ret = false
367
+ @stream.send_with_id(iq) do |reply|
368
+ ret = ( reply.type == :result )
369
+ end
282
370
 
371
+ ret
372
+ end
373
+
283
374
  ##
284
375
  # String representation
285
376
  # result:: [String] The PubSub service's JID
@@ -301,12 +392,13 @@ module Jabber
301
392
  # basic_pubsub_query(type)
302
393
  # type:: [Symbol]
303
394
  def basic_pubsub_query(type,ownerusecase = false)
304
- iq = Jabber::Iq::new(type,@pubsubjid)
305
- if ownerusecase
306
- iq.add(IqPubSubOwner.new)
307
- else
395
+ iq = Jabber::Iq.new(type,@pubsubjid)
396
+ if ownerusecase
397
+ iq.add(IqPubSubOwner.new)
398
+ else
308
399
  iq.add(IqPubSub.new)
309
- end
400
+ end
401
+ iq.from = @stream.jid #.strip
310
402
  iq
311
403
  end
312
404
 
@@ -320,7 +412,6 @@ module Jabber
320
412
  @event_cbs.process(event)
321
413
  end
322
414
  end
323
-
324
415
  end
325
416
  end
326
417
  end