From 91274495bc1e24bbab039e0e468be14fa34caf23 Mon Sep 17 00:00:00 2001 From: Dubslow Date: Sat, 28 Feb 2015 15:26:19 -0600 Subject: [PATCH 1/3] This is a combination of 11 commits. The first commit's message is: TOX_STATUS -> TOX_USER_STATUS, is more specific This is the 2nd commit message: I pretty strongly believe tox_iteration needs to be renamed to a verb There are several other noun functions in the API, but none of them *do* things. I think even tox_do is better than tox_iteration. tox_do_interval is one possibility, but I'm open to suggestions. This is the 3rd commit message: private_key -> secret_key This is more consistent with modern/NaCl/elliptic cryptography, and also "pk", meaning public key, is all over other toxcore code and documentation. This will eliminate ambiguity. This is the 4th commit message: Rename some functions for pseudo-namespace consistency The enum change results in long enum types, but I think consistency trumps having a few less characters. This is the 5th commit message: TOX_FILE_KIND -> TOX_FILE_TYPE This is more of an English thing than a consistency thing, but TOX_FILE_KIND sounds funnier/stranger to me than TOX_FILE_TYPE. This is the 6th commit message: More specific file control function names This is the 7th commit message: Rename custom packet functions for pseudo-namespace consistency This also has the issue with long enums... but I still think consistent enum names are better This is the 8th commit message: Rename functions for pseudo-namespace consistency This is the 9th commit message: Consistency with https://github.com/sonOfRa/tox4j/blob/master/doc/core-design.md#naming-conventions and the rest of the api This is the 10th commit message: Fix errors in previous function rename commits This is the 11th commit message: Shorten one error enum name --- toxcore/tox.c | 76 ++++++++++++++++----------------- toxcore/tox.h | 114 +++++++++++++++++++++++++------------------------- 2 files changed, 95 insertions(+), 95 deletions(-) diff --git a/toxcore/tox.c b/toxcore/tox.c index 554414b11..9a821bfb1 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -411,13 +411,13 @@ void tox_self_get_status_message(const Tox *tox, uint8_t *status) } } -void tox_self_set_status(Tox *tox, TOX_STATUS user_status) +void tox_self_set_status(Tox *tox, TOX_USER_STATUS user_status) { Messenger *m = tox; m_set_userstatus(m, user_status); } -TOX_STATUS tox_self_get_status(const Tox *tox) +TOX_USER_STATUS tox_self_get_status(const Tox *tox) { const Messenger *m = tox; return m_get_self_userstatus(m); @@ -561,7 +561,7 @@ size_t tox_friend_list_size(const Tox *tox) return count_friendlist(m); } -void tox_friend_list(const Tox *tox, uint32_t *list) +void tox_friend_get_list(const Tox *tox, uint32_t *list) { if (list) { const Messenger *m = tox; @@ -650,7 +650,7 @@ void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb * m_callback_statusmessage(m, function, user_data); } -TOX_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) +TOX_USER_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) { const Messenger *m = tox; @@ -658,7 +658,7 @@ TOX_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR if (ret == USERSTATUS_INVALID) { SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND); - return TOX_STATUS_INVALID; + return TOX_USER_STATUS_INVALID; } SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK); @@ -725,41 +725,41 @@ bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool is_typing, TOX_E return 1; } -static void set_message_error(int ret, TOX_ERR_SEND_MESSAGE *error) +static void set_message_error(int ret, TOX_ERR_FRIEND_SEND_MESSAGE *error) { switch (ret) { case 0: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_MESSAGE_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_OK); break; case -1: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_MESSAGE_FRIEND_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND); break; case -2: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_MESSAGE_TOO_LONG); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG); break; case -3: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_MESSAGE_FRIEND_NOT_CONNECTED); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED); break; case -4: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_MESSAGE_SENDQ); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ); break; } } -uint32_t tox_send_message(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, - TOX_ERR_SEND_MESSAGE *error) +uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, + TOX_ERR_FRIEND_SEND_MESSAGE *error) { if (!message) { - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_MESSAGE_NULL); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_NULL); return 0; } if (!length) { - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_MESSAGE_EMPTY); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY); return 0; } @@ -769,16 +769,16 @@ uint32_t tox_send_message(Tox *tox, uint32_t friend_number, const uint8_t *messa return message_id; } -uint32_t tox_send_action(Tox *tox, uint32_t friend_number, const uint8_t *action, size_t length, - TOX_ERR_SEND_MESSAGE *error) +uint32_t tox_friend_send_action(Tox *tox, uint32_t friend_number, const uint8_t *action, size_t length, + TOX_ERR_FRIEND_SEND_MESSAGE *error) { if (!action) { - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_MESSAGE_NULL); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_NULL); return 0; } if (!length) { - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_MESSAGE_EMPTY); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY); return 0; } @@ -788,7 +788,7 @@ uint32_t tox_send_action(Tox *tox, uint32_t friend_number, const uint8_t *action return message_id; } -void tox_callback_read_receipt(Tox *tox, tox_read_receipt_cb *function, void *user_data) +void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *function, void *user_data) { Messenger *m = tox; m_callback_read_receipt(m, function, user_data); @@ -871,13 +871,13 @@ bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TO return 0; } -void tox_callback_file_control(Tox *tox, tox_file_control_cb *function, void *user_data) +void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *function, void *user_data) { Messenger *m = tox; callback_file_control(m, function, user_data); } -uint32_t tox_file_send(Tox *tox, uint32_t friend_number, TOX_FILE_KIND kind, uint64_t file_size, +uint32_t tox_file_send(Tox *tox, uint32_t friend_number, TOX_FILE_TYPE kind, uint64_t file_size, const uint8_t *filename, size_t filename_length, TOX_ERR_FILE_SEND *error) { if (!filename) { @@ -979,52 +979,52 @@ void tox_callback_file_receive_chunk(Tox *tox, tox_file_receive_chunk_cb *functi callback_file_data(m, function, user_data); } -static void set_custom_packet_error(int ret, TOX_ERR_SEND_CUSTOM_PACKET *error) +static void set_custom_packet_error(int ret, TOX_ERR_FRIEND_CUSTOM_PACKET *error) { switch (ret) { case 0: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_OK); break; case -1: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_FRIEND_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_FRIEND_NOT_FOUND); break; case -2: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_TOO_LONG); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_TOO_LONG); break; case -3: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_INVALID); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_INVALID); break; case -4: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_FRIEND_NOT_CONNECTED); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_FRIEND_NOT_CONNECTED); break; case -5: - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_SENDQ); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_SENDQ); break; } } -bool tox_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, - TOX_ERR_SEND_CUSTOM_PACKET *error) +bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, + TOX_ERR_FRIEND_CUSTOM_PACKET *error) { if (!data) { - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_NULL); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); return 0; } Messenger *m = tox; if (length == 0) { - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_EMPTY); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_EMPTY); return 0; } if (data[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_LOSSY_AV_RESERVED)) { - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_INVALID); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_INVALID); return 0; } @@ -1045,18 +1045,18 @@ void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *func custom_lossy_packet_registerhandler(m, function, user_data); } -bool tox_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, - TOX_ERR_SEND_CUSTOM_PACKET *error) +bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, + TOX_ERR_FRIEND_CUSTOM_PACKET *error) { if (!data) { - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_NULL); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); return 0; } Messenger *m = tox; if (length == 0) { - SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_EMPTY); + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_EMPTY); return 0; } diff --git a/toxcore/tox.h b/toxcore/tox.h index 5323c4b63..c4309e59d 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -260,26 +260,26 @@ bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch); /** * Represents the possible statuses a client can have. */ -typedef enum TOX_STATUS { +typedef enum TOX_USER_STATUS { /** * User is online and available. */ - TOX_STATUS_NONE, + TOX_USER_STATUS_NONE, /** * User is away. Clients can set this e.g. after a user defined * inactivity time. */ - TOX_STATUS_AWAY, + TOX_USER_STATUS_AWAY, /** * User is busy. Signals to other clients that this client does not * currently wish to communicate. */ - TOX_STATUS_BUSY, + TOX_USER_STATUS_BUSY, /** * Invalid status used when function returns an error. */ - TOX_STATUS_INVALID -} TOX_STATUS; + TOX_USER_STATUS_INVALID +} TOX_USER_STATUS; /******************************************************************************* @@ -652,7 +652,7 @@ uint32_t tox_iteration_interval(const Tox *tox); * The main loop that needs to be run in intervals of tox_iteration_interval() * milliseconds. */ -void tox_iteration(Tox *tox); +void tox_do_iteration(Tox *tox); /******************************************************************************* @@ -695,12 +695,12 @@ uint32_t tox_self_get_nospam(const Tox *tox); void tox_self_get_public_key(const Tox *tox, uint8_t *public_key); /** - * Copy the private key from the Tox object. + * Copy the secret key from the Tox object. * - * @param private_key A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If + * @param secret_key A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If * this parameter is NULL, this function has no effect. */ -void tox_self_get_private_key(const Tox *tox, uint8_t *private_key); +void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key); /******************************************************************************* @@ -801,12 +801,12 @@ void tox_self_get_status_message(const Tox *tox, uint8_t *status); * * @param user_status One of the user statuses listed in the enumeration above. */ -void tox_self_set_status(Tox *tox, TOX_STATUS user_status); +void tox_self_set_status(Tox *tox, TOX_USER_STATUS user_status); /** * Returns the client's user status. */ -TOX_STATUS tox_self_get_status(const Tox *tox); +TOX_USER_STATUS tox_self_get_status(const Tox *tox); /******************************************************************************* @@ -992,7 +992,7 @@ size_t tox_friend_list_size(const Tox *tox); * @param list A memory region with enough space to hold the friend list. If * this parameter is NULL, this function has no effect. */ -void tox_friend_list(const Tox *tox, uint32_t *list); +void tox_friend_get_list(const Tox *tox, uint32_t *list); @@ -1114,7 +1114,7 @@ void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb * * The status returned is equal to the last status received through the * `friend_status` callback. */ -TOX_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error); +TOX_USER_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error); /** * The function type for the `friend_status` callback. @@ -1123,7 +1123,7 @@ TOX_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR * changed. * @param status The new user status. */ -typedef void tox_friend_status_cb(Tox *tox, uint32_t friend_number, TOX_STATUS status, void *user_data); +typedef void tox_friend_status_cb(Tox *tox, uint32_t friend_number, TOX_USER_STATUS status, void *user_data); /** * Set the callback for the `friend_status` event. Pass NULL to unset. @@ -1228,30 +1228,30 @@ typedef enum TOX_ERR_SET_TYPING { bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool is_typing, TOX_ERR_SET_TYPING *error); -typedef enum TOX_ERR_SEND_MESSAGE { - TOX_ERR_SEND_MESSAGE_OK, - TOX_ERR_SEND_MESSAGE_NULL, +typedef enum TOX_ERR_FRIEND_SEND_MESSAGE { + TOX_ERR_FRIEND_SEND_MESSAGE_OK, + TOX_ERR_FRIEND_SEND_MESSAGE_NULL, /** * The friend number did not designate a valid friend. */ - TOX_ERR_SEND_MESSAGE_FRIEND_NOT_FOUND, + TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND, /** * This client is currently not connected to the friend. */ - TOX_ERR_SEND_MESSAGE_FRIEND_NOT_CONNECTED, + TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED, /** * An allocation error occurred while increasing the send queue size. */ - TOX_ERR_SEND_MESSAGE_SENDQ, + TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ, /** * Message length exceeded TOX_MAX_MESSAGE_LENGTH. */ - TOX_ERR_SEND_MESSAGE_TOO_LONG, + TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG, /** * Attempted to send a zero-length message. */ - TOX_ERR_SEND_MESSAGE_EMPTY -} TOX_ERR_SEND_MESSAGE; + TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY +} TOX_ERR_FRIEND_SEND_MESSAGE; /** * Send a text chat message to an online friend. @@ -1270,8 +1270,8 @@ typedef enum TOX_ERR_SEND_MESSAGE { * incremented by 1 each time a message is sent. If UINT32_MAX messages were * sent, the next message ID is 0. */ -uint32_t tox_send_message(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, - TOX_ERR_SEND_MESSAGE *error); +uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, + TOX_ERR_FRIEND_SEND_MESSAGE *error); /** @@ -1283,10 +1283,10 @@ uint32_t tox_send_message(Tox *tox, uint32_t friend_number, const uint8_t *messa * means that sending a message will cause the next message ID from sending an * action will be incremented. * - * @see tox_send_message for more details. + * @see tox_friend_send_message for more details. */ -uint32_t tox_send_action(Tox *tox, uint32_t friend_number, const uint8_t *action, size_t length, - TOX_ERR_SEND_MESSAGE *error); +uint32_t tox_friend_send_action(Tox *tox, uint32_t friend_number, const uint8_t *action, size_t length, + TOX_ERR_FRIEND_SEND_MESSAGE *error); /** @@ -1296,7 +1296,7 @@ uint32_t tox_send_action(Tox *tox, uint32_t friend_number, const uint8_t *action * @param message_id The message ID as returned from tox_send_message or * tox_send_action corresponding to the message sent. */ -typedef void tox_read_receipt_cb(Tox *tox, uint32_t friend_number, uint32_t message_id, void *user_data); +typedef void tox_friend_read_receipt_cb(Tox *tox, uint32_t friend_number, uint32_t message_id, void *user_data); /** * Set the callback for the `read_receipt` event. Pass NULL to unset. @@ -1307,7 +1307,7 @@ typedef void tox_read_receipt_cb(Tox *tox, uint32_t friend_number, uint32_t mess * received here may not correspond to any message sent through tox_send_message * or tox_send_action. In that case, the receipt should be discarded. */ -void tox_callback_read_receipt(Tox *tox, tox_read_receipt_cb *function, void *user_data); +void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *function, void *user_data); /******************************************************************************* @@ -1390,12 +1390,12 @@ void tox_callback_friend_action(Tox *tox, tox_friend_action_cb *function, void * ******************************************************************************/ -typedef enum TOX_FILE_KIND { +typedef enum TOX_FILE_TYPE { /** * Arbitrary file data. Clients can choose to handle it based on the file name * or magic or any other way they choose. */ - TOX_FILE_KIND_DATA, + TOX_FILE_TYPE_DATA, /** * Avatar data. This consists of tox_hash(image) + image. * @@ -1412,8 +1412,8 @@ typedef enum TOX_FILE_KIND { * saved hash and send TOX_FILE_CONTROL_CANCEL to terminate the avatar * transfer if it matches. */ - TOX_FILE_KIND_AVATAR -} TOX_FILE_KIND; + TOX_FILE_TYPE_AVATAR +} TOX_FILE_TYPE; /** @@ -1502,7 +1502,7 @@ typedef enum TOX_ERR_FILE_CONTROL { * * @return true on success. */ -bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, +bool tox_file_send_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, TOX_ERR_FILE_CONTROL *error); @@ -1517,7 +1517,7 @@ bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TO * associated with. * @param control The file control command received. */ -typedef void tox_file_control_cb(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, +typedef void tox_file_recv_control_cb(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, void *user_data); /** @@ -1526,7 +1526,7 @@ typedef void tox_file_control_cb(Tox *tox, uint32_t friend_number, uint32_t file * This event is triggered when a file control command is received from a * friend. */ -void tox_callback_file_control(Tox *tox, tox_file_control_cb *function, void *user_data); +void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *function, void *user_data); /******************************************************************************* @@ -1618,7 +1618,7 @@ typedef enum TOX_ERR_FILE_SEND { * number is per friend. File numbers are reused after a transfer terminates. * on failure, this function returns UINT32_MAX. */ -uint32_t tox_file_send(Tox *tox, uint32_t friend_number, TOX_FILE_KIND kind, uint64_t file_size, +uint32_t tox_file_send(Tox *tox, uint32_t friend_number, TOX_FILE_TYPE kind, uint64_t file_size, const uint8_t *filename, size_t filename_length, TOX_ERR_FILE_SEND *error); @@ -1731,7 +1731,7 @@ void tox_callback_file_request_chunk(Tox *tox, tox_file_request_chunk_cb *functi * @param file_number The friend-specific file number the data received is * associated with. */ -typedef void tox_file_receive_cb(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_KIND kind, +typedef void tox_file_receive_cb(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_TYPE kind, uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data); /** @@ -1794,35 +1794,35 @@ void tox_callback_file_receive_chunk(Tox *tox, tox_file_receive_chunk_cb *functi ******************************************************************************/ -typedef enum TOX_ERR_SEND_CUSTOM_PACKET { - TOX_ERR_SEND_CUSTOM_PACKET_OK, - TOX_ERR_SEND_CUSTOM_PACKET_NULL, +typedef enum TOX_ERR_FRIEND_CUSTOM_PACKET { + TOX_ERR_FRIEND_CUSTOM_PACKET_OK, + TOX_ERR_FRIEND_CUSTOM_PACKET_NULL, /** * The friend number did not designate a valid friend. */ - TOX_ERR_SEND_CUSTOM_PACKET_FRIEND_NOT_FOUND, + TOX_ERR_FRIEND_CUSTOM_PACKET_FRIEND_NOT_FOUND, /** * This client is currently not connected to the friend. */ - TOX_ERR_SEND_CUSTOM_PACKET_FRIEND_NOT_CONNECTED, + TOX_ERR_FRIEND_CUSTOM_PACKET_FRIEND_NOT_CONNECTED, /** * The first byte of data was not in the specified range for the packet type. * This range is 200-254 for lossy, and 160-191 for lossless packets. */ - TOX_ERR_SEND_CUSTOM_PACKET_INVALID, + TOX_ERR_FRIEND_CUSTOM_PACKET_INVALID, /** * Attempted to send an empty packet. */ - TOX_ERR_SEND_CUSTOM_PACKET_EMPTY, + TOX_ERR_FRIEND_CUSTOM_PACKET_EMPTY, /** * Packet data length exceeded TOX_MAX_CUSTOM_PACKET_SIZE. */ - TOX_ERR_SEND_CUSTOM_PACKET_TOO_LONG, + TOX_ERR_FRIEND_CUSTOM_PACKET_TOO_LONG, /** * Send queue size exceeded. */ - TOX_ERR_SEND_CUSTOM_PACKET_SENDQ -} TOX_ERR_SEND_CUSTOM_PACKET; + TOX_ERR_FRIEND_CUSTOM_PACKET_SENDQ +} TOX_ERR_FRIEND_CUSTOM_PACKET; /** @@ -1845,8 +1845,8 @@ typedef enum TOX_ERR_SEND_CUSTOM_PACKET { * * @return true on success. */ -bool tox_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, - TOX_ERR_SEND_CUSTOM_PACKET *error); +bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, + TOX_ERR_FRIEND_CUSTOM_PACKET *error); /** * The function type for the `friend_lossy_packet` callback. @@ -1880,8 +1880,8 @@ void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *func * * @return true on success. */ -bool tox_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, - TOX_ERR_SEND_CUSTOM_PACKET *error); +bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, + TOX_ERR_FRIEND_CUSTOM_PACKET *error); /** * The function type for the `friend_lossless_packet` callback. @@ -1919,7 +1919,7 @@ void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb * @param dht_id A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If this * parameter is NULL, this function has no effect. */ -void tox_get_dht_id(const Tox *tox, uint8_t *dht_id); +void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id); typedef enum TOX_ERR_GET_PORT { @@ -1933,13 +1933,13 @@ typedef enum TOX_ERR_GET_PORT { /** * Return the UDP port this Tox instance is bound to. */ -uint16_t tox_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error); +uint16_t tox_self_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error); /** * Return the TCP port this Tox instance is bound to. This is only relevant if * the instance is acting as a TCP relay. */ -uint16_t tox_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error); +uint16_t tox_self_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error); #include "tox_old.h" From 3bf259f69d408dc5c380383ee3c0cde0504e9f02 Mon Sep 17 00:00:00 2001 From: Dubslow Date: Wed, 11 Mar 2015 17:26:25 -0500 Subject: [PATCH 2/3] Convert core code depending on the api --- auto_tests/tox_test.c | 106 +++++++++++++++++----------------- auto_tests/toxav_basic_test.c | 26 ++++----- auto_tests/toxav_many_test.c | 16 ++--- testing/irc_syncbot.c | 2 +- testing/nTox.c | 20 +++---- testing/tox_shell.c | 4 +- testing/tox_sync.c | 18 +++--- toxcore/tox.c | 10 ++-- toxcore/tox.h | 2 +- 9 files changed, 102 insertions(+), 102 deletions(-) diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 7cae9da68..8df6316fd 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -93,13 +93,13 @@ void handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *data, size uint8_t filenum; uint32_t file_accepted; uint64_t file_size; -void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_KIND kind, uint64_t filesize, +void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_TYPE kind, uint64_t filesize, const uint8_t *filename, size_t filename_length, void *userdata) { if (*((uint32_t *)userdata) != 974536) return; - if (kind != TOX_FILE_KIND_DATA) { + if (kind != TOX_FILE_TYPE_DATA) { ck_abort_msg("Bad kind"); return; } @@ -113,10 +113,10 @@ void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, TO TOX_ERR_FILE_CONTROL error; - if (tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error)) { + if (tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error)) { ++file_accepted; } else { - ck_abort_msg("tox_file_control failed. %i", error); + ck_abort_msg("tox_file_send_control failed. %i", error); } } @@ -221,7 +221,7 @@ START_TEST(test_one) { TOX_ERR_GET_PORT error; - ck_assert_msg(tox_get_udp_port(tox1, &error) == 33445, "First Tox instance did not bind to udp port 33445.\n"); + ck_assert_msg(tox_self_get_udp_port(tox1, &error) == 33445, "First Tox instance did not bind to udp port 33445.\n"); ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error"); } @@ -293,7 +293,7 @@ START_TEST(test_few_clients) { TOX_ERR_GET_PORT error; - ck_assert_msg(tox_get_udp_port(tox1, &error) == 33445, "First Tox instance did not bind to udp port 33445.\n"); + ck_assert_msg(tox_self_get_udp_port(tox1, &error) == 33445, "First Tox instance did not bind to udp port 33445.\n"); ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error"); } @@ -309,9 +309,9 @@ START_TEST(test_few_clients) uint8_t off = 1; while (1) { - tox_iteration(tox1); - tox_iteration(tox2); - tox_iteration(tox3); + tox_iterate(tox1); + tox_iterate(tox2); + tox_iterate(tox3); if (tox_get_connection_status(tox1) && tox_get_connection_status(tox2) && tox_get_connection_status(tox3)) { if (off) { @@ -334,17 +334,17 @@ START_TEST(test_few_clients) tox_callback_friend_message(tox3, print_message, &to_compare); uint8_t msgs[TOX_MAX_MESSAGE_LENGTH + 1]; memset(msgs, 'G', sizeof(msgs)); - TOX_ERR_SEND_MESSAGE errm; - tox_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH + 1, &errm); - ck_assert_msg(errm == TOX_ERR_SEND_MESSAGE_TOO_LONG, "TOX_MAX_MESSAGE_LENGTH is too small\n"); - tox_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH, &errm); - ck_assert_msg(errm == TOX_ERR_SEND_MESSAGE_OK, "TOX_MAX_MESSAGE_LENGTH is too big\n"); + TOX_ERR_FRIEND_SEND_MESSAGE errm; + tox_friend_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH + 1, &errm); + ck_assert_msg(errm == TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG, "TOX_MAX_MESSAGE_LENGTH is too small\n"); + tox_friend_send_message(tox2, 0, msgs, TOX_MAX_MESSAGE_LENGTH, &errm); + ck_assert_msg(errm == TOX_ERR_FRIEND_SEND_MESSAGE_OK, "TOX_MAX_MESSAGE_LENGTH is too big\n"); while (1) { messages_received = 0; - tox_iteration(tox1); - tox_iteration(tox2); - tox_iteration(tox3); + tox_iterate(tox1); + tox_iterate(tox2); + tox_iterate(tox3); if (messages_received) break; @@ -361,9 +361,9 @@ START_TEST(test_few_clients) while (1) { name_changes = 0; - tox_iteration(tox1); - tox_iteration(tox2); - tox_iteration(tox3); + tox_iterate(tox1); + tox_iterate(tox2); + tox_iterate(tox3); if (name_changes) break; @@ -381,9 +381,9 @@ START_TEST(test_few_clients) while (1) { typing_changes = 0; - tox_iteration(tox1); - tox_iteration(tox2); - tox_iteration(tox3); + tox_iterate(tox1); + tox_iterate(tox2); + tox_iterate(tox3); if (typing_changes == 2) @@ -399,9 +399,9 @@ START_TEST(test_few_clients) while (1) { typing_changes = 0; - tox_iteration(tox1); - tox_iteration(tox2); - tox_iteration(tox3); + tox_iterate(tox1); + tox_iterate(tox2); + tox_iterate(tox3); if (typing_changes == 1) break; @@ -419,16 +419,16 @@ START_TEST(test_few_clients) tox_callback_friend_lossless_packet(tox3, &handle_custom_packet, &packet_number); uint8_t data_c[TOX_MAX_CUSTOM_PACKET_SIZE + 1]; memset(data_c, ((uint8_t)packet_number), sizeof(data_c)); - int ret = tox_send_lossless_packet(tox2, 0, data_c, sizeof(data_c), 0); - ck_assert_msg(ret == 0, "tox_send_lossless_packet bigger fail %i", ret); - ret = tox_send_lossless_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE, 0); - ck_assert_msg(ret == 1, "tox_send_lossless_packet fail %i", ret); + int ret = tox_friend_send_lossless_packet(tox2, 0, data_c, sizeof(data_c), 0); + ck_assert_msg(ret == 0, "tox_friend_send_lossless_packet bigger fail %i", ret); + ret = tox_friend_send_lossless_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE, 0); + ck_assert_msg(ret == 1, "tox_friend_send_lossless_packet fail %i", ret); while (1) { custom_packet = 0; - tox_iteration(tox1); - tox_iteration(tox2); - tox_iteration(tox3); + tox_iterate(tox1); + tox_iterate(tox2); + tox_iterate(tox3); if (custom_packet == 1) break; @@ -441,16 +441,16 @@ START_TEST(test_few_clients) packet_number = 200; tox_callback_friend_lossy_packet(tox3, &handle_custom_packet, &packet_number); memset(data_c, ((uint8_t)packet_number), sizeof(data_c)); - ret = tox_send_lossy_packet(tox2, 0, data_c, sizeof(data_c), 0); - ck_assert_msg(ret == 0, "tox_send_lossy_packet bigger fail %i", ret); - ret = tox_send_lossy_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE, 0); - ck_assert_msg(ret == 1, "tox_send_lossy_packet fail %i", ret); + ret = tox_friend_send_lossy_packet(tox2, 0, data_c, sizeof(data_c), 0); + ck_assert_msg(ret == 0, "tox_friend_send_lossy_packet bigger fail %i", ret); + ret = tox_friend_send_lossy_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE, 0); + ck_assert_msg(ret == 1, "tox_friend_send_lossy_packet fail %i", ret); while (1) { custom_packet = 0; - tox_iteration(tox1); - tox_iteration(tox2); - tox_iteration(tox3); + tox_iterate(tox1); + tox_iterate(tox2); + tox_iterate(tox3); if (custom_packet == 1) break; @@ -463,20 +463,20 @@ START_TEST(test_few_clients) file_accepted = file_size = file_recv = sendf_ok = size_recv = 0; long long unsigned int f_time = time(NULL); tox_callback_file_receive_chunk(tox3, write_file, &to_compare); - tox_callback_file_control(tox2, file_print_control, &to_compare); + tox_callback_file_recv_control(tox2, file_print_control, &to_compare); tox_callback_file_request_chunk(tox2, tox_file_request_chunk, &to_compare); - tox_callback_file_control(tox3, file_print_control, &to_compare); + tox_callback_file_recv_control(tox3, file_print_control, &to_compare); tox_callback_file_receive(tox3, tox_file_receive, &to_compare); uint64_t totalf_size = 100 * 1024 * 1024; - uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), + uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_TYPE_DATA, totalf_size, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 0); ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); while (1) { - tox_iteration(tox1); - tox_iteration(tox2); - tox_iteration(tox3); + tox_iterate(tox1); + tox_iterate(tox2); + tox_iterate(tox3); if (file_sending_done) { if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv) { @@ -526,7 +526,7 @@ START_TEST(test_many_clients) { TOX_ERR_GET_PORT error; - ck_assert_msg(tox_get_udp_port(toxes[0], &error) == 33445, "First Tox instance did not bind to udp port 33445.\n"); + ck_assert_msg(tox_self_get_udp_port(toxes[0], &error) == 33445, "First Tox instance did not bind to udp port 33445.\n"); ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error"); } @@ -573,7 +573,7 @@ loop_top: } for (i = 0; i < NUM_TOXES; ++i) { - tox_iteration(toxes[i]); + tox_iterate(toxes[i]); } c_sleep(50); @@ -654,7 +654,7 @@ START_TEST(test_many_group) { TOX_ERR_GET_PORT error; - ck_assert_msg(tox_get_udp_port(toxes[0], &error) == 33445, "First Tox instance did not bind to udp port 33445.\n"); + ck_assert_msg(tox_self_get_udp_port(toxes[0], &error) == 33445, "First Tox instance did not bind to udp port 33445.\n"); ck_assert_msg(error == TOX_ERR_GET_PORT_OK, "wrong error"); } @@ -678,7 +678,7 @@ START_TEST(test_many_group) break; for (i = 0; i < NUM_GROUP_TOX; ++i) { - tox_iteration(toxes[i]); + tox_iterate(toxes[i]); } c_sleep(50); @@ -696,7 +696,7 @@ START_TEST(test_many_group) while (1) { for (i = 0; i < NUM_GROUP_TOX; ++i) { - tox_iteration(toxes[i]); + tox_iterate(toxes[i]); } if (!invite_counter) { @@ -734,7 +734,7 @@ START_TEST(test_many_group) for (j = 0; j < 20; ++j) { for (i = 0; i < NUM_GROUP_TOX; ++i) { - tox_iteration(toxes[i]); + tox_iterate(toxes[i]); } c_sleep(50); @@ -747,7 +747,7 @@ START_TEST(test_many_group) for (j = 0; j < 10; ++j) { for (i = 0; i < NUM_GROUP_TOX; ++i) { - tox_iteration(toxes[i]); + tox_iterate(toxes[i]); } c_sleep(50); diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 59730edf2..3f4a3b8d6 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -232,7 +232,7 @@ void register_callbacks(ToxAv *av, void *data) */ #define CALL_AND_START_LOOP(AliceCallType, BobCallType) \ { int step = 0, running = 1; while (running) {\ - tox_iteration(bootstrap_node); tox_iteration(Alice); tox_iteration(Bob); \ + tox_iterate(bootstrap_node); tox_iterate(Alice); tox_iterate(Bob); \ toxav_do(status_control.Bob.av); toxav_do(status_control.Alice.av); \ switch ( step ) {\ case 0: /* Alice */ printf("Alice is calling...\n");\ @@ -267,9 +267,9 @@ START_TEST(test_AV_flows) uint8_t off = 1; while (1) { - tox_iteration(bootstrap_node); - tox_iteration(Alice); - tox_iteration(Bob); + tox_iterate(bootstrap_node); + tox_iterate(Alice); + tox_iterate(Bob); if (tox_get_connection_status(bootstrap_node) && tox_get_connection_status(Alice) && tox_get_connection_status(Bob) && off) { @@ -484,9 +484,9 @@ START_TEST(test_AV_flows) int running = 1; while (running) { - tox_iteration(bootstrap_node); - tox_iteration(Alice); - tox_iteration(Bob); + tox_iterate(bootstrap_node); + tox_iterate(Alice); + tox_iterate(Bob); switch ( step ) { case 0: /* Alice */ @@ -525,9 +525,9 @@ START_TEST(test_AV_flows) int running = 1; while (running) { - tox_iteration(bootstrap_node); - tox_iteration(Alice); - tox_iteration(Bob); + tox_iterate(bootstrap_node); + tox_iterate(Alice); + tox_iterate(Bob); toxav_do(status_control.Alice.av); toxav_do(status_control.Bob.av); @@ -570,9 +570,9 @@ START_TEST(test_AV_flows) int running = 1; while (running) { - tox_iteration(bootstrap_node); - tox_iteration(Alice); - tox_iteration(Bob); + tox_iterate(bootstrap_node); + tox_iterate(Alice); + tox_iterate(Bob); toxav_do(status_control.Alice.av); toxav_do(status_control.Bob.av); diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 4002c4e70..f22043e13 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -294,11 +294,11 @@ START_TEST(test_AV_three_calls) uint8_t off = 1; while (1) { - tox_iteration(bootstrap_node); - tox_iteration(caller); + tox_iterate(bootstrap_node); + tox_iterate(caller); for (i = 0; i < 3; i ++) { - tox_iteration(callees[i]); + tox_iterate(callees[i]); } @@ -351,11 +351,11 @@ START_TEST(test_AV_three_calls) while (call_running[0] || call_running[1] || call_running[2]) { pthread_mutex_lock(&muhmutex); - tox_iteration(bootstrap_node); - tox_iteration(caller); - tox_iteration(callees[0]); - tox_iteration(callees[1]); - tox_iteration(callees[2]); + tox_iterate(bootstrap_node); + tox_iterate(caller); + tox_iterate(callees[0]); + tox_iterate(callees[1]); + tox_iterate(callees[2]); for ( i = 0; i < 3; i++ ) toxav_do(status_control.calls[0].Caller.av); diff --git a/testing/irc_syncbot.c b/testing/irc_syncbot.c index df9e964c7..ee49e1607 100644 --- a/testing/irc_syncbot.c +++ b/testing/irc_syncbot.c @@ -342,7 +342,7 @@ int main(int argc, char *argv[]) } } - tox_iteration(tox); + tox_iterate(tox); usleep(1000 * 50); } diff --git a/testing/nTox.c b/testing/nTox.c index 708397f9e..d373c683c 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -158,7 +158,7 @@ uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) fseek(tempfile, 0, SEEK_END); uint64_t filesize = ftell(tempfile); fseek(tempfile, 0, SEEK_SET); - uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_KIND_DATA, filesize, (uint8_t *)filename, strlen(filename) + 1, + uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_TYPE_DATA, filesize, (uint8_t *)filename, strlen(filename) + 1, 0); if (filenum == -1) @@ -389,13 +389,13 @@ void line_eval(Tox *m, char *line) new_lines(numstring); } else if (inpt_command == 'd') { - tox_iteration(m); + tox_iterate(m); } else if (inpt_command == 'm') { //message command: /m friendnumber messsage char *posi[1]; int num = strtoul(line + prompt_offset, posi, 0); if (**posi != 0) { - if (tox_send_message(m, num, (uint8_t *) *posi + 1, strlen(*posi + 1), NULL) < 1) { + if (tox_friend_send_message(m, num, (uint8_t *) *posi + 1, strlen(*posi + 1), NULL) < 1) { char sss[256]; sprintf(sss, "[i] could not send message to friend num %u", num); new_lines(sss); @@ -607,7 +607,7 @@ void line_eval(Tox *m, char *line) if (conversation_default != 0) { if (conversation_default > 0) { int friendnumber = conversation_default - 1; - uint32_t res = tox_send_message(m, friendnumber, (uint8_t *)line, strlen(line), NULL); + uint32_t res = tox_friend_send_message(m, friendnumber, (uint8_t *)line, strlen(line), NULL); if (res == 0) { char sss[128]; @@ -1127,12 +1127,12 @@ void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t print_groupchatpeers(m, groupnumber); } } -void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_KIND type, +void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_TYPE type, uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data) { - if (type != TOX_FILE_KIND_DATA) { + if (type != TOX_FILE_TYPE_DATA) { new_lines("Refused invalid file type."); - tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, 0); + tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, 0); return; } @@ -1140,7 +1140,7 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, sprintf(msg, "[t] %u is sending us: %s of size %llu", friend_number, filename, (long long unsigned int)file_size); new_lines(msg); - if (tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, 0)) { + if (tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, 0)) { sprintf(msg, "Accepted file transfer. (saving file as: %u.%u.bin)", friend_number, file_number); new_lines(msg); } else @@ -1270,7 +1270,7 @@ int main(int argc, char *argv[]) tox_callback_group_invite(m, print_invite, NULL); tox_callback_group_message(m, print_groupmessage, NULL); tox_callback_file_receive_chunk(m, write_file, NULL); - tox_callback_file_control(m, file_print_control, NULL); + tox_callback_file_recv_control(m, file_print_control, NULL); tox_callback_file_receive(m, file_request_accept, NULL); tox_callback_file_request_chunk(m, tox_file_request_chunk, NULL); tox_callback_group_namelist_change(m, print_groupnamelistchange, NULL); @@ -1326,7 +1326,7 @@ int main(int argc, char *argv[]) } } - tox_iteration(m); + tox_iterate(m); do_refresh(); int c = timeout_getch(m); diff --git a/testing/tox_shell.c b/testing/tox_shell.c index c8dc9ff29..38fe63648 100644 --- a/testing/tox_shell.c +++ b/testing/tox_shell.c @@ -148,10 +148,10 @@ int main(int argc, char *argv[]) if (ret <= 0) break; - tox_send_message(tox, num, buf, ret, 0); + tox_friend_send_message(tox, num, buf, ret, 0); } - tox_iteration(tox); + tox_iterate(tox); c_sleep(1); } diff --git a/testing/tox_sync.c b/testing/tox_sync.c index bdbd2e3f5..61f390fcf 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c @@ -88,7 +88,7 @@ uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) fseek(tempfile, 0, SEEK_END); uint64_t filesize = ftell(tempfile); fseek(tempfile, 0, SEEK_SET); - uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_KIND_DATA, filesize, (uint8_t *)filename, strlen(filename) + 1, + uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_TYPE_DATA, filesize, (uint8_t *)filename, strlen(filename) + 1, 0); if (filenum == -1) @@ -124,12 +124,12 @@ int not_sending() static char path[1024]; -void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_KIND type, +void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_TYPE type, uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data) { - if (type != TOX_FILE_KIND_DATA) { + if (type != TOX_FILE_TYPE_DATA) { printf("Refused invalid file type."); - tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, 0); + tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, 0); return; } @@ -151,7 +151,7 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, if (tempfile != 0) { fclose(tempfile); - tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, 0); + tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, 0); return; } @@ -159,11 +159,11 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, file_recv[file_index].file = fopen(fullpath, "wb"); if (file_recv[file_index].file == 0) { - tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, 0); + tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, 0); return; } - if (tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, 0)) { + if (tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, 0)) { printf("Accepted file transfer. (file: %s)\n", fullpath); } @@ -231,7 +231,7 @@ int main(int argc, char *argv[]) Tox *tox = tox_new(0, 0, 0, 0); tox_callback_file_receive_chunk(tox, write_file, NULL); - tox_callback_file_control(tox, file_print_control, NULL); + tox_callback_file_recv_control(tox, file_print_control, NULL); tox_callback_file_receive(tox, file_request_accept, NULL); tox_callback_file_request_chunk(tox, tox_file_request_chunk, NULL); tox_callback_friend_connection_status(tox, print_online, NULL); @@ -306,7 +306,7 @@ int main(int argc, char *argv[]) } } - tox_iteration(tox); + tox_iterate(tox); c_sleep(1); } diff --git a/toxcore/tox.c b/toxcore/tox.c index 9a821bfb1..6340aee9e 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -302,7 +302,7 @@ uint32_t tox_iteration_interval(const Tox *tox) return messenger_run_interval(m); } -void tox_iteration(Tox *tox) +void tox_iterate(Tox *tox) { Messenger *m = tox; do_messenger(m); @@ -822,7 +822,7 @@ bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length) return 1; } -bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, +bool tox_file_send_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, TOX_ERR_FILE_CONTROL *error) { Messenger *m = tox; @@ -1077,7 +1077,7 @@ void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb custom_lossless_packet_registerhandler(m, function, user_data); } -void tox_get_dht_id(const Tox *tox, uint8_t *dht_id) +void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) { if (dht_id) { const Messenger *m = tox; @@ -1085,7 +1085,7 @@ void tox_get_dht_id(const Tox *tox, uint8_t *dht_id) } } -uint16_t tox_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error) +uint16_t tox_self_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error) { const Messenger *m = tox; uint16_t port = htons(m->net->port); @@ -1099,7 +1099,7 @@ uint16_t tox_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error) return port; } -uint16_t tox_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error) +uint16_t tox_self_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error) { /* TCP server not yet implemented in clients. */ SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_NOT_BOUND); diff --git a/toxcore/tox.h b/toxcore/tox.h index c4309e59d..96969c436 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -652,7 +652,7 @@ uint32_t tox_iteration_interval(const Tox *tox); * The main loop that needs to be run in intervals of tox_iteration_interval() * milliseconds. */ -void tox_do_iteration(Tox *tox); +void tox_iterate(Tox *tox); /******************************************************************************* From 64fefb6f43e9213db9f3313aa7e8af7c36bf8538 Mon Sep 17 00:00:00 2001 From: Dubslow Date: Fri, 13 Mar 2015 12:34:14 -0500 Subject: [PATCH 3/3] revert to TOX_FILE_KIND --- auto_tests/tox_test.c | 6 +++--- testing/nTox.c | 6 +++--- testing/tox_sync.c | 6 +++--- toxcore/tox.c | 2 +- toxcore/tox.h | 12 ++++++------ 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 8df6316fd..938c44992 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -93,13 +93,13 @@ void handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *data, size uint8_t filenum; uint32_t file_accepted; uint64_t file_size; -void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_TYPE kind, uint64_t filesize, +void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_KIND kind, uint64_t filesize, const uint8_t *filename, size_t filename_length, void *userdata) { if (*((uint32_t *)userdata) != 974536) return; - if (kind != TOX_FILE_TYPE_DATA) { + if (kind != TOX_FILE_KIND_DATA) { ck_abort_msg("Bad kind"); return; } @@ -468,7 +468,7 @@ START_TEST(test_few_clients) tox_callback_file_recv_control(tox3, file_print_control, &to_compare); tox_callback_file_receive(tox3, tox_file_receive, &to_compare); uint64_t totalf_size = 100 * 1024 * 1024; - uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_TYPE_DATA, totalf_size, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), + uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 0); ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); diff --git a/testing/nTox.c b/testing/nTox.c index d373c683c..d6adecaa0 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -158,7 +158,7 @@ uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) fseek(tempfile, 0, SEEK_END); uint64_t filesize = ftell(tempfile); fseek(tempfile, 0, SEEK_SET); - uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_TYPE_DATA, filesize, (uint8_t *)filename, strlen(filename) + 1, + uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_KIND_DATA, filesize, (uint8_t *)filename, strlen(filename) + 1, 0); if (filenum == -1) @@ -1127,10 +1127,10 @@ void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t print_groupchatpeers(m, groupnumber); } } -void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_TYPE type, +void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_KIND type, uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data) { - if (type != TOX_FILE_TYPE_DATA) { + if (type != TOX_FILE_KIND_DATA) { new_lines("Refused invalid file type."); tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, 0); return; diff --git a/testing/tox_sync.c b/testing/tox_sync.c index 61f390fcf..520d66292 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c @@ -88,7 +88,7 @@ uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) fseek(tempfile, 0, SEEK_END); uint64_t filesize = ftell(tempfile); fseek(tempfile, 0, SEEK_SET); - uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_TYPE_DATA, filesize, (uint8_t *)filename, strlen(filename) + 1, + uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_KIND_DATA, filesize, (uint8_t *)filename, strlen(filename) + 1, 0); if (filenum == -1) @@ -124,10 +124,10 @@ int not_sending() static char path[1024]; -void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_TYPE type, +void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_KIND type, uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data) { - if (type != TOX_FILE_TYPE_DATA) { + if (type != TOX_FILE_KIND_DATA) { printf("Refused invalid file type."); tox_file_send_control(tox, friend_number, file_number, TOX_FILE_CONTROL_CANCEL, 0); return; diff --git a/toxcore/tox.c b/toxcore/tox.c index 6340aee9e..0b702a1b1 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -877,7 +877,7 @@ void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *function callback_file_control(m, function, user_data); } -uint32_t tox_file_send(Tox *tox, uint32_t friend_number, TOX_FILE_TYPE kind, uint64_t file_size, +uint32_t tox_file_send(Tox *tox, uint32_t friend_number, TOX_FILE_KIND kind, uint64_t file_size, const uint8_t *filename, size_t filename_length, TOX_ERR_FILE_SEND *error) { if (!filename) { diff --git a/toxcore/tox.h b/toxcore/tox.h index 96969c436..7093a2329 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -1390,12 +1390,12 @@ void tox_callback_friend_action(Tox *tox, tox_friend_action_cb *function, void * ******************************************************************************/ -typedef enum TOX_FILE_TYPE { +typedef enum TOX_FILE_KIND { /** * Arbitrary file data. Clients can choose to handle it based on the file name * or magic or any other way they choose. */ - TOX_FILE_TYPE_DATA, + TOX_FILE_KIND_DATA, /** * Avatar data. This consists of tox_hash(image) + image. * @@ -1412,8 +1412,8 @@ typedef enum TOX_FILE_TYPE { * saved hash and send TOX_FILE_CONTROL_CANCEL to terminate the avatar * transfer if it matches. */ - TOX_FILE_TYPE_AVATAR -} TOX_FILE_TYPE; + TOX_FILE_KIND_AVATAR +} TOX_FILE_KIND; /** @@ -1618,7 +1618,7 @@ typedef enum TOX_ERR_FILE_SEND { * number is per friend. File numbers are reused after a transfer terminates. * on failure, this function returns UINT32_MAX. */ -uint32_t tox_file_send(Tox *tox, uint32_t friend_number, TOX_FILE_TYPE kind, uint64_t file_size, +uint32_t tox_file_send(Tox *tox, uint32_t friend_number, TOX_FILE_KIND kind, uint64_t file_size, const uint8_t *filename, size_t filename_length, TOX_ERR_FILE_SEND *error); @@ -1731,7 +1731,7 @@ void tox_callback_file_request_chunk(Tox *tox, tox_file_request_chunk_cb *functi * @param file_number The friend-specific file number the data received is * associated with. */ -typedef void tox_file_receive_cb(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_TYPE kind, +typedef void tox_file_receive_cb(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_KIND kind, uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data); /**