Allow stubbing based on query xmlns

This commit is contained in:
James Booth
2015-06-02 00:19:53 +01:00
parent ddb837cdcd
commit fe36df4dbe
13 changed files with 380 additions and 82 deletions

View File

@@ -25,14 +25,19 @@
#include <string.h>
#include "server/stanza.h"
#include "server/parser.h"
static char *required_passwd = NULL;
static GHashTable *idstubs = NULL;
static GHashTable *querystubs = NULL;
void
prime_init(void)
{
required_passwd = strdup("password");
idstubs = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
querystubs = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)stanza_free);
}
void
@@ -44,7 +49,12 @@ prime_free_all(void)
if (idstubs) {
g_hash_table_destroy(idstubs);
}
idstubs = NULL;
querystubs = NULL;
if (querystubs) {
g_hash_table_destroy(querystubs);
}
querystubs = NULL;
}
void
@@ -69,7 +79,22 @@ prime_for_id(const char *id, char *stream)
}
char*
prime_get_for(const char *id)
prime_get_for_id(const char *id)
{
return g_hash_table_lookup(idstubs, id);
}
void
prime_for_query(const char *query, char *stream)
{
if (querystubs) {
XMPPStanza *stanza = parse_stanza(stream);
g_hash_table_insert(querystubs, strdup(query), stanza);
}
}
XMPPStanza *
prime_get_for_query(const char *query)
{
return g_hash_table_lookup(querystubs, query);
}