Mercurial > pidgin
changeset 9926:b23e70bd1215
[gaim-migrate @ 10818]
remove some code duplication, add some code duplication, make these
functions accessable to other stuff, and apparently a random whitespace cleanup
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Wed, 01 Sep 2004 00:48:38 +0000 |
parents | 4e7590473515 |
children | fb08a0973b3e |
files | src/blist.c src/log.c src/util.c src/util.h |
diffstat | 4 files changed, 60 insertions(+), 93 deletions(-) [+] |
line wrap: on
line diff
--- a/src/blist.c Wed Sep 01 00:46:42 2004 +0000 +++ b/src/blist.c Wed Sep 01 00:48:38 2004 +0000 @@ -655,7 +655,7 @@ gaim_blist_node_remove_setting((GaimBlistNode *)buddy, "buddy_icon"); schedule_blist_save(); - + gaim_blist_update_buddy_icon(buddy); }
--- a/src/log.c Wed Sep 01 00:46:42 2004 +0000 +++ b/src/log.c Wed Sep 01 00:48:38 2004 +0000 @@ -178,115 +178,31 @@ return size; } -#if 0 -static char* unescape_filename(const char *escaped) { - const char *c = escaped; - GString *ret; - - if (escaped == NULL) - return NULL; - - ret = g_string_new(""); - - /** - * <>:"/\ |?*'&$ - * The above chars are "taboo" for gaim log names and are URL escaped - * % is also escaped so we can convert back easily - */ - - while (*c) { - if (*c == '%') { - if (*(c + 1) && *(c + 2)) { - char hex[2]; - hex[0] = *(c + 1); - hex[1] = *(c + 2); - unsigned char *nonhex; - gaim_base16_decode(hex, &nonhex); - ret = g_string_append_c(ret, *nonhex); - g_free(nonhex); - c += 2; - } - } else { - ret = g_string_append_c(ret, *c); - } - c++; - } - - return g_string_free(ret, FALSE); -} -#endif - -static char* escape_filename(const char *unescaped) { - const char *c = unescaped; - char *hex; - GString *ret; - - if (unescaped == NULL) - return NULL; - - ret = g_string_new(""); - - /** - * <>:"/\ |?*'&$ - * The above chars are "taboo" for gaim log names and are URL escaped - * % is also escaped so we can convert back easily - */ - - while (*c) { - switch (*c) { - case '<': - case '>': - case ':': - case '"': - case '/': - case '\\': - case ' ': - case '|': - case '?': - case '*': - case '\'': - case '&': - case '$': - case '%': - hex = g_strdup_printf ("%%%X", (int) *c); - ret = g_string_append(ret, hex); - g_free(hex); - break; - default: - ret = g_string_append_c(ret, *c); - } - c++; - } - - return g_string_free(ret, FALSE); -} - static char* gaim_log_get_log_dir(GaimLogType type, const char *name, GaimAccount *account) { - char *acct_name = escape_filename(gaim_normalize(account, - gaim_account_get_username(account))); - char *target; + char *acct_name = g_strdup(gaim_escape_filename(gaim_normalize(account, + gaim_account_get_username(account)))); + const char *target; /* does this seem like a bad way to get this component of the path to anyone else? --Nathan */ const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO( gaim_find_prpl(gaim_account_get_protocol_id(account)) )->list_icon(account, NULL); - + char *dir; if (type == GAIM_LOG_CHAT) { char *temp = g_strdup_printf("%s.chat", gaim_normalize(account, name)); - target = escape_filename(temp); + target = gaim_escape_filename(temp); g_free(temp); } else if(type == GAIM_LOG_SYSTEM) { - target = g_strdup(".system"); + target = ".system"; } else { - target = escape_filename(gaim_normalize(account, name)); + target = gaim_escape_filename(gaim_normalize(account, name)); } dir = g_build_filename(gaim_user_dir(), "logs", prpl, acct_name, target, NULL); - g_free(target); + g_free(acct_name); - return dir; }
--- a/src/util.c Wed Sep 01 00:46:42 2004 +0000 +++ b/src/util.c Wed Sep 01 00:48:38 2004 +0000 @@ -3203,3 +3203,34 @@ return out; } +const char* gaim_unescape_filename(const char *escaped) { + return gaim_url_decode(escaped); +} + + +/* this is almost identical to gaim_url_encode (hence gaim_url_decode + * being used above), but we want to keep certain characters unescaped + * for compat reasons */ +const char * +gaim_escape_filename(const char *str) +{ + static char buf[BUF_LEN]; + guint i, j = 0; + + g_return_val_if_fail(str != NULL, NULL); + + for (i = 0; i < strlen(str); i++) { + if (isalnum(str[i]) || str[i] == '@') + buf[j++] = str[i]; + else { + sprintf(buf + j, "%%%02x", (unsigned char)str[i]); + j += 3; + } + } + + buf[j] = '\0'; + + return buf; +} + +
--- a/src/util.h Wed Sep 01 00:46:42 2004 +0000 +++ b/src/util.h Wed Sep 01 00:48:38 2004 +0000 @@ -736,6 +736,26 @@ */ #define gaim_add_eight(x) ((x)+8) +/** + * Does the reverse of gaim_escape_filename + * + * This will change hex codes and such to their ascii equivalents. + * + * @param str The string to translate. + * + * @return The resulting string. + */ +const char *gaim_unescape_filename(const char *str); + +/** + * Escapes filesystem-unfriendly characters from a filename + * + * @param str The string to translate. + * + * @return The resulting string. + */ +const char *gaim_escape_filename(const char *str); + #ifdef __cplusplus } #endif