stropheruby 0.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -2
- data/README.txt +3 -8
- data/ext/auth.c +22 -23
- data/ext/common.h +20 -8
- data/ext/conn.c +18 -167
- data/ext/ctx.c +5 -5
- data/ext/event.c +32 -28
- data/ext/handler.c +2 -6
- data/ext/hash.c +2 -2
- data/ext/hash.h +2 -2
- data/ext/jid.c +1 -1
- data/ext/md5.c +4 -4
- data/ext/md5.h +12 -5
- data/ext/ostypes.h +2 -2
- data/ext/parser.c +208 -0
- data/ext/sasl.h +3 -3
- data/ext/sock.c +1 -1
- data/ext/sock.h +2 -2
- data/ext/stanza.c +47 -8
- data/ext/strophe.h +5 -8
- data/ext/thread.c +2 -2
- data/ext/thread.h +2 -2
- data/ext/tls.h +1 -1
- data/ext/tls_dummy.c +2 -2
- data/ext/util.c +2 -2
- data/ext/util.h +2 -2
- metadata +18 -11
- data/ext/parser.h +0 -43
- data/ext/parser_expat.c +0 -202
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -4,7 +4,6 @@ Stropheruby is a ruby bindings for Strophe, a C library for writing XMPP clients
|
|
4
4
|
|
5
5
|
This is a fork of flamontagne's stropheruby (http://github.com/flamontagne/stropheruby/tree/master) with the following improvements:
|
6
6
|
|
7
|
-
* accessor of the connect_timeout in the Connection class
|
8
7
|
* A patched version of libstrophe (trunk) is included. So there is no extra library to install.
|
9
8
|
* (libstrophe) Fixed a timeout issue on Mac OSX: http://groups.google.com/group/strophe-dev/browse_thread/thread/ef4cb19785020fb6
|
10
9
|
* (libstrophe) Fixed basic auth: http://groups.google.com/group/strophe-dev/browse_thread/thread/b770f72c83d1a0b9
|
@@ -18,15 +17,11 @@ This is a fork of flamontagne's stropheruby (http://github.com/flamontagne/strop
|
|
18
17
|
|
19
18
|
== INSTALLATION
|
20
19
|
|
21
|
-
sudo gem sources -a http://
|
22
|
-
sudo gem install stropheruby
|
20
|
+
sudo gem sources -a http://gems.github.com
|
21
|
+
sudo gem install yong-stropheruby
|
23
22
|
|
24
23
|
For Rails app, add this line in your config/environment.rb:
|
25
|
-
config.gem "stropheruby", :source => "http://
|
26
|
-
|
27
|
-
== NOTES
|
28
|
-
|
29
|
-
Stropheruby v2.0 has upgraded the libstrophe to the upstream which is 20090526
|
24
|
+
config.gem "yong-stropheruby", :source => "http://gems.github.com", :lib => "strophe_ruby"
|
30
25
|
|
31
26
|
== EXAMPLE
|
32
27
|
|
data/ext/auth.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* auth.c
|
2
2
|
** strophe XMPP client library -- auth functions and handlers
|
3
3
|
**
|
4
|
-
** Copyright (C) 2005-
|
4
|
+
** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
|
5
5
|
**
|
6
6
|
** This software is provided AS-IS with no warranty, either express or
|
7
7
|
** implied.
|
@@ -208,11 +208,9 @@ static int _handle_features(xmpp_conn_t * const conn,
|
|
208
208
|
xmpp_timed_handler_delete(conn, _handle_missing_features);
|
209
209
|
|
210
210
|
/* check for TLS */
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
conn->tls_support = 1;
|
215
|
-
}
|
211
|
+
child = xmpp_stanza_get_child_by_name(stanza, "starttls");
|
212
|
+
if (child && (strcmp(xmpp_stanza_get_ns(child), XMPP_NS_TLS) == 0))
|
213
|
+
conn->tls_support = 1;
|
216
214
|
|
217
215
|
/* check for SASL */
|
218
216
|
child = xmpp_stanza_get_child_by_name(stanza, "mechanisms");
|
@@ -236,13 +234,13 @@ static int _handle_features(xmpp_conn_t * const conn,
|
|
236
234
|
if (conn->pass == NULL || conn->pass[0] == '\0') {
|
237
235
|
xmpp_debug(conn->ctx, "auth", "do not attempt auth as there is no password given");
|
238
236
|
//If no password, do not login, this will give 'register' a chance to run
|
239
|
-
|
240
|
-
|
241
|
-
|
237
|
+
conn->authenticated = 1;
|
238
|
+
/* call connection handler */
|
239
|
+
conn->conn_handler(conn, XMPP_CONN_CONNECT, 0, NULL, conn->userdata);
|
242
240
|
} else {
|
243
241
|
_auth(conn);
|
244
242
|
}
|
245
|
-
|
243
|
+
|
246
244
|
return 0;
|
247
245
|
}
|
248
246
|
|
@@ -267,7 +265,7 @@ static int _handle_proceedtls_default(xmpp_conn_t * const conn,
|
|
267
265
|
{
|
268
266
|
char *name;
|
269
267
|
name = xmpp_stanza_get_name(stanza);
|
270
|
-
xmpp_debug(conn->ctx, "xmpp",
|
268
|
+
xmpp_debug(conn->ctx, "xmpp",
|
271
269
|
"handle proceedtls called for %s", name);
|
272
270
|
|
273
271
|
if (strcmp(name, "proceed") == 0) {
|
@@ -287,8 +285,7 @@ static int _handle_proceedtls_default(xmpp_conn_t * const conn,
|
|
287
285
|
}
|
288
286
|
else
|
289
287
|
{
|
290
|
-
|
291
|
-
conn_prepare_reset(conn, auth_handle_open);
|
288
|
+
parser_prepare_reset(conn, _handle_open_tls);
|
292
289
|
|
293
290
|
conn_open_stream(conn);
|
294
291
|
}
|
@@ -318,7 +315,7 @@ static int _handle_sasl_result(xmpp_conn_t * const conn,
|
|
318
315
|
(char *)userdata);
|
319
316
|
|
320
317
|
/* reset parser */
|
321
|
-
|
318
|
+
parser_prepare_reset(conn, _handle_open_sasl);
|
322
319
|
|
323
320
|
/* send stream tag */
|
324
321
|
conn_open_stream(conn);
|
@@ -703,6 +700,16 @@ void auth_handle_open(xmpp_conn_t * const conn)
|
|
703
700
|
FEATURES_TIMEOUT, NULL);
|
704
701
|
}
|
705
702
|
|
703
|
+
/* called when stream:stream tag received after TLS connection */
|
704
|
+
static void _handle_open_tls(xmpp_conn_t * const conn)
|
705
|
+
{
|
706
|
+
xmpp_debug(conn->ctx, "xmpp", "TLS successful, proceeding with SASL");
|
707
|
+
|
708
|
+
/* go straight to SASL auth */
|
709
|
+
_auth(conn);
|
710
|
+
}
|
711
|
+
|
712
|
+
|
706
713
|
/* called when stream:stream tag received after SASL auth */
|
707
714
|
static void _handle_open_sasl(xmpp_conn_t * const conn)
|
708
715
|
{
|
@@ -841,17 +848,9 @@ static int _handle_bind(xmpp_conn_t * const conn,
|
|
841
848
|
xmpp_error(conn->ctx, "xmpp", "Binding failed.");
|
842
849
|
xmpp_disconnect(conn);
|
843
850
|
} else if (type && strcmp(type, "result") == 0) {
|
844
|
-
|
851
|
+
/* TODO: extract resource if present */
|
845
852
|
xmpp_debug(conn->ctx, "xmpp", "Bind successful.");
|
846
853
|
|
847
|
-
if (binding) {
|
848
|
-
xmpp_stanza_t *jid_stanza = xmpp_stanza_get_child_by_name(binding,
|
849
|
-
"jid");
|
850
|
-
if (jid_stanza) {
|
851
|
-
conn->bound_jid = xmpp_stanza_get_text(jid_stanza);
|
852
|
-
}
|
853
|
-
}
|
854
|
-
|
855
854
|
/* establish a session if required */
|
856
855
|
if (conn->session_required) {
|
857
856
|
/* setup response handlers */
|
data/ext/common.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* common.h
|
2
2
|
** strophe XMPP client library -- internal common structures
|
3
3
|
**
|
4
|
-
** Copyright (C) 2005-
|
4
|
+
** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
|
5
5
|
**
|
6
6
|
** This software is provided AS-IS with no warranty, either express or
|
7
7
|
** implied.
|
@@ -31,7 +31,8 @@
|
|
31
31
|
#include "tls.h"
|
32
32
|
#include "hash.h"
|
33
33
|
#include "util.h"
|
34
|
-
|
34
|
+
|
35
|
+
#include "expat.h"
|
35
36
|
|
36
37
|
/** run-time context **/
|
37
38
|
|
@@ -162,11 +163,10 @@ struct _xmpp_conn_t {
|
|
162
163
|
sock_t sock;
|
163
164
|
tls_t *tls;
|
164
165
|
|
165
|
-
int tls_support;
|
166
|
+
int tls_support;
|
166
167
|
int tls_failed; /* set when tls fails, so we don't try again */
|
167
168
|
int sasl_support; /* if true, field is a bitfield of supported
|
168
169
|
mechanisms */
|
169
|
-
int secured; /* set when stream is secured with TLS */
|
170
170
|
|
171
171
|
/* if server returns <bind/> or <session/> we must do them */
|
172
172
|
int bind_required;
|
@@ -178,7 +178,6 @@ struct _xmpp_conn_t {
|
|
178
178
|
char *connectport;
|
179
179
|
char *jid;
|
180
180
|
char *pass;
|
181
|
-
char *bound_jid;
|
182
181
|
char *stream_id;
|
183
182
|
|
184
183
|
/* send queue and parameters */
|
@@ -190,7 +189,9 @@ struct _xmpp_conn_t {
|
|
190
189
|
|
191
190
|
/* xml parser */
|
192
191
|
int reset_parser;
|
193
|
-
|
192
|
+
XML_Parser parser;
|
193
|
+
int depth;
|
194
|
+
xmpp_stanza_t *stanza;
|
194
195
|
|
195
196
|
/* timeouts */
|
196
197
|
unsigned int connect_timeout;
|
@@ -216,8 +217,6 @@ struct _xmpp_conn_t {
|
|
216
217
|
void conn_disconnect(xmpp_conn_t * const conn);
|
217
218
|
void conn_disconnect_clean(xmpp_conn_t * const conn);
|
218
219
|
void conn_open_stream(xmpp_conn_t * const conn);
|
219
|
-
void conn_prepare_reset(xmpp_conn_t * const conn, xmpp_open_handler handler);
|
220
|
-
void conn_parser_reset(xmpp_conn_t * const conn);
|
221
220
|
|
222
221
|
|
223
222
|
typedef enum {
|
@@ -242,6 +241,19 @@ struct _xmpp_stanza_t {
|
|
242
241
|
hash_t *attributes;
|
243
242
|
};
|
244
243
|
|
244
|
+
int xmpp_stanza_set_attributes(xmpp_stanza_t * const stanza,
|
245
|
+
const char * const * const attr);
|
246
|
+
|
247
|
+
/* parser functions */
|
248
|
+
void parser_handle_start(void *userdata,
|
249
|
+
const XML_Char *name,
|
250
|
+
const XML_Char **attr);
|
251
|
+
void parser_handle_character(void *userdata, const XML_Char *s, int len);
|
252
|
+
void parser_handle_end(void *userdata, const XML_Char *name);
|
253
|
+
void parser_prepare_reset(xmpp_conn_t * const conn,
|
254
|
+
xmpp_open_handler handler);
|
255
|
+
int parser_reset(xmpp_conn_t * const conn);
|
256
|
+
|
245
257
|
/* handler management */
|
246
258
|
void handler_fire_stanza(xmpp_conn_t * const conn,
|
247
259
|
xmpp_stanza_t * const stanza);
|
data/ext/conn.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* conn.c
|
2
2
|
** strophe XMPP client library -- connection object functions
|
3
3
|
**
|
4
|
-
** Copyright (C) 2005-
|
4
|
+
** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
|
5
5
|
**
|
6
6
|
** This software is provided AS-IS with no warranty, either express
|
7
7
|
** or implied.
|
@@ -23,11 +23,9 @@
|
|
23
23
|
#include <stdlib.h>
|
24
24
|
#include <string.h>
|
25
25
|
|
26
|
-
#include
|
27
|
-
|
26
|
+
#include "strophe.h"
|
28
27
|
#include "common.h"
|
29
28
|
#include "util.h"
|
30
|
-
#include "parser.h"
|
31
29
|
|
32
30
|
#ifndef DEFAULT_SEND_QUEUE_MAX
|
33
31
|
/** @def DEFAULT_SEND_QUEUE_MAX
|
@@ -53,13 +51,6 @@
|
|
53
51
|
static int _disconnect_cleanup(xmpp_conn_t * const conn,
|
54
52
|
void * const userdata);
|
55
53
|
|
56
|
-
static void _handle_stream_start(char *name, char **attrs,
|
57
|
-
void * const userdata);
|
58
|
-
static void _handle_stream_end(char *name,
|
59
|
-
void * const userdata);
|
60
|
-
static void _handle_stream_stanza(xmpp_stanza_t *stanza,
|
61
|
-
void * const userdata);
|
62
|
-
|
63
54
|
/** Create a new Strophe connection object.
|
64
55
|
*
|
65
56
|
* @param ctx a Strophe context object
|
@@ -105,23 +96,17 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t * const ctx)
|
|
105
96
|
conn->jid = NULL;
|
106
97
|
conn->pass = NULL;
|
107
98
|
conn->stream_id = NULL;
|
108
|
-
conn->bound_jid = NULL;
|
109
99
|
|
110
100
|
conn->tls_support = 0;
|
111
101
|
conn->tls_failed = 0;
|
112
102
|
conn->sasl_support = 0;
|
113
|
-
conn->secured = 0;
|
114
103
|
|
115
104
|
conn->bind_required = 0;
|
116
105
|
conn->session_required = 0;
|
117
106
|
|
118
|
-
conn->parser =
|
119
|
-
|
120
|
-
|
121
|
-
_handle_stream_stanza,
|
122
|
-
conn);
|
123
|
-
conn->reset_parser = 0;
|
124
|
-
conn_prepare_reset(conn, auth_handle_open);
|
107
|
+
conn->parser = NULL;
|
108
|
+
conn->stanza = NULL;
|
109
|
+
parser_prepare_reset(conn, auth_handle_open);
|
125
110
|
|
126
111
|
conn->authenticated = 0;
|
127
112
|
conn->conn_handler = NULL;
|
@@ -142,7 +127,7 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t * const ctx)
|
|
142
127
|
if (!item) {
|
143
128
|
xmpp_error(conn->ctx, "xmpp", "failed to allocate memory");
|
144
129
|
xmpp_free(conn->ctx, conn->lang);
|
145
|
-
|
130
|
+
XML_ParserFree(conn->parser);
|
146
131
|
xmpp_free(conn->ctx, conn);
|
147
132
|
conn = NULL;
|
148
133
|
} else {
|
@@ -166,7 +151,7 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t * const ctx)
|
|
166
151
|
*
|
167
152
|
* @ingroup Connections
|
168
153
|
*/
|
169
|
-
xmpp_conn_t *xmpp_conn_clone(xmpp_conn_t * const conn)
|
154
|
+
xmpp_conn_t * xmpp_conn_clone(xmpp_conn_t * const conn)
|
170
155
|
{
|
171
156
|
conn->ref++;
|
172
157
|
return conn;
|
@@ -264,14 +249,12 @@ int xmpp_conn_release(xmpp_conn_t * const conn)
|
|
264
249
|
xmpp_free(ctx, conn->stream_error);
|
265
250
|
}
|
266
251
|
|
267
|
-
|
252
|
+
XML_ParserFree(conn->parser);
|
268
253
|
|
269
254
|
if (conn->domain) xmpp_free(ctx, conn->domain);
|
270
255
|
if (conn->jid) xmpp_free(ctx, conn->jid);
|
271
|
-
if (conn->bound_jid) xmpp_free(ctx, conn->bound_jid);
|
272
256
|
if (conn->pass) xmpp_free(ctx, conn->pass);
|
273
257
|
if (conn->stream_id) xmpp_free(ctx, conn->stream_id);
|
274
|
-
if (conn->lang) xmpp_free(ctx, conn->lang);
|
275
258
|
xmpp_free(ctx, conn);
|
276
259
|
released = 1;
|
277
260
|
}
|
@@ -292,24 +275,6 @@ const char *xmpp_conn_get_jid(const xmpp_conn_t * const conn)
|
|
292
275
|
return conn->jid;
|
293
276
|
}
|
294
277
|
|
295
|
-
/**
|
296
|
-
* Get the JID discovered during binding time.
|
297
|
-
*
|
298
|
-
* This JID will contain the resource used by the current connection.
|
299
|
-
* This is useful in the case where a resource was not specified for
|
300
|
-
* binding.
|
301
|
-
*
|
302
|
-
* @param conn a Strophe connection object.
|
303
|
-
*
|
304
|
-
* @return a string containing the full JID or NULL if it's not been discovered
|
305
|
-
*
|
306
|
-
* @ingroup Connections
|
307
|
-
*/
|
308
|
-
const char *xmpp_conn_get_bound_jid(const xmpp_conn_t * const conn)
|
309
|
-
{
|
310
|
-
return conn->bound_jid;
|
311
|
-
}
|
312
|
-
|
313
278
|
/** Set the JID of the user that will be bound to the connection.
|
314
279
|
* If any JID was previously set, it will be discarded. This should not be
|
315
280
|
* be used after a connection is created. The function will make a copy of
|
@@ -414,32 +379,25 @@ int xmpp_connect_client(xmpp_conn_t * const conn,
|
|
414
379
|
{
|
415
380
|
char connectdomain[2048];
|
416
381
|
int connectport;
|
417
|
-
|
382
|
+
char *domain;
|
418
383
|
|
419
384
|
conn->type = XMPP_CLIENT;
|
420
385
|
|
421
386
|
conn->domain = xmpp_jid_domain(conn->ctx, conn->jid);
|
422
387
|
if (!conn->domain) return -1;
|
423
388
|
|
424
|
-
if (
|
425
|
-
|
426
|
-
strcpy(connectdomain, altdomain);
|
427
|
-
connectport = altport ? altport : 5222;
|
428
|
-
} else if (!sock_srv_lookup("xmpp-client", "tcp", conn->domain,
|
429
|
-
connectdomain, 2048, &connectport)) {
|
389
|
+
if (!sock_srv_lookup("xmpp-client", "tcp", conn->domain, connectdomain, 2048, &connectport))
|
390
|
+
{
|
430
391
|
xmpp_debug(conn->ctx, "xmpp", "SRV lookup failed.");
|
431
392
|
if (!altdomain)
|
432
393
|
domain = conn->domain;
|
433
394
|
else
|
434
395
|
domain = altdomain;
|
435
|
-
xmpp_debug(conn->ctx, "xmpp", "Using alternate domain %s, port %d",
|
436
|
-
altdomain, altport);
|
396
|
+
xmpp_debug(conn->ctx, "xmpp", "Using alternate domain %s, port %d", altdomain, altport);
|
437
397
|
strcpy(connectdomain, domain);
|
438
398
|
connectport = altport ? altport : 5222;
|
439
399
|
}
|
440
400
|
conn->sock = sock_connect(connectdomain, connectport);
|
441
|
-
xmpp_debug(conn->ctx, "xmpp", "sock_connect to %s:%d returned %d",
|
442
|
-
connectdomain, connectport, conn->sock);
|
443
401
|
if (conn->sock == -1) return -1;
|
444
402
|
|
445
403
|
/* setup handler */
|
@@ -468,7 +426,7 @@ void conn_disconnect_clean(xmpp_conn_t * const conn)
|
|
468
426
|
{
|
469
427
|
/* remove the timed handler */
|
470
428
|
xmpp_timed_handler_delete(conn, _disconnect_cleanup);
|
471
|
-
|
429
|
+
conn->error = -4;
|
472
430
|
conn_disconnect(conn);
|
473
431
|
}
|
474
432
|
|
@@ -487,26 +445,13 @@ void conn_disconnect(xmpp_conn_t * const conn)
|
|
487
445
|
tls_free(conn->tls);
|
488
446
|
conn->tls = NULL;
|
489
447
|
}
|
490
|
-
sock_close(conn->sock);
|
491
448
|
|
449
|
+
sock_close(conn->sock);
|
492
450
|
/* fire off connection handler */
|
493
|
-
|
451
|
+
if (NULL != conn->conn_handler) {
|
452
|
+
conn->conn_handler(conn, XMPP_CONN_DISCONNECT, conn->error,
|
494
453
|
conn->stream_error, conn->userdata);
|
495
|
-
}
|
496
|
-
|
497
|
-
/* prepares a parser reset. this is called from handlers. we can't
|
498
|
-
* reset the parser immediately as it is not re-entrant. */
|
499
|
-
void conn_prepare_reset(xmpp_conn_t * const conn, xmpp_open_handler handler)
|
500
|
-
{
|
501
|
-
conn->reset_parser = 1;
|
502
|
-
conn->open_handler = handler;
|
503
|
-
}
|
504
|
-
|
505
|
-
/* reset the parser */
|
506
|
-
void conn_parser_reset(xmpp_conn_t * const conn)
|
507
|
-
{
|
508
|
-
conn->reset_parser = 0;
|
509
|
-
parser_reset(conn->parser);
|
454
|
+
}
|
510
455
|
}
|
511
456
|
|
512
457
|
/* timed handler for cleanup if normal disconnect procedure takes too long */
|
@@ -515,7 +460,7 @@ static int _disconnect_cleanup(xmpp_conn_t * const conn,
|
|
515
460
|
{
|
516
461
|
xmpp_debug(conn->ctx, "xmpp",
|
517
462
|
"disconnection forced by cleanup timeout");
|
518
|
-
|
463
|
+
conn->error = -5;
|
519
464
|
conn_disconnect(conn);
|
520
465
|
|
521
466
|
return 0;
|
@@ -682,97 +627,3 @@ void conn_open_stream(xmpp_conn_t * const conn)
|
|
682
627
|
conn->type == XMPP_CLIENT ? XMPP_NS_CLIENT : XMPP_NS_COMPONENT,
|
683
628
|
XMPP_NS_STREAMS);
|
684
629
|
}
|
685
|
-
|
686
|
-
static void _log_open_tag(xmpp_conn_t *conn, char **attrs)
|
687
|
-
{
|
688
|
-
char buf[4096];
|
689
|
-
size_t len, pos;
|
690
|
-
int i;
|
691
|
-
|
692
|
-
if (!attrs) return;
|
693
|
-
|
694
|
-
pos = 0;
|
695
|
-
len = xmpp_snprintf(buf, 4096, "<stream:stream");
|
696
|
-
if (len < 0) return;
|
697
|
-
|
698
|
-
pos += len;
|
699
|
-
|
700
|
-
for (i = 0; attrs[i]; i += 2) {
|
701
|
-
len = xmpp_snprintf(&buf[pos], 4096 - pos, " %s='%s'",
|
702
|
-
attrs[i], attrs[i+1]);
|
703
|
-
if (len < 0) return;
|
704
|
-
pos += len;
|
705
|
-
}
|
706
|
-
|
707
|
-
len = xmpp_snprintf(&buf[pos], 4096 - pos, ">");
|
708
|
-
if (len < 0) return;
|
709
|
-
|
710
|
-
xmpp_debug(conn->ctx, "xmpp", "RECV: %s", buf);
|
711
|
-
}
|
712
|
-
|
713
|
-
static char *_get_stream_attribute(char **attrs, char *name)
|
714
|
-
{
|
715
|
-
int i;
|
716
|
-
|
717
|
-
if (!attrs) return NULL;
|
718
|
-
|
719
|
-
for (i = 0; attrs[i]; i += 2)
|
720
|
-
if (strcmp(name, attrs[i]) == 0)
|
721
|
-
return attrs[i+1];
|
722
|
-
|
723
|
-
return NULL;
|
724
|
-
}
|
725
|
-
|
726
|
-
static void _handle_stream_start(char *name, char **attrs,
|
727
|
-
void * const userdata)
|
728
|
-
{
|
729
|
-
xmpp_conn_t *conn = (xmpp_conn_t *)userdata;
|
730
|
-
char *id;
|
731
|
-
|
732
|
-
if (strcmp(name, "stream:stream") != 0) {
|
733
|
-
printf("name = %s\n", name);
|
734
|
-
xmpp_error(conn->ctx, "conn", "Server did not open valid stream.");
|
735
|
-
conn_disconnect(conn);
|
736
|
-
} else {
|
737
|
-
_log_open_tag(conn, attrs);
|
738
|
-
|
739
|
-
if (conn->stream_id) xmpp_free(conn->ctx, conn->stream_id);
|
740
|
-
|
741
|
-
id = _get_stream_attribute(attrs, "id");
|
742
|
-
if (id)
|
743
|
-
conn->stream_id = xmpp_strdup(conn->ctx, id);
|
744
|
-
|
745
|
-
if (!conn->stream_id) {
|
746
|
-
xmpp_error(conn->ctx, "conn", "Memory allocation failed.");
|
747
|
-
conn_disconnect(conn);
|
748
|
-
}
|
749
|
-
}
|
750
|
-
|
751
|
-
/* call stream open handler */
|
752
|
-
conn->open_handler(conn);
|
753
|
-
}
|
754
|
-
|
755
|
-
static void _handle_stream_end(char *name,
|
756
|
-
void * const userdata)
|
757
|
-
{
|
758
|
-
xmpp_conn_t *conn = (xmpp_conn_t *)userdata;
|
759
|
-
|
760
|
-
/* stream is over */
|
761
|
-
xmpp_debug(conn->ctx, "xmpp", "RECV: </stream:stream>");
|
762
|
-
conn_disconnect_clean(conn);
|
763
|
-
}
|
764
|
-
|
765
|
-
static void _handle_stream_stanza(xmpp_stanza_t *stanza,
|
766
|
-
void * const userdata)
|
767
|
-
{
|
768
|
-
xmpp_conn_t *conn = (xmpp_conn_t *)userdata;
|
769
|
-
char *buf;
|
770
|
-
size_t len;
|
771
|
-
|
772
|
-
if (xmpp_stanza_to_text(stanza, &buf, &len) == 0) {
|
773
|
-
xmpp_debug(conn->ctx, "xmpp", "RECV: %s", buf);
|
774
|
-
xmpp_free(conn->ctx, buf);
|
775
|
-
}
|
776
|
-
|
777
|
-
handler_fire_stanza(conn, stanza);
|
778
|
-
}
|
data/ext/ctx.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* ctx.c
|
2
2
|
** strophe XMPP client library -- run-time context implementation
|
3
3
|
**
|
4
|
-
** Copyright (C) 2005-
|
4
|
+
** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
|
5
5
|
**
|
6
6
|
** This software is provided AS-IS with no warranty, either express
|
7
7
|
** or implied.
|
@@ -58,7 +58,7 @@
|
|
58
58
|
*
|
59
59
|
* @ingroup Init
|
60
60
|
*/
|
61
|
-
|
61
|
+
void xmpp_initialize(void)
|
62
62
|
{
|
63
63
|
sock_initialize();
|
64
64
|
tls_initialize();
|
@@ -248,12 +248,12 @@ void xmpp_log(const xmpp_ctx_t * const ctx,
|
|
248
248
|
va_list ap)
|
249
249
|
{
|
250
250
|
int oldret, ret;
|
251
|
-
char smbuf[
|
251
|
+
char smbuf[4096] = {0};
|
252
252
|
char *buf;
|
253
253
|
|
254
254
|
buf = smbuf;
|
255
|
-
ret = xmpp_vsnprintf(buf,
|
256
|
-
if (ret >
|
255
|
+
ret = xmpp_vsnprintf(buf, 4096 - 1, fmt, ap);
|
256
|
+
if (ret > 4096 - 1) {
|
257
257
|
buf = (char *)xmpp_alloc(ctx, ret + 1);
|
258
258
|
if (!buf) {
|
259
259
|
buf = NULL;
|