# HG changeset patch # User Nathan Walp # Date 1093999718 0 # Node ID b23e70bd1215daa0266fb23b63e3ab09dfebf67f # Parent 4e7590473515043d1158efae85b062f30858b2de [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 diff -r 4e7590473515 -r b23e70bd1215 src/blist.c --- 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); } diff -r 4e7590473515 -r b23e70bd1215 src/log.c --- 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; } diff -r 4e7590473515 -r b23e70bd1215 src/util.c --- 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; +} + + diff -r 4e7590473515 -r b23e70bd1215 src/util.h --- 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