mirror of
https://github.com/weechat/weechat.git
synced 2026-07-06 17:53:13 +02:00
xfer: move and rename function xfer_filename_crc32 to xfer-file.c
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
+1
-54
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user