From d13e781d66b4c2df75ee84d9b78d76558f623af3 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 16 Sep 2019 20:41:06 -0400 Subject: [PATCH] zephyr: Fix const-ness of variable loading. --- libpurple/protocols/zephyr/ZVariables.c | 26 +++++++++---------- libpurple/protocols/zephyr/zephyr.c | 37 ++++++++++++++-------------- libpurple/protocols/zephyr/zephyr_internal.h | 2 +- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/libpurple/protocols/zephyr/ZVariables.c b/libpurple/protocols/zephyr/ZVariables.c index 566d29d6a1..f88faa9e34 100644 --- a/libpurple/protocols/zephyr/ZVariables.c +++ b/libpurple/protocols/zephyr/ZVariables.c @@ -19,13 +19,14 @@ #endif static char *get_localvarfile(void); -static char *get_varval(char *fn, char *val); -static int varline(char *bfr, char *var); +static const gchar *get_varval(const gchar *fn, const gchar *val); +static int varline(const gchar *bfr, const gchar *var); -char *ZGetVariable(var) - char *var; +const gchar * +ZGetVariable(const gchar *var) { - char *varfile, *ret; + gchar *varfile; + const gchar *ret; if ((varfile = get_localvarfile()) == NULL) return ((char *)0); @@ -162,12 +163,11 @@ static char *get_localvarfile(void) return g_strconcat(base, "/.zephyr.vars", NULL); } -static char *get_varval(fn, var) - char *fn; - char *var; +static const gchar * +get_varval(const gchar *fn, const gchar *var) { FILE *fp; - static char varbfr[512]; + static gchar varbfr[512]; int i; fp = fopen(fn, "r"); @@ -188,12 +188,10 @@ static char *get_varval(fn, var) /* If the variable in the line bfr[] is the same as var, return index to the variable value, else return 0. */ -static int varline(bfr, var) - char *bfr; - char *var; +static int +varline(const gchar *bfr, const gchar *var) { - register char *cp; - + register const gchar *cp; if (!bfr[0] || bfr[0] == '#') /* comment or null line */ return (0); diff --git a/libpurple/protocols/zephyr/zephyr.c b/libpurple/protocols/zephyr/zephyr.c index 991fdf0acc..80d46e71ec 100644 --- a/libpurple/protocols/zephyr/zephyr.c +++ b/libpurple/protocols/zephyr/zephyr.c @@ -1368,10 +1368,11 @@ static gint check_loc(gpointer data) #endif /* WIN32 */ -static char *get_exposure_level(void) +static const gchar * +get_exposure_level(void) { /* XXX add real error reporting */ - char *exposure = ZGetVariable("exposure"); + const gchar *exposure = ZGetVariable("exposure"); if (!exposure) return EXPOSE_REALMVIS; @@ -1551,22 +1552,20 @@ static void process_anyone(PurpleConnection *gc) g_free(filename); } -static char* normalize_zephyr_exposure(const char* exposure) { - char *exp2 = g_strstrip(g_ascii_strup(exposure,-1)); +static gchar * +normalize_zephyr_exposure(const gchar *exposure) +{ + gchar *exp2 = g_strstrip(g_ascii_strup(exposure, -1)); - if (!exp2) - return EXPOSE_REALMVIS; - if (!g_ascii_strcasecmp(exp2, EXPOSE_NONE)) - return EXPOSE_NONE; - if (!g_ascii_strcasecmp(exp2, EXPOSE_OPSTAFF)) - return EXPOSE_OPSTAFF; - if (!g_ascii_strcasecmp(exp2, EXPOSE_REALMANN)) - return EXPOSE_REALMANN; - if (!g_ascii_strcasecmp(exp2, EXPOSE_NETVIS)) - return EXPOSE_NETVIS; - if (!g_ascii_strcasecmp(exp2, EXPOSE_NETANN)) - return EXPOSE_NETANN; - return EXPOSE_REALMVIS; + if (!exp2) { + return g_strdup(EXPOSE_REALMVIS); + } + if (g_str_equal(exp2, EXPOSE_NONE) || g_str_equal(exp2, EXPOSE_OPSTAFF) || + g_str_equal(exp2, EXPOSE_REALMANN) || + g_str_equal(exp2, EXPOSE_NETVIS) || g_str_equal(exp2, EXPOSE_NETANN)) { + return exp2; + } + return g_strdup(EXPOSE_REALMVIS); } static void zephyr_login(PurpleAccount * account) @@ -1594,7 +1593,7 @@ static void zephyr_login(PurpleAccount * account) zephyr->account = account; /* Make sure that the exposure (visibility) is set to a sane value */ - zephyr->exposure=g_strdup(normalize_zephyr_exposure(exposure)); + zephyr->exposure = normalize_zephyr_exposure(exposure); if (purple_account_get_bool(purple_connection_get_account(gc),"use_tzc",0)) { zephyr->connection_type = PURPLE_ZEPHYR_TZC; @@ -2915,7 +2914,7 @@ static void zephyr_protocol_init(PurpleProtocol *protocol) { PurpleAccountOption *option; - char *tmp = get_exposure_level(); + const gchar *tmp = get_exposure_level(); protocol->id = "prpl-zephyr"; protocol->name = "Zephyr"; diff --git a/libpurple/protocols/zephyr/zephyr_internal.h b/libpurple/protocols/zephyr/zephyr_internal.h index df28c685d8..273c5ab7d2 100644 --- a/libpurple/protocols/zephyr/zephyr_internal.h +++ b/libpurple/protocols/zephyr/zephyr_internal.h @@ -141,7 +141,7 @@ typedef Code_t (*Z_AuthProc)(ZNotice_t *, char *, int, int *); Code_t ZMakeAuthentication(ZNotice_t *, char *, int, int *); char *ZGetSender(void); -char *ZGetVariable(char *); +const gchar *ZGetVariable(const gchar *); Code_t ZSetVariable(char *var, char *value); Code_t ZUnsetVariable(char *var); int ZGetWGPort(void); -- 2.11.4.GIT