Strophe 0.12
XMPP client library
|
Functions | |
xmpp_stanza_t * | xmpp_stanza_new (xmpp_ctx_t *ctx) |
Create a stanza object. More... | |
xmpp_stanza_t * | xmpp_stanza_clone (xmpp_stanza_t *stanza) |
Clone a stanza object. More... | |
xmpp_stanza_t * | xmpp_stanza_copy (const xmpp_stanza_t *stanza) |
Copy a stanza and its children. More... | |
int | xmpp_stanza_release (xmpp_stanza_t *stanza) |
Release a stanza object and all of its children. More... | |
xmpp_ctx_t * | xmpp_stanza_get_context (const xmpp_stanza_t *stanza) |
Get the strophe context that the stanza is associated with. More... | |
int | xmpp_stanza_is_text (xmpp_stanza_t *stanza) |
Determine if a stanza is a text node. More... | |
int | xmpp_stanza_is_tag (xmpp_stanza_t *stanza) |
Determine if a stanza is a tag node. More... | |
int | xmpp_stanza_to_text (xmpp_stanza_t *stanza, char **buf, size_t *buflen) |
Render a stanza object to text. More... | |
int | xmpp_stanza_set_name (xmpp_stanza_t *stanza, const char *name) |
Set the name of a stanza. More... | |
const char * | xmpp_stanza_get_name (xmpp_stanza_t *stanza) |
Get the stanza name. More... | |
int | xmpp_stanza_get_attribute_count (xmpp_stanza_t *stanza) |
Count the attributes in a stanza object. More... | |
int | xmpp_stanza_get_attributes (xmpp_stanza_t *stanza, const char **attr, int attrlen) |
Get all attributes for a stanza object. More... | |
int | xmpp_stanza_set_attribute (xmpp_stanza_t *stanza, const char *key, const char *value) |
Set an attribute for a stanza object. More... | |
int | xmpp_stanza_set_ns (xmpp_stanza_t *stanza, const char *ns) |
Set the stanza namespace. More... | |
int | xmpp_stanza_add_child_ex (xmpp_stanza_t *stanza, xmpp_stanza_t *child, int do_clone) |
Add a child stanza to a stanza object. More... | |
int | xmpp_stanza_add_child (xmpp_stanza_t *stanza, xmpp_stanza_t *child) |
Add a child stanza to a stanza object. More... | |
int | xmpp_stanza_set_text (xmpp_stanza_t *stanza, const char *text) |
Set the text data for a text stanza. More... | |
int | xmpp_stanza_set_text_with_size (xmpp_stanza_t *stanza, const char *text, size_t size) |
Set the text data for a text stanza. More... | |
const char * | xmpp_stanza_get_id (xmpp_stanza_t *stanza) |
Get the 'id' attribute of the stanza object. More... | |
const char * | xmpp_stanza_get_ns (xmpp_stanza_t *stanza) |
Get the namespace attribute of the stanza object. More... | |
const char * | xmpp_stanza_get_type (xmpp_stanza_t *stanza) |
Get the 'type' attribute of the stanza object. More... | |
const char * | xmpp_stanza_get_to (xmpp_stanza_t *stanza) |
Get the 'to' attribute of the stanza object. More... | |
const char * | xmpp_stanza_get_from (xmpp_stanza_t *stanza) |
Get the 'from' attribute of the stanza object. More... | |
xmpp_stanza_t * | xmpp_stanza_get_child_by_path (xmpp_stanza_t *stanza,...) |
Get the first child of stanza following a path-like list of names. More... | |
xmpp_stanza_t * | xmpp_stanza_get_child_by_name (xmpp_stanza_t *stanza, const char *name) |
Get the first child of stanza with name. More... | |
xmpp_stanza_t * | xmpp_stanza_get_child_by_ns (xmpp_stanza_t *stanza, const char *ns) |
Get the first child of a stanza with a given namespace. More... | |
xmpp_stanza_t * | xmpp_stanza_get_child_by_name_and_ns (xmpp_stanza_t *stanza, const char *name, const char *ns) |
Get the first child of stanza with name and a given namespace. More... | |
xmpp_stanza_t * | xmpp_stanza_get_children (xmpp_stanza_t *stanza) |
Get the list of children. More... | |
xmpp_stanza_t * | xmpp_stanza_get_next (xmpp_stanza_t *stanza) |
Get the next sibling of a stanza. More... | |
char * | xmpp_stanza_get_text (xmpp_stanza_t *stanza) |
Get the text data for a text stanza. More... | |
const char * | xmpp_stanza_get_text_ptr (xmpp_stanza_t *stanza) |
Get the text data pointer for a text stanza. More... | |
int | xmpp_stanza_set_id (xmpp_stanza_t *stanza, const char *id) |
Set the 'id' attribute of a stanza. More... | |
int | xmpp_stanza_set_type (xmpp_stanza_t *stanza, const char *type) |
Set the 'type' attribute of a stanza. More... | |
int | xmpp_stanza_set_to (xmpp_stanza_t *stanza, const char *to) |
Set the 'to' attribute of a stanza. More... | |
int | xmpp_stanza_set_from (xmpp_stanza_t *stanza, const char *from) |
Set the 'from' attribute of a stanza. More... | |
const char * | xmpp_stanza_get_attribute (xmpp_stanza_t *stanza, const char *name) |
Get an attribute from a stanza. More... | |
int | xmpp_stanza_del_attribute (xmpp_stanza_t *stanza, const char *name) |
Delete an attribute from a stanza. More... | |
xmpp_stanza_t * | xmpp_stanza_reply (xmpp_stanza_t *stanza) |
Create a stanza object in reply to another. More... | |
xmpp_stanza_t * | xmpp_stanza_reply_error (xmpp_stanza_t *stanza, const char *error_type, const char *condition, const char *text) |
Create an error stanza in reply to the provided stanza. More... | |
xmpp_stanza_t * | xmpp_message_new (xmpp_ctx_t *ctx, const char *type, const char *to, const char *id) |
Create a <message/> stanza object with given attributes. More... | |
char * | xmpp_message_get_body (xmpp_stanza_t *msg) |
Get text from <body/> child element. More... | |
int | xmpp_message_set_body (xmpp_stanza_t *msg, const char *text) |
Add <body/> child element to a <message/> stanza with the given text. More... | |
xmpp_stanza_t * | xmpp_iq_new (xmpp_ctx_t *ctx, const char *type, const char *id) |
Create an <iq/> stanza object with given attributes. More... | |
xmpp_stanza_t * | xmpp_presence_new (xmpp_ctx_t *ctx) |
Create a <presence/> stanza object. More... | |
xmpp_stanza_t * | xmpp_error_new (xmpp_ctx_t *ctx, xmpp_error_type_t type, const char *text) |
Create an <stream:error/> stanza object with given type and error text. More... | |
xmpp_stanza_t * | xmpp_stanza_new_from_string (xmpp_ctx_t *ctx, const char *str) |
Create a stanza object from the string. More... | |
xmpp_stanza_t * xmpp_stanza_new | ( | xmpp_ctx_t * | ctx | ) |
Create a stanza object.
This function allocates and initializes a blank stanza object. The stanza will have a reference count of one, so the caller does not need to clone it.
ctx | a Strophe context object |
xmpp_stanza_t * xmpp_stanza_clone | ( | xmpp_stanza_t * | stanza | ) |
Clone a stanza object.
This function increments the reference count of the stanza object.
stanza | a Strophe stanza object |
xmpp_stanza_t * xmpp_stanza_copy | ( | const xmpp_stanza_t * | stanza | ) |
Copy a stanza and its children.
This function copies a stanza along with all its children and returns the new stanza and children with a reference count of 1. The returned stanza will have no parent and no siblings. This function is useful for extracting a child stanza for inclusion in another tree.
stanza | a Strophe stanza object |
int xmpp_stanza_release | ( | xmpp_stanza_t * | stanza | ) |
Release a stanza object and all of its children.
This function releases a stanza object and potentially all of its children, which may cause the object(s) to be freed.
stanza | a Strophe stanza object |
xmpp_ctx_t * xmpp_stanza_get_context | ( | const xmpp_stanza_t * | stanza | ) |
Get the strophe context that the stanza is associated with.
stanza | a Strophe stanza object |
int xmpp_stanza_is_text | ( | xmpp_stanza_t * | stanza | ) |
Determine if a stanza is a text node.
stanza | a Strophe stanza object |
int xmpp_stanza_is_tag | ( | xmpp_stanza_t * | stanza | ) |
Determine if a stanza is a tag node.
stanza | a Strophe stanza object |
int xmpp_stanza_to_text | ( | xmpp_stanza_t * | stanza, |
char ** | buf, | ||
size_t * | buflen | ||
) |
Render a stanza object to text.
This function renders a given stanza object, along with its children, to text. The text is returned in an allocated, null-terminated buffer. It starts by allocating a 1024 byte buffer and reallocates more memory if that is not large enough.
stanza | a Strophe stanza object |
buf | a reference to a string pointer |
buflen | a reference to a size_t |
int xmpp_stanza_set_name | ( | xmpp_stanza_t * | stanza, |
const char * | name | ||
) |
Set the name of a stanza.
stanza | a Strophe stanza object |
name | a string with the name of the stanza |
const char * xmpp_stanza_get_name | ( | xmpp_stanza_t * | stanza | ) |
Get the stanza name.
This function returns a pointer to the stanza name. If the caller needs to store this data, it must make a copy.
stanza | a Strophe stanza object |
int xmpp_stanza_get_attribute_count | ( | xmpp_stanza_t * | stanza | ) |
Count the attributes in a stanza object.
stanza | a Strophe stanza object |
int xmpp_stanza_get_attributes | ( | xmpp_stanza_t * | stanza, |
const char ** | attr, | ||
int | attrlen | ||
) |
Get all attributes for a stanza object.
This function populates the array with attributes from the stanza. The attr array will be in the format: attr[i] = attribute name, attr[i+1] = attribute value.
stanza | a Strophe stanza object |
attr | the string array to populate |
attrlen | the size of the array |
int xmpp_stanza_set_attribute | ( | xmpp_stanza_t * | stanza, |
const char * | key, | ||
const char * | value | ||
) |
Set an attribute for a stanza object.
stanza | a Strophe stanza object |
key | a string with the attribute name |
value | a string with the attribute value |
int xmpp_stanza_set_ns | ( | xmpp_stanza_t * | stanza, |
const char * | ns | ||
) |
Set the stanza namespace.
This is a convenience function equivalent to calling: xmpp_stanza_set_attribute(stanza, "xmlns", ns);
stanza | a Strophe stanza object |
ns | a string with the namespace |
int xmpp_stanza_add_child_ex | ( | xmpp_stanza_t * | stanza, |
xmpp_stanza_t * | child, | ||
int | do_clone | ||
) |
Add a child stanza to a stanza object.
If do_clone is TRUE, user keeps reference to the child stanza and must call xmpp_stanza_release() to release the reference. If do_clone is FALSE, user transfers ownership and must not neither call xmpp_stanza_release() for the child stanza nor use it.
stanza | a Strophe stanza object |
child | the child stanza object |
do_clone | TRUE to increase ref count of child (default for xmpp_stanza_add_child()) |
int xmpp_stanza_add_child | ( | xmpp_stanza_t * | stanza, |
xmpp_stanza_t * | child | ||
) |
Add a child stanza to a stanza object.
This function clones the child and appends it to the stanza object's children.
stanza | a Strophe stanza object |
child | the child stanza object |
int xmpp_stanza_set_text | ( | xmpp_stanza_t * | stanza, |
const char * | text | ||
) |
Set the text data for a text stanza.
This function copies the text given and sets the stanza object's text to it. Attempting to use this function on a stanza that has a name will fail with XMPP_EINVOP. This function takes the text as a null-terminated string.
stanza | a Strophe stanza object |
text | a string with the text |
int xmpp_stanza_set_text_with_size | ( | xmpp_stanza_t * | stanza, |
const char * | text, | ||
size_t | size | ||
) |
Set the text data for a text stanza.
This function copies the text given and sets the stanza object's text to it. Attempting to use this function on a stanza that has a name will fail with XMPP_EINVOP. This function takes the text as buffer and a length as opposed to a null-terminated string.
stanza | a Strophe stanza object |
text | a buffer with the text |
size | the length of the text |
const char * xmpp_stanza_get_id | ( | xmpp_stanza_t * | stanza | ) |
Get the 'id' attribute of the stanza object.
This is a convenience function equivalent to: xmpp_stanza_get_attribute(stanza, "id");
stanza | a Strophe stanza object |
const char * xmpp_stanza_get_ns | ( | xmpp_stanza_t * | stanza | ) |
Get the namespace attribute of the stanza object.
This is a convenience function equivalent to: xmpp_stanza_get_attribute(stanza, "xmlns");
stanza | a Strophe stanza object |
const char * xmpp_stanza_get_type | ( | xmpp_stanza_t * | stanza | ) |
Get the 'type' attribute of the stanza object.
This is a convenience function equivalent to: xmpp_stanza_get_attribute(stanza, "type");
stanza | a Strophe stanza object |
const char * xmpp_stanza_get_to | ( | xmpp_stanza_t * | stanza | ) |
Get the 'to' attribute of the stanza object.
This is a convenience function equivalent to: xmpp_stanza_get_attribute(stanza, "to");
stanza | a Strophe stanza object |
const char * xmpp_stanza_get_from | ( | xmpp_stanza_t * | stanza | ) |
Get the 'from' attribute of the stanza object.
This is a convenience function equivalent to: xmpp_stanza_get_attribute(stanza, "from");
stanza | a Strophe stanza object |
xmpp_stanza_t * xmpp_stanza_get_child_by_path | ( | xmpp_stanza_t * | stanza, |
... | |||
) |
Get the first child of stanza following a path-like list of names.
This function searches the children and their children that match the given path.
The Syntax to pass namespaces is inspired by the XPATH way of passing attributes.
The namespace syntax only supports single quotes ‘’`.
The XMPP_STANZA_NAME_IN_NS macro is provided as a helper for names in namespaces.
stanza | a Strophe stanza object |
... | a var-args list that must be terminated by a NULL entry |
xmpp_stanza_t * xmpp_stanza_get_child_by_name | ( | xmpp_stanza_t * | stanza, |
const char * | name | ||
) |
Get the first child of stanza with name.
This function searches all the immediate children of stanza for a child stanza that matches the name. The first matching child is returned.
stanza | a Strophe stanza object |
name | a string with the name to match |
xmpp_stanza_t * xmpp_stanza_get_child_by_ns | ( | xmpp_stanza_t * | stanza, |
const char * | ns | ||
) |
Get the first child of a stanza with a given namespace.
This function searches all the immediate children of a stanza for a child stanza that matches the namespace provided. The first matching child is returned.
stanza | a Strophe stanza object |
ns | a string with the namespace to match |
xmpp_stanza_t * xmpp_stanza_get_child_by_name_and_ns | ( | xmpp_stanza_t * | stanza, |
const char * | name, | ||
const char * | ns | ||
) |
Get the first child of stanza with name and a given namespace.
This function searches all the immediate children of stanza for a child stanza that matches the name and namespace provided. The first matching child is returned.
stanza | a Strophe stanza object |
name | a string with the name to match |
ns | a string with the namespace to match |
xmpp_stanza_t * xmpp_stanza_get_children | ( | xmpp_stanza_t * | stanza | ) |
Get the list of children.
This function returns the first child of the stanza object. The rest of the children can be obtained by calling xmpp_stanza_get_next() to iterate over the siblings.
stanza | a Strophe stanza object |
xmpp_stanza_t * xmpp_stanza_get_next | ( | xmpp_stanza_t * | stanza | ) |
Get the next sibling of a stanza.
stanza | a Strophe stanza object |
char * xmpp_stanza_get_text | ( | xmpp_stanza_t * | stanza | ) |
Get the text data for a text stanza.
This function copies the text data from a stanza and returns the new allocated string. The caller is responsible for freeing this string with xmpp_free().
stanza | a Strophe stanza object |
const char * xmpp_stanza_get_text_ptr | ( | xmpp_stanza_t * | stanza | ) |
Get the text data pointer for a text stanza.
This function copies returns the raw pointer to the text data in the stanza. This should only be used in very special cases where the caller needs to translate the datatype as this will save a double allocation. The caller should not hold onto this pointer, and is responsible for allocating a copy if it needs one.
stanza | a Strophe stanza object |
int xmpp_stanza_set_id | ( | xmpp_stanza_t * | stanza, |
const char * | id | ||
) |
Set the 'id' attribute of a stanza.
This is a convenience function for: xmpp_stanza_set_attribute(stanza, 'id', id);
stanza | a Strophe stanza object |
id | a string containing the 'id' value |
int xmpp_stanza_set_type | ( | xmpp_stanza_t * | stanza, |
const char * | type | ||
) |
Set the 'type' attribute of a stanza.
This is a convenience function for: xmpp_stanza_set_attribute(stanza, 'type', type);
stanza | a Strophe stanza object |
type | a string containing the 'type' value |
int xmpp_stanza_set_to | ( | xmpp_stanza_t * | stanza, |
const char * | to | ||
) |
Set the 'to' attribute of a stanza.
This is a convenience function for: xmpp_stanza_set_attribute(stanza, 'to', to);
stanza | a Strophe stanza object |
to | a string containing the 'to' value |
int xmpp_stanza_set_from | ( | xmpp_stanza_t * | stanza, |
const char * | from | ||
) |
Set the 'from' attribute of a stanza.
This is a convenience function for: xmpp_stanza_set_attribute(stanza, 'from', from);
stanza | a Strophe stanza object |
from | a string containing the 'from' value |
const char * xmpp_stanza_get_attribute | ( | xmpp_stanza_t * | stanza, |
const char * | name | ||
) |
Get an attribute from a stanza.
This function returns a pointer to the attribute value. If the caller wishes to save this value it must make its own copy.
stanza | a Strophe stanza object |
name | a string containing attribute name |
int xmpp_stanza_del_attribute | ( | xmpp_stanza_t * | stanza, |
const char * | name | ||
) |
Delete an attribute from a stanza.
stanza | a Strophe stanza object |
name | a string containing attribute name |
xmpp_stanza_t * xmpp_stanza_reply | ( | xmpp_stanza_t * | stanza | ) |
Create a stanza object in reply to another.
This function makes a copy of a stanza object with the attribute "to" set its original "from". The stanza will have a reference count of one, so the caller does not need to clone it.
stanza | a Strophe stanza object |
xmpp_stanza_t * xmpp_stanza_reply_error | ( | xmpp_stanza_t * | stanza, |
const char * | error_type, | ||
const char * | condition, | ||
const char * | text | ||
) |
Create an error stanza in reply to the provided stanza.
Check https://tools.ietf.org/html/rfc6120#section-8.3 for details.
stanza | a Strophe stanza object |
error_type | type attribute in the <error/> child element |
condition | the defined-condition (e.g. "item-not-found") |
text | optional description, may be NULL |
xmpp_stanza_t * xmpp_message_new | ( | xmpp_ctx_t * | ctx, |
const char * | type, | ||
const char * | to, | ||
const char * | id | ||
) |
Create a <message/>
stanza object with given attributes.
Attributes are optional and may be NULL.
ctx | a Strophe context object |
type | attribute 'type' |
to | attribute 'to' |
id | attribute 'id' |
char * xmpp_message_get_body | ( | xmpp_stanza_t * | msg | ) |
Get text from <body/>
child element.
This function returns new allocated string. The caller is responsible for freeing this string with xmpp_free().
msg | well formed <message/> stanza |
<body/>
element or memory allocation error) int xmpp_message_set_body | ( | xmpp_stanza_t * | msg, |
const char * | text | ||
) |
Add <body/>
child element to a <message/>
stanza with the given text.
msg | a <message> stanza object without <body/> child element. |
text | The text that shall be placed in the body. |
xmpp_stanza_t * xmpp_iq_new | ( | xmpp_ctx_t * | ctx, |
const char * | type, | ||
const char * | id | ||
) |
Create an <iq/>
stanza object with given attributes.
Attributes are optional and may be NULL.
ctx | a Strophe context object |
type | attribute 'type' |
id | attribute 'id' |
xmpp_stanza_t * xmpp_presence_new | ( | xmpp_ctx_t * | ctx | ) |
Create a <presence/>
stanza object.
ctx | a Strophe context object |
xmpp_stanza_t * xmpp_error_new | ( | xmpp_ctx_t * | ctx, |
xmpp_error_type_t | type, | ||
const char * | text | ||
) |
Create an <stream:error/> stanza object with given type and error text.
The error text is optional and may be NULL.
ctx | a Strophe context object |
type | enum of strophe_error_type_t |
text | content of a 'text' |
xmpp_stanza_t * xmpp_stanza_new_from_string | ( | xmpp_ctx_t * | ctx, |
const char * | str | ||
) |
Create a stanza object from the string.
This function allocates and initializes a stanza object which represents stanza located in the string. The stanza will have a reference count of one, so the caller does not need to clone it.
ctx | a Strophe context object |
str | stanza in NULL terminated string representation |