Implements helpers for to and from attributes
xmpp_stanza_{get,set}_{from,to}
This commit is contained in:
committed by
Dmitry Podgorny
parent
64d65b3aed
commit
90a595f8ef
78
src/stanza.c
78
src/stanza.c
@@ -737,6 +737,48 @@ char *xmpp_stanza_get_type(xmpp_stanza_t * const stanza)
|
|||||||
return (char *)hash_get(stanza->attributes, "type");
|
return (char *)hash_get(stanza->attributes, "type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the 'to' attribute of the stanza object.
|
||||||
|
* This is a convenience function equivalent to:
|
||||||
|
* xmpp_stanza_get_attribute(stanza, "to");
|
||||||
|
*
|
||||||
|
* @param stanza a Strophe stanza object
|
||||||
|
*
|
||||||
|
* @return a string with the 'to' attribute value
|
||||||
|
*
|
||||||
|
* @ingroup Stanza
|
||||||
|
*/
|
||||||
|
char *xmpp_stanza_get_to(xmpp_stanza_t * const stanza)
|
||||||
|
{
|
||||||
|
if (stanza->type != XMPP_STANZA_TAG)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!stanza->attributes)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return (char *)hash_get(stanza->attributes, "to");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the 'from' attribute of the stanza object.
|
||||||
|
* This is a convenience function equivalent to:
|
||||||
|
* xmpp_stanza_get_attribute(stanza, "from");
|
||||||
|
*
|
||||||
|
* @param stanza a Strophe stanza object
|
||||||
|
*
|
||||||
|
* @return a string with the 'from' attribute value
|
||||||
|
*
|
||||||
|
* @ingroup Stanza
|
||||||
|
*/
|
||||||
|
char *xmpp_stanza_get_from(xmpp_stanza_t * const stanza)
|
||||||
|
{
|
||||||
|
if (stanza->type != XMPP_STANZA_TAG)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!stanza->attributes)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return (char *)hash_get(stanza->attributes, "from");
|
||||||
|
}
|
||||||
|
|
||||||
/** Get the first child of stanza with name.
|
/** Get the first child of stanza with name.
|
||||||
* This function searches all the immediate children of stanza for a child
|
* This function searches all the immediate children of stanza for a child
|
||||||
* stanza that matches the name. The first matching child is returned.
|
* stanza that matches the name. The first matching child is returned.
|
||||||
@@ -919,6 +961,42 @@ int xmpp_stanza_set_type(xmpp_stanza_t * const stanza,
|
|||||||
return xmpp_stanza_set_attribute(stanza, "type", type);
|
return xmpp_stanza_set_attribute(stanza, "type", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set the 'to' attribute of a stanza.
|
||||||
|
*
|
||||||
|
* This is a convenience function for:
|
||||||
|
* xmpp_stanza_set_attribute(stanza, 'to', to);
|
||||||
|
*
|
||||||
|
* @param stanza a Strophe stanza object
|
||||||
|
* @param to a string containing the 'to' value
|
||||||
|
*
|
||||||
|
* @return XMPP_EOK (0) on success or a number less than 0 on failure
|
||||||
|
*
|
||||||
|
* @ingroup Stanza
|
||||||
|
*/
|
||||||
|
int xmpp_stanza_set_to(xmpp_stanza_t * const stanza,
|
||||||
|
const char * const to)
|
||||||
|
{
|
||||||
|
return xmpp_stanza_set_attribute(stanza, "to", to);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the 'from' attribute of a stanza.
|
||||||
|
*
|
||||||
|
* This is a convenience function for:
|
||||||
|
* xmpp_stanza_set_attribute(stanza, 'from', from);
|
||||||
|
*
|
||||||
|
* @param stanza a Strophe stanza object
|
||||||
|
* @param from a string containing the 'from' value
|
||||||
|
*
|
||||||
|
* @return XMPP_EOK (0) on success or a number less than 0 on failure
|
||||||
|
*
|
||||||
|
* @ingroup Stanza
|
||||||
|
*/
|
||||||
|
int xmpp_stanza_set_from(xmpp_stanza_t * const stanza,
|
||||||
|
const char * const from)
|
||||||
|
{
|
||||||
|
return xmpp_stanza_set_attribute(stanza, "from", from);
|
||||||
|
}
|
||||||
|
|
||||||
/** Get an attribute from a stanza.
|
/** Get an attribute from a stanza.
|
||||||
* This function returns a pointer to the attribute value. If the caller
|
* This function returns a pointer to the attribute value. If the caller
|
||||||
* wishes to save this value it must make its own copy.
|
* wishes to save this value it must make its own copy.
|
||||||
|
|||||||
11
strophe.h
11
strophe.h
@@ -345,15 +345,16 @@ int xmpp_stanza_set_text_with_size(xmpp_stanza_t *stanza,
|
|||||||
/* common stanza helpers */
|
/* common stanza helpers */
|
||||||
char *xmpp_stanza_get_type(xmpp_stanza_t * const stanza);
|
char *xmpp_stanza_get_type(xmpp_stanza_t * const stanza);
|
||||||
char *xmpp_stanza_get_id(xmpp_stanza_t * const stanza);
|
char *xmpp_stanza_get_id(xmpp_stanza_t * const stanza);
|
||||||
|
char *xmpp_stanza_get_to(xmpp_stanza_t * const stanza);
|
||||||
|
char *xmpp_stanza_get_from(xmpp_stanza_t * const stanza);
|
||||||
int xmpp_stanza_set_id(xmpp_stanza_t * const stanza,
|
int xmpp_stanza_set_id(xmpp_stanza_t * const stanza,
|
||||||
const char * const id);
|
const char * const id);
|
||||||
int xmpp_stanza_set_type(xmpp_stanza_t * const stanza,
|
int xmpp_stanza_set_type(xmpp_stanza_t * const stanza,
|
||||||
const char * const type);
|
const char * const type);
|
||||||
|
int xmpp_stanza_set_to(xmpp_stanza_t * const stanza,
|
||||||
/* unimplemented
|
const char * const to);
|
||||||
int xmpp_stanza_set_to();
|
int xmpp_stanza_set_from(xmpp_stanza_t * const stanza,
|
||||||
int xmpp_stanza_set_from();
|
const char * const from);
|
||||||
*/
|
|
||||||
|
|
||||||
/* allocate and initialize a stanza in reply to another */
|
/* allocate and initialize a stanza in reply to another */
|
||||||
/* unimplemented
|
/* unimplemented
|
||||||
|
|||||||
Reference in New Issue
Block a user