yong-stropheruby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +3 -2
- data/Rakefile +1 -1
- data/examples/xmpp_client.rb +15 -2
- data/ext/conn.c +2 -2
- data/ext/event.c +2 -0
- data/ext/parser.c +2 -0
- metadata +1 -1
data/README.txt
CHANGED
@@ -9,9 +9,10 @@ This is a fork of flamontagne's stropheruby (http://github.com/flamontagne/strop
|
|
9
9
|
* (libstrophe) Fixed basic auth: http://groups.google.com/group/strophe-dev/browse_thread/thread/b770f72c83d1a0b9
|
10
10
|
* (libstrophe) Changed xmpp_run_once's return code so that the application can tell if an error or timeout occurs
|
11
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
|
12
13
|
* (stropheruby) Added send_raw_string method
|
13
14
|
* (stropheruby) Detect login failure
|
14
|
-
* (stropheruby)
|
15
|
+
* (stropheruby) Fixed a resource leak
|
15
16
|
* (stropheruby) Added wrapper class for xmpp_stream_error_t (StropheRuby::StreamError)
|
16
17
|
|
17
18
|
== INSTALLATION
|
@@ -24,4 +25,4 @@ config.gem "yong-stropheruby", :source => "http://gems.github.com", :lib => "str
|
|
24
25
|
|
25
26
|
== EXAMPLE
|
26
27
|
|
27
|
-
See
|
28
|
+
See examples/xmpp_client.rb
|
data/Rakefile
CHANGED
data/examples/xmpp_client.rb
CHANGED
@@ -7,7 +7,7 @@ class XmppClient
|
|
7
7
|
@connection.add_handler("iq") do |iq|
|
8
8
|
case current_stage
|
9
9
|
when 1
|
10
|
-
@connection.send_raw_string("<iq type='get' id='
|
10
|
+
@connection.send_raw_string("<iq type='get' id='#{Time.now.to_i.to_s}'><query xmlns='jabber:iq:roster'/></iq>")
|
11
11
|
current_stage += 1
|
12
12
|
else
|
13
13
|
StropheRuby::EventLoop.stop(@ctx)
|
@@ -15,6 +15,18 @@ class XmppClient
|
|
15
15
|
end
|
16
16
|
}
|
17
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
|
18
30
|
|
19
31
|
private
|
20
32
|
|
@@ -60,5 +72,6 @@ end
|
|
60
72
|
|
61
73
|
if $0 == __FILE__
|
62
74
|
client = XmppClient.new
|
63
|
-
client.
|
75
|
+
client.create_user("test@localhost", 'password')
|
76
|
+
client.query_roster("test@localhost", 'password')
|
64
77
|
end
|
data/ext/conn.c
CHANGED
@@ -408,7 +408,7 @@ void conn_disconnect_clean(xmpp_conn_t * const conn)
|
|
408
408
|
{
|
409
409
|
/* remove the timed handler */
|
410
410
|
xmpp_timed_handler_delete(conn, _disconnect_cleanup);
|
411
|
-
|
411
|
+
conn->error = -4;
|
412
412
|
conn_disconnect(conn);
|
413
413
|
}
|
414
414
|
|
@@ -440,7 +440,7 @@ static int _disconnect_cleanup(xmpp_conn_t * const conn,
|
|
440
440
|
{
|
441
441
|
xmpp_debug(conn->ctx, "xmpp",
|
442
442
|
"disconnection forced by cleanup timeout");
|
443
|
-
|
443
|
+
conn->error = -5;
|
444
444
|
conn_disconnect(conn);
|
445
445
|
|
446
446
|
return 0;
|
data/ext/event.c
CHANGED
@@ -226,6 +226,7 @@ int xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
|
|
226
226
|
if (!sock_is_recoverable(sock_error())) {
|
227
227
|
xmpp_error(ctx, "xmpp", "event watcher internal error %d",
|
228
228
|
sock_error());
|
229
|
+
conn->error = sock_error();
|
229
230
|
return -1;
|
230
231
|
}
|
231
232
|
}
|
@@ -278,6 +279,7 @@ int xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
|
|
278
279
|
/* parse error, we need to shut down */
|
279
280
|
/* FIXME */
|
280
281
|
xmpp_debug(ctx, "xmpp", "parse error, disconnecting");
|
282
|
+
conn -> error = -1;
|
281
283
|
conn_disconnect(conn);
|
282
284
|
}
|
283
285
|
} else {
|
data/ext/parser.c
CHANGED
@@ -64,6 +64,7 @@ void parser_handle_start(void *userdata,
|
|
64
64
|
if (strcmp(name, "stream:stream") != 0) {
|
65
65
|
xmpp_error(conn->ctx, "xmpp",
|
66
66
|
"Server did not open valid stream.");
|
67
|
+
conn->error = -3;
|
67
68
|
conn_disconnect(conn);
|
68
69
|
} else {
|
69
70
|
_log_open_tag(conn, attr);
|
@@ -73,6 +74,7 @@ void parser_handle_start(void *userdata,
|
|
73
74
|
if (!conn->stream_id) {
|
74
75
|
xmpp_error(conn->ctx, "xmpp",
|
75
76
|
"Memory allocation failure.");
|
77
|
+
conn->error = -2;
|
76
78
|
conn_disconnect(conn);
|
77
79
|
}
|
78
80
|
|