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:
@@ -93,8 +93,8 @@ int main(int argc, char **argv)
|
|||||||
xmpp_ctx_t *ctx;
|
xmpp_ctx_t *ctx;
|
||||||
xmpp_conn_t *conn;
|
xmpp_conn_t *conn;
|
||||||
|
|
||||||
if (argc != 4) {
|
if (argc != 3) {
|
||||||
fprintf(stderr, "Usage: active <jid> <pass> <server>\n\n");
|
fprintf(stderr, "Usage: active <jid> <pass>\n\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ int main(int argc, char **argv)
|
|||||||
xmpp_conn_set_pass(conn, argv[2]);
|
xmpp_conn_set_pass(conn, argv[2]);
|
||||||
|
|
||||||
/* initiate connection */
|
/* 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 */
|
/* start the event loop */
|
||||||
xmpp_run(ctx);
|
xmpp_run(ctx);
|
||||||
|
|||||||
@@ -40,22 +40,15 @@ int main(int argc, char **argv)
|
|||||||
xmpp_conn_t *conn;
|
xmpp_conn_t *conn;
|
||||||
xmpp_log_t *log;
|
xmpp_log_t *log;
|
||||||
char *jid, *pass;
|
char *jid, *pass;
|
||||||
char *server;
|
|
||||||
|
|
||||||
/* take a jid and password on the command line,
|
/* take a jid and password on the command line */
|
||||||
with optional server to connect to */
|
if (argc != 3) {
|
||||||
if ((argc < 3) || (argc > 4)) {
|
fprintf(stderr, "Usage: basic <jid> <pass>\n\n");
|
||||||
fprintf(stderr, "Usage: basic <jid> <pass> [<server>]\n\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
jid = argv[1];
|
jid = argv[1];
|
||||||
pass = argv[2];
|
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 */
|
/* init library */
|
||||||
xmpp_initialize();
|
xmpp_initialize();
|
||||||
@@ -72,7 +65,7 @@ int main(int argc, char **argv)
|
|||||||
xmpp_conn_set_pass(conn, pass);
|
xmpp_conn_set_pass(conn, pass);
|
||||||
|
|
||||||
/* initiate connection */
|
/* 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 -
|
/* enter the event loop -
|
||||||
our connect handler will trigger an exit */
|
our connect handler will trigger an exit */
|
||||||
|
|||||||
@@ -133,22 +133,15 @@ int main(int argc, char **argv)
|
|||||||
xmpp_conn_t *conn;
|
xmpp_conn_t *conn;
|
||||||
xmpp_log_t *log;
|
xmpp_log_t *log;
|
||||||
char *jid, *pass;
|
char *jid, *pass;
|
||||||
char *server;
|
|
||||||
|
|
||||||
/* take a jid and password on the command line,
|
/* take a jid and password on the command line */
|
||||||
with optional server to connect to */
|
if (argc != 3) {
|
||||||
if ((argc < 3) || (argc > 4)) {
|
fprintf(stderr, "Usage: bot <jid> <pass>\n\n");
|
||||||
fprintf(stderr, "Usage: basic <jid> <pass> [<server>]\n\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
jid = argv[1];
|
jid = argv[1];
|
||||||
pass = argv[2];
|
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 */
|
/* init library */
|
||||||
xmpp_initialize();
|
xmpp_initialize();
|
||||||
@@ -165,7 +158,7 @@ int main(int argc, char **argv)
|
|||||||
xmpp_conn_set_pass(conn, pass);
|
xmpp_conn_set_pass(conn, pass);
|
||||||
|
|
||||||
/* initiate connection */
|
/* initiate connection */
|
||||||
xmpp_connect_client(conn, server, conn_handler, ctx);
|
xmpp_connect_client(conn, NULL, 0, conn_handler, ctx);
|
||||||
|
|
||||||
/* enter the event loop -
|
/* enter the event loop -
|
||||||
our connect handler will trigger an exit */
|
our connect handler will trigger an exit */
|
||||||
|
|||||||
@@ -98,8 +98,8 @@ int main(int argc, char **argv)
|
|||||||
xmpp_ctx_t *ctx;
|
xmpp_ctx_t *ctx;
|
||||||
xmpp_conn_t *conn;
|
xmpp_conn_t *conn;
|
||||||
|
|
||||||
if (argc != 4) {
|
if (argc != 3) {
|
||||||
fprintf(stderr, "Usage: roster <jid> <pass> <server>\n\n");
|
fprintf(stderr, "Usage: roster <jid> <pass>\n\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ int main(int argc, char **argv)
|
|||||||
xmpp_conn_set_pass(conn, argv[2]);
|
xmpp_conn_set_pass(conn, argv[2]);
|
||||||
|
|
||||||
/* initiate connection */
|
/* 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 */
|
/* start the event loop */
|
||||||
xmpp_run(ctx);
|
xmpp_run(ctx);
|
||||||
|
|||||||
26
src/conn.c
26
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.
|
* altport will be used instead if specified.
|
||||||
*
|
*
|
||||||
* @param conn a Strophe connection object
|
* @param conn a Strophe connection object
|
||||||
* @param domain a string with the domain name to connect to. If this is
|
* @param altdomain a string with domain to use if SRV lookup fails. If this
|
||||||
* NULL then the domain is taken from the JID.
|
* is NULL, the domain from the JID will be used.
|
||||||
* @param altdomain a string with domain to use if SRV lookup fails
|
* @param altport an integer port number to use if SRV lookup fails. If this
|
||||||
* @param altport an integer port number to use if SRV lookup fails
|
* is 0, the default port (5222) will be assumed.
|
||||||
* @param callback a xmpp_conn_handler callback function that will receive
|
* @param callback a xmpp_conn_handler callback function that will receive
|
||||||
* notifications of connection status
|
* notifications of connection status
|
||||||
* @param userdata an opaque data pointer that will be passed to the callback
|
* @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
|
* @ingroup Connections
|
||||||
*/
|
*/
|
||||||
int xmpp_connect_client(xmpp_conn_t * const conn,
|
int xmpp_connect_client(xmpp_conn_t * const conn,
|
||||||
const char * const domain,
|
|
||||||
const char * const altdomain,
|
const char * const altdomain,
|
||||||
unsigned short altport,
|
unsigned short altport,
|
||||||
xmpp_conn_handler callback,
|
xmpp_conn_handler callback,
|
||||||
@@ -349,25 +348,20 @@ int xmpp_connect_client(xmpp_conn_t * const conn,
|
|||||||
{
|
{
|
||||||
char connectdomain[2048];
|
char connectdomain[2048];
|
||||||
int connectport;
|
int connectport;
|
||||||
|
char *domain;
|
||||||
|
|
||||||
conn->type = XMPP_CLIENT;
|
conn->type = XMPP_CLIENT;
|
||||||
|
|
||||||
if (domain) {
|
conn->domain = xmpp_jid_domain(conn->ctx, conn->jid);
|
||||||
conn->domain = xmpp_strdup(conn->ctx, domain);
|
|
||||||
} else {
|
|
||||||
conn->domain = xmpp_jid_domain(conn->ctx, conn->jid);
|
|
||||||
}
|
|
||||||
if (!conn->domain) return -1;
|
if (!conn->domain) return -1;
|
||||||
|
|
||||||
if (!sock_srv_lookup("xmpp-client", "tcp", conn->domain, connectdomain, 2048, &connectport))
|
if (!sock_srv_lookup("xmpp-client", "tcp", conn->domain, connectdomain, 2048, &connectport))
|
||||||
{
|
{
|
||||||
xmpp_debug(conn->ctx, "xmpp", "SRV lookup failed.");
|
xmpp_debug(conn->ctx, "xmpp", "SRV lookup failed.");
|
||||||
if (altdomain)
|
if (!altdomain) domain = conn->domain;
|
||||||
{
|
xmpp_debug(conn->ctx, "xmpp", "Using alternate domain %s, port %d", altdomain, altport);
|
||||||
xmpp_debug(conn->ctx, "xmpp", "Using alternate domain %s, port %d", altdomain, altport);
|
strcpy(connectdomain, domain);
|
||||||
strcpy(connectdomain, altdomain);
|
connectport = altport ? altport : 5222;
|
||||||
connectport = altport;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
conn->sock = sock_connect(connectdomain, connectport);
|
conn->sock = sock_connect(connectdomain, connectport);
|
||||||
if (conn->sock == -1) return -1;
|
if (conn->sock == -1) return -1;
|
||||||
|
|||||||
@@ -32,33 +32,6 @@
|
|||||||
#include "strophe.h"
|
#include "strophe.h"
|
||||||
#include "common.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.
|
/** Fire off all stanza handlers that match.
|
||||||
* This function is called internally by the event loop whenever stanzas
|
* This function is called internally by the event loop whenever stanzas
|
||||||
* are received from the XMPP server.
|
* are received from the XMPP server.
|
||||||
|
|||||||
64
src/sock.c
64
src/sock.c
@@ -35,6 +35,7 @@
|
|||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <arpa/nameser.h>
|
#include <arpa/nameser.h>
|
||||||
|
#include <arpa/nameser_compat.h>
|
||||||
#include <resolv.h>
|
#include <resolv.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -396,7 +397,7 @@ int netbuf_get_domain_name(unsigned char *buf, int buflen, int *offset, char *na
|
|||||||
|
|
||||||
/* actually copy in name */
|
/* actually copy in name */
|
||||||
p = start;
|
p = start;
|
||||||
p2 = namebuf;
|
p2 = (unsigned char *)namebuf;
|
||||||
while (*p)
|
while (*p)
|
||||||
{
|
{
|
||||||
if ((*p & 0xC0) == 0xC0)
|
if ((*p & 0xC0) == 0xC0)
|
||||||
@@ -861,45 +862,40 @@ int sock_srv_lookup(const char *service, const char *proto, const char *domain,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if (!set)
|
if (!set) {
|
||||||
{
|
unsigned char buf[65535];
|
||||||
char buf[65535];
|
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if ((len = res_query(fulldomain, C_IN, T_SRV, buf, 65535)) > 0)
|
if ((len = res_query(fulldomain, C_IN, T_SRV, buf, 65535)) > 0) {
|
||||||
{
|
int offset;
|
||||||
int offset;
|
int i;
|
||||||
int i;
|
struct dnsquery_header header;
|
||||||
struct dnsquery_header header;
|
struct dnsquery_question question;
|
||||||
struct dnsquery_question question;
|
struct dnsquery_resourcerecord rr;
|
||||||
struct dnsquery_resourcerecord rr;
|
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
netbuf_get_dnsquery_header(buf, 65536, &offset, &header);
|
netbuf_get_dnsquery_header(buf, 65536, &offset, &header);
|
||||||
|
|
||||||
for (i = 0; i < header.qdcount; i++)
|
for (i = 0; i < header.qdcount; i++) {
|
||||||
{
|
netbuf_get_dnsquery_question(buf, 65536, &offset, &question);
|
||||||
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++)
|
for (i = 0; i < header.ancount; i++) {
|
||||||
{
|
netbuf_get_dnsquery_resourcerecord(buf, 65536, &offset, &rr);
|
||||||
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
|
#endif
|
||||||
|
|||||||
@@ -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);
|
void xmpp_conn_set_pass(xmpp_conn_t * const conn, const char * const pass);
|
||||||
|
|
||||||
int xmpp_connect_client(xmpp_conn_t * const conn,
|
int xmpp_connect_client(xmpp_conn_t * const conn,
|
||||||
const char * const domain,
|
|
||||||
const char * const altdomain,
|
const char * const altdomain,
|
||||||
unsigned short altport,
|
unsigned short altport,
|
||||||
xmpp_conn_handler callback,
|
xmpp_conn_handler callback,
|
||||||
|
|||||||
Reference in New Issue
Block a user