stanza: return const char* for non allocated strings
If interface function returns char* the result must be freed with xmpp_free(). In case of const char* the result must not be changed by user. Also, the result is valid only during stanza lifetime.
This commit is contained in:
@@ -24,7 +24,7 @@ int handle_reply(xmpp_conn_t * const conn,
|
||||
void * const userdata)
|
||||
{
|
||||
xmpp_stanza_t *query, *item;
|
||||
char *type;
|
||||
const char *type;
|
||||
|
||||
type = xmpp_stanza_get_type(stanza);
|
||||
if (strcmp(type, "error") == 0)
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
|
||||
{
|
||||
xmpp_stanza_t *reply, *query, *name, *version, *text;
|
||||
char *ns;
|
||||
const char *ns;
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
|
||||
printf("Received version request from %s\n", xmpp_stanza_get_from(stanza));
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ int handle_reply(xmpp_conn_t * const conn,
|
||||
void * const userdata)
|
||||
{
|
||||
xmpp_stanza_t *query, *item;
|
||||
char *type, *name;
|
||||
const char *type, *name;
|
||||
|
||||
type = xmpp_stanza_get_type(stanza);
|
||||
if (strcmp(type, "error") == 0)
|
||||
|
||||
23
src/auth.c
23
src/auth.c
@@ -111,7 +111,7 @@ static int _handle_error(xmpp_conn_t * const conn,
|
||||
void * const userdata)
|
||||
{
|
||||
xmpp_stanza_t *child;
|
||||
char *name;
|
||||
const char *name;
|
||||
|
||||
/* free old stream error if it's still there */
|
||||
if (conn->stream_error) {
|
||||
@@ -130,7 +130,7 @@ static int _handle_error(xmpp_conn_t * const conn,
|
||||
if (conn->stream_error) {
|
||||
child = xmpp_stanza_get_children(stanza);
|
||||
do {
|
||||
char *ns = NULL;
|
||||
const char *ns = NULL;
|
||||
|
||||
if (child) {
|
||||
ns = xmpp_stanza_get_ns(child);
|
||||
@@ -279,7 +279,7 @@ static int _handle_proceedtls_default(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
{
|
||||
char *name;
|
||||
const char *name;
|
||||
|
||||
name = xmpp_stanza_get_name(stanza);
|
||||
xmpp_debug(conn->ctx, "xmpp", "handle proceedtls called for %s", name);
|
||||
@@ -302,7 +302,7 @@ static int _handle_sasl_result(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
{
|
||||
char *name;
|
||||
const char *name;
|
||||
|
||||
name = xmpp_stanza_get_name(stanza);
|
||||
|
||||
@@ -341,7 +341,7 @@ static int _handle_digestmd5_challenge(xmpp_conn_t * const conn,
|
||||
char *text;
|
||||
char *response;
|
||||
xmpp_stanza_t *auth, *authdata;
|
||||
char *name;
|
||||
const char *name;
|
||||
|
||||
name = xmpp_stanza_get_name(stanza);
|
||||
xmpp_debug(conn->ctx, "xmpp",\
|
||||
@@ -396,7 +396,7 @@ static int _handle_digestmd5_rspauth(xmpp_conn_t * const conn,
|
||||
void * const userdata)
|
||||
{
|
||||
xmpp_stanza_t *auth;
|
||||
char *name;
|
||||
const char *name;
|
||||
|
||||
name = xmpp_stanza_get_name(stanza);
|
||||
xmpp_debug(conn->ctx, "xmpp",
|
||||
@@ -429,7 +429,7 @@ static int _handle_scram_sha1_challenge(xmpp_conn_t * const conn,
|
||||
char *text;
|
||||
char *response;
|
||||
xmpp_stanza_t *auth, *authdata;
|
||||
char *name;
|
||||
const char *name;
|
||||
char *challenge;
|
||||
char *scram_init = (char *)userdata;
|
||||
|
||||
@@ -979,7 +979,7 @@ static int _handle_bind(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
{
|
||||
char *type;
|
||||
const char *type;
|
||||
xmpp_stanza_t *iq, *session;
|
||||
|
||||
/* delete missing bind handler */
|
||||
@@ -1062,7 +1062,7 @@ static int _handle_session(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
{
|
||||
char *type;
|
||||
const char *type;
|
||||
|
||||
/* delete missing session handler */
|
||||
xmpp_timed_handler_delete(conn, _handle_missing_session);
|
||||
@@ -1099,7 +1099,8 @@ static int _handle_legacy(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
{
|
||||
char *type, *name;
|
||||
const char *type;
|
||||
const char *name;
|
||||
|
||||
/* delete missing handler */
|
||||
xmpp_timed_handler_delete(conn, _handle_missing_legacy);
|
||||
@@ -1201,7 +1202,7 @@ int _handle_component_hs_response(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
{
|
||||
char *name;
|
||||
const char *name;
|
||||
|
||||
xmpp_timed_handler_delete(conn, _handle_missing_handshake);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ void handler_fire_stanza(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza)
|
||||
{
|
||||
xmpp_handlist_t *item, *prev;
|
||||
char *id, *ns, *name, *type;
|
||||
const char *id, *ns, *name, *type;
|
||||
|
||||
/* call id handlers */
|
||||
id = xmpp_stanza_get_id(stanza);
|
||||
|
||||
24
src/stanza.c
24
src/stanza.c
@@ -415,9 +415,9 @@ static int _render_stanza_recursive(xmpp_stanza_t *stanza,
|
||||
*
|
||||
* @ingroup Stanza
|
||||
*/
|
||||
int xmpp_stanza_to_text(xmpp_stanza_t *stanza,
|
||||
char ** const buf,
|
||||
size_t * const buflen)
|
||||
int xmpp_stanza_to_text(xmpp_stanza_t *stanza,
|
||||
char ** const buf,
|
||||
size_t * const buflen)
|
||||
{
|
||||
char *buffer, *tmp;
|
||||
size_t length;
|
||||
@@ -491,7 +491,7 @@ int xmpp_stanza_set_name(xmpp_stanza_t *stanza,
|
||||
*
|
||||
* @ingroup Stanza
|
||||
*/
|
||||
char *xmpp_stanza_get_name(xmpp_stanza_t * const stanza)
|
||||
const char *xmpp_stanza_get_name(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
if (stanza->type == XMPP_STANZA_TEXT) return NULL;
|
||||
return stanza->data;
|
||||
@@ -710,7 +710,7 @@ int xmpp_stanza_set_text_with_size(xmpp_stanza_t *stanza,
|
||||
*
|
||||
* @ingroup Stanza
|
||||
*/
|
||||
char *xmpp_stanza_get_id(xmpp_stanza_t * const stanza)
|
||||
const char *xmpp_stanza_get_id(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
return xmpp_stanza_get_attribute(stanza, "id");
|
||||
}
|
||||
@@ -725,7 +725,7 @@ char *xmpp_stanza_get_id(xmpp_stanza_t * const stanza)
|
||||
*
|
||||
* @ingroup Stanza
|
||||
*/
|
||||
char *xmpp_stanza_get_ns(xmpp_stanza_t * const stanza)
|
||||
const char *xmpp_stanza_get_ns(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
return xmpp_stanza_get_attribute(stanza, "xmlns");
|
||||
}
|
||||
@@ -740,7 +740,7 @@ char *xmpp_stanza_get_ns(xmpp_stanza_t * const stanza)
|
||||
*
|
||||
* @ingroup Stanza
|
||||
*/
|
||||
char *xmpp_stanza_get_type(xmpp_stanza_t * const stanza)
|
||||
const char *xmpp_stanza_get_type(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
return xmpp_stanza_get_attribute(stanza, "type");
|
||||
}
|
||||
@@ -755,7 +755,7 @@ char *xmpp_stanza_get_type(xmpp_stanza_t * const stanza)
|
||||
*
|
||||
* @ingroup Stanza
|
||||
*/
|
||||
char *xmpp_stanza_get_to(xmpp_stanza_t * const stanza)
|
||||
const char *xmpp_stanza_get_to(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
return xmpp_stanza_get_attribute(stanza, "to");
|
||||
}
|
||||
@@ -770,7 +770,7 @@ char *xmpp_stanza_get_to(xmpp_stanza_t * const stanza)
|
||||
*
|
||||
* @ingroup Stanza
|
||||
*/
|
||||
char *xmpp_stanza_get_from(xmpp_stanza_t * const stanza)
|
||||
const char *xmpp_stanza_get_from(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
return xmpp_stanza_get_attribute(stanza, "from");
|
||||
}
|
||||
@@ -915,7 +915,7 @@ char *xmpp_stanza_get_text(xmpp_stanza_t * const stanza)
|
||||
*
|
||||
* @ingroup Stanza
|
||||
*/
|
||||
char *xmpp_stanza_get_text_ptr(xmpp_stanza_t * const stanza)
|
||||
const char *xmpp_stanza_get_text_ptr(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
if (stanza->type == XMPP_STANZA_TEXT)
|
||||
return stanza->data;
|
||||
@@ -1004,8 +1004,8 @@ int xmpp_stanza_set_from(xmpp_stanza_t * const stanza,
|
||||
*
|
||||
* @ingroup Stanza
|
||||
*/
|
||||
char *xmpp_stanza_get_attribute(xmpp_stanza_t * const stanza,
|
||||
const char * const name)
|
||||
const char *xmpp_stanza_get_attribute(xmpp_stanza_t * const stanza,
|
||||
const char * const name)
|
||||
{
|
||||
if (stanza->type != XMPP_STANZA_TAG)
|
||||
return NULL;
|
||||
|
||||
40
strophe.h
40
strophe.h
@@ -295,7 +295,7 @@ xmpp_stanza_t *xmpp_stanza_new(xmpp_ctx_t *ctx);
|
||||
xmpp_stanza_t *xmpp_stanza_clone(xmpp_stanza_t * const stanza);
|
||||
|
||||
/** copies a stanza and all children */
|
||||
xmpp_stanza_t * xmpp_stanza_copy(const xmpp_stanza_t * const stanza);
|
||||
xmpp_stanza_t *xmpp_stanza_copy(const xmpp_stanza_t * const stanza);
|
||||
|
||||
/** free a stanza object and it's contents */
|
||||
int xmpp_stanza_release(xmpp_stanza_t * const stanza);
|
||||
@@ -317,21 +317,18 @@ xmpp_stanza_t *xmpp_stanza_get_child_by_name(xmpp_stanza_t * const stanza,
|
||||
xmpp_stanza_t *xmpp_stanza_get_child_by_ns(xmpp_stanza_t * const stanza,
|
||||
const char * const ns);
|
||||
xmpp_stanza_t *xmpp_stanza_get_next(xmpp_stanza_t * const stanza);
|
||||
char *xmpp_stanza_get_attribute(xmpp_stanza_t * const stanza,
|
||||
const char * const name);
|
||||
int xmpp_stanza_add_child(xmpp_stanza_t *stanza, xmpp_stanza_t *child);
|
||||
|
||||
const char *xmpp_stanza_get_attribute(xmpp_stanza_t * const stanza,
|
||||
const char * const name);
|
||||
int xmpp_stanza_get_attribute_count(xmpp_stanza_t * const stanza);
|
||||
int xmpp_stanza_get_attributes(xmpp_stanza_t * const stanza,
|
||||
const char **attr, int attrlen);
|
||||
char *xmpp_stanza_get_ns(xmpp_stanza_t * const stanza);
|
||||
/* concatenate all child text nodes. this function
|
||||
* returns a string that must be freed by the caller */
|
||||
|
||||
char *xmpp_stanza_get_text(xmpp_stanza_t * const stanza);
|
||||
char *xmpp_stanza_get_text_ptr(xmpp_stanza_t * const stanza);
|
||||
char *xmpp_stanza_get_name(xmpp_stanza_t * const stanza);
|
||||
|
||||
int xmpp_stanza_add_child(xmpp_stanza_t *stanza, xmpp_stanza_t *child);
|
||||
int xmpp_stanza_set_ns(xmpp_stanza_t * const stanza, const char * const ns);
|
||||
const char *xmpp_stanza_get_text_ptr(xmpp_stanza_t * const stanza);
|
||||
const char *xmpp_stanza_get_name(xmpp_stanza_t * const stanza);
|
||||
/* set_attribute adds/replaces attributes */
|
||||
int xmpp_stanza_set_attribute(xmpp_stanza_t * const stanza,
|
||||
const char * const key,
|
||||
@@ -343,23 +340,20 @@ int xmpp_stanza_set_text(xmpp_stanza_t *stanza,
|
||||
int xmpp_stanza_set_text_with_size(xmpp_stanza_t *stanza,
|
||||
const char * const text,
|
||||
const size_t size);
|
||||
|
||||
int xmpp_stanza_del_attribute(xmpp_stanza_t * const stanza,
|
||||
const char * const name);
|
||||
|
||||
/* common stanza helpers */
|
||||
char *xmpp_stanza_get_type(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,
|
||||
const char * const id);
|
||||
int xmpp_stanza_set_type(xmpp_stanza_t * const stanza,
|
||||
const char * const type);
|
||||
int xmpp_stanza_set_to(xmpp_stanza_t * const stanza,
|
||||
const char * const to);
|
||||
int xmpp_stanza_set_from(xmpp_stanza_t * const stanza,
|
||||
const char * const from);
|
||||
const char *xmpp_stanza_get_ns(xmpp_stanza_t * const stanza);
|
||||
const char *xmpp_stanza_get_type(xmpp_stanza_t * const stanza);
|
||||
const char *xmpp_stanza_get_id(xmpp_stanza_t * const stanza);
|
||||
const char *xmpp_stanza_get_to(xmpp_stanza_t * const stanza);
|
||||
const char *xmpp_stanza_get_from(xmpp_stanza_t * const stanza);
|
||||
int xmpp_stanza_set_ns(xmpp_stanza_t * const stanza, const char * const ns);
|
||||
int xmpp_stanza_set_id(xmpp_stanza_t * const stanza, const char * const id);
|
||||
int xmpp_stanza_set_type(xmpp_stanza_t * const stanza, const char * const type);
|
||||
int xmpp_stanza_set_to(xmpp_stanza_t * const stanza, const char * const to);
|
||||
int xmpp_stanza_set_from(xmpp_stanza_t * const stanza, const char * const from);
|
||||
|
||||
/* allocate and initialize a stanza in reply to another */
|
||||
xmpp_stanza_t *xmpp_stanza_reply(xmpp_stanza_t * const stanza);
|
||||
|
||||
Reference in New Issue
Block a user