Strophe 0.13 XMPP client library

Macros | Functions
conn.c File Reference

Connection management. More...

## Macros
#define | DEFAULT_SEND_QUEUE_MAX 64
| The default maximum send queue size.
#define | DISCONNECT_TIMEOUT 2000 /* 2 seconds */
| The time to wait (in milliseconds) for graceful disconnection to complete before the connection is reset.
#define | CONNECT_TIMEOUT 5000 /* 5 seconds */
| The time to wait (in milliseconds) for a connection attempt to succeed or error.
#define | KEEPALIVE_TIMEOUT 60
| The time (in seconds) the connection needs to remain idle before TCP starts sending keepalive probes, if the socket option SO_KEEPALIVE has been set on this socket.
#define | KEEPALIVE_INTERVAL 30
| The time (in seconds) between individual keepalive probes.
#define | KEEPALIVE_COUNT 3
| The maximum number of keepalive probes TCP should send before dropping the connection.

## Functions
static int | _is_connected (xmpp_conn_t *conn, xmpp_send_queue_owner_t owner)
static int | _disconnect_cleanup (xmpp_conn_t *conn, void *userdata)
static void | _reset_sm_state_for_reconnect (xmpp_conn_t *conn)
static char * | _conn_build_stream_tag (xmpp_conn_t *conn, char **attributes, size_t attributes_len)
static int | _conn_open_stream_with_attributes (xmpp_conn_t *conn, char **attributes, size_t attributes_len)
static void | _conn_attributes_new (xmpp_conn_t *conn, char **attrs, char ***attributes, size_t *attributes_len)
static void | _conn_attributes_destroy (xmpp_conn_t *conn, char **attributes, size_t attributes_len)
static void | _handle_stream_start (char *name, char **attrs, void *userdata)
static void | _handle_stream_end (char *name, void *userdata)
static void | _handle_stream_stanza (xmpp_stanza_t *stanza, void *userdata)
static void | _conn_sm_handle_stanza (xmpp_conn_t *const conn, xmpp_stanza_t *stanza)
static unsigned short | _conn_default_port (xmpp_conn_t *conn, xmpp_conn_type_t type)
static void | _conn_reset (xmpp_conn_t *conn)
static int | _conn_connect (xmpp_conn_t *conn, const char *domain, xmpp_conn_type_t type, xmpp_conn_handler callback, void *userdata)
static void | _send_valist (xmpp_conn_t *conn, const char *fmt, va_list ap, xmpp_send_queue_owner_t owner)
static int | _send_raw (xmpp_conn_t *conn, char *data, size_t len, xmpp_send_queue_owner_t owner, void *userdata)
void | xmpp_send_error (xmpp_conn_t *conn, xmpp_error_type_t type, char *text)
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.
void | xmpp_conn_set_certfail_handler (xmpp_conn_t *const conn, xmpp_certfail_handler hndl)
| Set the Handler function which will be called when the TLS stack can't verify the CA of the server we're trying to connect to.
void | xmpp_conn_set_cafile (xmpp_conn_t *const conn, const char *path)
| Set the CAfile.
void | xmpp_conn_set_capath (xmpp_conn_t *const conn, const char *path)
| Set the CApath.
xmpp_tlscert_t * | xmpp_conn_get_peer_cert (xmpp_conn_t *const conn)
| Retrieve the peer certificate.
void | xmpp_conn_set_password_callback (xmpp_conn_t *conn, xmpp_password_callback cb, void *userdata)
| Set the Callback function which will be called when the TLS stack can't decrypt a password protected key file.
void | xmpp_conn_set_password_retries (xmpp_conn_t *conn, unsigned int retries)
| Set the number of retry attempts to decrypt a private key file.
const char * | xmpp_conn_get_keyfile (const xmpp_conn_t *conn)
| Retrieve the path of the key file that shall be unlocked.
void | xmpp_conn_set_client_cert (xmpp_conn_t *const conn, const char *const cert, const char *const key)
| Set the Client Certificate and Private Key or PKCS#12 encoded file that will be bound to the connection.
unsigned int | xmpp_conn_cert_xmppaddr_num (xmpp_conn_t *const conn)
| Get the number of xmppAddr entries in the client certificate.
char * | xmpp_conn_cert_xmppaddr (xmpp_conn_t *const conn, unsigned int n)
| Get a specific xmppAddr entry.
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.
void | conn_established (xmpp_conn_t *conn)
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 | conn_disconnect_clean (xmpp_conn_t *conn)
| Cleanly disconnect the connection.
void | conn_disconnect (xmpp_conn_t *conn)
| Disconnect from the XMPP server.
void | conn_prepare_reset (xmpp_conn_t *conn, xmpp_open_handler handler)
void | conn_parser_reset (xmpp_conn_t *conn)
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.
void | conn_open_stream (xmpp_conn_t *conn)
| Send the opening <stream:stream> tag to the server.
int | conn_interface_write (struct conn_interface *intf, const void *buff, size_t len)
int | conn_int_nop (struct conn_interface *intf)
int | conn_tls_start (xmpp_conn_t *conn)
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 | reset_sm_state (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)
static char * | _drop_send_queue_element (xmpp_conn_t *conn, xmpp_send_queue_t *e)
char * | xmpp_conn_send_queue_drop_element (xmpp_conn_t *conn, xmpp_queue_element_t which)
| Drop an element of the send queue.
static void | _log_open_tag (xmpp_conn_t *conn, char **attrs)
static char * | _get_stream_attribute (char **attrs, char *name)
char * | queue_element_free (xmpp_ctx_t *ctx, xmpp_send_queue_t *e)
void | send_raw (xmpp_conn_t *conn, const char *data, size_t len, xmpp_send_queue_owner_t owner, void *userdata)
void | send_raw_string (xmpp_conn_t *conn, const char *fmt,...)
void | send_stanza (xmpp_conn_t *conn, xmpp_stanza_t *stanza, xmpp_send_queue_owner_t owner)
void | add_queue_back (xmpp_queue_t *queue, xmpp_send_queue_t *item)
xmpp_send_queue_t * | peek_queue_front (xmpp_queue_t *queue)
xmpp_send_queue_t * | pop_queue_front (xmpp_queue_t *queue)

## Detailed Description

Connection management.

## Macro Definition Documentation

## ◆ DEFAULT_SEND_QUEUE_MAX

#define DEFAULT_SEND_QUEUE_MAX 64

The default maximum send queue size.

This is currently unused.

## ◆ DISCONNECT_TIMEOUT

#define DISCONNECT_TIMEOUT 2000 /* 2 seconds */

The time to wait (in milliseconds) for graceful disconnection to complete before the connection is reset.

The default is 2 seconds.

## ◆ CONNECT_TIMEOUT

#define CONNECT_TIMEOUT 5000 /* 5 seconds */

The time to wait (in milliseconds) for a connection attempt to succeed or error.

The default is 5 seconds.

## ◆ KEEPALIVE_TIMEOUT

#define KEEPALIVE_TIMEOUT 60

The time (in seconds) the connection needs to remain idle before TCP starts sending keepalive probes, if the socket option SO_KEEPALIVE has been set on this socket.

c.f. `TCP_KEEPIDLE` in `man 7 tcp` for linux, FreeBSD and some others or `TCP_KEEPALIVE` on MacOS.

## ◆ KEEPALIVE_INTERVAL

#define KEEPALIVE_INTERVAL 30

The time (in seconds) between individual keepalive probes.

c.f. `TCP_KEEPINTVL` in `man 7 tcp`

## ◆ KEEPALIVE_COUNT

#define KEEPALIVE_COUNT 3

The maximum number of keepalive probes TCP should send before dropping the connection.

c.f. `TCP_KEEPCNT` in `man 7 tcp`

## Function Documentation

## ◆ _is_connected()

static int _is_connected | ( | xmpp_conn_t * | conn,
|  | xmpp_send_queue_owner_t | owner )
| static

## ◆ _disconnect_cleanup()

static int _disconnect_cleanup | ( | xmpp_conn_t * | conn,
|  | void * | userdata )
| static

## ◆ _reset_sm_state_for_reconnect()

static void _reset_sm_state_for_reconnect | ( | xmpp_conn_t * | conn | ) |
| static

## ◆ _conn_build_stream_tag()

static char * _conn_build_stream_tag | ( | xmpp_conn_t * | conn,
|  | char ** | attributes,
|  | size_t | attributes_len )
| static

## ◆ _conn_open_stream_with_attributes()

static int _conn_open_stream_with_attributes | ( | xmpp_conn_t * | conn,
|  | char ** | attributes,
|  | size_t | attributes_len )
| static

## ◆ _conn_attributes_new()

static void _conn_attributes_new | ( | xmpp_conn_t * | conn,
|  | char ** | attrs,
|  | char *** | attributes,
|  | size_t * | attributes_len )
| static

## ◆ _conn_attributes_destroy()

static void _conn_attributes_destroy | ( | xmpp_conn_t * | conn,
|  | char ** | attributes,
|  | size_t | attributes_len )
| static

## ◆ _handle_stream_start()

static void _handle_stream_start | ( | char * | name,
|  | char ** | attrs,
|  | void * | userdata )
| static

## ◆ _handle_stream_end()

static void _handle_stream_end | ( | char * | name,
|  | void * | userdata )
| static

## ◆ _handle_stream_stanza()

static void _handle_stream_stanza | ( | xmpp_stanza_t * | stanza,
|  | void * | userdata )
| static

## ◆ _conn_sm_handle_stanza()

static void _conn_sm_handle_stanza | ( | xmpp_conn_t *const | conn,
|  | xmpp_stanza_t * | stanza )
| static

## ◆ _conn_default_port()

static unsigned short _conn_default_port | ( | xmpp_conn_t * | conn,
|  | xmpp_conn_type_t | type )
| static

## ◆ _conn_reset()

static void _conn_reset | ( | xmpp_conn_t * | conn | ) |
| static

## ◆ _conn_connect()

static int _conn_connect | ( | xmpp_conn_t * | conn,
|  | const char * | domain,
|  | xmpp_conn_type_t | type,
|  | xmpp_conn_handler | callback,
|  | void * | userdata )
| static

## ◆ _send_valist()

static void _send_valist | ( | xmpp_conn_t * | conn,
|  | const char * | fmt,
|  | va_list | ap,
|  | xmpp_send_queue_owner_t | owner )
| static

## ◆ _send_raw()

static int _send_raw | ( | xmpp_conn_t * | conn,
|  | char * | data,
|  | size_t | len,
|  | xmpp_send_queue_owner_t | owner,
|  | void * | userdata )
| static

## ◆ xmpp_send_error()

void xmpp_send_error | ( | xmpp_conn_t * | conn,
|  | xmpp_error_type_t | type,
|  | char * | text )

## ◆ conn_established()

void conn_established | ( | xmpp_conn_t * | conn | ) |

## ◆ conn_disconnect_clean()

void conn_disconnect_clean | ( | xmpp_conn_t * | conn | ) |

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.

Parameters

  conn | a Strophe connection object

## ◆ conn_disconnect()

void conn_disconnect | ( | xmpp_conn_t * | conn | ) |

Disconnect from the XMPP server.

This function immediately disconnects from the XMPP server, and should not be used outside of the Strophe library.

Parameters

  conn | a Strophe connection object

## ◆ conn_prepare_reset()

void conn_prepare_reset | ( | xmpp_conn_t * | conn,
|  | xmpp_open_handler | handler )

## ◆ conn_parser_reset()

void conn_parser_reset | ( | xmpp_conn_t * | conn | ) |

## ◆ conn_open_stream()

void conn_open_stream | ( | xmpp_conn_t * | conn | ) |

Send the opening <stream:stream> tag to the server.

This function is used by Strophe to begin an XMPP stream. It should not be used outside of the library.

Parameters

  conn | a Strophe connection object

## ◆ conn_interface_write()

int conn_interface_write | ( | struct conn_interface * | intf,
|  | const void * | buff,
|  | size_t | len )

## ◆ conn_int_nop()

int conn_int_nop | ( | struct conn_interface * | intf | ) |

## ◆ conn_tls_start()

int conn_tls_start | ( | xmpp_conn_t * | conn | ) |

## ◆ reset_sm_state()

void reset_sm_state | ( | xmpp_sm_state_t * | sm_state | ) |

## ◆ _drop_send_queue_element()

static char * _drop_send_queue_element | ( | xmpp_conn_t * | conn,
|  | xmpp_send_queue_t * | e )
| static

## ◆ _log_open_tag()

static void _log_open_tag | ( | xmpp_conn_t * | conn,
|  | char ** | attrs )
| static

## ◆ _get_stream_attribute()

static char * _get_stream_attribute | ( | char ** | attrs,
|  | char * | name )
| static

## ◆ queue_element_free()

char * queue_element_free | ( | xmpp_ctx_t * | ctx,
|  | xmpp_send_queue_t * | e )

## ◆ send_raw()

void send_raw | ( | xmpp_conn_t * | conn,
|  | const char * | data,
|  | size_t | len,
|  | xmpp_send_queue_owner_t | owner,
|  | void * | userdata )

## ◆ send_raw_string()

void send_raw_string | ( | xmpp_conn_t * | conn,
|  | const char * | fmt,
|  |  | ... )

## ◆ send_stanza()

void send_stanza | ( | xmpp_conn_t * | conn,
|  | xmpp_stanza_t * | stanza,
|  | xmpp_send_queue_owner_t | owner )

## ◆ add_queue_back()

void add_queue_back | ( | xmpp_queue_t * | queue,
|  | xmpp_send_queue_t * | item )

## ◆ peek_queue_front()

xmpp_send_queue_t * peek_queue_front | ( | xmpp_queue_t * | queue | ) |

## ◆ pop_queue_front()

xmpp_send_queue_t * pop_queue_front | ( | xmpp_queue_t * | queue | ) |