diff --git a/src/core/context.c b/src/core/context.c index c60510e..c7dd6e2 100644 --- a/src/core/context.c +++ b/src/core/context.c @@ -11,14 +11,15 @@ #include #include "context.h" -extern struct BotXmppCtx *g_bctx = NULL; +/* static lifetime but only accessible here and through get and set functions below */ +static struct BotXmppCtx *g_bctx = NULL; struct BotXmppCtx *bot_get_ctx() { return g_bctx; } -void bot_set_ctx(struct BotXmppCtx *ctx) +void bot_set_ctx(struct BotXmppCtx * const ctx) { if(g_bctx) { fprintf(stderr, "Dev error: cannot set XMPP ctx twice in the same program run.\n"); @@ -137,7 +138,7 @@ return 0; } -int bot_xmpp_startup(struct BotUserInfo user, GString *avatarFile) +int bot_xmpp_startup(const struct BotUserInfo user, GString * const avatarFile) { xmpp_log_t* newLog; xmpp_ctx_t* newCtx; diff --git a/src/core/context.h b/src/core/context.h index f53f584..d0d25b8 100644 --- a/src/core/context.h +++ b/src/core/context.h @@ -8,24 +8,24 @@ #pragma once #include "handlers.h" -struct BotUserInfo { +typedef struct BotUserInfo { GString* jid; GString* pass; -}; +} BotUserInfo; -struct BotXmppCtx { +typedef struct BotXmppCtx { xmpp_log_t* log; xmpp_ctx_t* ctx; xmpp_conn_t* conn; -}; +} BotXmppCtx; -void bot_free_user_data(struct BotUserInfo user, GString *filename, bool freeSegment); +void bot_free_user_data(const BotUserInfo user, GString *filename, bool freeSegment); /* sets the given avatar file (base64 encoded) */ -int bot_xmpp_set_avatar(struct BotXmppCtx * const bctx, const GString *avatarFile); +int bot_xmpp_set_avatar(BotXmppCtx * const bctx, const GString *avatarFile); /* perform xmpp startup, store in bctx if completed successfully */ -int bot_xmpp_startup(struct BotUserInfo user, GString *avatarFile); +int bot_xmpp_startup(const BotUserInfo user, GString * const avatarFile); /* teardown and free ctx and connection in bctx */ void bot_xmpp_shutdown(); @@ -33,7 +33,6 @@ /* send a reminder when SIGALARM is triggered */ void bot_reminder_alarm_func(int s); -/* global context for signal handling */ -extern struct BotXmppCtx *g_bctx; -struct BotXmppCtx *bot_get_ctx(); -void bot_set_ctx(struct BotXmppCtx *bctx); +/* static-lifetime context for signal handling */ +BotXmppCtx *bot_get_ctx(); +void bot_set_ctx(BotXmppCtx * const bctx); diff --git a/src/expenses/types.c b/src/expenses/types.c index e467a63..e99c163 100644 --- a/src/expenses/types.c +++ b/src/expenses/types.c @@ -7,10 +7,11 @@ #include #include "types.h" -extern BotCommand g_LastCommand = BOT_CMD_NONE; -extern BotExpenseEntry *g_LastExpenseEntry = NULL; -extern BotReminder *g_LastReminder = NULL; -extern GString *g_filename = NULL; +/* static lifetime but only accessible here and through get and set functions below */ +static BotCommand g_LastCommand = BOT_CMD_NONE; +static BotExpenseEntry *g_LastExpenseEntry = NULL; +static BotReminder *g_LastReminder = NULL; +static GString *g_filename = NULL; BotCommand bot_get_last_command() { diff --git a/src/expenses/types.h b/src/expenses/types.h index 9899731..7731f0b 100644 --- a/src/expenses/types.h +++ b/src/expenses/types.h @@ -73,21 +73,17 @@ ); /* use this to check the last received command when responding */ -extern BotCommand g_LastCommand; BotCommand bot_get_last_command(); void bot_set_last_command(BotCommand cmd); /* store the last expense in memory */ -extern BotExpenseEntry *g_LastExpenseEntry; BotExpenseEntry *bot_get_last_expense(); void bot_set_last_expense(BotExpenseEntry *entry); /* store the last reminder in memory */ -extern BotReminder *g_LastReminder; BotReminder *bot_get_last_reminder(); void bot_set_last_reminder(BotReminder *reminder); /* store the filename in memory */ -extern GString *g_filename; GString *bot_get_filename(); void bot_set_filename(GString *fn);