From 3b47afaac9ef0497260ce575b923dacb128667f1 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 3 Jul 2008 05:20:59 +0000 Subject: [PATCH] Fix warnings and line endings from previous SRV commit. Get rid of domain parameter of xmpp_connect_client(). Remove usused handler.c helper left over from previous commit. --- examples/active.c | 6 ++-- examples/basic.c | 15 +++------ examples/bot.c | 17 +++------- examples/roster.c | 6 ++-- src/conn.c | 26 ++++++--------- src/handler.c | 27 ---------------- src/sock.c | 82 ++++++++++++++++++++++------------------------- strophe.h | 1 - 8 files changed, 64 insertions(+), 116 deletions(-) diff --git a/examples/active.c b/examples/active.c index d293d88..9a78dff 100644 --- a/examples/active.c +++ b/examples/active.c @@ -93,8 +93,8 @@ int main(int argc, char **argv) xmpp_ctx_t *ctx; xmpp_conn_t *conn; - if (argc != 4) { - fprintf(stderr, "Usage: active \n\n"); + if (argc != 3) { + fprintf(stderr, "Usage: active \n\n"); return 1; } @@ -112,7 +112,7 @@ int main(int argc, char **argv) xmpp_conn_set_pass(conn, argv[2]); /* initiate connection */ - xmpp_connect_client(conn, argv[3], NULL, 0, conn_handler, ctx); + xmpp_connect_client(conn, NULL, 0, conn_handler, ctx); /* start the event loop */ xmpp_run(ctx); diff --git a/examples/basic.c b/examples/basic.c index 9da647c..cc467cc 100644 --- a/examples/basic.c +++ b/examples/basic.c @@ -40,22 +40,15 @@ int main(int argc, char **argv) xmpp_conn_t *conn; xmpp_log_t *log; char *jid, *pass; - char *server; - /* take a jid and password on the command line, - with optional server to connect to */ - if ((argc < 3) || (argc > 4)) { - fprintf(stderr, "Usage: basic []\n\n"); + /* take a jid and password on the command line */ + if (argc != 3) { + fprintf(stderr, "Usage: basic \n\n"); return 1; } jid = argv[1]; pass = argv[2]; - server = NULL; - /* Normally we pass NULL for the connection domain, in which case - the library derives the target host from the jid, but we can - override this for testing. */ - if (argc >= 4) server = argv[3]; /* init library */ xmpp_initialize(); @@ -72,7 +65,7 @@ int main(int argc, char **argv) xmpp_conn_set_pass(conn, pass); /* initiate connection */ - xmpp_connect_client(conn, server, NULL, 0, conn_handler, ctx); + xmpp_connect_client(conn, NULL, 0, conn_handler, ctx); /* enter the event loop - our connect handler will trigger an exit */ diff --git a/examples/bot.c b/examples/bot.c index 5c3c04d..76c5064 100644 --- a/examples/bot.c +++ b/examples/bot.c @@ -133,23 +133,16 @@ int main(int argc, char **argv) xmpp_conn_t *conn; xmpp_log_t *log; char *jid, *pass; - char *server; - /* take a jid and password on the command line, - with optional server to connect to */ - if ((argc < 3) || (argc > 4)) { - fprintf(stderr, "Usage: basic []\n\n"); + /* take a jid and password on the command line */ + if (argc != 3) { + fprintf(stderr, "Usage: bot \n\n"); return 1; } jid = argv[1]; pass = argv[2]; - server = NULL; - /* Normally we pass NULL for the connection domain, in which case - the library derives the target host from the jid, but we can - override this for testing. */ - if (argc >= 4) server = argv[3]; - + /* init library */ xmpp_initialize(); @@ -165,7 +158,7 @@ int main(int argc, char **argv) xmpp_conn_set_pass(conn, pass); /* initiate connection */ - xmpp_connect_client(conn, server, conn_handler, ctx); + xmpp_connect_client(conn, NULL, 0, conn_handler, ctx); /* enter the event loop - our connect handler will trigger an exit */ diff --git a/examples/roster.c b/examples/roster.c index 6b2c7df..5e9f7db 100644 --- a/examples/roster.c +++ b/examples/roster.c @@ -98,8 +98,8 @@ int main(int argc, char **argv) xmpp_ctx_t *ctx; xmpp_conn_t *conn; - if (argc != 4) { - fprintf(stderr, "Usage: roster \n\n"); + if (argc != 3) { + fprintf(stderr, "Usage: roster \n\n"); return 1; } @@ -117,7 +117,7 @@ int main(int argc, char **argv) xmpp_conn_set_pass(conn, argv[2]); /* initiate connection */ - xmpp_connect_client(conn, argv[3], NULL, 0, conn_handler, ctx); + xmpp_connect_client(conn, NULL, 0, conn_handler, ctx); /* start the event loop */ xmpp_run(ctx); diff --git a/src/conn.c b/src/conn.c index e52cbe7..576c302 100644 --- a/src/conn.c +++ b/src/conn.c @@ -328,10 +328,10 @@ void xmpp_conn_set_pass(xmpp_conn_t * const conn, const char * const pass) * altport will be used instead if specified. * * @param conn a Strophe connection object - * @param domain a string with the domain name to connect to. If this is - * NULL then the domain is taken from the JID. - * @param altdomain a string with domain to use if SRV lookup fails - * @param altport an integer port number to use if SRV lookup fails + * @param altdomain a string with domain to use if SRV lookup fails. If this + * is NULL, the domain from the JID will be used. + * @param altport an integer port number to use if SRV lookup fails. If this + * is 0, the default port (5222) will be assumed. * @param callback a xmpp_conn_handler callback function that will receive * notifications of connection status * @param userdata an opaque data pointer that will be passed to the callback @@ -341,7 +341,6 @@ void xmpp_conn_set_pass(xmpp_conn_t * const conn, const char * const pass) * @ingroup Connections */ int xmpp_connect_client(xmpp_conn_t * const conn, - const char * const domain, const char * const altdomain, unsigned short altport, xmpp_conn_handler callback, @@ -349,25 +348,20 @@ int xmpp_connect_client(xmpp_conn_t * const conn, { char connectdomain[2048]; int connectport; + char *domain; conn->type = XMPP_CLIENT; - if (domain) { - conn->domain = xmpp_strdup(conn->ctx, domain); - } else { - conn->domain = xmpp_jid_domain(conn->ctx, conn->jid); - } + conn->domain = xmpp_jid_domain(conn->ctx, conn->jid); if (!conn->domain) return -1; if (!sock_srv_lookup("xmpp-client", "tcp", conn->domain, connectdomain, 2048, &connectport)) { xmpp_debug(conn->ctx, "xmpp", "SRV lookup failed."); - if (altdomain) - { - xmpp_debug(conn->ctx, "xmpp", "Using alternate domain %s, port %d", altdomain, altport); - strcpy(connectdomain, altdomain); - connectport = altport; - } + if (!altdomain) domain = conn->domain; + xmpp_debug(conn->ctx, "xmpp", "Using alternate domain %s, port %d", altdomain, altport); + strcpy(connectdomain, domain); + connectport = altport ? altport : 5222; } conn->sock = sock_connect(connectdomain, connectport); if (conn->sock == -1) return -1; diff --git a/src/handler.c b/src/handler.c index 7a1ec8a..55c7ad4 100644 --- a/src/handler.c +++ b/src/handler.c @@ -32,33 +32,6 @@ #include "strophe.h" #include "common.h" -/* do any of the immediate children have namespaces that match? */ -static int _match_children(xmpp_stanza_t * const stanza, - const char * const ns) -{ - xmpp_stanza_t *child; - int matched = 0; - char *childns; - - child = xmpp_stanza_get_children(stanza); - while (child) { - childns = xmpp_stanza_get_ns(child); - if (!childns) { - child = xmpp_stanza_get_next(child); - continue; - } - - if (strcmp(ns, childns) == 0) { - matched = 1; - break; - } - - child = xmpp_stanza_get_next(child); - } - - return matched; -} - /** Fire off all stanza handlers that match. * This function is called internally by the event loop whenever stanzas * are received from the XMPP server. diff --git a/src/sock.c b/src/sock.c index f137ad3..c3e5f2e 100644 --- a/src/sock.c +++ b/src/sock.c @@ -34,7 +34,8 @@ #include #include #include -#include +#include +#include #include #endif @@ -396,7 +397,7 @@ int netbuf_get_domain_name(unsigned char *buf, int buflen, int *offset, char *na /* actually copy in name */ p = start; - p2 = namebuf; + p2 = (unsigned char *)namebuf; while (*p) { if ((*p & 0xC0) == 0xC0) @@ -860,47 +861,42 @@ int sock_srv_lookup(const char *service, const char *proto, const char *domain, } -#else - if (!set) - { - char buf[65535]; - int len; - - if ((len = res_query(fulldomain, C_IN, T_SRV, buf, 65535)) > 0) - { - int offset; - int i; - struct dnsquery_header header; - struct dnsquery_question question; - struct dnsquery_resourcerecord rr; - - offset = 0; - netbuf_get_dnsquery_header(buf, 65536, &offset, &header); - - for (i = 0; i < header.qdcount; i++) - { - netbuf_get_dnsquery_question(buf, 65536, &offset, &question); - } - - for (i = 0; i < header.ancount; i++) - { - netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr); - - if (rr.type == 33) - { - struct dnsquery_srvrdata *srvrdata = &(rr.rdata); - - snprintf(resulttarget, resulttargetlength, srvrdata->target); - *resultport = srvrdata->port; - set = 1; - } - } - - for (i = 0; i < header.ancount; i++) - { - netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr); - } - } +#else + if (!set) { + unsigned char buf[65535]; + int len; + + if ((len = res_query(fulldomain, C_IN, T_SRV, buf, 65535)) > 0) { + int offset; + int i; + struct dnsquery_header header; + struct dnsquery_question question; + struct dnsquery_resourcerecord rr; + + offset = 0; + netbuf_get_dnsquery_header(buf, 65536, &offset, &header); + + for (i = 0; i < header.qdcount; i++) { + netbuf_get_dnsquery_question(buf, 65536, &offset, &question); + } + + for (i = 0; i < header.ancount; i++) { + netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr); + + if (rr.type == 33) { + struct dnsquery_srvrdata *srvrdata = &(rr.rdata); + + snprintf(resulttarget, resulttargetlength, + srvrdata->target); + *resultport = srvrdata->port; + set = 1; + } + } + + for (i = 0; i < header.ancount; i++) { + netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr); + } + } } #endif diff --git a/strophe.h b/strophe.h index d89eed5..930dcb6 100644 --- a/strophe.h +++ b/strophe.h @@ -217,7 +217,6 @@ const char *xmpp_conn_get_pass(const xmpp_conn_t * const conn); void xmpp_conn_set_pass(xmpp_conn_t * const conn, const char * const pass); int xmpp_connect_client(xmpp_conn_t * const conn, - const char * const domain, const char * const altdomain, unsigned short altport, xmpp_conn_handler callback,