Added verify any
This commit is contained in:
@@ -36,6 +36,12 @@ stbbr_verify_last(char *stanza)
|
||||
return verify_last(stanza);
|
||||
}
|
||||
|
||||
int
|
||||
stbbr_verify(char *stanza)
|
||||
{
|
||||
return verify_any(stanza);
|
||||
}
|
||||
|
||||
void
|
||||
stbbr_stop(void)
|
||||
{
|
||||
|
||||
@@ -243,6 +243,26 @@ _stanzas_equal(XMPPStanza *first, XMPPStanza *second)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
stanza_verify_any(XMPPStanza *stanza)
|
||||
{
|
||||
if (!stanzas) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
GList *curr = g_list_last(stanzas);
|
||||
while (curr) {
|
||||
XMPPStanza *curr_stanza = curr->data;
|
||||
if (_stanzas_equal(curr_stanza, stanza) == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
curr = g_list_previous(curr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
stanza_verify_last(XMPPStanza *stanza)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ 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);
|
||||
|
||||
int stanza_verify_any(XMPPStanza *stanza);
|
||||
int stanza_verify_last(XMPPStanza *stanza);
|
||||
|
||||
void stanza_free(XMPPStanza *stanza);
|
||||
|
||||
@@ -45,6 +45,30 @@ handle_data(void *data, const char *content, int length)
|
||||
g_string_append_len(curr_stanza->content, content, length);
|
||||
}
|
||||
|
||||
int
|
||||
verify_any(char *stanza_text)
|
||||
{
|
||||
depth = 0;
|
||||
if (curr_stanza) {
|
||||
stanza_free(curr_stanza);
|
||||
}
|
||||
XML_Parser parser = XML_ParserCreate(NULL);
|
||||
XML_SetElementHandler(parser, start_element, end_element);
|
||||
XML_SetCharacterDataHandler(parser, handle_data);
|
||||
|
||||
XML_Parse(parser, stanza_text, strlen(stanza_text), 0);
|
||||
XML_ParserFree(parser);
|
||||
|
||||
int result = stanza_verify_any(curr_stanza);
|
||||
if (result) {
|
||||
log_println("VERIFY SUCCESS: %s", stanza_text);
|
||||
} else {
|
||||
log_println("VERIFY FAIL: %s", stanza_text);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
verify_last(char *stanza_text)
|
||||
{
|
||||
@@ -61,9 +85,9 @@ verify_last(char *stanza_text)
|
||||
|
||||
int result = stanza_verify_last(curr_stanza);
|
||||
if (result) {
|
||||
log_println("VERIFY SUCCESS: %s", stanza_text);
|
||||
log_println("VERIFY LAST SUCCESS: %s", stanza_text);
|
||||
} else {
|
||||
log_println("VERIFY FAIL: %s", stanza_text);
|
||||
log_println("VERIFY LAST FAIL: %s", stanza_text);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
#define __H_VERIFY
|
||||
|
||||
int verify_last(char *stanza);
|
||||
int verify_any(char *stanza);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user