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.

This commit is contained in:
Jack Moffitt
2008-07-03 05:20:59 +00:00
parent 561fac842c
commit 3b47afaac9
8 changed files with 64 additions and 116 deletions

View File

@@ -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;
}
@@ -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);

View File

@@ -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();
@@ -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 */

View File

@@ -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();
@@ -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 */

View File

@@ -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;
}
@@ -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);

View File

@@ -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;

View File

@@ -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.

View File

@@ -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
@@ -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

View File

@@ -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,