Added stbbr_wait_for

This commit is contained in:
James Booth
2015-05-30 22:43:28 +01:00
parent 7ae9fe8466
commit e8ca581eea
6 changed files with 50 additions and 0 deletions

View File

@@ -36,6 +36,12 @@ stbbr_for(char *id, char *stream)
return 1; return 1;
} }
void
stbbr_wait_for(char *id)
{
server_wait_for(id);
}
int int
stbbr_last_received(char *stanza) stbbr_last_received(char *stanza)
{ {

View File

@@ -177,6 +177,20 @@ id_callback(const char *id)
} }
} }
void
server_wait_for(char *id)
{
log_println("WAIT for stanza with id: %s", id);
while (TRUE) {
int res = stanzas_contains_id(id);
if (res) {
log_println("WAIT complete for id: %s", id);
return;
}
usleep(1000 * 50);
}
}
void* void*
_start_server_cb(void* userdata) _start_server_cb(void* userdata)
{ {
@@ -321,6 +335,7 @@ server_stop(void)
static void static void
_shutdown(void) _shutdown(void)
{ {
log_println("SHUTDOWN");
// stanza_show_all(); // stanza_show_all();
xmppclient_end_session(client); xmppclient_end_session(client);
client = NULL; client = NULL;

View File

@@ -4,6 +4,8 @@
int server_run(int port); int server_run(int port);
void server_stop(void); void server_stop(void);
void server_wait_for(char *id);
void server_send(char *stream); void server_send(char *stream);
#endif #endif

View File

@@ -74,6 +74,29 @@ stanza_show_all(void)
pthread_mutex_unlock(&stanzas_lock); pthread_mutex_unlock(&stanzas_lock);
} }
int
stanzas_contains_id(char *id)
{
pthread_mutex_lock(&stanzas_lock);
GList *curr = stanzas;
while (curr) {
XMPPStanza *stanza = curr->data;
GList *curr_attr = stanza->attrs;
while (curr_attr) {
XMPPAttr *attr = curr_attr->data;
if (g_strcmp0(attr->name, "id") == 0 && g_strcmp0(attr->value, id) == 0) {
pthread_mutex_unlock(&stanzas_lock);
return 1;
}
curr_attr = g_list_next(curr_attr);
}
curr = g_list_next(curr);
}
pthread_mutex_unlock(&stanzas_lock);
return 0;
}
void void
stanza_add(XMPPStanza *stanza) stanza_add(XMPPStanza *stanza)
{ {

View File

@@ -29,6 +29,8 @@ XMPPStanza* stanza_get_child_by_name(XMPPStanza *stanza, char *name);
int stanza_verify_any(XMPPStanza *stanza); int stanza_verify_any(XMPPStanza *stanza);
int stanza_verify_last(XMPPStanza *stanza); int stanza_verify_last(XMPPStanza *stanza);
int stanzas_contains_id(char *id);
void stanza_free(XMPPStanza *stanza); void stanza_free(XMPPStanza *stanza);
void stanza_free_all(void); void stanza_free_all(void);

View File

@@ -9,6 +9,8 @@ void stbbr_set_timeout(int seconds);
int stbbr_auth_passwd(char *password); int stbbr_auth_passwd(char *password);
void stbbr_for(char *id, char *stream); void stbbr_for(char *id, char *stream);
void stbbr_wait_for(char *id);
int stbbr_received(char *stanza); int stbbr_received(char *stanza);
int stbbr_last_received(char *stanza); int stbbr_last_received(char *stanza);