Add .clang-format. Reformat everything.
This commit is contained in:
parent
2947cc1562
commit
fa579df623
32 changed files with 994 additions and 1126 deletions
62
.clang-format
Normal file
62
.clang-format
Normal file
|
@ -0,0 +1,62 @@
|
|||
---
|
||||
BasedOnStyle: LLVM
|
||||
Language: Cpp
|
||||
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlinesLeft: false
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: All
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Allman
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
ColumnLimit: 80
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
DerivePointerAlignment: false
|
||||
ForEachMacros: [ 'twc_list_foreach', 'twc_list_foreach_reverse' ]
|
||||
IncludeCategories:
|
||||
- Regex: '^"'
|
||||
Priority: 1
|
||||
- Regex: '^<'
|
||||
Priority: 2
|
||||
IndentCaseLabels: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
...
|
|
@ -17,20 +17,9 @@
|
|||
# along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
project(tox-weechat C)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
||||
|
||||
find_package(WeeChat REQUIRED)
|
||||
find_package(Tox REQUIRED
|
||||
COMPONENTS CORE
|
||||
OPTIONAL_COMPONENTS AV ENCRYPTSAVE)
|
||||
|
||||
set(PLUGIN_PATH "lib/weechat/plugins" CACHE PATH
|
||||
"Path to install the plugin binary to.")
|
||||
|
||||
add_library(tox MODULE
|
||||
src/twc.c
|
||||
src/twc-bootstrap.c
|
||||
|
@ -45,27 +34,33 @@ add_library(tox MODULE
|
|||
src/twc-message-queue.c
|
||||
src/twc-profile.c
|
||||
src/twc-tox-callbacks.c
|
||||
src/twc-utils.c
|
||||
)
|
||||
src/twc-utils.c)
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "-DTWC_DEBUG")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wextra -Wno-unused-parameter")
|
||||
set_target_properties(tox PROPERTIES
|
||||
PREFIX "" # remove lib prefix (libtox.so -> tox.so)
|
||||
C_STANDARD 99)
|
||||
target_compile_options(tox PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||
|
||||
include_directories(${Tox_INCLUDE_DIRS})
|
||||
include_directories(${WeeChat_INCLUDE_DIRS})
|
||||
# find include and shared library locations
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
find_package(WeeChat)
|
||||
find_package(Tox REQUIRED CORE OPTIONAL_COMPONENTS AV ENCRYPTSAVE)
|
||||
|
||||
target_link_libraries(tox ${Tox_LIBRARIES})
|
||||
target_include_directories(tox PRIVATE
|
||||
"${WeeChat_INCLUDE_DIRS}"
|
||||
"${Tox_INCLUDE_DIRS}")
|
||||
target_link_libraries(tox "${Tox_LIBRARIES}")
|
||||
|
||||
if(Tox_AV_FOUND)
|
||||
add_definitions(-DTOXAV_ENABLED)
|
||||
target_compile_definitions(tox PRIVATE TOXAV_ENABLED)
|
||||
endif()
|
||||
|
||||
if(Tox_ENCRYPTSAVE_FOUND)
|
||||
add_definitions(-DTOXENCRYPTSAVE_ENABLED)
|
||||
target_compile_definitions(tox PRIVATE TOXENCRYPTSAVE_ENABLED)
|
||||
endif()
|
||||
|
||||
# remove lib prefix (libtox.so -> tox.so)
|
||||
set_target_properties(tox PROPERTIES PREFIX "")
|
||||
|
||||
# install plugin binary
|
||||
set(PLUGIN_PATH "lib/weechat/plugins" CACHE PATH
|
||||
"Path to install the plugin binary to.")
|
||||
install(TARGETS tox DESTINATION "${PLUGIN_PATH}")
|
||||
|
||||
|
|
20
README.md
20
README.md
|
@ -2,7 +2,10 @@
|
|||
Tox-WeeChat is a [Tox][1] protocol plugin for [WeeChat][2]. It is functional,
|
||||
but lacks certain features that might be expected of a full-fledged Tox client.
|
||||
|
||||
[![Build Status](https://travis-ci.org/haavard/tox-weechat.svg?branch=master)][3]
|
||||
Tox-WeeChat is compliant with all "Required" points in the [Tox Client
|
||||
Standard][3].
|
||||
|
||||
[![Build Status](https://travis-ci.org/haavard/tox-weechat.svg?branch=master)][4]
|
||||
|
||||
## Features
|
||||
- One-to-one chats
|
||||
|
@ -12,8 +15,8 @@ but lacks certain features that might be expected of a full-fledged Tox client.
|
|||
- Encrypted save files
|
||||
|
||||
## Installation
|
||||
Tox-WeeChat is tested with [WeeChat][2] 1.7 and [TokTok c-toxcore][4] 0.1.6.
|
||||
It also requires CMake 2.8.11 or later to be built. Installation is fairly
|
||||
Tox-WeeChat is tested with [WeeChat][2] 1.7 and [TokTok c-toxcore][5] 0.1.6.
|
||||
It also requires CMake 2.8.12 or newer to be built. Installation is fairly
|
||||
simple; after getting the source code, compile and install with CMake:
|
||||
|
||||
$ mkdir build && cd build
|
||||
|
@ -25,7 +28,8 @@ This installs the plugin binary `tox.so` to the recommended location
|
|||
|
||||
## Usage
|
||||
- If the plugin does not load automatically, load it with `/plugin load tox`.
|
||||
You may have to specify the full path to the plugin binary.
|
||||
You may have to specify the full path to the plugin binary if you installed
|
||||
it to a non-standard location.
|
||||
- Create a new profile with `/tox create <profile name>`. The data file is
|
||||
stored in `~/.weechat/tox/` by default.
|
||||
- Load your profile and connect to the Tox network with
|
||||
|
@ -45,8 +49,7 @@ your screen space, you can set the following options in WeeChat:
|
|||
Make sure the proxy type, address and port is correct, and that UDP is
|
||||
disabled (`/set tox.profile.*.udp`).
|
||||
|
||||
License
|
||||
---------
|
||||
## License
|
||||
Copyright (c) 2017 Håvard Pettersson <mail@haavard.me>
|
||||
|
||||
This file is part of Tox-WeeChat.
|
||||
|
@ -66,6 +69,7 @@ along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
[1]: http://tox.chat
|
||||
[2]: http://weechat.org
|
||||
[3]: https://travis-ci.org/haavard/tox-weechat
|
||||
[4]: https://github.com/TokTok/c-toxcore
|
||||
[3]: https://github.com/Tox/Tox-Client-Standard
|
||||
[4]: https://travis-ci.org/haavard/tox-weechat
|
||||
[5]: https://github.com/TokTok/c-toxcore
|
||||
|
||||
|
|
|
@ -31,22 +31,25 @@ find_library(Tox_ENCRYPTSAVE_LIBRARY toxencryptsave)
|
|||
|
||||
if(Tox_CORE_INCLUDE_DIR AND Tox_CORE_LIBRARY)
|
||||
set(Tox_CORE_FOUND TRUE)
|
||||
list(APPEND Tox_INCLUDE_DIRS ${Tox_CORE_INCLUDE_DIR})
|
||||
list(APPEND Tox_LIBRARIES ${Tox_CORE_LIBRARY})
|
||||
list(APPEND Tox_INCLUDE_DIRS "${Tox_CORE_INCLUDE_DIR}")
|
||||
list(APPEND Tox_LIBRARIES "${Tox_CORE_LIBRARY}")
|
||||
endif()
|
||||
|
||||
if(Tox_AV_INCLUDE_DIR AND Tox_AV_LIBRARY)
|
||||
set(Tox_AV_FOUND TRUE)
|
||||
list(APPEND Tox_INCLUDE_DIRS ${Tox_AV_INCLUDE_DIR})
|
||||
list(APPEND Tox_LIBRARIES ${Tox_AV_LIBRARY})
|
||||
list(APPEND Tox_INCLUDE_DIRS "${Tox_AV_INCLUDE_DIR}")
|
||||
list(APPEND Tox_LIBRARIES "${Tox_AV_LIBRARY}")
|
||||
endif()
|
||||
|
||||
if(Tox_ENCRYPTSAVE_INCLUDE_DIR AND Tox_ENCRYPTSAVE_LIBRARY)
|
||||
set(Tox_ENCRYPTSAVE_FOUND TRUE)
|
||||
list(APPEND Tox_INCLUDE_DIRS ${Tox_ENCRYPTSAVE_INCLUDE_DIR})
|
||||
list(APPEND Tox_LIBRARIES ${Tox_ENCRYPTSAVE_LIBRARY})
|
||||
list(APPEND Tox_INCLUDE_DIRS "${Tox_ENCRYPTSAVE_INCLUDE_DIR}")
|
||||
list(APPEND Tox_LIBRARIES "${Tox_ENCRYPTSAVE_LIBRARY}")
|
||||
endif()
|
||||
|
||||
list(REMOVE_DUPLICATES Tox_INCLUDE_DIRS)
|
||||
list(REMOVE_DUPLICATES Tox_LIBRARIES)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Tox
|
||||
FOUND_VAR Tox_FOUND
|
||||
|
|
|
@ -78,27 +78,24 @@ char *twc_bootstrap_keys[] = {
|
|||
/* Maintainer: ws, location: NZ */
|
||||
"F202E0936ABEE09067F55B0955C3FF6A84ABEED3C750A9EB930D926D03248F4C",
|
||||
/* Maintainer: clearmartin, location: DE */
|
||||
"CD133B521159541FB1D326DE9850F5E56A6C724B5B8E5EB5CD8D950408E95707"
|
||||
};
|
||||
"CD133B521159541FB1D326DE9850F5E56A6C724B5B8E5EB5CD8D950408E95707"};
|
||||
|
||||
char *twc_bootstrap_addresses[] = {
|
||||
"130.133.110.14", "205.185.116.116", "198.98.51.198",
|
||||
"108.61.165.198", "194.249.212.109", "185.25.116.107",
|
||||
"95.215.46.114", "5.189.176.217", "148.251.23.146", "104.223.122.15",
|
||||
"104.233.104.126", "51.254.84.212", "185.58.206.164", "92.54.84.70",
|
||||
"95.215.44.78", "163.172.136.118", "37.97.185.116", "193.124.186.205",
|
||||
"80.87.193.193", "46.229.52.198", "185.14.30.213", "77.37.160.178",
|
||||
"85.21.144.224", "37.187.122.30", "202.36.75.162", "46.101.197.175"
|
||||
};
|
||||
"130.133.110.14", "205.185.116.116", "198.98.51.198", "108.61.165.198",
|
||||
"194.249.212.109", "185.25.116.107", "95.215.46.114", "5.189.176.217",
|
||||
"148.251.23.146", "104.223.122.15", "104.233.104.126", "51.254.84.212",
|
||||
"185.58.206.164", "92.54.84.70", "95.215.44.78", "163.172.136.118",
|
||||
"37.97.185.116", "193.124.186.205", "80.87.193.193", "46.229.52.198",
|
||||
"185.14.30.213", "77.37.160.178", "85.21.144.224", "37.187.122.30",
|
||||
"202.36.75.162", "46.101.197.175"};
|
||||
|
||||
uint16_t twc_bootstrap_ports[] = {
|
||||
33445, 33445, 33445, 33445, 33445, 33445, 33445, 5190, 2306, 33445,
|
||||
33445, 33445, 33445, 33445, 33445, 33445, 33445, 5228, 33445, 33445,
|
||||
443, 33440, 33445, 33445, 33445, 443
|
||||
};
|
||||
33445, 33445, 33445, 33445, 33445, 33445, 33445, 5190, 2306,
|
||||
33445, 33445, 33445, 33445, 33445, 33445, 33445, 33445, 5228,
|
||||
33445, 33445, 443, 33440, 33445, 33445, 33445, 443};
|
||||
|
||||
int twc_bootstrap_count = sizeof(twc_bootstrap_addresses)
|
||||
/ sizeof(twc_bootstrap_addresses[0]);
|
||||
int twc_bootstrap_count =
|
||||
sizeof(twc_bootstrap_addresses) / sizeof(twc_bootstrap_addresses[0]);
|
||||
|
||||
/**
|
||||
* Bootstrap a Tox object with a DHT bootstrap node. Returns the result of
|
||||
|
@ -112,8 +109,7 @@ twc_bootstrap_tox(Tox *tox, const char *address, uint16_t port,
|
|||
twc_hex2bin(public_key, TOX_ADDRESS_SIZE, binary_key);
|
||||
TOX_ERR_BOOTSTRAP err;
|
||||
|
||||
int result = tox_bootstrap(tox, address, port,
|
||||
binary_key, &err);
|
||||
int result = tox_bootstrap(tox, address, port, binary_key, &err);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -125,8 +121,6 @@ void
|
|||
twc_bootstrap_random_node(Tox *tox)
|
||||
{
|
||||
int i = rand() % twc_bootstrap_count;
|
||||
twc_bootstrap_tox(tox, twc_bootstrap_addresses[i],
|
||||
twc_bootstrap_ports[i],
|
||||
twc_bootstrap_keys[i]);
|
||||
twc_bootstrap_tox(tox, twc_bootstrap_addresses[i], twc_bootstrap_ports[i],
|
||||
twc_bootstrap_keys[i]);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,5 +29,4 @@ twc_bootstrap_tox(Tox *tox, const char *address, uint16_t port,
|
|||
void
|
||||
twc_bootstrap_random_node(Tox *tox);
|
||||
|
||||
#endif // TOX_WEECHAT_BOOTSTRAP_H
|
||||
|
||||
#endif /* TOX_WEECHAT_BOOTSTRAP_H */
|
||||
|
|
127
src/twc-chat.c
127
src/twc-chat.c
|
@ -20,14 +20,14 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-message-queue.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-utils.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-chat.h"
|
||||
|
||||
|
@ -36,13 +36,11 @@ const char *twc_tag_sent_message = "tox_sent";
|
|||
const char *twc_tag_received_message = "tox_received";
|
||||
|
||||
int
|
||||
twc_chat_buffer_input_callback(const void *pointer,
|
||||
void *data,
|
||||
twc_chat_buffer_input_callback(const void *pointer, void *data,
|
||||
struct t_gui_buffer *weechat_buffer,
|
||||
const char *input_data);
|
||||
int
|
||||
twc_chat_buffer_close_callback(const void *pointer,
|
||||
void *data,
|
||||
twc_chat_buffer_close_callback(const void *pointer, void *data,
|
||||
struct t_gui_buffer *weechat_buffer);
|
||||
|
||||
/**
|
||||
|
@ -65,20 +63,20 @@ twc_chat_new(struct t_twc_profile *profile, const char *name)
|
|||
chat->buffer = weechat_buffer_search("tox", full_name);
|
||||
if (!(chat->buffer))
|
||||
{
|
||||
chat->buffer = weechat_buffer_new(full_name,
|
||||
twc_chat_buffer_input_callback, chat, NULL,
|
||||
twc_chat_buffer_close_callback, chat, NULL);
|
||||
chat->buffer = weechat_buffer_new(
|
||||
full_name, twc_chat_buffer_input_callback, chat, NULL,
|
||||
twc_chat_buffer_close_callback, chat, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_buffer_set_pointer(chat->buffer,
|
||||
"input_callback",
|
||||
weechat_buffer_set_pointer(chat->buffer, "input_callback",
|
||||
twc_chat_buffer_input_callback);
|
||||
weechat_buffer_set_pointer(chat->buffer, "input_callback_pointer", chat);
|
||||
weechat_buffer_set_pointer(chat->buffer,
|
||||
"close_callback",
|
||||
weechat_buffer_set_pointer(chat->buffer, "input_callback_pointer",
|
||||
chat);
|
||||
weechat_buffer_set_pointer(chat->buffer, "close_callback",
|
||||
twc_chat_buffer_close_callback);
|
||||
weechat_buffer_set_pointer(chat->buffer, "close_callback_pointer", chat);
|
||||
weechat_buffer_set_pointer(chat->buffer, "close_callback_pointer",
|
||||
chat);
|
||||
}
|
||||
|
||||
free(full_name);
|
||||
|
@ -109,7 +107,7 @@ twc_chat_new_friend(struct t_twc_profile *profile, int32_t friend_number)
|
|||
TOX_ERR_FRIEND_GET_PUBLIC_KEY err;
|
||||
tox_friend_get_public_key(profile->tox, friend_number, client_id, &err);
|
||||
if (err != TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
char buffer_name[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
||||
twc_bin2hex(client_id, TOX_PUBLIC_KEY_SIZE, buffer_name);
|
||||
|
@ -135,8 +133,8 @@ twc_chat_new_group(struct t_twc_profile *profile, int32_t group_number)
|
|||
{
|
||||
chat->group_number = group_number;
|
||||
|
||||
chat->nicklist_group = weechat_nicklist_add_group(chat->buffer, NULL,
|
||||
NULL, NULL, true);
|
||||
chat->nicklist_group =
|
||||
weechat_nicklist_add_group(chat->buffer, NULL, NULL, NULL, true);
|
||||
chat->nicks = weechat_list_new();
|
||||
|
||||
weechat_buffer_set(chat->buffer, "nicklist", "1");
|
||||
|
@ -158,19 +156,20 @@ twc_chat_refresh(const struct t_twc_chat *chat)
|
|||
|
||||
if (chat->friend_number >= 0)
|
||||
{
|
||||
name = twc_get_name_nt(chat->profile->tox,
|
||||
chat->friend_number);
|
||||
title = twc_get_status_message_nt(chat->profile->tox,
|
||||
chat->friend_number);
|
||||
name = twc_get_name_nt(chat->profile->tox, chat->friend_number);
|
||||
title =
|
||||
twc_get_status_message_nt(chat->profile->tox, chat->friend_number);
|
||||
}
|
||||
else if (chat->group_number >= 0)
|
||||
{
|
||||
char group_name[TOX_MAX_NAME_LENGTH + 1] = {0};
|
||||
int len = tox_conference_get_title_size(chat->profile->tox, chat->group_number,
|
||||
&err);
|
||||
if ((err == TOX_ERR_CONFERENCE_TITLE_OK) && (len <= TOX_MAX_NAME_LENGTH))
|
||||
rc = tox_conference_get_title(chat->profile->tox, chat->group_number,
|
||||
(uint8_t *)group_name, &err);
|
||||
int len = tox_conference_get_title_size(chat->profile->tox,
|
||||
chat->group_number, &err);
|
||||
if ((err == TOX_ERR_CONFERENCE_TITLE_OK) &&
|
||||
(len <= TOX_MAX_NAME_LENGTH))
|
||||
rc =
|
||||
tox_conference_get_title(chat->profile->tox, chat->group_number,
|
||||
(uint8_t *)group_name, &err);
|
||||
if (!rc)
|
||||
sprintf(group_name, "Group Chat %d", chat->group_number);
|
||||
|
||||
|
@ -204,8 +203,7 @@ twc_chat_refresh_timer_callback(const void *pointer, void *data, int remaining)
|
|||
void
|
||||
twc_chat_queue_refresh(struct t_twc_chat *chat)
|
||||
{
|
||||
weechat_hook_timer(1, 0, 1,
|
||||
twc_chat_refresh_timer_callback, chat, NULL);
|
||||
weechat_hook_timer(1, 0, 1, twc_chat_refresh_timer_callback, chat, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,12 +211,12 @@ twc_chat_queue_refresh(struct t_twc_chat *chat)
|
|||
* create a new one.
|
||||
*/
|
||||
struct t_twc_chat *
|
||||
twc_chat_search_friend(struct t_twc_profile *profile,
|
||||
int32_t friend_number, bool create_new)
|
||||
twc_chat_search_friend(struct t_twc_profile *profile, int32_t friend_number,
|
||||
bool create_new)
|
||||
{
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(profile->chats, index, item)
|
||||
twc_list_foreach (profile->chats, index, item)
|
||||
{
|
||||
if (item->chat->friend_number == friend_number)
|
||||
return item->chat;
|
||||
|
@ -235,12 +233,12 @@ twc_chat_search_friend(struct t_twc_profile *profile,
|
|||
* create a new one.
|
||||
*/
|
||||
struct t_twc_chat *
|
||||
twc_chat_search_group(struct t_twc_profile *profile,
|
||||
int32_t group_number, bool create_new)
|
||||
twc_chat_search_group(struct t_twc_profile *profile, int32_t group_number,
|
||||
bool create_new)
|
||||
{
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(profile->chats, index, item)
|
||||
twc_list_foreach (profile->chats, index, item)
|
||||
{
|
||||
if (item->chat->group_number == group_number)
|
||||
return item->chat;
|
||||
|
@ -260,11 +258,11 @@ twc_chat_search_buffer(struct t_gui_buffer *buffer)
|
|||
{
|
||||
size_t profile_index;
|
||||
struct t_twc_list_item *profile_item;
|
||||
twc_list_foreach(twc_profiles, profile_index, profile_item)
|
||||
twc_list_foreach (twc_profiles, profile_index, profile_item)
|
||||
{
|
||||
size_t chat_index;
|
||||
struct t_twc_list_item *chat_item;
|
||||
twc_list_foreach(profile_item->profile->chats, chat_index, chat_item)
|
||||
twc_list_foreach (profile_item->profile->chats, chat_index, chat_item)
|
||||
{
|
||||
if (chat_item->chat->buffer == buffer)
|
||||
{
|
||||
|
@ -275,32 +273,24 @@ twc_chat_search_buffer(struct t_gui_buffer *buffer)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print a chat message to a chat's buffer.
|
||||
*/
|
||||
void
|
||||
twc_chat_print_message(struct t_twc_chat *chat,
|
||||
const char *tags,
|
||||
const char *color,
|
||||
const char *sender,
|
||||
const char *message,
|
||||
TOX_MESSAGE_TYPE message_type)
|
||||
twc_chat_print_message(struct t_twc_chat *chat, const char *tags,
|
||||
const char *color, const char *sender,
|
||||
const char *message, TOX_MESSAGE_TYPE message_type)
|
||||
{
|
||||
switch (message_type)
|
||||
{
|
||||
case TOX_MESSAGE_TYPE_NORMAL:
|
||||
weechat_printf_date_tags(chat->buffer, 0, tags,
|
||||
"%s%s%s\t%s",
|
||||
color, sender,
|
||||
weechat_color("reset"), message);
|
||||
weechat_printf_date_tags(chat->buffer, 0, tags, "%s%s%s\t%s", color,
|
||||
sender, weechat_color("reset"), message);
|
||||
break;
|
||||
case TOX_MESSAGE_TYPE_ACTION:
|
||||
weechat_printf_date_tags(chat->buffer, 0, tags,
|
||||
"%s%s%s%s %s",
|
||||
weechat_prefix("action"),
|
||||
color, sender,
|
||||
weechat_color("reset"), message);
|
||||
weechat_printf_date_tags(chat->buffer, 0, tags, "%s%s%s%s %s",
|
||||
weechat_prefix("action"), color, sender,
|
||||
weechat_color("reset"), message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -315,13 +305,12 @@ twc_chat_send_message(struct t_twc_chat *chat, const char *message,
|
|||
TOX_ERR_CONFERENCE_SEND_MESSAGE err = TOX_ERR_CONFERENCE_SEND_MESSAGE_OK;
|
||||
if (chat->friend_number >= 0)
|
||||
{
|
||||
twc_message_queue_add_friend_message(chat->profile,
|
||||
chat->friend_number,
|
||||
twc_message_queue_add_friend_message(chat->profile, chat->friend_number,
|
||||
message, message_type);
|
||||
char *name = twc_get_self_name_nt(chat->profile->tox);
|
||||
twc_chat_print_message(chat, "notify_message",
|
||||
weechat_color("chat_nick_self"), name,
|
||||
message, message_type);
|
||||
weechat_color("chat_nick_self"), name, message,
|
||||
message_type);
|
||||
free(name);
|
||||
}
|
||||
else if (chat->group_number >= 0)
|
||||
|
@ -332,8 +321,8 @@ twc_chat_send_message(struct t_twc_chat *chat, const char *message,
|
|||
int fit_len = twc_fit_utf8(message, TWC_MAX_GROUP_MESSAGE_LENGTH);
|
||||
err = TOX_ERR_CONFERENCE_SEND_MESSAGE_OK;
|
||||
tox_conference_send_message(chat->profile->tox, chat->group_number,
|
||||
message_type, (uint8_t *)message, fit_len,
|
||||
&err);
|
||||
message_type, (uint8_t *)message,
|
||||
fit_len, &err);
|
||||
if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK)
|
||||
break;
|
||||
message += fit_len;
|
||||
|
@ -341,12 +330,10 @@ twc_chat_send_message(struct t_twc_chat *chat, const char *message,
|
|||
}
|
||||
if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK)
|
||||
{
|
||||
weechat_printf(chat->buffer,
|
||||
"%s%sFailed to send message with error %d%s",
|
||||
weechat_prefix("error"),
|
||||
weechat_color("chat_highlight"),
|
||||
err,
|
||||
weechat_color("reset"));
|
||||
weechat_printf(
|
||||
chat->buffer, "%s%sFailed to send message with error %d%s",
|
||||
weechat_prefix("error"), weechat_color("chat_highlight"), err,
|
||||
weechat_color("reset"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -382,9 +369,10 @@ twc_chat_buffer_close_callback(const void *pointer, void *data,
|
|||
tox_conference_delete(chat->profile->tox, chat->group_number, &err);
|
||||
if (err != TOX_ERR_CONFERENCE_DELETE_OK)
|
||||
{
|
||||
weechat_printf(chat->profile->buffer,
|
||||
"%swarning: failed to leave group chat with error %d",
|
||||
weechat_prefix("error"), err);
|
||||
weechat_printf(
|
||||
chat->profile->buffer,
|
||||
"%swarning: failed to leave group chat with error %d",
|
||||
weechat_prefix("error"), err);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,4 +413,3 @@ twc_chat_free_list(struct t_twc_list *list)
|
|||
|
||||
free(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
#ifndef TOX_WEECHAT_CHAT_H
|
||||
#define TOX_WEECHAT_CHAT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct t_twc_list;
|
||||
|
||||
|
@ -42,12 +42,12 @@ struct t_twc_chat
|
|||
};
|
||||
|
||||
struct t_twc_chat *
|
||||
twc_chat_search_friend(struct t_twc_profile *profile,
|
||||
int32_t friend_number, bool create_new);
|
||||
twc_chat_search_friend(struct t_twc_profile *profile, int32_t friend_number,
|
||||
bool create_new);
|
||||
|
||||
struct t_twc_chat *
|
||||
twc_chat_search_group(struct t_twc_profile *profile,
|
||||
int32_t group_number, bool create_new);
|
||||
twc_chat_search_group(struct t_twc_profile *profile, int32_t group_number,
|
||||
bool create_new);
|
||||
|
||||
struct t_twc_chat *
|
||||
twc_chat_search_buffer(struct t_gui_buffer *target_buffer);
|
||||
|
@ -56,12 +56,9 @@ enum t_twc_rc
|
|||
twc_chat_set_logging(struct t_twc_chat const *const chat, bool logging);
|
||||
|
||||
void
|
||||
twc_chat_print_message(struct t_twc_chat *chat,
|
||||
const char *tags,
|
||||
const char *color,
|
||||
const char *sender,
|
||||
const char *message,
|
||||
TOX_MESSAGE_TYPE message_type);
|
||||
twc_chat_print_message(struct t_twc_chat *chat, const char *tags,
|
||||
const char *color, const char *sender,
|
||||
const char *message, TOX_MESSAGE_TYPE message_type);
|
||||
|
||||
void
|
||||
twc_chat_send_message(struct t_twc_chat *chat, const char *message,
|
||||
|
@ -76,5 +73,4 @@ twc_chat_free(struct t_twc_chat *chat);
|
|||
void
|
||||
twc_chat_free_list(struct t_twc_list *list);
|
||||
|
||||
#endif // TOX_WEECHAT_CHAT_H
|
||||
|
||||
#endif /* TOX_WEECHAT_CHAT_H */
|
||||
|
|
|
@ -17,21 +17,21 @@
|
|||
* along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-bootstrap.h"
|
||||
#include "twc-chat.h"
|
||||
#include "twc-config.h"
|
||||
#include "twc-friend-request.h"
|
||||
#include "twc-group-invite.h"
|
||||
#include "twc-bootstrap.h"
|
||||
#include "twc-config.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-utils.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-commands.h"
|
||||
|
||||
|
@ -45,96 +45,88 @@ enum TWC_FRIEND_MATCH
|
|||
* Make sure a command is executed on a Tox profile buffer. If not, warn user
|
||||
* and abort.
|
||||
*/
|
||||
#define TWC_CHECK_PROFILE(profile) \
|
||||
if (!profile) \
|
||||
{ \
|
||||
weechat_printf(NULL, \
|
||||
"%s%s: command \"%s\" must be executed on a Tox " \
|
||||
"buffer", \
|
||||
weechat_prefix("error"), weechat_plugin->name, \
|
||||
argv[0]); \
|
||||
return WEECHAT_RC_OK; \
|
||||
} \
|
||||
#define TWC_CHECK_PROFILE(profile) \
|
||||
if (!profile) \
|
||||
{ \
|
||||
weechat_printf(NULL, "%s%s: command \"%s\" must be executed on a Tox " \
|
||||
"buffer", \
|
||||
weechat_prefix("error"), weechat_plugin->name, \
|
||||
argv[0]); \
|
||||
return WEECHAT_RC_OK; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure a command is executed in a chat buffer. If not, warn user and
|
||||
* abort.
|
||||
*/
|
||||
#define TWC_CHECK_CHAT(chat) \
|
||||
if (!chat) \
|
||||
{ \
|
||||
weechat_printf(NULL, \
|
||||
"%s%s: command \"%s\" must be executed in a chat " \
|
||||
"buffer", \
|
||||
weechat_prefix("error"), \
|
||||
weechat_plugin->name, \
|
||||
argv[0]); \
|
||||
return WEECHAT_RC_OK; \
|
||||
#define TWC_CHECK_CHAT(chat) \
|
||||
if (!chat) \
|
||||
{ \
|
||||
weechat_printf( \
|
||||
NULL, "%s%s: command \"%s\" must be executed in a chat " \
|
||||
"buffer", \
|
||||
weechat_prefix("error"), weechat_plugin->name, argv[0]); \
|
||||
return WEECHAT_RC_OK; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure a command is executed in a group chat buffer. If not, warn user
|
||||
* and abort.
|
||||
*/
|
||||
#define TWC_CHECK_GROUP_CHAT(chat) \
|
||||
if (!chat || chat->group_number < 0) \
|
||||
{ \
|
||||
weechat_printf(NULL, \
|
||||
"%s%s: command \"%s\" must be executed in a group " \
|
||||
"chat buffer ", \
|
||||
weechat_prefix("error"), \
|
||||
weechat_plugin->name, \
|
||||
argv[0]); \
|
||||
return WEECHAT_RC_OK; \
|
||||
#define TWC_CHECK_GROUP_CHAT(chat) \
|
||||
if (!chat || chat->group_number < 0) \
|
||||
{ \
|
||||
weechat_printf( \
|
||||
NULL, "%s%s: command \"%s\" must be executed in a group " \
|
||||
"chat buffer ", \
|
||||
weechat_prefix("error"), weechat_plugin->name, argv[0]); \
|
||||
return WEECHAT_RC_OK; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure a profile with the given name exists. If not, warn user and abort.
|
||||
*/
|
||||
#define TWC_CHECK_PROFILE_EXISTS(profile) \
|
||||
if (!profile) \
|
||||
{ \
|
||||
weechat_printf(NULL, \
|
||||
"%s%s: profile \"%s\" does not exist.", \
|
||||
weechat_prefix("error"), weechat_plugin->name, \
|
||||
name); \
|
||||
return WEECHAT_RC_OK; \
|
||||
#define TWC_CHECK_PROFILE_EXISTS(profile) \
|
||||
if (!profile) \
|
||||
{ \
|
||||
weechat_printf(NULL, "%s%s: profile \"%s\" does not exist.", \
|
||||
weechat_prefix("error"), weechat_plugin->name, name); \
|
||||
return WEECHAT_RC_OK; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure a profile is loaded.
|
||||
*/
|
||||
#define TWC_CHECK_PROFILE_LOADED(profile) \
|
||||
if (!(profile->tox)) \
|
||||
{ \
|
||||
weechat_printf(profile->buffer, \
|
||||
"%sprofile must be loaded for command \"%s\"", \
|
||||
weechat_prefix("error"), argv[0]); \
|
||||
return WEECHAT_RC_OK; \
|
||||
#define TWC_CHECK_PROFILE_LOADED(profile) \
|
||||
if (!(profile->tox)) \
|
||||
{ \
|
||||
weechat_printf(profile->buffer, \
|
||||
"%sprofile must be loaded for command \"%s\"", \
|
||||
weechat_prefix("error"), argv[0]); \
|
||||
return WEECHAT_RC_OK; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure friend exists.
|
||||
*/
|
||||
#define TWC_CHECK_FRIEND_NUMBER(profile, number, string) \
|
||||
if (number == TWC_FRIEND_MATCH_NOMATCH) \
|
||||
{ \
|
||||
weechat_printf(profile->buffer, \
|
||||
"%sno friend number, name or Tox ID found matching " \
|
||||
"\"%s\"", \
|
||||
weechat_prefix("error"), string); \
|
||||
return WEECHAT_RC_OK; \
|
||||
} \
|
||||
if (number == TWC_FRIEND_MATCH_AMBIGUOUS) \
|
||||
{ \
|
||||
weechat_printf(profile->buffer, \
|
||||
"%smultiple friends with name \"%s\" found; please " \
|
||||
"use Tox ID instead", \
|
||||
weechat_prefix("error"), string); \
|
||||
return WEECHAT_RC_OK; \
|
||||
#define TWC_CHECK_FRIEND_NUMBER(profile, number, string) \
|
||||
if (number == TWC_FRIEND_MATCH_NOMATCH) \
|
||||
{ \
|
||||
weechat_printf(profile->buffer, \
|
||||
"%sno friend number, name or Tox ID found matching " \
|
||||
"\"%s\"", \
|
||||
weechat_prefix("error"), string); \
|
||||
return WEECHAT_RC_OK; \
|
||||
} \
|
||||
if (number == TWC_FRIEND_MATCH_AMBIGUOUS) \
|
||||
{ \
|
||||
weechat_printf(profile->buffer, \
|
||||
"%smultiple friends with name \"%s\" found; please " \
|
||||
"use Tox ID instead", \
|
||||
weechat_prefix("error"), string); \
|
||||
return WEECHAT_RC_OK; \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get number of friend matching string. Tries to match number, name and
|
||||
* Tox ID.
|
||||
|
@ -150,8 +142,8 @@ twc_match_friend(struct t_twc_profile *profile, const char *search_string)
|
|||
|
||||
char *endptr;
|
||||
uint32_t friend_number = (uint32_t)strtoul(search_string, &endptr, 10);
|
||||
if (endptr == search_string + strlen(search_string)
|
||||
&& tox_friend_exists(profile->tox, friend_number))
|
||||
if (endptr == search_string + strlen(search_string) &&
|
||||
tox_friend_exists(profile->tox, friend_number))
|
||||
return friend_number;
|
||||
|
||||
size_t search_size = strlen(search_string);
|
||||
|
@ -162,7 +154,8 @@ twc_match_friend(struct t_twc_profile *profile, const char *search_string)
|
|||
uint8_t tox_id[TOX_PUBLIC_KEY_SIZE];
|
||||
char hex_id[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
||||
|
||||
if (tox_friend_get_public_key(profile->tox, friend_numbers[i], tox_id, NULL))
|
||||
if (tox_friend_get_public_key(profile->tox, friend_numbers[i],
|
||||
tox_id, NULL))
|
||||
{
|
||||
twc_bin2hex(tox_id, TOX_PUBLIC_KEY_SIZE, hex_id);
|
||||
|
||||
|
@ -195,7 +188,7 @@ twc_cmd_bootstrap(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
TWC_CHECK_PROFILE(profile);
|
||||
TWC_CHECK_PROFILE_LOADED(profile);
|
||||
|
||||
// /bootstrap connect <address> <port> <key>
|
||||
/* /bootstrap connect <address> <port> <key> */
|
||||
if (argc == 5 && weechat_strcasecmp(argv[1], "connect") == 0)
|
||||
{
|
||||
char *address = argv[2];
|
||||
|
@ -226,7 +219,7 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
TWC_CHECK_PROFILE(profile);
|
||||
TWC_CHECK_PROFILE_LOADED(profile);
|
||||
|
||||
// /friend or /friend list
|
||||
/* /friend or /friend list */
|
||||
if (argc == 1 || (argc == 2 && weechat_strcasecmp(argv[1], "list") == 0))
|
||||
{
|
||||
size_t friend_count = tox_self_get_friend_list_size(profile->tox);
|
||||
|
@ -235,30 +228,32 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
|
||||
if (friend_count == 0)
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sYou have no friends :(",
|
||||
weechat_printf(profile->buffer, "%sYou have no friends :(",
|
||||
weechat_prefix("network"));
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
weechat_printf(profile->buffer,
|
||||
"%s[#] Name [Tox ID (short)] Status",
|
||||
weechat_printf(profile->buffer, "%s[#] Name [Tox ID (short)] Status",
|
||||
weechat_prefix("network"));
|
||||
|
||||
for (size_t i = 0; i < friend_count; ++i)
|
||||
{
|
||||
uint32_t friend_number = friend_numbers[i];
|
||||
char *name = twc_get_name_nt(profile->tox, friend_number);
|
||||
char *hex_address = twc_get_friend_id_short(profile->tox,
|
||||
friend_number);
|
||||
char *hex_address =
|
||||
twc_get_friend_id_short(profile->tox, friend_number);
|
||||
|
||||
char *status = twc_get_status_message_nt(profile->tox, friend_number);
|
||||
char *status =
|
||||
twc_get_status_message_nt(profile->tox, friend_number);
|
||||
char *online_color =
|
||||
(tox_friend_get_connection_status(profile->tox, friend_number, NULL) != TOX_CONNECTION_NONE) ? "chat_nick" : "chat_nick_offline";
|
||||
weechat_printf(profile->buffer,
|
||||
"%s[%d] %s%s [%s]%s %s",
|
||||
weechat_prefix("network"),
|
||||
friend_number, weechat_color(online_color), name, hex_address, weechat_color("reset"), status);
|
||||
(tox_friend_get_connection_status(profile->tox, friend_number,
|
||||
NULL) != TOX_CONNECTION_NONE)
|
||||
? "chat_nick"
|
||||
: "chat_nick_offline";
|
||||
weechat_printf(profile->buffer, "%s[%d] %s%s [%s]%s %s",
|
||||
weechat_prefix("network"), friend_number,
|
||||
weechat_color(online_color), name, hex_address,
|
||||
weechat_color("reset"), status);
|
||||
|
||||
free(name);
|
||||
free(status);
|
||||
|
@ -268,7 +263,7 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
// /friend add [-force] <Tox ID> [<message>]
|
||||
/* /friend add [-force] <Tox ID> [<message>] */
|
||||
else if (argc >= 3 && weechat_strcasecmp(argv[1], "add") == 0)
|
||||
{
|
||||
bool force;
|
||||
|
@ -325,16 +320,13 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
}
|
||||
|
||||
TOX_ERR_FRIEND_ADD err;
|
||||
(void)tox_friend_add(profile->tox,
|
||||
(uint8_t *)address,
|
||||
(uint8_t *)message,
|
||||
strlen(message), &err);
|
||||
(void)tox_friend_add(profile->tox, (uint8_t *)address,
|
||||
(uint8_t *)message, strlen(message), &err);
|
||||
|
||||
switch (err)
|
||||
{
|
||||
case TOX_ERR_FRIEND_ADD_OK:
|
||||
weechat_printf(profile->buffer,
|
||||
"%sFriend request sent!",
|
||||
weechat_printf(profile->buffer, "%sFriend request sent!",
|
||||
weechat_prefix("network"));
|
||||
break;
|
||||
case TOX_ERR_FRIEND_ADD_TOO_LONG:
|
||||
|
@ -377,7 +369,7 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
// /friend remove
|
||||
/* /friend remove */
|
||||
else if (argc >= 3 && (weechat_strcasecmp(argv[1], "remove") == 0))
|
||||
{
|
||||
int32_t friend_number = twc_match_friend(profile, argv[2]);
|
||||
|
@ -386,14 +378,12 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
char *name = twc_get_name_nt(profile->tox, friend_number);
|
||||
if (tox_friend_delete(profile->tox, friend_number, NULL))
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sRemoved %s from friend list.",
|
||||
weechat_printf(profile->buffer, "%sRemoved %s from friend list.",
|
||||
weechat_prefix("network"), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sCould not remove friend!",
|
||||
weechat_printf(profile->buffer, "%sCould not remove friend!",
|
||||
weechat_prefix("error"));
|
||||
}
|
||||
|
||||
|
@ -402,10 +392,9 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
// friend accept|decline <number>|all
|
||||
else if (argc == 3 &&
|
||||
(weechat_strcasecmp(argv[1], "accept") == 0
|
||||
|| weechat_strcasecmp(argv[1], "decline") == 0))
|
||||
/* friend accept|decline <number>|all */
|
||||
else if (argc == 3 && (weechat_strcasecmp(argv[1], "accept") == 0 ||
|
||||
weechat_strcasecmp(argv[1], "decline") == 0))
|
||||
{
|
||||
int accept = weechat_strcasecmp(argv[1], "accept") == 0;
|
||||
|
||||
|
@ -415,7 +404,7 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
size_t index;
|
||||
size_t count = 0;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(profile->friend_requests, index, item)
|
||||
twc_list_foreach (profile->friend_requests, index, item)
|
||||
{
|
||||
if (accept)
|
||||
{
|
||||
|
@ -427,11 +416,11 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
{
|
||||
char hex_address[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
||||
twc_bin2hex(item->friend_request->tox_id,
|
||||
TOX_PUBLIC_KEY_SIZE,
|
||||
hex_address);
|
||||
weechat_printf(profile->buffer,
|
||||
"%sCould not accept friend request from %s",
|
||||
weechat_prefix("error"), hex_address);
|
||||
TOX_PUBLIC_KEY_SIZE, hex_address);
|
||||
weechat_printf(
|
||||
profile->buffer,
|
||||
"%sCould not accept friend request from %s",
|
||||
weechat_prefix("error"), hex_address);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -441,11 +430,9 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
}
|
||||
}
|
||||
|
||||
weechat_printf(profile->buffer,
|
||||
"%s%s %d friend requests.",
|
||||
weechat_printf(profile->buffer, "%s%s %d friend requests.",
|
||||
weechat_prefix("network"),
|
||||
accept ? "Accepted" : "Declined",
|
||||
count);
|
||||
accept ? "Accepted" : "Declined", count);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
@ -453,18 +440,16 @@ twc_cmd_friend(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
{
|
||||
char *endptr;
|
||||
unsigned long num = strtoul(argv[2], &endptr, 10);
|
||||
if (endptr == argv[2] || (request = twc_friend_request_with_index(profile, num)) == NULL)
|
||||
if (endptr == argv[2] ||
|
||||
(request = twc_friend_request_with_index(profile, num)) == NULL)
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sInvalid friend request ID.",
|
||||
weechat_printf(profile->buffer, "%sInvalid friend request ID.",
|
||||
weechat_prefix("error"));
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
char hex_address[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
||||
twc_bin2hex(request->tox_id,
|
||||
TOX_PUBLIC_KEY_SIZE,
|
||||
hex_address);
|
||||
twc_bin2hex(request->tox_id, TOX_PUBLIC_KEY_SIZE, hex_address);
|
||||
|
||||
if (accept)
|
||||
{
|
||||
|
@ -495,27 +480,24 @@ 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)
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sPending friend requests:",
|
||||
weechat_printf(profile->buffer, "%sPending friend requests:",
|
||||
weechat_prefix("network"));
|
||||
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(profile->friend_requests, index, item)
|
||||
twc_list_foreach (profile->friend_requests, index, item)
|
||||
{
|
||||
char hex_address[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
||||
twc_bin2hex(item->friend_request->tox_id,
|
||||
TOX_PUBLIC_KEY_SIZE, hex_address);
|
||||
twc_bin2hex(item->friend_request->tox_id, TOX_PUBLIC_KEY_SIZE,
|
||||
hex_address);
|
||||
|
||||
weechat_printf(profile->buffer,
|
||||
"%s[%d] Address: %s\n"
|
||||
"[%d] Message: %s",
|
||||
weechat_prefix("network"),
|
||||
index, hex_address,
|
||||
index, item->friend_request->message);
|
||||
weechat_printf(profile->buffer, "%s[%d] Address: %s\n"
|
||||
"[%d] Message: %s",
|
||||
weechat_prefix("network"), index, hex_address, index,
|
||||
item->friend_request->message);
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
|
@ -536,7 +518,7 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
TWC_CHECK_PROFILE(profile);
|
||||
TWC_CHECK_PROFILE_LOADED(profile);
|
||||
|
||||
// /group create
|
||||
/* /group create */
|
||||
if (argc == 2 && weechat_strcasecmp(argv[1], "create") == 0)
|
||||
{
|
||||
int rc = tox_conference_new(profile->tox, &err);
|
||||
|
@ -550,10 +532,9 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
// /group join|decline <number>
|
||||
else if (argc == 3 &&
|
||||
(weechat_strcasecmp(argv[1], "join") == 0
|
||||
|| weechat_strcasecmp(argv[1], "decline") == 0))
|
||||
/* /group join|decline <number> */
|
||||
else if (argc == 3 && (weechat_strcasecmp(argv[1], "join") == 0 ||
|
||||
weechat_strcasecmp(argv[1], "decline") == 0))
|
||||
{
|
||||
bool join = weechat_strcasecmp(argv[1], "join") == 0;
|
||||
|
||||
|
@ -561,10 +542,10 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
|
||||
char *endptr;
|
||||
unsigned long num = strtoul(argv[2], &endptr, 10);
|
||||
if (endptr == argv[2] || (invite = twc_group_chat_invite_with_index(profile, num)) == NULL)
|
||||
if (endptr == argv[2] ||
|
||||
(invite = twc_group_chat_invite_with_index(profile, num)) == NULL)
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sInvalid group chat invite ID.",
|
||||
weechat_printf(profile->buffer, "%sInvalid group chat invite ID.",
|
||||
weechat_prefix("error"));
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
@ -573,7 +554,7 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
{
|
||||
int group_number = twc_group_chat_invite_join(invite);
|
||||
|
||||
// create a buffer for the new group chat
|
||||
/* create a buffer for the new group chat */
|
||||
if (group_number >= 0)
|
||||
twc_chat_search_group(profile, group_number, true);
|
||||
else
|
||||
|
@ -589,23 +570,20 @@ twc_cmd_group(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
// /group invites
|
||||
/* /group invites */
|
||||
else if (argc == 2 && weechat_strcasecmp(argv[1], "invites") == 0)
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%sPending group chat invites:",
|
||||
weechat_printf(profile->buffer, "%sPending group chat invites:",
|
||||
weechat_prefix("network"));
|
||||
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(profile->group_chat_invites, index, item)
|
||||
twc_list_foreach (profile->group_chat_invites, index, item)
|
||||
{
|
||||
char *friend_name =
|
||||
twc_get_name_nt(profile->tox, item->group_chat_invite->friend_number);
|
||||
weechat_printf(profile->buffer,
|
||||
"%s[%d] From: %s",
|
||||
weechat_prefix("network"),
|
||||
index, friend_name);
|
||||
char *friend_name = twc_get_name_nt(
|
||||
profile->tox, item->group_chat_invite->friend_number);
|
||||
weechat_printf(profile->buffer, "%s[%d] From: %s",
|
||||
weechat_prefix("network"), index, friend_name);
|
||||
free(friend_name);
|
||||
}
|
||||
|
||||
|
@ -634,14 +612,15 @@ twc_cmd_invite(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
int32_t friend_number = twc_match_friend(chat->profile, argv_eol[1]);
|
||||
TWC_CHECK_FRIEND_NUMBER(chat->profile, friend_number, argv_eol[1]);
|
||||
|
||||
tox_conference_invite(chat->profile->tox, friend_number, chat->group_number, &err);
|
||||
tox_conference_invite(chat->profile->tox, friend_number, chat->group_number,
|
||||
&err);
|
||||
|
||||
if (err == TOX_ERR_CONFERENCE_INVITE_OK)
|
||||
{
|
||||
char *friend_name = twc_get_name_nt(chat->profile->tox, friend_number);
|
||||
weechat_printf(chat->buffer, "%sInvited %s to the group chat.",
|
||||
weechat_prefix("network"), friend_name);
|
||||
free(friend_name);
|
||||
free(friend_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -685,8 +664,8 @@ twc_cmd_msg(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
TWC_CHECK_PROFILE(profile);
|
||||
TWC_CHECK_PROFILE_LOADED(profile);
|
||||
|
||||
// do a shell split in case a friend has spaces in his name and we need
|
||||
// quotes
|
||||
/* do a shell split in case a friend has spaces in his name and we need
|
||||
* quotes */
|
||||
int shell_argc;
|
||||
char **shell_argv = weechat_string_split_shell(argv_eol[0], &shell_argc);
|
||||
|
||||
|
@ -697,7 +676,7 @@ twc_cmd_msg(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
char *message = NULL;
|
||||
if (shell_argc >= 3)
|
||||
{
|
||||
// extract message, add two if quotes are used
|
||||
/* extract message, add two if quotes are used */
|
||||
message = argv_eol[1] + strlen(recipient);
|
||||
if (*argv[1] == '"' || *argv[1] == '\'')
|
||||
message += 2;
|
||||
|
@ -706,13 +685,13 @@ twc_cmd_msg(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
int32_t friend_number = twc_match_friend(profile, recipient);
|
||||
TWC_CHECK_FRIEND_NUMBER(profile, friend_number, recipient);
|
||||
|
||||
// create chat buffer if it does not exist
|
||||
struct t_twc_chat *chat = twc_chat_search_friend(profile, friend_number, true);
|
||||
/* create chat buffer if it does not exist */
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_friend(profile, friend_number, true);
|
||||
|
||||
// send a message if provided
|
||||
/* send a message if provided */
|
||||
if (message)
|
||||
twc_chat_send_message(chat,
|
||||
weechat_string_strip(message, 1, 1, " "),
|
||||
twc_chat_send_message(chat, weechat_string_strip(message, 1, 1, " "),
|
||||
TOX_MESSAGE_TYPE_NORMAL);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
|
@ -735,10 +714,8 @@ twc_cmd_myid(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
char address_str[TOX_ADDRESS_SIZE * 2 + 1];
|
||||
twc_bin2hex(address, TOX_ADDRESS_SIZE, address_str);
|
||||
|
||||
weechat_printf(profile->buffer,
|
||||
"%sYour Tox address: %s",
|
||||
weechat_prefix("network"),
|
||||
address_str);
|
||||
weechat_printf(profile->buffer, "%sYour Tox address: %s",
|
||||
weechat_prefix("network"), address_str);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
@ -776,28 +753,22 @@ twc_cmd_name(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
err_msg = "unknown error";
|
||||
break;
|
||||
}
|
||||
weechat_printf(profile->buffer,
|
||||
"%s%s%s",
|
||||
weechat_prefix("error"),
|
||||
weechat_printf(profile->buffer, "%s%s%s", weechat_prefix("error"),
|
||||
"Could not change name: ", err_msg);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
weechat_bar_item_update("input_prompt");
|
||||
|
||||
weechat_printf(profile->buffer,
|
||||
"%sYou are now known as %s",
|
||||
weechat_prefix("network"),
|
||||
name);
|
||||
weechat_printf(profile->buffer, "%sYou are now known as %s",
|
||||
weechat_prefix("network"), name);
|
||||
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(profile->chats, index, item)
|
||||
twc_list_foreach (profile->chats, index, item)
|
||||
{
|
||||
weechat_printf(item->chat->buffer,
|
||||
"%sYou are now known as %s",
|
||||
weechat_prefix("network"),
|
||||
name);
|
||||
weechat_printf(item->chat->buffer, "%sYou are now known as %s",
|
||||
weechat_prefix("network"), name);
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
|
@ -832,7 +803,7 @@ twc_cmd_nospam(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
// reverse the value bytes so it's displayed as entered in the Tox ID
|
||||
/* reverse the value bytes so it's displayed as entered in the Tox ID */
|
||||
new_nospam = twc_uint32_reverse_bytes(value);
|
||||
}
|
||||
else
|
||||
|
@ -846,7 +817,8 @@ twc_cmd_nospam(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
weechat_printf(profile->buffer,
|
||||
"%snew nospam has been set; this changes your Tox ID! To "
|
||||
"revert, run \"/nospam %x\"",
|
||||
weechat_prefix("network"), twc_uint32_reverse_bytes(old_nospam));
|
||||
weechat_prefix("network"),
|
||||
twc_uint32_reverse_bytes(old_nospam));
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
@ -866,8 +838,7 @@ twc_cmd_part(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
tox_conference_delete(chat->profile->tox, chat->group_number, &err);
|
||||
if (err == TOX_ERR_CONFERENCE_DELETE_OK)
|
||||
{
|
||||
weechat_printf(chat->buffer,
|
||||
"%sYou have left the group chat",
|
||||
weechat_printf(chat->buffer, "%sYou have left the group chat",
|
||||
weechat_prefix("network"));
|
||||
}
|
||||
else
|
||||
|
@ -890,27 +861,26 @@ twc_cmd_part(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
* Save Tox profile data when /save is executed.
|
||||
*/
|
||||
int
|
||||
twc_cmd_save(const void *pointer, 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;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(twc_profiles, index, item)
|
||||
twc_list_foreach (twc_profiles, index, item)
|
||||
{
|
||||
if (!(item->profile->tox)) continue;
|
||||
if (!(item->profile->tox))
|
||||
continue;
|
||||
|
||||
int rc = twc_profile_save_data_file(item->profile);
|
||||
if (rc == -1)
|
||||
{
|
||||
weechat_printf(NULL,
|
||||
"%s%s: failed to save data for profile %s",
|
||||
weechat_printf(NULL, "%s%s: failed to save data for profile %s",
|
||||
weechat_prefix("error"), weechat_plugin->name,
|
||||
item->profile->name);
|
||||
}
|
||||
}
|
||||
|
||||
weechat_printf(NULL,
|
||||
"%s: profile data saved",
|
||||
weechat_plugin->name);
|
||||
weechat_printf(NULL, "%s: profile data saved", weechat_plugin->name);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
@ -959,8 +929,7 @@ twc_cmd_statusmsg(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
char *message = argc > 1 ? argv_eol[1] : " ";
|
||||
|
||||
TOX_ERR_SET_INFO err;
|
||||
tox_self_set_status_message(profile->tox,
|
||||
(uint8_t *)message,
|
||||
tox_self_set_status_message(profile->tox, (uint8_t *)message,
|
||||
strlen(message), &err);
|
||||
if (err != TOX_ERR_SET_INFO_OK)
|
||||
{
|
||||
|
@ -977,9 +946,7 @@ twc_cmd_statusmsg(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
err_msg = "unknown error";
|
||||
break;
|
||||
}
|
||||
weechat_printf(profile->buffer,
|
||||
"%s%s%s",
|
||||
weechat_prefix("error"),
|
||||
weechat_printf(profile->buffer, "%s%s%s", weechat_prefix("error"),
|
||||
"Could not set status message: ", err_msg);
|
||||
}
|
||||
|
||||
|
@ -1014,11 +981,11 @@ twc_cmd_topic(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
char *topic = argv_eol[1];
|
||||
|
||||
tox_conference_set_title(chat->profile->tox, chat->group_number,
|
||||
(uint8_t *)topic, strlen(topic), &err);
|
||||
(uint8_t *)topic, strlen(topic), &err);
|
||||
if (err != TOX_ERR_CONFERENCE_TITLE_OK)
|
||||
{
|
||||
weechat_printf(chat->buffer, "%s%s",
|
||||
weechat_prefix("error"), "Could not set topic.");
|
||||
weechat_printf(chat->buffer, "%s%s", weechat_prefix("error"),
|
||||
"Could not set topic.");
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
|
@ -1032,53 +999,46 @@ twc_cmd_topic(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
*/
|
||||
int
|
||||
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] */
|
||||
if (argc == 1 || (argc == 2 && weechat_strcasecmp(argv[1], "list") == 0))
|
||||
{
|
||||
weechat_printf(NULL,
|
||||
"%sAll Tox profiles:",
|
||||
weechat_prefix("network"));
|
||||
weechat_printf(NULL, "%sAll Tox profiles:", weechat_prefix("network"));
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(twc_profiles, index, item)
|
||||
twc_list_foreach (twc_profiles, index, item)
|
||||
{
|
||||
weechat_printf(NULL,
|
||||
"%s%s",
|
||||
weechat_prefix("network"),
|
||||
weechat_printf(NULL, "%s%s", weechat_prefix("network"),
|
||||
item->profile->name);
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
// /tox create
|
||||
/* /tox create */
|
||||
else if (argc == 3 && (weechat_strcasecmp(argv[1], "create") == 0))
|
||||
{
|
||||
char *name = argv[2];
|
||||
|
||||
if (twc_profile_search_name(name))
|
||||
{
|
||||
weechat_printf(NULL,
|
||||
"%s%s: profile \"%s\" already exists!",
|
||||
weechat_prefix("error"), weechat_plugin->name,
|
||||
name);
|
||||
weechat_printf(NULL, "%s%s: profile \"%s\" already exists!",
|
||||
weechat_prefix("error"), weechat_plugin->name, name);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
struct t_twc_profile *profile = twc_profile_new(name);
|
||||
weechat_printf(NULL,
|
||||
"%s%s: profile \"%s\" created!",
|
||||
weechat_printf(NULL, "%s%s: profile \"%s\" created!",
|
||||
weechat_prefix("network"), weechat_plugin->name,
|
||||
profile->name);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
// /tox delete
|
||||
else if ((argc == 3 || argc == 4)
|
||||
&& (weechat_strcasecmp(argv[1], "delete") == 0))
|
||||
/* /tox delete */
|
||||
else if ((argc == 3 || argc == 4) &&
|
||||
(weechat_strcasecmp(argv[1], "delete") == 0))
|
||||
{
|
||||
char *name = argv[2];
|
||||
char *flag = argv[3];
|
||||
|
@ -1096,25 +1056,22 @@ twc_cmd_tox(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
}
|
||||
else
|
||||
{
|
||||
weechat_printf(NULL,
|
||||
"%s%s: You must confirm deletion with either "
|
||||
"\"-keepdata\" or \"-yes\" (see /help tox)",
|
||||
weechat_printf(NULL, "%s%s: You must confirm deletion with either "
|
||||
"\"-keepdata\" or \"-yes\" (see /help tox)",
|
||||
weechat_prefix("error"), weechat_plugin->name);
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
weechat_printf(NULL,
|
||||
"%s%s: profile \"%s\" has been deleted.",
|
||||
weechat_prefix("error"), weechat_plugin->name,
|
||||
name);
|
||||
weechat_printf(NULL, "%s%s: profile \"%s\" has been deleted.",
|
||||
weechat_prefix("error"), weechat_plugin->name, name);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
// /tox load|unload|reload [<profile>...]
|
||||
else if (argc >= 2 && (weechat_strcasecmp(argv[1], "load") == 0
|
||||
|| weechat_strcasecmp(argv[1], "unload") == 0
|
||||
|| weechat_strcasecmp(argv[1], "reload") == 0))
|
||||
/* /tox load|unload|reload [<profile>...] */
|
||||
else if (argc >= 2 && (weechat_strcasecmp(argv[1], "load") == 0 ||
|
||||
weechat_strcasecmp(argv[1], "unload") == 0 ||
|
||||
weechat_strcasecmp(argv[1], "reload") == 0))
|
||||
{
|
||||
bool load = weechat_strcasecmp(argv[1], "load") == 0;
|
||||
bool unload = weechat_strcasecmp(argv[1], "unload") == 0;
|
||||
|
@ -1158,16 +1115,14 @@ twc_cmd_tox(const void *pointer, void *data, struct t_gui_buffer *buffer,
|
|||
void
|
||||
twc_commands_init()
|
||||
{
|
||||
weechat_hook_command("bootstrap",
|
||||
"manage bootstrap nodes",
|
||||
weechat_hook_command("bootstrap", "manage bootstrap nodes",
|
||||
"connect <address> <port> <Tox ID>",
|
||||
"address: internet address of node to bootstrap with\n"
|
||||
" port: port of the node\n"
|
||||
" Tox ID: Tox ID of the node",
|
||||
"connect", twc_cmd_bootstrap, NULL, NULL);
|
||||
|
||||
weechat_hook_command("friend",
|
||||
"manage friends",
|
||||
weechat_hook_command("friend", "manage friends",
|
||||
"list"
|
||||
" || add [-force] <address> [<message>]"
|
||||
" || remove <number>|<name>|<Tox ID>"
|
||||
|
@ -1187,12 +1142,10 @@ twc_commands_init()
|
|||
" || decline",
|
||||
twc_cmd_friend, NULL, NULL);
|
||||
|
||||
weechat_hook_command("group",
|
||||
"manage group chats",
|
||||
"create"
|
||||
" || invites"
|
||||
" || join <number>"
|
||||
" || decline <number>",
|
||||
weechat_hook_command("group", "manage group chats", "create"
|
||||
" || invites"
|
||||
" || join <number>"
|
||||
" || decline <number>",
|
||||
" create: create a new group chat\n"
|
||||
"invites: list group chat invites\n"
|
||||
" join: join a group chat by its invite ID\n"
|
||||
|
@ -1202,94 +1155,71 @@ twc_commands_init()
|
|||
" || join",
|
||||
twc_cmd_group, NULL, NULL);
|
||||
|
||||
weechat_hook_command("invite",
|
||||
"invite someone to a group chat",
|
||||
"<number>|<name>|<Tox ID>",
|
||||
"number, name, Tox ID: friend to message\n",
|
||||
"%(tox_friend_name)|%(tox_friend_tox_id)",
|
||||
twc_cmd_invite, NULL, NULL);
|
||||
weechat_hook_command(
|
||||
"invite", "invite someone to a group chat", "<number>|<name>|<Tox ID>",
|
||||
"number, name, Tox ID: friend to message\n",
|
||||
"%(tox_friend_name)|%(tox_friend_tox_id)", twc_cmd_invite, NULL, NULL);
|
||||
|
||||
weechat_hook_command("me",
|
||||
"send an action to the current chat",
|
||||
"<message>",
|
||||
"message: message to send",
|
||||
NULL, twc_cmd_me, NULL, NULL);
|
||||
weechat_hook_command("me", "send an action to the current chat",
|
||||
"<message>", "message: message to send", NULL,
|
||||
twc_cmd_me, NULL, NULL);
|
||||
|
||||
weechat_hook_command("msg",
|
||||
"send a message to a Tox friend",
|
||||
weechat_hook_command("msg", "send a message to a Tox friend",
|
||||
"<number>|<name>|<Tox ID> [<message>]",
|
||||
"number, name, Tox ID: friend to message\n"
|
||||
"message: message to send",
|
||||
"%(tox_friend_name)|%(tox_friend_tox_id)",
|
||||
twc_cmd_msg, NULL, NULL);
|
||||
"%(tox_friend_name)|%(tox_friend_tox_id)", twc_cmd_msg,
|
||||
NULL, NULL);
|
||||
|
||||
weechat_hook_command("myid",
|
||||
"get your Tox ID to give to friends",
|
||||
"", "",
|
||||
weechat_hook_command("myid", "get your Tox ID to give to friends", "", "",
|
||||
NULL, twc_cmd_myid, NULL, NULL);
|
||||
|
||||
weechat_hook_command("name",
|
||||
"change your Tox name",
|
||||
"<name>",
|
||||
"name: your new name",
|
||||
NULL, twc_cmd_name, NULL, NULL);
|
||||
weechat_hook_command("name", "change your Tox name", "<name>",
|
||||
"name: your new name", NULL, twc_cmd_name, NULL, NULL);
|
||||
|
||||
weechat_hook_command("nospam",
|
||||
"change nospam value",
|
||||
"[<hex value>]",
|
||||
weechat_hook_command("nospam", "change nospam value", "[<hex value>]",
|
||||
"hex value: new nospam value; when omitted, a random "
|
||||
"new value is used\n\n"
|
||||
"Warning: changing your nospam value will alter your "
|
||||
"Tox ID!",
|
||||
NULL, twc_cmd_nospam, NULL, NULL);
|
||||
|
||||
weechat_hook_command("part",
|
||||
"leave a group chat",
|
||||
"", "",
|
||||
NULL, twc_cmd_part, NULL, NULL);
|
||||
weechat_hook_command("part", "leave a group chat", "", "", NULL,
|
||||
twc_cmd_part, NULL, NULL);
|
||||
|
||||
weechat_hook_command_run("/save", twc_cmd_save, NULL, NULL);
|
||||
|
||||
weechat_hook_command("status",
|
||||
"change your Tox status",
|
||||
"online|busy|away",
|
||||
"",
|
||||
NULL, twc_cmd_status, NULL, NULL);
|
||||
weechat_hook_command("status", "change your Tox status", "online|busy|away",
|
||||
"", NULL, twc_cmd_status, NULL, NULL);
|
||||
|
||||
weechat_hook_command("statusmsg",
|
||||
"change your Tox status message",
|
||||
"[<message>]",
|
||||
"message: your new status message",
|
||||
weechat_hook_command("statusmsg", "change your Tox status message",
|
||||
"[<message>]", "message: your new status message",
|
||||
NULL, twc_cmd_statusmsg, NULL, NULL);
|
||||
|
||||
weechat_hook_command("topic",
|
||||
"set a group chat topic",
|
||||
"<topic>",
|
||||
"topic: new group chat topic",
|
||||
NULL, twc_cmd_topic, NULL, NULL);
|
||||
weechat_hook_command("topic", "set a group chat topic", "<topic>",
|
||||
"topic: new group chat topic", NULL, twc_cmd_topic,
|
||||
NULL, NULL);
|
||||
|
||||
weechat_hook_command("tox",
|
||||
"manage Tox profiles",
|
||||
"list"
|
||||
" || create <name>"
|
||||
" || delete <name> -yes|-keepdata"
|
||||
" || load [<name>...]"
|
||||
" || unload [<name>...]"
|
||||
" || reload [<name>...]",
|
||||
" list: list all Tox profile\n"
|
||||
"create: create a new Tox profile\n"
|
||||
"delete: delete a Tox profile; requires either -yes "
|
||||
"to confirm deletion or -keepdata to delete the "
|
||||
"profile but keep the Tox data file\n"
|
||||
" load: load one or more Tox profiles and connect to the network\n"
|
||||
"unload: unload one or more Tox profiles\n"
|
||||
"reload: reload one or more Tox profiles\n",
|
||||
"list"
|
||||
" || create"
|
||||
" || delete %(tox_profiles) -yes|-keepdata"
|
||||
" || load %(tox_unloaded_profiles)|%*"
|
||||
" || unload %(tox_loaded_profiles)|%*"
|
||||
" || reload %(tox_loaded_profiles)|%*",
|
||||
twc_cmd_tox, NULL, NULL);
|
||||
weechat_hook_command(
|
||||
"tox", "manage Tox profiles", "list"
|
||||
" || create <name>"
|
||||
" || delete <name> -yes|-keepdata"
|
||||
" || load [<name>...]"
|
||||
" || unload [<name>...]"
|
||||
" || reload [<name>...]",
|
||||
" list: list all Tox profile\n"
|
||||
"create: create a new Tox profile\n"
|
||||
"delete: delete a Tox profile; requires either -yes "
|
||||
"to confirm deletion or -keepdata to delete the "
|
||||
"profile but keep the Tox data file\n"
|
||||
" load: load one or more Tox profiles and connect to the network\n"
|
||||
"unload: unload one or more Tox profiles\n"
|
||||
"reload: reload one or more Tox profiles\n",
|
||||
"list"
|
||||
" || create"
|
||||
" || delete %(tox_profiles) -yes|-keepdata"
|
||||
" || load %(tox_unloaded_profiles)|%*"
|
||||
" || unload %(tox_loaded_profiles)|%*"
|
||||
" || reload %(tox_loaded_profiles)|%*",
|
||||
twc_cmd_tox, NULL, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#ifndef TOX_WEECHAT_COMMANDS_H
|
||||
#define TOX_WEECHAT_COMMANDS_H
|
||||
|
||||
void twc_commands_init();
|
||||
|
||||
#endif // TOX_WEECHAT_COMMANDS_H
|
||||
void
|
||||
twc_commands_init();
|
||||
|
||||
#endif /* TOX_WEECHAT_COMMANDS_H */
|
||||
|
|
|
@ -17,15 +17,15 @@
|
|||
* along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-utils.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-completion.h"
|
||||
|
||||
|
@ -47,8 +47,7 @@ enum
|
|||
*/
|
||||
int
|
||||
twc_completion_friend(const void *pointer, void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
const char *completion_item, struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
int flags = (int)(intptr_t)pointer;
|
||||
|
@ -69,7 +68,8 @@ twc_completion_friend(const void *pointer, void *data,
|
|||
char hex_id[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
||||
|
||||
TOX_ERR_FRIEND_GET_PUBLIC_KEY err;
|
||||
tox_friend_get_public_key(profile->tox, friend_numbers[i], tox_id, &err);
|
||||
tox_friend_get_public_key(profile->tox, friend_numbers[i], tox_id,
|
||||
&err);
|
||||
if (err == TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK)
|
||||
{
|
||||
twc_bin2hex(tox_id, TOX_PUBLIC_KEY_SIZE, hex_id);
|
||||
|
@ -83,7 +83,7 @@ twc_completion_friend(const void *pointer, void *data,
|
|||
{
|
||||
char *name = twc_get_name_nt(profile->tox, friend_numbers[i]);
|
||||
|
||||
// add quotes if needed
|
||||
/* add quotes if needed */
|
||||
if (strchr(name, ' '))
|
||||
{
|
||||
size_t length = strlen(name) + 3;
|
||||
|
@ -109,23 +109,21 @@ twc_completion_friend(const void *pointer, void *data,
|
|||
*/
|
||||
int
|
||||
twc_completion_profile(const void *pointer, void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
const char *completion_item, struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
int flag = (int)(intptr_t)pointer;
|
||||
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(twc_profiles, index, item)
|
||||
twc_list_foreach (twc_profiles, index, item)
|
||||
{
|
||||
if (flag == TWC_ALL_PROFILES
|
||||
|| (flag == TWC_LOADED_PROFILES && item->profile->tox != NULL)
|
||||
|| (flag == TWC_UNLOADED_PROFILES && item->profile->tox == NULL))
|
||||
if (flag == TWC_ALL_PROFILES ||
|
||||
(flag == TWC_LOADED_PROFILES && item->profile->tox != NULL) ||
|
||||
(flag == TWC_UNLOADED_PROFILES && item->profile->tox == NULL))
|
||||
{
|
||||
weechat_hook_completion_list_add(completion,
|
||||
item->profile->name,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
weechat_hook_completion_list_add(completion, item->profile->name, 0,
|
||||
WEECHAT_LIST_POS_SORT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,8 +133,7 @@ twc_completion_profile(const void *pointer, void *data,
|
|||
void
|
||||
twc_completion_init()
|
||||
{
|
||||
weechat_hook_completion("tox_profiles", "profile",
|
||||
twc_completion_profile,
|
||||
weechat_hook_completion("tox_profiles", "profile", twc_completion_profile,
|
||||
(void *)(intptr_t)TWC_ALL_PROFILES, NULL);
|
||||
weechat_hook_completion("tox_loaded_profiles", "loaded profile",
|
||||
twc_completion_profile,
|
||||
|
@ -151,4 +148,3 @@ twc_completion_init()
|
|||
twc_completion_friend,
|
||||
(void *)(intptr_t)TWC_COMPLETE_FRIEND_NAME, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,5 +23,4 @@
|
|||
void
|
||||
twc_completion_init();
|
||||
|
||||
#endif // TOX_WEECHAT_COMPLETION_H
|
||||
|
||||
#endif /* TOX_WEECHAT_COMPLETION_H */
|
||||
|
|
150
src/twc-config.c
150
src/twc-config.c
|
@ -17,16 +17,16 @@
|
|||
* along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-config.h"
|
||||
|
||||
|
@ -38,19 +38,10 @@ struct t_config_section *twc_config_section_profile_default = NULL;
|
|||
struct t_config_option *twc_config_friend_request_message;
|
||||
struct t_config_option *twc_config_short_id_size;
|
||||
|
||||
char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] =
|
||||
{
|
||||
"save_file",
|
||||
"autoload",
|
||||
"autojoin",
|
||||
"max_friend_requests",
|
||||
"proxy_address",
|
||||
"proxy_port",
|
||||
"proxy_type",
|
||||
"udp",
|
||||
"ipv6",
|
||||
"passphrase",
|
||||
"logging",
|
||||
char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] = {
|
||||
"save_file", "autoload", "autojoin", "max_friend_requests",
|
||||
"proxy_address", "proxy_port", "proxy_type", "udp",
|
||||
"ipv6", "passphrase", "logging",
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -75,8 +66,7 @@ int
|
|||
twc_config_profile_read_callback(const void *pointer, void *data,
|
||||
struct t_config_file *config_file,
|
||||
struct t_config_section *section,
|
||||
const char *option_name,
|
||||
const char *value)
|
||||
const char *option_name, const char *value)
|
||||
{
|
||||
int rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
|
||||
|
||||
|
@ -85,12 +75,13 @@ twc_config_profile_read_callback(const void *pointer, void *data,
|
|||
char *dot_pos = strrchr(option_name, '.');
|
||||
if (dot_pos)
|
||||
{
|
||||
char *profile_name = weechat_strndup(option_name,
|
||||
dot_pos-option_name);
|
||||
char *profile_name =
|
||||
weechat_strndup(option_name, dot_pos - option_name);
|
||||
char *option_name = dot_pos + 1;
|
||||
if (profile_name)
|
||||
{
|
||||
int option_index = twc_config_profile_option_search(option_name);
|
||||
int option_index =
|
||||
twc_config_profile_option_search(option_name);
|
||||
if (option_index >= 0)
|
||||
{
|
||||
struct t_twc_profile *profile =
|
||||
|
@ -101,16 +92,15 @@ twc_config_profile_read_callback(const void *pointer, void *data,
|
|||
|
||||
if (profile)
|
||||
{
|
||||
rc = weechat_config_option_set(profile->options[option_index],
|
||||
value, 1);
|
||||
rc = weechat_config_option_set(
|
||||
profile->options[option_index], value, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_printf(NULL,
|
||||
"%s%s: error creating profile \"%s\"",
|
||||
weechat_prefix("error"),
|
||||
weechat_plugin->name,
|
||||
profile_name);
|
||||
weechat_plugin->name, profile_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,8 +111,7 @@ twc_config_profile_read_callback(const void *pointer, void *data,
|
|||
|
||||
if (rc == WEECHAT_CONFIG_OPTION_SET_ERROR)
|
||||
{
|
||||
weechat_printf(NULL,
|
||||
"%s%s: error creating profile option \"%s\"",
|
||||
weechat_printf(NULL, "%s%s: error creating profile option \"%s\"",
|
||||
weechat_prefix("error"), weechat_plugin->name,
|
||||
option_name);
|
||||
}
|
||||
|
@ -140,7 +129,7 @@ twc_config_check_value_callback(const void *pointer, void *data,
|
|||
{
|
||||
int int_value = atoi(value);
|
||||
|
||||
// must be multiple of two
|
||||
/* must be multiple of two */
|
||||
if (option == twc_config_short_id_size && int_value % 2)
|
||||
return 0;
|
||||
|
||||
|
@ -190,11 +179,10 @@ twc_config_profile_change_callback(const void *pointer, void *data,
|
|||
/* option changed for default profile, update all profiles */
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(twc_profiles, index, item)
|
||||
twc_list_foreach (twc_profiles, index, item)
|
||||
{
|
||||
bool logging_enabled
|
||||
= TWC_PROFILE_OPTION_BOOLEAN(item->profile,
|
||||
TWC_PROFILE_OPTION_LOGGING);
|
||||
bool logging_enabled = TWC_PROFILE_OPTION_BOOLEAN(
|
||||
item->profile, TWC_PROFILE_OPTION_LOGGING);
|
||||
twc_profile_set_logging(item->profile, logging_enabled);
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +190,6 @@ twc_config_profile_change_callback(const void *pointer, void *data,
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,9 +197,8 @@ twc_config_profile_change_callback(const void *pointer, void *data,
|
|||
*/
|
||||
struct t_config_option *
|
||||
twc_config_init_option(struct t_twc_profile *profile,
|
||||
struct t_config_section *section,
|
||||
int option_index, const char *option_name,
|
||||
bool is_default_profile)
|
||||
struct t_config_section *section, int option_index,
|
||||
const char *option_name, bool is_default_profile)
|
||||
{
|
||||
char *type;
|
||||
char *description;
|
||||
|
@ -251,7 +237,8 @@ twc_config_init_option(struct t_twc_profile *profile,
|
|||
type = "integer";
|
||||
description = "maximum amount of friend requests to retain before "
|
||||
"ignoring new ones";
|
||||
min = 0; max = INT_MAX;
|
||||
min = 0;
|
||||
max = INT_MAX;
|
||||
default_value = "100";
|
||||
break;
|
||||
case TWC_PROFILE_OPTION_PASSPHRASE:
|
||||
|
@ -267,14 +254,16 @@ twc_config_init_option(struct t_twc_profile *profile,
|
|||
case TWC_PROFILE_OPTION_PROXY_PORT:
|
||||
type = "integer";
|
||||
description = "proxy port";
|
||||
min = 0; max = UINT16_MAX;
|
||||
min = 0;
|
||||
max = UINT16_MAX;
|
||||
null_allowed = true;
|
||||
break;
|
||||
case TWC_PROFILE_OPTION_PROXY_TYPE:
|
||||
type = "integer";
|
||||
description = "proxy type; requires profile reload to take effect";
|
||||
string_values = "none|socks5|http";
|
||||
min = 0; max = 0;
|
||||
min = 0;
|
||||
max = 0;
|
||||
default_value = "none";
|
||||
break;
|
||||
case TWC_PROFILE_OPTION_SAVEFILE:
|
||||
|
@ -308,12 +297,11 @@ twc_config_init_option(struct t_twc_profile *profile,
|
|||
*index_change_pointer = option_index;
|
||||
|
||||
return weechat_config_new_option(
|
||||
twc_config_file, section,
|
||||
option_name, type, description, string_values, min, max,
|
||||
default_value, value, null_allowed,
|
||||
twc_config_file, section, option_name, type, description, string_values,
|
||||
min, max, default_value, value, null_allowed,
|
||||
twc_config_profile_check_value_callback, profile, index_check_pointer,
|
||||
twc_config_profile_change_callback, profile, index_change_pointer,
|
||||
NULL, NULL, NULL);
|
||||
twc_config_profile_change_callback, profile, index_change_pointer, NULL,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -324,57 +312,39 @@ twc_config_init()
|
|||
{
|
||||
twc_config_file = weechat_config_new("tox", NULL, NULL, NULL);
|
||||
|
||||
twc_config_section_profile =
|
||||
weechat_config_new_section(twc_config_file, "profile",
|
||||
0, 0,
|
||||
twc_config_profile_read_callback,
|
||||
NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
twc_config_section_profile = weechat_config_new_section(
|
||||
twc_config_file, "profile", 0, 0, twc_config_profile_read_callback,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL);
|
||||
|
||||
twc_config_section_profile_default =
|
||||
weechat_config_new_section(twc_config_file, "profile_default",
|
||||
0, 0,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
twc_config_section_profile_default = weechat_config_new_section(
|
||||
twc_config_file, "profile_default", 0, 0, 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)
|
||||
{
|
||||
twc_config_profile_default[i] =
|
||||
twc_config_init_option(NULL, twc_config_section_profile_default,
|
||||
i, twc_profile_option_names[i], true);
|
||||
twc_config_init_option(NULL, twc_config_section_profile_default, i,
|
||||
twc_profile_option_names[i], true);
|
||||
}
|
||||
|
||||
twc_config_section_look =
|
||||
weechat_config_new_section(twc_config_file, "look",
|
||||
0, 0,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
twc_config_section_look = weechat_config_new_section(
|
||||
twc_config_file, "look", 0, 0, 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_file, twc_config_section_look,
|
||||
"friend_request_message", "string",
|
||||
twc_config_file, twc_config_section_look, "friend_request_message",
|
||||
"string",
|
||||
"message sent with friend requests if no other message is specified",
|
||||
NULL, 0, 0,
|
||||
"Hi! Please add me on Tox!", NULL, 0,
|
||||
twc_config_check_value_callback, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
NULL, 0, 0, "Hi! Please add me on Tox!", NULL, 0,
|
||||
twc_config_check_value_callback, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL);
|
||||
twc_config_short_id_size = weechat_config_new_option(
|
||||
twc_config_file, twc_config_section_look,
|
||||
"short_id_size", "integer",
|
||||
twc_config_file, twc_config_section_look, "short_id_size", "integer",
|
||||
"length of Tox IDs shown in short format; must be a multiple of two",
|
||||
NULL, 2, TOX_PUBLIC_KEY_SIZE * 2,
|
||||
"8", NULL, 0,
|
||||
twc_config_check_value_callback, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
NULL, 2, TOX_PUBLIC_KEY_SIZE * 2, "8", NULL, 0,
|
||||
twc_config_check_value_callback, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -385,19 +355,18 @@ twc_config_init_profile(struct t_twc_profile *profile)
|
|||
{
|
||||
for (int i = 0; i < TWC_PROFILE_NUM_OPTIONS; ++i)
|
||||
{
|
||||
// length: name + . + option + \0
|
||||
size_t length = strlen(profile->name) + 1
|
||||
+ strlen(twc_profile_option_names[i]) + 1;
|
||||
/* length: name + . + option + \0 */
|
||||
size_t length =
|
||||
strlen(profile->name) + 1 + strlen(twc_profile_option_names[i]) + 1;
|
||||
|
||||
char *option_name = malloc(sizeof(*option_name) * length);
|
||||
if (option_name)
|
||||
{
|
||||
snprintf(option_name, length, "%s.%s",
|
||||
profile->name,
|
||||
snprintf(option_name, length, "%s.%s", profile->name,
|
||||
twc_profile_option_names[i]);
|
||||
|
||||
profile->options[i] = twc_config_init_option(profile,
|
||||
twc_config_section_profile, i, option_name, false);
|
||||
profile->options[i] = twc_config_init_option(
|
||||
profile, twc_config_section_profile, i, option_name, false);
|
||||
free(option_name);
|
||||
}
|
||||
}
|
||||
|
@ -420,4 +389,3 @@ twc_config_write()
|
|||
{
|
||||
return weechat_config_write(twc_config_file);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,5 +44,4 @@ twc_config_write();
|
|||
void
|
||||
twc_config_init_profile(struct t_twc_profile *profile);
|
||||
|
||||
#endif // TOX_WEECHAT_CONFIG_H
|
||||
|
||||
#endif /* TOX_WEECHAT_CONFIG_H */
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-utils.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-friend-request.h"
|
||||
|
||||
|
@ -36,18 +36,17 @@
|
|||
* other error.
|
||||
*/
|
||||
int
|
||||
twc_friend_request_add(struct t_twc_profile *profile,
|
||||
const uint8_t *client_id,
|
||||
twc_friend_request_add(struct t_twc_profile *profile, const uint8_t *client_id,
|
||||
const char *message)
|
||||
{
|
||||
size_t max_request_count =
|
||||
TWC_PROFILE_OPTION_INTEGER(profile, TWC_PROFILE_OPTION_MAX_FRIEND_REQUESTS);
|
||||
size_t max_request_count = TWC_PROFILE_OPTION_INTEGER(
|
||||
profile, TWC_PROFILE_OPTION_MAX_FRIEND_REQUESTS);
|
||||
if (profile->friend_requests->count >= max_request_count)
|
||||
return -1;
|
||||
|
||||
// create a new request
|
||||
struct t_twc_friend_request *request
|
||||
= malloc(sizeof(struct t_twc_friend_request));
|
||||
/* create a new request */
|
||||
struct t_twc_friend_request *request =
|
||||
malloc(sizeof(struct t_twc_friend_request));
|
||||
if (!request)
|
||||
return -2;
|
||||
|
||||
|
@ -114,4 +113,3 @@ twc_friend_request_free_list(struct t_twc_list *list)
|
|||
|
||||
free(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,7 @@ struct t_twc_friend_request
|
|||
};
|
||||
|
||||
int
|
||||
twc_friend_request_add(struct t_twc_profile *profile,
|
||||
const uint8_t *client_id,
|
||||
twc_friend_request_add(struct t_twc_profile *profile, const uint8_t *client_id,
|
||||
const char *message);
|
||||
|
||||
bool
|
||||
|
@ -47,8 +46,7 @@ void
|
|||
twc_friend_request_remove(struct t_twc_friend_request *request);
|
||||
|
||||
struct t_twc_friend_request *
|
||||
twc_friend_request_with_index(struct t_twc_profile *profile,
|
||||
int64_t index);
|
||||
twc_friend_request_with_index(struct t_twc_profile *profile, int64_t index);
|
||||
|
||||
void
|
||||
twc_friend_request_free(struct t_twc_friend_request *request);
|
||||
|
@ -56,5 +54,4 @@ twc_friend_request_free(struct t_twc_friend_request *request);
|
|||
void
|
||||
twc_friend_request_free_list(struct t_twc_list *list);
|
||||
|
||||
#endif // TOX_WEECHAT_FRIEND_REQUEST_H
|
||||
|
||||
#endif /* TOX_WEECHAT_FRIEND_REQUEST_H */
|
||||
|
|
|
@ -19,17 +19,17 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#ifdef TOXAV_ENABLED
|
||||
#include <tox/toxav.h>
|
||||
#endif // TOXAV_ENABLED
|
||||
#include <tox/toxav.h>
|
||||
#endif /* TOXAV_ENABLED */
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-utils.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-group-invite.h"
|
||||
|
||||
|
@ -39,13 +39,12 @@
|
|||
* Returns the index of the invite on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
twc_group_chat_invite_add(struct t_twc_profile *profile,
|
||||
int32_t friend_number, uint8_t group_chat_type,
|
||||
uint8_t *data, size_t size)
|
||||
twc_group_chat_invite_add(struct t_twc_profile *profile, int32_t friend_number,
|
||||
uint8_t group_chat_type, uint8_t *data, size_t size)
|
||||
{
|
||||
// create a new invite object
|
||||
struct t_twc_group_chat_invite *invite
|
||||
= malloc(sizeof(struct t_twc_group_chat_invite));
|
||||
/* create a new invite object */
|
||||
struct t_twc_group_chat_invite *invite =
|
||||
malloc(sizeof(struct t_twc_group_chat_invite));
|
||||
if (!invite)
|
||||
return -1;
|
||||
|
||||
|
@ -75,15 +74,15 @@ twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite)
|
|||
switch (invite->group_chat_type)
|
||||
{
|
||||
case TOX_CONFERENCE_TYPE_TEXT:
|
||||
rc = tox_conference_join(invite->profile->tox, invite->friend_number,
|
||||
invite->data, invite->data_size, &err);
|
||||
rc =
|
||||
tox_conference_join(invite->profile->tox, invite->friend_number,
|
||||
invite->data, invite->data_size, &err);
|
||||
break;
|
||||
#ifdef TOXAV_ENABLED
|
||||
case TOX_CONFERENCE_TYPE_AV:
|
||||
rc = toxav_join_av_groupchat(invite->profile->tox,
|
||||
invite->friend_number,
|
||||
invite->data, invite->data_size,
|
||||
NULL, NULL);
|
||||
invite->friend_number, invite->data,
|
||||
invite->data_size, NULL, NULL);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
@ -112,8 +111,7 @@ twc_group_chat_invite_remove(struct t_twc_group_chat_invite *invite)
|
|||
* Get group chat invite with a given index.
|
||||
*/
|
||||
struct t_twc_group_chat_invite *
|
||||
twc_group_chat_invite_with_index(struct t_twc_profile *profile,
|
||||
size_t index)
|
||||
twc_group_chat_invite_with_index(struct t_twc_profile *profile, size_t index)
|
||||
{
|
||||
struct t_twc_list_item *item =
|
||||
twc_list_get(profile->group_chat_invites, index);
|
||||
|
@ -145,4 +143,3 @@ twc_group_chat_invite_free_list(struct t_twc_list *list)
|
|||
|
||||
free(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,9 +40,8 @@ struct t_twc_group_chat_invite
|
|||
};
|
||||
|
||||
int
|
||||
twc_group_chat_invite_add(struct t_twc_profile *profile,
|
||||
int32_t friend_number, uint8_t group_chat_type,
|
||||
uint8_t *data, size_t size);
|
||||
twc_group_chat_invite_add(struct t_twc_profile *profile, int32_t friend_number,
|
||||
uint8_t group_chat_type, uint8_t *data, size_t size);
|
||||
|
||||
int
|
||||
twc_group_chat_invite_join(struct t_twc_group_chat_invite *invite);
|
||||
|
@ -51,8 +50,7 @@ void
|
|||
twc_group_chat_invite_remove(struct t_twc_group_chat_invite *invite);
|
||||
|
||||
struct t_twc_group_chat_invite *
|
||||
twc_group_chat_invite_with_index(struct t_twc_profile *profile,
|
||||
size_t index);
|
||||
twc_group_chat_invite_with_index(struct t_twc_profile *profile, size_t index);
|
||||
|
||||
void
|
||||
twc_group_chat_invite_free(struct t_twc_group_chat_invite *invite);
|
||||
|
@ -60,5 +58,4 @@ twc_group_chat_invite_free(struct t_twc_group_chat_invite *invite);
|
|||
void
|
||||
twc_group_chat_invite_free_list(struct t_twc_list *list);
|
||||
|
||||
#endif // TOX_WEECHAT_GROUP_INVITE_H
|
||||
|
||||
#endif /* TOX_WEECHAT_GROUP_INVITE_H */
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
*
|
||||
* Tox-WeeChat is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or * (at your option) any later version.
|
||||
* the Free Software Foundation, either version 3 of the License, or * (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Tox-WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
@ -19,20 +20,18 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-utils.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-gui.h"
|
||||
|
||||
char *
|
||||
twc_bar_item_away(const void *pointer, void *data,
|
||||
struct t_gui_bar_item *item,
|
||||
struct t_gui_window *window,
|
||||
struct t_gui_buffer *buffer,
|
||||
twc_bar_item_away(const void *pointer, void *data, struct t_gui_bar_item *item,
|
||||
struct t_gui_window *window, struct t_gui_buffer *buffer,
|
||||
struct t_hashtable *extra_info)
|
||||
{
|
||||
struct t_twc_profile *profile = twc_profile_search_buffer(buffer);
|
||||
|
@ -90,23 +89,19 @@ twc_bar_item_buffer_plugin(const void *pointer, void *data,
|
|||
|
||||
const char *profile_name = profile->name;
|
||||
|
||||
snprintf(string, sizeof(string),
|
||||
"%s%s/%s%s%s/%s%s",
|
||||
plugin_name,
|
||||
weechat_color("bar_delim"),
|
||||
weechat_color("bar_fg"),
|
||||
profile_name,
|
||||
weechat_color("bar_delim"),
|
||||
weechat_color("bar_fg"),
|
||||
snprintf(string, sizeof(string), "%s%s/%s%s%s/%s%s", plugin_name,
|
||||
weechat_color("bar_delim"), weechat_color("bar_fg"), profile_name,
|
||||
weechat_color("bar_delim"), weechat_color("bar_fg"),
|
||||
profile->tox_online ? "online" : "offline");
|
||||
|
||||
return strdup(string);
|
||||
}
|
||||
|
||||
void twc_gui_init()
|
||||
void
|
||||
twc_gui_init()
|
||||
{
|
||||
weechat_bar_item_new("away", twc_bar_item_away, NULL, 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, NULL);
|
||||
weechat_bar_item_new("buffer_plugin", twc_bar_item_buffer_plugin, NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#ifndef TOX_WEECHAT_GUI_H
|
||||
#define TOX_WEECHAT_GUI_H
|
||||
|
||||
void twc_gui_init();
|
||||
|
||||
#endif // TOX_WEECHAT_GUI_H
|
||||
void
|
||||
twc_gui_init();
|
||||
|
||||
#endif /* TOX_WEECHAT_GUI_H */
|
||||
|
|
|
@ -82,8 +82,7 @@ twc_list_item_new_data_add(struct t_twc_list *list, const void *data)
|
|||
* Add an item to the list.
|
||||
*/
|
||||
void
|
||||
twc_list_add(struct t_twc_list *list,
|
||||
struct t_twc_list_item *item)
|
||||
twc_list_add(struct t_twc_list *list, struct t_twc_list_item *item)
|
||||
{
|
||||
item->list = list;
|
||||
|
||||
|
@ -140,7 +139,7 @@ twc_list_remove_with_data(struct t_twc_list *list, const void *data)
|
|||
{
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(list, index, item)
|
||||
twc_list_foreach (list, index, item)
|
||||
{
|
||||
if (item->data == data)
|
||||
{
|
||||
|
@ -176,7 +175,7 @@ twc_list_get(struct t_twc_list *list, size_t index)
|
|||
struct t_twc_list_item *item;
|
||||
if (list->count - index > index / 2)
|
||||
{
|
||||
twc_list_foreach(list, current_index, item)
|
||||
twc_list_foreach (list, current_index, item)
|
||||
{
|
||||
if (current_index == index)
|
||||
return item;
|
||||
|
@ -184,7 +183,7 @@ twc_list_get(struct t_twc_list *list, size_t index)
|
|||
}
|
||||
else
|
||||
{
|
||||
twc_list_foreach_reverse(list, current_index, item)
|
||||
twc_list_foreach_reverse (list, current_index, item)
|
||||
{
|
||||
if (current_index == index)
|
||||
return item;
|
||||
|
@ -193,4 +192,3 @@ twc_list_get(struct t_twc_list *list, size_t index)
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,10 +33,9 @@ struct t_twc_list_item
|
|||
{
|
||||
struct t_twc_list *list;
|
||||
|
||||
// don't know if this is a good idea
|
||||
// probably not
|
||||
union
|
||||
{
|
||||
/* don't know if this is a good idea
|
||||
* probably not */
|
||||
union {
|
||||
void *data;
|
||||
struct t_twc_profile *profile;
|
||||
struct t_twc_friend_request *friend_request;
|
||||
|
@ -79,15 +78,11 @@ twc_list_pop(struct t_twc_list *list);
|
|||
struct t_twc_list_item *
|
||||
twc_list_get(struct t_twc_list *list, size_t index);
|
||||
|
||||
#define twc_list_foreach(list, index, item) \
|
||||
for (item = list->head, index = 0; \
|
||||
item; \
|
||||
item = item->next_item, ++index)
|
||||
#define twc_list_foreach(list, index, item) \
|
||||
for (item = list->head, index = 0; item; item = item->next_item, ++index)
|
||||
|
||||
#define twc_list_foreach_reverse(list, index, item) \
|
||||
for (item = list->tail, index = list->count - 1; \
|
||||
item; \
|
||||
#define twc_list_foreach_reverse(list, index, item) \
|
||||
for (item = list->tail, index = list->count - 1; item; \
|
||||
item = item->prev_item, --index)
|
||||
|
||||
#endif // TOX_WEECHAT_LIST_H
|
||||
|
||||
#endif /* TOX_WEECHAT_LIST_H */
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-utils.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-message-queue.h"
|
||||
|
||||
|
@ -36,12 +36,12 @@ struct t_twc_list *
|
|||
twc_message_queue_get_or_create(struct t_twc_profile *profile,
|
||||
int32_t friend_number)
|
||||
{
|
||||
struct t_twc_list *message_queue = weechat_hashtable_get(profile->message_queues, &friend_number);
|
||||
struct t_twc_list *message_queue =
|
||||
weechat_hashtable_get(profile->message_queues, &friend_number);
|
||||
if (!message_queue)
|
||||
{
|
||||
message_queue = twc_list_new();
|
||||
weechat_hashtable_set(profile->message_queues,
|
||||
&friend_number,
|
||||
weechat_hashtable_set(profile->message_queues, &friend_number,
|
||||
message_queue);
|
||||
}
|
||||
|
||||
|
@ -50,12 +50,12 @@ twc_message_queue_get_or_create(struct t_twc_profile *profile,
|
|||
|
||||
/**
|
||||
* Add a friend message to the message queue and tries to send it if the
|
||||
* friend is online. Handles splitting of messages. (TODO: actually split messages)
|
||||
* friend is online. Handles splitting of messages. (TODO: actually split
|
||||
* messages)
|
||||
*/
|
||||
void
|
||||
twc_message_queue_add_friend_message(struct t_twc_profile *profile,
|
||||
int32_t friend_number,
|
||||
const char *message,
|
||||
int32_t friend_number, const char *message,
|
||||
TOX_MESSAGE_TYPE message_type)
|
||||
{
|
||||
int len = strlen(message);
|
||||
|
@ -63,8 +63,8 @@ twc_message_queue_add_friend_message(struct t_twc_profile *profile,
|
|||
{
|
||||
int fit_len = twc_fit_utf8(message, TWC_MAX_FRIEND_MESSAGE_LENGTH);
|
||||
|
||||
struct t_twc_queued_message *queued_message
|
||||
= malloc(sizeof(struct t_twc_queued_message));
|
||||
struct t_twc_queued_message *queued_message =
|
||||
malloc(sizeof(struct t_twc_queued_message));
|
||||
|
||||
time_t rawtime = time(NULL);
|
||||
queued_message->time = malloc(sizeof(struct tm));
|
||||
|
@ -76,15 +76,16 @@ twc_message_queue_add_friend_message(struct t_twc_profile *profile,
|
|||
message += fit_len;
|
||||
len -= fit_len;
|
||||
|
||||
// create a queue if needed and add message
|
||||
struct t_twc_list *message_queue
|
||||
= twc_message_queue_get_or_create(profile, friend_number);
|
||||
/* create a queue if needed and add message */
|
||||
struct t_twc_list *message_queue =
|
||||
twc_message_queue_get_or_create(profile, friend_number);
|
||||
twc_list_item_new_data_add(message_queue, queued_message);
|
||||
}
|
||||
|
||||
// flush if friend is online
|
||||
if (profile->tox
|
||||
&& (tox_friend_get_connection_status(profile->tox, friend_number, NULL) != TOX_CONNECTION_NONE))
|
||||
|
||||
/* flush if friend is online */
|
||||
if (profile->tox &&
|
||||
(tox_friend_get_connection_status(profile->tox, friend_number, NULL) !=
|
||||
TOX_CONNECTION_NONE))
|
||||
twc_message_queue_flush_friend(profile, friend_number);
|
||||
}
|
||||
|
||||
|
@ -95,32 +96,30 @@ void
|
|||
twc_message_queue_flush_friend(struct t_twc_profile *profile,
|
||||
int32_t friend_number)
|
||||
{
|
||||
struct t_twc_list *message_queue
|
||||
= twc_message_queue_get_or_create(profile, friend_number);
|
||||
struct t_twc_list *message_queue =
|
||||
twc_message_queue_get_or_create(profile, friend_number);
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(message_queue, index, item)
|
||||
twc_list_foreach (message_queue, index, item)
|
||||
{
|
||||
struct t_twc_queued_message *queued_message = item->queued_message;
|
||||
|
||||
// TODO: store and deal with message IDs
|
||||
/* TODO: store and deal with message IDs */
|
||||
TOX_ERR_FRIEND_SEND_MESSAGE err;
|
||||
(void)tox_friend_send_message(profile->tox,
|
||||
friend_number,
|
||||
(void)tox_friend_send_message(profile->tox, friend_number,
|
||||
queued_message->message_type,
|
||||
(uint8_t *)queued_message->message,
|
||||
strlen(queued_message->message),
|
||||
&err);
|
||||
strlen(queued_message->message), &err);
|
||||
|
||||
if (err == TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED)
|
||||
{
|
||||
// break if message send failed
|
||||
/* break if message send failed */
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *err_str;
|
||||
// check if error occured
|
||||
/* check if error occured */
|
||||
switch (err)
|
||||
{
|
||||
case TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG:
|
||||
|
@ -146,22 +145,20 @@ twc_message_queue_flush_friend(struct t_twc_profile *profile,
|
|||
}
|
||||
if (err != TOX_ERR_FRIEND_SEND_MESSAGE_OK)
|
||||
{
|
||||
struct t_twc_chat *friend_chat
|
||||
= twc_chat_search_friend(profile, friend_number, true);
|
||||
struct t_twc_chat *friend_chat =
|
||||
twc_chat_search_friend(profile, friend_number, true);
|
||||
|
||||
weechat_printf(friend_chat->buffer,
|
||||
"%s%sFailed to send message: %s%s",
|
||||
weechat_prefix("error"),
|
||||
weechat_color("chat_highlight"),
|
||||
err_str,
|
||||
weechat_color("reset"));
|
||||
weechat_printf(
|
||||
friend_chat->buffer, "%s%sFailed to send message: %s%s",
|
||||
weechat_prefix("error"), weechat_color("chat_highlight"),
|
||||
err_str, weechat_color("reset"));
|
||||
}
|
||||
twc_message_queue_free_message(queued_message);
|
||||
item->queued_message = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// remove any now-empty items
|
||||
/* remove any now-empty items */
|
||||
while (message_queue->head && !(message_queue->head->queued_message))
|
||||
twc_list_remove(message_queue->head);
|
||||
}
|
||||
|
@ -200,4 +197,3 @@ twc_message_queue_free_profile(struct t_twc_profile *profile)
|
|||
twc_message_queue_free_map_callback, NULL);
|
||||
weechat_hashtable_free(profile->message_queues);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,8 +38,7 @@ struct t_twc_queued_message
|
|||
|
||||
void
|
||||
twc_message_queue_add_friend_message(struct t_twc_profile *profile,
|
||||
int32_t friend_number,
|
||||
const char *message,
|
||||
int32_t friend_number, const char *message,
|
||||
TOX_MESSAGE_TYPE message_type);
|
||||
|
||||
void
|
||||
|
@ -52,5 +51,4 @@ twc_message_queue_free_message(struct t_twc_queued_message *message);
|
|||
void
|
||||
twc_message_queue_free_profile(struct t_twc_profile *profile);
|
||||
|
||||
#endif // TOX_WEECHAT_MESSAGE_QUEUE_H
|
||||
|
||||
#endif /* TOX_WEECHAT_MESSAGE_QUEUE_H */
|
||||
|
|
|
@ -17,27 +17,27 @@
|
|||
* along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#ifdef TOXENCRYPTSAVE_ENABLED
|
||||
#include <tox/toxencryptsave.h>
|
||||
#endif // TOXENCRYPTSAVE_ENABLED
|
||||
#include <tox/toxencryptsave.h>
|
||||
#endif /* TOXENCRYPTSAVE_ENABLED */
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-bootstrap.h"
|
||||
#include "twc-chat.h"
|
||||
#include "twc-config.h"
|
||||
#include "twc-friend-request.h"
|
||||
#include "twc-group-invite.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-message-queue.h"
|
||||
#include "twc-chat.h"
|
||||
#include "twc-tox-callbacks.h"
|
||||
#include "twc-utils.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-profile.h"
|
||||
|
||||
|
@ -54,10 +54,12 @@ struct t_config_option *twc_config_profile_default[TWC_PROFILE_NUM_OPTIONS];
|
|||
char *
|
||||
twc_profile_expanded_data_path(struct t_twc_profile *profile)
|
||||
{
|
||||
const char *weechat_dir = weechat_info_get ("weechat_dir", NULL);
|
||||
const char *base_path = TWC_PROFILE_OPTION_STRING(profile, TWC_PROFILE_OPTION_SAVEFILE);
|
||||
const char *weechat_dir = weechat_info_get("weechat_dir", NULL);
|
||||
const char *base_path =
|
||||
TWC_PROFILE_OPTION_STRING(profile, TWC_PROFILE_OPTION_SAVEFILE);
|
||||
char *home_expanded = weechat_string_replace(base_path, "%h", weechat_dir);
|
||||
char *full_path = weechat_string_replace(home_expanded, "%p", profile->name);
|
||||
char *full_path =
|
||||
weechat_string_replace(home_expanded, "%p", profile->name);
|
||||
free(home_expanded);
|
||||
|
||||
return full_path;
|
||||
|
@ -72,17 +74,17 @@ int
|
|||
twc_profile_save_data_file(struct t_twc_profile *profile)
|
||||
{
|
||||
if (!(profile->tox))
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
char *full_path = twc_profile_expanded_data_path(profile);
|
||||
|
||||
// create containing folder if it doesn't exist
|
||||
/* create containing folder if it doesn't exist */
|
||||
char *rightmost_slash = strrchr(full_path, '/');
|
||||
char *dir_path = weechat_strndup(full_path, rightmost_slash - full_path);
|
||||
weechat_mkdir_parents(dir_path, 0755);
|
||||
free(dir_path);
|
||||
|
||||
// save Tox data to a buffer
|
||||
/* save Tox data to a buffer */
|
||||
size_t size = tox_get_savedata_size(profile->tox);
|
||||
uint8_t data[size];
|
||||
uint8_t *d = data;
|
||||
|
@ -90,13 +92,14 @@ twc_profile_save_data_file(struct t_twc_profile *profile)
|
|||
|
||||
#ifdef TOXENCRYPTSAVE_ENABLED
|
||||
uint8_t enc_data[size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
|
||||
const 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)
|
||||
{
|
||||
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))
|
||||
{
|
||||
weechat_printf(profile->buffer, "error encrypting data");
|
||||
return -1;
|
||||
|
@ -104,9 +107,9 @@ twc_profile_save_data_file(struct t_twc_profile *profile)
|
|||
d = enc_data;
|
||||
size += TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
|
||||
}
|
||||
#endif // TOXENCRYPTSAVE_ENABLED
|
||||
#endif /* TOXENCRYPTSAVE_ENABLED */
|
||||
|
||||
// save buffer to a file
|
||||
/* save buffer to a file */
|
||||
FILE *file = fopen(full_path, "w");
|
||||
if (file)
|
||||
{
|
||||
|
@ -152,10 +155,10 @@ twc_profile_new(const char *name)
|
|||
struct t_twc_profile *profile = malloc(sizeof(struct t_twc_profile));
|
||||
profile->name = strdup(name);
|
||||
|
||||
// add to profile list
|
||||
/* add to profile list */
|
||||
twc_list_item_new_data_add(twc_profiles, profile);
|
||||
|
||||
// set up internal vars
|
||||
/* set up internal vars */
|
||||
profile->tox = NULL;
|
||||
profile->buffer = NULL;
|
||||
profile->tox_do_timer = NULL;
|
||||
|
@ -164,12 +167,10 @@ twc_profile_new(const char *name)
|
|||
profile->chats = twc_list_new();
|
||||
profile->friend_requests = twc_list_new();
|
||||
profile->group_chat_invites = twc_list_new();
|
||||
profile->message_queues = weechat_hashtable_new(32,
|
||||
WEECHAT_HASHTABLE_INTEGER,
|
||||
WEECHAT_HASHTABLE_POINTER,
|
||||
NULL, NULL);
|
||||
profile->message_queues = weechat_hashtable_new(
|
||||
32, WEECHAT_HASHTABLE_INTEGER, WEECHAT_HASHTABLE_POINTER, NULL, NULL);
|
||||
|
||||
// set up config
|
||||
/* set up config */
|
||||
twc_config_init_profile(profile);
|
||||
|
||||
return profile;
|
||||
|
@ -203,11 +204,11 @@ twc_profile_set_options(struct Tox_Options *options,
|
|||
}
|
||||
|
||||
options->proxy_port =
|
||||
TWC_PROFILE_OPTION_INTEGER(profile, TWC_PROFILE_OPTION_PROXY_PORT);
|
||||
TWC_PROFILE_OPTION_INTEGER(profile, TWC_PROFILE_OPTION_PROXY_PORT);
|
||||
options->udp_enabled =
|
||||
TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_UDP);
|
||||
TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_UDP);
|
||||
options->ipv6_enabled =
|
||||
TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_IPV6);
|
||||
TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_IPV6);
|
||||
|
||||
#ifndef NDEBUG
|
||||
options->log_callback = twc_tox_log_callback;
|
||||
|
@ -217,57 +218,58 @@ twc_profile_set_options(struct Tox_Options *options,
|
|||
|
||||
void
|
||||
twc_tox_new_print_error(struct t_twc_profile *profile,
|
||||
struct Tox_Options *options,
|
||||
TOX_ERR_NEW error)
|
||||
struct Tox_Options *options, TOX_ERR_NEW error)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case TOX_ERR_NEW_MALLOC:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (malloc error)",
|
||||
weechat_prefix("error"));
|
||||
break;
|
||||
case TOX_ERR_NEW_PORT_ALLOC:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (failed to allocate a port)",
|
||||
weechat_prefix("error"));
|
||||
break;
|
||||
case TOX_ERR_NEW_PROXY_BAD_TYPE:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (internal error; bad proxy type)",
|
||||
weechat_prefix("error"));
|
||||
break;
|
||||
case TOX_ERR_NEW_PROXY_BAD_HOST:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (invalid proxy host: \"%s\")",
|
||||
weechat_prefix("error"), options->proxy_host);
|
||||
break;
|
||||
case TOX_ERR_NEW_PROXY_BAD_PORT:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (invalid proxy port: \"%d\")",
|
||||
weechat_prefix("error"), options->proxy_port);
|
||||
break;
|
||||
case TOX_ERR_NEW_PROXY_NOT_FOUND:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (proxy host not found: \"%s\")",
|
||||
weechat_prefix("error"), options->proxy_host);
|
||||
break;
|
||||
case TOX_ERR_NEW_LOAD_ENCRYPTED:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (encrypted data files are not yet supported)",
|
||||
weechat_prefix("error"));
|
||||
break;
|
||||
case TOX_ERR_NEW_LOAD_BAD_FORMAT:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (invalid data file, some data "
|
||||
"may have been loaded; use -force to try using it)",
|
||||
weechat_prefix("error"));
|
||||
break;
|
||||
default:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (unknown error %d)",
|
||||
weechat_prefix("error"), error);
|
||||
break;
|
||||
case TOX_ERR_NEW_MALLOC:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (malloc error)",
|
||||
weechat_prefix("error"));
|
||||
break;
|
||||
case TOX_ERR_NEW_PORT_ALLOC:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (failed to allocate a port)",
|
||||
weechat_prefix("error"));
|
||||
break;
|
||||
case TOX_ERR_NEW_PROXY_BAD_TYPE:
|
||||
weechat_printf(
|
||||
profile->buffer,
|
||||
"%scould not load Tox (internal error; bad proxy type)",
|
||||
weechat_prefix("error"));
|
||||
break;
|
||||
case TOX_ERR_NEW_PROXY_BAD_HOST:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (invalid proxy host: \"%s\")",
|
||||
weechat_prefix("error"), options->proxy_host);
|
||||
break;
|
||||
case TOX_ERR_NEW_PROXY_BAD_PORT:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (invalid proxy port: \"%d\")",
|
||||
weechat_prefix("error"), options->proxy_port);
|
||||
break;
|
||||
case TOX_ERR_NEW_PROXY_NOT_FOUND:
|
||||
weechat_printf(
|
||||
profile->buffer,
|
||||
"%scould not load Tox (proxy host not found: \"%s\")",
|
||||
weechat_prefix("error"), options->proxy_host);
|
||||
break;
|
||||
case TOX_ERR_NEW_LOAD_ENCRYPTED:
|
||||
weechat_printf(profile->buffer, "%scould not load Tox (encrypted "
|
||||
"data files are not yet supported)",
|
||||
weechat_prefix("error"));
|
||||
break;
|
||||
case TOX_ERR_NEW_LOAD_BAD_FORMAT:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (invalid data file, some data "
|
||||
"may have been loaded; use -force to try using it)",
|
||||
weechat_prefix("error"));
|
||||
break;
|
||||
default:
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox (unknown error %d)",
|
||||
weechat_prefix("error"), error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,43 +285,39 @@ twc_profile_load(struct t_twc_profile *profile)
|
|||
|
||||
if (!(profile->buffer))
|
||||
{
|
||||
// create main buffer
|
||||
profile->buffer = weechat_buffer_new(profile->name,
|
||||
NULL, NULL, NULL,
|
||||
/* create main buffer */
|
||||
profile->buffer = weechat_buffer_new(profile->name, NULL, NULL, NULL,
|
||||
twc_profile_buffer_close_callback,
|
||||
profile, NULL);
|
||||
if (!(profile->buffer))
|
||||
return TWC_RC_ERROR;
|
||||
|
||||
/* disable logging for buffer if option is off */
|
||||
bool logging = TWC_PROFILE_OPTION_BOOLEAN(profile,
|
||||
TWC_PROFILE_OPTION_LOGGING);
|
||||
bool logging =
|
||||
TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_LOGGING);
|
||||
twc_set_buffer_logging(profile->buffer, logging);
|
||||
|
||||
profile->nicklist_group = weechat_nicklist_add_group(profile->buffer, NULL,
|
||||
NULL, NULL, true);
|
||||
profile->nicklist_group =
|
||||
weechat_nicklist_add_group(profile->buffer, NULL, NULL, NULL, true);
|
||||
weechat_buffer_set(profile->buffer, "nicklist", "1");
|
||||
}
|
||||
|
||||
weechat_printf(profile->buffer,
|
||||
"%sprofile %s connecting",
|
||||
weechat_printf(profile->buffer, "%sprofile %s connecting",
|
||||
weechat_prefix("network"), profile->name);
|
||||
|
||||
// create Tox options object
|
||||
/* create Tox options object */
|
||||
struct Tox_Options options;
|
||||
|
||||
//tox_options_default(&options);
|
||||
twc_profile_set_options(&options, profile);
|
||||
|
||||
// print a proxy message
|
||||
/* print a proxy message */
|
||||
if (options.proxy_type != TOX_PROXY_TYPE_NONE)
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%susing %s proxy %s:%d",
|
||||
weechat_printf(profile->buffer, "%susing %s proxy %s:%d",
|
||||
weechat_prefix("network"),
|
||||
options.proxy_type == TOX_PROXY_TYPE_HTTP ? "HTTP" :
|
||||
TOX_PROXY_TYPE_SOCKS5 ? "SOCKS5" :
|
||||
NULL,
|
||||
options.proxy_type == TOX_PROXY_TYPE_HTTP
|
||||
? "HTTP"
|
||||
: TOX_PROXY_TYPE_SOCKS5 ? "SOCKS5" : NULL,
|
||||
options.proxy_host, options.proxy_port);
|
||||
|
||||
if (options.udp_enabled)
|
||||
|
@ -327,12 +325,12 @@ twc_profile_load(struct t_twc_profile *profile)
|
|||
"%s%swarning:%s Tox is configured to use a proxy, "
|
||||
"but UDP is not disabled. Your IP address may not "
|
||||
"be hidden.",
|
||||
weechat_prefix("error"),
|
||||
weechat_color("lightred"), weechat_color("reset"),
|
||||
options.proxy_host, options.proxy_port);
|
||||
weechat_prefix("error"), weechat_color("lightred"),
|
||||
weechat_color("reset"), options.proxy_host,
|
||||
options.proxy_port);
|
||||
}
|
||||
|
||||
// try loading data file
|
||||
/* try loading data file */
|
||||
char *path = twc_profile_expanded_data_path(profile);
|
||||
FILE *file = NULL;
|
||||
size_t data_size;
|
||||
|
@ -355,7 +353,8 @@ twc_profile_load(struct t_twc_profile *profile)
|
|||
if ((data_size != fread(&data, 1, data_size, file)))
|
||||
{
|
||||
fclose(file);
|
||||
weechat_printf(profile->buffer, "%scould not load Tox data file, aborting",
|
||||
weechat_printf(profile->buffer,
|
||||
"%scould not load Tox data file, aborting",
|
||||
weechat_prefix("error"));
|
||||
return TWC_RC_ERROR;
|
||||
}
|
||||
|
@ -367,15 +366,19 @@ twc_profile_load(struct t_twc_profile *profile)
|
|||
|
||||
if (data_size && tox_is_data_encrypted(data))
|
||||
{
|
||||
const 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)
|
||||
{
|
||||
// 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);
|
||||
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))
|
||||
{
|
||||
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"));
|
||||
return TWC_RC_ERROR;
|
||||
}
|
||||
|
@ -387,12 +390,13 @@ twc_profile_load(struct t_twc_profile *profile)
|
|||
{
|
||||
options.savedata_data = data;
|
||||
}
|
||||
#endif // TOXENCRYPTSAVE_ENABLED
|
||||
#endif /* TOXENCRYPTSAVE_ENABLED */
|
||||
|
||||
options.savedata_type = (data_size == 0) ? TOX_SAVEDATA_TYPE_NONE : TOX_SAVEDATA_TYPE_TOX_SAVE;
|
||||
options.savedata_type =
|
||||
(data_size == 0) ? TOX_SAVEDATA_TYPE_NONE : TOX_SAVEDATA_TYPE_TOX_SAVE;
|
||||
options.savedata_length = data_size;
|
||||
|
||||
// create Tox
|
||||
/* create Tox */
|
||||
TOX_ERR_NEW rc;
|
||||
profile->tox = tox_new(&options, &rc);
|
||||
if (rc != TOX_ERR_NEW_OK)
|
||||
|
@ -404,7 +408,7 @@ twc_profile_load(struct t_twc_profile *profile)
|
|||
|
||||
if (data_size == 0)
|
||||
{
|
||||
// no data file loaded, set default name
|
||||
/* no data file loaded, set default name */
|
||||
const char *default_name = "Tox-WeeChat User";
|
||||
|
||||
const char *name;
|
||||
|
@ -415,35 +419,35 @@ twc_profile_load(struct t_twc_profile *profile)
|
|||
name = default_name;
|
||||
|
||||
TOX_ERR_SET_INFO rc;
|
||||
tox_self_set_name(profile->tox,
|
||||
(uint8_t *)name, strlen(name),
|
||||
&rc);
|
||||
tox_self_set_name(profile->tox, (uint8_t *)name, strlen(name), &rc);
|
||||
|
||||
if (rc == TOX_ERR_SET_INFO_TOO_LONG)
|
||||
tox_self_set_name(profile->tox,
|
||||
(uint8_t *)default_name, strlen(default_name),
|
||||
NULL);
|
||||
tox_self_set_name(profile->tox, (uint8_t *)default_name,
|
||||
strlen(default_name), NULL);
|
||||
}
|
||||
|
||||
// bootstrap DHT
|
||||
// TODO: add count to config
|
||||
/* bootstrap DHT
|
||||
* TODO: add count to config */
|
||||
int bootstrap_node_count = 5;
|
||||
for (int i = 0; i < bootstrap_node_count; ++i)
|
||||
twc_bootstrap_random_node(profile->tox);
|
||||
|
||||
// start tox_iterate loop
|
||||
/* start tox_iterate loop */
|
||||
twc_do_timer_cb(profile, NULL, 0);
|
||||
|
||||
// register Tox callbacks
|
||||
/* register Tox callbacks */
|
||||
tox_callback_friend_message(profile->tox, twc_friend_message_callback);
|
||||
tox_callback_friend_connection_status(profile->tox, twc_connection_status_callback);
|
||||
tox_callback_friend_connection_status(profile->tox,
|
||||
twc_connection_status_callback);
|
||||
tox_callback_friend_name(profile->tox, twc_name_change_callback);
|
||||
tox_callback_friend_status(profile->tox, twc_user_status_callback);
|
||||
tox_callback_friend_status_message(profile->tox, twc_status_message_callback);
|
||||
tox_callback_friend_status_message(profile->tox,
|
||||
twc_status_message_callback);
|
||||
tox_callback_friend_request(profile->tox, twc_friend_request_callback);
|
||||
tox_callback_conference_invite(profile->tox, twc_group_invite_callback);
|
||||
tox_callback_conference_message(profile->tox, twc_group_message_callback);
|
||||
tox_callback_conference_namelist_change(profile->tox, twc_group_namelist_change_callback);
|
||||
tox_callback_conference_namelist_change(profile->tox,
|
||||
twc_group_namelist_change_callback);
|
||||
tox_callback_conference_title(profile->tox, twc_group_title_callback);
|
||||
return TWC_RC_OK;
|
||||
}
|
||||
|
@ -454,11 +458,11 @@ twc_profile_load(struct t_twc_profile *profile)
|
|||
void
|
||||
twc_profile_unload(struct t_twc_profile *profile)
|
||||
{
|
||||
// check that we're not already disconnected
|
||||
/* check that we're not already disconnected */
|
||||
if (!(profile->tox))
|
||||
return;
|
||||
|
||||
// save and kill tox
|
||||
/* save and kill tox */
|
||||
int result = twc_profile_save_data_file(profile);
|
||||
tox_kill(profile->tox);
|
||||
profile->tox = NULL;
|
||||
|
@ -466,19 +470,17 @@ twc_profile_unload(struct t_twc_profile *profile)
|
|||
if (result == -1)
|
||||
{
|
||||
char *path = twc_profile_expanded_data_path(profile);
|
||||
weechat_printf(NULL,
|
||||
"%s%s: Could not save Tox data for profile %s to file: %s",
|
||||
weechat_prefix("error"), weechat_plugin->name,
|
||||
profile->name,
|
||||
path);
|
||||
weechat_printf(
|
||||
NULL, "%s%s: Could not save Tox data for profile %s to file: %s",
|
||||
weechat_prefix("error"), weechat_plugin->name, profile->name, path);
|
||||
free(path);
|
||||
}
|
||||
|
||||
// stop Tox timer
|
||||
/* stop Tox timer */
|
||||
weechat_unhook(profile->tox_do_timer);
|
||||
|
||||
// have to refresh and hide bar items even if we were already offline
|
||||
// TODO
|
||||
/* have to refresh and hide bar items even if we were already offline
|
||||
* TODO */
|
||||
twc_profile_refresh_online_status(profile);
|
||||
twc_profile_set_online_status(profile, false);
|
||||
}
|
||||
|
@ -491,9 +493,10 @@ twc_profile_autoload()
|
|||
{
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(twc_profiles, index, item)
|
||||
twc_list_foreach (twc_profiles, index, item)
|
||||
{
|
||||
if (TWC_PROFILE_OPTION_BOOLEAN(item->profile, TWC_PROFILE_OPTION_AUTOLOAD))
|
||||
if (TWC_PROFILE_OPTION_BOOLEAN(item->profile,
|
||||
TWC_PROFILE_OPTION_AUTOLOAD))
|
||||
twc_profile_load(item->profile);
|
||||
}
|
||||
}
|
||||
|
@ -507,8 +510,7 @@ twc_profile_refresh_online_status(struct t_twc_profile *profile)
|
|||
}
|
||||
|
||||
void
|
||||
twc_profile_set_online_status(struct t_twc_profile *profile,
|
||||
bool status)
|
||||
twc_profile_set_online_status(struct t_twc_profile *profile, bool status)
|
||||
{
|
||||
if (profile->tox_online ^ status)
|
||||
{
|
||||
|
@ -517,18 +519,14 @@ twc_profile_set_online_status(struct t_twc_profile *profile,
|
|||
|
||||
if (profile->tox_online)
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%s%s: profile %s connected",
|
||||
weechat_prefix("network"),
|
||||
weechat_plugin->name,
|
||||
weechat_printf(profile->buffer, "%s%s: profile %s connected",
|
||||
weechat_prefix("network"), weechat_plugin->name,
|
||||
profile->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_printf(profile->buffer,
|
||||
"%s%s: profile %s disconnected",
|
||||
weechat_prefix("network"),
|
||||
weechat_plugin->name,
|
||||
weechat_printf(profile->buffer, "%s%s: profile %s disconnected",
|
||||
weechat_prefix("network"), weechat_plugin->name,
|
||||
profile->name);
|
||||
}
|
||||
}
|
||||
|
@ -542,7 +540,7 @@ twc_profile_search_name(const char *name)
|
|||
{
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(twc_profiles, index, item)
|
||||
twc_list_foreach (twc_profiles, index, item)
|
||||
{
|
||||
if (weechat_strcasecmp(item->profile->name, name) == 0)
|
||||
return item->profile;
|
||||
|
@ -559,14 +557,14 @@ twc_profile_search_buffer(struct t_gui_buffer *buffer)
|
|||
{
|
||||
size_t profile_index;
|
||||
struct t_twc_list_item *profile_item;
|
||||
twc_list_foreach(twc_profiles, profile_index, profile_item)
|
||||
twc_list_foreach (twc_profiles, profile_index, profile_item)
|
||||
{
|
||||
if (profile_item->profile->buffer == buffer)
|
||||
return profile_item->profile;
|
||||
|
||||
size_t chat_index;
|
||||
struct t_twc_list_item *chat_item;
|
||||
twc_list_foreach(profile_item->profile->chats, chat_index, chat_item)
|
||||
twc_list_foreach (profile_item->profile->chats, chat_index, chat_item)
|
||||
{
|
||||
if (chat_item->chat->buffer == buffer)
|
||||
return profile_item->profile;
|
||||
|
@ -597,22 +595,23 @@ twc_profile_set_logging(struct t_twc_profile *profile, bool logging)
|
|||
{
|
||||
error = true;
|
||||
weechat_printf(profile->buffer,
|
||||
"%swarning: failed to %s logging in this buffer!",
|
||||
weechat_prefix("error"), logging ? "enable" : "disable");
|
||||
"%swarning: failed to %s logging in this buffer!",
|
||||
weechat_prefix("error"), logging ? "enable" : "disable");
|
||||
}
|
||||
|
||||
/* signal all chat buffers for profile */
|
||||
size_t index;
|
||||
struct t_twc_list_item *item;
|
||||
twc_list_foreach(profile->chats, index, item)
|
||||
twc_list_foreach (profile->chats, index, item)
|
||||
{
|
||||
if (WEECHAT_RC_ERROR == twc_set_buffer_logging(item->chat->buffer,
|
||||
logging))
|
||||
if (WEECHAT_RC_ERROR ==
|
||||
twc_set_buffer_logging(item->chat->buffer, logging))
|
||||
{
|
||||
error = true;
|
||||
weechat_printf(item->chat->buffer,
|
||||
"%swarning: failed to %s logging in this buffer!",
|
||||
weechat_prefix("error"), logging ? "enable" : "disable");
|
||||
"%swarning: failed to %s logging in this buffer!",
|
||||
weechat_prefix("error"),
|
||||
logging ? "enable" : "disable");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -624,8 +623,7 @@ twc_profile_set_logging(struct t_twc_profile *profile, bool logging)
|
|||
* true, Tox data on disk is also deleted.
|
||||
*/
|
||||
void
|
||||
twc_profile_delete(struct t_twc_profile *profile,
|
||||
bool delete_data)
|
||||
twc_profile_delete(struct t_twc_profile *profile, bool delete_data)
|
||||
{
|
||||
char *data_path = twc_profile_expanded_data_path(profile);
|
||||
|
||||
|
@ -644,17 +642,17 @@ twc_profile_delete(struct t_twc_profile *profile,
|
|||
void
|
||||
twc_profile_free(struct t_twc_profile *profile)
|
||||
{
|
||||
// unload if needed
|
||||
/* unload if needed */
|
||||
twc_profile_unload(profile);
|
||||
|
||||
// close buffer
|
||||
/* close buffer */
|
||||
if (profile->buffer)
|
||||
{
|
||||
weechat_buffer_set_pointer(profile->buffer, "close_callback", NULL);
|
||||
weechat_buffer_close(profile->buffer);
|
||||
}
|
||||
|
||||
// free things
|
||||
/* free things */
|
||||
twc_chat_free_list(profile->chats);
|
||||
twc_friend_request_free_list(profile->friend_requests);
|
||||
twc_group_chat_invite_free_list(profile->group_chat_invites);
|
||||
|
@ -662,7 +660,7 @@ twc_profile_free(struct t_twc_profile *profile)
|
|||
free(profile->name);
|
||||
free(profile);
|
||||
|
||||
// remove from list
|
||||
/* remove from list */
|
||||
twc_list_remove_with_data(twc_profiles, profile);
|
||||
}
|
||||
|
||||
|
@ -678,4 +676,3 @@ twc_profile_free_all()
|
|||
|
||||
free(twc_profiles);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
enum t_twc_profile_option
|
||||
{
|
||||
|
@ -61,34 +61,41 @@ struct t_twc_profile
|
|||
};
|
||||
|
||||
extern struct t_twc_list *twc_profiles;
|
||||
extern struct t_config_option *twc_config_profile_default[TWC_PROFILE_NUM_OPTIONS];
|
||||
extern struct t_config_option
|
||||
*twc_config_profile_default[TWC_PROFILE_NUM_OPTIONS];
|
||||
|
||||
#define TWC_PROFILE_OPTION_BOOLEAN(profile, index) \
|
||||
(!weechat_config_option_is_null(profile->options[index]) \
|
||||
? weechat_config_boolean(profile->options[index]) \
|
||||
: (!weechat_config_option_is_null(twc_config_profile_default[index]) \
|
||||
? weechat_config_boolean(twc_config_profile_default[index]) \
|
||||
: (!weechat_config_option_default_is_null(twc_config_profile_default[index]) \
|
||||
? weechat_config_boolean_default(twc_config_profile_default[index]) \
|
||||
: 0)))
|
||||
#define TWC_PROFILE_OPTION_BOOLEAN(profile, index) \
|
||||
(!weechat_config_option_is_null(profile->options[index]) \
|
||||
? weechat_config_boolean(profile->options[index]) \
|
||||
: (!weechat_config_option_is_null(twc_config_profile_default[index]) \
|
||||
? weechat_config_boolean(twc_config_profile_default[index]) \
|
||||
: (!weechat_config_option_default_is_null( \
|
||||
twc_config_profile_default[index]) \
|
||||
? weechat_config_boolean_default( \
|
||||
twc_config_profile_default[index]) \
|
||||
: 0)))
|
||||
|
||||
#define TWC_PROFILE_OPTION_INTEGER(profile, index) \
|
||||
(!weechat_config_option_is_null(profile->options[index]) \
|
||||
? weechat_config_integer(profile->options[index]) \
|
||||
: (!weechat_config_option_is_null(twc_config_profile_default[index]) \
|
||||
? weechat_config_integer(twc_config_profile_default[index]) \
|
||||
: (!weechat_config_option_default_is_null(twc_config_profile_default[index]) \
|
||||
? weechat_config_integer_default(twc_config_profile_default[index]) \
|
||||
: 0)))
|
||||
#define TWC_PROFILE_OPTION_INTEGER(profile, index) \
|
||||
(!weechat_config_option_is_null(profile->options[index]) \
|
||||
? weechat_config_integer(profile->options[index]) \
|
||||
: (!weechat_config_option_is_null(twc_config_profile_default[index]) \
|
||||
? weechat_config_integer(twc_config_profile_default[index]) \
|
||||
: (!weechat_config_option_default_is_null( \
|
||||
twc_config_profile_default[index]) \
|
||||
? weechat_config_integer_default( \
|
||||
twc_config_profile_default[index]) \
|
||||
: 0)))
|
||||
|
||||
#define TWC_PROFILE_OPTION_STRING(profile, index) \
|
||||
(!weechat_config_option_is_null(profile->options[index]) \
|
||||
? weechat_config_string(profile->options[index]) \
|
||||
: (!weechat_config_option_is_null(twc_config_profile_default[index]) \
|
||||
? weechat_config_string(twc_config_profile_default[index]) \
|
||||
: (!weechat_config_option_default_is_null(twc_config_profile_default[index]) \
|
||||
? weechat_config_string_default(twc_config_profile_default[index]) \
|
||||
: NULL)))
|
||||
#define TWC_PROFILE_OPTION_STRING(profile, index) \
|
||||
(!weechat_config_option_is_null(profile->options[index]) \
|
||||
? weechat_config_string(profile->options[index]) \
|
||||
: (!weechat_config_option_is_null(twc_config_profile_default[index]) \
|
||||
? weechat_config_string(twc_config_profile_default[index]) \
|
||||
: (!weechat_config_option_default_is_null( \
|
||||
twc_config_profile_default[index]) \
|
||||
? weechat_config_string_default( \
|
||||
twc_config_profile_default[index]) \
|
||||
: NULL)))
|
||||
|
||||
void
|
||||
twc_profile_init();
|
||||
|
@ -132,5 +139,4 @@ twc_profile_free(struct t_twc_profile *profile);
|
|||
void
|
||||
twc_profile_free_all();
|
||||
|
||||
#endif // TOX_WEECHAT_PROFILE_H
|
||||
|
||||
#endif /* TOX_WEECHAT_PROFILE_H */
|
||||
|
|
|
@ -17,42 +17,42 @@
|
|||
* along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#ifdef TOXAV_ENABLED
|
||||
#include <tox/toxav.h>
|
||||
#endif // TOXAV_ENABLED
|
||||
#include <tox/toxav.h>
|
||||
#endif /* TOXAV_ENABLED */
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-chat.h"
|
||||
#include "twc-friend-request.h"
|
||||
#include "twc-group-invite.h"
|
||||
#include "twc-message-queue.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-utils.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-tox-callbacks.h"
|
||||
|
||||
int
|
||||
twc_do_timer_cb(const void *pointer, void *data,
|
||||
int remaining_calls)
|
||||
twc_do_timer_cb(const void *pointer, void *data, int remaining_calls)
|
||||
{
|
||||
/* TODO: don't strip the const */
|
||||
struct t_twc_profile *profile = (void *)pointer;
|
||||
|
||||
tox_iterate(profile->tox, profile);
|
||||
struct t_hook *hook = weechat_hook_timer(tox_iteration_interval(profile->tox),
|
||||
0, 1, twc_do_timer_cb, profile, NULL);
|
||||
struct t_hook *hook =
|
||||
weechat_hook_timer(tox_iteration_interval(profile->tox), 0, 1,
|
||||
twc_do_timer_cb, profile, NULL);
|
||||
profile->tox_do_timer = hook;
|
||||
|
||||
// check connection status
|
||||
/* check connection status */
|
||||
TOX_CONNECTION connection = tox_self_get_connection_status(profile->tox);
|
||||
bool is_connected = connection == TOX_CONNECTION_TCP
|
||||
|| connection == TOX_CONNECTION_UDP;
|
||||
bool is_connected =
|
||||
connection == TOX_CONNECTION_TCP || connection == TOX_CONNECTION_UDP;
|
||||
twc_profile_set_online_status(profile, is_connected);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
|
@ -60,20 +60,19 @@ twc_do_timer_cb(const void *pointer, void *data,
|
|||
|
||||
void
|
||||
twc_friend_message_callback(Tox *tox, uint32_t friend_number,
|
||||
TOX_MESSAGE_TYPE type,
|
||||
const uint8_t *message, size_t length,
|
||||
void *data)
|
||||
TOX_MESSAGE_TYPE type, const uint8_t *message,
|
||||
size_t length, void *data)
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
struct t_twc_chat *chat = twc_chat_search_friend(profile,
|
||||
friend_number,
|
||||
true);
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_friend(profile, friend_number, true);
|
||||
|
||||
char *name = twc_get_name_nt(profile->tox, friend_number);
|
||||
char *message_nt = twc_null_terminate(message, length);
|
||||
|
||||
twc_chat_print_message(chat, "notify_private", weechat_color("chat_nick_other"), name,
|
||||
message_nt, type);
|
||||
twc_chat_print_message(chat, "notify_private",
|
||||
weechat_color("chat_nick_other"), name, message_nt,
|
||||
type);
|
||||
|
||||
free(name);
|
||||
free(message_nt);
|
||||
|
@ -86,11 +85,10 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number,
|
|||
struct t_twc_profile *profile = data;
|
||||
char *name = twc_get_name_nt(profile->tox, friend_number);
|
||||
struct t_gui_nick *nick = NULL;
|
||||
struct t_twc_chat *chat = twc_chat_search_friend(profile,
|
||||
friend_number,
|
||||
false);
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_friend(profile, friend_number, false);
|
||||
|
||||
// TODO: print in friend's buffer if it exists
|
||||
/* TODO: print in friend's buffer if it exists */
|
||||
if (status == 0)
|
||||
{
|
||||
nick = weechat_nicklist_search_nick(profile->buffer,
|
||||
|
@ -98,16 +96,12 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number,
|
|||
if (nick)
|
||||
weechat_nicklist_remove_nick(profile->buffer, nick);
|
||||
|
||||
weechat_printf(profile->buffer,
|
||||
"%s%s just went offline.",
|
||||
weechat_prefix("network"),
|
||||
name);
|
||||
weechat_printf(profile->buffer, "%s%s just went offline.",
|
||||
weechat_prefix("network"), name);
|
||||
if (chat)
|
||||
{
|
||||
weechat_printf(chat->buffer,
|
||||
"%s%s just went offline.",
|
||||
weechat_prefix("network"),
|
||||
name);
|
||||
weechat_printf(chat->buffer, "%s%s just went offline.",
|
||||
weechat_prefix("network"), name);
|
||||
}
|
||||
}
|
||||
else if (status == 1)
|
||||
|
@ -115,16 +109,12 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number,
|
|||
weechat_nicklist_add_nick(profile->buffer, profile->nicklist_group,
|
||||
name, NULL, NULL, NULL, 1);
|
||||
|
||||
weechat_printf(profile->buffer,
|
||||
"%s%s just came online.",
|
||||
weechat_prefix("network"),
|
||||
name);
|
||||
weechat_printf(profile->buffer, "%s%s just came online.",
|
||||
weechat_prefix("network"), name);
|
||||
if (chat)
|
||||
{
|
||||
weechat_printf(chat->buffer,
|
||||
"%s%s just came online.",
|
||||
weechat_prefix("network"),
|
||||
name);
|
||||
weechat_printf(chat->buffer, "%s%s just came online.",
|
||||
weechat_prefix("network"), name);
|
||||
}
|
||||
twc_message_queue_flush_friend(profile, friend_number);
|
||||
}
|
||||
|
@ -132,15 +122,13 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number,
|
|||
}
|
||||
|
||||
void
|
||||
twc_name_change_callback(Tox *tox, uint32_t friend_number,
|
||||
const uint8_t *name, size_t length,
|
||||
void *data)
|
||||
twc_name_change_callback(Tox *tox, uint32_t friend_number, const uint8_t *name,
|
||||
size_t length, void *data)
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
struct t_gui_nick *nick = NULL;
|
||||
struct t_twc_chat *chat = twc_chat_search_friend(profile,
|
||||
friend_number,
|
||||
false);
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_friend(profile, friend_number, false);
|
||||
|
||||
char *old_name = twc_get_name_nt(profile->tox, friend_number);
|
||||
char *new_name = twc_null_terminate(name, length);
|
||||
|
@ -151,10 +139,8 @@ twc_name_change_callback(Tox *tox, uint32_t friend_number,
|
|||
{
|
||||
twc_chat_queue_refresh(chat);
|
||||
|
||||
weechat_printf(chat->buffer,
|
||||
"%s%s is now known as %s",
|
||||
weechat_prefix("network"),
|
||||
old_name, new_name);
|
||||
weechat_printf(chat->buffer, "%s%s is now known as %s",
|
||||
weechat_prefix("network"), old_name, new_name);
|
||||
}
|
||||
|
||||
nick = weechat_nicklist_search_nick(profile->buffer,
|
||||
|
@ -165,10 +151,8 @@ twc_name_change_callback(Tox *tox, uint32_t friend_number,
|
|||
weechat_nicklist_add_nick(profile->buffer, profile->nicklist_group,
|
||||
new_name, NULL, NULL, NULL, 1);
|
||||
|
||||
weechat_printf(profile->buffer,
|
||||
"%s%s is now known as %s",
|
||||
weechat_prefix("network"),
|
||||
old_name, new_name);
|
||||
weechat_printf(profile->buffer, "%s%s is now known as %s",
|
||||
weechat_prefix("network"), old_name, new_name);
|
||||
}
|
||||
|
||||
free(old_name);
|
||||
|
@ -180,30 +164,26 @@ twc_user_status_callback(Tox *tox, uint32_t friend_number,
|
|||
TOX_USER_STATUS status, void *data)
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
struct t_twc_chat *chat = twc_chat_search_friend(profile,
|
||||
friend_number,
|
||||
false);
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_friend(profile, friend_number, false);
|
||||
if (chat)
|
||||
twc_chat_queue_refresh(chat);
|
||||
}
|
||||
|
||||
void
|
||||
twc_status_message_callback(Tox *tox, uint32_t friend_number,
|
||||
const uint8_t *message, size_t length,
|
||||
void *data)
|
||||
const uint8_t *message, size_t length, void *data)
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
struct t_twc_chat *chat = twc_chat_search_friend(profile,
|
||||
friend_number,
|
||||
false);
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_friend(profile, friend_number, false);
|
||||
if (chat)
|
||||
twc_chat_queue_refresh(chat);
|
||||
}
|
||||
|
||||
void
|
||||
twc_friend_request_callback(Tox *tox, const uint8_t *public_key,
|
||||
const uint8_t *message, size_t length,
|
||||
void *data)
|
||||
const uint8_t *message, size_t length, void *data)
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
|
||||
|
@ -213,26 +193,28 @@ twc_friend_request_callback(Tox *tox, const uint8_t *public_key,
|
|||
if (rc == -1)
|
||||
{
|
||||
weechat_printf_date_tags(profile->buffer, 0, "notify_highlight",
|
||||
"%sReceived a friend request, but your friend request list is full!",
|
||||
weechat_prefix("warning"));
|
||||
"%sReceived a friend request, but your friend "
|
||||
"request list is full!",
|
||||
weechat_prefix("warning"));
|
||||
}
|
||||
else
|
||||
{
|
||||
char hex_address[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
||||
twc_bin2hex(public_key, TOX_PUBLIC_KEY_SIZE, hex_address);
|
||||
|
||||
weechat_printf_date_tags(profile->buffer, 0, "notify_highlight",
|
||||
"%sReceived a friend request from %s with message \"%s\"; "
|
||||
"accept it with \"/friend accept %d\"",
|
||||
weechat_prefix("network"),
|
||||
hex_address, message_nt, rc);
|
||||
weechat_printf_date_tags(
|
||||
profile->buffer, 0, "notify_highlight",
|
||||
"%sReceived a friend request from %s with message \"%s\"; "
|
||||
"accept it with \"/friend accept %d\"",
|
||||
weechat_prefix("network"), hex_address, message_nt, rc);
|
||||
|
||||
if (rc == -2)
|
||||
{
|
||||
weechat_printf_date_tags(profile->buffer, 0, "notify_highlight",
|
||||
"%sFailed to save friend request, try manually "
|
||||
"accepting with /friend add",
|
||||
weechat_prefix("error"));
|
||||
weechat_printf_date_tags(
|
||||
profile->buffer, 0, "notify_highlight",
|
||||
"%sFailed to save friend request, try manually "
|
||||
"accepting with /friend add",
|
||||
weechat_prefix("error"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,16 +222,15 @@ twc_friend_request_callback(Tox *tox, const uint8_t *public_key,
|
|||
}
|
||||
|
||||
void
|
||||
twc_group_invite_callback(Tox *tox,
|
||||
uint32_t friend_number, TOX_CONFERENCE_TYPE type,
|
||||
const uint8_t *invite_data, size_t length,
|
||||
void *data)
|
||||
twc_group_invite_callback(Tox *tox, uint32_t friend_number,
|
||||
TOX_CONFERENCE_TYPE type, const uint8_t *invite_data,
|
||||
size_t length, void *data)
|
||||
{
|
||||
TOX_ERR_CONFERENCE_JOIN err = TOX_ERR_CONFERENCE_JOIN_OK;
|
||||
struct t_twc_profile *profile = data;
|
||||
char *friend_name = twc_get_name_nt(profile->tox, friend_number);
|
||||
struct t_twc_chat *friend_chat
|
||||
= twc_chat_search_friend(profile, friend_number, false);
|
||||
struct t_twc_chat *friend_chat =
|
||||
twc_chat_search_friend(profile, friend_number, false);
|
||||
int64_t rc;
|
||||
char *tags;
|
||||
|
||||
|
@ -257,11 +238,14 @@ twc_group_invite_callback(Tox *tox,
|
|||
switch (type)
|
||||
{
|
||||
case TOX_CONFERENCE_TYPE_TEXT:
|
||||
type_str = "a text-only group chat"; break;
|
||||
type_str = "a text-only group chat";
|
||||
break;
|
||||
case TOX_CONFERENCE_TYPE_AV:
|
||||
type_str = "an audio/vikdeo group chat"; break;
|
||||
type_str = "an audio/vikdeo group chat";
|
||||
break;
|
||||
default:
|
||||
type_str = "a group chat"; break;
|
||||
type_str = "a group chat";
|
||||
break;
|
||||
}
|
||||
|
||||
if (TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_AUTOJOIN))
|
||||
|
@ -269,14 +253,13 @@ twc_group_invite_callback(Tox *tox,
|
|||
switch (type)
|
||||
{
|
||||
case TOX_CONFERENCE_TYPE_TEXT:
|
||||
rc = tox_conference_join(tox, friend_number,
|
||||
invite_data, length, &err);
|
||||
rc = tox_conference_join(tox, friend_number, invite_data,
|
||||
length, &err);
|
||||
break;
|
||||
#ifdef TOXAV_ENABLED
|
||||
case TOX_CONFERENCE_TYPE_AV:
|
||||
rc = toxav_join_av_groupchat(tox, friend_number,
|
||||
invite_data, length,
|
||||
NULL, NULL);
|
||||
rc = toxav_join_av_groupchat(tox, friend_number, invite_data,
|
||||
length, NULL, NULL);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
@ -289,38 +272,38 @@ twc_group_invite_callback(Tox *tox,
|
|||
tags = "notify_private";
|
||||
if (friend_chat)
|
||||
{
|
||||
weechat_printf_date_tags(friend_chat->buffer, 0, tags,
|
||||
"%sWe joined the %s%s%s's invite to %s.",
|
||||
weechat_prefix("network"),
|
||||
weechat_color("chat_nick_other"), friend_name,
|
||||
weechat_color("reset"), type_str);
|
||||
weechat_printf_date_tags(
|
||||
friend_chat->buffer, 0, tags,
|
||||
"%sWe joined the %s%s%s's invite to %s.",
|
||||
weechat_prefix("network"), weechat_color("chat_nick_other"),
|
||||
friend_name, weechat_color("reset"), type_str);
|
||||
tags = "";
|
||||
}
|
||||
weechat_printf_date_tags(profile->buffer, 0, tags,
|
||||
"%sWe joined the %s%s%s's invite to %s.",
|
||||
weechat_prefix("network"),
|
||||
weechat_color("chat_nick_other"), friend_name,
|
||||
weechat_color("reset"), type_str);
|
||||
weechat_printf_date_tags(
|
||||
profile->buffer, 0, tags,
|
||||
"%sWe joined the %s%s%s's invite to %s.",
|
||||
weechat_prefix("network"), weechat_color("chat_nick_other"),
|
||||
friend_name, weechat_color("reset"), type_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
tags = "notify_highlight";
|
||||
if (friend_chat)
|
||||
{
|
||||
weechat_printf_date_tags(friend_chat->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s, but we failed to "
|
||||
"process the invite. Please try again.",
|
||||
weechat_prefix("network"),
|
||||
weechat_color("chat_nick_other"), friend_name,
|
||||
weechat_color("reset"));
|
||||
weechat_printf_date_tags(
|
||||
friend_chat->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s, but we failed to "
|
||||
"process the invite. Please try again.",
|
||||
weechat_prefix("network"), weechat_color("chat_nick_other"),
|
||||
friend_name, weechat_color("reset"));
|
||||
tags = "";
|
||||
}
|
||||
weechat_printf_date_tags(profile->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s, but we failed to "
|
||||
"process the invite. Please try again.",
|
||||
weechat_prefix("network"),
|
||||
weechat_color("chat_nick_other"), friend_name,
|
||||
weechat_color("reset"));
|
||||
weechat_printf_date_tags(
|
||||
profile->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s, but we failed to "
|
||||
"process the invite. Please try again.",
|
||||
weechat_prefix("network"), weechat_color("chat_nick_other"),
|
||||
friend_name, weechat_color("reset"));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -333,59 +316,56 @@ twc_group_invite_callback(Tox *tox,
|
|||
tags = "notify_highlight";
|
||||
if (friend_chat)
|
||||
{
|
||||
weechat_printf_date_tags(friend_chat->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s. Type "
|
||||
"\"/group join %d\" to accept.",
|
||||
weechat_prefix("network"),
|
||||
weechat_color("chat_nick_other"), friend_name,
|
||||
weechat_color("reset"), type_str, rc);
|
||||
weechat_printf_date_tags(
|
||||
friend_chat->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s. Type "
|
||||
"\"/group join %d\" to accept.",
|
||||
weechat_prefix("network"), weechat_color("chat_nick_other"),
|
||||
friend_name, weechat_color("reset"), type_str, rc);
|
||||
tags = "";
|
||||
}
|
||||
weechat_printf_date_tags(profile->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s. Type "
|
||||
"\"/group join %d\" to accept.",
|
||||
weechat_prefix("network"),
|
||||
weechat_color("chat_nick_other"), friend_name,
|
||||
weechat_color("reset"), type_str, rc);
|
||||
weechat_printf_date_tags(
|
||||
profile->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s. Type "
|
||||
"\"/group join %d\" to accept.",
|
||||
weechat_prefix("network"), weechat_color("chat_nick_other"),
|
||||
friend_name, weechat_color("reset"), type_str, rc);
|
||||
}
|
||||
else
|
||||
{
|
||||
tags = "notify_highlight";
|
||||
if (friend_chat)
|
||||
{
|
||||
weechat_printf_date_tags(friend_chat->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s, but we failed to "
|
||||
"process the invite with error %d. Please try again.",
|
||||
weechat_prefix("network"),
|
||||
weechat_color("chat_nick_other"), friend_name,
|
||||
weechat_color("reset"), rc, err);
|
||||
weechat_printf_date_tags(
|
||||
friend_chat->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s, but we failed to "
|
||||
"process the invite with error %d. Please try again.",
|
||||
weechat_prefix("network"), weechat_color("chat_nick_other"),
|
||||
friend_name, weechat_color("reset"), rc, err);
|
||||
tags = "";
|
||||
}
|
||||
weechat_printf_date_tags(profile->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s, but we failed to "
|
||||
"process the invite. Please try again.",
|
||||
weechat_prefix("network"),
|
||||
weechat_color("chat_nick_other"), friend_name,
|
||||
weechat_color("reset"), rc);
|
||||
weechat_printf_date_tags(
|
||||
profile->buffer, 0, tags,
|
||||
"%s%s%s%s invites you to join %s, but we failed to "
|
||||
"process the invite. Please try again.",
|
||||
weechat_prefix("network"), weechat_color("chat_nick_other"),
|
||||
friend_name, weechat_color("reset"), rc);
|
||||
}
|
||||
}
|
||||
free(friend_name);
|
||||
}
|
||||
|
||||
void
|
||||
twc_handle_group_message(Tox *tox,
|
||||
int32_t group_number, int32_t peer_number,
|
||||
const uint8_t *message, uint16_t length,
|
||||
void *data,
|
||||
twc_handle_group_message(Tox *tox, int32_t group_number, int32_t peer_number,
|
||||
const uint8_t *message, uint16_t length, void *data,
|
||||
TOX_MESSAGE_TYPE message_type)
|
||||
{
|
||||
TOX_ERR_CONFERENCE_PEER_QUERY err = TOX_ERR_CONFERENCE_PEER_QUERY_OK;
|
||||
bool rc;
|
||||
struct t_twc_profile *profile = data;
|
||||
|
||||
struct t_twc_chat *chat = twc_chat_search_group(profile,
|
||||
group_number,
|
||||
true);
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_group(profile, group_number, true);
|
||||
|
||||
char *myname = twc_get_self_name_nt(profile->tox);
|
||||
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number);
|
||||
|
@ -393,7 +373,8 @@ twc_handle_group_message(Tox *tox,
|
|||
char *message_nt = twc_null_terminate(message, length);
|
||||
|
||||
const char *nick_color;
|
||||
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 (rc && (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK))
|
||||
nick_color = weechat_color("chat_nick_self");
|
||||
else
|
||||
|
@ -401,8 +382,8 @@ twc_handle_group_message(Tox *tox,
|
|||
|
||||
if (weechat_string_has_highlight(message_nt, myname))
|
||||
tags = "notify_highlight";
|
||||
twc_chat_print_message(chat, tags, nick_color, name,
|
||||
message_nt, message_type);
|
||||
twc_chat_print_message(chat, tags, nick_color, name, message_nt,
|
||||
message_type);
|
||||
|
||||
free(name);
|
||||
free(myname);
|
||||
|
@ -410,30 +391,23 @@ twc_handle_group_message(Tox *tox,
|
|||
}
|
||||
|
||||
void
|
||||
twc_group_message_callback(Tox *tox,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
TOX_MESSAGE_TYPE type, const uint8_t *message,
|
||||
size_t length, void *data)
|
||||
twc_group_message_callback(Tox *tox, uint32_t group_number,
|
||||
uint32_t peer_number, TOX_MESSAGE_TYPE type,
|
||||
const uint8_t *message, size_t length, void *data)
|
||||
{
|
||||
twc_handle_group_message(tox,
|
||||
group_number,
|
||||
peer_number,
|
||||
message,
|
||||
length,
|
||||
data,
|
||||
type);
|
||||
twc_handle_group_message(tox, group_number, peer_number, message, length,
|
||||
data, type);
|
||||
}
|
||||
|
||||
void
|
||||
twc_group_namelist_change_callback(Tox *tox,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
twc_group_namelist_change_callback(Tox *tox, uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
TOX_CONFERENCE_STATE_CHANGE change_type,
|
||||
void *data)
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
struct t_twc_chat *chat = twc_chat_search_group(profile,
|
||||
group_number,
|
||||
true);
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_group(profile, group_number, true);
|
||||
|
||||
struct t_gui_nick *nick = NULL;
|
||||
int i, npeers;
|
||||
|
@ -457,7 +431,7 @@ twc_group_namelist_change_callback(Tox *tox,
|
|||
else
|
||||
return;
|
||||
|
||||
// searching for exits
|
||||
/* searching for exits */
|
||||
n = weechat_list_get(chat->nicks, 0);
|
||||
|
||||
while (n)
|
||||
|
@ -468,14 +442,13 @@ twc_group_namelist_change_callback(Tox *tox,
|
|||
weechat_printf(chat->buffer, "%s%s just left the group chat",
|
||||
weechat_prefix("quit"), name);
|
||||
nick = weechat_nicklist_search_nick(chat->buffer,
|
||||
chat->nicklist_group,
|
||||
name);
|
||||
chat->nicklist_group, name);
|
||||
weechat_nicklist_remove_nick(chat->buffer, nick);
|
||||
}
|
||||
n = weechat_list_next(n);
|
||||
}
|
||||
|
||||
// searching for joins
|
||||
/* searching for joins */
|
||||
n = weechat_list_get(new_nicks, 0);
|
||||
|
||||
while (n)
|
||||
|
@ -485,8 +458,8 @@ twc_group_namelist_change_callback(Tox *tox,
|
|||
{
|
||||
weechat_printf(chat->buffer, "%s%s just joined the group chat",
|
||||
weechat_prefix("join"), name);
|
||||
weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group,
|
||||
name, NULL, NULL, NULL, 1);
|
||||
weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group, name,
|
||||
NULL, NULL, NULL, 1);
|
||||
}
|
||||
n = weechat_list_next(n);
|
||||
}
|
||||
|
@ -497,15 +470,12 @@ twc_group_namelist_change_callback(Tox *tox,
|
|||
}
|
||||
|
||||
void
|
||||
twc_group_title_callback(Tox *tox,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
const uint8_t *title, size_t length,
|
||||
void *data)
|
||||
twc_group_title_callback(Tox *tox, uint32_t group_number, uint32_t peer_number,
|
||||
const uint8_t *title, size_t length, void *data)
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
struct t_twc_chat *chat = twc_chat_search_group(profile,
|
||||
group_number,
|
||||
true);
|
||||
struct t_twc_chat *chat =
|
||||
twc_chat_search_group(profile, group_number, true);
|
||||
twc_chat_queue_refresh(chat);
|
||||
|
||||
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number);
|
||||
|
@ -518,10 +488,9 @@ twc_group_title_callback(Tox *tox,
|
|||
|
||||
#ifndef NDEBUG
|
||||
void
|
||||
twc_tox_log_callback(Tox *tox,
|
||||
TOX_LOG_LEVEL level,
|
||||
const char *file, uint32_t line, const char *func,
|
||||
const char *message, void *user_data)
|
||||
twc_tox_log_callback(Tox *tox, TOX_LOG_LEVEL level, const char *file,
|
||||
uint32_t line, const char *func, const char *message,
|
||||
void *user_data)
|
||||
{
|
||||
struct t_twc_profile *const profile = user_data;
|
||||
|
||||
|
@ -547,9 +516,8 @@ twc_tox_log_callback(Tox *tox,
|
|||
color = weechat_color("reset");
|
||||
}
|
||||
|
||||
weechat_printf(profile->buffer, "%stox\t%s%s:%"PRIu32" [%s]%s %s",
|
||||
color, weechat_color("reset"), file, line, func,
|
||||
weechat_color("lightred"), message);
|
||||
weechat_printf(profile->buffer, "%stox\t%s%s:%" PRIu32 " [%s]%s %s", color,
|
||||
weechat_color("reset"), file, line, func,
|
||||
weechat_color("lightred"), message);
|
||||
}
|
||||
#endif /* !NDEBUG */
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
#include <tox/tox.h>
|
||||
|
||||
int
|
||||
twc_do_timer_cb(const void *pointer, void *data,
|
||||
int remaining_calls);
|
||||
twc_do_timer_cb(const void *pointer, void *data, int remaining_calls);
|
||||
|
||||
void
|
||||
twc_friend_message_callback(Tox *tox, uint32_t friend_number,
|
||||
|
@ -36,9 +35,8 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number,
|
|||
TOX_CONNECTION status, void *data);
|
||||
|
||||
void
|
||||
twc_name_change_callback(Tox *tox, uint32_t friend_number,
|
||||
const uint8_t *name, size_t length,
|
||||
void *data);
|
||||
twc_name_change_callback(Tox *tox, uint32_t friend_number, const uint8_t *name,
|
||||
size_t length, void *data);
|
||||
|
||||
void
|
||||
twc_user_status_callback(Tox *tox, uint32_t friend_number,
|
||||
|
@ -46,45 +44,37 @@ twc_user_status_callback(Tox *tox, uint32_t friend_number,
|
|||
|
||||
void
|
||||
twc_status_message_callback(Tox *tox, uint32_t friend_number,
|
||||
const uint8_t *message, size_t length,
|
||||
void *data);
|
||||
const uint8_t *message, size_t length, void *data);
|
||||
|
||||
void
|
||||
twc_friend_request_callback(Tox *tox, const uint8_t *public_key,
|
||||
const uint8_t *message, size_t length,
|
||||
void *data);
|
||||
const uint8_t *message, size_t length, void *data);
|
||||
|
||||
void
|
||||
twc_group_invite_callback(Tox *tox,
|
||||
uint32_t friend_number, TOX_CONFERENCE_TYPE type,
|
||||
const uint8_t *invite_data, size_t length,
|
||||
void *data);
|
||||
twc_group_invite_callback(Tox *tox, uint32_t friend_number,
|
||||
TOX_CONFERENCE_TYPE type, const uint8_t *invite_data,
|
||||
size_t length, void *data);
|
||||
|
||||
void
|
||||
twc_group_message_callback(Tox *tox,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
TOX_MESSAGE_TYPE type, const uint8_t *message,
|
||||
size_t length, void *data);
|
||||
twc_group_message_callback(Tox *tox, uint32_t group_number,
|
||||
uint32_t peer_number, TOX_MESSAGE_TYPE type,
|
||||
const uint8_t *message, size_t length, void *data);
|
||||
|
||||
void
|
||||
twc_group_namelist_change_callback(Tox *tox,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
twc_group_namelist_change_callback(Tox *tox, uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
TOX_CONFERENCE_STATE_CHANGE change_type,
|
||||
void *data);
|
||||
|
||||
void
|
||||
twc_group_title_callback(Tox *tox,
|
||||
uint32_t group_number, uint32_t peer_number,
|
||||
const uint8_t *title, size_t length,
|
||||
void *data);
|
||||
twc_group_title_callback(Tox *tox, uint32_t group_number, uint32_t peer_number,
|
||||
const uint8_t *title, size_t length, void *data);
|
||||
|
||||
#ifndef NDEBUG
|
||||
void
|
||||
twc_tox_log_callback(Tox *tox,
|
||||
TOX_LOG_LEVEL level,
|
||||
const char *file, uint32_t line, const char *func,
|
||||
const char *message, void *user_data);
|
||||
twc_tox_log_callback(Tox *tox, TOX_LOG_LEVEL level, const char *file,
|
||||
uint32_t line, const char *func, const char *message,
|
||||
void *user_data);
|
||||
#endif /* !NDEBUG */
|
||||
|
||||
#endif // TOX_WEECHAT_TOX_CALLBACKS_H
|
||||
|
||||
#endif /* TOX_WEECHAT_TOX_CALLBACKS_H */
|
||||
|
|
|
@ -17,14 +17,14 @@
|
|||
* along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-config.h"
|
||||
#include "twc.h"
|
||||
|
||||
#include "twc-utils.h"
|
||||
|
||||
|
@ -84,9 +84,8 @@ twc_get_name_nt(Tox *tox, int32_t friend_number)
|
|||
TOX_ERR_FRIEND_QUERY err;
|
||||
size_t length = tox_friend_get_name_size(tox, friend_number, &err);
|
||||
|
||||
if ((err != TOX_ERR_FRIEND_QUERY_OK) ||
|
||||
(length == 0))
|
||||
return twc_get_friend_id_short(tox, friend_number);
|
||||
if ((err != TOX_ERR_FRIEND_QUERY_OK) || (length == 0))
|
||||
return twc_get_friend_id_short(tox, friend_number);
|
||||
|
||||
uint8_t name[length];
|
||||
|
||||
|
@ -101,13 +100,14 @@ char *
|
|||
twc_get_status_message_nt(Tox *tox, int32_t friend_number)
|
||||
{
|
||||
TOX_ERR_FRIEND_QUERY err;
|
||||
size_t length = tox_friend_get_status_message_size(tox, friend_number, &err);
|
||||
size_t length =
|
||||
tox_friend_get_status_message_size(tox, friend_number, &err);
|
||||
|
||||
if ((err != TOX_ERR_FRIEND_QUERY_OK) ||
|
||||
(length == SIZE_MAX)) {
|
||||
char *msg = malloc(1);
|
||||
*msg = 0;
|
||||
return msg;
|
||||
if ((err != TOX_ERR_FRIEND_QUERY_OK) || (length == SIZE_MAX))
|
||||
{
|
||||
char *msg = malloc(1);
|
||||
*msg = 0;
|
||||
return msg;
|
||||
}
|
||||
|
||||
uint8_t message[length];
|
||||
|
@ -123,13 +123,16 @@ twc_get_status_message_nt(Tox *tox, int32_t friend_number)
|
|||
char *
|
||||
twc_get_peer_name_nt(Tox *tox, int32_t group_number, int32_t peer_number)
|
||||
{
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH+1] = {0};
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH + 1] = {0};
|
||||
TOX_ERR_CONFERENCE_PEER_QUERY err = TOX_ERR_CONFERENCE_PEER_QUERY_OK;
|
||||
|
||||
int length = tox_conference_peer_get_name_size(tox, group_number, peer_number, &err);
|
||||
if ((err == TOX_ERR_CONFERENCE_PEER_QUERY_OK) && (length <= TOX_MAX_NAME_LENGTH))
|
||||
int length =
|
||||
tox_conference_peer_get_name_size(tox, group_number, peer_number, &err);
|
||||
if ((err == TOX_ERR_CONFERENCE_PEER_QUERY_OK) &&
|
||||
(length <= TOX_MAX_NAME_LENGTH))
|
||||
{
|
||||
tox_conference_peer_get_name(tox, group_number, peer_number, name, &err);
|
||||
tox_conference_peer_get_name(tox, group_number, peer_number, name,
|
||||
&err);
|
||||
if (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK)
|
||||
return twc_null_terminate(name, length);
|
||||
else
|
||||
|
@ -165,13 +168,11 @@ twc_get_friend_id_short(Tox *tox, int32_t friend_number)
|
|||
|
||||
tox_friend_get_public_key(tox, friend_number, client_id, &err);
|
||||
|
||||
// return a zero public key on failure
|
||||
/* return a zero public key on failure */
|
||||
if (err != TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK)
|
||||
memset(client_id, 0, TOX_PUBLIC_KEY_SIZE);
|
||||
memset(client_id, 0, TOX_PUBLIC_KEY_SIZE);
|
||||
|
||||
twc_bin2hex(client_id,
|
||||
short_id_length / 2,
|
||||
hex_address);
|
||||
twc_bin2hex(client_id, short_id_length / 2, hex_address);
|
||||
|
||||
return hex_address;
|
||||
}
|
||||
|
@ -184,9 +185,15 @@ twc_uint32_reverse_bytes(uint32_t num)
|
|||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
res += num & 0xFF; num >>= 8; res <<= 8;
|
||||
res += num & 0xFF; num >>= 8; res <<= 8;
|
||||
res += num & 0xFF; num >>= 8; res <<= 8;
|
||||
res += num & 0xFF;
|
||||
num >>= 8;
|
||||
res <<= 8;
|
||||
res += num & 0xFF;
|
||||
num >>= 8;
|
||||
res <<= 8;
|
||||
res += num & 0xFF;
|
||||
num >>= 8;
|
||||
res <<= 8;
|
||||
res += num & 0xFF;
|
||||
|
||||
return res;
|
||||
|
@ -222,6 +229,6 @@ twc_set_buffer_logging(struct t_gui_buffer *buffer, bool logging)
|
|||
signal = "logger_stop";
|
||||
}
|
||||
|
||||
return weechat_hook_signal_send(signal,
|
||||
WEECHAT_HOOK_SIGNAL_POINTER, buffer);
|
||||
return weechat_hook_signal_send(signal, WEECHAT_HOOK_SIGNAL_POINTER,
|
||||
buffer);
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
void
|
||||
twc_hex2bin(const char *hex, size_t size, uint8_t *out);
|
||||
|
@ -58,5 +58,4 @@ twc_fit_utf8(const char *str, int max);
|
|||
int
|
||||
twc_set_buffer_logging(struct t_gui_buffer *buffer, bool logging);
|
||||
|
||||
#endif // TOX_WEECHAT_UTILS_H
|
||||
|
||||
#endif /* TOX_WEECHAT_UTILS_H */
|
||||
|
|
11
src/twc.c
11
src/twc.c
|
@ -21,11 +21,11 @@
|
|||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "twc-profile.h"
|
||||
#include "twc-commands.h"
|
||||
#include "twc-gui.h"
|
||||
#include "twc-config.h"
|
||||
#include "twc-completion.h"
|
||||
#include "twc-config.h"
|
||||
#include "twc-gui.h"
|
||||
#include "twc-profile.h"
|
||||
|
||||
#include "twc.h"
|
||||
|
||||
|
@ -53,8 +53,8 @@ weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
|
|||
bool no_autoconnect = false;
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
if (weechat_strcasecmp(argv[i], "-a") == 0
|
||||
|| weechat_strcasecmp(argv[i], "--no-connect") == 0)
|
||||
if (weechat_strcasecmp(argv[i], "-a") == 0 ||
|
||||
weechat_strcasecmp(argv[i], "--no-connect") == 0)
|
||||
{
|
||||
no_autoconnect = true;
|
||||
}
|
||||
|
@ -74,4 +74,3 @@ weechat_plugin_end(struct t_weechat_plugin *plugin)
|
|||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
|
|
13
src/twc.h
13
src/twc.h
|
@ -22,18 +22,17 @@
|
|||
|
||||
extern struct t_weechat_plugin *weechat_plugin;
|
||||
|
||||
/// Return codes used throughout Tox-WeeChat.
|
||||
/** Return codes used throughout Tox-WeeChat. */
|
||||
enum t_twc_rc
|
||||
{
|
||||
TWC_RC_OK = 0,
|
||||
/// Generic error return code.
|
||||
/* Generic error return code. */
|
||||
TWC_RC_ERROR = -1,
|
||||
/// Malloc error return code.
|
||||
/* Malloc error return code. */
|
||||
TWC_RC_ERROR_MALLOC = -2,
|
||||
};
|
||||
|
||||
#define TWC_MAX_FRIEND_MESSAGE_LENGTH (TOX_MAX_MESSAGE_LENGTH-1)
|
||||
#define TWC_MAX_GROUP_MESSAGE_LENGTH (TOX_MAX_MESSAGE_LENGTH-16)
|
||||
|
||||
#endif // TOX_WEECHAT_H
|
||||
#define TWC_MAX_FRIEND_MESSAGE_LENGTH (TOX_MAX_MESSAGE_LENGTH - 1)
|
||||
#define TWC_MAX_GROUP_MESSAGE_LENGTH (TOX_MAX_MESSAGE_LENGTH - 16)
|
||||
|
||||
#endif /* TOX_WEECHAT_H */
|
||||
|
|
Loading…
Reference in a new issue