Introduce our own shutdown callback mechanism.
Instead of adding stuff to `_shutdown()`, we can now register a shutdown routine from the respective `init()` function of our modules. This also has the advantage, that we're sure they're called in reverse order from how the initialization happened. I didn't simply use `atexit()` because POSIX says that the number of possible callbacks is limited (min 32) and I was not sure whether we will maybe extend this number at one point. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -69,10 +69,26 @@ static EntityCapabilities* _caps_by_ver(const char* const ver);
|
||||
static EntityCapabilities* _caps_by_jid(const char* const jid);
|
||||
static EntityCapabilities* _caps_copy(EntityCapabilities* caps);
|
||||
|
||||
static void
|
||||
_caps_close(void)
|
||||
{
|
||||
free_keyfile(&caps_prof_keyfile);
|
||||
cache = NULL;
|
||||
g_hash_table_destroy(jid_to_ver);
|
||||
g_hash_table_destroy(jid_to_caps);
|
||||
g_free(cache_loc);
|
||||
cache_loc = NULL;
|
||||
g_hash_table_destroy(prof_features);
|
||||
prof_features = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
caps_init(void)
|
||||
{
|
||||
log_info("Loading capabilities cache");
|
||||
|
||||
prof_add_shutdown_routine(_caps_close);
|
||||
|
||||
load_data_keyfile(&caps_prof_keyfile, FILE_CAPSCACHE);
|
||||
cache = caps_prof_keyfile.keyfile;
|
||||
|
||||
@@ -339,19 +355,6 @@ caps_reset_ver(void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
caps_close(void)
|
||||
{
|
||||
free_keyfile(&caps_prof_keyfile);
|
||||
cache = NULL;
|
||||
g_hash_table_destroy(jid_to_ver);
|
||||
g_hash_table_destroy(jid_to_caps);
|
||||
g_free(cache_loc);
|
||||
cache_loc = NULL;
|
||||
g_hash_table_destroy(prof_features);
|
||||
prof_features = NULL;
|
||||
}
|
||||
|
||||
static EntityCapabilities*
|
||||
_caps_by_ver(const char* const ver)
|
||||
{
|
||||
|
||||
@@ -91,17 +91,8 @@ static Occupant* _muc_occupant_new(const char* const nick, const char* const jid
|
||||
muc_affiliation_t affiliation, resource_presence_t presence, const char* const status);
|
||||
static void _occupant_free(Occupant* occupant);
|
||||
|
||||
void
|
||||
muc_init(void)
|
||||
{
|
||||
invite_ac = autocomplete_new();
|
||||
confservers_ac = autocomplete_new();
|
||||
rooms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_room);
|
||||
invite_passwords = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
}
|
||||
|
||||
void
|
||||
muc_close(void)
|
||||
static void
|
||||
_muc_close(void)
|
||||
{
|
||||
autocomplete_free(invite_ac);
|
||||
autocomplete_free(confservers_ac);
|
||||
@@ -113,6 +104,16 @@ muc_close(void)
|
||||
confservers_ac = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
muc_init(void)
|
||||
{
|
||||
prof_add_shutdown_routine(_muc_close);
|
||||
invite_ac = autocomplete_new();
|
||||
confservers_ac = autocomplete_new();
|
||||
rooms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_room);
|
||||
invite_passwords = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
}
|
||||
|
||||
void
|
||||
muc_confserver_add(const char* const server)
|
||||
{
|
||||
|
||||
@@ -82,7 +82,6 @@ typedef struct _muc_occupant_t
|
||||
} Occupant;
|
||||
|
||||
void muc_init(void);
|
||||
void muc_close(void);
|
||||
|
||||
void muc_join(const char* const room, const char* const nick, const char* const password, gboolean autojoin);
|
||||
void muc_leave(const char* const room);
|
||||
|
||||
@@ -99,10 +99,25 @@ static char* saved_status;
|
||||
static void _session_free_internals(void);
|
||||
static void _session_free_saved_details(void);
|
||||
|
||||
static void
|
||||
_session_shutdown(void)
|
||||
{
|
||||
_session_free_internals();
|
||||
|
||||
chat_sessions_clear();
|
||||
presence_sub_requests_destroy();
|
||||
|
||||
connection_shutdown();
|
||||
if (saved_status) {
|
||||
free(saved_status);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
session_init(void)
|
||||
{
|
||||
log_info("Initialising XMPP");
|
||||
prof_add_shutdown_routine(_session_shutdown);
|
||||
connection_init();
|
||||
presence_sub_requests_init();
|
||||
caps_init();
|
||||
@@ -227,20 +242,6 @@ session_disconnect(void)
|
||||
connection_set_disconnected();
|
||||
}
|
||||
|
||||
void
|
||||
session_shutdown(void)
|
||||
{
|
||||
_session_free_internals();
|
||||
|
||||
chat_sessions_clear();
|
||||
presence_sub_requests_destroy();
|
||||
|
||||
connection_shutdown();
|
||||
if (saved_status) {
|
||||
free(saved_status);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
session_process_events(void)
|
||||
{
|
||||
|
||||
@@ -183,7 +183,6 @@ jabber_conn_status_t session_connect_with_details(const char* const jid, const c
|
||||
jabber_conn_status_t session_connect_with_account(const ProfAccount* const account);
|
||||
|
||||
void session_disconnect(void);
|
||||
void session_shutdown(void);
|
||||
void session_process_events(void);
|
||||
const char* session_get_account_name(void);
|
||||
void session_reconnect_now(void);
|
||||
@@ -275,7 +274,6 @@ void iq_muc_register_nick(const char* const roomjid);
|
||||
void autoping_timer_extend(void);
|
||||
|
||||
EntityCapabilities* caps_lookup(const char* const jid);
|
||||
void caps_close(void);
|
||||
void caps_destroy(EntityCapabilities* caps);
|
||||
void caps_reset_ver(void);
|
||||
void caps_add_feature(char* feature);
|
||||
|
||||
Reference in New Issue
Block a user