cancer 0.1.0.a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/.autotest +3 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE.txt +22 -0
  4. data/Rakefile +46 -0
  5. data/VERSION +1 -0
  6. data/cancer.gemspec +156 -0
  7. data/documentation/STREAM_INITIATION.markdown +18 -0
  8. data/examples/example.rb +80 -0
  9. data/examples/example_2.rb +20 -0
  10. data/examples/example_em.rb +11 -0
  11. data/examples/example_em_helper.rb +23 -0
  12. data/examples/example_im_roster.rb +26 -0
  13. data/examples/example_xep_0004.rb +124 -0
  14. data/examples/example_xep_0047.rb +35 -0
  15. data/examples/example_xep_0050.rb +78 -0
  16. data/examples/example_xep_0065.rb +66 -0
  17. data/examples/example_xep_0096.dup.rb +40 -0
  18. data/examples/example_xep_0096_xep_0047.rb +42 -0
  19. data/examples/example_xep_0096_xep_0065.rb +40 -0
  20. data/lib/cancer.rb +122 -0
  21. data/lib/cancer/adapter.rb +33 -0
  22. data/lib/cancer/adapters/em.rb +88 -0
  23. data/lib/cancer/adapters/socket.rb +122 -0
  24. data/lib/cancer/builder.rb +28 -0
  25. data/lib/cancer/controller.rb +32 -0
  26. data/lib/cancer/dependencies.rb +187 -0
  27. data/lib/cancer/events/abstract_event.rb +10 -0
  28. data/lib/cancer/events/base_matchers.rb +63 -0
  29. data/lib/cancer/events/binary_matchers.rb +30 -0
  30. data/lib/cancer/events/eventable.rb +92 -0
  31. data/lib/cancer/events/exception_events.rb +28 -0
  32. data/lib/cancer/events/handler.rb +33 -0
  33. data/lib/cancer/events/manager.rb +130 -0
  34. data/lib/cancer/events/named_events.rb +25 -0
  35. data/lib/cancer/events/proc_matcher.rb +16 -0
  36. data/lib/cancer/events/xml_events.rb +44 -0
  37. data/lib/cancer/exceptions.rb +53 -0
  38. data/lib/cancer/jid.rb +215 -0
  39. data/lib/cancer/lock.rb +32 -0
  40. data/lib/cancer/spec.rb +35 -0
  41. data/lib/cancer/spec/error.rb +18 -0
  42. data/lib/cancer/spec/extentions.rb +79 -0
  43. data/lib/cancer/spec/matcher.rb +30 -0
  44. data/lib/cancer/spec/mock_adapter.rb +139 -0
  45. data/lib/cancer/spec/mock_stream.rb +15 -0
  46. data/lib/cancer/spec/transcript.rb +107 -0
  47. data/lib/cancer/stream.rb +182 -0
  48. data/lib/cancer/stream/builder.rb +20 -0
  49. data/lib/cancer/stream/controller.rb +36 -0
  50. data/lib/cancer/stream/event_helper.rb +12 -0
  51. data/lib/cancer/stream/xep.rb +52 -0
  52. data/lib/cancer/stream_parser.rb +144 -0
  53. data/lib/cancer/support.rb +27 -0
  54. data/lib/cancer/support/hash.rb +32 -0
  55. data/lib/cancer/support/string.rb +22 -0
  56. data/lib/cancer/synchronized_stanza.rb +79 -0
  57. data/lib/cancer/thread_pool.rb +118 -0
  58. data/lib/cancer/xep.rb +43 -0
  59. data/lib/cancer/xeps/core.rb +109 -0
  60. data/lib/cancer/xeps/core/bind.rb +33 -0
  61. data/lib/cancer/xeps/core/sasl.rb +113 -0
  62. data/lib/cancer/xeps/core/session.rb +22 -0
  63. data/lib/cancer/xeps/core/stream.rb +18 -0
  64. data/lib/cancer/xeps/core/terminator.rb +21 -0
  65. data/lib/cancer/xeps/core/tls.rb +34 -0
  66. data/lib/cancer/xeps/im.rb +323 -0
  67. data/lib/cancer/xeps/xep_0004_x_data.rb +692 -0
  68. data/lib/cancer/xeps/xep_0020_feature_neg.rb +35 -0
  69. data/lib/cancer/xeps/xep_0030_disco.rb +167 -0
  70. data/lib/cancer/xeps/xep_0047_ibb.rb +322 -0
  71. data/lib/cancer/xeps/xep_0050_commands.rb +256 -0
  72. data/lib/cancer/xeps/xep_0065_bytestreams.rb +306 -0
  73. data/lib/cancer/xeps/xep_0066_oob.rb +69 -0
  74. data/lib/cancer/xeps/xep_0095_si.rb +211 -0
  75. data/lib/cancer/xeps/xep_0096_si_filetransfer.rb +173 -0
  76. data/lib/cancer/xeps/xep_0114_component.rb +73 -0
  77. data/lib/cancer/xeps/xep_0115_caps.rb +180 -0
  78. data/lib/cancer/xeps/xep_0138_compress.rb +134 -0
  79. data/lib/cancer/xeps/xep_0144_rosterx.rb +250 -0
  80. data/lib/cancer/xeps/xep_0184_receipts.rb +40 -0
  81. data/lib/cancer/xeps/xep_0199_ping.rb +41 -0
  82. data/spec/spec.opts +2 -0
  83. data/spec/spec_helper.rb +14 -0
  84. data/spec/stream/stanza_errors_spec.rb +47 -0
  85. data/spec/stream/stream_errors_spec.rb +38 -0
  86. data/spec/stream/stream_initialization_spec.rb +160 -0
  87. data/spec/xep_0050/local_spec.rb +165 -0
  88. data/spec/xep_0050/remote_spec.rb +44 -0
  89. metadata +200 -0
@@ -0,0 +1,3 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ %w{.svn .hg .git vendor}.each {|exception| at.add_exception(exception)}
3
+ end
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ .yardoc
3
+ coverage/
4
+ doc/
5
+ pkg/
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009 Simon Menke
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+
2
+ begin
3
+ require 'yard'
4
+ YARD::Rake::YardocTask.new do |t|
5
+ t.files = FileList['lib/**/*.rb'].to_a
6
+ t.options = ['-m', 'markdown', '--files', FileList['documentation/*.markdown'].to_a.join(',')]
7
+ end
8
+ rescue LoadError
9
+ puts "YARD not available. Install it with: sudo gem install yard"
10
+ end
11
+
12
+ begin
13
+ require 'spec/rake/spectask'
14
+ desc "Run all examples"
15
+ Spec::Rake::SpecTask.new('spec') do |t|
16
+ t.spec_files = FileList['spec/**/*_spec.rb']
17
+ end
18
+
19
+ desc "Run all examples with RCov"
20
+ Spec::Rake::SpecTask.new('spec:rcov') do |t|
21
+ t.spec_files = FileList['spec/**/*_spec.rb']
22
+ t.rcov = true
23
+ t.rcov_opts = ['--exclude', 'examples', '--exclude', 'spec']
24
+ end
25
+ rescue LoadError
26
+ puts "RSpec not available. Install it with: sudo gem install rspec"
27
+ end
28
+
29
+ begin
30
+ require 'jeweler'
31
+ Jeweler::Tasks.new do |gemspec|
32
+ gemspec.name = "cancer"
33
+ gemspec.summary = "A Nokogiri based XMPP client library"
34
+ gemspec.description = "Building XMPP clients should be easy."
35
+ gemspec.email = "simon.menke@gmail.com"
36
+ gemspec.homepage = "http://github.com/simonmenke/cancer"
37
+ gemspec.authors = ["Simon Menke"]
38
+ gemspec.add_runtime_dependency 'nokogiri', '>= 1.3.3'
39
+ gemspec.add_runtime_dependency 'astro-ruby-sasl', '>= 0.0.3'
40
+ gemspec.add_runtime_dependency 'openssl-nonblock', '>= 0.2.0'
41
+ gemspec.add_runtime_dependency 'net-dns', '>= 0.5.3'
42
+ end
43
+ Jeweler::GemcutterTasks.new
44
+ rescue LoadError
45
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0.a1
@@ -0,0 +1,156 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cancer}
8
+ s.version = "0.1.0.a1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Simon Menke"]
12
+ s.date = %q{2009-10-28}
13
+ s.description = %q{Building XMPP clients should be easy.}
14
+ s.email = %q{simon.menke@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt"
17
+ ]
18
+ s.files = [
19
+ ".autotest",
20
+ ".gitignore",
21
+ "LICENSE.txt",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "cancer.gemspec",
25
+ "documentation/STREAM_INITIATION.markdown",
26
+ "examples/example.rb",
27
+ "examples/example_2.rb",
28
+ "examples/example_em.rb",
29
+ "examples/example_em_helper.rb",
30
+ "examples/example_im_roster.rb",
31
+ "examples/example_xep_0004.rb",
32
+ "examples/example_xep_0047.rb",
33
+ "examples/example_xep_0050.rb",
34
+ "examples/example_xep_0065.rb",
35
+ "examples/example_xep_0096.dup.rb",
36
+ "examples/example_xep_0096_xep_0047.rb",
37
+ "examples/example_xep_0096_xep_0065.rb",
38
+ "lib/cancer.rb",
39
+ "lib/cancer/adapter.rb",
40
+ "lib/cancer/adapters/em.rb",
41
+ "lib/cancer/adapters/socket.rb",
42
+ "lib/cancer/builder.rb",
43
+ "lib/cancer/controller.rb",
44
+ "lib/cancer/dependencies.rb",
45
+ "lib/cancer/events/abstract_event.rb",
46
+ "lib/cancer/events/base_matchers.rb",
47
+ "lib/cancer/events/binary_matchers.rb",
48
+ "lib/cancer/events/eventable.rb",
49
+ "lib/cancer/events/exception_events.rb",
50
+ "lib/cancer/events/handler.rb",
51
+ "lib/cancer/events/manager.rb",
52
+ "lib/cancer/events/named_events.rb",
53
+ "lib/cancer/events/proc_matcher.rb",
54
+ "lib/cancer/events/xml_events.rb",
55
+ "lib/cancer/exceptions.rb",
56
+ "lib/cancer/jid.rb",
57
+ "lib/cancer/lock.rb",
58
+ "lib/cancer/spec.rb",
59
+ "lib/cancer/spec/error.rb",
60
+ "lib/cancer/spec/extentions.rb",
61
+ "lib/cancer/spec/matcher.rb",
62
+ "lib/cancer/spec/mock_adapter.rb",
63
+ "lib/cancer/spec/mock_stream.rb",
64
+ "lib/cancer/spec/transcript.rb",
65
+ "lib/cancer/stream.rb",
66
+ "lib/cancer/stream/builder.rb",
67
+ "lib/cancer/stream/controller.rb",
68
+ "lib/cancer/stream/event_helper.rb",
69
+ "lib/cancer/stream/xep.rb",
70
+ "lib/cancer/stream_parser.rb",
71
+ "lib/cancer/support.rb",
72
+ "lib/cancer/support/hash.rb",
73
+ "lib/cancer/support/string.rb",
74
+ "lib/cancer/synchronized_stanza.rb",
75
+ "lib/cancer/thread_pool.rb",
76
+ "lib/cancer/xep.rb",
77
+ "lib/cancer/xeps/core.rb",
78
+ "lib/cancer/xeps/core/bind.rb",
79
+ "lib/cancer/xeps/core/sasl.rb",
80
+ "lib/cancer/xeps/core/session.rb",
81
+ "lib/cancer/xeps/core/stream.rb",
82
+ "lib/cancer/xeps/core/terminator.rb",
83
+ "lib/cancer/xeps/core/tls.rb",
84
+ "lib/cancer/xeps/im.rb",
85
+ "lib/cancer/xeps/xep_0004_x_data.rb",
86
+ "lib/cancer/xeps/xep_0020_feature_neg.rb",
87
+ "lib/cancer/xeps/xep_0030_disco.rb",
88
+ "lib/cancer/xeps/xep_0047_ibb.rb",
89
+ "lib/cancer/xeps/xep_0050_commands.rb",
90
+ "lib/cancer/xeps/xep_0065_bytestreams.rb",
91
+ "lib/cancer/xeps/xep_0066_oob.rb",
92
+ "lib/cancer/xeps/xep_0095_si.rb",
93
+ "lib/cancer/xeps/xep_0096_si_filetransfer.rb",
94
+ "lib/cancer/xeps/xep_0114_component.rb",
95
+ "lib/cancer/xeps/xep_0115_caps.rb",
96
+ "lib/cancer/xeps/xep_0138_compress.rb",
97
+ "lib/cancer/xeps/xep_0144_rosterx.rb",
98
+ "lib/cancer/xeps/xep_0184_receipts.rb",
99
+ "lib/cancer/xeps/xep_0199_ping.rb",
100
+ "spec/spec.opts",
101
+ "spec/spec_helper.rb",
102
+ "spec/stream/stanza_errors_spec.rb",
103
+ "spec/stream/stream_errors_spec.rb",
104
+ "spec/stream/stream_initialization_spec.rb",
105
+ "spec/xep_0050/local_spec.rb",
106
+ "spec/xep_0050/remote_spec.rb"
107
+ ]
108
+ s.homepage = %q{http://github.com/simonmenke/cancer}
109
+ s.rdoc_options = ["--charset=UTF-8"]
110
+ s.require_paths = ["lib"]
111
+ s.rubygems_version = %q{1.3.5}
112
+ s.summary = %q{A Nokogiri based XMPP client library}
113
+ s.test_files = [
114
+ "spec/spec_helper.rb",
115
+ "spec/stream/stanza_errors_spec.rb",
116
+ "spec/stream/stream_errors_spec.rb",
117
+ "spec/stream/stream_initialization_spec.rb",
118
+ "spec/xep_0050/local_spec.rb",
119
+ "spec/xep_0050/remote_spec.rb",
120
+ "examples/example.rb",
121
+ "examples/example_2.rb",
122
+ "examples/example_em.rb",
123
+ "examples/example_em_helper.rb",
124
+ "examples/example_im_roster.rb",
125
+ "examples/example_xep_0004.rb",
126
+ "examples/example_xep_0047.rb",
127
+ "examples/example_xep_0050.rb",
128
+ "examples/example_xep_0065.rb",
129
+ "examples/example_xep_0096.dup.rb",
130
+ "examples/example_xep_0096_xep_0047.rb",
131
+ "examples/example_xep_0096_xep_0065.rb"
132
+ ]
133
+
134
+ if s.respond_to? :specification_version then
135
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
136
+ s.specification_version = 3
137
+
138
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
139
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.3.3"])
140
+ s.add_runtime_dependency(%q<astro-ruby-sasl>, [">= 0.0.3"])
141
+ s.add_runtime_dependency(%q<openssl-nonblock>, [">= 0.2.0"])
142
+ s.add_runtime_dependency(%q<net-dns>, [">= 0.5.3"])
143
+ else
144
+ s.add_dependency(%q<nokogiri>, [">= 1.3.3"])
145
+ s.add_dependency(%q<astro-ruby-sasl>, [">= 0.0.3"])
146
+ s.add_dependency(%q<openssl-nonblock>, [">= 0.2.0"])
147
+ s.add_dependency(%q<net-dns>, [">= 0.5.3"])
148
+ end
149
+ else
150
+ s.add_dependency(%q<nokogiri>, [">= 1.3.3"])
151
+ s.add_dependency(%q<astro-ruby-sasl>, [">= 0.0.3"])
152
+ s.add_dependency(%q<openssl-nonblock>, [">= 0.2.0"])
153
+ s.add_dependency(%q<net-dns>, [">= 0.5.3"])
154
+ end
155
+ end
156
+
@@ -0,0 +1,18 @@
1
+ # The Stream Initiation Process
2
+
3
+ The stream initiation process is consists of multiple phases which are are ordered by priority. Some phases are optional others are required. Many techniques to sort the phases into a good order have been tried but a simple priority system seems to work best.
4
+
5
+
6
+ ## Phases and there priority
7
+
8
+ 1. Stream header element
9
+ 1. Stream Controller (priority 200; xmpp-core)
10
+ 2. Features element
11
+ 1. TLS Controller (priority 100; xmpp-core)
12
+ 2. SASL Controller (priority 200; xmpp-core)
13
+ 3. Compression Controller (priority 250; xep-0138)
14
+ 4. Bind Controller (priority 300; xmpp-core)
15
+ 5. Session Controller (priority 400; xmpp-core)
16
+ 6. Terminator Controller (priority 500; xmpp-core)
17
+
18
+ Each extension to Cancer that wants to add new feature negotiation abilities must register its priority with me (simon.menke@gmail.com) in order to prevent any conflicts with other extensions.
@@ -0,0 +1,80 @@
1
+ require '../lib/cancer'
2
+
3
+ =begin
4
+ options = { :jid => 'alice@xmpp.dev/ccc', :password => 'ihatethequeen', :xeps => %w( xep-0138 xep-0030 ) }
5
+ Cancer::Stream.open(options) do |stream|
6
+ stream.send {|x| x.presence(:priority => 10) }
7
+
8
+ p stream.disco_items_for('xmpp.dev')
9
+ p stream.disco_info_for('xmpp.dev')
10
+
11
+ stream.send {|x| x.presence(:type => :unavailable) }
12
+ end
13
+ =end
14
+
15
+
16
+ # a client
17
+ Cancer::Stream.open(:jid => 'alice@xmpp.dev/bbb', :password => 'ihatethequeen', :xeps => %w( xep-0138 xep-0184 )) do |other|
18
+ other.controller do
19
+
20
+ on { |e| e.xpath('/c:message/c:body', 'c' => Cancer::CLIENT_NS) }
21
+ def on_message_body(e)
22
+ # puts e.xml.first('/c:message/c:body').text
23
+ end
24
+
25
+ on { |e| e.exception(Exception) }
26
+ def on_exception(event)
27
+ $stderr.puts "#{event.exception.class} -- #{event.exception.message}\n#{event.exception.backtrace.join("\n")}"
28
+ $stderr.flush
29
+ end
30
+
31
+ end
32
+ other.send {|x| x.presence(:priority => 10) }
33
+
34
+ Cancer::Stream.open(:jid => 'alice@xmpp.dev/aaa', :password => 'ihatethequeen', :xeps => %w( xep-0138 xep-0184 )) do |stream|
35
+
36
+ $lock = Cancer::Lock.new
37
+ $count = $total = 0
38
+
39
+ stream.controller do
40
+
41
+ on { |e| e.xpath('/c:message', 'c' => Cancer::CLIENT_NS) }
42
+ def count_receipts(e)
43
+ $count += 1
44
+ if $count == $total
45
+ $lock.continue!
46
+ end
47
+ end
48
+
49
+ on { |e| e.exception(Exception) }
50
+ def on_exception(event)
51
+ $stderr.puts "#{event.exception.class} -- #{event.exception.message}\n#{event.exception.backtrace.join("\n")}"
52
+ $stderr.flush
53
+ end
54
+
55
+ end
56
+
57
+ stream.send {|x| x.presence(:priority => 5) }
58
+
59
+ 1000.times do
60
+ $total += 1
61
+ stream.send_message('alice@xmpp.dev/bbb') do |x|
62
+ x.body "Hello there #{$total}"
63
+ x.request_receipt
64
+ end
65
+ end
66
+
67
+ $lock.wait!
68
+ stream.send {|x| x.presence(:type => :unavailable) }
69
+
70
+ end
71
+
72
+ other.send {|x| x.presence(:type => :unavailable) }
73
+ end
74
+
75
+ # a component
76
+ Cancer::Stream.open(:jid => 'taurus.xmpp.dev', :password => 'taurus', :server => 'xmpp.dev', :port => 5275, :xeps => %w( xep-0114 )) do |stream|
77
+ stream.send {|x| x.presence(:priority => 5) { x.show } }
78
+ sleep 5
79
+ stream.send {|x| x.presence(:priority => 5, :type => :unavailable) }
80
+ end
@@ -0,0 +1,20 @@
1
+ require '../lib/cancer'
2
+
3
+ # Cancer.logger.level = Logger::WARN
4
+
5
+ # a client
6
+ Cancer::Stream.open(:jid => 'alice@xmpp.dev/bbb', :password => 'ihatethequeen', :xeps => %w( xep-0096 xep-0065 xep-0115 xep-0047 ), :server => 'xmpp.dev') do |other|
7
+ other.controller do
8
+
9
+ on { |e| e.si_file(:filename => /\.gem$/) }
10
+ def transfer_gem(e)
11
+ e.accept! :path => File.join(File.dirname(__FILE__), e.ft[:name])
12
+ end
13
+
14
+ end
15
+ other.send {|x| x.presence(:priority => 10) }
16
+
17
+ sleep 600
18
+
19
+ other.send {|x| x.presence(:type => :unavailable) }
20
+ end
@@ -0,0 +1,11 @@
1
+ require '../lib/cancer'
2
+
3
+ options = { :jid => 'alice@xmpp.dev/bbb', :password => 'ihatethequeen',
4
+ :adapter => Cancer::Adapters::EM, :xeps => %w( xep-0184 xep-0138 ) }
5
+
6
+ EM.run do
7
+ stream = Cancer::Stream.new(options)
8
+ stream.use lambda { |x| puts x.first('c:body').text rescue :next }
9
+ stream.use lambda { |x| :halt }
10
+ EM.defer { stream.open ; stream.send {|x| x.presence(:priority => 5) } }
11
+ end
@@ -0,0 +1,23 @@
1
+ require '../lib/cancer'
2
+
3
+ Cancer::Stream.open(:jid => 'alice@xmpp.dev/aaa', :password => 'ihatethequeen', :xeps => %w( xep-0138 xep-0184 )) do |stream|
4
+ lock = Cancer::Lock.new
5
+ count = total = 0
6
+ stream.use lambda { |x| x.first('/c:message') { |x| count += 1 ; lock.continue! if count == total } }
7
+ stream.use lambda { |x| :halt }
8
+
9
+
10
+ stream.send {|x| x.presence(:priority => 10) }
11
+
12
+ 1000.times do
13
+ total += 1
14
+ stream.send_message('alice@xmpp.dev/bbb') do |x|
15
+ x.body "Hello there"
16
+ x.request_receipt
17
+ end
18
+ end
19
+
20
+ lock.wait!
21
+ stream.send {|x| x.presence(:type => :unavailable) }
22
+
23
+ end
@@ -0,0 +1,26 @@
1
+ require '../lib/cancer'
2
+
3
+ # Cancer.logger.level = Logger::WARN
4
+
5
+ Cancer::Stream.open(:jid => 'alice@xmpp.dev/aaa', :password => 'ihatethequeen', :xeps => %w( im ), :server => 'xmpp.dev') do |stream|
6
+
7
+ stream.controller do
8
+
9
+ on { |e| e.subscription_request }
10
+ def accept_subscriptions(e)
11
+ roster.save(e.sender, :subscription => :subscribed)
12
+ roster.save(e.sender, :subscription => true)
13
+ end
14
+
15
+ end
16
+
17
+ stream.send {|x| x.presence(:priority => 5) }
18
+
19
+ stream.roster.save('simon@xmpp.dev', :name => 'Simon Menke', :groups => %w( Mr.\ Henry Friends ))
20
+ # stream.roster.save('simon@xmpp.dev', :subscription => false)
21
+ stream.roster.each do |item|
22
+ p item
23
+ end
24
+
25
+ stream.send {|x| x.presence(:type => :unavailable) }
26
+ end
@@ -0,0 +1,124 @@
1
+ require '../lib/cancer'
2
+ NS = 'jabber:x:data'
3
+
4
+
5
+
6
+ form = Nokogiri::XML.parse(%{
7
+ <x xmlns='jabber:x:data' type='form'>
8
+ <title>Bot Configuration</title>
9
+ <instructions>Fill out this form to configure your new bot!</instructions>
10
+ <field type='hidden'
11
+ var='FORM_TYPE'>
12
+ <value>jabber:bot</value>
13
+ </field>
14
+ <field type='fixed'><value>Section 1: Bot Info</value></field>
15
+ <field type='text-single'
16
+ label='The name of your bot'
17
+ var='botname'/>
18
+ <field type='text-multi'
19
+ label='Helpful description of your bot'
20
+ var='description'/>
21
+ <field type='boolean'
22
+ label='Public bot?'
23
+ var='public'>
24
+ <required/>
25
+ </field>
26
+ <field type='text-private'
27
+ label='Password for special access'
28
+ var='password'/>
29
+ <field type='fixed'><value>Section 2: Features</value></field>
30
+ <field type='list-multi'
31
+ label='What features will the bot support?'
32
+ var='features'>
33
+ <option label='Contests'><value>contests</value></option>
34
+ <option label='News'><value>news</value></option>
35
+ <option label='Polls'><value>polls</value></option>
36
+ <option label='Reminders'><value>reminders</value></option>
37
+ <option label='Search'><value>search</value></option>
38
+ <value>news</value>
39
+ <value>search</value>
40
+ </field>
41
+ <field type='fixed'><value>Section 3: Subscriber List</value></field>
42
+ <field type='list-single'
43
+ label='Maximum number of subscribers'
44
+ var='maxsubs'>
45
+ <value>20</value>
46
+ <option label='10'><value>10</value></option>
47
+ <option label='20'><value>20</value></option>
48
+ <option label='30'><value>30</value></option>
49
+ <option label='50'><value>50</value></option>
50
+ <option label='100'><value>100</value></option>
51
+ <option label='None'><value>none</value></option>
52
+ </field>
53
+ <field type='fixed'><value>Section 4: Invitations</value></field>
54
+ <field type='jid-multi'
55
+ label='People to invite'
56
+ var='invitelist'>
57
+ <desc>Tell all your friends about your new bot!</desc>
58
+ </field>
59
+ </x>}).root
60
+
61
+ # form_def = FormDefinition.load(form)
62
+ form = Cancer::XEP_0004::Form.load(form)
63
+ puts form.to_xml(:verbose => true)
64
+ p [:valid, form.valid?]
65
+ form.each do |k, v|
66
+ p [k, v]
67
+ end
68
+
69
+ form = Nokogiri::XML.parse(%{
70
+ <x xmlns='jabber:x:data' type='result'>
71
+ <title>Joogle Search: verona</title>
72
+ <reported>
73
+ <field var='name' label="Website" />
74
+ <field var='url' label="Location" />
75
+ </reported>
76
+ <item>
77
+ <field var='name'>
78
+ <value>Comune di Verona - Benvenuti nel sito ufficiale</value>
79
+ </field>
80
+ <field var='url'>
81
+ <value>http://www.comune.verona.it/</value>
82
+ </field>
83
+ </item>
84
+ <item>
85
+ <field var='name'>
86
+ <value>benvenuto!</value>
87
+ </field>
88
+ <field var='url'>
89
+ <value>http://www.hellasverona.it/</value>
90
+ </field>
91
+ </item>
92
+ <item>
93
+ <field var='name'>
94
+ <value>Universita degli Studi di Verona - Home Page</value>
95
+ </field>
96
+ <field var='url'>
97
+ <value>http://www.univr.it/</value>
98
+ </field>
99
+ </item>
100
+ <item>
101
+ <field var='name'>
102
+ <value>Aeroporti del Garda</value>
103
+ </field>
104
+ <field var='url'>
105
+ <value>http://www.aeroportoverona.it/</value>
106
+ </field>
107
+ </item>
108
+ <item>
109
+ <field var='name'>
110
+ <value>Veronafiere - fiera di Verona</value>
111
+ </field>
112
+ <field var='url'>
113
+ <value>http://www.veronafiere.it/</value>
114
+ </field>
115
+ </item>
116
+ </x>}).root
117
+ form = Cancer::XEP_0004::Form.load(form)
118
+ puts form.to_xml(:verbose => true)
119
+ p [:valid, form.valid?]
120
+ form.items.each do |item|
121
+ item.each do |k, v|
122
+ p [k, v]
123
+ end
124
+ end