From f1f8a71bd4df7f239e28a9625b82ee02428c3f3f Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 3 Jan 2015 08:12:27 +0000 Subject: Tox: work commit - removed *.lib and lib generator - disabled profile encryption and import - loading tox profile on connection - project reordering - http proxy support git-svn-id: http://svn.miranda-ng.org/main/trunk@11730 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/api_avatars.cpp | 48 +++ protocols/Tox/src/api_connection.cpp | 28 ++ protocols/Tox/src/api_dns.cpp | 23 ++ protocols/Tox/src/api_encryption.cpp | 88 ++++++ protocols/Tox/src/api_groupchats.cpp | 88 ++++++ protocols/Tox/src/api_main.cpp | 252 ++++++++++++++++ protocols/Tox/src/api_transfer.cpp | 43 +++ protocols/Tox/src/tox_account.cpp | 100 +++---- protocols/Tox/src/tox_accounts.cpp | 14 +- protocols/Tox/src/tox_api.cpp | 561 ----------------------------------- protocols/Tox/src/tox_avatars.cpp | 37 ++- protocols/Tox/src/tox_events.cpp | 12 +- protocols/Tox/src/tox_options.cpp | 30 +- protocols/Tox/src/tox_profile.cpp | 56 ++-- protocols/Tox/src/tox_proto.cpp | 9 +- protocols/Tox/src/tox_proto.h | 3 +- protocols/Tox/src/tox_utils.cpp | 2 +- 17 files changed, 712 insertions(+), 682 deletions(-) create mode 100644 protocols/Tox/src/api_avatars.cpp create mode 100644 protocols/Tox/src/api_connection.cpp create mode 100644 protocols/Tox/src/api_dns.cpp create mode 100644 protocols/Tox/src/api_encryption.cpp create mode 100644 protocols/Tox/src/api_groupchats.cpp create mode 100644 protocols/Tox/src/api_main.cpp create mode 100644 protocols/Tox/src/api_transfer.cpp delete mode 100644 protocols/Tox/src/tox_api.cpp (limited to 'protocols/Tox/src') diff --git a/protocols/Tox/src/api_avatars.cpp b/protocols/Tox/src/api_avatars.cpp new file mode 100644 index 0000000000..5b5aa0c487 --- /dev/null +++ b/protocols/Tox/src/api_avatars.cpp @@ -0,0 +1,48 @@ +#include "common.h" + +/* AVATAR FUNCTIONS */ + +void tox_callback_avatar_info(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, uint8_t *, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_avatar_data(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, uint8_t *, uint8_t *, uint32_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length) +{ + return CreateFunction(__FUNCTION__)(tox, format, data, length); +} + +int tox_unset_avatar(Tox *tox) +{ + return CreateFunction(__FUNCTION__)(tox); +} + +int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash) +{ + return CreateFunction(__FUNCTION__)(tox, format, buf, length, maxlen, hash); +} + +int tox_hash(uint8_t *hash, const uint8_t *data, const uint32_t datalen) +{ + return CreateFunction(__FUNCTION__)(hash, data, datalen); +} + +int tox_request_avatar_info(const Tox *tox, const int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +int tox_send_avatar_info(Tox *tox, const int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +int tox_request_avatar_data(const Tox *tox, const int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} \ No newline at end of file diff --git a/protocols/Tox/src/api_connection.cpp b/protocols/Tox/src/api_connection.cpp new file mode 100644 index 0000000000..3b3ffb4143 --- /dev/null +++ b/protocols/Tox/src/api_connection.cpp @@ -0,0 +1,28 @@ +#include "common.h" + +/* CONNECTION FUNCTIONS */ + +int tox_bootstrap_from_address(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key) +{ + return CreateFunction(__FUNCTION__)(tox, address, port, public_key); +} + +int tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key) +{ + return CreateFunction(__FUNCTION__)(tox, address, port, public_key); +} + +int tox_isconnected(const Tox *tox) +{ + return CreateFunction(__FUNCTION__)(tox); +} + +uint32_t tox_do_interval(Tox *tox) +{ + return CreateFunction(__FUNCTION__)(tox); +} + +void tox_do(Tox *tox) +{ + CreateFunction(__FUNCTION__)(tox); +} \ No newline at end of file diff --git a/protocols/Tox/src/api_dns.cpp b/protocols/Tox/src/api_dns.cpp new file mode 100644 index 0000000000..3b4e601d9a --- /dev/null +++ b/protocols/Tox/src/api_dns.cpp @@ -0,0 +1,23 @@ +#include "common.h" + +/* DNS TOXID RESOILVING FUNCTIONS */ + +void *tox_dns3_new(uint8_t *server_public_key) +{ + return CreateFunction(__FUNCTION__)(server_public_key); +} + +void tox_dns3_kill(void *dns3_object) +{ + CreateFunction(__FUNCTION__)(dns3_object); +} + +int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id, uint8_t *name, uint8_t name_len) +{ + return CreateFunction(__FUNCTION__)(dns3_object, string, string_max_len, request_id, name, name_len); +} + +int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len, uint32_t request_id) +{ + return CreateFunction(__FUNCTION__)(dns3_object, tox_id, id_record, id_record_len, request_id); +} \ No newline at end of file diff --git a/protocols/Tox/src/api_encryption.cpp b/protocols/Tox/src/api_encryption.cpp new file mode 100644 index 0000000000..7125743096 --- /dev/null +++ b/protocols/Tox/src/api_encryption.cpp @@ -0,0 +1,88 @@ +#include "common.h" + +/* ENCRYPTION FUNCTIONS */ + +int tox_pass_encryption_extra_length() +{ + return CreateFunction(__FUNCTION__)(); +} + +int tox_pass_key_length() +{ + return CreateFunction(__FUNCTION__)(); +} + +int tox_pass_salt_length() +{ + return CreateFunction(__FUNCTION__)(); +} + +uint32_t tox_encrypted_size(const Tox *tox) +{ + return CreateFunction(__FUNCTION__)(tox); +} + +int tox_pass_encrypt(const uint8_t *data, uint32_t data_len, uint8_t *passphrase, uint32_t pplength, uint8_t *out) +{ + return CreateFunction(__FUNCTION__)(data, data_len, passphrase, pplength, out); +} + +int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint32_t pplength) +{ + return CreateFunction(__FUNCTION__)(tox, data, passphrase, pplength); +} + +int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out) +{ + return CreateFunction(__FUNCTION__)(data, length, passphrase, pplength, out); +} + +int tox_encrypted_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength) +{ + return CreateFunction(__FUNCTION__)(tox, data, length, passphrase, pplength); +} + +int tox_derive_key_from_pass(uint8_t *passphrase, uint32_t pplength, uint8_t *out_key) +{ + return CreateFunction(__FUNCTION__)(passphrase, pplength, out_key); +} + +int tox_derive_key_with_salt(uint8_t *passphrase, uint32_t pplength, uint8_t *salt, uint8_t *out_key) +{ + return CreateFunction(__FUNCTION__)(passphrase, pplength, salt, out_key); +} + +int tox_get_salt(uint8_t *data, uint8_t *salt) +{ + return CreateFunction(__FUNCTION__)(data, salt); +} + +int tox_pass_key_encrypt(const uint8_t *data, uint32_t data_len, const uint8_t *key, uint8_t *out) +{ + return CreateFunction(__FUNCTION__)(data, data_len, key, out); +} + +int tox_encrypted_key_save(const Tox *tox, uint8_t *data, uint8_t *key) +{ + return CreateFunction(__FUNCTION__)(tox, data, key); +} + +int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *key, uint8_t *out) +{ + return CreateFunction(__FUNCTION__)(data, length, key, out); +} + +int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *key) +{ + return CreateFunction(__FUNCTION__)(tox, data, length, key); +} + +int tox_is_data_encrypted(const uint8_t *data) +{ + return CreateFunction(__FUNCTION__)(data); +} + +int tox_is_save_encrypted(const uint8_t *data) +{ + return CreateFunction(__FUNCTION__)(data); +} \ No newline at end of file diff --git a/protocols/Tox/src/api_groupchats.cpp b/protocols/Tox/src/api_groupchats.cpp new file mode 100644 index 0000000000..8f49b8f421 --- /dev/null +++ b/protocols/Tox/src/api_groupchats.cpp @@ -0,0 +1,88 @@ +#include "common.h" + +/* GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change */ +/* +void tox_callback_group_invite(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, const uint8_t *, uint16_t, void *), void *userdata) +{ +} + +void tox_callback_group_message(Tox *tox, void(*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *), void *userdata) +{ +} + +void tox_callback_group_action(Tox *tox, void(*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *), void *userdata) +{ +} + +void tox_callback_group_title(Tox *tox, void(*function)(Tox *tox, int, int, const uint8_t *, uint8_t, void *), void *userdata) +{ +} + +void tox_callback_group_namelist_change(Tox *tox, void(*function)(Tox *tox, int, int, uint8_t, void *), void *userdata) +{ +} + +int tox_add_groupchat(Tox *tox) +{ +} + +int tox_del_groupchat(Tox *tox, int groupnumber) +{ +} + +int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name) +{ +} + +int tox_group_peer_pubkey(const Tox *tox, int groupnumber, int peernumber, uint8_t *pk) +{ +} + +int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) +{ +} + +int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length) +{ +} + +int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint16_t length) +{ +} + +int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length) +{ +} + +int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length) +{ +} + +int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title, uint32_t max_length) +{ +} + +unsigned int tox_group_peernumber_is_ours(const Tox *tox, int groupnumber, int peernumber) +{ +} + +int tox_group_number_peers(const Tox *tox, int groupnumber) +{ +} + +int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], uint16_t length) +{ +} + +uint32_t tox_count_chatlist(const Tox *tox) +{ +} + +uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size) +{ +} + +int tox_group_get_type(const Tox *tox, int groupnumber) +{ +} +*/ \ No newline at end of file diff --git a/protocols/Tox/src/api_main.cpp b/protocols/Tox/src/api_main.cpp new file mode 100644 index 0000000000..fc23165d44 --- /dev/null +++ b/protocols/Tox/src/api_main.cpp @@ -0,0 +1,252 @@ +#include "common.h" + +/* MAIN FUNCTIONS */ + +Tox *tox_new(Tox_Options *options) +{ + return CreateFunction(__FUNCTION__)(options); +} + +void tox_kill(Tox *tox) +{ + CreateFunction(__FUNCTION__)(tox); + tox = NULL; +} + +void tox_get_address(const Tox *tox, uint8_t *address) +{ + CreateFunction(__FUNCTION__)(tox, address); +} + +int32_t tox_add_friend(Tox *tox,const uint8_t *address, const uint8_t *data, uint16_t length) +{ + return CreateFunction(__FUNCTION__)(tox, address, data, length); +} + +int32_t tox_add_friend_norequest(Tox *tox, const uint8_t *client_id) +{ + return CreateFunction(__FUNCTION__)(tox, client_id); +} + +int32_t tox_get_friend_number(const Tox *tox, const uint8_t *client_id) +{ + return CreateFunction(__FUNCTION__)(tox, client_id); +} + +int tox_get_client_id(const Tox *tox, int32_t friendnumber, uint8_t *client_id) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber, client_id); +} + +int tox_del_friend(Tox *tox, int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +int tox_get_friend_connection_status(const Tox *tox, int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +int tox_friend_exists(const Tox *tox, int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +uint32_t tox_send_message(Tox *tox, int32_t friendnumber, const uint8_t *message, uint32_t length) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber, message, length); +} + +uint32_t tox_send_action(Tox *tox, int32_t friendnumber, const uint8_t *action, uint32_t length) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber, action, length); +} + +int tox_set_name(Tox *tox, const uint8_t *name, uint16_t length) +{ + return CreateFunction(__FUNCTION__ )(tox, name, length); +} + +uint16_t tox_get_self_name(const Tox *tox, uint8_t *name) +{ + return CreateFunction(__FUNCTION__)(tox, name); +} + +int tox_get_name(const Tox *tox, int32_t friendnumber, uint8_t *name) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber, name); +} + +int tox_get_name_size(const Tox *tox, int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +int tox_get_self_name_size(const Tox *tox) +{ + return CreateFunction(__FUNCTION__)(tox); +} + +int tox_set_status_message(Tox *tox, const uint8_t *status, uint16_t length) +{ + return CreateFunction(__FUNCTION__)(tox, status, length); +} + +int tox_set_user_status(Tox *tox, uint8_t userstatus) +{ + return CreateFunction(__FUNCTION__)(tox, userstatus); +} + +int tox_get_status_message_size(const Tox *tox, int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +int tox_get_self_status_message_size(const Tox *tox) +{ + return CreateFunction(__FUNCTION__)(tox); +} + +int tox_get_status_message(const Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber, buf, maxlen); +} + +int tox_get_self_status_message(const Tox *tox, uint8_t *buf, uint32_t maxlen) +{ + return CreateFunction(__FUNCTION__)(tox, buf, maxlen); +} + +uint8_t tox_get_user_status(const Tox *tox, int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +uint8_t tox_get_self_user_status(const Tox *tox) +{ + return CreateFunction(__FUNCTION__)(tox); +} + +uint64_t tox_get_last_online(const Tox *tox, int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +int tox_set_user_is_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber, is_typing); +} + +uint8_t tox_get_is_typing(const Tox *tox, int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +uint32_t tox_count_friendlist(const Tox *tox) +{ + return CreateFunction(__FUNCTION__)(tox); +} + +uint32_t tox_get_num_online_friends(const Tox *tox) +{ + return CreateFunction(__FUNCTION__)(tox); +} + +uint32_t tox_get_friendlist(const Tox *tox, int32_t *out_list, uint32_t list_size) +{ + return CreateFunction(__FUNCTION__)(tox, out_list, list_size); +} + +void tox_callback_friend_request(Tox *tox, void(*function)(Tox *tox, const uint8_t *, const uint8_t *, uint16_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_friend_message(Tox *tox, void(*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_friend_action(Tox *tox, void(*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_name_change(Tox *tox, void(*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_status_message(Tox *tox, void(*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_user_status(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_typing_change(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_read_receipt(Tox *tox, void(*function)(Tox *tox, int32_t, uint32_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_connection_status(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +/* SAVING AND LOADING FUNCTIONS */ + +uint32_t tox_size(const Tox *tox) +{ + return CreateFunction(__FUNCTION__)(tox); +} + +void tox_save(const Tox *tox, uint8_t *data) +{ + CreateFunction(__FUNCTION__)(tox, data); +} + +int tox_load(Tox *tox, const uint8_t *data, uint32_t length) +{ + return CreateFunction(__FUNCTION__)(tox, data, length); +} + +/* ADVANCED FUNCTIONS (If you don't know what they do you can safely ignore them.) */ +/* +uint32_t tox_get_nospam(const Tox *tox) +{ +} + +void tox_set_nospam(Tox *tox, uint32_t nospam) +{ +} + +void tox_get_keys(Tox *tox, uint8_t *public_key, uint8_t *secret_key) +{ +} + +int tox_lossy_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, int(*packet_handler_callback)(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object) +{ +} + +int tox_send_lossy_packet(const Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length) +{ +} + +int tox_lossless_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, int(*packet_handler_callback)(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object) +{ +} + +int tox_send_lossless_packet(const Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length) +{ +} +*/ \ No newline at end of file diff --git a/protocols/Tox/src/api_transfer.cpp b/protocols/Tox/src/api_transfer.cpp new file mode 100644 index 0000000000..c5ba1b5f4a --- /dev/null +++ b/protocols/Tox/src/api_transfer.cpp @@ -0,0 +1,43 @@ +#include "common.h" + +/* FILE SENDING FUNCTIONS */ + +void tox_callback_file_send_request(Tox *tox, void(*function)(Tox *m, int32_t, uint8_t, uint64_t, const uint8_t *, uint16_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_file_control(Tox *tox, void(*function)(Tox *m, int32_t, uint8_t, uint8_t, uint8_t, const uint8_t *, uint16_t, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +void tox_callback_file_data(Tox *tox, void(*function)(Tox *m, int32_t, uint8_t, const uint8_t *, uint16_t length, void *), void *userdata) +{ + CreateFunction(__FUNCTION__)(tox, function, userdata); +} + +int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, const uint8_t *filename, uint16_t filename_length) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber, filesize, filename, filename_length); +} + +int tox_file_send_control(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, const uint8_t *data, uint16_t length) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber, send_receive, filenumber, message_id, data, length); +} + +int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber, filenumber, data, length); +} + +int tox_file_data_size(const Tox *tox, int32_t friendnumber) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber); +} + +uint64_t tox_file_data_remaining(const Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive) +{ + return CreateFunction(__FUNCTION__)(tox, friendnumber, filenumber, send_receive); +} \ No newline at end of file diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp index d6a34a0006..d57b7faf2c 100644 --- a/protocols/Tox/src/tox_account.cpp +++ b/protocols/Tox/src/tox_account.cpp @@ -10,7 +10,7 @@ int CToxProto::OnAccountLoaded(WPARAM, LPARAM) { HookProtoEvent(ME_OPT_INITIALISE, &CToxProto::OnOptionsInit); HookProtoEvent(ME_USERINFO_INITIALISE, &CToxProto::OnUserInfoInit); - HookProtoEvent(ME_DB_CONTACT_SETTINGCHANGED, &CToxProto::OnSettingsChanged); + //HookProtoEvent(ME_DB_CONTACT_SETTINGCHANGED, &CToxProto::OnSettingsChanged); HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage); return 0; @@ -23,7 +23,7 @@ int CToxProto::OnAccountRenamed(WPARAM, LPARAM lParam) std::tstring newPath = GetToxProfilePath(); TCHAR oldPath[MAX_PATH]; mir_sntprintf(oldPath, MAX_PATH, _T("%s\\%s.tox"), VARST(_T("%miranda_userdata%")), accountName); - MoveFileEx(oldPath, newPath.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED); + _trename(oldPath, newPath.c_str()); mir_free(accountName); accountName = mir_tstrdup(m_tszUserName); @@ -32,23 +32,7 @@ int CToxProto::OnAccountRenamed(WPARAM, LPARAM lParam) bool CToxProto::InitToxCore() { - std::tstring profilePath = GetToxProfilePath(); - bool isProfileExists = IsFileExists(profilePath); - - hProfile = CreateFile( - profilePath.c_str(), - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, - OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); - - if (hProfile == INVALID_HANDLE_VALUE) - { - debugLogA("CToxProto::InitToxCore: cannot open tox profile"); - return false; - } + debugLogA("CToxProto::InitToxCore: initializing tox profile"); Tox_Options options = { 0 }; options.udp_disabled = getBool("DisableUDP", 0); @@ -61,10 +45,18 @@ bool CToxProto::InitToxCore() if (nlus.useProxy) { + if (nlus.proxyType == PROXYTYPE_HTTP || nlus.proxyType == PROXYTYPE_HTTPS) + { + debugLogA("CToxProto::InitToxCore: setting http user proxy config"); + options.proxy_type = TOX_PROXY_HTTP; + strcpy(&options.proxy_address[0], nlus.szProxyServer); + options.proxy_port = nlus.wProxyPort; + } + if (nlus.proxyType == PROXYTYPE_SOCKS4 || nlus.proxyType == PROXYTYPE_SOCKS5) { debugLogA("CToxProto::InitToxCore: setting socks user proxy config"); - options.proxy_enabled = 1; + options.proxy_type = TOX_PROXY_SOCKS5; strcpy(&options.proxy_address[0], nlus.szProxyServer); options.proxy_port = nlus.wProxyPort; } @@ -72,34 +64,30 @@ bool CToxProto::InitToxCore() } tox = tox_new(&options); - tox_callback_friend_request(tox, OnFriendRequest, this); - tox_callback_friend_message(tox, OnFriendMessage, this); - tox_callback_friend_action(tox, OnFriendAction, this); - tox_callback_typing_change(tox, OnTypingChanged, this); - tox_callback_name_change(tox, OnFriendNameChange, this); - tox_callback_status_message(tox, OnStatusMessageChanged, this); - tox_callback_user_status(tox, OnUserStatusChanged, this); - tox_callback_read_receipt(tox, OnReadReceipt, this); - tox_callback_connection_status(tox, OnConnectionStatusChanged, this); - // file transfers - tox_callback_file_control(tox, OnFileRequest, this); - tox_callback_file_send_request(tox, OnFriendFile, this); - tox_callback_file_data(tox, OnFileData, this); - // avatars - tox_callback_avatar_info(tox, OnGotFriendAvatarInfo, this); - tox_callback_avatar_data(tox, OnGotFriendAvatarData, this); - - std::vector pubKey(TOX_FRIEND_ADDRESS_SIZE); - tox_get_address(tox, &pubKey[0]); - std::string address = DataToHexString(pubKey); - setString(NULL, TOX_SETTINGS_ID, address.c_str()); - - if (isProfileExists) + bool isProfileLoaded = LoadToxProfile(); + if (isProfileLoaded) { - if (!LoadToxProfile()) - { - return false; - } + tox_callback_friend_request(tox, OnFriendRequest, this); + tox_callback_friend_message(tox, OnFriendMessage, this); + tox_callback_friend_action(tox, OnFriendAction, this); + tox_callback_typing_change(tox, OnTypingChanged, this); + tox_callback_name_change(tox, OnFriendNameChange, this); + tox_callback_status_message(tox, OnStatusMessageChanged, this); + tox_callback_user_status(tox, OnUserStatusChanged, this); + tox_callback_read_receipt(tox, OnReadReceipt, this); + tox_callback_connection_status(tox, OnConnectionStatusChanged, this); + // file transfers + tox_callback_file_control(tox, OnFileRequest, this); + tox_callback_file_send_request(tox, OnFriendFile, this); + tox_callback_file_data(tox, OnFileData, this); + // avatars + tox_callback_avatar_info(tox, OnGotFriendAvatarInfo, this); + tox_callback_avatar_data(tox, OnGotFriendAvatarData, this); + + std::vector pubKey(TOX_FRIEND_ADDRESS_SIZE); + tox_get_address(tox, &pubKey[0]); + std::string address = DataToHexString(pubKey); + setString(NULL, TOX_SETTINGS_ID, address.c_str()); int size = tox_get_self_name_size(tox); std::vector username(size); @@ -114,14 +102,16 @@ bool CToxProto::InitToxCore() } } - return true; + return isProfileLoaded; } void CToxProto::UninitToxCore() { + ptrA nickname(mir_utf8encodeW(ptrT(getTStringA("Nick")))); + tox_set_name(tox, (uint8_t*)(char*)nickname, (uint16_t)strlen(nickname)); + SaveToxProfile(); tox_kill(tox); - CloseHandle(hProfile); } void CToxProto::DoBootstrap() @@ -150,7 +140,16 @@ void CToxProto::PollingThread(void*) debugLogA("CToxProto::PollingThread: entering"); isConnected = false; - DoBootstrap(); + if (InitToxCore()) + { + DoBootstrap(); + } + else + { + isTerminated = true; + m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; + ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, LOGINERR_NOSERVER); + } while (!isTerminated) { @@ -184,6 +183,7 @@ void CToxProto::PollingThread(void*) }*/ } + UninitToxCore(); isConnected = false; debugLogA("CToxProto::PollingThread: leaving"); diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp index 09eb5932c2..4c3af7bc18 100644 --- a/protocols/Tox/src/tox_accounts.cpp +++ b/protocols/Tox/src/tox_accounts.cpp @@ -9,7 +9,7 @@ int CToxProto::CompareAccounts(const CToxProto *p1, const CToxProto *p2) CToxProto* CToxProto::InitAccount(const char* protoName, const wchar_t* userName) { - ptrA address(db_get_sa(NULL, protoName, TOX_SETTINGS_ID)); + /*ptrA address(db_get_sa(NULL, protoName, TOX_SETTINGS_ID)); if (address == NULL) { DialogBoxParam( @@ -18,19 +18,9 @@ CToxProto* CToxProto::InitAccount(const char* protoName, const wchar_t* userName GetActiveWindow(), CToxProto::ToxProfileImportProc, (LPARAM)userName); - } + }*/ CToxProto *proto = new CToxProto(protoName, userName); - if (proto->InitToxCore()) - { - accounts.insert(proto); - } - else - { - delete proto; - proto = NULL; - } - return proto; } diff --git a/protocols/Tox/src/tox_api.cpp b/protocols/Tox/src/tox_api.cpp deleted file mode 100644 index d930f3f4a7..0000000000 --- a/protocols/Tox/src/tox_api.cpp +++ /dev/null @@ -1,561 +0,0 @@ -#include "common.h" - -/* GENERAL FUNCTIONS */ - -Tox *tox_new(Tox_Options *options) -{ - return CreateFunction(__FUNCTION__)(options); -} - -void tox_kill(Tox *tox) -{ - CreateFunction(__FUNCTION__)(tox); -} - -void tox_get_address(const Tox *tox, uint8_t *address) -{ - CreateFunction(__FUNCTION__)(tox, address); -} - -int32_t tox_add_friend(Tox *tox,const uint8_t *address, const uint8_t *data, uint16_t length) -{ - return CreateFunction(__FUNCTION__)(tox, address, data, length); -} - -int32_t tox_add_friend_norequest(Tox *tox, const uint8_t *client_id) -{ - return CreateFunction(__FUNCTION__)(tox, client_id); -} - -int32_t tox_get_friend_number(const Tox *tox, const uint8_t *client_id) -{ - return CreateFunction(__FUNCTION__)(tox, client_id); -} - -int tox_get_client_id(const Tox *tox, int32_t friendnumber, uint8_t *client_id) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber, client_id); -} - -int tox_del_friend(Tox *tox, int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -int tox_get_friend_connection_status(const Tox *tox, int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -int tox_friend_exists(const Tox *tox, int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -uint32_t tox_send_message(Tox *tox, int32_t friendnumber, const uint8_t *message, uint32_t length) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber, message, length); -} - -uint32_t tox_send_action(Tox *tox, int32_t friendnumber, const uint8_t *action, uint32_t length) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber, action, length); -} - -int tox_set_name(Tox *tox, const uint8_t *name, uint16_t length) -{ - return CreateFunction(__FUNCTION__ )(tox, name, length); -} - -uint16_t tox_get_self_name(const Tox *tox, uint8_t *name) -{ - return CreateFunction(__FUNCTION__)(tox, name); -} - -int tox_get_name(const Tox *tox, int32_t friendnumber, uint8_t *name) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber, name); -} - -int tox_get_name_size(const Tox *tox, int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -int tox_get_self_name_size(const Tox *tox) -{ - return CreateFunction(__FUNCTION__)(tox); -} - -int tox_set_status_message(Tox *tox, const uint8_t *status, uint16_t length) -{ - return CreateFunction(__FUNCTION__)(tox, status, length); -} - -int tox_set_user_status(Tox *tox, uint8_t userstatus) -{ - return CreateFunction(__FUNCTION__)(tox, userstatus); -} - -int tox_get_status_message_size(const Tox *tox, int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -int tox_get_self_status_message_size(const Tox *tox) -{ - return CreateFunction(__FUNCTION__)(tox); -} - -int tox_get_status_message(const Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber, buf, maxlen); -} - -int tox_get_self_status_message(const Tox *tox, uint8_t *buf, uint32_t maxlen) -{ - return CreateFunction(__FUNCTION__)(tox, buf, maxlen); -} - -uint8_t tox_get_user_status(const Tox *tox, int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -uint8_t tox_get_self_user_status(const Tox *tox) -{ - return CreateFunction(__FUNCTION__)(tox); -} - -uint64_t tox_get_last_online(const Tox *tox, int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -int tox_set_user_is_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber, is_typing); -} - -uint8_t tox_get_is_typing(const Tox *tox, int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -uint32_t tox_count_friendlist(const Tox *tox) -{ - return CreateFunction(__FUNCTION__)(tox); -} - -uint32_t tox_get_num_online_friends(const Tox *tox) -{ - return CreateFunction(__FUNCTION__)(tox); -} - -uint32_t tox_get_friendlist(const Tox *tox, int32_t *out_list, uint32_t list_size) -{ - return CreateFunction(__FUNCTION__ )(); -} - -void tox_callback_friend_request(Tox *tox, void(*function)(Tox *tox, const uint8_t *, const uint8_t *, uint16_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_friend_message(Tox *tox, void(*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_friend_action(Tox *tox, void(*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_name_change(Tox *tox, void(*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_status_message(Tox *tox, void(*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_user_status(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_typing_change(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_read_receipt(Tox *tox, void(*function)(Tox *tox, int32_t, uint32_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_connection_status(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -/* ADVANCED FUNCTIONS (If you don't know what they do you can safely ignore them.) */ -/* -uint32_t tox_get_nospam(const Tox *tox) -{ -} - -void tox_set_nospam(Tox *tox, uint32_t nospam) -{ -} - -void tox_get_keys(Tox *tox, uint8_t *public_key, uint8_t *secret_key) -{ -} - -int tox_lossy_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, int(*packet_handler_callback)(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object) -{ -} - -int tox_send_lossy_packet(const Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length) -{ -} - -int tox_lossless_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte, int(*packet_handler_callback)(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object), void *object) -{ -} - -int tox_send_lossless_packet(const Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length) -{ -} -*/ -/* GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change */ -/* -void tox_callback_group_invite(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, const uint8_t *, uint16_t, void *), void *userdata) -{ -} - -void tox_callback_group_message(Tox *tox, void(*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *), void *userdata) -{ -} - -void tox_callback_group_action(Tox *tox, void(*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *), void *userdata) -{ -} - -void tox_callback_group_title(Tox *tox, void(*function)(Tox *tox, int, int, const uint8_t *, uint8_t, void *), void *userdata) -{ -} - -void tox_callback_group_namelist_change(Tox *tox, void(*function)(Tox *tox, int, int, uint8_t, void *), void *userdata) -{ -} - -int tox_add_groupchat(Tox *tox) -{ -} - -int tox_del_groupchat(Tox *tox, int groupnumber) -{ -} - -int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name) -{ -} - -int tox_group_peer_pubkey(const Tox *tox, int groupnumber, int peernumber, uint8_t *pk) -{ -} - -int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) -{ -} - -int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length) -{ -} - -int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint16_t length) -{ -} - -int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length) -{ -} - -int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length) -{ -} - -int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title, uint32_t max_length) -{ -} - -unsigned int tox_group_peernumber_is_ours(const Tox *tox, int groupnumber, int peernumber) -{ -} - -int tox_group_number_peers(const Tox *tox, int groupnumber) -{ -} - -int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], uint16_t length) -{ -} - -uint32_t tox_count_chatlist(const Tox *tox) -{ -} - -uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size) -{ -} - -int tox_group_get_type(const Tox *tox, int groupnumber) -{ -} -*/ -/* AVATAR FUNCTIONS */ - -void tox_callback_avatar_info(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, uint8_t *, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_avatar_data(Tox *tox, void(*function)(Tox *tox, int32_t, uint8_t, uint8_t *, uint8_t *, uint32_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length) -{ - return CreateFunction(__FUNCTION__)(tox, format, data, length); -} - -int tox_unset_avatar(Tox *tox) -{ - return CreateFunction(__FUNCTION__)(tox); -} - -int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash) -{ - return CreateFunction(__FUNCTION__)(tox, format, buf, length, maxlen, hash); -} - -int tox_hash(uint8_t *hash, const uint8_t *data, const uint32_t datalen) -{ - return CreateFunction(__FUNCTION__)(hash, data, datalen); -} - -int tox_request_avatar_info(const Tox *tox, const int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -int tox_send_avatar_info(Tox *tox, const int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -int tox_request_avatar_data(const Tox *tox, const int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -/* FILE SENDING FUNCTIONS */ - -void tox_callback_file_send_request(Tox *tox, void(*function)(Tox *m, int32_t, uint8_t, uint64_t, const uint8_t *, uint16_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_file_control(Tox *tox, void(*function)(Tox *m, int32_t, uint8_t, uint8_t, uint8_t, const uint8_t *, uint16_t, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -void tox_callback_file_data(Tox *tox, void(*function)(Tox *m, int32_t, uint8_t, const uint8_t *, uint16_t length, void *), void *userdata) -{ - CreateFunction(__FUNCTION__)(tox, function, userdata); -} - -int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, const uint8_t *filename, uint16_t filename_length) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber, filesize, filename, filename_length); -} - -int tox_file_send_control(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, const uint8_t *data, uint16_t length) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber, send_receive, filenumber, message_id, data, length); -} - -int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber, filenumber, data, length); -} - -int tox_file_data_size(const Tox *tox, int32_t friendnumber) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber); -} - -uint64_t tox_file_data_remaining(const Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive) -{ - return CreateFunction(__FUNCTION__)(tox, friendnumber, filenumber, send_receive); -} - -/* CONNECTION FUNCTIONS */ - -int tox_bootstrap_from_address(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key) -{ - return CreateFunction(__FUNCTION__)(tox, address, port, public_key); -} - -int tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key) -{ - return CreateFunction(__FUNCTION__)(tox, address, port,public_key); -} - -int tox_isconnected(const Tox *tox) -{ - return CreateFunction(__FUNCTION__)(tox); -} - -uint32_t tox_do_interval(Tox *tox) -{ - return CreateFunction(__FUNCTION__)(tox); -} - -void tox_do(Tox *tox) -{ - CreateFunction(__FUNCTION__)(tox); -} - -/* SAVING AND LOADING FUNCTIONS */ - -uint32_t tox_size(const Tox *tox) -{ - return CreateFunction(__FUNCTION__)(tox); -} - -void tox_save(const Tox *tox, uint8_t *data) -{ - CreateFunction(__FUNCTION__)(tox, data); -} - -int tox_load(Tox *tox, const uint8_t *data, uint32_t length) -{ - return CreateFunction(__FUNCTION__)(tox, data, length); -} - -/* ENCRYPTION FUNCTIONS */ - -int tox_pass_encryption_extra_length() -{ - return CreateFunction(__FUNCTION__)(); -} - -int tox_pass_key_length() -{ - return CreateFunction(__FUNCTION__)(); -} - -int tox_pass_salt_length() -{ - return CreateFunction(__FUNCTION__)(); -} - -uint32_t tox_encrypted_size(const Tox *tox) -{ - return CreateFunction(__FUNCTION__)(tox); -} - -int tox_pass_encrypt(const uint8_t *data, uint32_t data_len, uint8_t *passphrase, uint32_t pplength, uint8_t *out) -{ - return CreateFunction(__FUNCTION__)(data, data_len, passphrase, pplength, out); -} - -int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint32_t pplength) -{ - return CreateFunction(__FUNCTION__)(tox, data, passphrase, pplength); -} - -int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out) -{ - return CreateFunction(__FUNCTION__)(data, length, passphrase, pplength, out); -} - -int tox_encrypted_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength) -{ - return CreateFunction(__FUNCTION__)(tox, data, length, passphrase, pplength); -} - -int tox_derive_key_from_pass(uint8_t *passphrase, uint32_t pplength, uint8_t *out_key) -{ - return CreateFunction(__FUNCTION__)(passphrase, pplength, out_key); -} - -int tox_derive_key_with_salt(uint8_t *passphrase, uint32_t pplength, uint8_t *salt, uint8_t *out_key) -{ - return CreateFunction(__FUNCTION__)(passphrase, pplength, salt, out_key); -} - -int tox_get_salt(uint8_t *data, uint8_t *salt) -{ - return CreateFunction(__FUNCTION__)(data, salt); -} - -int tox_pass_key_encrypt(const uint8_t *data, uint32_t data_len, const uint8_t *key, uint8_t *out) -{ - return CreateFunction(__FUNCTION__)(data, data_len, key, out); -} - -int tox_encrypted_key_save(const Tox *tox, uint8_t *data, uint8_t *key) -{ - return CreateFunction(__FUNCTION__)(tox, data, key); -} - -int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *key, uint8_t *out) -{ - return CreateFunction(__FUNCTION__)(data, length, key, out); -} - -int tox_encrypted_key_load(Tox *tox, const uint8_t *data, uint32_t length, uint8_t *key) -{ - return CreateFunction(__FUNCTION__)(tox, data, length, key); -} - -int tox_is_data_encrypted(const uint8_t *data) -{ - return CreateFunction(__FUNCTION__)(data); -} - -int tox_is_save_encrypted(const uint8_t *data) -{ - return CreateFunction(__FUNCTION__)(data); -} - -/* DNS TOXID RESOILVING FUNCTIONS */ - -void *tox_dns3_new(uint8_t *server_public_key) -{ - return CreateFunction(__FUNCTION__)(server_public_key); -} - -void tox_dns3_kill(void *dns3_object) -{ - CreateFunction(__FUNCTION__)(dns3_object); -} - -int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string_max_len, uint32_t *request_id, uint8_t *name, uint8_t name_len) -{ - return CreateFunction(__FUNCTION__)(dns3_object, string, string_max_len, request_id, name, name_len); -} - -int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len, uint32_t request_id) -{ - return CreateFunction(__FUNCTION__)(dns3_object, tox_id, id_record, id_record_len, request_id); -} \ No newline at end of file diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index e4f6d4afbb..5c7c43664e 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -7,28 +7,41 @@ std::tstring CToxProto::GetAvatarFilePath(MCONTACT hContact) DWORD dwAttributes = GetFileAttributes(path); if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) + { CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)path); + } ptrT id(getTStringA(hContact, TOX_SETTINGS_ID)); if (hContact != NULL) + { mir_sntprintf(path, MAX_PATH, _T("%s\\%s.png"), path, id); + } else if (id != NULL) + { mir_sntprintf(path, MAX_PATH, _T("%s\\%s avatar.png"), path, id); + } else + { return _T(""); + } return path; } -bool CToxProto::SetToxAvatar(std::tstring path, bool checkHash) +void CToxProto::SetToxAvatar(std::tstring path, bool checkHash) { + if (!IsOnline()) + { + return; + } + int length; uint8_t *data; FILE *hFile = _tfopen(path.c_str(), L"rb"); if (!hFile) { - debugLogA("CToxProto::SetMyAvatar: failed to open avatar file"); - return false; + debugLogA("CToxProto::SetToxAvatar: failed to open avatar file"); + return; } fseek(hFile, 0, SEEK_END); @@ -37,8 +50,8 @@ bool CToxProto::SetToxAvatar(std::tstring path, bool checkHash) if (length > TOX_AVATAR_MAX_DATA_LENGTH) { fclose(hFile); - debugLogA("CToxProto::SetMyAvatar: new avatar size is excessive"); - return false; + debugLogA("CToxProto::SetToxAvatar: new avatar size is excessive"); + return; } data = (uint8_t*)mir_alloc(length); @@ -46,8 +59,8 @@ bool CToxProto::SetToxAvatar(std::tstring path, bool checkHash) if (readed != length) { fclose(hFile); - debugLogA("CToxProto::SetMyAvatar: failed to read avatar file"); - return false; + debugLogA("CToxProto::SetToxAvatar: failed to read avatar file"); + return; } fclose(hFile); @@ -60,8 +73,8 @@ bool CToxProto::SetToxAvatar(std::tstring path, bool checkHash) { db_free(&dbv); mir_free(data); - debugLogA("CToxProto::SetMyAvatar: new avatar is same with old"); - return false; + debugLogA("CToxProto::SetToxAvatar: new avatar is same with old"); + return; } db_free(&dbv); } @@ -69,8 +82,8 @@ bool CToxProto::SetToxAvatar(std::tstring path, bool checkHash) if (tox_set_avatar(tox, TOX_AVATAR_FORMAT_PNG, data, length) == TOX_ERROR) { mir_free(data); - debugLogA("CToxProto::SetMyAvatar: failed to set new avatar"); - return false; + debugLogA("CToxProto::SetToxAvatar: failed to set new avatar"); + return; } mir_free(data); @@ -78,8 +91,6 @@ bool CToxProto::SetToxAvatar(std::tstring path, bool checkHash) { db_set_blob(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, (void*)hash, TOX_HASH_LENGTH); } - - return true; } INT_PTR CToxProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 5987557851..789ac6039e 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -38,19 +38,11 @@ int CToxProto::OnSettingsChanged(WPARAM hContact, LPARAM lParam) { if (!strcmp(dbcws->szSetting, "Nick") && dbcws->value.pszVal) { - if (tox_set_name(tox, (uint8_t*)dbcws->value.pszVal, (uint16_t)strlen(dbcws->value.pszVal))) + if (tox && tox_set_name(tox, (uint8_t*)dbcws->value.pszVal, (uint16_t)strlen(dbcws->value.pszVal))) { - //SaveToxProfile(); + SaveToxProfile(); } } - - /*if (!strcmp(dbcws->szSetting, "StatusMsg") || !strcmp(dbcws->szSetting, "StatusNote")) - { - if (tox_set_status_message(tox, (uint8_t*)(char*)ptrA(mir_utf8encodeW(dbcws->value.ptszVal)), (uint16_t)_tcslen(dbcws->value.ptszVal))) - { - SaveToxData(); - } - }*/ } return 0; diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 8b6331a8a7..02748633ea 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -30,6 +30,11 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l CheckDlgButton(hwnd, IDC_DISABLE_UDP, proto->getBool("DisableUDP", 0)); CheckDlgButton(hwnd, IDC_DISABLE_IPV6, proto->getBool("DisableIPv6", 0)); + + EnableWindow(GetDlgItem(hwnd, IDC_TOXID), proto->IsOnline()); + EnableWindow(GetDlgItem(hwnd, IDC_CLIPBOARD), proto->IsOnline()); + EnableWindow(GetDlgItem(hwnd, IDC_NAME), proto->IsOnline()); + EnableWindow(GetDlgItem(hwnd, IDC_PASSWORD), proto->IsOnline()); } return TRUE; @@ -74,16 +79,6 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l case WM_NOTIFY: if (reinterpret_cast(lParam)->code == PSN_APPLY) { - TCHAR nick[TOX_MAX_NAME_LENGTH], pass[MAX_PATH]; - GetDlgItemText(hwnd, IDC_NAME, nick, TOX_MAX_NAME_LENGTH); - proto->setTString("Nick", nick); - - GetDlgItemText(hwnd, IDC_PASSWORD, pass, SIZEOF(pass)); - proto->setTString("Password", pass); - - proto->setByte("DisableUDP", (BYTE)IsDlgButtonChecked(hwnd, IDC_DISABLE_UDP)); - proto->setByte("DisableIPv6", (BYTE)IsDlgButtonChecked(hwnd, IDC_DISABLE_IPV6)); - TCHAR group[64]; GetDlgItemText(hwnd, IDC_GROUP, group, SIZEOF(group)); if (_tcslen(group) > 0) @@ -96,7 +91,20 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l proto->delSetting(NULL, TOX_SETTINGS_GROUP); } - proto->SaveToxProfile(); + proto->setByte("DisableUDP", (BYTE)IsDlgButtonChecked(hwnd, IDC_DISABLE_UDP)); + proto->setByte("DisableIPv6", (BYTE)IsDlgButtonChecked(hwnd, IDC_DISABLE_IPV6)); + + if (proto->IsOnline()) + { + TCHAR nick[TOX_MAX_NAME_LENGTH], pass[MAX_PATH]; + GetDlgItemText(hwnd, IDC_NAME, nick, TOX_MAX_NAME_LENGTH); + proto->setTString("Nick", nick); + + GetDlgItemText(hwnd, IDC_PASSWORD, pass, SIZEOF(pass)); + proto->setTString("Password", pass); + + proto->SaveToxProfile(); + } return TRUE; } diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index 417042a9b6..136bc66ca1 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -17,23 +17,36 @@ std::tstring CToxProto::GetToxProfilePath(const TCHAR *accountName) bool CToxProto::LoadToxProfile() { - DWORD size = GetFileSize(hProfile, NULL); + std::tstring profilePath = GetToxProfilePath(); + FILE *profile = _tfopen(profilePath.c_str(), _T("rb")); + if (profile == NULL) + { + debugLogA("CToxProto::LoadToxData: could not open tox profile"); + return true; + } + + fseek(profile, 0L, SEEK_END); + DWORD size = ftell(profile); + rewind(profile); if (size == 0) { + fclose(profile); debugLogA("CToxProto::LoadToxData: tox profile is empty"); - return false; + return true; } - DWORD read = 0; uint8_t *data = (uint8_t*)mir_calloc(size); - if (!ReadFile(hProfile, data, size, &read, NULL) || size != read) + DWORD read = fread((char*)data, sizeof(char), size, profile); + if (size != read) { + fclose(profile); debugLogA("CToxProto::LoadToxData: could not read tox profile"); mir_free(data); return false; } + fclose(profile); - if (tox_is_data_encrypted(data)) + /*if (tox_is_data_encrypted(data)) { ptrA password(mir_utf8encodeW(ptrT(getTStringA("Password")))); if (password == NULL || strlen(password) == 0) @@ -58,7 +71,7 @@ bool CToxProto::LoadToxProfile() return false; } } - else + else*/ { if (tox_load(tox, data, size) == TOX_ERROR) { @@ -69,13 +82,12 @@ bool CToxProto::LoadToxProfile() } mir_free(data); - return true; } void CToxProto::SaveToxProfile() { - ptrA password(mir_utf8encodeW(ptrT(getTStringA("Password")))); + /*ptrA password(mir_utf8encodeW(ptrT(getTStringA("Password")))); bool needToEncrypt = password && strlen(password); DWORD size = needToEncrypt ? tox_encrypted_size(tox) @@ -94,16 +106,28 @@ void CToxProto::SaveToxProfile() else { tox_save(tox, data); + }*/ + + DWORD size = tox_size(tox); + uint8_t *data = (uint8_t*)mir_calloc(size); + tox_save(tox, data); + + std::tstring profilePath = GetToxProfilePath(); + FILE *profile = _tfopen(profilePath.c_str(), _T("wb")); + if (profile == NULL) + { + debugLogA("CToxProto::LoadToxData: could not open tox profile"); + return; } - SetFilePointer(hProfile, 0, NULL, FILE_BEGIN); - SetEndOfFile(hProfile); - DWORD written = 0; - if (!WriteFile(hProfile, data, size, &written, NULL) || size != written) + DWORD written = fwrite(data, sizeof(char), size, profile); + if (size != written) { + fclose(profile); debugLogA("CToxProto::LoadToxData: could not write tox profile"); } + fclose(profile); mir_free(data); } @@ -160,7 +184,7 @@ INT_PTR CToxProto::ToxProfileImportProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA SetDlgItemText(hwnd, IDC_PROFILE_PATH, profilePath); } } - break; + break; case IDOK: { @@ -172,13 +196,9 @@ INT_PTR CToxProto::ToxProfileImportProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA CopyFile(profilePath, defaultProfilePath.c_str(), FALSE); } } - else - { - fclose(_wfopen(defaultProfilePath.c_str(), _T("w"))); - } EndDialog(hwnd, 1); } - break; + break; case IDCANCEL: EndDialog(hwnd, 0); diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index de3ac3f0cb..f3785a3893 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -49,7 +49,7 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) : CToxProto::~CToxProto() { mir_free(accountName); - UninitToxCore(); + //UninitToxCore(); UninitNetlib(); } @@ -58,12 +58,12 @@ DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact) switch (type) { case PFLAGNUM_1: - return PF1_IM | PF1_FILE | PF1_AUTHREQ | PF1_EXTSEARCH; + return PF1_IM | PF1_FILE | PF1_AUTHREQ | PF1_EXTSEARCH | PF1_SERVERCLIST; case PFLAGNUM_2: return PF2_ONLINE | PF2_SHORTAWAY | PF2_LIGHTDND; case PFLAGNUM_4: - return PF4_IMSENDUTF | PF4_SINGLEFILEONLY | PF4_NOAUTHDENYREASON | PF4_FORCEAUTH - | PF4_FORCEADDED | PF4_SUPPORTTYPING | PF4_AVATARS; + return PF4_IMSENDUTF | PF4_SINGLEFILEONLY | PF4_SUPPORTTYPING | PF4_AVATARS + | PF4_FORCEADDED | PF4_NOAUTHDENYREASON | PF4_FORCEAUTH; case PFLAG_UNIQUEIDTEXT: return (INT_PTR)"Tox ID"; case PFLAG_UNIQUEIDSETTING: @@ -224,6 +224,7 @@ int __cdecl CToxProto::SetStatus(int iNewStatus) if (old_status == ID_STATUS_OFFLINE && !IsOnline()) { + // login m_iStatus = ID_STATUS_CONNECTING; isTerminated = false; diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index c53a5d14c0..d7937fdfc1 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -126,7 +126,6 @@ private: void __cdecl PollingThread(void*); // tox profile - HANDLE hProfile; std::tstring GetToxProfilePath(); static std::tstring CToxProto::GetToxProfilePath(const TCHAR *accountName); @@ -210,7 +209,7 @@ private: // avatars std::tstring GetAvatarFilePath(MCONTACT hContact = NULL); - bool SetToxAvatar(std::tstring path, bool checkHash = false); + void SetToxAvatar(std::tstring path, bool checkHash = false); INT_PTR __cdecl GetAvatarCaps(WPARAM wParam, LPARAM lParam); INT_PTR __cdecl GetAvatarInfo(WPARAM, LPARAM lParam); diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index f45c8d937e..bc515000f9 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -121,4 +121,4 @@ bool CToxProto::IsFileExists(std::tstring path) return true; } return false; -} +} \ No newline at end of file -- cgit v1.2.3