stropheruby 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +9 -0
- data/History.txt +4 -0
- data/Manifest.txt +40 -0
- data/PostInstall.txt +4 -0
- data/README.txt +28 -0
- data/Rakefile +21 -0
- data/examples/xmpp_client.rb +77 -0
- data/ext/auth.c +990 -0
- data/ext/common.h +287 -0
- data/ext/conn.c +611 -0
- data/ext/ctx.c +416 -0
- data/ext/event.c +351 -0
- data/ext/extconf.rb +8 -0
- data/ext/handler.c +592 -0
- data/ext/hash.c +278 -0
- data/ext/hash.h +64 -0
- data/ext/jid.c +177 -0
- data/ext/md5.c +289 -0
- data/ext/md5.h +41 -0
- data/ext/ostypes.h +27 -0
- data/ext/parser.c +208 -0
- data/ext/sasl.c +614 -0
- data/ext/sasl.h +44 -0
- data/ext/sha1.c +389 -0
- data/ext/sha1.h +31 -0
- data/ext/snprintf.c +839 -0
- data/ext/sock.c +911 -0
- data/ext/sock.h +51 -0
- data/ext/stanza.c +908 -0
- data/ext/strophe.h +372 -0
- data/ext/strophe_ruby.c +721 -0
- data/ext/thread.c +119 -0
- data/ext/thread.h +43 -0
- data/ext/tls.h +46 -0
- data/ext/tls_dummy.c +89 -0
- data/ext/util.c +107 -0
- data/ext/util.h +32 -0
- data/lib/strophe_ruby.rb +6 -0
- data/test/test_helper.rb +3 -0
- data/test/test_strophe_ruby.rb +11 -0
- data/test/test_strophe_ruby_extn.rb +9 -0
- metadata +111 -0
data/.autotest
ADDED
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
.autotest
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
examples/xmpp_client.rb
|
8
|
+
ext/md5.c
|
9
|
+
ext/parser.c
|
10
|
+
ext/util.c
|
11
|
+
ext/strophe_ruby.c
|
12
|
+
ext/conn.c
|
13
|
+
ext/ctx.c
|
14
|
+
ext/jid.c
|
15
|
+
ext/handler.c
|
16
|
+
ext/hash.c
|
17
|
+
ext/sasl.c
|
18
|
+
ext/event.c
|
19
|
+
ext/auth.c
|
20
|
+
ext/thread.c
|
21
|
+
ext/stanza.c
|
22
|
+
ext/tls_dummy.c
|
23
|
+
ext/sha1.c
|
24
|
+
ext/snprintf.c
|
25
|
+
ext/sock.c
|
26
|
+
ext/tls.h
|
27
|
+
ext/sasl.h
|
28
|
+
ext/thread.h
|
29
|
+
ext/util.h
|
30
|
+
ext/common.h
|
31
|
+
ext/md5.h
|
32
|
+
ext/hash.h
|
33
|
+
ext/sha1.h
|
34
|
+
ext/sock.h
|
35
|
+
ext/strophe.h
|
36
|
+
ext/ostypes.h
|
37
|
+
lib/strophe_ruby.rb
|
38
|
+
test/test_helper.rb
|
39
|
+
test/test_strophe_ruby.rb
|
40
|
+
test/test_strophe_ruby_extn.rb
|
data/PostInstall.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
== OVERVIEW
|
2
|
+
|
3
|
+
Stropheruby is a ruby bindings for Strophe, a C library for writing XMPP clients.
|
4
|
+
|
5
|
+
This is a fork of flamontagne's stropheruby (http://github.com/flamontagne/stropheruby/tree/master) with the following improvements:
|
6
|
+
|
7
|
+
* A patched version of libstrophe (trunk) is included. So there is no extra library to install.
|
8
|
+
* (libstrophe) Fixed a timeout issue on Mac OSX: http://groups.google.com/group/strophe-dev/browse_thread/thread/ef4cb19785020fb6
|
9
|
+
* (libstrophe) Fixed basic auth: http://groups.google.com/group/strophe-dev/browse_thread/thread/b770f72c83d1a0b9
|
10
|
+
* (libstrophe) Changed xmpp_run_once's return code so that the application can tell if an error or timeout occurs
|
11
|
+
* (libstrophe) Better error reporting for login failure
|
12
|
+
* (libstrophe) If no password given, do not login. This will give 'register' a chance to run
|
13
|
+
* (stropheruby) Added send_raw_string method
|
14
|
+
* (stropheruby) Detect login failure
|
15
|
+
* (stropheruby) Fixed a resource leak
|
16
|
+
* (stropheruby) Added wrapper class for xmpp_stream_error_t (StropheRuby::StreamError)
|
17
|
+
|
18
|
+
== INSTALLATION
|
19
|
+
|
20
|
+
sudo gem sources -a http://gems.github.com
|
21
|
+
sudo gem install yong-stropheruby
|
22
|
+
|
23
|
+
For Rails app, add this line in your config/environment.rb:
|
24
|
+
config.gem "yong-stropheruby", :source => "http://gems.github.com", :lib => "strophe_ruby"
|
25
|
+
|
26
|
+
== EXAMPLE
|
27
|
+
|
28
|
+
See examples/xmpp_client.rb
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
|
4
|
+
EXT = "ext/strophe_ruby.#{Hoe::DLEXT}"
|
5
|
+
|
6
|
+
Hoe.new('stropheruby', '0.1.3') do |p|
|
7
|
+
p.developer('François Lamontagne', 'flamontagne@gmail.com')
|
8
|
+
p.summary = 'strophe_ruby'
|
9
|
+
|
10
|
+
p.spec_extras[:extensions] = "ext/extconf.rb"
|
11
|
+
p.clean_globs << EXT << "ext/*.o" << "ext/Makefile"
|
12
|
+
end
|
13
|
+
|
14
|
+
task :test => EXT
|
15
|
+
|
16
|
+
file EXT => ["ext/extconf.rb", "ext/strophe_ruby.c"] do
|
17
|
+
Dir.chdir "ext" do
|
18
|
+
ruby "extconf.rb"
|
19
|
+
sh "make"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'strophe_ruby'
|
2
|
+
|
3
|
+
class XmppClient
|
4
|
+
def query_roster(jid, password)
|
5
|
+
new_connection(jid, password) {
|
6
|
+
current_stage = 1
|
7
|
+
@connection.add_handler("iq") do |iq|
|
8
|
+
case current_stage
|
9
|
+
when 1
|
10
|
+
@connection.send_raw_string("<iq type='get' id='#{Time.now.to_i.to_s}'><query xmlns='jabber:iq:roster'/></iq>")
|
11
|
+
current_stage += 1
|
12
|
+
else
|
13
|
+
StropheRuby::EventLoop.stop(@ctx)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_user(jid, password)
|
20
|
+
new_connection(jid, "", false) {
|
21
|
+
#create_user is special, it does not wait for an iq reply to send the resgister message
|
22
|
+
@connection.add_handler("iq") do |iq|
|
23
|
+
StropheRuby::EventLoop.stop(@ctx)
|
24
|
+
end
|
25
|
+
username = jid.split('@')[0]
|
26
|
+
hostname = jid.split('@')[1]
|
27
|
+
@connection.send_raw_string("<iq type='set' id='#{Time.now.to_i.to_s}' to='#{hostname}' xmlns='jabber:client'><query xmlns='jabber:iq:register'><username>#{username}</username><password>#{password}</password></query></iq>")
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def new_connection(jid, password, login_can_not_fail = true)
|
34
|
+
lib = StropheRuby::EventLoop.prepare
|
35
|
+
@ctx = StropheRuby::Context.new(StropheRuby::Logging::DEBUG)
|
36
|
+
@connection = StropheRuby::Connection.new(@ctx)
|
37
|
+
@connection.jid = jid
|
38
|
+
@connection.password = password
|
39
|
+
logged_in = false
|
40
|
+
@connection.connect do |status, error, stream_error|
|
41
|
+
if !logged_in
|
42
|
+
if login_can_not_fail && status != StropheRuby::ConnectionEvents::CONNECT
|
43
|
+
#do somthing after login fails
|
44
|
+
raise "failed to login: #{error} #{stream_error}"
|
45
|
+
else
|
46
|
+
yield if block_given?
|
47
|
+
logged_in = true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
run_event_loop_until_timeout_or_stopped_by_callback!
|
53
|
+
end
|
54
|
+
|
55
|
+
#run event loop until timeout or 'StropheRuby::EventLoop.stop' is called inside callback
|
56
|
+
def run_event_loop_until_timeout_or_stopped_by_callback!(timeout = 3000)
|
57
|
+
raise 'unexpected state' if (@ctx.loop_status != StropheRuby::EventLoop::LOOP_NOTSTARTED)
|
58
|
+
@ctx.loop_status = StropheRuby::EventLoop::LOOP_RUNNING
|
59
|
+
|
60
|
+
while @ctx.loop_status == StropheRuby::EventLoop::LOOP_RUNNING
|
61
|
+
#return if the socket is idle for more than timeout (in millisecond)
|
62
|
+
if StropheRuby::EventLoop.run_once(@ctx, timeout) != 0
|
63
|
+
@connection.disconnect
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
@connection.disconnect
|
69
|
+
return true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
if $0 == __FILE__
|
74
|
+
client = XmppClient.new
|
75
|
+
client.create_user("test@localhost", 'password')
|
76
|
+
client.query_roster("test@localhost", 'password')
|
77
|
+
end
|