From bbe8afcbd436a1aa81090042f461da6999de3296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Mon, 8 Aug 2022 06:57:39 +0200 Subject: [PATCH] xfer: move and rename function xfer_filename_crc32 to xfer-file.c --- src/plugins/xfer/xfer-file.c | 53 ++++++++++++++++++++++++++++++++++ src/plugins/xfer/xfer-file.h | 1 + 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 @@ -36,6 +36,59 @@ #include "xfer-config.h" +/* + * 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. * 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 @@ -618,59 +618,6 @@ xfer_nick_auto_accepted (const char *server, const char *nick) return rc; } -/* - * 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. * @@ -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));