agent_xmpp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/.document +5 -0
  2. data/.gitignore +11 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +417 -0
  5. data/Rakefile +75 -0
  6. data/VERSION +1 -0
  7. data/agent_xmpp.gemspec +144 -0
  8. data/lib/agent_xmpp.rb +22 -0
  9. data/lib/agent_xmpp/admin.rb +113 -0
  10. data/lib/agent_xmpp/client.rb +7 -0
  11. data/lib/agent_xmpp/client/boot.rb +83 -0
  12. data/lib/agent_xmpp/client/client.rb +64 -0
  13. data/lib/agent_xmpp/client/connection.rb +108 -0
  14. data/lib/agent_xmpp/client/controller.rb +394 -0
  15. data/lib/agent_xmpp/client/message_delegate.rb +720 -0
  16. data/lib/agent_xmpp/client/message_pipe.rb +193 -0
  17. data/lib/agent_xmpp/client/response.rb +102 -0
  18. data/lib/agent_xmpp/config.rb +48 -0
  19. data/lib/agent_xmpp/main.rb +175 -0
  20. data/lib/agent_xmpp/models.rb +7 -0
  21. data/lib/agent_xmpp/models/contact.rb +85 -0
  22. data/lib/agent_xmpp/models/message.rb +152 -0
  23. data/lib/agent_xmpp/models/publication.rb +53 -0
  24. data/lib/agent_xmpp/models/roster.rb +107 -0
  25. data/lib/agent_xmpp/models/service.rb +91 -0
  26. data/lib/agent_xmpp/models/subscription.rb +61 -0
  27. data/lib/agent_xmpp/models/table_definitions.rb +107 -0
  28. data/lib/agent_xmpp/patches.rb +7 -0
  29. data/lib/agent_xmpp/patches/array.rb +32 -0
  30. data/lib/agent_xmpp/patches/float.rb +10 -0
  31. data/lib/agent_xmpp/patches/hash.rb +13 -0
  32. data/lib/agent_xmpp/patches/object.rb +15 -0
  33. data/lib/agent_xmpp/patches/rexml.rb +69 -0
  34. data/lib/agent_xmpp/patches/string.rb +15 -0
  35. data/lib/agent_xmpp/xmpp.rb +18 -0
  36. data/lib/agent_xmpp/xmpp/element.rb +158 -0
  37. data/lib/agent_xmpp/xmpp/entry.rb +36 -0
  38. data/lib/agent_xmpp/xmpp/error_response.rb +189 -0
  39. data/lib/agent_xmpp/xmpp/iq.rb +90 -0
  40. data/lib/agent_xmpp/xmpp/iq_command.rb +54 -0
  41. data/lib/agent_xmpp/xmpp/iq_disco.rb +206 -0
  42. data/lib/agent_xmpp/xmpp/iq_pubsub.rb +270 -0
  43. data/lib/agent_xmpp/xmpp/iq_roster.rb +183 -0
  44. data/lib/agent_xmpp/xmpp/iq_version.rb +89 -0
  45. data/lib/agent_xmpp/xmpp/jid.rb +150 -0
  46. data/lib/agent_xmpp/xmpp/message.rb +82 -0
  47. data/lib/agent_xmpp/xmpp/presence.rb +127 -0
  48. data/lib/agent_xmpp/xmpp/sasl.rb +241 -0
  49. data/lib/agent_xmpp/xmpp/stanza.rb +107 -0
  50. data/lib/agent_xmpp/xmpp/x_data.rb +357 -0
  51. data/test/app/app.rb +339 -0
  52. data/test/cases/test_application_message_processing.rb +65 -0
  53. data/test/cases/test_errors.rb +24 -0
  54. data/test/cases/test_presence_management.rb +139 -0
  55. data/test/cases/test_roster_management.rb +214 -0
  56. data/test/cases/test_service_discovery.rb +168 -0
  57. data/test/cases/test_session_management.rb +120 -0
  58. data/test/cases/test_version_discovery.rb +67 -0
  59. data/test/helpers/matchers.rb +23 -0
  60. data/test/helpers/mocks.rb +82 -0
  61. data/test/helpers/test_case_extensions.rb +45 -0
  62. data/test/helpers/test_client.rb +44 -0
  63. data/test/helpers/test_delegate.rb +60 -0
  64. data/test/helpers/test_helper.rb +91 -0
  65. data/test/messages/application_messages.rb +206 -0
  66. data/test/messages/error_messages.rb +35 -0
  67. data/test/messages/presence_messages.rb +66 -0
  68. data/test/messages/roster_messages.rb +126 -0
  69. data/test/messages/service_discovery_messages.rb +201 -0
  70. data/test/messages/session_messages.rb +158 -0
  71. data/test/messages/version_discovery_messages.rb +69 -0
  72. data/test/peer/peer.rb +21 -0
  73. metadata +187 -0
@@ -0,0 +1,89 @@
1
+ # Original from XMPP4R - XMPP Library for Ruby Website::http://home.gna.org/xmpp4r/
2
+ ##############################################################################################################
3
+ module AgentXmpp
4
+
5
+ #####-------------------------------------------------------------------------------------------------------
6
+ module Xmpp
7
+
8
+ #.......................................................................................................
9
+ class IqVersion < IqQuery
10
+
11
+ #.......................................................................................................
12
+ name_xmlns 'query', 'jabber:iq:version'
13
+
14
+ #####-----------------------------------------------------------------------------------------------------
15
+ class << self
16
+
17
+ #.........................................................................................................
18
+ def get(pipe, contact_jid)
19
+ iq = Xmpp::Iq.new(:get, contact_jid)
20
+ iq.query = new
21
+ Send(iq) do |r|
22
+ if (r.type == :result) && r.query.kind_of?(Xmpp::IqVersion)
23
+ pipe.broadcast_to_delegates(:on_version_result, pipe, r)
24
+ elsif r.type.eql?(:error)
25
+ pipe.broadcast_to_delegates(:on_version_error, pipe, r)
26
+ end
27
+ end
28
+ end
29
+
30
+ #.........................................................................................................
31
+ def result(pipe, request)
32
+ iq = Xmpp::Iq.new(:result, request.from.to_s)
33
+ iq.id = request.id unless request.id.nil?
34
+ iq.query = new
35
+ iq.query.iname = AgentXmpp::AGENT_XMPP_NAME
36
+ iq.query.version = AgentXmpp::VERSION
37
+ iq.query.os = AgentXmpp::OS_VERSION
38
+ Send(iq)
39
+ end
40
+
41
+ #### self
42
+ end
43
+
44
+ #.......................................................................................................
45
+ def initialize(iname=nil, version=nil, os=nil)
46
+ super()
47
+ self.iname = iname if iname
48
+ self.version = version if version
49
+ self.os = os if os
50
+ end
51
+
52
+ #.......................................................................................................
53
+ def iname
54
+ first_element_text('name')
55
+ end
56
+
57
+ #.......................................................................................................
58
+ def iname=(text)
59
+ replace_element_text('name', text.nil? ? '' : text)
60
+ end
61
+
62
+ #.......................................................................................................
63
+ def version
64
+ first_element_text('version')
65
+ end
66
+
67
+ #.......................................................................................................
68
+ def version=(text)
69
+ replace_element_text('version', text.nil? ? '' : text)
70
+ end
71
+
72
+ #.......................................................................................................
73
+ def os
74
+ first_element_text('os')
75
+ end
76
+
77
+ #.......................................................................................................
78
+ def os=(text)
79
+ replace_element_text('os', text.nil? ? '' : text)
80
+ end
81
+
82
+ #### IqQueryVersion
83
+ end
84
+
85
+ #### XMPP
86
+ end
87
+
88
+ #### AgentXmpp
89
+ end
@@ -0,0 +1,150 @@
1
+ # Original from XMPP4R - XMPP Library for Ruby Website::http://home.gna.org/xmpp4r/
2
+ ##############################################################################################################
3
+ module AgentXmpp
4
+
5
+ #####-------------------------------------------------------------------------------------------------------
6
+ module Xmpp
7
+
8
+ #####-------------------------------------------------------------------------------------------------------
9
+ class Jid
10
+
11
+ #.......................................................................................................
12
+ include Comparable
13
+
14
+ #.......................................................................................................
15
+ PATTERN = /^(?:([^@]*)@)??([^@\/]*)(?:\/(.*?))?$/
16
+
17
+ #.......................................................................................................
18
+ begin
19
+ require 'idn'
20
+ USE_STRINGPREP = true
21
+ rescue LoadError
22
+ USE_STRINGPREP = false
23
+ end
24
+
25
+ #.......................................................................................................
26
+ def initialize(node = "", domain = nil, resource = nil)
27
+ @resource = resource
28
+ @domain = domain
29
+ @node = node
30
+ if @domain.nil? and @resource.nil? and @node
31
+ @node, @domain, @resource = @node.to_s.scan(PATTERN).first
32
+ end
33
+ if USE_STRINGPREP
34
+ @node = IDN::Stringprep.nodeprep(@node) if @node
35
+ @domain = IDN::Stringprep.nameprep(@domain) if @domain
36
+ @resource = IDN::Stringprep.resourceprep(@resource) if @resource
37
+ else
38
+ @node.downcase! if @node
39
+ @domain.downcase! if @domain
40
+ end
41
+ raise ArgumentError, 'Node too long' if (@node || '').length > 1023
42
+ raise ArgumentError, 'Domain too long' if (@domain || '').length > 1023
43
+ raise ArgumentError, 'Resource too long' if (@resource || '').length > 1023
44
+ end
45
+
46
+ #.......................................................................................................
47
+ def to_s
48
+ s = @domain
49
+ s = "#{@node}@#{s}" if @node
50
+ s += "/#{@resource}" if @resource
51
+ return s
52
+ end
53
+
54
+ #.......................................................................................................
55
+ def strip
56
+ Jid.new(@node, @domain)
57
+ end
58
+ alias_method :bare, :strip
59
+
60
+ #.......................................................................................................
61
+ def strip!
62
+ @resource = nil
63
+ self
64
+ end
65
+ alias_method :bare!, :strip!
66
+
67
+ #.......................................................................................................
68
+ def hash
69
+ return to_s.hash
70
+ end
71
+
72
+ #.......................................................................................................
73
+ def eql?(o)
74
+ to_s.eql?(o.to_s)
75
+ end
76
+
77
+ #.......................................................................................................
78
+ def ==(o)
79
+ to_s == o.to_s
80
+ end
81
+
82
+ #.......................................................................................................
83
+ def <=>(o)
84
+ to_s <=> o.to_s
85
+ end
86
+
87
+ #.......................................................................................................
88
+ def node
89
+ @node
90
+ end
91
+
92
+ #.......................................................................................................
93
+ def node=(v)
94
+ @node = v.to_s
95
+ if USE_STRINGPREP
96
+ @node = IDN::Stringprep.nodeprep(@node) if @node
97
+ end
98
+ end
99
+
100
+ #.......................................................................................................
101
+ def domain
102
+ return nil if @domain.empty?
103
+ @domain
104
+ end
105
+
106
+ #.......................................................................................................
107
+ def domain=(v)
108
+ @domain = v.to_s
109
+ if USE_STRINGPREP
110
+ @domain = IDN::Stringprep.nodeprep(@domain)
111
+ end
112
+ end
113
+
114
+ #.......................................................................................................
115
+ def resource
116
+ @resource
117
+ end
118
+
119
+ #.......................................................................................................
120
+ def resource=(v)
121
+ @resource = v.to_s
122
+ if USE_STRINGPREP
123
+ @resource = IDN::Stringprep.nodeprep(@resource)
124
+ end
125
+ end
126
+
127
+ #.......................................................................................................
128
+ def Jid::escape(jid)
129
+ return jid.to_s.gsub('@', '%')
130
+ end
131
+
132
+ #.......................................................................................................
133
+ def empty?
134
+ to_s.empty?
135
+ end
136
+
137
+ #.......................................................................................................
138
+ def stripped?
139
+ @resource.nil?
140
+ end
141
+ alias_method :bared?, :stripped?
142
+
143
+ #### Jid
144
+ end
145
+
146
+ #### XMPP
147
+ end
148
+
149
+ #### AgentXmpp
150
+ end
@@ -0,0 +1,82 @@
1
+ # Original from XMPP4R - XMPP Library for Ruby Website::http://home.gna.org/xmpp4r/
2
+ ##############################################################################################################
3
+ module AgentXmpp
4
+
5
+ #####-------------------------------------------------------------------------------------------------------
6
+ module Xmpp
7
+
8
+ #####-------------------------------------------------------------------------------------------------------
9
+ class Message < Stanza
10
+
11
+ #.......................................................................................................
12
+ name_xmlns 'message', 'jabber:client'
13
+ xmpp_child :actions, :event
14
+
15
+ #####-----------------------------------------------------------------------------------------------------
16
+ class << self
17
+
18
+ #.........................................................................................................
19
+ def chat(to, body)
20
+ message = Xmpp::Message.new(to, body)
21
+ message.type = :chat
22
+ Send(message)
23
+ end
24
+
25
+ #### self
26
+ end
27
+
28
+ #.......................................................................................................
29
+ include XParent
30
+
31
+ #.......................................................................................................
32
+ def initialize(to = nil, body = nil)
33
+ super()
34
+ self.to = to if to
35
+ add_element(REXML::Element.new("body").add_text(body)) if body
36
+ end
37
+
38
+ #.......................................................................................................
39
+ def type
40
+ stanza_type = attributes['type']
41
+ stanza_type.nil? ? :normal : stanza_type.to_sym
42
+ end
43
+
44
+ #.......................................................................................................
45
+ def body
46
+ first_element_text('body')
47
+ end
48
+
49
+ #.......................................................................................................
50
+ def body=(b)
51
+ replace_element_text('body', b)
52
+ end
53
+
54
+ #.......................................................................................................
55
+ def subject=(s)
56
+ replace_element_text('subject', s)
57
+ end
58
+
59
+ #.......................................................................................................
60
+ def subject
61
+ first_element_text('subject')
62
+ end
63
+
64
+ #.......................................................................................................
65
+ def thread=(s)
66
+ delete_elements('thread')
67
+ replace_element_text('thread', s) if s
68
+ end
69
+
70
+ #.......................................................................................................
71
+ def thread
72
+ first_element_text('thread')
73
+ end
74
+
75
+ #### Message
76
+ end
77
+
78
+ #### XMPP
79
+ end
80
+
81
+ #### AgentXmpp
82
+ end
@@ -0,0 +1,127 @@
1
+ # Original from XMPP4R - XMPP Library for Ruby Website::http://home.gna.org/xmpp4r/
2
+ ##############################################################################################################
3
+ module AgentXmpp
4
+
5
+ #####-------------------------------------------------------------------------------------------------------
6
+ module Xmpp
7
+
8
+ #####-------------------------------------------------------------------------------------------------------
9
+ class Presence < Stanza
10
+
11
+ #.......................................................................................................
12
+ include Comparable
13
+ include XParent
14
+
15
+ #.......................................................................................................
16
+ name_xmlns 'presence', 'jabber:client'
17
+
18
+ #####-------------------------------------------------------------------------------------------------------
19
+ class << self
20
+
21
+ #.........................................................................................................
22
+ def accept(contact_jid)
23
+ pres = Xmpp::Presence.new
24
+ pres.type = :subscribed
25
+ pres.to = contact_jid
26
+ Send(pres)
27
+ end
28
+
29
+ #.........................................................................................................
30
+ def decline(contact_jid)
31
+ pres = Xmpp::Presence.new
32
+ pres.type = :unsubscribed
33
+ pres.to = contact_jid
34
+ Send(pres)
35
+ end
36
+
37
+ #.........................................................................................................
38
+ def subscribe(contact_jid)
39
+ pres = Xmpp::Presence.new
40
+ pres.type = :subscribe
41
+ pres.to = contact_jid
42
+ Send(pres)
43
+ end
44
+
45
+ #### self
46
+ end
47
+
48
+ #.......................................................................................................
49
+ def initialize(show=nil, status=nil, priority=nil)
50
+ super()
51
+ self.show = show if show
52
+ self.status = status if status
53
+ self.priority = priority if priority
54
+ end
55
+
56
+ #.......................................................................................................
57
+ def show
58
+ e = first_element('show')
59
+ text = e ? e.text : nil
60
+ text.to_sym
61
+ end
62
+
63
+ #.......................................................................................................
64
+ def show=(val)
65
+ xe = first_element('show')
66
+ if xe.nil?
67
+ xe = add_element('show')
68
+ end
69
+ if text.nil?
70
+ delete_element(xe)
71
+ else
72
+ xe.text = text
73
+ end
74
+ end
75
+
76
+ #.......................................................................................................
77
+ def status
78
+ first_element_text('status')
79
+ end
80
+
81
+ #.......................................................................................................
82
+ def status=(val)
83
+ val.nil? ? delete_element('status') : replace_element_text('status', val)
84
+ end
85
+
86
+ #.......................................................................................................
87
+ def priority
88
+ (e = first_element_text('priority')).nil? ? nil : e.to_i
89
+ end
90
+
91
+ #.......................................................................................................
92
+ def priority=(val)
93
+ val.nil? ? delete_element('priority') : replace_element_text('priority', val)
94
+ end
95
+
96
+ #.......................................................................................................
97
+ def <=>(o)
98
+ priority.to_i == o.priority.to_i ? cmp_interest(o) : priority.to_i <=> o.priority.to_i
99
+ end
100
+
101
+ #.......................................................................................................
102
+ PRESENCE_STATUS = { :chat => 4,
103
+ nil => 3,
104
+ :dnd => 2,
105
+ :away => 1,
106
+ :xa => 0,
107
+ :unavailable => -1,
108
+ :error => -2 }
109
+ #.......................................................................................................
110
+ def cmp_interest(o)
111
+ if type.nil?
112
+ o.type.nil? ? PRESENCE_STATUS[show] <=> PRESENCE_STATUS[o.show] : -1
113
+ elsif o.type.nil?
114
+ return 1
115
+ else
116
+ return 0
117
+ end
118
+ end
119
+
120
+ #### Presence
121
+ end
122
+
123
+ #### XMPP
124
+ end
125
+
126
+ #### AgentXmpp
127
+ end