Update to match WeeChat 1.5 plugin API.

This commit is contained in:
Håvard Pettersson 2016-05-10 10:51:08 +02:00
parent 5e30b18d50
commit 174f00eccd
9 changed files with 111 additions and 105 deletions

View File

@ -19,9 +19,9 @@ future.
- [ ] Audio/video - [ ] Audio/video
## Installation ## Installation
Tox-WeeChat requires [WeeChat][2] >= 1.0.1 and the latest-ish [toxcore][4]. Tox-WeeChat requires [WeeChat][2] >= 1.5 and the latest-ish [toxcore][4]. It
It also requires CMake to be built. Installation is fairly simple; after also requires CMake to be built. Installation is fairly simple; after getting
getting the source, compile and install using CMake: the source, compile and install using CMake:
$ mkdir build && cd build $ mkdir build && cd build
$ cmake -DPLUGIN_PATH=~/.weechat/plugins .. $ cmake -DPLUGIN_PATH=~/.weechat/plugins ..

View File

@ -36,11 +36,13 @@ const char *twc_tag_sent_message = "tox_sent";
const char *twc_tag_received_message = "tox_received"; const char *twc_tag_received_message = "tox_received";
int int
twc_chat_buffer_input_callback(void *data, twc_chat_buffer_input_callback(const void *pointer,
void *data,
struct t_gui_buffer *weechat_buffer, struct t_gui_buffer *weechat_buffer,
const char *input_data); const char *input_data);
int int
twc_chat_buffer_close_callback(void *data, twc_chat_buffer_close_callback(const void *pointer,
void *data,
struct t_gui_buffer *weechat_buffer); struct t_gui_buffer *weechat_buffer);
/** /**
@ -80,8 +82,8 @@ twc_chat_new(struct t_twc_profile *profile, const char *name)
char *full_name = malloc(full_name_size); char *full_name = malloc(full_name_size);
snprintf(full_name, full_name_size, "%s/%s", profile->name, name); snprintf(full_name, full_name_size, "%s/%s", profile->name, name);
chat->buffer = weechat_buffer_new(full_name, chat->buffer = weechat_buffer_new(full_name,
twc_chat_buffer_input_callback, chat, twc_chat_buffer_input_callback, chat, NULL,
twc_chat_buffer_close_callback, chat); twc_chat_buffer_close_callback, chat, NULL);
free(full_name); free(full_name);
if (!(chat->buffer)) if (!(chat->buffer))
@ -150,7 +152,7 @@ twc_chat_new_group(struct t_twc_profile *profile, int32_t group_number)
* Refresh a chat. Updates buffer short_name and title. * Refresh a chat. Updates buffer short_name and title.
*/ */
void void
twc_chat_refresh(struct t_twc_chat *chat) twc_chat_refresh(const struct t_twc_chat *chat)
{ {
char *name = NULL; char *name = NULL;
char *title = NULL; char *title = NULL;
@ -186,9 +188,9 @@ twc_chat_refresh(struct t_twc_chat *chat)
* Callback for twc_chat_queue_refresh. Simply calls twc_chat_refresh. * Callback for twc_chat_queue_refresh. Simply calls twc_chat_refresh.
*/ */
int int
twc_chat_refresh_timer_callback(void *data, int remaining) twc_chat_refresh_timer_callback(const void *pointer, void *data, int remaining)
{ {
twc_chat_refresh(data); twc_chat_refresh(pointer);
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
} }
@ -201,7 +203,7 @@ void
twc_chat_queue_refresh(struct t_twc_chat *chat) twc_chat_queue_refresh(struct t_twc_chat *chat)
{ {
weechat_hook_timer(1, 0, 1, weechat_hook_timer(1, 0, 1,
twc_chat_refresh_timer_callback, chat); twc_chat_refresh_timer_callback, chat, NULL);
} }
/** /**
@ -328,10 +330,12 @@ twc_chat_send_message(struct t_twc_chat *chat, const char *message,
* Callback for a buffer receiving user input. * Callback for a buffer receiving user input.
*/ */
int int
twc_chat_buffer_input_callback(void *data, struct t_gui_buffer *weechat_buffer, twc_chat_buffer_input_callback(const void *pointer, void *data,
struct t_gui_buffer *weechat_buffer,
const char *input_data) const char *input_data)
{ {
struct t_twc_chat *chat = data; /* TODO: don't strip the const */
struct t_twc_chat *chat = (void *)pointer;
twc_chat_send_message(chat, input_data, TWC_MESSAGE_TYPE_MESSAGE); twc_chat_send_message(chat, input_data, TWC_MESSAGE_TYPE_MESSAGE);
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
@ -341,9 +345,11 @@ twc_chat_buffer_input_callback(void *data, struct t_gui_buffer *weechat_buffer,
* Callback for a buffer being closed. * Callback for a buffer being closed.
*/ */
int int
twc_chat_buffer_close_callback(void *data, struct t_gui_buffer *weechat_buffer) twc_chat_buffer_close_callback(const void *pointer, void *data,
struct t_gui_buffer *weechat_buffer)
{ {
struct t_twc_chat *chat = data; /* TODO: don't strip the const */
struct t_twc_chat *chat = (void *)pointer;
if (chat->profile->tox && chat->group_number >= 0) if (chat->profile->tox && chat->group_number >= 0)
{ {

View File

@ -188,7 +188,7 @@ twc_match_friend(struct t_twc_profile *profile, const char *search_string)
* Command /bootstrap callback. * Command /bootstrap callback.
*/ */
int int
twc_cmd_bootstrap(void *data, struct t_gui_buffer *buffer, twc_cmd_bootstrap(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
struct t_twc_profile *profile = twc_profile_search_buffer(buffer); struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
@ -219,7 +219,7 @@ twc_cmd_bootstrap(void *data, struct t_gui_buffer *buffer,
* Command /friend callback. * Command /friend callback.
*/ */
int int
twc_cmd_friend(void *data, struct t_gui_buffer *buffer, twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
struct t_twc_profile *profile = twc_profile_search_buffer(buffer); struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
@ -526,7 +526,7 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
* Command /group callback. * Command /group callback.
*/ */
int int
twc_cmd_group(void *data, struct t_gui_buffer *buffer, twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
struct t_twc_profile *profile = twc_profile_search_buffer(buffer); struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
@ -616,7 +616,7 @@ twc_cmd_group(void *data, struct t_gui_buffer *buffer,
* Command /invite callback. * Command /invite callback.
*/ */
int int
twc_cmd_invite(void *data, struct t_gui_buffer *buffer, twc_cmd_invite(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
if (argc == 1) if (argc == 1)
@ -654,7 +654,7 @@ twc_cmd_invite(void *data, struct t_gui_buffer *buffer,
* Command /me callback. * Command /me callback.
*/ */
int int
twc_cmd_me(void *data, struct t_gui_buffer *buffer, twc_cmd_me(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
if (argc == 1) if (argc == 1)
@ -672,7 +672,7 @@ twc_cmd_me(void *data, struct t_gui_buffer *buffer,
* Command /msg callback. * Command /msg callback.
*/ */
int int
twc_cmd_msg(void *data, struct t_gui_buffer *buffer, twc_cmd_msg(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
if (argc == 1) if (argc == 1)
@ -719,7 +719,7 @@ twc_cmd_msg(void *data, struct t_gui_buffer *buffer,
* Command /myid callback. * Command /myid callback.
*/ */
int int
twc_cmd_myid(void *data, struct t_gui_buffer *buffer, twc_cmd_myid(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
struct t_twc_profile *profile = twc_profile_search_buffer(buffer); struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
@ -744,7 +744,7 @@ twc_cmd_myid(void *data, struct t_gui_buffer *buffer,
* Command /name callback. * Command /name callback.
*/ */
int int
twc_cmd_name(void *data, struct t_gui_buffer *buffer, twc_cmd_name(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
if (argc == 1) if (argc == 1)
@ -804,7 +804,7 @@ twc_cmd_name(void *data, struct t_gui_buffer *buffer,
* Command /nospam callback. * Command /nospam callback.
*/ */
int int
twc_cmd_nospam(void *data, struct t_gui_buffer *buffer, twc_cmd_nospam(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
if (argc > 2) if (argc > 2)
@ -852,7 +852,7 @@ twc_cmd_nospam(void *data, struct t_gui_buffer *buffer,
* Command /part callback. * Command /part callback.
*/ */
int int
twc_cmd_part(void *data, struct t_gui_buffer *buffer, twc_cmd_part(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
struct t_twc_chat *chat = twc_chat_search_buffer(buffer); struct t_twc_chat *chat = twc_chat_search_buffer(buffer);
@ -886,7 +886,7 @@ twc_cmd_part(void *data, struct t_gui_buffer *buffer,
* Save Tox profile data when /save is executed. * Save Tox profile data when /save is executed.
*/ */
int int
twc_cmd_save(void *data, struct t_gui_buffer *buffer, const char *command) twc_cmd_save(const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command)
{ {
size_t index; size_t index;
struct t_twc_list_item *item; struct t_twc_list_item *item;
@ -915,7 +915,7 @@ twc_cmd_save(void *data, struct t_gui_buffer *buffer, const char *command)
* Command /status callback. * Command /status callback.
*/ */
int int
twc_cmd_status(void *data, struct t_gui_buffer *buffer, twc_cmd_status(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
if (argc != 2) if (argc != 2)
@ -945,7 +945,7 @@ twc_cmd_status(void *data, struct t_gui_buffer *buffer,
* Command /statusmsg callback. * Command /statusmsg callback.
*/ */
int int
twc_cmd_statusmsg(void *data, struct t_gui_buffer *buffer, twc_cmd_statusmsg(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
struct t_twc_profile *profile = twc_profile_search_buffer(buffer); struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
@ -986,7 +986,7 @@ twc_cmd_statusmsg(void *data, struct t_gui_buffer *buffer,
* Command /topic callback. * Command /topic callback.
*/ */
int int
twc_cmd_topic(void *data, struct t_gui_buffer *buffer, twc_cmd_topic(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
if (argc == 1) if (argc == 1)
@ -1025,7 +1025,7 @@ twc_cmd_topic(void *data, struct t_gui_buffer *buffer,
* Command /tox callback. * Command /tox callback.
*/ */
int int
twc_cmd_tox(void *data, struct t_gui_buffer *buffer, twc_cmd_tox(const void *pointer, void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol) int argc, char **argv, char **argv_eol)
{ {
// /tox [list] // /tox [list]
@ -1158,7 +1158,7 @@ twc_commands_init()
"address: internet address of node to bootstrap with\n" "address: internet address of node to bootstrap with\n"
" port: port of the node\n" " port: port of the node\n"
" Tox ID: Tox ID of the node", " Tox ID: Tox ID of the node",
"connect", twc_cmd_bootstrap, NULL); "connect", twc_cmd_bootstrap, NULL, NULL);
weechat_hook_command("friend", weechat_hook_command("friend",
"manage friends", "manage friends",
@ -1179,7 +1179,7 @@ twc_commands_init()
" || requests" " || requests"
" || accept" " || accept"
" || decline", " || decline",
twc_cmd_friend, NULL); twc_cmd_friend, NULL, NULL);
weechat_hook_command("group", weechat_hook_command("group",
"manage group chats", "manage group chats",
@ -1194,20 +1194,20 @@ twc_commands_init()
"create" "create"
" || invites" " || invites"
" || join", " || join",
twc_cmd_group, NULL); twc_cmd_group, NULL, NULL);
weechat_hook_command("invite", weechat_hook_command("invite",
"invite someone to a group chat", "invite someone to a group chat",
"<number>|<name>|<Tox ID>", "<number>|<name>|<Tox ID>",
"number, name, Tox ID: friend to message\n", "number, name, Tox ID: friend to message\n",
"%(tox_friend_name)|%(tox_friend_tox_id)", "%(tox_friend_name)|%(tox_friend_tox_id)",
twc_cmd_invite, NULL); twc_cmd_invite, NULL, NULL);
weechat_hook_command("me", weechat_hook_command("me",
"send an action to the current chat", "send an action to the current chat",
"<message>", "<message>",
"message: message to send", "message: message to send",
NULL, twc_cmd_me, NULL); NULL, twc_cmd_me, NULL, NULL);
weechat_hook_command("msg", weechat_hook_command("msg",
"send a message to a Tox friend", "send a message to a Tox friend",
@ -1215,18 +1215,18 @@ twc_commands_init()
"number, name, Tox ID: friend to message\n" "number, name, Tox ID: friend to message\n"
"message: message to send", "message: message to send",
"%(tox_friend_name)|%(tox_friend_tox_id)", "%(tox_friend_name)|%(tox_friend_tox_id)",
twc_cmd_msg, NULL); twc_cmd_msg, NULL, NULL);
weechat_hook_command("myid", weechat_hook_command("myid",
"get your Tox ID to give to friends", "get your Tox ID to give to friends",
"", "", "", "",
NULL, twc_cmd_myid, NULL); NULL, twc_cmd_myid, NULL, NULL);
weechat_hook_command("name", weechat_hook_command("name",
"change your Tox name", "change your Tox name",
"<name>", "<name>",
"name: your new name", "name: your new name",
NULL, twc_cmd_name, NULL); NULL, twc_cmd_name, NULL, NULL);
weechat_hook_command("nospam", weechat_hook_command("nospam",
"change nospam value", "change nospam value",
@ -1235,32 +1235,32 @@ twc_commands_init()
"new value is used\n\n" "new value is used\n\n"
"Warning: changing your nospam value will alter your " "Warning: changing your nospam value will alter your "
"Tox ID!", "Tox ID!",
NULL, twc_cmd_nospam, NULL); NULL, twc_cmd_nospam, NULL, NULL);
weechat_hook_command("part", weechat_hook_command("part",
"leave a group chat", "leave a group chat",
"", "", "", "",
NULL, twc_cmd_part, NULL); NULL, twc_cmd_part, NULL, NULL);
weechat_hook_command_run("/save", twc_cmd_save, NULL); weechat_hook_command_run("/save", twc_cmd_save, NULL, NULL);
weechat_hook_command("status", weechat_hook_command("status",
"change your Tox status", "change your Tox status",
"online|busy|away", "online|busy|away",
"", "",
NULL, twc_cmd_status, NULL); NULL, twc_cmd_status, NULL, NULL);
weechat_hook_command("statusmsg", weechat_hook_command("statusmsg",
"change your Tox status message", "change your Tox status message",
"[<message>]", "[<message>]",
"message: your new status message", "message: your new status message",
NULL, twc_cmd_statusmsg, NULL); NULL, twc_cmd_statusmsg, NULL, NULL);
weechat_hook_command("topic", weechat_hook_command("topic",
"set a group chat topic", "set a group chat topic",
"<topic>", "<topic>",
"topic: new group chat topic", "topic: new group chat topic",
NULL, twc_cmd_topic, NULL); NULL, twc_cmd_topic, NULL, NULL);
weechat_hook_command("tox", weechat_hook_command("tox",
"manage Tox profiles", "manage Tox profiles",
@ -1284,6 +1284,6 @@ twc_commands_init()
" || load %(tox_unloaded_profiles)|%*" " || load %(tox_unloaded_profiles)|%*"
" || unload %(tox_loaded_profiles)|%*" " || unload %(tox_loaded_profiles)|%*"
" || reload %(tox_loaded_profiles)|%*", " || reload %(tox_loaded_profiles)|%*",
twc_cmd_tox, NULL); twc_cmd_tox, NULL, NULL);
} }

View File

@ -46,12 +46,12 @@ enum
* Complete a friends name and/or Tox ID. * Complete a friends name and/or Tox ID.
*/ */
int int
twc_completion_friend(void *data, twc_completion_friend(const void *pointer, void *data,
const char *completion_item, const char *completion_item,
struct t_gui_buffer *buffer, struct t_gui_buffer *buffer,
struct t_gui_completion *completion) struct t_gui_completion *completion)
{ {
int flags = (int)(intptr_t)data; int flags = (int)(intptr_t)pointer;
struct t_twc_profile *profile = twc_profile_search_buffer(buffer); struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
if (!profile) if (!profile)
@ -108,12 +108,12 @@ twc_completion_friend(void *data,
* Complete a profile name, possibly filtering by loaded/unloaded profiles. * Complete a profile name, possibly filtering by loaded/unloaded profiles.
*/ */
int int
twc_completion_profile(void *data, twc_completion_profile(const void *pointer, void *data,
const char *completion_item, const char *completion_item,
struct t_gui_buffer *buffer, struct t_gui_buffer *buffer,
struct t_gui_completion *completion) struct t_gui_completion *completion)
{ {
int flag = (int)(intptr_t)data; int flag = (int)(intptr_t)pointer;
size_t index; size_t index;
struct t_twc_list_item *item; struct t_twc_list_item *item;
@ -137,18 +137,18 @@ twc_completion_init()
{ {
weechat_hook_completion("tox_profiles", "profile", weechat_hook_completion("tox_profiles", "profile",
twc_completion_profile, twc_completion_profile,
(void *)(intptr_t)TWC_ALL_PROFILES); (void *)(intptr_t)TWC_ALL_PROFILES, NULL);
weechat_hook_completion("tox_loaded_profiles", "loaded profile", weechat_hook_completion("tox_loaded_profiles", "loaded profile",
twc_completion_profile, twc_completion_profile,
(void *)(intptr_t)TWC_LOADED_PROFILES); (void *)(intptr_t)TWC_LOADED_PROFILES, NULL);
weechat_hook_completion("tox_unloaded_profiles", "unloaded profile", weechat_hook_completion("tox_unloaded_profiles", "unloaded profile",
twc_completion_profile, twc_completion_profile,
(void *)(intptr_t)TWC_UNLOADED_PROFILES); (void *)(intptr_t)TWC_UNLOADED_PROFILES, NULL);
weechat_hook_completion("tox_friend_tox_id", "friend Tox ID", weechat_hook_completion("tox_friend_tox_id", "friend Tox ID",
twc_completion_friend, twc_completion_friend,
(void *)(intptr_t)TWC_COMPLETE_FRIEND_ID); (void *)(intptr_t)TWC_COMPLETE_FRIEND_ID, NULL);
weechat_hook_completion("tox_friend_name", "friend name", weechat_hook_completion("tox_friend_name", "friend name",
twc_completion_friend, twc_completion_friend,
(void *)(intptr_t)TWC_COMPLETE_FRIEND_NAME); (void *)(intptr_t)TWC_COMPLETE_FRIEND_NAME, NULL);
} }

View File

@ -70,7 +70,7 @@ twc_config_profile_option_search(const char *option_name)
* Called when a profile option is read. * Called when a profile option is read.
*/ */
int int
twc_config_profile_read_callback(void *data, twc_config_profile_read_callback(const void *pointer, void *data,
struct t_config_file *config_file, struct t_config_file *config_file,
struct t_config_section *section, struct t_config_section *section,
const char *option_name, const char *option_name,
@ -132,7 +132,7 @@ twc_config_profile_read_callback(void *data,
* Callback for checking an option value being set. * Callback for checking an option value being set.
*/ */
int int
twc_config_check_value_callback(void *data, twc_config_check_value_callback(const void *pointer, void *data,
struct t_config_option *option, struct t_config_option *option,
const char *value) const char *value)
{ {
@ -149,11 +149,11 @@ twc_config_check_value_callback(void *data,
* Callback for checking an option value being set for a profile. * Callback for checking an option value being set for a profile.
*/ */
int int
twc_config_profile_check_value_callback(void *data, twc_config_profile_check_value_callback(const void *pointer, void *data,
struct t_config_option *option, struct t_config_option *option,
const char *value) const char *value)
{ {
enum t_twc_profile_option option_index = (intptr_t)data; enum t_twc_profile_option option_index = (intptr_t)pointer;
switch (option_index) switch (option_index)
{ {
@ -168,7 +168,7 @@ twc_config_profile_check_value_callback(void *data,
* Callback for option being changed for a profile. * Callback for option being changed for a profile.
*/ */
void void
twc_config_profile_change_callback(void *data, twc_config_profile_change_callback(const void *pointer, void *data,
struct t_config_option *option) struct t_config_option *option)
{ {
} }
@ -256,9 +256,11 @@ twc_config_init_option(struct t_config_section *section,
twc_config_file, section, twc_config_file, section,
option_name, type, description, string_values, min, max, option_name, type, description, string_values, min, max,
default_value, value, null_allowed, default_value, value, null_allowed,
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index, twc_config_profile_check_value_callback,
twc_config_profile_change_callback, (void *)(intptr_t)option_index, (void *)(intptr_t)option_index, NULL,
NULL, NULL); twc_config_profile_change_callback,
(void *)(intptr_t)option_index, NULL,
NULL, NULL, NULL);
} }
/** /**
@ -267,25 +269,26 @@ twc_config_init_option(struct t_config_section *section,
void void
twc_config_init() twc_config_init()
{ {
twc_config_file = weechat_config_new("tox", NULL, NULL); twc_config_file = weechat_config_new("tox", NULL, NULL, NULL);
twc_config_section_profile = twc_config_section_profile =
weechat_config_new_section(twc_config_file, "profile", weechat_config_new_section(twc_config_file, "profile",
0, 0, 0, 0,
twc_config_profile_read_callback, NULL, twc_config_profile_read_callback,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL); NULL, NULL, NULL,
NULL, NULL, NULL);
twc_config_section_profile_default = twc_config_section_profile_default =
weechat_config_new_section(twc_config_file, "profile_default", weechat_config_new_section(twc_config_file, "profile_default",
0, 0, 0, 0,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL); NULL, NULL, NULL);
for (int i = 0; i < TWC_PROFILE_NUM_OPTIONS; ++i) for (int i = 0; i < TWC_PROFILE_NUM_OPTIONS; ++i)
{ {
@ -297,11 +300,11 @@ twc_config_init()
twc_config_section_look = twc_config_section_look =
weechat_config_new_section(twc_config_file, "look", weechat_config_new_section(twc_config_file, "look",
0, 0, 0, 0,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL); NULL, NULL, NULL);
twc_config_friend_request_message = weechat_config_new_option( twc_config_friend_request_message = weechat_config_new_option(
twc_config_file, twc_config_section_look, twc_config_file, twc_config_section_look,
@ -309,16 +312,16 @@ twc_config_init()
"message sent with friend requests if no other message is specified", "message sent with friend requests if no other message is specified",
NULL, 0, 0, NULL, 0, 0,
"Hi! Please add me on Tox!", NULL, 0, "Hi! Please add me on Tox!", NULL, 0,
twc_config_check_value_callback, NULL, twc_config_check_value_callback, NULL, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL, NULL, NULL);
twc_config_short_id_size = weechat_config_new_option( twc_config_short_id_size = weechat_config_new_option(
twc_config_file, twc_config_section_look, twc_config_file, twc_config_section_look,
"short_id_size", "integer", "short_id_size", "integer",
"length of Tox IDs shown in short format; must be a multiple of two", "length of Tox IDs shown in short format; must be a multiple of two",
NULL, 2, TOX_PUBLIC_KEY_SIZE * 2, NULL, 2, TOX_PUBLIC_KEY_SIZE * 2,
"8", NULL, 0, "8", NULL, 0,
twc_config_check_value_callback, NULL, twc_config_check_value_callback, NULL, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL, NULL, NULL);
} }
/** /**

View File

@ -29,7 +29,7 @@
#include "twc-gui.h" #include "twc-gui.h"
char * char *
twc_bar_item_away(void *data, twc_bar_item_away(const void *pointer, void *data,
struct t_gui_bar_item *item, struct t_gui_bar_item *item,
struct t_gui_window *window, struct t_gui_window *window,
struct t_gui_buffer *buffer, struct t_gui_buffer *buffer,
@ -58,7 +58,7 @@ twc_bar_item_away(void *data,
} }
char * char *
twc_bar_item_input_prompt(void *data, twc_bar_item_input_prompt(const void *pointer, void *data,
struct t_gui_bar_item *item, struct t_gui_bar_item *item,
struct t_gui_window *window, struct t_gui_window *window,
struct t_gui_buffer *buffer, struct t_gui_buffer *buffer,
@ -73,7 +73,8 @@ twc_bar_item_input_prompt(void *data,
} }
char * char *
twc_bar_item_buffer_plugin(void *data, struct t_gui_bar_item *item, twc_bar_item_buffer_plugin(const void *pointer, void *data,
struct t_gui_bar_item *item,
struct t_gui_window *window, struct t_gui_window *window,
struct t_gui_buffer *buffer, struct t_gui_buffer *buffer,
struct t_hashtable *extra_info) struct t_hashtable *extra_info)
@ -104,8 +105,8 @@ twc_bar_item_buffer_plugin(void *data, struct t_gui_bar_item *item,
void twc_gui_init() void twc_gui_init()
{ {
weechat_bar_item_new("away", twc_bar_item_away, NULL); weechat_bar_item_new("away", twc_bar_item_away, NULL, NULL);
weechat_bar_item_new("input_prompt", twc_bar_item_input_prompt, NULL); weechat_bar_item_new("input_prompt", twc_bar_item_input_prompt, NULL, NULL);
weechat_bar_item_new("buffer_plugin", twc_bar_item_buffer_plugin, NULL); weechat_bar_item_new("buffer_plugin", twc_bar_item_buffer_plugin, NULL, NULL);
} }

View File

@ -90,18 +90,17 @@ twc_profile_save_data_file(struct t_twc_profile *profile)
#ifdef TOXENCRYPTSAVE_ENABLED #ifdef TOXENCRYPTSAVE_ENABLED
uint8_t enc_data[size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; uint8_t enc_data[size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
char *pw = weechat_config_string(profile->options[TWC_PROFILE_OPTION_PASSPHRASE]); const char *pw
= weechat_config_string(profile->options[TWC_PROFILE_OPTION_PASSPHRASE]);
if (pw) if (pw)
{ {
pw = weechat_string_eval_expression(pw, NULL, NULL, NULL); pw = weechat_string_eval_expression(pw, NULL, NULL, NULL);
if (!tox_pass_encrypt(data, size, (uint8_t *)pw, strlen(pw), enc_data, NULL)) if (!tox_pass_encrypt(data, size, (uint8_t *)pw, strlen(pw), enc_data, NULL))
{ {
free(pw);
weechat_printf(profile->buffer, "error encrypting data"); weechat_printf(profile->buffer, "error encrypting data");
return -1; return -1;
} }
free(pw);
d = enc_data; d = enc_data;
size += TOX_PASS_ENCRYPTION_EXTRA_LENGTH; size += TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
} }
@ -124,7 +123,7 @@ twc_profile_save_data_file(struct t_twc_profile *profile)
* Callback when a profile's main buffer is closed. Unloads the profile. * Callback when a profile's main buffer is closed. Unloads the profile.
*/ */
int int
twc_profile_buffer_close_callback(void *data, twc_profile_buffer_close_callback(const void *pointer, void *data,
struct t_gui_buffer *buffer) struct t_gui_buffer *buffer)
{ {
struct t_twc_profile *profile = data; struct t_twc_profile *profile = data;
@ -281,8 +280,9 @@ twc_profile_load(struct t_twc_profile *profile)
{ {
// create main buffer // create main buffer
profile->buffer = weechat_buffer_new(profile->name, profile->buffer = weechat_buffer_new(profile->name,
NULL, NULL, NULL, NULL, NULL,
twc_profile_buffer_close_callback, profile); twc_profile_buffer_close_callback,
profile, NULL);
if (!(profile->buffer)) if (!(profile->buffer))
return TWC_RC_ERROR; return TWC_RC_ERROR;
} }
@ -344,23 +344,18 @@ twc_profile_load(struct t_twc_profile *profile)
if (data_size && tox_is_data_encrypted(data)) if (data_size && tox_is_data_encrypted(data))
{ {
char *pw = weechat_config_string(profile->options[TWC_PROFILE_OPTION_PASSPHRASE]); const char *pw = weechat_config_string(profile->options[TWC_PROFILE_OPTION_PASSPHRASE]);
if (pw) if (pw)
{ {
// evaluate password option and duplicate as tox_*_decrypt wipes it // evaluate password option and duplicate as tox_*_decrypt wipes it
pw = weechat_string_eval_expression(pw, NULL, NULL, NULL); pw = weechat_string_eval_expression(pw, NULL, NULL, NULL);
}
if (pw)
{
if (!tox_pass_decrypt(data, data_size, (uint8_t *)pw, strlen(pw), dec_data, NULL)) if (!tox_pass_decrypt(data, data_size, (uint8_t *)pw, strlen(pw), dec_data, NULL))
{ {
free(pw);
weechat_printf(profile->buffer, "%scould not decrypt Tox data file, aborting", weechat_printf(profile->buffer, "%scould not decrypt Tox data file, aborting",
weechat_prefix("error")); weechat_prefix("error"));
return TWC_RC_ERROR; return TWC_RC_ERROR;
} }
free(pw);
data_size -= TOX_PASS_ENCRYPTION_EXTRA_LENGTH; data_size -= TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
} }
options.savedata_data = dec_data; options.savedata_data = dec_data;
@ -414,7 +409,7 @@ twc_profile_load(struct t_twc_profile *profile)
twc_bootstrap_random_node(profile->tox); twc_bootstrap_random_node(profile->tox);
// start tox_iterate loop // start tox_iterate loop
twc_do_timer_cb(profile, 0); twc_do_timer_cb(profile, NULL, 0);
// register Tox callbacks // register Tox callbacks
tox_callback_friend_message(profile->tox, twc_friend_message_callback, profile); tox_callback_friend_message(profile->tox, twc_friend_message_callback, profile);

View File

@ -33,14 +33,15 @@
#include "twc-tox-callbacks.h" #include "twc-tox-callbacks.h"
int int
twc_do_timer_cb(void *data, twc_do_timer_cb(const void *pointer, void *data,
int remaining_calls) int remaining_calls)
{ {
struct t_twc_profile *profile = data; /* TODO: don't strip the const */
struct t_twc_profile *profile = (void *)pointer;
tox_iterate(profile->tox); tox_iterate(profile->tox);
struct t_hook *hook = weechat_hook_timer(tox_iteration_interval(profile->tox), struct t_hook *hook = weechat_hook_timer(tox_iteration_interval(profile->tox),
0, 1, twc_do_timer_cb, profile); 0, 1, twc_do_timer_cb, profile, NULL);
profile->tox_do_timer = hook; profile->tox_do_timer = hook;
// check connection status // check connection status

View File

@ -23,7 +23,7 @@
#include <tox/tox.h> #include <tox/tox.h>
int int
twc_do_timer_cb(void *data, twc_do_timer_cb(const void *pointer, void *data,
int remaining_calls); int remaining_calls);
void void