Made verifications blocking calls with timeout
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "server/stanza.h"
|
||||
#include "server/log.h"
|
||||
|
||||
pthread_mutex_t stanzas_lock;
|
||||
static GList *stanzas;
|
||||
|
||||
XMPPStanza*
|
||||
@@ -62,6 +63,7 @@ stanza_show(XMPPStanza *stanza)
|
||||
void
|
||||
stanza_show_all(void)
|
||||
{
|
||||
pthread_mutex_lock(&stanzas_lock);
|
||||
GList *curr = stanzas;
|
||||
while (curr) {
|
||||
XMPPStanza *stanza = curr->data;
|
||||
@@ -69,12 +71,15 @@ stanza_show_all(void)
|
||||
log_println("");
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
pthread_mutex_unlock(&stanzas_lock);
|
||||
}
|
||||
|
||||
void
|
||||
stanza_add(XMPPStanza *stanza)
|
||||
{
|
||||
pthread_mutex_lock(&stanzas_lock);
|
||||
stanzas = g_list_append(stanzas, stanza);
|
||||
pthread_mutex_unlock(&stanzas_lock);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -253,7 +258,9 @@ _stanzas_equal(XMPPStanza *first, XMPPStanza *second)
|
||||
int
|
||||
stanza_verify_any(XMPPStanza *stanza)
|
||||
{
|
||||
pthread_mutex_lock(&stanzas_lock);
|
||||
if (!stanzas) {
|
||||
pthread_mutex_unlock(&stanzas_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -261,30 +268,35 @@ stanza_verify_any(XMPPStanza *stanza)
|
||||
while (curr) {
|
||||
XMPPStanza *curr_stanza = curr->data;
|
||||
if (_stanzas_equal(stanza, curr_stanza) == 0) {
|
||||
pthread_mutex_unlock(&stanzas_lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
curr = g_list_previous(curr);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&stanzas_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
stanza_verify_last(XMPPStanza *stanza)
|
||||
{
|
||||
pthread_mutex_lock(&stanzas_lock);
|
||||
if (!stanzas) {
|
||||
pthread_mutex_unlock(&stanzas_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
GList *last = g_list_last(stanzas);
|
||||
if (!last) {
|
||||
pthread_mutex_unlock(&stanzas_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
XMPPStanza *last_stanza = (XMPPStanza *)last->data;
|
||||
|
||||
int res = _stanzas_equal(stanza, last_stanza);
|
||||
pthread_mutex_unlock(&stanzas_lock);
|
||||
if (res == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
@@ -319,6 +331,8 @@ stanza_free(XMPPStanza *stanza)
|
||||
void
|
||||
stanza_free_all(void)
|
||||
{
|
||||
pthread_mutex_lock(&stanzas_lock);
|
||||
g_list_free_full(stanzas, (GDestroyNotify)stanza_free);
|
||||
stanzas = NULL;
|
||||
pthread_mutex_unlock(&stanzas_lock);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user