diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-08-08 06:57:39 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-08-08 06:57:39 +0200 |
commit | bbe8afcbd436a1aa81090042f461da6999de3296 (patch) | |
tree | 38fe86960a82c654ab0dad1b6e052b956de4d5d5 /src | |
parent | 25f25073b9334fa2996678fc73c1729ce3d83839 (diff) | |
download | weechat-bbe8afcbd436a1aa81090042f461da6999de3296.zip |
xfer: move and rename function xfer_filename_crc32 to xfer-file.c
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/xfer/xfer-file.c | 53 | ||||
-rw-r--r-- | src/plugins/xfer/xfer-file.h | 1 | ||||
-rw-r--r-- | src/plugins/xfer/xfer.c | 55 |
3 files changed, 55 insertions, 54 deletions
diff --git a/src/plugins/xfer/xfer-file.c b/src/plugins/xfer/xfer-file.c index 67c7c78fa..6f69c7c23 100644 --- a/src/plugins/xfer/xfer-file.c +++ b/src/plugins/xfer/xfer-file.c @@ -37,6 +37,59 @@ /* + * Searches CRC32 in a filename. + * + * If more than one CRC32 are found, the last one is returned + * (with the higher index in filename). + * + * The chars before/after CRC32 must be either beginning/end of string or + * non-hexadecimal chars. + * + * Examples: + * + * test_filename => NULL (not found: no CRC32) + * test_1234abcd => "1234abcd" + * 1234abcd_test => "1234abcd" + * 1234abcd_12345678 => "12345678" + * 123456781234abcd => NULL (not found: missing delimiter around CRC32) + * + * Returns pointer to last CRC32 in string, NULL if no CRC32 was found. + */ + +const char * +xfer_file_search_crc32 (const char *filename) +{ + int length; + const char *ptr_string, *ptr_crc32; + + length = 0; + ptr_crc32 = NULL; + + ptr_string = filename; + while (ptr_string && ptr_string[0]) + { + if (((ptr_string[0] >= '0') && (ptr_string[0] <= '9')) + || ((ptr_string[0] >= 'A') && (ptr_string[0] <= 'F')) + || ((ptr_string[0] >= 'a') && (ptr_string[0] <= 'f'))) + { + length++; + } + else + { + if (length == 8) + ptr_crc32 = ptr_string - 8; + length = 0; + } + + ptr_string = weechat_utf8_next_char (ptr_string); + } + if (length == 8) + ptr_crc32 = ptr_string - 8; + + return ptr_crc32; +} + +/* * Resumes a download. * * Returns: diff --git a/src/plugins/xfer/xfer-file.h b/src/plugins/xfer/xfer-file.h index 13a5d4499..164945315 100644 --- a/src/plugins/xfer/xfer-file.h +++ b/src/plugins/xfer/xfer-file.h @@ -20,6 +20,7 @@ #ifndef WEECHAT_PLUGIN_XFER_FILE_H #define WEECHAT_PLUGIN_XFER_FILE_H +extern const char *xfer_file_search_crc32 (const char *filename); extern void xfer_file_find_filename (struct t_xfer *xfer); extern void xfer_file_calculate_speed (struct t_xfer *xfer, int ended); diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c index c068f806f..331c5f521 100644 --- a/src/plugins/xfer/xfer.c +++ b/src/plugins/xfer/xfer.c @@ -619,59 +619,6 @@ xfer_nick_auto_accepted (const char *server, const char *nick) } /* - * Searches CRC32 in a filename. - * - * If more than one CRC32 are found, the last one is returned - * (with the higher index in filename). - * - * The chars before/after CRC32 must be either beginning/end of string or - * non-hexadecimal chars. - * - * Examples: - * - * test_filename => -1 (not found: no CRC32) - * test_1234abcd => 5 ("1234abcd") - * 1234abcd_test => 0 ("1234abcd") - * 1234abcd_12345678 => 9 ("12345678") - * 123456789abcdef => -1 (not found: missing delimiter around CRC32) - * - * Returns pointer to last CRC32 in string, NULL if no CRC32 was found. - */ - -const char * -xfer_filename_crc32 (const char *filename) -{ - int length; - const char *ptr_string, *ptr_crc32; - - length = 0; - ptr_crc32 = NULL; - - ptr_string = filename; - while (ptr_string && ptr_string[0]) - { - if (((ptr_string[0] >= '0') && (ptr_string[0] <= '9')) - || ((ptr_string[0] >= 'A') && (ptr_string[0] <= 'F')) - || ((ptr_string[0] >= 'a') && (ptr_string[0] <= 'f'))) - { - length++; - } - else - { - if (length == 8) - ptr_crc32 = ptr_string - 8; - length = 0; - } - - ptr_string = weechat_utf8_next_char (ptr_string); - } - if (length == 8) - ptr_crc32 = ptr_string - 8; - - return ptr_crc32; -} - -/* * Adds a xfer to list. * * Returns pointer to new xfer, NULL if error. @@ -762,7 +709,7 @@ xfer_new (const char *plugin_name, const char *plugin_id, if ((type == XFER_TYPE_FILE_RECV) && weechat_config_boolean (xfer_config_file_auto_check_crc32)) { - ptr_crc32 = xfer_filename_crc32 (new_xfer->filename); + ptr_crc32 = xfer_file_search_crc32 (new_xfer->filename); if (ptr_crc32) { new_xfer->hash_handle = malloc (sizeof (gcry_md_hd_t)); |