Sun, 15 May 2022 02:27:58 -0500
Remove a bunch of utility functions that were no longer used.
Testing Done:
compiled and ran the unit tests
Reviewed at https://reviews.imfreedom.org/r/1448/
| ChangeLog.API | file | annotate | diff | comparison | revisions | |
| libpurple/tests/test_util.c | file | annotate | diff | comparison | revisions | |
| libpurple/util.c | file | annotate | diff | comparison | revisions | |
| libpurple/util.h | file | annotate | diff | comparison | revisions |
--- a/ChangeLog.API Sun May 15 02:27:07 2022 -0500 +++ b/ChangeLog.API Sun May 15 02:27:58 2022 -0500 @@ -437,6 +437,7 @@ yourself. See GLib Main Event Loop docs. * purple_fd_get_ip. Use GSocket instead. * purple_find_pounce + * purple_gai_strerror * PurpleGetPublicAliasSuccessCallback * PurpleGetPublicAliasFailureCallback * purple_get_attention_type_from_code @@ -463,6 +464,7 @@ purple_mime_part_get_data_decoded, purple_mime_part_get_length, purple_mime_part_set_data, and purple_mime_decode_field. Use the GMime library, instead. + * purple_mkstemp * purple_network_convert_idn_to_ascii. Use g_hostname_to_ascii, instead. * purple_network_get_all_local_system_ips. Use libnice instead. @@ -492,6 +494,7 @@ * PurplePluginType * PurplePluginPriority * PurplePluginLoaderInfo + * PurplePluginProtocolInfo * PurplePluginUiInfo * purple_plugin_ipc_* * purple_plugin_is_unloadable @@ -563,7 +566,7 @@ * purple_presence_new_for_account * purple_presence_new_for_buddy * purple_print_utf8_to_console - * PurplePluginProtocolInfo + * purple_program_is_valid * pidgin_protocol_option_menu_new * purple_proxy_connect_socks5 * purple_proxy_connect_socks5_account @@ -586,6 +589,7 @@ * purple_roomlist_get_fields * purple_roomlist_get_protocol_data * purple_roomlist_set_protocol_data + * purple_running_osx * PurpleSetPublicAliasFailureCallback * PurpleSetPublicAliasSuccessCallback * purple_smiley_get_type @@ -643,6 +647,8 @@ * purple_srv_cancel * purple_srv_resolve_account * purple_srv_txt_query_destroy + * purple_str_add_cr + * purple_strcasereplace * PurpleStunNatType * PurpleStunNatDiscovery.type * PURPLE_SSL_DEFAULT_PORT @@ -684,6 +690,8 @@ * purple_txt_cancel * purple_txt_resolve_account * PurpleType, use GType instead. + * purple_unescape_filename + * purple_url_decode * purple_utf8_salvage. Use g_utf8_make_valid instead. * purple_utf8_strftime * purple_util_write_data_to_file_absolute. Use g_file_set_contents
--- a/libpurple/tests/test_util.c Sun May 15 02:27:07 2022 -0500 +++ b/libpurple/tests/test_util.c Sun May 15 02:27:58 2022 -0500 @@ -39,15 +39,6 @@ g_assert_cmpstr("%21oo", ==, purple_escape_filename("!oo")); } -static void -test_util_filename_unescape(void) { - g_assert_cmpstr("bar", ==, purple_unescape_filename("bar")); - g_assert_cmpstr("@ar", ==, purple_unescape_filename("@ar")); - g_assert_cmpstr("!ar", ==, purple_unescape_filename("!ar")); - g_assert_cmpstr("!ar", ==, purple_unescape_filename("%21ar")); - g_assert_cmpstr("%ar", ==, purple_unescape_filename("%25ar")); -} - /****************************************************************************** * text_strip tests *****************************************************************************/ @@ -239,8 +230,6 @@ g_test_add_func("/util/filename/escape", test_util_filename_escape); - g_test_add_func("/util/filename/unescape", - test_util_filename_unescape); g_test_add_func("/util/mnemonic/strip", test_util_text_strip_mnemonic);
--- a/libpurple/util.c Sun May 15 02:27:07 2022 -0500 +++ b/libpurple/util.c Sun May 15 02:27:58 2022 -0500 @@ -201,88 +201,6 @@ return purple_xmlnode_from_file(purple_data_dir(), filename, description, "util"); } -/* - * Like mkstemp() but returns a file pointer, uses a pre-set template, - * uses the semantics of tempnam() for the directory to use and allocates - * the space for the filepath. - * - * Caller is responsible for closing the file and removing it when done, - * as well as freeing the space pointed-to by "path" with g_free(). - * - * Returns NULL on failure and cleans up after itself if so. - */ -static const char *purple_mkstemp_templ = {"purpleXXXXXX"}; - -FILE * -purple_mkstemp(char **fpath, gboolean binary) -{ - const gchar *tmpdir; - int fd; - FILE *fp = NULL; - - g_return_val_if_fail(fpath != NULL, NULL); - - if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) { - if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, purple_mkstemp_templ)) != NULL) { - fd = g_mkstemp(*fpath); - if(fd == -1) { - purple_debug_error("purple_mkstemp", "Couldn't make \"%s\", error: %d", - *fpath, errno); - } else { - if((fp = fdopen(fd, "r+")) == NULL) { - close(fd); - purple_debug_error("purple_mkstemp", "Couldn't fdopen(), error: %d", errno); - } - } - - if(!fp) { - g_free(*fpath); - *fpath = NULL; - } - } - } else { - purple_debug_error("purple_mkstemp", "g_get_tmp_dir() failed!"); - } - - return fp; -} - -gboolean -purple_program_is_valid(const char *program) -{ - GError *error = NULL; - char **argv; - gchar *progname; - gboolean is_valid = FALSE; - - g_return_val_if_fail(program != NULL, FALSE); - g_return_val_if_fail(*program != '\0', FALSE); - - if (!g_shell_parse_argv(program, NULL, &argv, &error)) { - purple_debug_error("program_is_valid", "Could not parse program '%s': %s", - program, error->message); - g_error_free(error); - return FALSE; - } - - if (argv == NULL) { - return FALSE; - } - - progname = g_find_program_in_path(argv[0]); - is_valid = (progname != NULL); - - if(purple_debug_is_verbose()) - purple_debug_info("program_is_valid", "Tested program %s. %s.\n", program, - is_valid ? "Valid" : "Invalid"); - - g_strfreev(argv); - g_free(progname); - - return is_valid; -} - - gboolean purple_running_gnome(void) { @@ -332,16 +250,6 @@ #endif } -gboolean -purple_running_osx(void) -{ -#if defined(__APPLE__) - return TRUE; -#else - return FALSE; -#endif -} - /************************************************************************** * String Functions **************************************************************************/ @@ -462,39 +370,6 @@ return (g_ascii_strncasecmp(s, p, strlen(p)) == 0); } -char * -purple_str_add_cr(const char *text) -{ - char *ret = NULL; - int count = 0, j; - guint i; - - g_return_val_if_fail(text != NULL, NULL); - - if (text[0] == '\n') - count++; - for (i = 1; i < strlen(text); i++) - if (text[i] == '\n' && text[i - 1] != '\r') - count++; - - if (count == 0) - return g_strdup(text); - - ret = g_malloc0(strlen(text) + count + 1); - - i = 0; j = 0; - if (text[i] == '\n') - ret[j++] = '\r'; - ret[j++] = text[i++]; - for (; i < strlen(text); i++) { - if (text[i] == '\n' && text[i - 1] != '\r') - ret[j++] = '\r'; - ret[j++] = text[i]; - } - - return ret; -} - void purple_str_strip_char(char *text, char thechar) { @@ -543,54 +418,6 @@ return ret; } -gchar * -purple_strcasereplace(const char *string, const char *delimiter, - const char *replacement) -{ - gchar *ret; - int length_del, length_rep, i, j; - - g_return_val_if_fail(string != NULL, NULL); - g_return_val_if_fail(delimiter != NULL, NULL); - g_return_val_if_fail(replacement != NULL, NULL); - - length_del = strlen(delimiter); - length_rep = strlen(replacement); - - /* Count how many times the delimiter appears */ - i = 0; /* position in the source string */ - j = 0; /* number of occurrences of "delimiter" */ - while (string[i] != '\0') { - if (!g_ascii_strncasecmp(&string[i], delimiter, length_del)) { - i += length_del; - j += length_rep; - } else { - i++; - j++; - } - } - - ret = g_malloc(j+1); - - i = 0; /* position in the source string */ - j = 0; /* position in the destination string */ - while (string[i] != '\0') { - if (!g_ascii_strncasecmp(&string[i], delimiter, length_del)) { - strncpy(&ret[j], replacement, length_rep); - i += length_del; - j += length_rep; - } else { - ret[j] = string[i]; - i++; - j++; - } - } - - ret[j] = '\0'; - - return ret; -} - /** TODO: Expose this when we can add API */ static const char * purple_strcasestr_len(const char *haystack, gssize hlen, const char *needle, gssize nlen) @@ -769,50 +596,6 @@ } const char * -purple_url_decode(const char *str) -{ - static char buf[BUF_LEN]; - guint i, j = 0; - char *bum; - char hex[3]; - - g_return_val_if_fail(str != NULL, NULL); - - /* - * XXX - This check could be removed and buf could be made - * dynamically allocated, but this is easier. - */ - if (strlen(str) >= BUF_LEN) - return NULL; - - for (i = 0; i < strlen(str); i++) { - - if (str[i] != '%') - buf[j++] = str[i]; - else { - strncpy(hex, str + ++i, 2); - hex[2] = '\0'; - - /* i is pointing to the start of the number */ - i++; - - /* - * Now it's at the end and at the start of the for loop - * will be at the next character. - */ - buf[j++] = strtol(hex, NULL, 16); - } - } - - buf[j] = '\0'; - - if (!g_utf8_validate(buf, -1, (const char **)&bum)) - *bum = '\0'; - - return buf; -} - -const char * purple_url_encode(const char *str) { const char *iter; @@ -1067,55 +850,6 @@ return workstr; } -/* - * This function is copied from g_strerror() but changed to use - * gai_strerror(). - */ -const gchar * -purple_gai_strerror(gint errnum) -{ - static GPrivate msg_private = G_PRIVATE_INIT(g_free); - char *msg; - int saved_errno = errno; - - const char *msg_locale; - - msg_locale = gai_strerror(errnum); - if (g_get_charset(NULL)) - { - /* This string is already UTF-8--great! */ - errno = saved_errno; - return msg_locale; - } - else - { - gchar *msg_utf8 = g_locale_to_utf8(msg_locale, -1, NULL, NULL, NULL); - if (msg_utf8) - { - /* Stick in the quark table so that we can return a static result */ - GQuark msg_quark = g_quark_from_string(msg_utf8); - g_free(msg_utf8); - - msg_utf8 = (gchar *)g_quark_to_string(msg_quark); - errno = saved_errno; - return msg_utf8; - } - } - - msg = g_private_get(&msg_private); - - if (!msg) - { - msg = g_new(gchar, 64); - g_private_set(&msg_private, msg); - } - - sprintf(msg, "unknown error (%d)", errnum); - - errno = saved_errno; - return msg; -} - char * purple_utf8_ncr_encode(const char *str) { @@ -1348,11 +1082,6 @@ return out; } -const char* purple_unescape_filename(const char *escaped) { - return purple_url_decode(escaped); -} - - /* this is almost identical to purple_url_encode (hence purple_url_decode * being used above), but we want to keep certain characters unescaped * for compat reasons */
--- a/libpurple/util.h Sun May 15 02:27:07 2022 -0500 +++ b/libpurple/util.h Sun May 15 02:27:58 2022 -0500 @@ -37,8 +37,6 @@ #include "purpleprotocol.h" -typedef char *(*PurpleInfoFieldFormatCallback)(const char *field, size_t len); - G_BEGIN_DECLS /** @@ -286,41 +284,11 @@ PurpleXmlNode * purple_util_read_xml_from_data_file(const char *filename, const char *description); -/** - * purple_mkstemp: - * @path: The returned path to the temp file. - * @binary: Text or binary, for platforms where it matters. - * - * Creates a temporary file and returns a file pointer to it. - * - * This is like mkstemp(), but returns a file pointer and uses a - * pre-set template. It uses the semantics of tempnam() for the - * directory to use and allocates the space for the file path. - * - * The caller is responsible for closing the file and removing it when - * done, as well as freeing the space pointed to by @path with - * g_free(). - * - * Returns: A file pointer to the temporary file, or %NULL on failure. - */ -FILE *purple_mkstemp(char **path, gboolean binary); - - /**************************************************************************/ /* Environment Detection Functions */ /**************************************************************************/ /** - * purple_program_is_valid: - * @program: The file name of the application. - * - * Checks if the given program name is valid and executable. - * - * Returns: TRUE if the program is runable. - */ -gboolean purple_program_is_valid(const char *program); - -/** * purple_running_gnome: * * Check if running GNOME. @@ -338,16 +306,6 @@ */ gboolean purple_running_kde(void); -/** - * purple_running_osx: - * - * Check if running OS X. - * - * Returns: TRUE if running OS X, FALSE otherwise. - */ -gboolean purple_running_osx(void); - - /**************************************************************************/ /* String Functions */ /**************************************************************************/ @@ -440,16 +398,6 @@ gchar *purple_strdup_withhtml(const gchar *src); /** - * purple_str_add_cr: - * @str: The source string. - * - * Ensures that all linefeeds have a matching carriage return. - * - * Returns: The string with carriage returns. - */ -char *purple_str_add_cr(const char *str); - -/** * purple_str_strip_char: * @str: The string to strip characters from. * @thechar: The character to strip from the given string. @@ -521,23 +469,6 @@ */ char *purple_utf8_ncr_decode(const char *in); - -/** - * purple_strcasereplace: - * @string: The string from which to replace stuff. - * @delimiter: The substring you want replaced. - * @replacement: The substring you want inserted in place - * of the delimiting substring. - * - * Given a string, this replaces one substring with another - * ignoring case and returns a newly allocated string. - * - * Returns: A new string, after performing the substitution. - * free this with g_free(). - */ -gchar *purple_strcasereplace(const char *string, const char *delimiter, - const char *replacement); - /** * purple_strcasestr: * @haystack: The string to search in. @@ -578,18 +509,6 @@ void purple_got_protocol_handler_uri(const char *uri); /** - * purple_url_decode: - * @str: The string to translate. - * - * Decodes a URL into a plain string. - * - * This will change hex codes and such to their ascii equivalents. - * - * Returns: The resulting string. - */ -const char *purple_url_decode(const char *str); - -/** * purple_url_encode: * @str: The string to translate. * @@ -683,18 +602,6 @@ gchar *purple_utf8_strip_unprintables(const gchar *str); /** - * purple_gai_strerror: - * @errnum: The error code. - * - * Return the UTF-8 version of #gai_strerror. It calls #gai_strerror - * then converts the result to UTF-8. This function is analogous to - * g_strerror(). - * - * Returns: The UTF-8 error message. - */ -const gchar *purple_gai_strerror(gint errnum); - -/** * purple_utf8_strcasecmp: * @a: The first string. * @b: The second string. @@ -747,18 +654,6 @@ char *purple_text_strip_mnemonic(const char *in); /** - * purple_unescape_filename: - * @str: The string to translate. - * - * Does the reverse of purple_escape_filename - * - * This will change hex codes and such to their ascii equivalents. - * - * Returns: The resulting string. - */ -const char *purple_unescape_filename(const char *str); - -/** * purple_escape_filename: * @str: The string to translate. *