xmpp4r 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/ChangeLog +28 -0
- data/LICENSE +59 -0
- data/README +20 -0
- data/Rakefile +103 -0
- data/UPDATING +40 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/README +57 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +425 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.rb +344 -0
- data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
- data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
- data/data/doc/xmpp4r/examples/advanced/migrate.rb +89 -0
- data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
- data/data/doc/xmpp4r/examples/advanced/recvfile.rb +83 -0
- data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +130 -0
- data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
- data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
- data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +90 -0
- data/data/doc/xmpp4r/examples/advanced/xmpping.rb +134 -0
- data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +9 -0
- data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/client.rb +68 -0
- data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
- data/data/doc/xmpp4r/examples/basic/echo_nonthreaded.rb +32 -0
- data/data/doc/xmpp4r/examples/basic/echo_threaded.rb +32 -0
- data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/mass_sender.rb +67 -0
- data/data/doc/xmpp4r/examples/basic/mucinfo.rb +39 -0
- data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +83 -0
- data/data/doc/xmpp4r/examples/basic/register.rb +25 -0
- data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
- data/data/doc/xmpp4r/examples/basic/roster.rb +42 -0
- data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
- data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
- data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +172 -0
- data/data/doc/xmpp4r/examples/basic/send_vcard.rb +68 -0
- data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
- data/data/doc/xmpp4r/examples/buggy/jabber2jabber/jabber2jabber.rb +18 -0
- data/data/doc/xmpp4r/examples/buggy/miniedgarr_cgi.rb +192 -0
- data/data/doc/xmpp4r/examples/buggy/miniedgarr_watch.rb +82 -0
- data/lib/callbacks.rb +122 -0
- data/lib/xmpp4r/authenticationfailure.rb +13 -0
- data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +315 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +256 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +30 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +46 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +151 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +85 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +178 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +56 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +61 -0
- data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +177 -0
- data/lib/xmpp4r/bytestreams/iq/si.rb +221 -0
- data/lib/xmpp4r/bytestreams.rb +11 -0
- data/lib/xmpp4r/client.rb +249 -0
- data/lib/xmpp4r/component.rb +103 -0
- data/lib/xmpp4r/connection.rb +166 -0
- data/lib/xmpp4r/dataforms/x/data.rb +248 -0
- data/lib/xmpp4r/dataforms.rb +1 -0
- data/lib/xmpp4r/debuglog.rb +34 -0
- data/lib/xmpp4r/delay/x/delay.rb +100 -0
- data/lib/xmpp4r/delay.rb +1 -0
- data/lib/xmpp4r/discovery/iq/discoinfo.rb +225 -0
- data/lib/xmpp4r/discovery/iq/discoitems.rb +162 -0
- data/lib/xmpp4r/discovery.rb +2 -0
- data/lib/xmpp4r/error.rb +230 -0
- data/lib/xmpp4r/errorexception.rb +32 -0
- data/lib/xmpp4r/feature_negotiation/iq/feature.rb +42 -0
- data/lib/xmpp4r/feature_negotiation.rb +1 -0
- data/lib/xmpp4r/idgenerator.rb +37 -0
- data/lib/xmpp4r/iq.rb +229 -0
- data/lib/xmpp4r/jid.rb +167 -0
- data/lib/xmpp4r/message.rb +171 -0
- data/lib/xmpp4r/muc/helper/mucbrowser.rb +107 -0
- data/lib/xmpp4r/muc/helper/mucclient.rb +382 -0
- data/lib/xmpp4r/muc/helper/simplemucclient.rb +222 -0
- data/lib/xmpp4r/muc/x/muc.rb +98 -0
- data/lib/xmpp4r/muc/x/mucuserinvite.rb +58 -0
- data/lib/xmpp4r/muc/x/mucuseritem.rb +148 -0
- data/lib/xmpp4r/muc.rb +6 -0
- data/lib/xmpp4r/presence.rb +255 -0
- data/lib/xmpp4r/query.rb +43 -0
- data/lib/xmpp4r/rexmladdons.rb +826 -0
- data/lib/xmpp4r/roster/helper/roster.rb +514 -0
- data/lib/xmpp4r/roster/iq/roster.rb +244 -0
- data/lib/xmpp4r/roster/x/roster.rb +155 -0
- data/lib/xmpp4r/roster.rb +4 -0
- data/lib/xmpp4r/sasl.rb +167 -0
- data/lib/xmpp4r/stream.rb +543 -0
- data/lib/xmpp4r/streamparser.rb +77 -0
- data/lib/xmpp4r/vcard/helper/vcard.rb +86 -0
- data/lib/xmpp4r/vcard/iq/vcard.rb +102 -0
- data/lib/xmpp4r/vcard.rb +3 -0
- data/lib/xmpp4r/version/helper/responder.rb +71 -0
- data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
- data/lib/xmpp4r/version/iq/version.rb +118 -0
- data/lib/xmpp4r/version.rb +3 -0
- data/lib/xmpp4r/x.rb +43 -0
- data/lib/xmpp4r/xmlstanza.rb +174 -0
- data/lib/xmpp4r/xmpp4r.rb +16 -0
- data/lib/xmpp4r.rb +122 -0
- data/setup.rb +1360 -0
- data/test/bytestreams/tc_ibb.rb +186 -0
- data/test/bytestreams/tc_socks5bytestreams.rb +57 -0
- data/test/delay/tc_xdelay.rb +51 -0
- data/test/lib/clienttester.rb +110 -0
- data/test/muc/tc_muc_mucclient.rb +569 -0
- data/test/muc/tc_muc_simplemucclient.rb +72 -0
- data/test/roster/.tc_helper.rb.swp +0 -0
- data/test/roster/tc_helper.rb +389 -0
- data/test/roster/tc_iqqueryroster.rb +140 -0
- data/test/roster/tc_xroster.rb +70 -0
- data/test/tc_callbacks.rb +128 -0
- data/test/tc_class_names.rb +129 -0
- data/test/tc_client.rb +30 -0
- data/test/tc_error.rb +103 -0
- data/test/tc_idgenerator.rb +30 -0
- data/test/tc_iq.rb +109 -0
- data/test/tc_iqquery.rb +31 -0
- data/test/tc_jid.rb +202 -0
- data/test/tc_message.rb +114 -0
- data/test/tc_presence.rb +148 -0
- data/test/tc_stream.rb +182 -0
- data/test/tc_streamError.rb +87 -0
- data/test/tc_streamSend.rb +59 -0
- data/test/tc_streamThreaded.rb +168 -0
- data/test/tc_xmlstanza.rb +76 -0
- data/test/ts_xmpp4r.rb +34 -0
- data/test/vcard/tc_iqvcard.rb +52 -0
- data/test/version/tc_helper.rb +46 -0
- data/test/version/tc_iqqueryversion.rb +96 -0
- data/tools/doctoweb.bash +30 -0
- data/tools/gen_requires.bash +10 -0
- metadata +232 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File::dirname(__FILE__) + '/../../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require File::dirname(__FILE__) + '/../lib/clienttester'
|
7
|
+
|
8
|
+
require 'xmpp4r'
|
9
|
+
require 'xmpp4r/bytestreams'
|
10
|
+
include Jabber
|
11
|
+
|
12
|
+
class IBBTest < Test::Unit::TestCase
|
13
|
+
include ClientTester
|
14
|
+
|
15
|
+
def create_buffer(size)
|
16
|
+
([nil] * size).collect { rand(256).chr }.join
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_ibb_target2initiator
|
20
|
+
target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
|
21
|
+
initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
|
22
|
+
|
23
|
+
buffer = create_buffer(9999)
|
24
|
+
|
25
|
+
Thread.new do
|
26
|
+
target.accept
|
27
|
+
target.write(buffer)
|
28
|
+
Thread.pass
|
29
|
+
target.close
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
initiator.open
|
34
|
+
|
35
|
+
received = ''
|
36
|
+
while buf = initiator.read
|
37
|
+
received += buf
|
38
|
+
end
|
39
|
+
|
40
|
+
initiator.close
|
41
|
+
|
42
|
+
assert_equal(buffer, received)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_ibb_initiator2target
|
46
|
+
target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
|
47
|
+
initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
|
48
|
+
|
49
|
+
buffer = create_buffer(9999)
|
50
|
+
|
51
|
+
Thread.new do
|
52
|
+
Thread.pass
|
53
|
+
initiator.open
|
54
|
+
initiator.write(buffer)
|
55
|
+
Thread.pass
|
56
|
+
initiator.close
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
target.accept
|
61
|
+
|
62
|
+
received = ''
|
63
|
+
while buf = target.read
|
64
|
+
received += buf
|
65
|
+
end
|
66
|
+
|
67
|
+
target.close
|
68
|
+
|
69
|
+
assert_equal(buffer, received)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_ibb_pingpong
|
73
|
+
ignored_stanzas = 0
|
74
|
+
wait = Mutex.new
|
75
|
+
wait.lock
|
76
|
+
@server.add_message_callback { ignored_stanzas += 1; wait.unlock }
|
77
|
+
@server.add_iq_callback { ignored_stanzas += 1; wait.unlock }
|
78
|
+
|
79
|
+
|
80
|
+
target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
|
81
|
+
initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
|
82
|
+
|
83
|
+
Thread.new do
|
84
|
+
target.accept
|
85
|
+
|
86
|
+
while buf = target.read
|
87
|
+
target.write(buf)
|
88
|
+
target.flush
|
89
|
+
end
|
90
|
+
|
91
|
+
target.close
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
assert_equal(0, ignored_stanzas)
|
96
|
+
@client.send("<iq from='1@a.com/1' type='set'>
|
97
|
+
<close xmlns='http://jabber.org/protocol/ibb' sid='another session id'/>
|
98
|
+
</iq>")
|
99
|
+
wait.lock
|
100
|
+
assert_equal(1, ignored_stanzas)
|
101
|
+
|
102
|
+
|
103
|
+
initiator.open
|
104
|
+
|
105
|
+
|
106
|
+
assert_equal(1, ignored_stanzas)
|
107
|
+
@client.send("<message from='1@a.com/1' type='error'>
|
108
|
+
<data xmlns='http://jabber.org/protocol/ibb' sid='another session id' seq='0'/>
|
109
|
+
</message>")
|
110
|
+
wait.lock
|
111
|
+
assert_equal(2, ignored_stanzas)
|
112
|
+
@client.send("<iq from='1@a.com/1' type='set'>
|
113
|
+
<close xmlns='http://jabber.org/protocol/ibb' sid='another session id'/>
|
114
|
+
</iq>")
|
115
|
+
wait.lock
|
116
|
+
assert_equal(3, ignored_stanzas)
|
117
|
+
|
118
|
+
|
119
|
+
10.times do
|
120
|
+
buf = create_buffer(9999)
|
121
|
+
initiator.write(buf)
|
122
|
+
initiator.flush
|
123
|
+
|
124
|
+
bufr = ''
|
125
|
+
begin
|
126
|
+
bufr += initiator.read
|
127
|
+
end while bufr.size < buf.size
|
128
|
+
assert_equal(buf, bufr)
|
129
|
+
end
|
130
|
+
|
131
|
+
initiator.close
|
132
|
+
|
133
|
+
|
134
|
+
assert_equal(3, ignored_stanzas)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_ibb_error
|
138
|
+
target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
|
139
|
+
initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
|
140
|
+
|
141
|
+
Thread.new do
|
142
|
+
target.accept
|
143
|
+
|
144
|
+
@server.send("<message from='1@a.com/1' type='error'>
|
145
|
+
<data xmlns='http://jabber.org/protocol/ibb' sid='#{target.instance_variable_get(:@session_id)}' seq='0'/>
|
146
|
+
</message>")
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
initiator.open
|
151
|
+
|
152
|
+
assert_nil(initiator.read)
|
153
|
+
|
154
|
+
initiator.close
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_ibb_inactive
|
158
|
+
target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
|
159
|
+
initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
|
160
|
+
|
161
|
+
assert_nil(target.read)
|
162
|
+
assert_nil(initiator.read)
|
163
|
+
|
164
|
+
assert_raise(RuntimeError) {
|
165
|
+
target.write('a' * target.block_size)
|
166
|
+
}
|
167
|
+
assert_raise(RuntimeError) {
|
168
|
+
initiator.write('a' * initiator.block_size)
|
169
|
+
}
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_ibb_queueitem
|
173
|
+
i1 = Bytestreams::IBBQueueItem.new(:close)
|
174
|
+
assert_equal(:close, i1.type)
|
175
|
+
assert_nil(i1.seq)
|
176
|
+
|
177
|
+
i2 = Bytestreams::IBBQueueItem.new(:data, 1, Base64::encode64('blah'))
|
178
|
+
assert_equal(:data, i2.type)
|
179
|
+
assert_equal(1, i2.seq)
|
180
|
+
assert_equal('blah', i2.data)
|
181
|
+
|
182
|
+
assert_raise(RuntimeError) {
|
183
|
+
i3 = Bytestreams::IBBQueueItem.new(:invalid)
|
184
|
+
}
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File::dirname(__FILE__) + '/../../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require File::dirname(__FILE__) + '/../lib/clienttester'
|
7
|
+
|
8
|
+
require 'xmpp4r'
|
9
|
+
require 'xmpp4r/bytestreams'
|
10
|
+
include Jabber
|
11
|
+
|
12
|
+
class SOCKS5BytestreamsTest < Test::Unit::TestCase
|
13
|
+
include ClientTester
|
14
|
+
|
15
|
+
@@server = Bytestreams::SOCKS5BytestreamsServer.new(65005)
|
16
|
+
@@server.add_address('localhost')
|
17
|
+
|
18
|
+
def create_buffer(size)
|
19
|
+
([nil] * size).collect { rand(256).chr }.join
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_pingpong
|
23
|
+
target = Bytestreams::SOCKS5BytestreamsTarget.new(@server, '1', '1@a.com/1', '1@a.com/2')
|
24
|
+
initiator = Bytestreams::SOCKS5BytestreamsInitiator.new(@client, '1', '1@a.com/1', '1@a.com/2')
|
25
|
+
initiator.add_streamhost(@@server)
|
26
|
+
|
27
|
+
|
28
|
+
Thread.new do
|
29
|
+
target.accept
|
30
|
+
|
31
|
+
while buf = target.read(256)
|
32
|
+
target.write(buf)
|
33
|
+
target.flush
|
34
|
+
end
|
35
|
+
|
36
|
+
target.close
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
initiator.open
|
41
|
+
|
42
|
+
10.times do
|
43
|
+
buf = create_buffer(8192)
|
44
|
+
initiator.write(buf)
|
45
|
+
initiator.flush
|
46
|
+
|
47
|
+
bufr = ''
|
48
|
+
begin
|
49
|
+
bufr += initiator.read(256)
|
50
|
+
end while bufr.size < buf.size
|
51
|
+
assert_equal(buf, bufr)
|
52
|
+
end
|
53
|
+
|
54
|
+
initiator.close
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File::dirname(__FILE__) + '/../../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'xmpp4r/rexmladdons'
|
7
|
+
require 'xmpp4r/delay/x/delay'
|
8
|
+
include Jabber
|
9
|
+
|
10
|
+
class XDelayTest < Test::Unit::TestCase
|
11
|
+
def test_create1
|
12
|
+
d = Delay::XDelay.new(false)
|
13
|
+
assert_equal(nil, d.stamp)
|
14
|
+
assert_equal(nil, d.from)
|
15
|
+
assert_equal('jabber:x:delay', d.namespace)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_create2
|
19
|
+
d = Delay::XDelay.new
|
20
|
+
# Hopefully the seconds don't change here...
|
21
|
+
assert_equal(Time.now.to_s, d.stamp.to_s)
|
22
|
+
assert_equal(nil, d.from)
|
23
|
+
assert_equal('jabber:x:delay', d.namespace)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_from
|
27
|
+
d = Delay::XDelay.new
|
28
|
+
assert_equal(nil, d.from)
|
29
|
+
d.from = JID::new('astro@spaceboyz.net')
|
30
|
+
assert_equal(JID::new('astro@spaceboyz.net'), d.from)
|
31
|
+
assert_equal(d, d.set_from(nil))
|
32
|
+
assert_equal(nil, d.from)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_stamp
|
36
|
+
d = Delay::XDelay.new(false)
|
37
|
+
assert_equal(nil, d.stamp)
|
38
|
+
now = Time.now
|
39
|
+
d.stamp = now
|
40
|
+
assert_equal(now.to_s, d.stamp.to_s)
|
41
|
+
assert_equal(d, d.set_stamp(nil))
|
42
|
+
assert_equal(nil, d.stamp)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_import
|
46
|
+
x1 = X.new
|
47
|
+
x1.add_namespace('jabber:x:delay')
|
48
|
+
x2 = X::import(x1)
|
49
|
+
assert_equal(Delay::XDelay, x2.class)
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
$:.unshift '../lib'
|
2
|
+
require 'xmpp4r'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'socket'
|
5
|
+
|
6
|
+
# Turn $VERBOSE off to suppress warnings about redefinition
|
7
|
+
oldverbose = $VERBOSE
|
8
|
+
$VERBOSE = false
|
9
|
+
|
10
|
+
module Jabber
|
11
|
+
##
|
12
|
+
# The ClientTester is a mix-in which provides a setup and teardown
|
13
|
+
# method to prepare a Stream object (@client) and two methods
|
14
|
+
# interfacing as the "server side":
|
15
|
+
# * send(xml):: Send a stanza to @client
|
16
|
+
# * receive:: (Wait and) retrieve a stanza sent by the client (in order)
|
17
|
+
#
|
18
|
+
# The server side is a stream, too: add your callbacks to @server
|
19
|
+
#
|
20
|
+
# ClientTester is written to test complex helper classes.
|
21
|
+
module ClientTester
|
22
|
+
@@SOCKET_PORT = 65223
|
23
|
+
|
24
|
+
def setup
|
25
|
+
Thread::abort_on_exception = true
|
26
|
+
|
27
|
+
servlisten = TCPServer.new(@@SOCKET_PORT)
|
28
|
+
serverwait = Mutex.new
|
29
|
+
serverwait.lock
|
30
|
+
Thread.new {
|
31
|
+
serversock = servlisten.accept
|
32
|
+
servlisten.close
|
33
|
+
serversock.sync = true
|
34
|
+
@server = Stream.new(true)
|
35
|
+
@server.add_xml_callback { |xml|
|
36
|
+
if xml.prefix == 'stream' and xml.name == 'stream'
|
37
|
+
send('<stream:stream>')
|
38
|
+
true
|
39
|
+
else
|
40
|
+
false
|
41
|
+
end
|
42
|
+
}
|
43
|
+
@server.start(serversock)
|
44
|
+
|
45
|
+
serverwait.unlock
|
46
|
+
}
|
47
|
+
|
48
|
+
clientsock = TCPSocket.new('localhost', @@SOCKET_PORT)
|
49
|
+
clientsock.sync = true
|
50
|
+
@client = Stream.new(true)
|
51
|
+
@client.start(clientsock)
|
52
|
+
|
53
|
+
@client.send('<stream:stream>') { |reply|
|
54
|
+
true
|
55
|
+
}
|
56
|
+
|
57
|
+
@state = 0
|
58
|
+
@states = []
|
59
|
+
@state_wait = Mutex.new
|
60
|
+
@state_wait.lock
|
61
|
+
@server.add_stanza_callback { |stanza|
|
62
|
+
if @state < @states.size
|
63
|
+
@states[@state].call(stanza)
|
64
|
+
@state += 1
|
65
|
+
end
|
66
|
+
@state_wait.unlock
|
67
|
+
|
68
|
+
false
|
69
|
+
}
|
70
|
+
|
71
|
+
serverwait.lock
|
72
|
+
end
|
73
|
+
|
74
|
+
def teardown
|
75
|
+
@client.close
|
76
|
+
@server.close
|
77
|
+
end
|
78
|
+
|
79
|
+
def send(xml)
|
80
|
+
@server.send(xml)
|
81
|
+
end
|
82
|
+
|
83
|
+
def receive
|
84
|
+
@receive_lock.lock
|
85
|
+
|
86
|
+
loop {
|
87
|
+
@stanzas_lock.synchronize {
|
88
|
+
if @stanzas.size > 0
|
89
|
+
@receive_lock.unlock
|
90
|
+
return @stanzas.shift
|
91
|
+
end
|
92
|
+
}
|
93
|
+
|
94
|
+
@receive_lock.lock
|
95
|
+
@receive_lock.unlock
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
def state(&block)
|
100
|
+
@states << block
|
101
|
+
end
|
102
|
+
|
103
|
+
def wait_state
|
104
|
+
@state_wait.lock
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Restore the old $VERBOSE setting
|
110
|
+
$VERBOSE = oldverbose
|