Skip to content

Commit

Permalink
Fix warnings and line endings from previous SRV commit. Get rid of do…
Browse files Browse the repository at this point in the history
…main parameter of xmpp_connect_client(). Remove usused handler.c helper left over from previous commit.
  • Loading branch information
metajack committed Jul 3, 2008
1 parent 561fac8 commit 3b47afa
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 116 deletions.
6 changes: 3 additions & 3 deletions examples/active.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <jid> <pass> <server>\n\n");
if (argc != 3) {
fprintf(stderr, "Usage: active <jid> <pass>\n\n");
return 1;
}

Expand All @@ -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);
Expand Down
15 changes: 4 additions & 11 deletions examples/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <jid> <pass> [<server>]\n\n");
/* take a jid and password on the command line */
if (argc != 3) {
fprintf(stderr, "Usage: basic <jid> <pass>\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();
Expand All @@ -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 */
Expand Down
17 changes: 5 additions & 12 deletions examples/bot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <jid> <pass> [<server>]\n\n");
/* take a jid and password on the command line */
if (argc != 3) {
fprintf(stderr, "Usage: bot <jid> <pass>\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();

Expand All @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions examples/roster.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <jid> <pass> <server>\n\n");
if (argc != 3) {
fprintf(stderr, "Usage: roster <jid> <pass>\n\n");
return 1;
}

Expand All @@ -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);
Expand Down
26 changes: 10 additions & 16 deletions src/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -341,33 +341,27 @@ 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,
void * const userdata)
{
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;
Expand Down
27 changes: 0 additions & 27 deletions src/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
82 changes: 39 additions & 43 deletions src/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
#include <netinet/in.h>
#include <netdb.h>
#include <fcntl.h>
#include <arpa/nameser.h>
#include <arpa/nameser.h>
#include <arpa/nameser_compat.h>
#include <resolv.h>
#endif

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion strophe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3b47afa

Please sign in to comment.