Strophe 0.13
XMPP client library
|
These functions manage a connection object. More...
Typedefs | |
typedef int(* | xmpp_sockopt_callback) (xmpp_conn_t *conn, void *sock) |
The function which will be called when Strophe creates a new socket. | |
Functions | |
xmpp_conn_t * | xmpp_conn_new (xmpp_ctx_t *ctx) |
Create a new Strophe connection object. | |
xmpp_conn_t * | xmpp_conn_clone (xmpp_conn_t *conn) |
Clone a Strophe connection object. | |
void | xmpp_conn_set_sockopt_callback (xmpp_conn_t *conn, xmpp_sockopt_callback callback) |
Register sockopt callback Set function to be called when a new socket is created to allow setting socket options before connection is started. | |
int | xmpp_conn_release (xmpp_conn_t *conn) |
Release a Strophe connection object. | |
const char * | xmpp_conn_get_jid (const xmpp_conn_t *conn) |
Get the JID which is or will be bound to the connection. | |
const char * | xmpp_conn_get_bound_jid (const xmpp_conn_t *conn) |
Get the JID discovered during binding time. | |
void | xmpp_conn_set_jid (xmpp_conn_t *conn, const char *jid) |
Set the JID of the user that will be bound to the connection. | |
const char * | xmpp_conn_get_pass (const xmpp_conn_t *conn) |
Get the password used for authentication of a connection. | |
void | xmpp_conn_set_pass (xmpp_conn_t *conn, const char *pass) |
Set the password used to authenticate the connection. | |
xmpp_ctx_t * | xmpp_conn_get_context (xmpp_conn_t *conn) |
Get the strophe context that the connection is associated with. | |
int | xmpp_connect_client (xmpp_conn_t *conn, const char *altdomain, unsigned short altport, xmpp_conn_handler callback, void *userdata) |
Initiate a connection to the XMPP server. | |
int | xmpp_connect_component (xmpp_conn_t *conn, const char *server, unsigned short port, xmpp_conn_handler callback, void *userdata) |
Initiate a component connection to server. | |
int | xmpp_connect_raw (xmpp_conn_t *conn, const char *altdomain, unsigned short altport, xmpp_conn_handler callback, void *userdata) |
Initiate a raw connection to the XMPP server. | |
int | xmpp_conn_open_stream_default (xmpp_conn_t *conn) |
Send the default opening stream tag. | |
int | xmpp_conn_open_stream (xmpp_conn_t *conn, char **attributes, size_t attributes_len) |
Send an opening stream tag. | |
int | xmpp_conn_tls_start (xmpp_conn_t *conn) |
Start synchronous TLS handshake with the server. | |
void | xmpp_disconnect (xmpp_conn_t *conn) |
Initiate termination of the connection to the XMPP server. | |
void | xmpp_send_raw_string (xmpp_conn_t *conn, const char *fmt,...) |
Send a raw string to the XMPP server. | |
void | xmpp_send_raw (xmpp_conn_t *conn, const char *data, size_t len) |
Send raw bytes to the XMPP server. | |
void | xmpp_send (xmpp_conn_t *conn, xmpp_stanza_t *stanza) |
Send an XML stanza to the XMPP server. | |
long | xmpp_conn_get_flags (const xmpp_conn_t *conn) |
Return applied flags for the connection. | |
int | xmpp_conn_set_flags (xmpp_conn_t *conn, long flags) |
Set flags for the connection. | |
int | xmpp_conn_is_secured (xmpp_conn_t *conn) |
Return whether TLS session is established or not. | |
int | xmpp_conn_is_connecting (xmpp_conn_t *conn) |
int | xmpp_conn_is_connected (xmpp_conn_t *conn) |
int | xmpp_conn_is_disconnected (xmpp_conn_t *conn) |
xmpp_sm_state_t * | xmpp_conn_get_sm_state (xmpp_conn_t *conn) |
This returns the Stream Management state of a connection object after it has been disconnected. | |
int | xmpp_conn_set_sm_state (xmpp_conn_t *conn, xmpp_sm_state_t *sm_state) |
void | xmpp_free_sm_state (xmpp_sm_state_t *sm_state) |
c.f. | |
int | xmpp_conn_send_queue_len (const xmpp_conn_t *conn) |
char * | xmpp_conn_send_queue_drop_element (xmpp_conn_t *conn, xmpp_queue_element_t which) |
Drop an element of the send queue. | |
int | xmpp_sockopt_cb_keepalive (xmpp_conn_t *conn, void *socket) |
Example sockopt callback function An example function that can be used to set reasonable default keepalive options on sockets when registered for a connection with xmpp_conn_set_sockopt_callback() | |
These functions manage a connection object.
A part of those functions is listed under the SSL/TLS specific functionality section.
typedef int(* xmpp_sockopt_callback) (xmpp_conn_t *conn, void *sock) |
The function which will be called when Strophe creates a new socket.
The sock
argument is a pointer that is dependent on the architecture Strophe is compiled for.
For POSIX compatible systems usage shall be:
On Windows usage shall be:
This function will be called for each socket that is created.
examples/bot.c
uses a libstrophe supplied callback function that sets basic keepalive parameters (xmpp_sockopt_cb_keepalive()
).
examples/complex.c
implements a custom function that could be useful for an application.
conn | The Strophe connection object this callback originates from. |
sock | A pointer to the underlying file descriptor. |
xmpp_conn_t * xmpp_conn_new | ( | xmpp_ctx_t * | ctx | ) |
Create a new Strophe connection object.
ctx | a Strophe context object |
xmpp_conn_t * xmpp_conn_clone | ( | xmpp_conn_t * | conn | ) |
Clone a Strophe connection object.
conn | a Strophe connection object |
void xmpp_conn_set_sockopt_callback | ( | xmpp_conn_t * | conn, |
xmpp_sockopt_callback | callback | ||
) |
Register sockopt callback Set function to be called when a new socket is created to allow setting socket options before connection is started.
If the connection is already connected, this callback will be called immediately.
To set options that can only be applied to disconnected sockets, the callback must be registered before connecting.
conn | The Strophe connection object this callback is being registered for |
callback | a xmpp_sockopt_callback callback function that will receive notifications of connection status |
int xmpp_conn_release | ( | xmpp_conn_t * | conn | ) |
Release a Strophe connection object.
Decrement the reference count by one for a connection, freeing the connection object if the count reaches 0.
conn | a Strophe connection object |
const char * xmpp_conn_get_jid | ( | const xmpp_conn_t * | conn | ) |
Get the JID which is or will be bound to the connection.
conn | a Strophe connection object |
const char * xmpp_conn_get_bound_jid | ( | const xmpp_conn_t * | conn | ) |
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.
conn | a Strophe connection object. |
void xmpp_conn_set_jid | ( | xmpp_conn_t * | conn, |
const char * | jid | ||
) |
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 be used after a connection is created. The function will make a copy of the JID string. If the supplied JID is missing the node, SASL ANONYMOUS authentication will be used.
conn | a Strophe connection object |
jid | a full or bare JID |
const char * xmpp_conn_get_pass | ( | const xmpp_conn_t * | conn | ) |
Get the password used for authentication of a connection.
conn | a Strophe connection object |
void xmpp_conn_set_pass | ( | xmpp_conn_t * | conn, |
const char * | pass | ||
) |
Set the password used to authenticate the connection.
If any password was previously set, it will be discarded. The function will make a copy of the password string.
conn | a Strophe connection object |
pass | the password |
xmpp_ctx_t * xmpp_conn_get_context | ( | xmpp_conn_t * | conn | ) |
Get the strophe context that the connection is associated with.
conn | a Strophe connection object |
int xmpp_connect_client | ( | xmpp_conn_t * | conn, |
const char * | altdomain, | ||
unsigned short | altport, | ||
xmpp_conn_handler | callback, | ||
void * | userdata | ||
) |
Initiate a connection to the XMPP 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 callback function. The domain and port to connect to are usually determined by an SRV lookup for the xmpp-client service at the domain specified in the JID. If SRV lookup fails, altdomain and altport will be used instead if specified.
conn | a Strophe connection object |
altdomain | a string with domain to use if SRV lookup fails. If this is NULL, the domain from the JID will be used. |
altport | an integer port number to use if SRV lookup fails. If this is 0, the default port will be assumed. |
callback | a xmpp_conn_handler callback function that will receive notifications of connection status |
userdata | an opaque data pointer that will be passed to the callback |
int xmpp_connect_component | ( | xmpp_conn_t * | conn, |
const char * | server, | ||
unsigned short | port, | ||
xmpp_conn_handler | callback, | ||
void * | userdata | ||
) |
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.
conn | a Strophe connection object |
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. |
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. |
callback | a xmpp_conn_handler callback function that will receive notifications of connection status |
userdata | an opaque data pointer that will be passed to the callback |
int xmpp_connect_raw | ( | xmpp_conn_t * | conn, |
const char * | altdomain, | ||
unsigned short | altport, | ||
xmpp_conn_handler | callback, | ||
void * | userdata | ||
) |
Initiate a raw connection to the XMPP server.
Arguments and behaviour of the function are similar to xmpp_connect_client(), but it skips authentication process. In opposite to xmpp_connect_client() during connection process two events are generated instead of one. User's callback is called with event XMPP_CONN_RAW_CONNECT when the TCP connection with the server is established. At this point user might want to open an XMPP stream with xmpp_conn_open_stream() or establish TLS session with xmpp_conn_tls_start(). Event XMPP_CONN_CONNECT is generated when the XMPP stream is opened successfully and user may send stanzas over the connection.
This function doesn't use password nor node part of a jid. Therefore, the only required configuration is a domain (or full jid) passed via xmpp_conn_set_jid().
int xmpp_conn_open_stream_default | ( | xmpp_conn_t * | conn | ) |
Send the default opening stream tag.
The default tag is the one sent by xmpp_connect_client(). User's connection handler is called with event XMPP_CONN_CONNECT when server replies with its opening tag.
int xmpp_conn_open_stream | ( | xmpp_conn_t * | conn, |
char ** | attributes, | ||
size_t | attributes_len | ||
) |
Send an opening stream tag.
User's connection handler is called with event XMPP_CONN_CONNECT when server replies with its opening tag.
conn | a Strophe connection object |
attributes | Array of strings in format: even index points to an attribute name and odd index points to its value |
attributes_len | Number of elements in the attributes array, it should be number of attributes multiplied by 2 |
int xmpp_conn_tls_start | ( | xmpp_conn_t * | conn | ) |
Start synchronous TLS handshake with the server.
void xmpp_disconnect | ( | xmpp_conn_t * | conn | ) |
Initiate termination of the connection to the XMPP server.
This function starts the disconnection sequence by sending </stream:stream> to the XMPP server. This function will do nothing if the connection state is different from CONNECTING or CONNECTED.
conn | a Strophe connection object |
void xmpp_send_raw_string | ( | xmpp_conn_t * | conn, |
const char * | fmt, | ||
... | |||
) |
Send a raw string to the XMPP server.
This function is a convenience function to send raw string data to the XMPP server. It is used by Strophe to send short messages instead of building up an XML stanza with DOM methods. This should be used with care as it does not validate the data; invalid data may result in immediate stream termination by the XMPP server.
conn | a Strophe connection object |
fmt | a printf-style format string followed by a variable list of arguments to format |
void xmpp_send_raw | ( | xmpp_conn_t * | conn, |
const char * | data, | ||
size_t | len | ||
) |
Send raw bytes to the XMPP server.
This function is a convenience function to send raw bytes to the XMPP server. It is used primarily by xmpp_send_raw_string(). This function should be used with care as it does not validate the bytes and invalid data may result in stream termination by the XMPP server.
conn | a Strophe connection object |
data | a buffer of raw bytes |
len | the length of the data in the buffer |
void xmpp_send | ( | xmpp_conn_t * | conn, |
xmpp_stanza_t * | stanza | ||
) |
Send an XML stanza to the XMPP server.
This is the main way to send data to the XMPP server. The function will terminate without action if the connection state is not CONNECTED.
conn | a Strophe connection object |
stanza | a Strophe stanza object |
long xmpp_conn_get_flags | ( | const xmpp_conn_t * | conn | ) |
Return applied flags for the connection.
conn | a Strophe connection object |
int xmpp_conn_set_flags | ( | xmpp_conn_t * | conn, |
long | flags | ||
) |
Set flags for the connection.
This function applies set flags and resets unset ones. Default connection configuration is all flags unset. Flags can be applied only for a connection in disconnected state. All unsupported flags are ignored. If a flag is unset after successful set operation then the flag is not supported by current version.
Supported flags are:
conn | a Strophe connection object |
flags | ORed connection flags |
int xmpp_conn_is_secured | ( | xmpp_conn_t * | conn | ) |
Return whether TLS session is established or not.
int xmpp_conn_is_connecting | ( | xmpp_conn_t * | conn | ) |
int xmpp_conn_is_connected | ( | xmpp_conn_t * | conn | ) |
int xmpp_conn_is_disconnected | ( | xmpp_conn_t * | conn | ) |
xmpp_sm_state_t * xmpp_conn_get_sm_state | ( | xmpp_conn_t * | conn | ) |
This returns the Stream Management state of a connection object after it has been disconnected.
One can then initialise a fresh connection object and set this Stream Management state by calling xmpp_conn_set_sm_state
In case one wants to dispose of the state w/o setting it into a fresh connection object, one can call xmpp_free_sm_state
After calling this function to retrieve the state, only call one of the other two.
conn | a Strophe connection object |
int xmpp_conn_set_sm_state | ( | xmpp_conn_t * | conn, |
xmpp_sm_state_t * | sm_state | ||
) |
conn | a Strophe connection object |
sm_state | A Stream Management state returned from a call to xmpp_conn_get_sm_state() |
void xmpp_free_sm_state | ( | xmpp_sm_state_t * | sm_state | ) |
c.f.
xmpp_conn_get_sm_state for usage documentation
sm_state | A Stream Management state returned from a call to xmpp_conn_get_sm_state() |
int xmpp_conn_send_queue_len | ( | const xmpp_conn_t * | conn | ) |
char * xmpp_conn_send_queue_drop_element | ( | xmpp_conn_t * | conn, |
xmpp_queue_element_t | which | ||
) |
Drop an element of the send queue.
This can be used to manage the send queue in case a server isn't fast enough in processing the elements you're trying to send or your outgoing bandwidth isn't fast enough to transfer everything you want to send out.
conn | a Strophe connection object |
which | the element that shall be removed |
int xmpp_sockopt_cb_keepalive | ( | xmpp_conn_t * | conn, |
void * | socket | ||
) |
Example sockopt callback function An example function that can be used to set reasonable default keepalive options on sockets when registered for a connection with xmpp_conn_set_sockopt_callback()
conn | a Strophe connection object |
socket | pointer to a socket descriptor |
socket
parameter