clang-format

This commit is contained in:
Håvard Pettersson 2018-12-22 21:16:45 +01:00
parent 4ca6ae3169
commit d0ab7b0139
10 changed files with 402 additions and 340 deletions

View File

@ -19,21 +19,21 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <wordexp.h> #include <wordexp.h>
#include <tox/tox.h> #include <tox/tox.h>
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "twc-bootstrap.h" #include "twc-bootstrap.h"
#include "twc-tfer.h"
#include "twc-chat.h" #include "twc-chat.h"
#include "twc-config.h" #include "twc-config.h"
#include "twc-friend-request.h" #include "twc-friend-request.h"
#include "twc-group-invite.h" #include "twc-group-invite.h"
#include "twc-list.h" #include "twc-list.h"
#include "twc-profile.h" #include "twc-profile.h"
#include "twc-tfer.h"
#include "twc-utils.h" #include "twc-utils.h"
#include "twc.h" #include "twc.h"
@ -52,7 +52,8 @@ enum TWC_FRIEND_MATCH
#define TWC_CHECK_PROFILE(profile) \ #define TWC_CHECK_PROFILE(profile) \
if (!profile) \ if (!profile) \
{ \ { \
weechat_printf(NULL, "%s%s: command \"%s\" must be executed on a Tox " \ weechat_printf(NULL, \
"%s%s: command \"%s\" must be executed on a Tox " \
"buffer", \ "buffer", \
weechat_prefix("error"), weechat_plugin->name, \ weechat_prefix("error"), weechat_plugin->name, \
argv[0]); \ argv[0]); \
@ -66,10 +67,11 @@ enum TWC_FRIEND_MATCH
#define TWC_CHECK_CHAT(chat) \ #define TWC_CHECK_CHAT(chat) \
if (!chat) \ if (!chat) \
{ \ { \
weechat_printf( \ weechat_printf(NULL, \
NULL, "%s%s: command \"%s\" must be executed in a chat " \ "%s%s: command \"%s\" must be executed in a chat " \
"buffer", \ "buffer", \
weechat_prefix("error"), weechat_plugin->name, argv[0]); \ weechat_prefix("error"), weechat_plugin->name, \
argv[0]); \
return WEECHAT_RC_OK; \ return WEECHAT_RC_OK; \
} }
@ -80,10 +82,11 @@ enum TWC_FRIEND_MATCH
#define TWC_CHECK_GROUP_CHAT(chat) \ #define TWC_CHECK_GROUP_CHAT(chat) \
if (!chat || chat->group_number < 0) \ if (!chat || chat->group_number < 0) \
{ \ { \
weechat_printf( \ weechat_printf(NULL, \
NULL, "%s%s: command \"%s\" must be executed in a group " \ "%s%s: command \"%s\" must be executed in a group " \
"chat buffer ", \ "chat buffer ", \
weechat_prefix("error"), weechat_plugin->name, argv[0]); \ weechat_prefix("error"), weechat_plugin->name, \
argv[0]); \
return WEECHAT_RC_OK; \ return WEECHAT_RC_OK; \
} }
@ -143,8 +146,10 @@ enum TWC_FRIEND_MATCH
} }
#define TWC_RETURN_WITH_FILE_ERROR(filename, type) \ #define TWC_RETURN_WITH_FILE_ERROR(filename, type) \
weechat_printf(NULL, "%s\"%s\" must be a regular file or pipe, " \ weechat_printf(NULL, \
"not a %s", weechat_prefix("error"), filename, type); \ "%s\"%s\" must be a regular file or pipe, " \
"not a %s", \
weechat_prefix("error"), filename, type); \
return WEECHAT_RC_ERROR; return WEECHAT_RC_ERROR;
/** /**
@ -503,8 +508,8 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
/* /friend requests */ /* /friend requests */
else if (argc == 2 && weechat_strcasecmp(argv[1], "requests") == 0) else if (argc == 2 && weechat_strcasecmp(argv[1], "requests") == 0)
{ {
weechat_printf(profile->buffer, "%sPending friend requests:", weechat_printf(profile->buffer,
weechat_prefix("network")); "%sPending friend requests:", weechat_prefix("network"));
size_t index; size_t index;
struct t_twc_list_item *item; struct t_twc_list_item *item;
@ -514,7 +519,8 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
twc_bin2hex(item->friend_request->tox_id, TOX_PUBLIC_KEY_SIZE, twc_bin2hex(item->friend_request->tox_id, TOX_PUBLIC_KEY_SIZE,
hex_address); hex_address);
weechat_printf(profile->buffer, "%s[%d] Address: %s\n" weechat_printf(profile->buffer,
"%s[%d] Address: %s\n"
"[%d] Message: %s", "[%d] Message: %s",
weechat_prefix("network"), index, hex_address, index, weechat_prefix("network"), index, hex_address, index,
item->friend_request->message); item->friend_request->message);
@ -1142,7 +1148,8 @@ twc_cmd_tox(const void *pointer, void *data, struct t_gui_buffer *buffer,
} }
else else
{ {
weechat_printf(NULL, "%s%s: You must confirm deletion with either " weechat_printf(NULL,
"%s%s: You must confirm deletion with either "
"\"-keepdata\" or \"-yes\" (see /help tox)", "\"-keepdata\" or \"-yes\" (see /help tox)",
weechat_prefix("error"), weechat_plugin->name); weechat_prefix("error"), weechat_plugin->name);
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
@ -1217,14 +1224,17 @@ twc_cmd_send(const void *pointer, void *data, struct t_gui_buffer *buffer,
{ {
if (profile->buffer == buffer || profile->tfer->buffer == buffer) if (profile->buffer == buffer || profile->tfer->buffer == buffer)
{ {
weechat_printf(profile->buffer, "%s%s", weechat_prefix("error"), "you must specify a friend"); weechat_printf(profile->buffer, "%s%s", weechat_prefix("error"),
"you must specify a friend");
return WEECHAT_RC_ERROR; return WEECHAT_RC_ERROR;
} }
snprintf(recipient, TOX_MAX_NAME_LENGTH, "%s", weechat_buffer_get_string(buffer, "name")); snprintf(recipient, TOX_MAX_NAME_LENGTH, "%s",
weechat_buffer_get_string(buffer, "name"));
struct t_twc_chat *chat = twc_chat_search_buffer(buffer); struct t_twc_chat *chat = twc_chat_search_buffer(buffer);
if (chat->group_number != -1) if (chat->group_number != -1)
{ {
weechat_printf(profile->buffer, "%s%s", weechat_prefix("error"), "the file transmission is " weechat_printf(profile->buffer, "%s%s", weechat_prefix("error"),
"the file transmission is "
"allowed only between friends"); "allowed only between friends");
return WEECHAT_RC_ERROR; return WEECHAT_RC_ERROR;
} }
@ -1241,7 +1251,8 @@ twc_cmd_send(const void *pointer, void *data, struct t_gui_buffer *buffer,
/* do a shell split in case a friend has spaces in his name /* do a shell split in case a friend has spaces in his name
* and join the name */ * and join the name */
int shell_argc; int shell_argc;
char **shell_argv = weechat_string_split_shell(argv_eol[1], &shell_argc); char **shell_argv =
weechat_string_split_shell(argv_eol[1], &shell_argc);
for (int i = 0; i < shell_argc - 1; i++) for (int i = 0; i < shell_argc - 1; i++)
{ {
strcat(recipient, shell_argv[i]); strcat(recipient, shell_argv[i]);
@ -1277,30 +1288,34 @@ twc_cmd_send(const void *pointer, void *data, struct t_gui_buffer *buffer,
case S_IFLNK: case S_IFLNK:
break; break;
default: default:
weechat_printf(NULL, "%sunknown file type", weechat_prefix("error")); weechat_printf(NULL, "%sunknown file type",
weechat_prefix("error"));
return WEECHAT_RC_ERROR; return WEECHAT_RC_ERROR;
} }
char *stripped_name = twc_tfer_file_name_strip(filename, FILENAME_MAX + 1 - strlen(filename)); char *stripped_name =
twc_tfer_file_name_strip(filename, FILENAME_MAX + 1 - strlen(filename));
TOX_ERR_FILE_SEND error; TOX_ERR_FILE_SEND error;
uint32_t file_number = tox_file_send(profile->tox, friend_number, TOX_FILE_KIND_DATA, uint32_t file_number =
tox_file_send(profile->tox, friend_number, TOX_FILE_KIND_DATA,
S_ISFIFO(st.st_mode) ? UINT64_MAX : (size_t)st.st_size, S_ISFIFO(st.st_mode) ? UINT64_MAX : (size_t)st.st_size,
NULL, (uint8_t *)stripped_name, strlen(filename), &error); NULL, (uint8_t *)stripped_name, strlen(filename), &error);
free(stripped_name); free(stripped_name);
if (error != TOX_ERR_FILE_SEND_OK) if (error != TOX_ERR_FILE_SEND_OK)
{ {
weechat_printf(profile->buffer, "%ssending \"%s\" has been failed: %s", weechat_printf(profile->buffer, "%ssending \"%s\" has been failed: %s",
weechat_prefix("error"), filename, twc_tox_err_file_send(error)); weechat_prefix("error"), filename,
twc_tox_err_file_send(error));
return WEECHAT_RC_ERROR; return WEECHAT_RC_ERROR;
} }
if (!(profile->tfer->buffer)) if (!(profile->tfer->buffer))
{ {
twc_tfer_load(profile); twc_tfer_load(profile);
} }
struct t_twc_tfer_file *file = twc_tfer_file_new(profile, recipient, filename, struct t_twc_tfer_file *file = twc_tfer_file_new(
friend_number, file_number, profile, recipient, filename, friend_number, file_number, st.st_size,
st.st_size, TWC_TFER_FILE_TYPE_UPLOADING); TWC_TFER_FILE_TYPE_UPLOADING);
if (!file) if (!file)
{ {
weechat_printf(profile->buffer, "%scannot open the file \"%s\"", weechat_printf(profile->buffer, "%scannot open the file \"%s\"",
@ -1347,7 +1362,8 @@ twc_commands_init()
" || decline", " || decline",
twc_cmd_friend, NULL, NULL); twc_cmd_friend, NULL, NULL);
weechat_hook_command("group", "manage group chats", "create" weechat_hook_command("group", "manage group chats",
"create"
" || invites" " || invites"
" || join <number>" " || join <number>"
" || decline <number>", " || decline <number>",
@ -1416,7 +1432,8 @@ twc_commands_init()
NULL, NULL); NULL, NULL);
weechat_hook_command( weechat_hook_command(
"tox", "manage Tox profiles", "list" "tox", "manage Tox profiles",
"list"
" || create <name>" " || create <name>"
" || delete <name> -yes|-keepdata" " || delete <name> -yes|-keepdata"
" || load [<name>...]" " || load [<name>...]"
@ -1437,7 +1454,8 @@ twc_commands_init()
" || unload %(tox_loaded_profiles)|%*" " || unload %(tox_loaded_profiles)|%*"
" || reload %(tox_loaded_profiles)|%*", " || reload %(tox_loaded_profiles)|%*",
twc_cmd_tox, NULL, NULL); twc_cmd_tox, NULL, NULL);
weechat_hook_command("send", "send a file to a friend", weechat_hook_command(
"send", "send a file to a friend",
"<file>" "<file>"
" || <number>|<name>|<Tox ID> <file>", " || <number>|<name>|<Tox ID> <file>",
"file: path to the file\n" "file: path to the file\n"

View File

@ -40,9 +40,19 @@ struct t_config_option *twc_config_friend_request_message;
struct t_config_option *twc_config_short_id_size; struct t_config_option *twc_config_short_id_size;
char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] = { char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] = {
"save_file", "autoload", "autojoin", "autojoin_delay", "save_file",
"max_friend_requests", "proxy_address", "proxy_port", "proxy_type", "autoload",
"udp", "ipv6", "passphrase", "logging", "downloading_path", "autojoin",
"autojoin_delay",
"max_friend_requests",
"proxy_address",
"proxy_port",
"proxy_type",
"udp",
"ipv6",
"passphrase",
"logging",
"downloading_path",
}; };
/** /**
@ -227,7 +237,8 @@ twc_config_init_option(struct t_twc_profile *profile,
break; break;
case TWC_PROFILE_OPTION_AUTOJOIN_DELAY: case TWC_PROFILE_OPTION_AUTOJOIN_DELAY:
type = "integer"; type = "integer";
description = "delay befor do autojoin (in ms) this required to " description =
"delay befor do autojoin (in ms) this required to "
"tox from entering incorrect state and stop processing " "tox from entering incorrect state and stop processing "
"group events"; "group events";
min = 0; min = 0;
@ -291,7 +302,8 @@ twc_config_init_option(struct t_twc_profile *profile,
break; break;
case TWC_PROFILE_OPTION_DOWNLOADING_PATH: case TWC_PROFILE_OPTION_DOWNLOADING_PATH:
type = "string"; type = "string";
description = "path to downloaded files (\"%h\" will be replaced by " description =
"path to downloaded files (\"%h\" will be replaced by "
"WeeChat home folder and \"%p\" by profile name"; "WeeChat home folder and \"%p\" by profile name";
default_value = "%h/tfer/%p/"; default_value = "%h/tfer/%p/";
break; break;

View File

@ -58,7 +58,8 @@ twc_group_chat_invite_add(struct t_twc_profile *profile, int32_t friend_number,
invite->data_size = size; invite->data_size = size;
if (TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_AUTOJOIN)) if (TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_AUTOJOIN))
invite->autojoin_delay = TWC_PROFILE_OPTION_INTEGER(profile, TWC_PROFILE_OPTION_AUTOJOIN_DELAY); invite->autojoin_delay = TWC_PROFILE_OPTION_INTEGER(
profile, TWC_PROFILE_OPTION_AUTOJOIN_DELAY);
else else
invite->autojoin_delay = 0; invite->autojoin_delay = 0;

View File

@ -20,8 +20,8 @@
#ifndef TOX_WEECHAT_LIST_H #ifndef TOX_WEECHAT_LIST_H
#define TOX_WEECHAT_LIST_H #define TOX_WEECHAT_LIST_H
#include <stdlib.h>
#include "twc-tfer.h" #include "twc-tfer.h"
#include <stdlib.h>
struct t_twc_list struct t_twc_list
{ {

View File

@ -257,7 +257,8 @@ twc_tox_new_print_error(struct t_twc_profile *profile,
weechat_prefix("error"), options->proxy_host); weechat_prefix("error"), options->proxy_host);
break; break;
case TOX_ERR_NEW_LOAD_ENCRYPTED: case TOX_ERR_NEW_LOAD_ENCRYPTED:
weechat_printf(profile->buffer, "%scould not load Tox (encrypted " weechat_printf(profile->buffer,
"%scould not load Tox (encrypted "
"data files are not yet supported)", "data files are not yet supported)",
weechat_prefix("error")); weechat_prefix("error"));
break; break;
@ -394,7 +395,8 @@ twc_profile_load(struct t_twc_profile *profile)
{ {
weechat_printf(profile->buffer, weechat_printf(profile->buffer,
"%scould not decrypt Tox data file (no passphrase " "%scould not decrypt Tox data file (no passphrase "
"specified)", weechat_prefix("error")); "specified)",
weechat_prefix("error"));
return TWC_RC_ERROR; return TWC_RC_ERROR;
} }
} }
@ -453,13 +455,15 @@ twc_profile_load(struct t_twc_profile *profile)
tox_callback_friend_request(profile->tox, twc_friend_request_callback); tox_callback_friend_request(profile->tox, twc_friend_request_callback);
tox_callback_conference_invite(profile->tox, twc_group_invite_callback); tox_callback_conference_invite(profile->tox, twc_group_invite_callback);
tox_callback_conference_message(profile->tox, twc_group_message_callback); tox_callback_conference_message(profile->tox, twc_group_message_callback);
tox_callback_conference_peer_list_changed(profile->tox, tox_callback_conference_peer_list_changed(
twc_group_peer_list_changed_callback); profile->tox, twc_group_peer_list_changed_callback);
tox_callback_conference_peer_name(profile->tox, tox_callback_conference_peer_name(profile->tox,
twc_group_peer_name_callback); twc_group_peer_name_callback);
tox_callback_conference_title(profile->tox, twc_group_title_callback); tox_callback_conference_title(profile->tox, twc_group_title_callback);
tox_callback_file_recv_control(profile->tox, twc_file_recv_control_callback); tox_callback_file_recv_control(profile->tox,
tox_callback_file_chunk_request(profile->tox, twc_file_chunk_request_callback); twc_file_recv_control_callback);
tox_callback_file_chunk_request(profile->tox,
twc_file_chunk_request_callback);
tox_callback_file_recv(profile->tox, twc_file_recv_callback); tox_callback_file_recv(profile->tox, twc_file_recv_callback);
tox_callback_file_recv_chunk(profile->tox, twc_file_recv_chunk_callback); tox_callback_file_recv_chunk(profile->tox, twc_file_recv_chunk_callback);
@ -685,7 +689,8 @@ twc_profile_free(struct t_twc_profile *profile)
/* close tfer's buffer */ /* close tfer's buffer */
if (profile->tfer->buffer) if (profile->tfer->buffer)
{ {
weechat_buffer_set_pointer(profile->tfer->buffer, "close_callback", NULL); weechat_buffer_set_pointer(profile->tfer->buffer, "close_callback",
NULL);
weechat_buffer_close(profile->tfer->buffer); weechat_buffer_close(profile->tfer->buffer);
} }

View File

@ -17,40 +17,49 @@
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <time.h> #include <time.h>
#include <unistd.h>
#include <tox/tox.h> #include <tox/tox.h>
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "twc-tfer.h"
#include "twc-profile.h"
#include "twc-list.h" #include "twc-list.h"
#include "twc-profile.h"
#include "twc-tfer.h"
#include "twc-utils.h" #include "twc-utils.h"
#include "twc.h" #include "twc.h"
#define PROGRESS_BAR_LEN (50) #define PROGRESS_BAR_LEN (50)
#define TWC_TFER_UPDATE_STATUS_AND_RETURN(fmt, ...) {\ #define TWC_TFER_UPDATE_STATUS_AND_RETURN(fmt, ...) \
do \
{ \
sprintf(status, fmt, ##__VA_ARGS__); \ sprintf(status, fmt, ##__VA_ARGS__); \
twc_tfer_update_status(profile->tfer, status); \ twc_tfer_update_status(profile->tfer, status); \
weechat_string_free_split(argv); \ weechat_string_free_split(argv); \
free(status); \ free(status); \
return WEECHAT_RC_OK; \ return WEECHAT_RC_OK; \
} } while (0)
#define TWC_TFER_MESSAGE(present, past) {\ #define TWC_TFER_MESSAGE(present, past) \
do \
{ \
int result = twc_tfer_file_##present(profile, n); \ int result = twc_tfer_file_##present(profile, n); \
switch (result) \ switch (result) \
{ \ { \
case 1: \ case 1: \
TWC_TFER_UPDATE_STATUS_AND_RETURN("request number %ld has been " #past, n); \ TWC_TFER_UPDATE_STATUS_AND_RETURN( \
"request number %ld has been " #past, n); \
case 0: \ case 0: \
TWC_TFER_UPDATE_STATUS_AND_RETURN("request number %ld cannot be " #past " because " \ TWC_TFER_UPDATE_STATUS_AND_RETURN( \
"of tox internal issues", n); \ "request number %ld cannot be " #past " because " \
"of tox internal issues", \
n); \
case -1: \ case -1: \
TWC_TFER_UPDATE_STATUS_AND_RETURN("request number %ld cannot be " #past, n); \ TWC_TFER_UPDATE_STATUS_AND_RETURN( \
} }\ "request number %ld cannot be " #past, n); \
} \
} while (0)
/** /**
* Create a new "tfer" object that handles a list of transmitting files and * Create a new "tfer" object that handles a list of transmitting files and
@ -76,11 +85,9 @@ twc_tfer_load(struct t_twc_profile *profile)
struct t_gui_buffer *buffer; struct t_gui_buffer *buffer;
char *name = malloc(sizeof(profile->name) + 5); char *name = malloc(sizeof(profile->name) + 5);
sprintf(name, "tfer/%s", profile->name); sprintf(name, "tfer/%s", profile->name);
profile->tfer->buffer = buffer = weechat_buffer_new(name, profile->tfer->buffer = buffer = weechat_buffer_new(
twc_tfer_buffer_input_callback, name, twc_tfer_buffer_input_callback, (void *)profile, NULL,
(void *)profile, NULL, twc_tfer_buffer_close_callback, (void *)profile, NULL);
twc_tfer_buffer_close_callback,
(void *)profile, NULL);
free(name); free(name);
if (!buffer) if (!buffer)
return TWC_RC_ERROR; return TWC_RC_ERROR;
@ -104,9 +111,7 @@ twc_tfer_print_legend(struct t_twc_tfer *tfer)
char *text[TWC_TFER_LEGEND_LINES] = { char *text[TWC_TFER_LEGEND_LINES] = {
"status: OK", /* This line is reserved for the status */ "status: OK", /* This line is reserved for the status */
"r: refresh | a <n>: accept | d <n>: decline", "r: refresh | a <n>: accept | d <n>: decline",
"p <n>: pause | c <n>: continue | b <n>: abort", "p <n>: pause | c <n>: continue | b <n>: abort", "files:"};
"files:"
};
int i; int i;
for (i = 0; i < TWC_TFER_LEGEND_LINES; i++) for (i = 0; i < TWC_TFER_LEGEND_LINES; i++)
{ {
@ -139,16 +144,19 @@ twc_tfer_expanded_path(struct t_twc_profile *profile, const char *base_path)
void void
twc_tfer_update_downloading_path(struct t_twc_profile *profile) twc_tfer_update_downloading_path(struct t_twc_profile *profile)
{ {
const char *base_path = TWC_PROFILE_OPTION_STRING(profile, const char *base_path =
TWC_PROFILE_OPTION_DOWNLOADING_PATH); TWC_PROFILE_OPTION_STRING(profile, TWC_PROFILE_OPTION_DOWNLOADING_PATH);
char *full_path = twc_tfer_expanded_path(profile, base_path); char *full_path = twc_tfer_expanded_path(profile, base_path);
if (!weechat_mkdir_parents(full_path, 0755)) if (!weechat_mkdir_parents(full_path, 0755))
{ {
char *bad_path = full_path; char *bad_path = full_path;
base_path = weechat_config_string(twc_config_profile_default[TWC_PROFILE_OPTION_DOWNLOADING_PATH]); base_path = weechat_config_string(
twc_config_profile_default[TWC_PROFILE_OPTION_DOWNLOADING_PATH]);
full_path = twc_tfer_expanded_path(profile, base_path); full_path = twc_tfer_expanded_path(profile, base_path);
weechat_printf(profile->buffer, "cannot create directory \"%s\"," weechat_printf(profile->buffer,
"using default value: \"%s\"", bad_path, full_path); "cannot create directory \"%s\","
"using default value: \"%s\"",
bad_path, full_path);
free(bad_path); free(bad_path);
weechat_mkdir_parents(full_path, 0755); weechat_mkdir_parents(full_path, 0755);
} }
@ -214,8 +222,7 @@ twc_tfer_file_unique_name(const char* original)
{ {
snprintf(name, FILENAME_MAX, "%s(%i)%s", body, i, extension); snprintf(name, FILENAME_MAX, "%s(%i)%s", body, i, extension);
i++; i++;
} } while (twc_tfer_file_check(name));
while (twc_tfer_file_check(name));
return name; return name;
} }
@ -244,10 +251,10 @@ twc_tfer_file_name_strip(const char *original, size_t size)
* Create a new file. * Create a new file.
*/ */
struct t_twc_tfer_file * struct t_twc_tfer_file *
twc_tfer_file_new(struct t_twc_profile *profile, twc_tfer_file_new(struct t_twc_profile *profile, const char *nickname,
const char *nickname, const char *filename, const char *filename, uint32_t friend_number,
uint32_t friend_number, uint32_t file_number, uint32_t file_number, uint64_t size,
uint64_t size, enum t_twc_tfer_file_type filetype) enum t_twc_tfer_file_type filetype)
{ {
struct t_twc_tfer_file *file = malloc(sizeof(struct t_twc_tfer_file)); struct t_twc_tfer_file *file = malloc(sizeof(struct t_twc_tfer_file));
file->status = TWC_TFER_FILE_STATUS_REQUEST; file->status = TWC_TFER_FILE_STATUS_REQUEST;
@ -264,8 +271,8 @@ twc_tfer_file_new(struct t_twc_profile *profile,
{ {
char *full_path = malloc(sizeof(char) * (FILENAME_MAX + 1)); char *full_path = malloc(sizeof(char) * (FILENAME_MAX + 1));
sprintf(full_path, "%s", profile->tfer->downloading_path); sprintf(full_path, "%s", profile->tfer->downloading_path);
char *final_name = twc_tfer_file_name_strip(filename, char *final_name = twc_tfer_file_name_strip(
FILENAME_MAX + 1 - strlen(full_path)); filename, FILENAME_MAX + 1 - strlen(full_path));
if (!final_name) if (!final_name)
return NULL; return NULL;
@ -286,8 +293,8 @@ twc_tfer_file_new(struct t_twc_profile *profile,
} }
else else
{ {
file->filename = twc_tfer_file_name_strip(filename, file->filename = twc_tfer_file_name_strip(
FILENAME_MAX + 1 - strlen(filename)); filename, FILENAME_MAX + 1 - strlen(filename));
file->full_path = NULL; file->full_path = NULL;
file->fp = fopen(filename, "r"); file->fp = fopen(filename, "r");
} }
@ -295,7 +302,6 @@ twc_tfer_file_new(struct t_twc_profile *profile,
if (!(file->fp)) if (!(file->fp))
return NULL; return NULL;
return file; return file;
} }
/** /**
@ -322,14 +328,8 @@ twc_tfer_file_get_type_str(struct t_twc_tfer_file *file)
const char * const char *
twc_tfer_file_get_status_str(struct t_twc_tfer_file *file) twc_tfer_file_get_status_str(struct t_twc_tfer_file *file)
{ {
char *statuses[] = { char *statuses[] = {"[request]", "", "[paused]",
"[request]", "[done]", "[declined]", "[aborted]"};
"",
"[paused]",
"[done]",
"[declined]",
"[aborted]"
};
return statuses[file->status]; return statuses[file->status];
} }
@ -441,8 +441,7 @@ twc_tfer_file_update(struct t_twc_tfer *tfer, struct t_twc_tfer_file *file)
{ {
remainder = remainder / 10; remainder = remainder / 10;
indent++; indent++;
} } while (remainder > 0);
while (remainder > 0);
indent += 5; /* length of ") => " */ indent += 5; /* length of ") => " */
char placeholder[indent + 1]; char placeholder[indent + 1];
memset(placeholder, ' ', indent); memset(placeholder, ' ', indent);
@ -450,21 +449,16 @@ twc_tfer_file_update(struct t_twc_tfer *tfer, struct t_twc_tfer_file *file)
const char *status = twc_tfer_file_get_status_str(file); const char *status = twc_tfer_file_get_status_str(file);
if (file->size == UINT64_MAX) if (file->size == UINT64_MAX)
{ {
weechat_printf_y(tfer->buffer, line, "%i) %s %s: %s [STREAM]", weechat_printf_y(tfer->buffer, line, "%i) %s %s: %s [STREAM]", index,
index, type, file->nickname, file->filename); type, file->nickname, file->filename);
} }
else else
{ {
float display_size = twc_tfer_cut_size(file->size); float display_size = twc_tfer_cut_size(file->size);
const char *size_suffix = twc_tfer_size_suffix(file->size); const char *size_suffix = twc_tfer_size_suffix(file->size);
weechat_printf_y(tfer->buffer, line, "%i) %s %s: %s %i (%.2f%s)", weechat_printf_y(tfer->buffer, line, "%i) %s %s: %s %i (%.2f%s)", index,
index, type, file->nickname, file->filename, file->size,
type, display_size, size_suffix);
file->nickname,
file->filename,
file->size,
display_size,
size_suffix);
} }
if (file->status == TWC_TFER_FILE_STATUS_IN_PROGRESS) if (file->status == TWC_TFER_FILE_STATUS_IN_PROGRESS)
{ {
@ -473,8 +467,8 @@ twc_tfer_file_update(struct t_twc_tfer *tfer, struct t_twc_tfer_file *file)
const char *speed_suffix = twc_tfer_speed_suffix(speed); const char *speed_suffix = twc_tfer_speed_suffix(speed);
if (file->size == UINT64_MAX) if (file->size == UINT64_MAX)
{ {
weechat_printf_y(tfer->buffer, line + 1, "%s%.2f%s", weechat_printf_y(tfer->buffer, line + 1, "%s%.2f%s", placeholder,
placeholder, display_speed, speed_suffix); display_speed, speed_suffix);
return; return;
} }
double ratio = (double)(file->position) / (double)(file->size); double ratio = (double)(file->position) / (double)(file->size);
@ -493,31 +487,28 @@ twc_tfer_file_update(struct t_twc_tfer *tfer, struct t_twc_tfer_file *file)
const char *pos_suffix = twc_tfer_size_suffix(file->position); const char *pos_suffix = twc_tfer_size_suffix(file->position);
weechat_printf_y(tfer->buffer, line + 1, "%s%i%% [%s] %.2f%s %.2f%s", weechat_printf_y(tfer->buffer, line + 1, "%s%i%% [%s] %.2f%s %.2f%s",
placeholder, placeholder, percents, progress_bar, display_pos,
percents, pos_suffix, display_speed, speed_suffix);
progress_bar,
display_pos,
pos_suffix,
display_speed,
speed_suffix);
} }
else else
weechat_printf_y(tfer->buffer, line + 1, "%s%s", weechat_printf_y(tfer->buffer, line + 1, "%s%s", placeholder, status);
placeholder,status);
} }
/** /**
* Allocate and return "uint8_t data[length]" chunk of data starting from "position". * Allocate and return "uint8_t data[length]" chunk of data starting from
* "position".
*/ */
uint8_t * uint8_t *
twc_tfer_file_get_chunk(struct t_twc_tfer_file *file, uint64_t position, size_t length) twc_tfer_file_get_chunk(struct t_twc_tfer_file *file, uint64_t position,
size_t length)
{ {
fseek(file->fp, position, SEEK_SET); fseek(file->fp, position, SEEK_SET);
uint8_t *data = malloc(sizeof(uint8_t) * length); uint8_t *data = malloc(sizeof(uint8_t) * length);
size_t read = fread(data, sizeof(uint8_t), length, file->fp); size_t read = fread(data, sizeof(uint8_t), length, file->fp);
while ((read < length) && !feof(file->fp)) while ((read < length) && !feof(file->fp))
{ {
read += fread(data + read * sizeof(uint8_t), sizeof(uint8_t), length - read, file->fp); read += fread(data + read * sizeof(uint8_t), sizeof(uint8_t),
length - read, file->fp);
} }
if (read != length) if (read != length)
return NULL; return NULL;
@ -528,13 +519,15 @@ twc_tfer_file_get_chunk(struct t_twc_tfer_file *file, uint64_t position, size_t
* Write a chunk to the file. * Write a chunk to the file.
*/ */
bool bool
twc_tfer_file_write_chunk(struct t_twc_tfer_file *file, const uint8_t *data, uint64_t position, size_t length) twc_tfer_file_write_chunk(struct t_twc_tfer_file *file, const uint8_t *data,
uint64_t position, size_t length)
{ {
fseek(file->fp, position, SEEK_SET); fseek(file->fp, position, SEEK_SET);
size_t wrote = fwrite(data, sizeof(uint8_t), length, file->fp); size_t wrote = fwrite(data, sizeof(uint8_t), length, file->fp);
while (wrote < length) while (wrote < length)
{ {
wrote += fwrite(data + wrote * sizeof(uint8_t), sizeof(uint8_t), length - wrote, file->fp); wrote += fwrite(data + wrote * sizeof(uint8_t), sizeof(uint8_t),
length - wrote, file->fp);
} }
if (wrote != length) if (wrote != length)
@ -626,9 +619,9 @@ twc_tfer_buffer_refresh(struct t_twc_tfer *tfer)
/** /**
* Send TOX_FILE_CONTROL command to a client. * Send TOX_FILE_CONTROL command to a client.
* "сheck" is a file status that a file should be in before sending a control command. * "сheck" is a file status that a file should be in before sending a control
* "send" is a control comand you are going to send. * command. "send" is a control comand you are going to send. "set" is a file
* "set" is a file status that will be set after successful sending a control command. * status that will be set after successful sending a control command.
*/ */
int int
twc_tfer_file_send_control(struct t_twc_profile *profile, size_t index, twc_tfer_file_send_control(struct t_twc_profile *profile, size_t index,
@ -649,8 +642,10 @@ twc_tfer_file_send_control(struct t_twc_profile *profile, size_t index,
&control_error); &control_error);
if (control_error) if (control_error)
{ {
weechat_printf(profile->buffer, "%scannot send control command for \"%s\" file: %s", weechat_printf(profile->buffer,
weechat_prefix("error"), file->filename, twc_tox_err_file_control(control_error)); "%scannot send control command for \"%s\" file: %s",
weechat_prefix("error"), file->filename,
twc_tox_err_file_control(control_error));
return 0; return 0;
} }
else else
@ -658,7 +653,8 @@ twc_tfer_file_send_control(struct t_twc_profile *profile, size_t index,
if (send == TOX_FILE_CONTROL_CANCEL) if (send == TOX_FILE_CONTROL_CANCEL)
{ {
fclose(file->fp); fclose(file->fp);
if (file->type == TWC_TFER_FILE_TYPE_DOWNLOADING && file->size != UINT64_MAX) if (file->type == TWC_TFER_FILE_TYPE_DOWNLOADING &&
file->size != UINT64_MAX)
remove(file->full_path); remove(file->full_path);
} }
file->status = set; file->status = set;
@ -667,8 +663,6 @@ twc_tfer_file_send_control(struct t_twc_profile *profile, size_t index,
} }
} }
/** /**
* Accept a file with number <index> in the list. * Accept a file with number <index> in the list.
* Returns 1 if successful, 0 when there's an issue with tox calls * Returns 1 if successful, 0 when there's an issue with tox calls
@ -677,9 +671,8 @@ twc_tfer_file_send_control(struct t_twc_profile *profile, size_t index,
int int
twc_tfer_file_accept(struct t_twc_profile *profile, size_t index) twc_tfer_file_accept(struct t_twc_profile *profile, size_t index)
{ {
return twc_tfer_file_send_control(profile, index, return twc_tfer_file_send_control(
TWC_TFER_FILE_STATUS_REQUEST, profile, index, TWC_TFER_FILE_STATUS_REQUEST, TOX_FILE_CONTROL_RESUME,
TOX_FILE_CONTROL_RESUME,
TWC_TFER_FILE_STATUS_IN_PROGRESS); TWC_TFER_FILE_STATUS_IN_PROGRESS);
} }
@ -691,9 +684,8 @@ twc_tfer_file_accept(struct t_twc_profile *profile, size_t index)
int int
twc_tfer_file_decline(struct t_twc_profile *profile, size_t index) twc_tfer_file_decline(struct t_twc_profile *profile, size_t index)
{ {
return twc_tfer_file_send_control(profile, index, return twc_tfer_file_send_control(
TWC_TFER_FILE_STATUS_REQUEST, profile, index, TWC_TFER_FILE_STATUS_REQUEST, TOX_FILE_CONTROL_CANCEL,
TOX_FILE_CONTROL_CANCEL,
TWC_TFER_FILE_STATUS_DECLINED); TWC_TFER_FILE_STATUS_DECLINED);
} }
@ -705,10 +697,9 @@ twc_tfer_file_decline(struct t_twc_profile *profile, size_t index)
int int
twc_tfer_file_pause(struct t_twc_profile *profile, size_t index) twc_tfer_file_pause(struct t_twc_profile *profile, size_t index)
{ {
return twc_tfer_file_send_control(profile, index, return twc_tfer_file_send_control(
TWC_TFER_FILE_STATUS_IN_PROGRESS, profile, index, TWC_TFER_FILE_STATUS_IN_PROGRESS,
TOX_FILE_CONTROL_PAUSE, TOX_FILE_CONTROL_PAUSE, TWC_TFER_FILE_STATUS_PAUSED);
TWC_TFER_FILE_STATUS_PAUSED);
} }
/** /**
@ -719,9 +710,8 @@ twc_tfer_file_pause(struct t_twc_profile *profile, size_t index)
int int
twc_tfer_file_continue(struct t_twc_profile *profile, size_t index) twc_tfer_file_continue(struct t_twc_profile *profile, size_t index)
{ {
return twc_tfer_file_send_control(profile, index, return twc_tfer_file_send_control(
TWC_TFER_FILE_STATUS_PAUSED, profile, index, TWC_TFER_FILE_STATUS_PAUSED, TOX_FILE_CONTROL_RESUME,
TOX_FILE_CONTROL_RESUME,
TWC_TFER_FILE_STATUS_IN_PROGRESS); TWC_TFER_FILE_STATUS_IN_PROGRESS);
} }
@ -733,10 +723,9 @@ twc_tfer_file_continue(struct t_twc_profile *profile, size_t index)
int int
twc_tfer_file_abort(struct t_twc_profile *profile, size_t index) twc_tfer_file_abort(struct t_twc_profile *profile, size_t index)
{ {
return twc_tfer_file_send_control(profile, index, return twc_tfer_file_send_control(
TWC_TFER_FILE_STATUS_IN_PROGRESS, profile, index, TWC_TFER_FILE_STATUS_IN_PROGRESS,
TOX_FILE_CONTROL_CANCEL, TOX_FILE_CONTROL_CANCEL, TWC_TFER_FILE_STATUS_ABORTED);
TWC_TFER_FILE_STATUS_ABORTED);
} }
/** /**
@ -751,9 +740,13 @@ twc_tfer_buffer_input_callback(const void *pointer, void *data,
profile = (struct t_twc_profile *)pointer; profile = (struct t_twc_profile *)pointer;
int argc; int argc;
char **argv = weechat_string_split_shell(input_data, &argc); char **argv = weechat_string_split_shell(input_data, &argc);
char *status = malloc(sizeof(char) * weechat_window_get_integer(weechat_current_window(), "win_width") + 1); char *status =
malloc(sizeof(char) * weechat_window_get_integer(
weechat_current_window(), "win_width") +
1);
/* refresh file list, i.e delete files that have been marked as "denied", "aborted" and "done" */ /* refresh file list, i.e delete files that have been marked as "denied",
* "aborted" and "done" */
if (weechat_strcasecmp(argv[0], "r") == 0) if (weechat_strcasecmp(argv[0], "r") == 0)
{ {
if (argc == 1) if (argc == 1)
@ -763,7 +756,8 @@ twc_tfer_buffer_input_callback(const void *pointer, void *data,
} }
else else
{ {
TWC_TFER_UPDATE_STATUS_AND_RETURN("this command doesn't accept any arguments"); TWC_TFER_UPDATE_STATUS_AND_RETURN(
"this command doesn't accept any arguments");
} }
} }
if (strstr("adpcbADPCB", argv[0]) && argc < 2) if (strstr("adpcbADPCB", argv[0]) && argc < 2)
@ -771,9 +765,11 @@ twc_tfer_buffer_input_callback(const void *pointer, void *data,
if (argc == 2) if (argc == 2)
{ {
size_t n = (size_t)strtol(argv[1], NULL, 0); size_t n = (size_t)strtol(argv[1], NULL, 0);
if ((n == 0 && strcmp(argv[1], "0") != 0) || n > (profile->tfer->files->count - 1)) if ((n == 0 && strcmp(argv[1], "0") != 0) ||
n > (profile->tfer->files->count - 1))
{ {
TWC_TFER_UPDATE_STATUS_AND_RETURN("<n> must be existing number of file"); TWC_TFER_UPDATE_STATUS_AND_RETURN(
"<n> must be existing number of file");
} }
/* accept */ /* accept */
if (weechat_strcasecmp(argv[0], "a") == 0) if (weechat_strcasecmp(argv[0], "a") == 0)

View File

@ -103,19 +103,21 @@ char *
twc_tfer_file_name_strip(const char *original, size_t size); twc_tfer_file_name_strip(const char *original, size_t size);
struct t_twc_tfer_file * struct t_twc_tfer_file *
twc_tfer_file_new(struct t_twc_profile *profile, twc_tfer_file_new(struct t_twc_profile *profile, const char *nickname,
const char *nickname, const char *filename, const char *filename, uint32_t friend_number,
uint32_t friend_number, uint32_t file_number, uint32_t file_number, uint64_t size,
uint64_t size, enum t_twc_tfer_file_type filetype); enum t_twc_tfer_file_type filetype);
void void
twc_tfer_file_add(struct t_twc_tfer *tfer, struct t_twc_tfer_file *file); twc_tfer_file_add(struct t_twc_tfer *tfer, struct t_twc_tfer_file *file);
uint8_t * uint8_t *
twc_tfer_file_get_chunk(struct t_twc_tfer_file *file, uint64_t position, size_t length); twc_tfer_file_get_chunk(struct t_twc_tfer_file *file, uint64_t position,
size_t length);
bool bool
twc_tfer_file_write_chunk(struct t_twc_tfer_file *file, const uint8_t *data, uint64_t position, size_t length); twc_tfer_file_write_chunk(struct t_twc_tfer_file *file, const uint8_t *data,
uint64_t position, size_t length);
struct t_twc_tfer_file * struct t_twc_tfer_file *
twc_tfer_file_get_by_number(struct t_twc_tfer *tfer, uint32_t file_number); twc_tfer_file_get_by_number(struct t_twc_tfer *tfer, uint32_t file_number);

View File

@ -32,13 +32,15 @@
#include "twc-group-invite.h" #include "twc-group-invite.h"
#include "twc-message-queue.h" #include "twc-message-queue.h"
#include "twc-profile.h" #include "twc-profile.h"
#include "twc-utils.h"
#include "twc-tfer.h" #include "twc-tfer.h"
#include "twc-utils.h"
#include "twc.h" #include "twc.h"
#include "twc-tox-callbacks.h" #include "twc-tox-callbacks.h"
#define TWC_TFER_FILE_UPDATE_STATUS(st) do { \ #define TWC_TFER_FILE_UPDATE_STATUS(st) \
do \
{ \
file->status = st; \ file->status = st; \
twc_tfer_file_update(profile->tfer, file); \ twc_tfer_file_update(profile->tfer, file); \
} while (0) } while (0)
@ -57,8 +59,7 @@ twc_do_timer_cb(const void *pointer, void *data, int remaining_calls)
interval = tox_iteration_interval(profile->tox); interval = tox_iteration_interval(profile->tox);
tox_iterate(profile->tox, profile); tox_iterate(profile->tox, profile);
struct t_hook *hook = struct t_hook *hook =
weechat_hook_timer(interval, 0, 1, weechat_hook_timer(interval, 0, 1, twc_do_timer_cb, profile, NULL);
twc_do_timer_cb, profile, NULL);
profile->tox_do_timer = hook; profile->tox_do_timer = hook;
/* check connection status */ /* check connection status */
@ -70,12 +71,14 @@ twc_do_timer_cb(const void *pointer, void *data, int remaining_calls)
if (TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_AUTOJOIN)) if (TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_AUTOJOIN))
{ {
struct t_twc_group_chat_invite *invite; struct t_twc_group_chat_invite *invite;
for(i = 0; (invite = twc_group_chat_invite_with_index(profile, i)); i++) for (i = 0; (invite = twc_group_chat_invite_with_index(profile, i));
i++)
if (invite->autojoin_delay <= 0) if (invite->autojoin_delay <= 0)
{ {
struct t_twc_chat *friend_chat = struct t_twc_chat *friend_chat = twc_chat_search_friend(
twc_chat_search_friend(profile, invite->friend_number, false); profile, invite->friend_number, false);
char *friend_name = twc_get_name_nt(profile->tox, invite->friend_number); char *friend_name =
twc_get_name_nt(profile->tox, invite->friend_number);
char *type_str; char *type_str;
switch (invite->group_chat_type) switch (invite->group_chat_type)
{ {
@ -101,15 +104,17 @@ twc_do_timer_cb(const void *pointer, void *data, int remaining_calls)
weechat_printf_date_tags( weechat_printf_date_tags(
friend_chat->buffer, 0, tags, friend_chat->buffer, 0, tags,
"%sWe joined the %s%s%s's invite to %s.", "%sWe joined the %s%s%s's invite to %s.",
weechat_prefix("network"), weechat_color("chat_nick_other"), weechat_prefix("network"),
friend_name, weechat_color("reset"), type_str); weechat_color("chat_nick_other"), friend_name,
weechat_color("reset"), type_str);
tags = ""; tags = "";
} }
weechat_printf_date_tags( weechat_printf_date_tags(
profile->buffer, 0, tags, profile->buffer, 0, tags,
"%sWe joined the %s%s%s's invite to %s.", "%sWe joined the %s%s%s's invite to %s.",
weechat_prefix("network"), weechat_color("chat_nick_other"), weechat_prefix("network"),
friend_name, weechat_color("reset"), type_str); weechat_color("chat_nick_other"), friend_name,
weechat_color("reset"), type_str);
} }
else else
{ {
@ -120,16 +125,18 @@ twc_do_timer_cb(const void *pointer, void *data, int remaining_calls)
friend_chat->buffer, 0, tags, friend_chat->buffer, 0, tags,
"%s%s%s%s invites you to join %s, but we failed to " "%s%s%s%s invites you to join %s, but we failed to "
"process the invite. Please try again.", "process the invite. Please try again.",
weechat_prefix("network"), weechat_color("chat_nick_other"), weechat_prefix("network"),
friend_name, weechat_color("reset")); weechat_color("chat_nick_other"), friend_name,
weechat_color("reset"));
tags = ""; tags = "";
} }
weechat_printf_date_tags( weechat_printf_date_tags(
profile->buffer, 0, tags, profile->buffer, 0, tags,
"%s%s%s%s invites you to join %s, but we failed to " "%s%s%s%s invites you to join %s, but we failed to "
"process the invite. Please try again.", "process the invite. Please try again.",
weechat_prefix("network"), weechat_color("chat_nick_other"), weechat_prefix("network"),
friend_name, weechat_color("reset")); weechat_color("chat_nick_other"), friend_name,
weechat_color("reset"));
} }
} }
else else
@ -361,12 +368,12 @@ twc_group_invite_callback(Tox *tox, uint32_t friend_number,
friend_name, weechat_color("reset"), type_str, rc); friend_name, weechat_color("reset"), type_str, rc);
tags = ""; tags = "";
} }
weechat_printf_date_tags( weechat_printf_date_tags(profile->buffer, 0, tags,
profile->buffer, 0, tags,
"%s%s%s%s invites you to join %s. Type " "%s%s%s%s invites you to join %s. Type "
"\"/group join %d\" to accept.", "\"/group join %d\" to accept.",
weechat_prefix("network"), weechat_color("chat_nick_other"), weechat_prefix("network"),
friend_name, weechat_color("reset"), type_str, rc); weechat_color("chat_nick_other"), friend_name,
weechat_color("reset"), type_str, rc);
} }
else else
{ {
@ -505,10 +512,8 @@ twc_group_peer_list_changed_callback(Tox *tox, uint32_t group_number,
void void
twc_group_peer_name_callback(Tox *tox, uint32_t group_number, twc_group_peer_name_callback(Tox *tox, uint32_t group_number,
uint32_t peer_number, uint32_t peer_number, const uint8_t *pname,
const uint8_t *pname, size_t pname_len, void *data)
size_t pname_len,
void *data)
{ {
struct t_twc_profile *profile = data; struct t_twc_profile *profile = data;
struct t_twc_chat *chat = struct t_twc_chat *chat =
@ -549,26 +554,26 @@ twc_group_peer_name_callback(Tox *tox, uint32_t group_number,
prev_name = weechat_list_string(n); prev_name = weechat_list_string(n);
name = twc_null_terminate(pname, pname_len); name = twc_null_terminate(pname, pname_len);
nick = weechat_nicklist_search_nick(chat->buffer, nick = weechat_nicklist_search_nick(chat->buffer, chat->nicklist_group,
chat->nicklist_group, prev_name); prev_name);
weechat_nicklist_remove_nick(chat->buffer, nick); weechat_nicklist_remove_nick(chat->buffer, nick);
err = TOX_ERR_CONFERENCE_PEER_QUERY_OK; err = TOX_ERR_CONFERENCE_PEER_QUERY_OK;
rc = tox_conference_peer_number_is_ours(tox, group_number, peer_number, &err); rc = tox_conference_peer_number_is_ours(tox, group_number, peer_number,
&err);
if ((err == TOX_ERR_CONFERENCE_PEER_QUERY_OK) && (!rc)) if ((err == TOX_ERR_CONFERENCE_PEER_QUERY_OK) && (!rc))
weechat_printf(chat->buffer, "%s%s is now known as %s", weechat_printf(chat->buffer, "%s%s is now known as %s",
weechat_prefix("network"), prev_name, name); weechat_prefix("network"), prev_name, name);
weechat_list_set(n, name); weechat_list_set(n, name);
weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group, name, weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group, name, NULL,
NULL, NULL, NULL, 1); NULL, NULL, 1);
free(name); free(name);
} }
void void
twc_group_title_callback(Tox *tox, uint32_t group_number, uint32_t peer_number, twc_group_title_callback(Tox *tox, uint32_t group_number, uint32_t peer_number,
const uint8_t *title, size_t length, void *data) const uint8_t *title, size_t length, void *data)
@ -587,14 +592,17 @@ twc_group_title_callback(Tox *tox, uint32_t group_number, uint32_t peer_number,
} }
void void
twc_file_recv_control_callback(Tox *tox, uint32_t friend_number, uint32_t file_number, twc_file_recv_control_callback(Tox *tox, uint32_t friend_number,
TOX_FILE_CONTROL control, void *user_data) uint32_t file_number, TOX_FILE_CONTROL control,
void *user_data)
{ {
struct t_twc_profile *profile = twc_profile_search_tox(tox); struct t_twc_profile *profile = twc_profile_search_tox(tox);
struct t_twc_tfer_file *file = twc_tfer_file_get_by_number(profile->tfer, file_number); struct t_twc_tfer_file *file =
twc_tfer_file_get_by_number(profile->tfer, file_number);
if (!file) if (!file)
{ {
weechat_printf(profile->tfer->buffer, "%sthere is no file with number %i in queue", weechat_printf(profile->tfer->buffer,
"%sthere is no file with number %i in queue",
weechat_prefix("error"), file_number); weechat_prefix("error"), file_number);
return; return;
} }
@ -609,7 +617,8 @@ twc_file_recv_control_callback(Tox *tox, uint32_t friend_number, uint32_t file_n
break; break;
case TOX_FILE_CONTROL_CANCEL: case TOX_FILE_CONTROL_CANCEL:
fclose(file->fp); fclose(file->fp);
if (file->type == TWC_TFER_FILE_TYPE_DOWNLOADING && file->size != UINT64_MAX) if (file->type == TWC_TFER_FILE_TYPE_DOWNLOADING &&
file->size != UINT64_MAX)
remove(file->full_path); remove(file->full_path);
if (file->position != 0) if (file->position != 0)
{ {
@ -624,15 +633,18 @@ twc_file_recv_control_callback(Tox *tox, uint32_t friend_number, uint32_t file_n
} }
void void
twc_file_chunk_request_callback(Tox *tox, uint32_t friend_number, uint32_t file_number, twc_file_chunk_request_callback(Tox *tox, uint32_t friend_number,
uint64_t position, size_t length, void *user_data) uint32_t file_number, uint64_t position,
size_t length, void *user_data)
{ {
struct t_twc_profile *profile = twc_profile_search_tox(tox); struct t_twc_profile *profile = twc_profile_search_tox(tox);
struct t_twc_tfer_file *file = twc_tfer_file_get_by_number(profile->tfer, file_number); struct t_twc_tfer_file *file =
twc_tfer_file_get_by_number(profile->tfer, file_number);
/* the file is missing */ /* the file is missing */
if (!file) if (!file)
{ {
weechat_printf(profile->tfer->buffer, "%sthere is no file with number %i in queue", weechat_printf(profile->tfer->buffer,
"%sthere is no file with number %i in queue",
weechat_prefix("error"), file_number); weechat_prefix("error"), file_number);
return; return;
} }
@ -657,10 +669,12 @@ twc_file_chunk_request_callback(Tox *tox, uint32_t friend_number, uint32_t file_
return; return;
} }
enum TOX_ERR_FILE_SEND_CHUNK error; enum TOX_ERR_FILE_SEND_CHUNK error;
tox_file_send_chunk(profile->tox, friend_number, file_number, position, data, length, &error); tox_file_send_chunk(profile->tox, friend_number, file_number, position,
data, length, &error);
if (error) if (error)
weechat_printf(profile->buffer, "%s%s: chunk sending error: %s", weechat_printf(profile->buffer, "%s%s: chunk sending error: %s",
weechat_prefix("error"), file->filename, twc_tox_err_file_send_chunk(error)); weechat_prefix("error"), file->filename,
twc_tox_err_file_send_chunk(error));
else else
{ {
file->position += length; file->position += length;
@ -677,14 +691,16 @@ twc_file_chunk_request_callback(Tox *tox, uint32_t friend_number, uint32_t file_
void void
twc_file_recv_callback(Tox *tox, uint32_t friend_number, uint32_t file_number, twc_file_recv_callback(Tox *tox, uint32_t friend_number, uint32_t file_number,
uint32_t kind, uint64_t file_size, const uint8_t *filename, uint32_t kind, uint64_t file_size,
size_t filename_length, void *user_data) const uint8_t *filename, size_t filename_length,
void *user_data)
{ {
struct t_twc_profile *profile = twc_profile_search_tox(tox); struct t_twc_profile *profile = twc_profile_search_tox(tox);
if (kind == TOX_FILE_KIND_AVATAR) if (kind == TOX_FILE_KIND_AVATAR)
{ {
TOX_ERR_FILE_CONTROL error; TOX_ERR_FILE_CONTROL error;
tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, &error); tox_file_control(tox, friend_number, file_number,
TOX_FILE_CONTROL_CANCEL, &error);
if (error) if (error)
{ {
weechat_printf(profile->buffer, "%scannot cancel avatar receiving", weechat_printf(profile->buffer, "%scannot cancel avatar receiving",
@ -694,14 +710,15 @@ twc_file_recv_callback(Tox *tox, uint32_t friend_number, uint32_t file_number,
} }
char *name = twc_get_name_nt(tox, friend_number); char *name = twc_get_name_nt(tox, friend_number);
char *fname = twc_null_terminate(filename, filename_length); char *fname = twc_null_terminate(filename, filename_length);
struct t_twc_tfer_file *file = twc_tfer_file_new(profile, name, fname, struct t_twc_tfer_file *file =
friend_number, file_number, twc_tfer_file_new(profile, name, fname, friend_number, file_number,
file_size, TWC_TFER_FILE_TYPE_DOWNLOADING); file_size, TWC_TFER_FILE_TYPE_DOWNLOADING);
free(name); free(name);
free(fname); free(fname);
if (!file) if (!file)
{ {
weechat_printf(profile->buffer, "%scannot open the file \"%s\" with write permissions", weechat_printf(profile->buffer,
"%scannot open the file \"%s\" with write permissions",
weechat_prefix("error"), filename); weechat_prefix("error"), filename);
return; return;
} }
@ -715,19 +732,24 @@ twc_file_recv_callback(Tox *tox, uint32_t friend_number, uint32_t file_number,
} }
void void
twc_file_recv_chunk_callback(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, twc_file_recv_chunk_callback(Tox *tox, uint32_t friend_number,
const uint8_t *data, size_t length, void *user_data) uint32_t file_number, uint64_t position,
const uint8_t *data, size_t length,
void *user_data)
{ {
struct t_twc_profile *profile = twc_profile_search_tox(tox); struct t_twc_profile *profile = twc_profile_search_tox(tox);
struct t_twc_tfer_file *file = twc_tfer_file_get_by_number(profile->tfer, file_number); struct t_twc_tfer_file *file =
twc_tfer_file_get_by_number(profile->tfer, file_number);
/* the file is missing */ /* the file is missing */
if (!file) if (!file)
{ {
weechat_printf(profile->tfer->buffer, "%sthere is no file with number %i in queue", weechat_printf(profile->tfer->buffer,
"%sthere is no file with number %i in queue",
weechat_prefix("error"), file_number); weechat_prefix("error"), file_number);
return; return;
} }
/* 0-length chunk transmitted that means the file transmission is completed */ /* 0-length chunk transmitted that means the file transmission is completed
*/
if (length == 0) if (length == 0)
{ {
TWC_TFER_FILE_UPDATE_STATUS(TWC_TFER_FILE_STATUS_DONE); TWC_TFER_FILE_UPDATE_STATUS(TWC_TFER_FILE_STATUS_DONE);

View File

@ -66,30 +66,34 @@ twc_group_peer_list_changed_callback(Tox *tox, uint32_t group_number,
void void
twc_group_peer_name_callback(Tox *tox, uint32_t group_number, twc_group_peer_name_callback(Tox *tox, uint32_t group_number,
uint32_t peer_number, uint32_t peer_number, const uint8_t *nick,
const uint8_t *nick, size_t nick_len, void *data);
size_t nick_len,
void *data);
void void
twc_group_title_callback(Tox *tox, uint32_t group_number, uint32_t peer_number, twc_group_title_callback(Tox *tox, uint32_t group_number, uint32_t peer_number,
const uint8_t *title, size_t length, void *data); const uint8_t *title, size_t length, void *data);
void void
twc_file_recv_control_callback(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, twc_file_recv_control_callback(Tox *tox, uint32_t friend_number,
uint32_t file_number, TOX_FILE_CONTROL control,
void *user_data); void *user_data);
void void
twc_file_chunk_request_callback(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, twc_file_chunk_request_callback(Tox *tox, uint32_t friend_number,
uint32_t file_number, uint64_t position,
size_t length, void *user_data); size_t length, void *user_data);
void void
twc_file_recv_callback(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t kind, uint64_t file_size, twc_file_recv_callback(Tox *tox, uint32_t friend_number, uint32_t file_number,
const uint8_t *filename, size_t filename_length, void *user_data); uint32_t kind, uint64_t file_size,
const uint8_t *filename, size_t filename_length,
void *user_data);
void void
twc_file_recv_chunk_callback(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, twc_file_recv_chunk_callback(Tox *tox, uint32_t friend_number,
const uint8_t *data, size_t length, void *user_data); uint32_t file_number, uint64_t position,
const uint8_t *data, size_t length,
void *user_data);
#ifndef NDEBUG #ifndef NDEBUG
void void

View File

@ -245,12 +245,13 @@ twc_tox_err_file_control(enum TOX_ERR_FILE_CONTROL error)
"success", "success",
"the friend number passed did not designate a valid friend", "the friend number passed did not designate a valid friend",
"this client is currently not connected to the friend", "this client is currently not connected to the friend",
"no file transfer with the given file number was found for the given friend", "no file transfer with the given file number was found for the given "
"friend",
"a RESUME control was sent, but the file transfer is running normally", "a RESUME control was sent, but the file transfer is running normally",
"A RESUME control was sent, but the file transfer was paused by the other party", "A RESUME control was sent, but the file transfer was paused by the "
"other party",
"a PAUSE control was sent, but the file transfer was already paused", "a PAUSE control was sent, but the file transfer was already paused",
"packet queue is full" "packet queue is full"};
};
return messages[error]; return messages[error];
} }
@ -259,10 +260,11 @@ twc_tox_err_file_get(enum TOX_ERR_FILE_GET error)
{ {
char *messages[] = { char *messages[] = {
"success", "success",
"one of the arguments to the function was NULL when it was not expected", "one of the arguments to the function was NULL when it was not "
"expected",
"the friend number passed did not designate a valid friend", "the friend number passed did not designate a valid friend",
"no file transfer with the given number was found for the given friend" "no file transfer with the given number was found for the given "
}; "friend"};
return messages[error]; return messages[error];
} }
@ -273,11 +275,11 @@ twc_tox_err_file_seek(enum TOX_ERR_FILE_SEEK error)
"success", "success",
"the friend number passed did not designate a valid friend", "the friend number passed did not designate a valid friend",
"the client is currently not connected to the friend", "the client is currently not connected to the friend",
"no file transfer with the given file number was found for the given friend", "no file transfer with the given file number was found for the given "
"friend",
"file was not in a state where it could be seeked", "file was not in a state where it could be seeked",
"seek position was invalid", "seek position was invalid",
"packet queue is full" "packet queue is full"};
};
return messages[error]; return messages[error];
} }
@ -286,12 +288,12 @@ twc_tox_err_file_send(enum TOX_ERR_FILE_SEND error)
{ {
char *messages[] = { char *messages[] = {
"success", "success",
"one of the arguments of the function was NULL when it was not expected", "one of the arguments of the function was NULL when it was not "
"expected",
"the friend number passed did not designate a valid friend", "the friend number passed did not designate a valid friend",
"this client is currently not connected to the friend", "this client is currently not connected to the friend",
"filename lenth exceeded TOX_MAX_FILENAME_LENGTH bytes", "filename lenth exceeded TOX_MAX_FILENAME_LENGTH bytes",
"too many ongoing transfers" "too many ongoing transfers"};
};
return messages[error]; return messages[error];
} }
@ -303,11 +305,11 @@ twc_tox_err_file_send_chunk(enum TOX_ERR_FILE_SEND_CHUNK error)
"the length parameter was non-zero, but data was NULL", "the length parameter was non-zero, but data was NULL",
"the friend number passed did not designate a valid friend", "the friend number passed did not designate a valid friend",
"this client is currently not connected to the friend", "this client is currently not connected to the friend",
"no file transfer with the given file number was found for the given friend", "no file transfer with the given file number was found for the given "
"friend",
"not called from the request chunk callback", "not called from the request chunk callback",
"attempted to send more or less data than requested", "attempted to send more or less data than requested",
"packet queue is full", "packet queue is full",
"position parameter was wrong" "position parameter was wrong"};
};
return messages[error]; return messages[error];
} }