diff --git a/src/twc-bootstrap.c b/src/twc-bootstrap.c index 1ec8a12..f1d438f 100644 --- a/src/twc-bootstrap.c +++ b/src/twc-bootstrap.c @@ -68,8 +68,8 @@ int twc_bootstrap_tox(Tox *tox, const char *address, uint16_t port, const char *public_key) { - uint8_t binary_key[TOX_FRIEND_ADDRESS_SIZE]; - twc_hex2bin(public_key, TOX_FRIEND_ADDRESS_SIZE, binary_key); + uint8_t binary_key[TOX_ADDRESS_SIZE]; + twc_hex2bin(public_key, TOX_ADDRESS_SIZE, binary_key); int result = tox_bootstrap_from_address(tox, address, port, binary_key); diff --git a/src/twc-chat.c b/src/twc-chat.c index dbe4d28..574842f 100644 --- a/src/twc-chat.c +++ b/src/twc-chat.c @@ -59,7 +59,7 @@ int twc_tox_id_compare_callback(struct t_hashtable *hashtable, const void *id1, const void *id2) { - return memcmp(id1, id2, TOX_CLIENT_ID_SIZE); + return memcmp(id1, id2, TOX_PUBLIC_KEY_SIZE); } /** @@ -102,11 +102,11 @@ twc_chat_new(struct t_twc_profile *profile, const char *name) struct t_twc_chat * twc_chat_new_friend(struct t_twc_profile *profile, int32_t friend_number) { - uint8_t client_id[TOX_CLIENT_ID_SIZE]; + uint8_t client_id[TOX_PUBLIC_KEY_SIZE]; tox_get_client_id(profile->tox, friend_number, client_id); - char buffer_name[TOX_CLIENT_ID_SIZE * 2 + 1]; - twc_bin2hex(client_id, TOX_CLIENT_ID_SIZE, buffer_name); + char buffer_name[TOX_PUBLIC_KEY_SIZE * 2 + 1]; + twc_bin2hex(client_id, TOX_PUBLIC_KEY_SIZE, buffer_name); struct t_twc_chat *chat = twc_chat_new(profile, buffer_name); if (chat) diff --git a/src/twc-commands.c b/src/twc-commands.c index f5ac341..a9169cc 100644 --- a/src/twc-commands.c +++ b/src/twc-commands.c @@ -157,13 +157,13 @@ twc_match_friend(struct t_twc_profile *profile, const char *search_string) size_t search_size = strlen(search_string); for (uint32_t i = 0; i < friend_count; ++i) { - if (search_size == TOX_CLIENT_ID_SIZE * 2) + if (search_size == TOX_PUBLIC_KEY_SIZE * 2) { - uint8_t tox_id[TOX_CLIENT_ID_SIZE]; - char hex_id[TOX_CLIENT_ID_SIZE * 2 + 1]; + uint8_t tox_id[TOX_PUBLIC_KEY_SIZE]; + char hex_id[TOX_PUBLIC_KEY_SIZE * 2 + 1]; tox_get_client_id(profile->tox, friend_numbers[i], tox_id); - twc_bin2hex(tox_id, TOX_CLIENT_ID_SIZE, hex_id); + twc_bin2hex(tox_id, TOX_PUBLIC_KEY_SIZE, hex_id); if (weechat_strcasecmp(hex_id, search_string) == 0) return friend_numbers[i]; @@ -284,7 +284,7 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer, if (!message) message = weechat_config_string(twc_config_friend_request_message); - if (strlen(hex_id) != TOX_FRIEND_ADDRESS_SIZE * 2) + if (strlen(hex_id) != TOX_ADDRESS_SIZE * 2) { weechat_printf(profile->buffer, "%sTox ID length invalid. Please try again.", @@ -293,13 +293,13 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer, return WEECHAT_RC_OK; } - uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; - twc_hex2bin(hex_id, TOX_FRIEND_ADDRESS_SIZE, address); + uint8_t address[TOX_ADDRESS_SIZE]; + twc_hex2bin(hex_id, TOX_ADDRESS_SIZE, address); if (force) { bool fail = false; - char *hex_key = strndup(hex_id, TOX_CLIENT_ID_SIZE * 2); + char *hex_key = strndup(hex_id, TOX_PUBLIC_KEY_SIZE * 2); int32_t friend_number = twc_match_friend(profile, hex_key); free(hex_key); @@ -318,50 +318,52 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer, } } - int32_t result = tox_add_friend(profile->tox, - (uint8_t *)address, - (uint8_t *)message, - strlen(message)); + TOX_ERR_FRIEND_ADD result = tox_add_friend(profile->tox, + (uint8_t *)address, + (uint8_t *)message, + strlen(message)); switch (result) { - case TOX_FAERR_TOOLONG: + case TOX_ERR_FRIEND_ADD_OK: + weechat_printf(profile->buffer, + "%sFriend request sent!", + weechat_prefix("network")); + break; + case TOX_ERR_FRIEND_ADD_TOO_LONG: weechat_printf(profile->buffer, "%sFriend request message too long! Try again.", weechat_prefix("error")); break; - case TOX_FAERR_ALREADYSENT: + case TOX_ERR_FRIEND_ADD_ALREADY_SENT: + case TOX_ERR_FRIEND_ADD_SET_NEW_NOSPAM: weechat_printf(profile->buffer, "%sYou have already sent a friend request to " "that address (use -force to circumvent)", weechat_prefix("error")); break; - case TOX_FAERR_OWNKEY: + case TOX_ERR_FRIEND_ADD_OWN_KEY: weechat_printf(profile->buffer, "%sYou can't add yourself as a friend.", weechat_prefix("error")); break; - case TOX_FAERR_BADCHECKSUM: + case TOX_ERR_FRIEND_ADD_BAD_CHECKSUM: weechat_printf(profile->buffer, "%sInvalid friend address - try again.", weechat_prefix("error")); break; - case TOX_FAERR_NOMEM: + case TOX_ERR_FRIEND_ADD_MALLOC: weechat_printf(profile->buffer, "%sCould not add friend (out of memory).", weechat_prefix("error")); break; - case TOX_FAERR_UNKNOWN: - case TOX_FAERR_SETNEWNOSPAM: - case TOX_FAERR_NOMESSAGE: - weechat_printf(profile->buffer, - "%sCould not add friend (unknown error).", - weechat_prefix("error")); - break; + case TOX_ERR_FRIEND_ADD_NULL: + case TOX_ERR_FRIEND_ADD_NO_MESSAGE: /* this should not happen as we + validate the message */ default: weechat_printf(profile->buffer, - "%sFriend request sent!", - weechat_prefix("network")); + "%sCould not add friend (unknown error %d).", + weechat_prefix("error"), result); break; } @@ -433,9 +435,9 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer, return WEECHAT_RC_OK; } - char hex_address[TOX_CLIENT_ID_SIZE * 2 + 1]; + char hex_address[TOX_PUBLIC_KEY_SIZE * 2 + 1]; twc_bin2hex(request->tox_id, - TOX_CLIENT_ID_SIZE, + TOX_PUBLIC_KEY_SIZE, hex_address); if (accept) @@ -690,11 +692,11 @@ twc_cmd_myid(void *data, struct t_gui_buffer *buffer, TWC_CHECK_PROFILE(profile); TWC_CHECK_PROFILE_LOADED(profile); - uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; + uint8_t address[TOX_ADDRESS_SIZE]; tox_get_address(profile->tox, address); - char address_str[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; - twc_bin2hex(address, TOX_FRIEND_ADDRESS_SIZE, address_str); + char address_str[TOX_ADDRESS_SIZE * 2 + 1]; + twc_bin2hex(address, TOX_ADDRESS_SIZE, address_str); weechat_printf(profile->buffer, "%sYour Tox address: %s", @@ -875,15 +877,14 @@ twc_cmd_status(void *data, struct t_gui_buffer *buffer, TWC_CHECK_PROFILE(profile); TWC_CHECK_PROFILE_LOADED(profile); - TOX_USERSTATUS status = TOX_USERSTATUS_INVALID; + TOX_USER_STATUS status; if (weechat_strcasecmp(argv[1], "online") == 0) - status = TOX_USERSTATUS_NONE; + status = TOX_USER_STATUS_NONE; else if (weechat_strcasecmp(argv[1], "busy") == 0) - status = TOX_USERSTATUS_BUSY; + status = TOX_USER_STATUS_BUSY; else if (weechat_strcasecmp(argv[1], "away") == 0) - status = TOX_USERSTATUS_AWAY; - - if (status == TOX_USERSTATUS_INVALID) + status = TOX_USER_STATUS_AWAY; + else return WEECHAT_RC_ERROR; tox_set_user_status(profile->tox, status); diff --git a/src/twc-completion.c b/src/twc-completion.c index f6ef3f6..b351204 100644 --- a/src/twc-completion.c +++ b/src/twc-completion.c @@ -65,11 +65,11 @@ twc_completion_friend(void *data, { if (flags & TWC_COMPLETE_FRIEND_ID) { - uint8_t tox_id[TOX_CLIENT_ID_SIZE]; - char hex_id[TOX_CLIENT_ID_SIZE * 2 + 1]; + uint8_t tox_id[TOX_PUBLIC_KEY_SIZE]; + char hex_id[TOX_PUBLIC_KEY_SIZE * 2 + 1]; tox_get_client_id(profile->tox, friend_numbers[i], tox_id); - twc_bin2hex(tox_id, TOX_CLIENT_ID_SIZE, hex_id); + twc_bin2hex(tox_id, TOX_PUBLIC_KEY_SIZE, hex_id); weechat_hook_completion_list_add(completion, hex_id, 0, WEECHAT_LIST_POS_SORT); diff --git a/src/twc-config.c b/src/twc-config.c index 031821d..0d7e3f6 100644 --- a/src/twc-config.c +++ b/src/twc-config.c @@ -309,7 +309,7 @@ twc_config_init() 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_CLIENT_ID_SIZE * 2, + NULL, 2, TOX_PUBLIC_KEY_SIZE * 2, "8", NULL, 0, twc_config_check_value_callback, NULL, NULL, NULL, NULL, NULL); diff --git a/src/twc-dns.c b/src/twc-dns.c index fbde918..fb9f132 100644 --- a/src/twc-dns.c +++ b/src/twc-dns.c @@ -52,16 +52,16 @@ twc_dns_fd_callback(void *data, int fd) { struct t_twc_dns_callback_info *callback_info = data; - char buffer[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; + char buffer[TOX_ADDRESS_SIZE * 2 + 1]; ssize_t size = read(fd, buffer, sizeof(buffer) - 1); buffer[size] = '\0'; if (size > 0) { - if (size == TOX_FRIEND_ADDRESS_SIZE * 2) + if (size == TOX_ADDRESS_SIZE * 2) { - uint8_t tox_id[TOX_FRIEND_ADDRESS_SIZE]; - twc_hex2bin(buffer, TOX_FRIEND_ADDRESS_SIZE, tox_id); + uint8_t tox_id[TOX_ADDRESS_SIZE]; + twc_hex2bin(buffer, TOX_ADDRESS_SIZE, tox_id); callback_info->callback(callback_info->data, TWC_DNS_RC_OK, tox_id); diff --git a/src/twc-friend-request.c b/src/twc-friend-request.c index 77b3476..0bcd896 100644 --- a/src/twc-friend-request.c +++ b/src/twc-friend-request.c @@ -53,7 +53,7 @@ twc_friend_request_add(struct t_twc_profile *profile, request->profile = profile; request->message = strdup(message); - memcpy(request->tox_id, client_id, TOX_CLIENT_ID_SIZE); + memcpy(request->tox_id, client_id, TOX_PUBLIC_KEY_SIZE); if (!twc_list_item_new_data_add(profile->friend_requests, request)) return -2; diff --git a/src/twc-friend-request.h b/src/twc-friend-request.h index 3986080..2470535 100644 --- a/src/twc-friend-request.h +++ b/src/twc-friend-request.h @@ -31,7 +31,7 @@ struct t_twc_friend_request { struct t_twc_profile *profile; - uint8_t tox_id[TOX_CLIENT_ID_SIZE]; + uint8_t tox_id[TOX_PUBLIC_KEY_SIZE]; char *message; }; diff --git a/src/twc-gui.c b/src/twc-gui.c index 0108a1e..e8e1639 100644 --- a/src/twc-gui.c +++ b/src/twc-gui.c @@ -43,10 +43,10 @@ twc_bar_item_away(void *data, char *status = NULL;; switch (tox_get_self_user_status(profile->tox)) { - case TOX_USERSTATUS_BUSY: + case TOX_USER_STATUS_BUSY: status = strdup("busy"); break; - case TOX_USERSTATUS_AWAY: + case TOX_USER_STATUS_AWAY: status = strdup("away"); break; } diff --git a/src/twc-tox-callbacks.c b/src/twc-tox-callbacks.c index 2748dbd..907fdff 100644 --- a/src/twc-tox-callbacks.c +++ b/src/twc-tox-callbacks.c @@ -198,8 +198,8 @@ twc_friend_request_callback(Tox *tox, const uint8_t *public_key, } else { - char hex_address[TOX_CLIENT_ID_SIZE * 2 + 1]; - twc_bin2hex(public_key, TOX_CLIENT_ID_SIZE, hex_address); + char hex_address[TOX_PUBLIC_KEY_SIZE * 2 + 1]; + twc_bin2hex(public_key, TOX_PUBLIC_KEY_SIZE, hex_address); weechat_printf(profile->buffer, "%sReceived a friend request from %s with message \"%s\"; " @@ -328,7 +328,7 @@ twc_group_namelist_change_callback(Tox *tox, char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number); char *prev_name = NULL; - uint8_t pubkey[TOX_CLIENT_ID_SIZE]; + uint8_t pubkey[TOX_PUBLIC_KEY_SIZE]; int pkrc = tox_group_peer_pubkey(profile->tox, group_number, peer_number, pubkey); if (pkrc == 0) @@ -353,7 +353,7 @@ twc_group_namelist_change_callback(Tox *tox, name, NULL, NULL, NULL, 1); if (nick) weechat_hashtable_set_with_size(chat->nicks, - pubkey, TOX_CLIENT_ID_SIZE, + pubkey, TOX_PUBLIC_KEY_SIZE, nick, 0); } } diff --git a/src/twc-utils.c b/src/twc-utils.c index 7039e06..f7f65b3 100644 --- a/src/twc-utils.c +++ b/src/twc-utils.c @@ -140,7 +140,7 @@ twc_get_self_name_nt(Tox *tox) char * twc_get_friend_id_short(Tox *tox, int32_t friend_number) { - uint8_t client_id[TOX_CLIENT_ID_SIZE]; + uint8_t client_id[TOX_PUBLIC_KEY_SIZE]; tox_get_client_id(tox, friend_number, client_id); size_t short_id_length = weechat_config_integer(twc_config_short_id_size); @@ -170,7 +170,7 @@ twc_uint32_reverse_bytes(uint32_t num) } /** - * Hash a Tox ID of size TOX_CLIENT_ID_SIZE bytes using a modified djb2 hash. + * Hash a Tox ID of size TOX_PUBLIC_KEY_SIZE bytes using a modified djb2 hash. */ unsigned long long twc_hash_tox_id(const uint8_t *tox_id)