strophe_ruby 0.0.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/.autotest +9 -0
- data/History.txt +4 -0
- data/Manifest.txt +24 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +152 -0
- data/Rakefile +23 -0
- data/ext/strophe_ruby/extconf.rb +7 -0
- data/ext/strophe_ruby/libexpat.a +0 -0
- data/ext/strophe_ruby/libstrophe.a +0 -0
- data/ext/strophe_ruby/strophe.h +363 -0
- data/ext/strophe_ruby/strophe/common.h +293 -0
- data/ext/strophe_ruby/strophe/hash.h +64 -0
- data/ext/strophe_ruby/strophe/sock.h +51 -0
- data/ext/strophe_ruby/strophe/tls.h +46 -0
- data/ext/strophe_ruby/strophe_ruby.c +661 -0
- data/lib/strophe_ruby.rb +6 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/tasks/extconf.rake +13 -0
- data/tasks/extconf/strophe_ruby.rake +47 -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 +93 -0
@@ -0,0 +1,293 @@
|
|
1
|
+
/* common.h
|
2
|
+
** strophe XMPP client library -- internal common structures
|
3
|
+
**
|
4
|
+
** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
|
5
|
+
**
|
6
|
+
** This software is provided AS-IS with no warranty, either express or
|
7
|
+
** implied.
|
8
|
+
**
|
9
|
+
** This software is distributed under license and may not be copied,
|
10
|
+
** modified or distributed except as expressly authorized under the
|
11
|
+
** terms of the license contained in the file LICENSE.txt in this
|
12
|
+
** distribution.
|
13
|
+
*/
|
14
|
+
|
15
|
+
/** @file
|
16
|
+
* Internally used functions and structures.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef __LIBSTROPHE_COMMON_H__
|
20
|
+
#define __LIBSTROPHE_COMMON_H__
|
21
|
+
|
22
|
+
#include <stdio.h>
|
23
|
+
#include <stdarg.h>
|
24
|
+
#ifndef _WIN32
|
25
|
+
#include <stdint.h>
|
26
|
+
#endif
|
27
|
+
|
28
|
+
|
29
|
+
#include "strophe.h"
|
30
|
+
#include "sock.h"
|
31
|
+
#include "tls.h"
|
32
|
+
#include "hash.h"
|
33
|
+
#include "util.h"
|
34
|
+
|
35
|
+
#include "expat.h"
|
36
|
+
|
37
|
+
/** run-time context **/
|
38
|
+
|
39
|
+
typedef enum {
|
40
|
+
XMPP_LOOP_NOTSTARTED,
|
41
|
+
XMPP_LOOP_RUNNING,
|
42
|
+
XMPP_LOOP_QUIT
|
43
|
+
} xmpp_loop_status_t;
|
44
|
+
|
45
|
+
typedef struct _xmpp_connlist_t {
|
46
|
+
xmpp_conn_t *conn;
|
47
|
+
struct _xmpp_connlist_t *next;
|
48
|
+
} xmpp_connlist_t;
|
49
|
+
|
50
|
+
struct _xmpp_ctx_t {
|
51
|
+
const xmpp_mem_t *mem;
|
52
|
+
const xmpp_log_t *log;
|
53
|
+
|
54
|
+
xmpp_loop_status_t loop_status;
|
55
|
+
xmpp_connlist_t *connlist;
|
56
|
+
};
|
57
|
+
|
58
|
+
|
59
|
+
/* convenience functions for accessing the context */
|
60
|
+
void *xmpp_alloc(const xmpp_ctx_t * const ctx, const size_t size);
|
61
|
+
void xmpp_free(const xmpp_ctx_t * const ctx, void *p);
|
62
|
+
void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p,
|
63
|
+
const size_t size);
|
64
|
+
char *xmpp_strdup(const xmpp_ctx_t * const ctx, const char * const s);
|
65
|
+
|
66
|
+
void xmpp_log(const xmpp_ctx_t * const ctx,
|
67
|
+
const xmpp_log_level_t level,
|
68
|
+
const char * const area,
|
69
|
+
const char * const fmt,
|
70
|
+
va_list ap);
|
71
|
+
|
72
|
+
/* wrappers for xmpp_log at specific levels */
|
73
|
+
void xmpp_error(const xmpp_ctx_t * const ctx,
|
74
|
+
const char * const area,
|
75
|
+
const char * const fmt,
|
76
|
+
...);
|
77
|
+
void xmpp_warn(const xmpp_ctx_t * const ctx,
|
78
|
+
const char * const area,
|
79
|
+
const char * const fmt,
|
80
|
+
...);
|
81
|
+
void xmpp_info(const xmpp_ctx_t * const ctx,
|
82
|
+
const char * const area,
|
83
|
+
const char * const fmt,
|
84
|
+
...);
|
85
|
+
void xmpp_debug(const xmpp_ctx_t * const ctx,
|
86
|
+
const char * const area,
|
87
|
+
const char * const fmt,
|
88
|
+
...);
|
89
|
+
|
90
|
+
/** jid */
|
91
|
+
/* these return new strings that must be xmpp_free()'d */
|
92
|
+
char *xmpp_jid_new(xmpp_ctx_t *ctx, const char *node,
|
93
|
+
const char *domain,
|
94
|
+
const char *resource);
|
95
|
+
char *xmpp_jid_bare(xmpp_ctx_t *ctx, const char *jid);
|
96
|
+
char *xmpp_jid_node(xmpp_ctx_t *ctx, const char *jid);
|
97
|
+
char *xmpp_jid_domain(xmpp_ctx_t *ctx, const char *jid);
|
98
|
+
char *xmpp_jid_resource(xmpp_ctx_t *ctx, const char *jid);
|
99
|
+
|
100
|
+
|
101
|
+
/** connection **/
|
102
|
+
|
103
|
+
/* opaque connection object */
|
104
|
+
typedef enum {
|
105
|
+
XMPP_STATE_DISCONNECTED,
|
106
|
+
XMPP_STATE_CONNECTING,
|
107
|
+
XMPP_STATE_CONNECTED
|
108
|
+
} xmpp_conn_state_t;
|
109
|
+
|
110
|
+
typedef struct _xmpp_send_queue_t xmpp_send_queue_t;
|
111
|
+
struct _xmpp_send_queue_t {
|
112
|
+
char *data;
|
113
|
+
size_t len;
|
114
|
+
size_t written;
|
115
|
+
|
116
|
+
xmpp_send_queue_t *next;
|
117
|
+
};
|
118
|
+
|
119
|
+
typedef struct _xmpp_handlist_t xmpp_handlist_t;
|
120
|
+
struct _xmpp_handlist_t {
|
121
|
+
/* common members */
|
122
|
+
int user_handler;
|
123
|
+
void *handler;
|
124
|
+
void *userdata;
|
125
|
+
int enabled; /* handlers are added disabled and enabled after the
|
126
|
+
* handler chain is processed to prevent stanzas from
|
127
|
+
* getting processed by newly added handlers */
|
128
|
+
xmpp_handlist_t *next;
|
129
|
+
|
130
|
+
union {
|
131
|
+
/* timed handlers */
|
132
|
+
struct {
|
133
|
+
unsigned long period;
|
134
|
+
uint64_t last_stamp;
|
135
|
+
};
|
136
|
+
/* id handlers */
|
137
|
+
struct {
|
138
|
+
char *id;
|
139
|
+
};
|
140
|
+
/* normal handlers */
|
141
|
+
struct {
|
142
|
+
char *ns;
|
143
|
+
char *name;
|
144
|
+
char *type;
|
145
|
+
};
|
146
|
+
};
|
147
|
+
};
|
148
|
+
|
149
|
+
#define SASL_MASK_PLAIN 0x01
|
150
|
+
#define SASL_MASK_DIGESTMD5 0x02
|
151
|
+
#define SASL_MASK_ANONYMOUS 0x04
|
152
|
+
|
153
|
+
typedef void (*xmpp_open_handler)(xmpp_conn_t * const conn);
|
154
|
+
|
155
|
+
struct _xmpp_conn_t {
|
156
|
+
unsigned int ref;
|
157
|
+
xmpp_ctx_t *ctx;
|
158
|
+
xmpp_conn_type_t type;
|
159
|
+
|
160
|
+
xmpp_conn_state_t state;
|
161
|
+
uint64_t timeout_stamp;
|
162
|
+
int error;
|
163
|
+
xmpp_stream_error_t *stream_error;
|
164
|
+
sock_t sock;
|
165
|
+
tls_t *tls;
|
166
|
+
|
167
|
+
int tls_support;
|
168
|
+
int tls_failed; /* set when tls fails, so we don't try again */
|
169
|
+
int sasl_support; /* if true, field is a bitfield of supported
|
170
|
+
mechanisms */
|
171
|
+
|
172
|
+
/* if server returns <bind/> or <session/> we must do them */
|
173
|
+
int bind_required;
|
174
|
+
int session_required;
|
175
|
+
|
176
|
+
char *lang;
|
177
|
+
char *domain;
|
178
|
+
char *connectdomain;
|
179
|
+
char *connectport;
|
180
|
+
char *jid;
|
181
|
+
char *pass;
|
182
|
+
char *stream_id;
|
183
|
+
|
184
|
+
/* send queue and parameters */
|
185
|
+
int blocking_send;
|
186
|
+
int send_queue_max;
|
187
|
+
int send_queue_len;
|
188
|
+
xmpp_send_queue_t *send_queue_head;
|
189
|
+
xmpp_send_queue_t *send_queue_tail;
|
190
|
+
|
191
|
+
/* xml parser */
|
192
|
+
int reset_parser;
|
193
|
+
XML_Parser parser;
|
194
|
+
int depth;
|
195
|
+
xmpp_stanza_t *stanza;
|
196
|
+
|
197
|
+
/* timeouts */
|
198
|
+
unsigned int connect_timeout;
|
199
|
+
|
200
|
+
/* event handlers */
|
201
|
+
|
202
|
+
/* stream open handler */
|
203
|
+
xmpp_open_handler open_handler;
|
204
|
+
|
205
|
+
/* user handlers only get called after authentication */
|
206
|
+
int authenticated;
|
207
|
+
|
208
|
+
/* connection events handler */
|
209
|
+
xmpp_conn_handler conn_handler;
|
210
|
+
void *userdata;
|
211
|
+
|
212
|
+
/* other handlers */
|
213
|
+
xmpp_handlist_t *timed_handlers;
|
214
|
+
hash_t *id_handlers;
|
215
|
+
xmpp_handlist_t *handlers;
|
216
|
+
};
|
217
|
+
|
218
|
+
void conn_disconnect(xmpp_conn_t * const conn);
|
219
|
+
void conn_disconnect_clean(xmpp_conn_t * const conn);
|
220
|
+
void conn_open_stream(xmpp_conn_t * const conn);
|
221
|
+
|
222
|
+
void xmpp_send_raw_string(xmpp_conn_t * const conn,
|
223
|
+
const char * const fmt, ...);
|
224
|
+
void xmpp_send_raw(xmpp_conn_t * const conn,
|
225
|
+
const char * const data, const size_t len);
|
226
|
+
|
227
|
+
|
228
|
+
typedef enum {
|
229
|
+
XMPP_STANZA_UNKNOWN,
|
230
|
+
XMPP_STANZA_TEXT,
|
231
|
+
XMPP_STANZA_TAG
|
232
|
+
} xmpp_stanza_type_t;
|
233
|
+
|
234
|
+
struct _xmpp_stanza_t {
|
235
|
+
int ref;
|
236
|
+
xmpp_ctx_t *ctx;
|
237
|
+
|
238
|
+
xmpp_stanza_type_t type;
|
239
|
+
|
240
|
+
xmpp_stanza_t *prev;
|
241
|
+
xmpp_stanza_t *next;
|
242
|
+
xmpp_stanza_t *children;
|
243
|
+
xmpp_stanza_t *parent;
|
244
|
+
|
245
|
+
char *data;
|
246
|
+
|
247
|
+
hash_t *attributes;
|
248
|
+
};
|
249
|
+
|
250
|
+
int xmpp_stanza_set_attributes(xmpp_stanza_t * const stanza,
|
251
|
+
const char * const * const attr);
|
252
|
+
|
253
|
+
/* parser functions */
|
254
|
+
void parser_handle_start(void *userdata,
|
255
|
+
const XML_Char *name,
|
256
|
+
const XML_Char **attr);
|
257
|
+
void parser_handle_character(void *userdata, const XML_Char *s, int len);
|
258
|
+
void parser_handle_end(void *userdata, const XML_Char *name);
|
259
|
+
void parser_prepare_reset(xmpp_conn_t * const conn,
|
260
|
+
xmpp_open_handler handler);
|
261
|
+
int parser_reset(xmpp_conn_t * const conn);
|
262
|
+
|
263
|
+
/* handler management */
|
264
|
+
void handler_fire_stanza(xmpp_conn_t * const conn,
|
265
|
+
xmpp_stanza_t * const stanza);
|
266
|
+
uint64_t handler_fire_timed(xmpp_ctx_t * const ctx);
|
267
|
+
void handler_reset_timed(xmpp_conn_t *conn, int user_only);
|
268
|
+
void handler_add_timed(xmpp_conn_t * const conn,
|
269
|
+
xmpp_timed_handler handler,
|
270
|
+
const unsigned long period,
|
271
|
+
void * const userdata);
|
272
|
+
void handler_add_id(xmpp_conn_t * const conn,
|
273
|
+
xmpp_handler handler,
|
274
|
+
const char * const id,
|
275
|
+
void * const userdata);
|
276
|
+
void handler_add(xmpp_conn_t * const conn,
|
277
|
+
xmpp_handler handler,
|
278
|
+
const char * const ns,
|
279
|
+
const char * const name,
|
280
|
+
const char * const type,
|
281
|
+
void * const userdata);
|
282
|
+
|
283
|
+
/* utility functions */
|
284
|
+
void disconnect_mem_error(xmpp_conn_t * const conn);
|
285
|
+
|
286
|
+
/* auth functions */
|
287
|
+
void auth_handle_open(xmpp_conn_t * const conn);
|
288
|
+
|
289
|
+
/* replacement snprintf and vsnprintf */
|
290
|
+
int xmpp_snprintf (char *str, size_t count, const char *fmt, ...);
|
291
|
+
int xmpp_vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
|
292
|
+
|
293
|
+
#endif /* __LIBSTROPHE_COMMON_H__ */
|
@@ -0,0 +1,64 @@
|
|
1
|
+
/* hash.h
|
2
|
+
** strophe XMPP client library -- hash table interface
|
3
|
+
**
|
4
|
+
** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
|
5
|
+
**
|
6
|
+
** This software is provided AS-IS with no warranty, either express
|
7
|
+
** or implied.
|
8
|
+
**
|
9
|
+
** This software is distributed under license and may not be copied,
|
10
|
+
** modified or distributed except as expressly authorized under the
|
11
|
+
** terms of the license contained in the file LICENSE.txt in this
|
12
|
+
** distribution.
|
13
|
+
*/
|
14
|
+
|
15
|
+
/** @file
|
16
|
+
* Hash table API.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef __LIBSTROPHE_HASH_H__
|
20
|
+
#define __LIBSTROPHE_HASH_H__
|
21
|
+
|
22
|
+
typedef struct _hash_t hash_t;
|
23
|
+
|
24
|
+
typedef void (*hash_free_func)(const xmpp_ctx_t * const ctx, void *p);
|
25
|
+
|
26
|
+
/** allocate and initialize a new hash table */
|
27
|
+
hash_t *hash_new(xmpp_ctx_t * const ctx, const int size,
|
28
|
+
hash_free_func free);
|
29
|
+
|
30
|
+
/** allocate a new reference to an existing hash table */
|
31
|
+
hash_t *hash_clone(hash_t * const table);
|
32
|
+
|
33
|
+
/** release a hash table when no longer needed */
|
34
|
+
void hash_release(hash_t * const table);
|
35
|
+
|
36
|
+
/** add a key, value pair to a hash table.
|
37
|
+
* each key can appear only once; the value of any
|
38
|
+
* identical key will be replaced
|
39
|
+
*/
|
40
|
+
int hash_add(hash_t *table, const char * const key, void *data);
|
41
|
+
|
42
|
+
/** look up a key in a hash table */
|
43
|
+
void *hash_get(hash_t *table, const char *key);
|
44
|
+
|
45
|
+
/** delete a key from a hash table */
|
46
|
+
int hash_drop(hash_t *table, const char *key);
|
47
|
+
|
48
|
+
/** return the number of keys in a hash */
|
49
|
+
int hash_num_keys(hash_t *table);
|
50
|
+
|
51
|
+
/** hash key iterator functions */
|
52
|
+
typedef struct _hash_iterator_t hash_iterator_t;
|
53
|
+
|
54
|
+
/** allocate and initialize a new iterator */
|
55
|
+
hash_iterator_t *hash_iter_new(hash_t *table);
|
56
|
+
|
57
|
+
/** release an iterator that is no longer needed */
|
58
|
+
void hash_iter_release(hash_iterator_t *iter);
|
59
|
+
|
60
|
+
/** return the next hash table key from the iterator.
|
61
|
+
the returned key should not be freed */
|
62
|
+
const char * hash_iter_next(hash_iterator_t *iter);
|
63
|
+
|
64
|
+
#endif /* __LIBXMPPP_HASH_H__ */
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/* sock.h
|
2
|
+
** strophe XMPP client library -- socket abstraction header
|
3
|
+
**
|
4
|
+
** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
|
5
|
+
**
|
6
|
+
** This software is provided AS-IS with no warranty, either express
|
7
|
+
** or implied.
|
8
|
+
**
|
9
|
+
** This software is distributed under license and may not be copied,
|
10
|
+
** modified or distributed except as expressly authorized under the
|
11
|
+
** terms of the license contained in the file LICENSE.txt in this
|
12
|
+
** distribution.
|
13
|
+
*/
|
14
|
+
|
15
|
+
/** @file
|
16
|
+
* Socket abstraction API.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef __LIBSTROPHE_SOCK_H__
|
20
|
+
#define __LIBSTROPHE_SOCK_H__
|
21
|
+
|
22
|
+
#include <stdio.h>
|
23
|
+
|
24
|
+
#ifndef _WIN32
|
25
|
+
typedef int sock_t;
|
26
|
+
#else
|
27
|
+
#include <winsock2.h>
|
28
|
+
typedef SOCKET sock_t;
|
29
|
+
#endif
|
30
|
+
|
31
|
+
void sock_initialize(void);
|
32
|
+
void sock_shutdown(void);
|
33
|
+
|
34
|
+
int sock_error(void);
|
35
|
+
|
36
|
+
sock_t sock_connect(const char * const host, const unsigned int port);
|
37
|
+
int sock_close(const sock_t sock);
|
38
|
+
|
39
|
+
int sock_set_blocking(const sock_t sock);
|
40
|
+
int sock_set_nonblocking(const sock_t sock);
|
41
|
+
int sock_read(const sock_t sock, void * const buff, const size_t len);
|
42
|
+
int sock_write(const sock_t sock, const void * const buff, const size_t len);
|
43
|
+
int sock_is_recoverable(const int error);
|
44
|
+
/* checks for an error after connect, return 0 if connect successful */
|
45
|
+
int sock_connect_error(const sock_t sock);
|
46
|
+
|
47
|
+
int sock_srv_lookup(const char *service, const char *proto,
|
48
|
+
const char *domain, char *resulttarget,
|
49
|
+
int resulttargetlength, int *resultport);
|
50
|
+
|
51
|
+
#endif /* __LIBSTROPHE_SOCK_H__ */
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/* tls.h
|
2
|
+
** strophe XMPP client library -- TLS abstraction header
|
3
|
+
**
|
4
|
+
** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
|
5
|
+
**
|
6
|
+
** This software is provided AS-IS with no warranty, either express
|
7
|
+
** or implied.
|
8
|
+
**
|
9
|
+
** This software is distributed under license and may not be copied,
|
10
|
+
** modified or distributed except as expressly authorized under the
|
11
|
+
** terms of the license contained in the file LICENSE.txt in this
|
12
|
+
** distribution.
|
13
|
+
*/
|
14
|
+
|
15
|
+
/** @file
|
16
|
+
* TLS abstraction API.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef __LIBSTROPHE_TLS_H__
|
20
|
+
#define __LIBSTROPHE_TLS_H__
|
21
|
+
|
22
|
+
#include "common.h"
|
23
|
+
#include "sock.h"
|
24
|
+
|
25
|
+
typedef struct _tls tls_t;
|
26
|
+
|
27
|
+
void tls_initialize(void);
|
28
|
+
void tls_shutdown(void);
|
29
|
+
|
30
|
+
tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock);
|
31
|
+
void tls_free(tls_t *tls);
|
32
|
+
|
33
|
+
int tls_set_credentials(tls_t *tls, const char *cafilename);
|
34
|
+
|
35
|
+
int tls_start(tls_t *tls);
|
36
|
+
int tls_stop(tls_t *tls);
|
37
|
+
|
38
|
+
int tls_error(tls_t *tls);
|
39
|
+
|
40
|
+
int tls_read(tls_t *tls, void * const buff, const size_t len);
|
41
|
+
int tls_write(tls_t *tls, const void * const buff, const size_t len);
|
42
|
+
|
43
|
+
int tls_clear_pending_write(tls_t *tls);
|
44
|
+
int tls_is_recoverable(int error);
|
45
|
+
|
46
|
+
#endif /* __LIBSTROPHE_TLS_H__ */
|