static jabber_conn_status_t _jabber_connect(const char * const fulljid, const char * const passwd, const char * const altdomain, int port) { assert(fulljid != NULL); assert(passwd != NULL); Jid *jid = jid_create(fulljid); if (jid == NULL) { log_error("Malformed JID not able to connect: %s", fulljid); jabber_conn.conn_status = JABBER_DISCONNECTED; return jabber_conn.conn_status; } else if (jid->fulljid == NULL) { log_error("Full JID required to connect, received: %s", fulljid); jabber_conn.conn_status = JABBER_DISCONNECTED; return jabber_conn.conn_status; } jid_destroy(jid); log_info("Connecting as %s", fulljid); if (jabber_conn.log) { free(jabber_conn.log); } jabber_conn.log = _xmpp_get_file_logger(); if (jabber_conn.conn) { xmpp_conn_release(jabber_conn.conn); } if (jabber_conn.ctx) { xmpp_ctx_free(jabber_conn.ctx); } jabber_conn.ctx = xmpp_ctx_new(NULL, jabber_conn.log); if (jabber_conn.ctx == NULL) { log_warning("Failed to get libstrophe ctx during connect"); return JABBER_DISCONNECTED; } jabber_conn.conn = xmpp_conn_new(jabber_conn.ctx); if (jabber_conn.conn == NULL) { log_warning("Failed to get libstrophe conn during connect"); return JABBER_DISCONNECTED; } xmpp_conn_set_jid(jabber_conn.conn, fulljid); xmpp_conn_set_pass(jabber_conn.conn, passwd); if (jabber_conn.tls_disabled) { xmpp_conn_disable_tls(jabber_conn.conn); } int connect_status = xmpp_connect_client(jabber_conn.conn, altdomain, port, _connection_handler, jabber_conn.ctx); if (connect_status == 0) jabber_conn.conn_status = JABBER_CONNECTING; else jabber_conn.conn_status = JABBER_DISCONNECTED; return jabber_conn.conn_status; }
/** Initiate a component connection to server. * This function returns immediately after starting the connection * process to the XMPP server, and notifications of connection state changes * will be sent to the internal callback function that will set up handler * for the component handshake as defined in XEP-0114. * The domain and port to connect to must be provided in this case as the JID * provided to the call serves as component identifier to the server and is * not subject to DNS resolution. * * @param conn a Strophe connection object * @param server a string with domain to use directly as the domain can't be * extracted from the component name/JID. If this is not set, the call * will fail. * @param port an integer port number to use to connect to server expecting * an external component. If this is 0, the port 5347 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 * * @return XMPP_EOK (0) on success or a number less than 0 on failure * * @ingroup Connections */ int xmpp_connect_component(xmpp_conn_t * const conn, const char * const server, unsigned short port, xmpp_conn_handler callback, void * const userdata) { /* The server domain, jid and password MUST be specified. */ if (!(server && conn->jid && conn->pass)) return XMPP_EINVOP; /* XEP-0114 does not support TLS */ xmpp_conn_disable_tls(conn); if (!conn->tls_disabled) { xmpp_error(conn->ctx, "conn", "Failed to disable TLS. " "XEP-0114 does not support TLS"); return XMPP_EINT; } port = port ? port : _conn_default_port(conn, XMPP_COMPONENT); /* JID serves as an identifier here and will be used as "to" attribute of the stream */ return _conn_connect(conn, conn->jid, server, port, XMPP_COMPONENT, callback, userdata); }