Capture the bound jid.
I'd kind of like to be able to discover the JID with full resource for some operations.
This commit is contained in:
10
src/auth.c
10
src/auth.c
@@ -833,9 +833,17 @@ static int _handle_bind(xmpp_conn_t * const conn,
|
|||||||
xmpp_error(conn->ctx, "xmpp", "Binding failed.");
|
xmpp_error(conn->ctx, "xmpp", "Binding failed.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
} else if (type && strcmp(type, "result") == 0) {
|
} else if (type && strcmp(type, "result") == 0) {
|
||||||
/* TODO: extract resource if present */
|
xmpp_stanza_t *binding = xmpp_stanza_get_child_by_name(stanza, "bind");
|
||||||
xmpp_debug(conn->ctx, "xmpp", "Bind successful.");
|
xmpp_debug(conn->ctx, "xmpp", "Bind successful.");
|
||||||
|
|
||||||
|
if (binding) {
|
||||||
|
xmpp_stanza_t *jid_stanza = xmpp_stanza_get_child_by_name(binding,
|
||||||
|
"jid");
|
||||||
|
if (jid_stanza) {
|
||||||
|
conn->bound_jid = xmpp_stanza_get_text(jid_stanza);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* establish a session if required */
|
/* establish a session if required */
|
||||||
if (conn->session_required) {
|
if (conn->session_required) {
|
||||||
/* setup response handlers */
|
/* setup response handlers */
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ struct _xmpp_conn_t {
|
|||||||
char *connectport;
|
char *connectport;
|
||||||
char *jid;
|
char *jid;
|
||||||
char *pass;
|
char *pass;
|
||||||
|
char *bound_jid;
|
||||||
char *stream_id;
|
char *stream_id;
|
||||||
|
|
||||||
/* send queue and parameters */
|
/* send queue and parameters */
|
||||||
|
|||||||
20
src/conn.c
20
src/conn.c
@@ -105,6 +105,7 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t * const ctx)
|
|||||||
conn->jid = NULL;
|
conn->jid = NULL;
|
||||||
conn->pass = NULL;
|
conn->pass = NULL;
|
||||||
conn->stream_id = NULL;
|
conn->stream_id = NULL;
|
||||||
|
conn->bound_jid = NULL;
|
||||||
|
|
||||||
conn->tls_support = 0;
|
conn->tls_support = 0;
|
||||||
conn->tls_failed = 0;
|
conn->tls_failed = 0;
|
||||||
@@ -267,6 +268,7 @@ int xmpp_conn_release(xmpp_conn_t * const conn)
|
|||||||
|
|
||||||
if (conn->domain) xmpp_free(ctx, conn->domain);
|
if (conn->domain) xmpp_free(ctx, conn->domain);
|
||||||
if (conn->jid) xmpp_free(ctx, conn->jid);
|
if (conn->jid) xmpp_free(ctx, conn->jid);
|
||||||
|
if (conn->bound_jid) xmpp_free(ctx, conn->bound_jid);
|
||||||
if (conn->pass) xmpp_free(ctx, conn->pass);
|
if (conn->pass) xmpp_free(ctx, conn->pass);
|
||||||
if (conn->stream_id) xmpp_free(ctx, conn->stream_id);
|
if (conn->stream_id) xmpp_free(ctx, conn->stream_id);
|
||||||
if (conn->lang) xmpp_free(ctx, conn->lang);
|
if (conn->lang) xmpp_free(ctx, conn->lang);
|
||||||
@@ -290,6 +292,24 @@ const char *xmpp_conn_get_jid(const xmpp_conn_t * const conn)
|
|||||||
return conn->jid;
|
return conn->jid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the JID discovered during binding time.
|
||||||
|
*
|
||||||
|
* This JID will contain the resource used by the current connection.
|
||||||
|
* This is useful in the case where a resource was not specified for
|
||||||
|
* binding.
|
||||||
|
*
|
||||||
|
* @param conn a Strophe connection object.
|
||||||
|
*
|
||||||
|
* @return a string containing the full JID or NULL if it's not been discovered
|
||||||
|
*
|
||||||
|
* @ingroup Connections
|
||||||
|
*/
|
||||||
|
const char *xmpp_conn_get_bound_jid(const xmpp_conn_t * const conn)
|
||||||
|
{
|
||||||
|
return conn->bound_jid;
|
||||||
|
}
|
||||||
|
|
||||||
/** Set the JID of the user that will be bound to the connection.
|
/** Set the JID of the user that will be bound to the connection.
|
||||||
* If any JID was previously set, it will be discarded. This should not be
|
* If any JID was previously set, it will be discarded. This should not be
|
||||||
* be used after a connection is created. The function will make a copy of
|
* be used after a connection is created. The function will make a copy of
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ xmpp_conn_t * xmpp_conn_clone(xmpp_conn_t * const conn);
|
|||||||
int xmpp_conn_release(xmpp_conn_t * const conn);
|
int xmpp_conn_release(xmpp_conn_t * const conn);
|
||||||
|
|
||||||
const char *xmpp_conn_get_jid(const xmpp_conn_t * const conn);
|
const char *xmpp_conn_get_jid(const xmpp_conn_t * const conn);
|
||||||
|
const char *xmpp_conn_get_bound_jid(const xmpp_conn_t * const conn);
|
||||||
void xmpp_conn_set_jid(xmpp_conn_t * const conn, const char * const jid);
|
void xmpp_conn_set_jid(xmpp_conn_t * const conn, const char * const jid);
|
||||||
const char *xmpp_conn_get_pass(const xmpp_conn_t * const conn);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user