Make the server argument optional. Passing a NULL domain arg to xmpp_connect_client()
now derives the domain from the jid. Is it reasonable to just remove the 'domain' (more properly server) argument directly? The library should always handle this and I can't think why you'd want to override unless maybe if you have a proxy.
This commit is contained in:
@@ -45,12 +45,19 @@ int main(int argc, char **argv)
|
||||
xmpp_ctx_t *ctx;
|
||||
xmpp_conn_t *conn;
|
||||
xmpp_log_t log;
|
||||
char *jid, *pass;
|
||||
char *server;
|
||||
|
||||
if (argc != 4) {
|
||||
if ((argc < 3) || (argc > 4)) {
|
||||
fprintf(stderr, "Usage: basic <jid> <pass> <server>\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
jid = argv[1];
|
||||
pass = argv[2];
|
||||
if (argc >= 4) server = argv[3];
|
||||
else server = NULL;
|
||||
|
||||
/* init library */
|
||||
xmpp_initialize();
|
||||
|
||||
|
||||
11
src/conn.c
11
src/conn.c
@@ -228,10 +228,15 @@ int xmpp_connect_client(xmpp_conn_t * const conn,
|
||||
{
|
||||
conn->type = XMPP_CLIENT;
|
||||
|
||||
conn->domain = xmpp_strdup(conn->ctx, domain);
|
||||
if (domain) {
|
||||
conn->domain = xmpp_strdup(conn->ctx, domain);
|
||||
} else {
|
||||
conn->domain = xmpp_jid_domain(conn->ctx, conn->jid);
|
||||
}
|
||||
if (!conn->domain) return -1;
|
||||
|
||||
conn->sock = sock_connect(domain, 5222);
|
||||
/* TODO: look up SRV record for actual host and port */
|
||||
conn->sock = sock_connect(conn->domain, 5222);
|
||||
if (conn->sock < 0) return -1;
|
||||
|
||||
/* setup handler */
|
||||
@@ -244,7 +249,7 @@ int xmpp_connect_client(xmpp_conn_t * const conn,
|
||||
* from within the event loop */
|
||||
|
||||
conn->state = XMPP_STATE_CONNECTING;
|
||||
xmpp_debug(conn->ctx, "xmpp", "attempting to connect to %s", domain);
|
||||
xmpp_debug(conn->ctx, "xmpp", "attempting to connect to %s", conn->domain);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user