mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-24 05:26:21 +00:00
Rage-cleanup.
While trying to get the unit tests working again I stumbled over all those things that I thought could be better^TM. Now we also know "TODO: why does this make the test fail?" - because the unit tests are brittle AF ... and we have to init the subsystems we use in the test, otherwise the cleanup will fail... BTW. you can now also only run a single test ... or a pattern or so ... you'd have to read how `cmocka_set_test_filter()` works exactly. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -77,22 +77,30 @@ _free_avatar_data(avatar_metadata* data)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_avatar_cleanup(void)
|
||||
{
|
||||
if (looking_for) {
|
||||
g_hash_table_destroy(looking_for);
|
||||
}
|
||||
if (shall_open) {
|
||||
g_hash_table_destroy(shall_open);
|
||||
}
|
||||
looking_for = NULL;
|
||||
shall_open = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
avatar_pep_subscribe(void)
|
||||
{
|
||||
prof_add_shutdown_routine(_avatar_cleanup);
|
||||
message_pubsub_event_handler_add(STANZA_NS_USER_AVATAR_METADATA, _avatar_metadata_handler, NULL, NULL);
|
||||
message_pubsub_event_handler_add(STANZA_NS_USER_AVATAR_DATA, _avatar_metadata_handler, NULL, NULL);
|
||||
|
||||
// caps_add_feature(XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY);
|
||||
|
||||
if (looking_for) {
|
||||
g_hash_table_destroy(looking_for);
|
||||
}
|
||||
_avatar_cleanup();
|
||||
looking_for = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
|
||||
|
||||
if (shall_open) {
|
||||
g_hash_table_destroy(shall_open);
|
||||
}
|
||||
shall_open = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ _chat_session_new(const char* const barejid, const char* const resource, gboolea
|
||||
assert(barejid != NULL);
|
||||
assert(resource != NULL);
|
||||
|
||||
ChatSession* new_session = malloc(sizeof(struct chat_session_t));
|
||||
ChatSession* new_session = calloc(1, sizeof(*new_session));
|
||||
new_session->barejid = strdup(barejid);
|
||||
new_session->resource = strdup(resource);
|
||||
new_session->resource_override = resource_override;
|
||||
@@ -88,8 +88,10 @@ chat_sessions_init(void)
|
||||
void
|
||||
chat_sessions_clear(void)
|
||||
{
|
||||
if (sessions)
|
||||
if (sessions) {
|
||||
g_hash_table_remove_all(sessions);
|
||||
sessions = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -101,7 +103,7 @@ chat_session_resource_override(const char* const barejid, const char* const reso
|
||||
ChatSession*
|
||||
chat_session_get(const char* const barejid)
|
||||
{
|
||||
return g_hash_table_lookup(sessions, barejid);
|
||||
return sessions ? g_hash_table_lookup(sessions, barejid) : NULL;
|
||||
}
|
||||
|
||||
char*
|
||||
|
||||
@@ -320,7 +320,6 @@ void
|
||||
iq_handlers_clear(void)
|
||||
{
|
||||
if (id_handlers) {
|
||||
g_hash_table_remove_all(id_handlers);
|
||||
g_hash_table_destroy(id_handlers);
|
||||
id_handlers = NULL;
|
||||
}
|
||||
@@ -410,7 +409,6 @@ void
|
||||
iq_rooms_cache_clear(void)
|
||||
{
|
||||
if (rooms_cache) {
|
||||
g_hash_table_remove_all(rooms_cache);
|
||||
g_hash_table_destroy(rooms_cache);
|
||||
rooms_cache = NULL;
|
||||
}
|
||||
|
||||
@@ -320,13 +320,9 @@ _handle_form(xmpp_stanza_t* const stanza)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
message_handlers_init(void)
|
||||
static void
|
||||
_message_handlers_cleanup(void)
|
||||
{
|
||||
xmpp_conn_t* const conn = connection_get_conn();
|
||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||
xmpp_handler_add(conn, _message_handler, NULL, STANZA_NAME_MESSAGE, NULL, ctx);
|
||||
|
||||
if (pubsub_event_handlers) {
|
||||
GList* keys = g_hash_table_get_keys(pubsub_event_handlers);
|
||||
GList* curr = keys;
|
||||
@@ -340,7 +336,17 @@ message_handlers_init(void)
|
||||
g_list_free(keys);
|
||||
g_hash_table_destroy(pubsub_event_handlers);
|
||||
}
|
||||
pubsub_event_handlers = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
message_handlers_init(void)
|
||||
{
|
||||
prof_add_shutdown_routine(_message_handlers_cleanup);
|
||||
xmpp_conn_t* const conn = connection_get_conn();
|
||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||
xmpp_handler_add(conn, _message_handler, NULL, STANZA_NAME_MESSAGE, NULL, ctx);
|
||||
_message_handlers_cleanup();
|
||||
pubsub_event_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user