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/ext/strophe.h
ADDED
@@ -0,0 +1,372 @@
|
|
1
|
+
/* strophe.h
|
2
|
+
** strophe XMPP client library C API
|
3
|
+
**
|
4
|
+
** Copyright (C) 2005-2008 OGG, LLC.
|
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
|
+
* Strophe public C API definitions.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef __LIBSTROPHE_STROPHE_H__
|
20
|
+
#define __LIBSTROPHE_STROPHE_H__
|
21
|
+
|
22
|
+
#ifdef __cplusplus
|
23
|
+
extern "C" {
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#include <stdio.h>
|
27
|
+
|
28
|
+
/* namespace defines */
|
29
|
+
/** @def XMPP_NS_CLIENT
|
30
|
+
* Namespace definition for 'jabber:client'.
|
31
|
+
*/
|
32
|
+
#define XMPP_NS_CLIENT "jabber:client"
|
33
|
+
/** @def XMPP_NS_COMPONENT
|
34
|
+
* Namespace definition for 'jabber:component:accept'.
|
35
|
+
*/
|
36
|
+
#define XMPP_NS_COMPONENT "jabber:component:accept"
|
37
|
+
/** @def XMPP_NS_STREAMS
|
38
|
+
* Namespace definition for 'http://etherx.jabber.org/streams'.
|
39
|
+
*/
|
40
|
+
#define XMPP_NS_STREAMS "http://etherx.jabber.org/streams"
|
41
|
+
/** @def XMPP_NS_STREAMS_IETF
|
42
|
+
* Namespace definition for 'urn:ietf:params:xml:ns:xmpp-streams'.
|
43
|
+
*/
|
44
|
+
#define XMPP_NS_STREAMS_IETF "urn:ietf:params:xml:ns:xmpp-streams"
|
45
|
+
/** @def XMPP_NS_TLS
|
46
|
+
* Namespace definition for 'url:ietf:params:xml:ns:xmpp-tls'.
|
47
|
+
*/
|
48
|
+
#define XMPP_NS_TLS "urn:ietf:params:xml:ns:xmpp-tls"
|
49
|
+
/** @def XMPP_NS_SASL
|
50
|
+
* Namespace definition for 'urn:ietf:params:xml:ns:xmpp-sasl'.
|
51
|
+
*/
|
52
|
+
#define XMPP_NS_SASL "urn:ietf:params:xml:ns:xmpp-sasl"
|
53
|
+
/** @def XMPP_NS_BIND
|
54
|
+
* Namespace definition for 'urn:ietf:params:xml:ns:xmpp-bind'.
|
55
|
+
*/
|
56
|
+
#define XMPP_NS_BIND "urn:ietf:params:xml:ns:xmpp-bind"
|
57
|
+
/** @def XMPP_NS_SESSION
|
58
|
+
* Namespace definition for 'urn:ietf:params:xml:ns:xmpp-session'.
|
59
|
+
*/
|
60
|
+
#define XMPP_NS_SESSION "urn:ietf:params:xml:ns:xmpp-session"
|
61
|
+
/** @def XMPP_NS_AUTH
|
62
|
+
* Namespace definition for 'jabber:iq:auth'.
|
63
|
+
*/
|
64
|
+
#define XMPP_NS_AUTH "jabber:iq:auth"
|
65
|
+
/** @def XMPP_NS_DISCO_INFO
|
66
|
+
* Namespace definition for 'http://jabber.org/protocol/disco#info'.
|
67
|
+
*/
|
68
|
+
#define XMPP_NS_DISCO_INFO "http://jabber.org/protocol/disco#info"
|
69
|
+
/** @def XMPP_NS_DISCO_ITEMS
|
70
|
+
* Namespace definition for 'http://jabber.org/protocol/disco#items'.
|
71
|
+
*/
|
72
|
+
#define XMPP_NS_DISCO_ITEMS "http://jabber.org/protocol/disco#items"
|
73
|
+
/** @def XMPP_NS_ROSTER
|
74
|
+
* Namespace definition for 'jabber:iq:roster'.
|
75
|
+
*/
|
76
|
+
#define XMPP_NS_ROSTER "jabber:iq:roster"
|
77
|
+
|
78
|
+
/* error defines */
|
79
|
+
/** @def XMPP_EOK
|
80
|
+
* Success error code.
|
81
|
+
*/
|
82
|
+
#define XMPP_EOK 0
|
83
|
+
/** @def XMPP_EMEM
|
84
|
+
* Memory related failure error code.
|
85
|
+
*
|
86
|
+
* This is returned on allocation errors and signals that the host may
|
87
|
+
* be out of memory.
|
88
|
+
*/
|
89
|
+
#define XMPP_EMEM -1
|
90
|
+
/** @def XMPP_EINVOP
|
91
|
+
* Invalid operation error code.
|
92
|
+
*
|
93
|
+
* This error code is returned when the operation was invalid and signals
|
94
|
+
* that the Strophe API is being used incorrectly.
|
95
|
+
*/
|
96
|
+
#define XMPP_EINVOP -2
|
97
|
+
/** @def XMPP_EINT
|
98
|
+
* Internal failure error code.
|
99
|
+
*/
|
100
|
+
#define XMPP_EINT -3
|
101
|
+
|
102
|
+
/* initialization and shutdown */
|
103
|
+
void xmpp_initialize(void);
|
104
|
+
void xmpp_shutdown(void);
|
105
|
+
|
106
|
+
/* version */
|
107
|
+
int xmpp_version_check(int major, int minor);
|
108
|
+
|
109
|
+
/* run-time contexts */
|
110
|
+
|
111
|
+
/* user-replaceable memory allocator */
|
112
|
+
typedef struct _xmpp_mem_t xmpp_mem_t;
|
113
|
+
|
114
|
+
/* user-replaceable log object */
|
115
|
+
typedef struct _xmpp_log_t xmpp_log_t;
|
116
|
+
|
117
|
+
/* opaque run time context containing the above hooks */
|
118
|
+
typedef struct _xmpp_ctx_t xmpp_ctx_t;
|
119
|
+
|
120
|
+
xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem,
|
121
|
+
const xmpp_log_t * const log);
|
122
|
+
void xmpp_ctx_free(xmpp_ctx_t * const ctx);
|
123
|
+
|
124
|
+
struct _xmpp_mem_t {
|
125
|
+
void *(*alloc)(const size_t size, void * const userdata);
|
126
|
+
void (*free)(void *p, void * const userdata);
|
127
|
+
void *(*realloc)(void *p, const size_t size, void * const userdata);
|
128
|
+
void *userdata;
|
129
|
+
};
|
130
|
+
|
131
|
+
typedef enum {
|
132
|
+
XMPP_LEVEL_DEBUG,
|
133
|
+
XMPP_LEVEL_INFO,
|
134
|
+
XMPP_LEVEL_WARN,
|
135
|
+
XMPP_LEVEL_ERROR
|
136
|
+
} xmpp_log_level_t;
|
137
|
+
|
138
|
+
typedef enum {
|
139
|
+
XMPP_UNKNOWN,
|
140
|
+
XMPP_CLIENT,
|
141
|
+
XMPP_COMPONENT
|
142
|
+
} xmpp_conn_type_t;
|
143
|
+
|
144
|
+
typedef void (*xmpp_log_handler)(void * const userdata,
|
145
|
+
const xmpp_log_level_t level,
|
146
|
+
const char * const area,
|
147
|
+
const char * const msg);
|
148
|
+
|
149
|
+
struct _xmpp_log_t {
|
150
|
+
xmpp_log_handler handler;
|
151
|
+
void *userdata;
|
152
|
+
/* mutex_t lock; */
|
153
|
+
};
|
154
|
+
|
155
|
+
/* return a default logger filtering at a given level */
|
156
|
+
xmpp_log_t *xmpp_get_default_logger(xmpp_log_level_t level);
|
157
|
+
|
158
|
+
/* connection */
|
159
|
+
|
160
|
+
/* opaque connection object */
|
161
|
+
typedef struct _xmpp_conn_t xmpp_conn_t;
|
162
|
+
typedef struct _xmpp_stanza_t xmpp_stanza_t;
|
163
|
+
|
164
|
+
/* connect callback */
|
165
|
+
typedef enum {
|
166
|
+
XMPP_CONN_CONNECT,
|
167
|
+
XMPP_CONN_DISCONNECT,
|
168
|
+
XMPP_CONN_FAIL
|
169
|
+
} xmpp_conn_event_t;
|
170
|
+
|
171
|
+
typedef enum {
|
172
|
+
XMPP_SE_BAD_FORMAT,
|
173
|
+
XMPP_SE_BAD_NS_PREFIX,
|
174
|
+
XMPP_SE_CONFLICT,
|
175
|
+
XMPP_SE_CONN_TIMEOUT,
|
176
|
+
XMPP_SE_HOST_GONE,
|
177
|
+
XMPP_SE_HOST_UNKNOWN,
|
178
|
+
XMPP_SE_IMPROPER_ADDR,
|
179
|
+
XMPP_SE_INTERNAL_SERVER_ERROR,
|
180
|
+
XMPP_SE_INVALID_FROM,
|
181
|
+
XMPP_SE_INVALID_ID,
|
182
|
+
XMPP_SE_INVALID_NS,
|
183
|
+
XMPP_SE_INVALID_XML,
|
184
|
+
XMPP_SE_NOT_AUTHORIZED,
|
185
|
+
XMPP_SE_POLICY_VIOLATION,
|
186
|
+
XMPP_SE_REMOTE_CONN_FAILED,
|
187
|
+
XMPP_SE_RESOURCE_CONSTRAINT,
|
188
|
+
XMPP_SE_RESTRICTED_XML,
|
189
|
+
XMPP_SE_SEE_OTHER_HOST,
|
190
|
+
XMPP_SE_SYSTEM_SHUTDOWN,
|
191
|
+
XMPP_SE_UNDEFINED_CONDITION,
|
192
|
+
XMPP_SE_UNSUPPORTED_ENCODING,
|
193
|
+
XMPP_SE_UNSUPPORTED_STANZA_TYPE,
|
194
|
+
XMPP_SE_UNSUPPORTED_VERSION,
|
195
|
+
XMPP_SE_XML_NOT_WELL_FORMED
|
196
|
+
} xmpp_error_type_t;
|
197
|
+
|
198
|
+
typedef struct {
|
199
|
+
xmpp_error_type_t type;
|
200
|
+
char *text;
|
201
|
+
xmpp_stanza_t *stanza;
|
202
|
+
} xmpp_stream_error_t;
|
203
|
+
|
204
|
+
typedef void (*xmpp_conn_handler)(xmpp_conn_t * const conn,
|
205
|
+
const xmpp_conn_event_t event,
|
206
|
+
const int error,
|
207
|
+
xmpp_stream_error_t * const stream_error,
|
208
|
+
void * const userdata);
|
209
|
+
|
210
|
+
xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t * const ctx);
|
211
|
+
xmpp_conn_t * xmpp_conn_clone(xmpp_conn_t * const conn);
|
212
|
+
int xmpp_conn_release(xmpp_conn_t * const conn);
|
213
|
+
|
214
|
+
const char *xmpp_conn_get_jid(const xmpp_conn_t * const conn);
|
215
|
+
void xmpp_conn_set_jid(xmpp_conn_t * const conn, const char * const jid);
|
216
|
+
const char *xmpp_conn_get_pass(const xmpp_conn_t * const conn);
|
217
|
+
void xmpp_conn_set_pass(xmpp_conn_t * const conn, const char * const pass);
|
218
|
+
xmpp_ctx_t* xmpp_conn_get_context(xmpp_conn_t * const conn);
|
219
|
+
|
220
|
+
int xmpp_connect_client(xmpp_conn_t * const conn,
|
221
|
+
const char * const altdomain,
|
222
|
+
unsigned short altport,
|
223
|
+
xmpp_conn_handler callback,
|
224
|
+
void * const userdata);
|
225
|
+
|
226
|
+
/*
|
227
|
+
int xmpp_connect_component(conn, name)
|
228
|
+
*/
|
229
|
+
void xmpp_disconnect(xmpp_conn_t * const conn);
|
230
|
+
|
231
|
+
void xmpp_send(xmpp_conn_t * const conn,
|
232
|
+
xmpp_stanza_t * const stanza);
|
233
|
+
|
234
|
+
void xmpp_send_raw_string(xmpp_conn_t * const conn,
|
235
|
+
const char * const fmt, ...);
|
236
|
+
void xmpp_send_raw(xmpp_conn_t * const conn,
|
237
|
+
const char * const data, const size_t len);
|
238
|
+
|
239
|
+
|
240
|
+
/* handlers */
|
241
|
+
|
242
|
+
/* if the handle returns false it is removed */
|
243
|
+
typedef int (*xmpp_timed_handler)(xmpp_conn_t * const conn,
|
244
|
+
void * const userdata);
|
245
|
+
|
246
|
+
void xmpp_timed_handler_add(xmpp_conn_t * const conn,
|
247
|
+
xmpp_timed_handler handler,
|
248
|
+
const unsigned long period,
|
249
|
+
void * const userdata);
|
250
|
+
void xmpp_timed_handler_delete(xmpp_conn_t * const conn,
|
251
|
+
xmpp_timed_handler handler);
|
252
|
+
|
253
|
+
|
254
|
+
/* if the handler returns false it is removed */
|
255
|
+
typedef int (*xmpp_handler)(xmpp_conn_t * const conn,
|
256
|
+
xmpp_stanza_t * const stanza,
|
257
|
+
void * const userdata);
|
258
|
+
|
259
|
+
void xmpp_handler_add(xmpp_conn_t * const conn,
|
260
|
+
xmpp_handler handler,
|
261
|
+
const char * const ns,
|
262
|
+
const char * const name,
|
263
|
+
const char * const type,
|
264
|
+
void * const userdata);
|
265
|
+
void xmpp_handler_delete(xmpp_conn_t * const conn,
|
266
|
+
xmpp_handler handler);
|
267
|
+
|
268
|
+
void xmpp_id_handler_add(xmpp_conn_t * const conn,
|
269
|
+
xmpp_handler handler,
|
270
|
+
const char * const id,
|
271
|
+
void * const userdata);
|
272
|
+
void xmpp_id_handler_delete(xmpp_conn_t * const conn,
|
273
|
+
xmpp_handler handler,
|
274
|
+
const char * const id);
|
275
|
+
|
276
|
+
/*
|
277
|
+
void xmpp_register_stanza_handler(conn, stanza, xmlns, type, handler)
|
278
|
+
*/
|
279
|
+
|
280
|
+
/** stanzas **/
|
281
|
+
|
282
|
+
/** allocate an initialize a blank stanza */
|
283
|
+
xmpp_stanza_t *xmpp_stanza_new(xmpp_ctx_t *ctx);
|
284
|
+
|
285
|
+
/** clone a stanza */
|
286
|
+
xmpp_stanza_t *xmpp_stanza_clone(xmpp_stanza_t * const stanza);
|
287
|
+
|
288
|
+
/** copies a stanza and all children */
|
289
|
+
xmpp_stanza_t * xmpp_stanza_copy(const xmpp_stanza_t * const stanza);
|
290
|
+
|
291
|
+
/** free a stanza object and it's contents */
|
292
|
+
int xmpp_stanza_release(xmpp_stanza_t * const stanza);
|
293
|
+
|
294
|
+
/** free some blocks returned by other APIs, for example the
|
295
|
+
buffer you get from xmpp_stanza_to_text **/
|
296
|
+
void xmpp_free(const xmpp_ctx_t * const ctx, void *p);
|
297
|
+
|
298
|
+
int xmpp_stanza_is_text(xmpp_stanza_t * const stanza);
|
299
|
+
int xmpp_stanza_is_tag(xmpp_stanza_t * const stanza);
|
300
|
+
|
301
|
+
/** marshall a stanza into text for transmission or display **/
|
302
|
+
int xmpp_stanza_to_text(xmpp_stanza_t *stanza,
|
303
|
+
char ** const buf, size_t * const buflen);
|
304
|
+
|
305
|
+
xmpp_stanza_t *xmpp_stanza_get_children(xmpp_stanza_t * const stanza);
|
306
|
+
xmpp_stanza_t *xmpp_stanza_get_child_by_name(xmpp_stanza_t * const stanza,
|
307
|
+
const char * const name);
|
308
|
+
xmpp_stanza_t *xmpp_stanza_get_child_by_ns(xmpp_stanza_t * const stanza,
|
309
|
+
const char * const ns);
|
310
|
+
xmpp_stanza_t *xmpp_stanza_get_next(xmpp_stanza_t * const stanza);
|
311
|
+
char *xmpp_stanza_get_attribute(xmpp_stanza_t * const stanza,
|
312
|
+
const char * const name);
|
313
|
+
char * xmpp_stanza_get_ns(xmpp_stanza_t * const stanza);
|
314
|
+
/* concatenate all child text nodes. this function
|
315
|
+
* returns a string that must be freed by the caller */
|
316
|
+
|
317
|
+
char *xmpp_stanza_get_text(xmpp_stanza_t * const stanza);
|
318
|
+
char *xmpp_stanza_get_text_ptr(xmpp_stanza_t * const stanza);
|
319
|
+
char *xmpp_stanza_get_name(xmpp_stanza_t * const stanza);
|
320
|
+
|
321
|
+
int xmpp_stanza_add_child(xmpp_stanza_t *stanza, xmpp_stanza_t *child);
|
322
|
+
int xmpp_stanza_set_ns(xmpp_stanza_t * const stanza, const char * const ns);
|
323
|
+
/* set_attribute adds/replaces attributes */
|
324
|
+
int xmpp_stanza_set_attribute(xmpp_stanza_t * const stanza,
|
325
|
+
const char * const key,
|
326
|
+
const char * const value);
|
327
|
+
int xmpp_stanza_set_name(xmpp_stanza_t *stanza,
|
328
|
+
const char * const name);
|
329
|
+
int xmpp_stanza_set_text(xmpp_stanza_t *stanza,
|
330
|
+
const char * const text);
|
331
|
+
int xmpp_stanza_set_text_with_size(xmpp_stanza_t *stanza,
|
332
|
+
const char * const text,
|
333
|
+
const size_t size);
|
334
|
+
|
335
|
+
/* common stanza helpers */
|
336
|
+
char *xmpp_stanza_get_type(xmpp_stanza_t * const stanza);
|
337
|
+
char *xmpp_stanza_get_id(xmpp_stanza_t * const stanza);
|
338
|
+
int xmpp_stanza_set_id(xmpp_stanza_t * const stanza,
|
339
|
+
const char * const id);
|
340
|
+
int xmpp_stanza_set_type(xmpp_stanza_t * const stanza,
|
341
|
+
const char * const type);
|
342
|
+
|
343
|
+
/* unimplemented
|
344
|
+
int xmpp_stanza_set_to();
|
345
|
+
int xmpp_stanza_set_from();
|
346
|
+
*/
|
347
|
+
|
348
|
+
/* allocate and initialize a stanza in reply to another */
|
349
|
+
/* unimplemented
|
350
|
+
xmpp_stanza_t *xmpp_stanza_reply(const xmpp_stanza_t *stanza);
|
351
|
+
*/
|
352
|
+
|
353
|
+
/* stanza subclasses */
|
354
|
+
/* unimplemented
|
355
|
+
void xmpp_message_new();
|
356
|
+
void xmpp_message_get_body();
|
357
|
+
void xmpp_message_set_body();
|
358
|
+
|
359
|
+
void xmpp_iq_new();
|
360
|
+
void xmpp_presence_new();
|
361
|
+
*/
|
362
|
+
|
363
|
+
/** event loop **/
|
364
|
+
int xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout);
|
365
|
+
void xmpp_run(xmpp_ctx_t *ctx);
|
366
|
+
void xmpp_stop(xmpp_ctx_t *ctx);
|
367
|
+
|
368
|
+
#ifdef __cplusplus
|
369
|
+
}
|
370
|
+
#endif
|
371
|
+
|
372
|
+
#endif /* __LIBSTROPHE_STROPHE_H__ */
|