stropheruby 0.1.5 → 0.2
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 -0
- data/README.txt +8 -3
- data/ext/auth.c +23 -22
- data/ext/common.h +8 -20
- data/ext/conn.c +167 -18
- data/ext/ctx.c +5 -5
- data/ext/event.c +28 -32
- data/ext/handler.c +6 -2
- data/ext/hash.c +2 -2
- data/ext/hash.h +2 -2
- data/ext/jid.c +1 -1
- data/ext/md5.h +1 -1
- data/ext/ostypes.h +2 -2
- data/ext/parser.h +43 -0
- data/ext/parser_expat.c +202 -0
- data/ext/sasl.h +3 -3
- data/ext/sock.c +1 -1
- data/ext/sock.h +2 -2
- data/ext/stanza.c +8 -47
- data/ext/strophe.h +8 -5
- 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 +8 -4
- data/ext/parser.c +0 -208
data/ext/thread.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* thread.h
|
2
2
|
** strophe XMPP client library -- thread abstraction header
|
3
3
|
**
|
4
|
-
** Copyright (C) 2005-
|
4
|
+
** Copyright (C) 2005-2009 Collecta, Inc.
|
5
5
|
**
|
6
6
|
** This software is provided AS-IS with no warranty, either express
|
7
7
|
** or implied.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
/** @file
|
16
16
|
* Threading abstraction API.
|
17
|
-
*/
|
17
|
+
*/
|
18
18
|
|
19
19
|
#ifndef __LIBSTROPHE_THREAD_H__
|
20
20
|
#define __LIBSTROPHE_THREAD_H__
|
data/ext/tls.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* tls.h
|
2
2
|
** strophe XMPP client library -- TLS abstraction header
|
3
3
|
**
|
4
|
-
** Copyright (C) 2005-
|
4
|
+
** Copyright (C) 2005-2009 Collecta, Inc.
|
5
5
|
**
|
6
6
|
** This software is provided AS-IS with no warranty, either express
|
7
7
|
** or implied.
|
data/ext/tls_dummy.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* tls_dummy.c
|
2
2
|
** strophe XMPP client library -- TLS abstraction dummy impl.
|
3
3
|
**
|
4
|
-
** Copyright (C) 2005-
|
4
|
+
** Copyright (C) 2005-2009 Collecta, Inc.
|
5
5
|
**
|
6
6
|
** This software is provided AS-IS with no warranty, either express
|
7
7
|
** or implied.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
/** @file
|
16
16
|
* TLS dummy implementation.
|
17
|
-
*/
|
17
|
+
*/
|
18
18
|
|
19
19
|
#include "common.h"
|
20
20
|
#include "tls.h"
|
data/ext/util.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* util.c
|
2
2
|
** strophe XMPP client library -- various utility functions
|
3
3
|
**
|
4
|
-
** Copyright (C) 2005-
|
4
|
+
** Copyright (C) 2005-2009 Collecta, Inc.
|
5
5
|
**
|
6
6
|
** This software is provided AS-IS with no warranty, either express
|
7
7
|
** or implied.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
/** @file
|
16
16
|
* Utility functions.
|
17
|
-
*/
|
17
|
+
*/
|
18
18
|
|
19
19
|
#include <stdio.h>
|
20
20
|
#include <string.h>
|
data/ext/util.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* util.h
|
2
2
|
** strophe XMPP client library -- various utility functions
|
3
3
|
**
|
4
|
-
** Copyright (C) 2005-
|
4
|
+
** Copyright (C) 2005-2009 Collecta, Inc.
|
5
5
|
**
|
6
6
|
** This software is provided AS-IS with no warranty, either express
|
7
7
|
** or implied.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
/** @file
|
16
16
|
* Internally used utility functions.
|
17
|
-
*/
|
17
|
+
*/
|
18
18
|
|
19
19
|
#ifndef __LIBSTROPHE_UTIL_H__
|
20
20
|
#define __LIBSTROPHE_UTIL_H__
|
metadata
CHANGED
@@ -4,11 +4,12 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
|
9
|
-
version: 0.1.5
|
7
|
+
- 2
|
8
|
+
version: "0.2"
|
10
9
|
platform: ruby
|
11
10
|
authors:
|
11
|
+
- Dingding Ye
|
12
|
+
- Xue Yong Zhi
|
12
13
|
- "Fran\xC3\xA7ois Lamontagne"
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
@@ -33,6 +34,8 @@ dependencies:
|
|
33
34
|
version_requirements: *id001
|
34
35
|
description:
|
35
36
|
email:
|
37
|
+
- yedingding@gmail.com
|
38
|
+
- xue.yong.zhi@gmail.com
|
36
39
|
- flamontagne@gmail.com
|
37
40
|
executables: []
|
38
41
|
|
@@ -50,7 +53,8 @@ files:
|
|
50
53
|
- README.txt
|
51
54
|
- Rakefile
|
52
55
|
- ext/md5.c
|
53
|
-
- ext/parser.
|
56
|
+
- ext/parser.h
|
57
|
+
- ext/parser_expat.c
|
54
58
|
- ext/util.c
|
55
59
|
- ext/strophe_ruby.c
|
56
60
|
- ext/conn.c
|
data/ext/parser.c
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
/* parser.c
|
2
|
-
** strophe XMPP client library -- xml parser handlers and utility functions
|
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
|
-
* XML parser handlers.
|
17
|
-
*/
|
18
|
-
|
19
|
-
#include <stdio.h>
|
20
|
-
#include <stdlib.h>
|
21
|
-
#include <string.h>
|
22
|
-
|
23
|
-
#include "expat.h"
|
24
|
-
|
25
|
-
#include "strophe.h"
|
26
|
-
#include "common.h"
|
27
|
-
|
28
|
-
static void _log_open_tag(xmpp_conn_t * const conn,
|
29
|
-
const XML_Char **attr)
|
30
|
-
{
|
31
|
-
char buf[4096];
|
32
|
-
size_t len, pos;
|
33
|
-
int i;
|
34
|
-
|
35
|
-
pos = 0;
|
36
|
-
len = xmpp_snprintf(buf, 4096, "<stream:stream");
|
37
|
-
if (len < 0) return;
|
38
|
-
|
39
|
-
pos += len;
|
40
|
-
|
41
|
-
for (i = 0; attr[i]; i += 2) {
|
42
|
-
len = xmpp_snprintf(&buf[pos], 4096 - pos, " %s=\"%s\"",
|
43
|
-
attr[i], attr[i+1]);
|
44
|
-
if (len < 0) return;
|
45
|
-
|
46
|
-
pos += len;
|
47
|
-
}
|
48
|
-
|
49
|
-
len = xmpp_snprintf(&buf[pos], 4096 - pos, ">");
|
50
|
-
if (len < 0) return;
|
51
|
-
|
52
|
-
xmpp_debug(conn->ctx, "xmpp", "RECV: %s", buf);
|
53
|
-
}
|
54
|
-
|
55
|
-
void parser_handle_start(void *userdata,
|
56
|
-
const XML_Char *name,
|
57
|
-
const XML_Char **attr)
|
58
|
-
{
|
59
|
-
xmpp_conn_t *conn = (xmpp_conn_t *)userdata;
|
60
|
-
xmpp_stanza_t *child;
|
61
|
-
|
62
|
-
if (conn->depth == 0) {
|
63
|
-
/* we're expecting a stream:stream tag. */
|
64
|
-
if (strcmp(name, "stream:stream") != 0) {
|
65
|
-
xmpp_error(conn->ctx, "xmpp",
|
66
|
-
"Server did not open valid stream.");
|
67
|
-
conn->error = -3;
|
68
|
-
conn_disconnect(conn);
|
69
|
-
} else {
|
70
|
-
_log_open_tag(conn, attr);
|
71
|
-
|
72
|
-
if (conn->stream_id) xmpp_free(conn->ctx, conn->stream_id);
|
73
|
-
conn->stream_id = xmpp_strdup(conn->ctx, "foo");
|
74
|
-
if (!conn->stream_id) {
|
75
|
-
xmpp_error(conn->ctx, "xmpp",
|
76
|
-
"Memory allocation failure.");
|
77
|
-
conn->error = -2;
|
78
|
-
conn_disconnect(conn);
|
79
|
-
}
|
80
|
-
|
81
|
-
/* call stream open handler */
|
82
|
-
conn->open_handler(conn);
|
83
|
-
}
|
84
|
-
} else {
|
85
|
-
/* build stanzas at depth 1 */
|
86
|
-
if (!conn->stanza && conn->depth != 1) {
|
87
|
-
/* something terrible happened */
|
88
|
-
/* FIXME: shutdown disconnect */
|
89
|
-
xmpp_debug(conn->ctx, "xmpp", "oops, where did our stanza go?");
|
90
|
-
} else if (!conn->stanza) {
|
91
|
-
/* starting a new toplevel stanza */
|
92
|
-
conn->stanza = xmpp_stanza_new(conn->ctx);
|
93
|
-
if (!conn->stanza) {
|
94
|
-
/* FIXME: can't allocate, disconnect */
|
95
|
-
}
|
96
|
-
xmpp_stanza_set_name(conn->stanza, name);
|
97
|
-
xmpp_stanza_set_attributes(conn->stanza, attr);
|
98
|
-
} else {
|
99
|
-
/* starting a child of conn->stanza */
|
100
|
-
child = xmpp_stanza_new(conn->ctx);
|
101
|
-
if (!child) {
|
102
|
-
/* FIXME: can't allocate, disconnect */
|
103
|
-
}
|
104
|
-
xmpp_stanza_set_name(child, name);
|
105
|
-
xmpp_stanza_set_attributes(child, attr);
|
106
|
-
|
107
|
-
/* add child to parent */
|
108
|
-
xmpp_stanza_add_child(conn->stanza, child);
|
109
|
-
|
110
|
-
/* the child is owned by the toplevel stanza now */
|
111
|
-
xmpp_stanza_release(child);
|
112
|
-
|
113
|
-
/* make child the current stanza */
|
114
|
-
conn->stanza = child;
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
conn->depth++;
|
119
|
-
}
|
120
|
-
|
121
|
-
void parser_handle_end(void *userdata, const XML_Char *name)
|
122
|
-
{
|
123
|
-
xmpp_conn_t *conn = (xmpp_conn_t *)userdata;
|
124
|
-
char *buf;
|
125
|
-
size_t len;
|
126
|
-
xmpp_stanza_t *stanza;
|
127
|
-
|
128
|
-
conn->depth--;
|
129
|
-
|
130
|
-
if (conn->depth == 0) {
|
131
|
-
/* got a closing stream tag */
|
132
|
-
xmpp_debug(conn->ctx, "xmpp", "RECV: </stream:stream>");
|
133
|
-
conn_disconnect_clean(conn);
|
134
|
-
} else {
|
135
|
-
if (conn->stanza->parent) {
|
136
|
-
/* we're finishing a child stanza, so set current to the parent */
|
137
|
-
conn->stanza = conn->stanza->parent;
|
138
|
-
} else {
|
139
|
-
/* we're finishing a toplevel stanza, so fire off handler */
|
140
|
-
if (xmpp_stanza_to_text(conn->stanza, &buf, &len) == 0) {
|
141
|
-
xmpp_debug(conn->ctx, "xmpp", "RECV: %s", buf);
|
142
|
-
xmpp_free(conn->ctx, buf);
|
143
|
-
}
|
144
|
-
|
145
|
-
stanza = xmpp_stanza_clone(conn->stanza);
|
146
|
-
xmpp_stanza_release(conn->stanza);
|
147
|
-
conn->stanza = NULL;
|
148
|
-
|
149
|
-
/* fire handlers */
|
150
|
-
handler_fire_stanza(conn, stanza);
|
151
|
-
|
152
|
-
xmpp_stanza_release(stanza);
|
153
|
-
}
|
154
|
-
}
|
155
|
-
}
|
156
|
-
|
157
|
-
void parser_handle_character(void *userdata, const XML_Char *s, int len)
|
158
|
-
{
|
159
|
-
xmpp_conn_t *conn = (xmpp_conn_t *)userdata;
|
160
|
-
xmpp_stanza_t *stanza;
|
161
|
-
|
162
|
-
if (conn->depth < 2) return;
|
163
|
-
|
164
|
-
/* create and populate stanza */
|
165
|
-
stanza = xmpp_stanza_new(conn->ctx);
|
166
|
-
if (!stanza) {
|
167
|
-
/* FIXME: allocation error, disconnect */
|
168
|
-
return;
|
169
|
-
}
|
170
|
-
xmpp_stanza_set_text_with_size(stanza, s, len);
|
171
|
-
|
172
|
-
xmpp_stanza_add_child(conn->stanza, stanza);
|
173
|
-
xmpp_stanza_release(stanza);
|
174
|
-
}
|
175
|
-
|
176
|
-
/* prepares a parser reset. this is called from handlers. we can't
|
177
|
-
* reset the parser immediately as it is not reentrant. */
|
178
|
-
void parser_prepare_reset(xmpp_conn_t * const conn,
|
179
|
-
xmpp_open_handler handler)
|
180
|
-
{
|
181
|
-
conn->reset_parser = 1;
|
182
|
-
conn->open_handler = handler;
|
183
|
-
}
|
184
|
-
|
185
|
-
/* shuts down and restarts XML parser. true on success */
|
186
|
-
int parser_reset(xmpp_conn_t * const conn)
|
187
|
-
{
|
188
|
-
conn->reset_parser = 0;
|
189
|
-
|
190
|
-
if (conn->parser)
|
191
|
-
XML_ParserFree(conn->parser);
|
192
|
-
|
193
|
-
if (conn->stanza)
|
194
|
-
xmpp_stanza_release(conn->stanza);
|
195
|
-
|
196
|
-
conn->parser = XML_ParserCreate(NULL);
|
197
|
-
if (!conn->parser) return 0;
|
198
|
-
|
199
|
-
conn->depth = 0;
|
200
|
-
conn->stanza = NULL;
|
201
|
-
XML_SetUserData(conn->parser, conn);
|
202
|
-
XML_SetElementHandler(conn->parser, parser_handle_start,
|
203
|
-
parser_handle_end);
|
204
|
-
XML_SetCharacterDataHandler(conn->parser, parser_handle_character);
|
205
|
-
|
206
|
-
return 1;
|
207
|
-
}
|
208
|
-
|