Added id handler

This commit is contained in:
James Booth
2015-05-16 21:55:51 +01:00
parent 50cd28a977
commit ede3ccab9d
10 changed files with 88 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ static XMPPStanza *curr_stanza;
static stream_start_func stream_start_cb = NULL;
static auth_func auth_cb = NULL;
static id_func id_cb = NULL;
static void
start_element(void *data, const char *element, const char **attributes)
@@ -44,18 +45,20 @@ end_element(void *data, const char *element)
{
depth--;
if (stanza_get_child_by_ns(curr_stanza, "jabber:iq:auth")) {
auth_cb(curr_stanza, xmppclient);
}
if (depth > 0) {
stanza_add_child(curr_stanza->parent, curr_stanza);
curr_stanza = curr_stanza->parent;
} else {
stanza_add(curr_stanza);
}
if (stanza_get_child_by_ns(curr_stanza, "jabber:iq:auth")) {
auth_cb(curr_stanza, xmppclient);
} else {
const char *id = stanza_get_id(curr_stanza);
if (id) {
id_cb(id, xmppclient);
}
}
if (depth == 0) {
do_reset = 1;
}
}
@@ -71,11 +74,12 @@ handle_data(void *data, const char *content, int length)
}
void
parser_init(XMPPClient *client, stream_start_func startcb, auth_func authcb)
parser_init(XMPPClient *client, stream_start_func startcb, auth_func authcb, id_func idcb)
{
xmppclient = client;
stream_start_cb = startcb;
auth_cb = authcb;
id_cb = idcb;
parser = XML_ParserCreate(NULL);
XML_SetElementHandler(parser, start_element, end_element);
@@ -99,7 +103,7 @@ parser_reset(void)
{
if (do_reset == 1) {
parser_close();
parser_init(xmppclient, stream_start_cb, auth_cb);
parser_init(xmppclient, stream_start_cb, auth_cb, id_cb);
do_reset = 0;
}
}