Skip to content
This repository was archived by the owner on Oct 29, 2021. It is now read-only.

Commit 949b067

Browse files
committed
Merge remote-tracking branch 'upstream/master'
Conflicts: Makefile.am README.markdown examples/bot.c src/auth.c src/conn.c src/event.c src/resolver.c src/resolver.h src/sasl.c src/tls_openssl.c src/tls_schannel.c
2 parents f4265e4 + 936ddb0 commit 949b067

26 files changed

+829
-399
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ tests/test_sasl
5353
tests/test_scram
5454
tests/test_sha1
5555
tests/test_snprintf
56+
tests/test_string
5657
tests/test_sock
5758
m4/
5859
libmesode.project

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: c
2+
install:
3+
- sudo apt-get update
4+
- sudo apt-get -y install libtool pkg-config libexpat1-dev libxml2-dev libssl-dev check
5+
script:
6+
- ./bootstrap.sh
7+
- ./configure --without-libxml2 && make CFLAGS="-Wall -Werror" && make CFLAGS="-Wall -Werror" check-TESTS
8+
- make clean
9+
- ./configure --with-libxml2 && make CFLAGS="-Wall -Werror" && make CFLAGS="-Wall -Werror" check-TESTS
10+
- make clean
11+
- ./configure --disable-tls && make CFLAGS="-Wall -Werror" && make CFLAGS="-Wall -Werror" check-TESTS

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22
- IPv6 support
33
- Legacy SSL support
44
- Initial Android support
5+
- Resolver returns all SRV records instead of one. Lookup is performed
6+
according to RFC2052.
7+
- xmpp_connect_raw() provides access to a xmpp_conn object just after
8+
establishing TCP connection. This allows to implement in-band
9+
registration or authentication mechanisms.
10+
- xmpp_conn_t object is reusable now and can be reconnected with saving
11+
all handlers, flags, jid and password.
512
- New API:
613
- xmpp_uuid_gen()
14+
- xmpp_connect_raw()
15+
- xmpp_conn_raw_open_stream()
16+
- xmpp_conn_raw_tls_start()
717
- xmpp_conn_get_flags()
818
- xmpp_conn_set_flags()
919
- xmpp_conn_set_keepalive()

Makefile.am

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ examples_uuid_LDADD = $(MESODE_LIBS)
7171
## Tests
7272
TESTS = tests/check_parser tests/test_sha1 tests/test_md5 tests/test_rand \
7373
tests/test_scram tests/test_ctx tests/test_base64 tests/test_jid \
74-
tests/test_snprintf tests/test_resolver
74+
tests/test_snprintf tests/test_string tests/test_resolver
7575
check_PROGRAMS = $(TESTS)
7676

7777
tests_check_parser_SOURCES = tests/check_parser.c tests/test.h
@@ -95,10 +95,10 @@ tests_test_jid_CFLAGS = $(MESODE_FLAGS) -I$(top_srcdir)/src
9595
tests_test_jid_LDADD = $(MESODE_LIBS)
9696
tests_test_jid_LDFLAGS = -static
9797

98-
tests_test_resolver_SOURCES = tests/test_resolver.c tests/test.h \
99-
src/resolver.c src/snprintf.c
98+
tests_test_resolver_SOURCES = tests/test_resolver.c tests/test.h
10099
tests_test_resolver_CFLAGS = $(MESODE_FLAGS) -I$(top_srcdir)/src
101-
tests_test_resolver_LDADD = $(RESOLV_LIBS)
100+
tests_test_resolver_LDADD = $(MESODE_LIBS)
101+
tests_test_resolver_LDFLAGS = -static
102102

103103
tests_test_rand_SOURCES = tests/test_rand.c tests/test.c src/sha1.c
104104
tests_test_rand_CFLAGS = $(MESODE_FLAGS) -I$(top_srcdir)/src
@@ -114,3 +114,8 @@ tests_test_md5_CFLAGS = -I$(top_srcdir)/src
114114

115115
tests_test_snprintf_SOURCES = tests/test_snprintf.c
116116
tests_test_snprintf_CFLAGS = -I$(top_srcdir)/src
117+
118+
tests_test_string_SOURCES = tests/test_string.c tests/test.h
119+
tests_test_string_CFLAGS = $(MESODE_FLAGS) -I$(top_srcdir)/src
120+
tests_test_string_LDADD = $(MESODE_LIBS)
121+
tests_test_string_LDFLAGS = -static

examples/bot.c

Lines changed: 75 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -25,107 +25,103 @@
2525

2626
int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
2727
{
28-
xmpp_stanza_t *reply, *query, *name, *version, *text;
29-
const char *ns;
30-
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
31-
printf("Received version request from %s\n", xmpp_stanza_get_from(stanza));
32-
33-
reply = xmpp_stanza_reply(stanza);
34-
xmpp_stanza_set_type(reply, "result");
35-
36-
query = xmpp_stanza_new(ctx);
37-
xmpp_stanza_set_name(query, "query");
28+
xmpp_stanza_t *reply, *query, *name, *version, *text;
29+
const char *ns;
30+
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
31+
32+
printf("Received version request from %s\n", xmpp_stanza_get_from(stanza));
33+
34+
reply = xmpp_stanza_reply(stanza);
35+
xmpp_stanza_set_type(reply, "result");
36+
37+
query = xmpp_stanza_new(ctx);
38+
xmpp_stanza_set_name(query, "query");
3839
ns = xmpp_stanza_get_ns(xmpp_stanza_get_children(stanza));
3940
if (ns) {
4041
xmpp_stanza_set_ns(query, ns);
4142
}
4243

43-
name = xmpp_stanza_new(ctx);
44-
xmpp_stanza_set_name(name, "name");
45-
xmpp_stanza_add_child(query, name);
44+
name = xmpp_stanza_new(ctx);
45+
xmpp_stanza_set_name(name, "name");
46+
xmpp_stanza_add_child(query, name);
47+
xmpp_stanza_release(name);
4648

47-
text = xmpp_stanza_new(ctx);
48-
xmpp_stanza_set_text(text, "libstrophe example bot");
49-
xmpp_stanza_add_child(name, text);
49+
text = xmpp_stanza_new(ctx);
50+
xmpp_stanza_set_text(text, "libstrophe example bot");
51+
xmpp_stanza_add_child(name, text);
52+
xmpp_stanza_release(text);
5053

51-
version = xmpp_stanza_new(ctx);
52-
xmpp_stanza_set_name(version, "version");
53-
xmpp_stanza_add_child(query, version);
54+
version = xmpp_stanza_new(ctx);
55+
xmpp_stanza_set_name(version, "version");
56+
xmpp_stanza_add_child(query, version);
57+
xmpp_stanza_release(version);
5458

55-
text = xmpp_stanza_new(ctx);
56-
xmpp_stanza_set_text(text, "1.0");
57-
xmpp_stanza_add_child(version, text);
59+
text = xmpp_stanza_new(ctx);
60+
xmpp_stanza_set_text(text, "1.0");
61+
xmpp_stanza_add_child(version, text);
62+
xmpp_stanza_release(text);
5863

59-
xmpp_stanza_add_child(reply, query);
64+
xmpp_stanza_add_child(reply, query);
65+
xmpp_stanza_release(query);
6066

61-
xmpp_send(conn, reply);
62-
xmpp_stanza_release(reply);
63-
return 1;
67+
xmpp_send(conn, reply);
68+
xmpp_stanza_release(reply);
69+
return 1;
6470
}
6571

6672

6773
int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
6874
{
69-
xmpp_stanza_t *reply, *body, *text;
70-
char *intext, *replytext;
71-
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
72-
73-
if(!xmpp_stanza_get_child_by_name(stanza, "body")) return 1;
74-
if(xmpp_stanza_get_type(stanza) !=NULL && !strcmp(xmpp_stanza_get_type(stanza), "error")) return 1;
75-
76-
intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
77-
78-
printf("Incoming message from %s: %s\n", xmpp_stanza_get_from(stanza), intext);
79-
80-
reply = xmpp_stanza_reply(stanza);
81-
if (xmpp_stanza_get_type(reply) == NULL)
82-
xmpp_stanza_set_type(reply, "chat");
83-
84-
body = xmpp_stanza_new(ctx);
85-
xmpp_stanza_set_name(body, "body");
86-
87-
replytext = (char *) malloc(strlen(" to you too!") + strlen(intext) + 1);
88-
strcpy(replytext, intext);
89-
strcat(replytext, " to you too!");
90-
91-
xmpp_free(ctx, intext);
92-
93-
text = xmpp_stanza_new(ctx);
94-
xmpp_stanza_set_text(text, replytext);
95-
xmpp_stanza_add_child(body, text);
96-
xmpp_stanza_add_child(reply, body);
97-
98-
xmpp_stanza_release(body);
99-
xmpp_stanza_release(text);
100-
101-
xmpp_send(conn, reply);
102-
xmpp_stanza_release(reply);
103-
free(replytext);
104-
return 1;
75+
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
76+
xmpp_stanza_t *reply;
77+
char *intext, *replytext;
78+
79+
if (!xmpp_stanza_get_child_by_name(stanza, "body"))
80+
return 1;
81+
if (xmpp_stanza_get_type(stanza) != NULL && !strcmp(xmpp_stanza_get_type(stanza), "error"))
82+
return 1;
83+
84+
intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
85+
86+
printf("Incoming message from %s: %s\n", xmpp_stanza_get_from(stanza), intext);
87+
88+
reply = xmpp_stanza_reply(stanza);
89+
if (xmpp_stanza_get_type(reply) == NULL)
90+
xmpp_stanza_set_type(reply, "chat");
91+
92+
replytext = (char *) malloc(strlen(" to you too!") + strlen(intext) + 1);
93+
strcpy(replytext, intext);
94+
strcat(replytext, " to you too!");
95+
xmpp_free(ctx, intext);
96+
xmpp_message_set_body(reply, replytext);
97+
98+
xmpp_send(conn, reply);
99+
xmpp_stanza_release(reply);
100+
free(replytext);
101+
return 1;
105102
}
106103

107104
/* define a handler for connection events */
108-
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
109-
const int error, xmpp_stream_error_t * const stream_error,
110-
void * const userdata)
105+
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
106+
const int error, xmpp_stream_error_t * const stream_error,
107+
void * const userdata)
111108
{
112109
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
113110

114111
if (status == XMPP_CONN_CONNECT) {
115-
xmpp_stanza_t* pres;
116-
fprintf(stderr, "DEBUG: connected\n");
117-
xmpp_handler_add(conn,version_handler, "jabber:iq:version", "iq", NULL, ctx);
118-
xmpp_handler_add(conn,message_handler, NULL, "message", NULL, ctx);
119-
120-
/* Send initial <presence/> so that we appear online to contacts */
121-
pres = xmpp_stanza_new(ctx);
122-
xmpp_stanza_set_name(pres, "presence");
123-
xmpp_send(conn, pres);
124-
xmpp_stanza_release(pres);
112+
xmpp_stanza_t* pres;
113+
fprintf(stderr, "DEBUG: connected\n");
114+
xmpp_handler_add(conn, version_handler, "jabber:iq:version", "iq", NULL, ctx);
115+
xmpp_handler_add(conn, message_handler, NULL, "message", NULL, ctx);
116+
117+
/* Send initial <presence/> so that we appear online to contacts */
118+
pres = xmpp_presence_new(ctx);
119+
xmpp_send(conn, pres);
120+
xmpp_stanza_release(pres);
125121
}
126122
else {
127-
fprintf(stderr, "DEBUG: disconnected\n");
128-
xmpp_stop(ctx);
123+
fprintf(stderr, "DEBUG: disconnected\n");
124+
xmpp_stop(ctx);
129125
}
130126
}
131127

@@ -138,8 +134,8 @@ int main(int argc, char **argv)
138134

139135
/* take a jid and password on the command line */
140136
if (argc != 3) {
141-
fprintf(stderr, "Usage: bot <jid> <pass>\n\n");
142-
return 1;
137+
fprintf(stderr, "Usage: bot <jid> <pass>\n\n");
138+
return 1;
143139
}
144140

145141
jid = argv[1];

mesode.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ typedef struct _xmpp_ctx_t xmpp_ctx_t;
116116

117117
typedef struct _tlscert_t xmpp_tlscert_t;
118118

119-
xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem,
119+
xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem,
120120
const xmpp_log_t * const log);
121121
void xmpp_ctx_free(xmpp_ctx_t * const ctx);
122122

@@ -171,6 +171,7 @@ typedef struct _xmpp_stanza_t xmpp_stanza_t;
171171
/* connect callback */
172172
typedef enum {
173173
XMPP_CONN_CONNECT,
174+
XMPP_CONN_RAW_CONNECT,
174175
XMPP_CONN_DISCONNECT,
175176
XMPP_CONN_FAIL
176177
} xmpp_conn_event_t;
@@ -256,6 +257,15 @@ int xmpp_connect_component(xmpp_conn_t * const conn, const char * const server,
256257
unsigned short port, xmpp_conn_handler callback,
257258
void * const userdata);
258259

260+
int xmpp_connect_raw(xmpp_conn_t * const conn,
261+
const char * const altdomain,
262+
unsigned short altport,
263+
xmpp_certfail_handler certfail_cb,
264+
xmpp_conn_handler callback,
265+
void * const userdata);
266+
int xmpp_conn_raw_open_stream(xmpp_conn_t * const conn);
267+
int xmpp_conn_raw_tls_start(xmpp_conn_t * const conn);
268+
259269
void xmpp_disconnect(xmpp_conn_t * const conn);
260270

261271
void xmpp_send(xmpp_conn_t * const conn,
@@ -325,7 +335,7 @@ int xmpp_stanza_is_text(xmpp_stanza_t * const stanza);
325335
int xmpp_stanza_is_tag(xmpp_stanza_t * const stanza);
326336

327337
/* marshall a stanza into text for transmission or display */
328-
int xmpp_stanza_to_text(xmpp_stanza_t *stanza,
338+
int xmpp_stanza_to_text(xmpp_stanza_t *stanza,
329339
char ** const buf, size_t * const buflen);
330340

331341
xmpp_stanza_t *xmpp_stanza_get_children(xmpp_stanza_t * const stanza);

src/auth.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ static int _handle_proceedtls_default(xmpp_conn_t * const conn,
288288
xmpp_debug(conn->ctx, "xmpp", "proceeding with TLS");
289289

290290
if (conn_tls_start(conn) == 0) {
291+
conn_prepare_reset(conn, auth_handle_open);
291292
conn_open_stream(conn);
292293
} else {
293294
/* failed tls spoils the connection, so disconnect */
@@ -562,19 +563,15 @@ static void _auth(xmpp_conn_t * const conn)
562563
anonjid = 0;
563564
}
564565

565-
if (conn->tls_support)
566-
{
566+
if (conn->tls_support) {
567567
tls_t *tls = tls_new(conn->ctx, conn->sock, conn->certfail_handler, conn->tls_cert_path);
568568

569569
/* If we couldn't init tls, it isn't there, so go on */
570-
if (!tls)
571-
{
570+
if (!tls) {
572571
conn->tls_support = 0;
573572
_auth(conn);
574573
return;
575-
}
576-
else
577-
{
574+
} else {
578575
tls_free(tls);
579576
}
580577

@@ -1235,3 +1232,16 @@ int _handle_missing_handshake(xmpp_conn_t * const conn, void * const userdata)
12351232
xmpp_disconnect(conn);
12361233
return 0;
12371234
}
1235+
1236+
void auth_handle_open_raw(xmpp_conn_t * const conn)
1237+
{
1238+
handler_reset_timed(conn, 0);
1239+
/* user handlers are not called before authentication is completed. */
1240+
conn->authenticated = 1;
1241+
conn->conn_handler(conn, XMPP_CONN_CONNECT, 0, NULL, conn->userdata);
1242+
}
1243+
1244+
void auth_handle_open_stub(xmpp_conn_t * const conn)
1245+
{
1246+
xmpp_warn(conn->ctx, "auth", "Stub callback is called.");
1247+
}

src/common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct _xmpp_conn_t {
149149
unsigned int ref;
150150
xmpp_ctx_t *ctx;
151151
xmpp_conn_type_t type;
152+
int is_raw;
152153

153154
xmpp_conn_state_t state;
154155
uint64_t timeout_stamp;
@@ -216,6 +217,7 @@ struct _xmpp_conn_t {
216217

217218
void conn_disconnect(xmpp_conn_t * const conn);
218219
void conn_disconnect_clean(xmpp_conn_t * const conn);
220+
void conn_established(xmpp_conn_t * const conn);
219221
void conn_open_stream(xmpp_conn_t * const conn);
220222
int conn_tls_start(xmpp_conn_t * const conn);
221223
void conn_prepare_reset(xmpp_conn_t * const conn, xmpp_open_handler handler);
@@ -270,6 +272,8 @@ void disconnect_mem_error(xmpp_conn_t * const conn);
270272
/* auth functions */
271273
void auth_handle_open(xmpp_conn_t * const conn);
272274
void auth_handle_component_open(xmpp_conn_t * const conn);
275+
void auth_handle_open_raw(xmpp_conn_t * const conn);
276+
void auth_handle_open_stub(xmpp_conn_t * const conn);
273277

274278
/* replacement snprintf and vsnprintf */
275279
int xmpp_snprintf (char *str, size_t count, const char *fmt, ...);

0 commit comments

Comments
 (0)