XEP-0114: external component authentication
New API xmpp_connect_component() introduced.
This commit is contained in:
committed by
Dmitry Podgorny
parent
37a40dec23
commit
5d76e052ec
69
src/conn.c
69
src/conn.c
@@ -439,6 +439,73 @@ int xmpp_connect_client(xmpp_conn_t * const conn,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Initiate a component connection to server.
|
||||
* This function returns immediately after starting the connection
|
||||
* process to the XMPP server, and notifiations 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 0 on success and -1 on an error
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
int connectport;
|
||||
|
||||
conn->type = XMPP_COMPONENT;
|
||||
/* JID serves as an identificator here and will be used as "to" attribute
|
||||
of the stream */
|
||||
conn->domain = xmpp_strdup(conn->ctx, conn->jid);
|
||||
|
||||
/* The server domain, jid and password MUST be specified. */
|
||||
if (!(server && conn->jid && conn->pass)) return -1;
|
||||
|
||||
|
||||
connectport = port ? port : 5347;
|
||||
|
||||
xmpp_debug(conn->ctx, "xmpp", "Connecting via %s", server);
|
||||
conn->sock = sock_connect(server, connectport);
|
||||
xmpp_debug(conn->ctx, "xmpp", "sock_connect to %s:%d returned %d",
|
||||
server, connectport, conn->sock);
|
||||
if (conn->sock == -1) return -1;
|
||||
|
||||
/* XEP-0114 does not support TLS */
|
||||
conn->tls_disabled = 1;
|
||||
|
||||
/* setup handler */
|
||||
conn->conn_handler = callback;
|
||||
conn->userdata = userdata;
|
||||
|
||||
conn_prepare_reset(conn, auth_handle_component_open);
|
||||
|
||||
/* FIXME: it could happen that the connect returns immediately as
|
||||
* successful, though this is pretty unlikely. This would be a little
|
||||
* hard to fix, since we'd have to detect and fire off the callback
|
||||
* from within the event loop */
|
||||
|
||||
conn->state = XMPP_STATE_CONNECTING;
|
||||
conn->timeout_stamp = time_stamp();
|
||||
xmpp_debug(conn->ctx, "xmpp", "attempting to connect to %s", server);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Cleanly disconnect the connection.
|
||||
* This function is only called by the stream parser when </stream:stream>
|
||||
* is received, and it not intended to be called by code outside of Strophe.
|
||||
@@ -740,7 +807,7 @@ static void _handle_stream_start(char *name, char **attrs,
|
||||
conn_disconnect(conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* call stream open handler */
|
||||
conn->open_handler(conn);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user