Added stanza free functions

This commit is contained in:
James Booth
2015-05-17 20:36:11 +01:00
parent f7b3be3699
commit 2e1a2f7c14
3 changed files with 37 additions and 4 deletions

View File

@@ -218,7 +218,7 @@ server_run(int port)
static void
_shutdown(void)
{
stanza_show_all();
// stanza_show_all();
xmppclient_end_session(client);
parser_close();
@@ -226,5 +226,6 @@ _shutdown(void)
shutdown(listen_socket, 2);
close(listen_socket);
stanza_free_all();
log_close();
}

View File

@@ -163,3 +163,33 @@ stanza_get_id(XMPPStanza *stanza)
return NULL;
}
static void
_attrs_free(XMPPAttr *attr)
{
if (attr) {
free(attr->name);
free(attr->value);
free(attr);
}
}
static void
_stanza_free(XMPPStanza *stanza)
{
if (stanza) {
free(stanza->name);
if (stanza->content) {
g_string_free(stanza->content, TRUE);
}
g_list_free_full(stanza->attrs, (GDestroyNotify)_attrs_free);
g_list_free_full(stanza->children, (GDestroyNotify)_stanza_free);
free(stanza);
}
}
void
stanza_free_all(void)
{
g_list_free_full(stanzas, (GDestroyNotify)_stanza_free);
}

View File

@@ -2,12 +2,12 @@
#define __H_STANZA
typedef struct xmpp_attr_t {
const char *name;
const char *value;
char *name;
char *value;
} XMPPAttr;
typedef struct xmpp_stanza_t {
const char *name;
char *name;
GList *attrs;
GList *children;
GString *content;
@@ -24,4 +24,6 @@ const char* stanza_get_id(XMPPStanza *stanza);
XMPPStanza* stanza_get_child_by_ns(XMPPStanza *stanza, char *ns);
XMPPStanza* stanza_get_child_by_name(XMPPStanza *stanza, char *name);
void stanza_free_all(void);
#endif