Added verify for last received stanza
This commit is contained in:
@@ -164,6 +164,107 @@ stanza_get_id(XMPPStanza *stanza)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
_xmpp_attr_equal(XMPPAttr *attr1, XMPPAttr *attr2)
|
||||
{
|
||||
if (g_strcmp0(attr1->name, attr2->name) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (g_strcmp0(attr1->value, attr2->value) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_stanzas_equal(XMPPStanza *first, XMPPStanza *second)
|
||||
{
|
||||
// check name
|
||||
if (g_strcmp0(first->name, second->name) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// check attribute count
|
||||
if (g_list_length(first->attrs) != g_list_length(second->attrs)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// check children count
|
||||
if (g_list_length(first->children) != g_list_length(second->children)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// check presence of content
|
||||
if (!first->content && second->content) {
|
||||
return -1;
|
||||
}
|
||||
if (first->content && !second->content) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// check content is exists
|
||||
if (first->content) {
|
||||
if (g_strcmp0(first->content->str, second->content->str) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// check attributes
|
||||
if (first->attrs) {
|
||||
GList *first_curr_attr = first->attrs;
|
||||
while (first_curr_attr) {
|
||||
XMPPAttr *first_attr = (XMPPAttr *)first_curr_attr->data;
|
||||
|
||||
GList *second_found_attr = g_list_find_custom(second->attrs, first_attr, (GCompareFunc)_xmpp_attr_equal);
|
||||
if (!second_found_attr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
first_curr_attr = g_list_next(first_curr_attr);
|
||||
}
|
||||
}
|
||||
|
||||
// check children
|
||||
if (first->children) {
|
||||
GList *first_curr_child = first->children;
|
||||
while (first_curr_child) {
|
||||
XMPPStanza *first_child = (XMPPStanza *)first_curr_child->data;
|
||||
GList *second_found_child = g_list_find_custom(second->children, first_child, (GCompareFunc)_stanzas_equal);
|
||||
if (!second_found_child) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
first_curr_child = g_list_next(first_curr_child);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
stanza_verify_last(XMPPStanza *stanza)
|
||||
{
|
||||
if (!stanzas) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
GList *last = g_list_last(stanzas);
|
||||
if (!last) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
XMPPStanza *last_stanza = (XMPPStanza *)last->data;
|
||||
|
||||
int res = _stanzas_equal(stanza, last_stanza);
|
||||
if (res == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_attrs_free(XMPPAttr *attr)
|
||||
{
|
||||
@@ -174,8 +275,8 @@ _attrs_free(XMPPAttr *attr)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_stanza_free(XMPPStanza *stanza)
|
||||
void
|
||||
stanza_free(XMPPStanza *stanza)
|
||||
{
|
||||
if (stanza) {
|
||||
free(stanza->name);
|
||||
@@ -183,7 +284,7 @@ _stanza_free(XMPPStanza *stanza)
|
||||
g_string_free(stanza->content, TRUE);
|
||||
}
|
||||
g_list_free_full(stanza->attrs, (GDestroyNotify)_attrs_free);
|
||||
g_list_free_full(stanza->children, (GDestroyNotify)_stanza_free);
|
||||
g_list_free_full(stanza->children, (GDestroyNotify)stanza_free);
|
||||
free(stanza);
|
||||
}
|
||||
}
|
||||
@@ -191,6 +292,6 @@ _stanza_free(XMPPStanza *stanza)
|
||||
void
|
||||
stanza_free_all(void)
|
||||
{
|
||||
g_list_free_full(stanzas, (GDestroyNotify)_stanza_free);
|
||||
g_list_free_full(stanzas, (GDestroyNotify)stanza_free);
|
||||
stanzas = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user