diff --git a/src/server/parser.c b/src/server/parser.c index e1ab683..894440b 100644 --- a/src/server/parser.c +++ b/src/server/parser.c @@ -18,29 +18,15 @@ static stream_start_func stream_start_cb = NULL; static auth_func auth_cb = NULL; static void -start_element(void *data, const char *element, const char **attribute) +start_element(void *data, const char *element, const char **attributes) { - int i; - if (g_strcmp0(element, "stream:stream") == 0) { stream_start_cb(xmppclient); do_reset = 1; return; } - XMPPStanza *stanza = malloc(sizeof(XMPPStanza)); - stanza->name = strdup(element); - stanza->content = NULL; - stanza->children = NULL; - stanza->attrs = NULL; - if (attribute[0]) { - for (i = 0; attribute[i]; i += 2) { - XMPPAttr *attr = malloc(sizeof(XMPPAttr)); - attr->name = strdup(attribute[i]); - attr->value = strdup(attribute[i+1]); - stanza->attrs = g_list_append(stanza->attrs, attr); - } - } + XMPPStanza *stanza = stanza_new(element, attributes); if (depth == 0) { curr_stanza = stanza; diff --git a/src/server/server.c b/src/server/server.c index 69b8c2c..8e4c581 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -93,7 +93,7 @@ listen_to(XMPPClient *client) fflush(stdout); parser_reset(); g_string_append_len(stream, buf, read_size); - if (g_str_has_suffix(stream->str, "")) { + if (g_str_has_suffix(stream->str, STREAM_END)) { stream_end(client); break; } diff --git a/src/server/stanza.c b/src/server/stanza.c index d2d9bd0..e651738 100644 --- a/src/server/stanza.c +++ b/src/server/stanza.c @@ -1,10 +1,33 @@ #include +#include +#include #include #include "server/stanza.h" static GList *stanzas; +XMPPStanza* +stanza_new(const char *name, const char **attributes) +{ + XMPPStanza *stanza = malloc(sizeof(XMPPStanza)); + stanza->name = strdup(name); + stanza->content = NULL; + stanza->children = NULL; + stanza->attrs = NULL; + if (attributes[0]) { + int i; + for (i = 0; attributes[i]; i += 2) { + XMPPAttr *attr = malloc(sizeof(XMPPAttr)); + attr->name = strdup(attributes[i]); + attr->value = strdup(attributes[i+1]); + stanza->attrs = g_list_append(stanza->attrs, attr); + } + } + + return stanza; +} + void stanza_show(XMPPStanza *stanza) { diff --git a/src/server/stanza.h b/src/server/stanza.h index 82fba73..ab55872 100644 --- a/src/server/stanza.h +++ b/src/server/stanza.h @@ -14,6 +14,7 @@ typedef struct xmpp_stanza_t { struct xmpp_stanza_t *parent; } XMPPStanza; +XMPPStanza* stanza_new(const char *name, const char **attributes); void stanza_show(XMPPStanza *stanza); void stanza_show_all(void); void stanza_add(XMPPStanza *stanza);