本文整理汇总了C++中xmpp_free函数的典型用法代码示例。如果您正苦于以下问题:C++ xmpp_free函数的具体用法?C++ xmpp_free怎么用?C++ xmpp_free使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmpp_free函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xmpp_stanza_release
/** 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.
*
* @param stanza a Strophe stanza object
*
* @return TRUE if the object was freed and FALSE otherwise
*
* @ingroup Stanza
*/
int xmpp_stanza_release(xmpp_stanza_t * const stanza)
{
int released = 0;
xmpp_stanza_t *child, *tchild;
/* release stanza */
if (stanza->ref > 1)
stanza->ref--;
else {
/* release all children */
child = stanza->children;
while (child) {
tchild = child;
child = child->next;
xmpp_stanza_release(tchild);
}
if (stanza->attributes) hash_release(stanza->attributes);
if (stanza->data) xmpp_free(stanza->ctx, stanza->data);
xmpp_free(stanza->ctx, stanza);
released = 1;
}
return released;
}
示例2: xmpp_handler_delete
/** Delete a stanza handler.
*
* @param conn a Strophe connection object
* @param handler a function pointer to a stanza handler
*
* @ingroup Handlers
*/
void xmpp_handler_delete(xmpp_conn_t * const conn,
xmpp_handler handler)
{
xmpp_handlist_t *prev, *item;
if (!conn->handlers) return;
prev = NULL;
item = conn->handlers;
while (item) {
if (item->handler == (void *)handler)
break;
prev = item;
item = item->next;
}
if (item) {
if (prev)
prev->next = item->next;
else
conn->handlers = item->next;
if (item->ns) xmpp_free(conn->ctx, item->ns);
if (item->name) xmpp_free(conn->ctx, item->name);
if (item->type) xmpp_free(conn->ctx, item->type);
xmpp_free(conn->ctx, item);
}
}
示例3: hash_drop
/** delete a key from a hash table */
int hash_drop(hash_t *table, const char *key)
{
xmpp_ctx_t *ctx = table->ctx;
hashentry_t *entry, *prev;
int table_index = _hash_key(table, key);
/* look up the hash entry */
entry = table->entries[table_index];
prev = NULL;
while (entry != NULL) {
/* traverse the linked list looking for the key */
if (!strcmp(key, entry->key)) {
/* match, remove the entry */
xmpp_free(ctx, entry->key);
if (table->free) table->free(ctx, entry->value);
if (prev == NULL) {
table->entries[table_index] = entry->next;
} else {
prev->next = entry->next;
}
xmpp_free(ctx, entry);
table->num_keys--;
return 0;
}
prev = entry;
entry = entry->next;
}
/* no match */
return -1;
}
示例4: xmpp_id_handler_delete
/** Delete an id based stanza handler.
*
* @param conn a Strophe connection object
* @param handler a function pointer to a stanza handler
* @param id a string containing the id the handler is for
*
* @ingroup Handlers
*/
void xmpp_id_handler_delete(xmpp_conn_t * const conn,
xmpp_handler handler,
const char * const id)
{
xmpp_handlist_t *item, *prev;
prev = NULL;
item = (xmpp_handlist_t *)hash_get(conn->id_handlers, id);
if (!item) return;
while (item) {
if (item->handler == (void *)handler)
break;
prev = item;
item = item->next;
}
if (item) {
if (prev)
prev->next = item->next;
else {
hash_drop(conn->id_handlers, id);
hash_add(conn->id_handlers, id, item->next);
}
xmpp_free(conn->ctx, item->id);
xmpp_free(conn->ctx, item);
}
}
示例5: zkmuc_group_msg_handler
static int zkmuc_group_msg_handler(xmpp_ua_t *ua, xmpp_stanza_t *stanza, void *userdata)
{
char *type = xmpp_stanza_get_type(stanza);
if (type && !strcmp(type, "groupchat"))
{
zkmuc_ctx_t *ctx = (zkmuc_ctx_t *)userdata;
// char *from = xmpp_stanza_get_attribute(stanza, "from");
xmpp_stanza_t *stanza_body = xmpp_stanza_get_child_by_name(stanza, "zonekey");
if (!stanza_body)
{
return 0;
}
xmpp_stanza_t *stanza_jid = xmpp_stanza_get_child_by_name(stanza_body, "jid");
char *jid_value = xmpp_stanza_get_text(stanza_jid);
char *text = xmpp_stanza_get_text(stanza_body);
if (text && ctx->room_cbs.on_broadcast_message)
{
ctx->room_cbs.on_broadcast_message(ctx, /*from*/jid_value, text, ctx->room_data);
}
xmpp_free(_xmpp_ctx, jid_value);
xmpp_free(_xmpp_ctx, text);
return 1;
}
return 0;
}
示例6: strlen
/* split key, value pairs into a hash */
static hash_t *_parse_digest_challenge(xmpp_ctx_t *ctx, const char *msg)
{
hash_t *result;
unsigned char *text;
char *key, *value;
unsigned char *s, *t;
text = (unsigned char *)xmpp_base64_decode_str(ctx, msg, strlen(msg));
if (text == NULL) {
xmpp_error(ctx, "SASL", "couldn't Base64 decode challenge!");
return NULL;
}
result = hash_new(ctx, 10, xmpp_free);
if (result != NULL) {
s = text;
while (*s != '\0') {
/* skip any leading commas and spaces */
while ((*s == ',') || (*s == ' ')) s++;
/* accumulate a key ending at '=' */
t = s;
while ((*t != '=') && (*t != '\0')) t++;
if (*t == '\0') break; /* bad string */
key = _make_string(ctx, (char *)s, (t-s));
if (key == NULL) break;
/* advance our start pointer past the key */
s = t + 1;
t = s;
/* if we see quotes, grab the string in between */
if ((*s == '\'') || (*s == '"')) {
t++;
while ((*t != *s) && (*t != '\0'))
t++;
value = _make_string(ctx, (char *)s+1, (t-s-1));
if (*t == *s) {
s = t + 1;
} else {
s = t;
}
/* otherwise, accumulate a value ending in ',' or '\0' */
} else {
while ((*t != ',') && (*t != '\0')) t++;
value = _make_string(ctx, (char *)s, (t-s));
s = t;
}
if (value == NULL) {
xmpp_free(ctx, key);
break;
}
/* TODO: check for collisions per spec */
hash_add(result, key, value);
/* hash table now owns the value, free the key */
xmpp_free(ctx, key);
}
}
xmpp_free(ctx, text);
return result;
}
示例7: _start_element
static void _start_element(void *userdata,
const XML_Char *nsname,
const XML_Char **attrs)
{
parser_t *parser = (parser_t *)userdata;
xmpp_stanza_t *child;
char *ns, *name;
ns = _xml_namespace(parser->ctx, nsname);
name = _xml_name(parser->ctx, nsname);
if (parser->depth == 0) {
/* notify the owner */
if (parser->startcb)
parser->startcb((char *)name, (char **)attrs,
parser->userdata);
} else {
/* build stanzas at depth 1 */
if (!parser->stanza && parser->depth != 1) {
/* something terrible happened */
/* FIXME: shutdown disconnect */
xmpp_error(parser->ctx, "parser", "oops, where did our stanza go?");
} else if (!parser->stanza) {
/* starting a new toplevel stanza */
parser->stanza = xmpp_stanza_new(parser->ctx);
if (!parser->stanza) {
/* FIXME: can't allocate, disconnect */
}
xmpp_stanza_set_name(parser->stanza, name);
_set_attributes(parser->stanza, attrs);
if (ns)
xmpp_stanza_set_ns(parser->stanza, ns);
} else {
/* starting a child of parser->stanza */
child = xmpp_stanza_new(parser->ctx);
if (!child) {
/* FIXME: can't allocate, disconnect */
}
xmpp_stanza_set_name(child, name);
_set_attributes(child, attrs);
if (ns)
xmpp_stanza_set_ns(child, ns);
/* add child to parent */
xmpp_stanza_add_child(parser->stanza, child);
/* the child is owned by the toplevel stanza now */
xmpp_stanza_release(child);
/* make child the current stanza */
parser->stanza = child;
}
}
if (ns) xmpp_free(parser->ctx, ns);
if (name) xmpp_free(parser->ctx, name);
parser->depth++;
}
示例8: _handle_carbons
static gboolean
_handle_carbons(xmpp_stanza_t *const stanza)
{
xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS);
if (!carbons) {
return FALSE;
}
char *name = xmpp_stanza_get_name(carbons);
if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0) {
xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD);
xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE);
xmpp_ctx_t *ctx = connection_get_ctx();
gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO);
gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM);
// happens when receive a carbon of a self sent message
if (!to) to = from;
Jid *jid_from = jid_create(from);
Jid *jid_to = jid_create(to);
Jid *my_jid = jid_create(jabber_get_fulljid());
// check for and deal with message
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY);
if (body) {
char *message_txt = xmpp_stanza_get_text(body);
if (message_txt) {
// check for pgp encrypted message
char *enc_message = NULL;
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(message, STANZA_NS_ENCRYPTED);
if (x) {
enc_message = xmpp_stanza_get_text(x);
}
// if we are the recipient, treat as standard incoming message
if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){
sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message);
// else treat as a sent message
} else {
sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message);
}
xmpp_free(ctx, message_txt);
xmpp_free(ctx, enc_message);
}
}
jid_destroy(jid_from);
jid_destroy(jid_to);
jid_destroy(my_jid);
return TRUE;
}
return FALSE;
}
示例9: xmpp_user_release
void xmpp_user_release(xmpp_user_t * const user)
{
xmpp_ctx_t *ctx = user->conn->ctx;
if (user->name) xmpp_free(ctx, user->name);
if (user->jid) xmpp_free(ctx, user->jid);
xmpp_free(ctx, user);
}
示例10: XMPP_IBB_Data_Process
int XMPP_IBB_Data_Process(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
{
char* intext;
unsigned char *result;
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
char *szSid, szSeq;
// xmpp_ibb_session_t* ibb_ssn;
szSid = \
xmpp_stanza_get_attribute(xmpp_stanza_get_child_by_name(stanza, "data"), "sid");
szSeq = \
xmpp_stanza_get_attribute(xmpp_stanza_get_child_by_name(stanza, "data"), "seq");
intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "data"));
printf("[Sid=%s][Seq=%s][Raw Data=%s]\n", szSid, szSeq, intext);
result = base64_decode(ctx, intext, strlen(intext));
printf("Decode result=%s\n", result);
gRecv = malloc(strlen(result)+1);
strcpy(gRecv, result);
if(gStanza == NULL)
gStanza = xmpp_stanza_copy(stanza);
#if 0 //data queue function has not been verified.
ibb_ssn = XMPP_Get_IBB_Session_Handle(szSid);
if( ibb_ssn == NULL)
{
printf("Opened Session ID not found\n");
goto error;
}
xmpp_ibb_data_t* ibb_data_new = malloc(sizeof(xmpp_ibb_data_t));
ibb_data_new->seq_num = malloc(strlen(szSeq)+1);
ibb_data_new->recv_data = malloc(strlen(result)+1);
strcpy(ibb_data_new->seq_num, szSeq);
strcpy(ibb_data_new->recv_data, result);
XMPP_IBB_Add_Session_Data_Queue(ibb_ssn, ibb_data_new);
#endif
error:
xmpp_free(ctx, szSid);
xmpp_free(ctx, szSeq);
xmpp_free(ctx, intext);
xmpp_free(ctx, result);
return 1;
}
示例11: _handle_digestmd5_challenge
/* handle the challenge phase of digest auth */
static int _handle_digestmd5_challenge(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza,
void * const userdata)
{
char *text;
char *response;
xmpp_stanza_t *auth, *authdata;
char *name;
name = xmpp_stanza_get_name(stanza);
xmpp_debug(conn->ctx, "xmpp",\
"handle digest-md5 (challenge) called for %s", name);
if (strcmp(name, "challenge") == 0) {
text = xmpp_stanza_get_text(stanza);
response = sasl_digest_md5(conn->ctx, text, conn->jid, conn->pass);
if (!response) {
disconnect_mem_error(conn);
return 0;
}
xmpp_free(conn->ctx, text);
auth = xmpp_stanza_new(conn->ctx);
if (!auth) {
disconnect_mem_error(conn);
return 0;
}
xmpp_stanza_set_name(auth, "response");
xmpp_stanza_set_ns(auth, XMPP_NS_SASL);
authdata = xmpp_stanza_new(conn->ctx);
if (!authdata) {
disconnect_mem_error(conn);
return 0;
}
xmpp_stanza_set_text(authdata, response);
xmpp_free(conn->ctx, response);
xmpp_stanza_add_child(auth, authdata);
xmpp_stanza_release(authdata);
handler_add(conn, _handle_digestmd5_rspauth,
XMPP_NS_SASL, NULL, NULL, NULL);
xmpp_send(conn, auth);
xmpp_stanza_release(auth);
} else {
return _handle_sasl_result(conn, stanza, "DIGEST-MD5");
}
/* remove ourselves */
return 0;
}
示例12: _conn_attributes_destroy
static void _conn_attributes_destroy(xmpp_conn_t *conn, char **attributes,
size_t attributes_len)
{
size_t i;
if (attributes) {
for (i = 0; i < attributes_len; ++i)
xmpp_free(conn->ctx, attributes[i]);
xmpp_free(conn->ctx, attributes);
}
}
示例13: _muc_user_handler
static int
_muc_user_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata)
{
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_stanza_t *xns_muc_user = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
char *room = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (!room) {
log_warning("Message received with no from attribute, ignoring");
return 1;
}
// XEP-0045
xmpp_stanza_t *invite = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_INVITE);
if (!invite) {
return 1;
}
char *invitor_jid = xmpp_stanza_get_attribute(invite, STANZA_ATTR_FROM);
if (!invitor_jid) {
log_warning("Chat room invite received with no from attribute");
return 1;
}
Jid *jidp = jid_create(invitor_jid);
if (!jidp) {
return 1;
}
char *invitor = jidp->barejid;
char *reason = NULL;
xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_name(invite, STANZA_NAME_REASON);
if (reason_st) {
reason = xmpp_stanza_get_text(reason_st);
}
char *password = NULL;
xmpp_stanza_t *password_st = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_PASSWORD);
if (password_st) {
password = xmpp_stanza_get_text(password_st);
}
sv_ev_room_invite(INVITE_MEDIATED, invitor, room, reason, password);
jid_destroy(jidp);
if (reason) {
xmpp_free(ctx, reason);
}
if (password) {
xmpp_free(ctx, password);
}
return 1;
}
示例14: main
int main(int argc, char **argv)
{
xmpp_ctx_t *ctx;
xmpp_mem_t mymem;
xmpp_log_t mylog;
char my_str[5] = "asdf";
void *testptr1, *testptr2;
ctx = xmpp_ctx_new(NULL, NULL);
if (ctx == NULL) return 1;
/* destroy context */
xmpp_ctx_free(ctx);
/* setup our memory handler */
mymem.alloc = my_alloc;
mymem.free = my_free;
mymem.realloc = my_realloc;
/* setup our logger */
mylog.handler = my_logger;
mylog.userdata = my_str;
ctx = xmpp_ctx_new(&mymem, &mylog);
xmpp_debug(ctx, "test", "hello");
testptr1 = xmpp_alloc(ctx, 1024);
if (testptr1 == NULL) {
xmpp_ctx_free(ctx);
return 1;
}
testptr2 = xmpp_realloc(ctx, testptr1, 2048);
if (testptr2 == NULL) {
xmpp_free(ctx, testptr1);
xmpp_ctx_free(ctx);
return 1;
}
xmpp_free(ctx, testptr2);
xmpp_ctx_free(ctx);
/* check for test failure */
if (!(log_called && mem_alloc_called && mem_realloc_called &&
mem_free_called))
return 1;
if (mem_alloc_called != mem_free_called)
return 1;
return 0;
}
示例15: _free_cbattrs
static void _free_cbattrs(parser_t *parser, char **attrs)
{
int i;
if (!attrs)
return;
for (i = 0; attrs[i]; i += 2) {
if (attrs[i]) xmpp_free(parser->ctx, attrs[i]);
if (attrs[i+1]) xmpp_free(parser->ctx, attrs[i+1]);
}
xmpp_free(parser->ctx, attrs);
}