From 6c6c0b1b1be56b93d1d7644b07ec2bab01ce832b Mon Sep 17 00:00:00 2001 From: iphydf Date: Fri, 5 Jan 2024 16:40:25 +0000 Subject: [PATCH] cleanup: Make setters take non-const `Tox *`. Also renamed the setter parameters to match the property being set.. --- toxcore/tox.c | 30 ++++++++++++++--------------- toxcore/tox.h | 44 +++++++++++++++++++++---------------------- toxcore/tox_api.c | 48 +++++++++++++++++++++++------------------------ 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/toxcore/tox.c b/toxcore/tox.c index d638b08e..26c15014 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -2387,12 +2387,12 @@ uint64_t tox_conference_offline_peer_get_last_active(const Tox *tox, uint32_t co } bool tox_conference_set_max_offline(Tox *tox, uint32_t conference_number, - uint32_t max_offline_peers, + uint32_t max_offline, Tox_Err_Conference_Set_Max_Offline *error) { assert(tox != nullptr); tox_lock(tox); - const int ret = group_set_max_frozen(tox->m->conferences_object, conference_number, max_offline_peers); + const int ret = group_set_max_frozen(tox->m->conferences_object, conference_number, max_offline); tox_unlock(tox); if (ret == -1) { @@ -3193,7 +3193,7 @@ bool tox_group_leave(Tox *tox, uint32_t group_number, const uint8_t *part_messag return false; } -bool tox_group_self_set_name(const Tox *tox, uint32_t group_number, const uint8_t *name, size_t length, +bool tox_group_self_set_name(Tox *tox, uint32_t group_number, const uint8_t *name, size_t length, Tox_Err_Group_Self_Name_Set *error) { assert(tox != nullptr); @@ -3277,7 +3277,7 @@ bool tox_group_self_get_name(const Tox *tox, uint32_t group_number, uint8_t *nam return true; } -bool tox_group_self_set_status(const Tox *tox, uint32_t group_number, Tox_User_Status status, +bool tox_group_self_set_status(Tox *tox, uint32_t group_number, Tox_User_Status status, Tox_Err_Group_Self_Status_Set *error) { assert(tox != nullptr); @@ -3550,7 +3550,7 @@ Tox_Connection tox_group_peer_get_connection_status(const Tox *tox, uint32_t gro return (Tox_Connection)ret; } -bool tox_group_set_topic(const Tox *tox, uint32_t group_number, const uint8_t *topic, size_t length, +bool tox_group_set_topic(Tox *tox, uint32_t group_number, const uint8_t *topic, size_t length, Tox_Err_Group_Topic_Set *error) { assert(tox != nullptr); @@ -3668,7 +3668,7 @@ size_t tox_group_get_name_size(const Tox *tox, uint32_t group_number, Tox_Err_Gr return ret; } -bool tox_group_get_name(const Tox *tox, uint32_t group_number, uint8_t *group_name, Tox_Err_Group_State_Queries *error) +bool tox_group_get_name(const Tox *tox, uint32_t group_number, uint8_t *name, Tox_Err_Group_State_Queries *error) { assert(tox != nullptr); @@ -3681,7 +3681,7 @@ bool tox_group_get_name(const Tox *tox, uint32_t group_number, uint8_t *group_na return false; } - gc_get_group_name(chat, group_name); + gc_get_group_name(chat, name); tox_unlock(tox); SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -4205,7 +4205,7 @@ uint32_t tox_group_invite_accept(Tox *tox, uint32_t friend_number, const uint8_t return UINT32_MAX; } -bool tox_group_founder_set_password(const Tox *tox, uint32_t group_number, const uint8_t *password, size_t length, +bool tox_group_founder_set_password(Tox *tox, uint32_t group_number, const uint8_t *password, size_t length, Tox_Err_Group_Founder_Set_Password *error) { assert(tox != nullptr); @@ -4261,7 +4261,7 @@ bool tox_group_founder_set_password(const Tox *tox, uint32_t group_number, const return false; } -bool tox_group_founder_set_privacy_state(const Tox *tox, uint32_t group_number, Tox_Group_Privacy_State privacy_state, +bool tox_group_founder_set_privacy_state(Tox *tox, uint32_t group_number, Tox_Group_Privacy_State privacy_state, Tox_Err_Group_Founder_Set_Privacy_State *error) { assert(tox != nullptr); @@ -4308,7 +4308,7 @@ bool tox_group_founder_set_privacy_state(const Tox *tox, uint32_t group_number, return false; } -bool tox_group_founder_set_topic_lock(const Tox *tox, uint32_t group_number, Tox_Group_Topic_Lock topic_lock, +bool tox_group_founder_set_topic_lock(Tox *tox, uint32_t group_number, Tox_Group_Topic_Lock topic_lock, Tox_Err_Group_Founder_Set_Topic_Lock *error) { assert(tox != nullptr); @@ -4360,7 +4360,7 @@ bool tox_group_founder_set_topic_lock(const Tox *tox, uint32_t group_number, Tox return false; } -bool tox_group_founder_set_voice_state(const Tox *tox, uint32_t group_number, Tox_Group_Voice_State voice_state, +bool tox_group_founder_set_voice_state(Tox *tox, uint32_t group_number, Tox_Group_Voice_State voice_state, Tox_Err_Group_Founder_Set_Voice_State *error) { assert(tox != nullptr); @@ -4407,7 +4407,7 @@ bool tox_group_founder_set_voice_state(const Tox *tox, uint32_t group_number, To return false; } -bool tox_group_founder_set_peer_limit(const Tox *tox, uint32_t group_number, uint16_t max_peers, +bool tox_group_founder_set_peer_limit(Tox *tox, uint32_t group_number, uint16_t peer_limit, Tox_Err_Group_Founder_Set_Peer_Limit *error) { assert(tox != nullptr); @@ -4427,7 +4427,7 @@ bool tox_group_founder_set_peer_limit(const Tox *tox, uint32_t group_number, uin return false; } - const int ret = gc_founder_set_max_peers(chat, max_peers); + const int ret = gc_founder_set_max_peers(chat, peer_limit); tox_unlock(tox); switch (ret) { @@ -4458,7 +4458,7 @@ bool tox_group_founder_set_peer_limit(const Tox *tox, uint32_t group_number, uin return false; } -bool tox_group_set_ignore(const Tox *tox, uint32_t group_number, uint32_t peer_id, bool ignore, +bool tox_group_set_ignore(Tox *tox, uint32_t group_number, uint32_t peer_id, bool ignore, Tox_Err_Group_Set_Ignore *error) { assert(tox != nullptr); @@ -4498,7 +4498,7 @@ bool tox_group_set_ignore(const Tox *tox, uint32_t group_number, uint32_t peer_i return false; } -bool tox_group_mod_set_role(const Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Group_Role role, +bool tox_group_mod_set_role(Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Group_Role role, Tox_Err_Group_Mod_Set_Role *error) { assert(tox != nullptr); diff --git a/toxcore/tox.h b/toxcore/tox.h index 897e75a6..b2ece005 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -720,15 +720,15 @@ void tox_options_set_dht_announcements_enabled(struct Tox_Options *options, bool Tox_Proxy_Type tox_options_get_proxy_type(const struct Tox_Options *options); -void tox_options_set_proxy_type(struct Tox_Options *options, Tox_Proxy_Type type); +void tox_options_set_proxy_type(struct Tox_Options *options, Tox_Proxy_Type proxy_type); const char *tox_options_get_proxy_host(const struct Tox_Options *options); -void tox_options_set_proxy_host(struct Tox_Options *options, const char *host); +void tox_options_set_proxy_host(struct Tox_Options *options, const char *proxy_host); uint16_t tox_options_get_proxy_port(const struct Tox_Options *options); -void tox_options_set_proxy_port(struct Tox_Options *options, uint16_t port); +void tox_options_set_proxy_port(struct Tox_Options *options, uint16_t proxy_port); uint16_t tox_options_get_start_port(const struct Tox_Options *options); @@ -748,23 +748,23 @@ void tox_options_set_hole_punching_enabled(struct Tox_Options *options, bool hol Tox_Savedata_Type tox_options_get_savedata_type(const struct Tox_Options *options); -void tox_options_set_savedata_type(struct Tox_Options *options, Tox_Savedata_Type type); +void tox_options_set_savedata_type(struct Tox_Options *options, Tox_Savedata_Type savedata_type); const uint8_t *tox_options_get_savedata_data(const struct Tox_Options *options); -void tox_options_set_savedata_data(struct Tox_Options *options, const uint8_t data[], size_t length); +void tox_options_set_savedata_data(struct Tox_Options *options, const uint8_t savedata_data[], size_t length); size_t tox_options_get_savedata_length(const struct Tox_Options *options); -void tox_options_set_savedata_length(struct Tox_Options *options, size_t length); +void tox_options_set_savedata_length(struct Tox_Options *options, size_t savedata_length); tox_log_cb *tox_options_get_log_callback(const struct Tox_Options *options); -void tox_options_set_log_callback(struct Tox_Options *options, tox_log_cb *callback); +void tox_options_set_log_callback(struct Tox_Options *options, tox_log_cb *log_callback); void *tox_options_get_log_user_data(const struct Tox_Options *options); -void tox_options_set_log_user_data(struct Tox_Options *options, void *user_data); +void tox_options_set_log_user_data(struct Tox_Options *options, void *log_user_data); bool tox_options_get_experimental_thread_safety(const struct Tox_Options *options); @@ -2862,7 +2862,7 @@ const char *tox_err_conference_set_max_offline_to_string(Tox_Err_Conference_Set_ * @brief Set maximum number of offline peers to store, overriding the default. */ bool tox_conference_set_max_offline( - Tox *tox, Tox_Conference_Number conference_number, uint32_t max_offline_peers, + Tox *tox, Tox_Conference_Number conference_number, uint32_t max_offline, Tox_Err_Conference_Set_Max_Offline *error); typedef enum Tox_Err_Conference_Invite { @@ -3970,7 +3970,7 @@ const char *tox_err_group_self_name_set_to_string(Tox_Err_Group_Self_Name_Set va * @return true on success. */ bool tox_group_self_set_name( - const Tox *tox, Tox_Group_Number group_number, + Tox *tox, Tox_Group_Number group_number, const uint8_t name[], size_t length, Tox_Err_Group_Self_Name_Set *error); @@ -4032,7 +4032,7 @@ const char *tox_err_group_self_status_set_to_string(Tox_Err_Group_Self_Status_Se * * @return true on success. */ -bool tox_group_self_set_status(const Tox *tox, Tox_Group_Number group_number, Tox_User_Status status, +bool tox_group_self_set_status(Tox *tox, Tox_Group_Number group_number, Tox_User_Status status, Tox_Err_Group_Self_Status_Set *error); /** @@ -4311,7 +4311,7 @@ const char *tox_err_group_topic_set_to_string(Tox_Err_Group_Topic_Set value); * @return true on success. */ bool tox_group_set_topic( - const Tox *tox, Tox_Group_Number group_number, + Tox *tox, Tox_Group_Number group_number, const uint8_t topic[], size_t length, Tox_Err_Group_Topic_Set *error); @@ -4372,14 +4372,14 @@ size_t tox_group_get_name_size(const Tox *tox, Tox_Group_Number group_number, To * * Call tox_group_get_name_size to determine the allocation size for the `name` parameter. * - * @param group_name A valid memory region large enough to store the group name. + * @param name A valid memory region large enough to store the group name. * If this parameter is NULL, this function call has no effect. * * @return true on success. */ bool tox_group_get_name( const Tox *tox, Tox_Group_Number group_number, - uint8_t group_name[], Tox_Err_Group_State_Queries *error); + uint8_t name[], Tox_Err_Group_State_Queries *error); /** * Write the Chat ID designated by the given group number to a byte array. @@ -5281,7 +5281,7 @@ const char *tox_err_group_founder_set_password_to_string(Tox_Err_Group_Founder_S * @return true on success. */ bool tox_group_founder_set_password( - const Tox *tox, Tox_Group_Number group_number, + Tox *tox, Tox_Group_Number group_number, const uint8_t password[], size_t length, Tox_Err_Group_Founder_Set_Password *error); @@ -5342,7 +5342,7 @@ const char *tox_err_group_founder_set_topic_lock_to_string(Tox_Err_Group_Founder * * @return true on success. */ -bool tox_group_founder_set_topic_lock(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Topic_Lock topic_lock, +bool tox_group_founder_set_topic_lock(Tox *tox, Tox_Group_Number group_number, Tox_Group_Topic_Lock topic_lock, Tox_Err_Group_Founder_Set_Topic_Lock *error); typedef enum Tox_Err_Group_Founder_Set_Voice_State { @@ -5396,7 +5396,7 @@ const char *tox_err_group_founder_set_voice_state_to_string(Tox_Err_Group_Founde * * @return true on success. */ -bool tox_group_founder_set_voice_state(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Voice_State voice_state, +bool tox_group_founder_set_voice_state(Tox *tox, Tox_Group_Number group_number, Tox_Group_Voice_State voice_state, Tox_Err_Group_Founder_Set_Voice_State *error); typedef enum Tox_Err_Group_Founder_Set_Privacy_State { @@ -5450,7 +5450,7 @@ const char *tox_err_group_founder_set_privacy_state_to_string(Tox_Err_Group_Foun * * @return true on success. */ -bool tox_group_founder_set_privacy_state(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Privacy_State privacy_state, +bool tox_group_founder_set_privacy_state(Tox *tox, Tox_Group_Number group_number, Tox_Group_Privacy_State privacy_state, Tox_Err_Group_Founder_Set_Privacy_State *error); typedef enum Tox_Err_Group_Founder_Set_Peer_Limit { @@ -5498,11 +5498,11 @@ const char *tox_err_group_founder_set_peer_limit_to_string(Tox_Err_Group_Founder * group shared state including the change, and distributes it to the rest of the group. * * @param group_number The group number of the group for which we wish to set the peer limit. - * @param max_peers The maximum number of peers to allow in the group. + * @param peer_limit The maximum number of peers to allow in the group. * * @return true on success. */ -bool tox_group_founder_set_peer_limit(const Tox *tox, Tox_Group_Number group_number, uint16_t max_peers, +bool tox_group_founder_set_peer_limit(Tox *tox, Tox_Group_Number group_number, uint16_t peer_limit, Tox_Err_Group_Founder_Set_Peer_Limit *error); @@ -5550,7 +5550,7 @@ const char *tox_err_group_set_ignore_to_string(Tox_Err_Group_Set_Ignore value); * * @return true on success. */ -bool tox_group_set_ignore(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, bool ignore, +bool tox_group_set_ignore(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, bool ignore, Tox_Err_Group_Set_Ignore *error); typedef enum Tox_Err_Group_Mod_Set_Role { @@ -5610,7 +5610,7 @@ const char *tox_err_group_mod_set_role_to_string(Tox_Err_Group_Mod_Set_Role valu * * @return true on success. */ -bool tox_group_mod_set_role(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Group_Role role, +bool tox_group_mod_set_role(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Group_Role role, Tox_Err_Group_Mod_Set_Role *error); typedef enum Tox_Err_Group_Mod_Kick_Peer { diff --git a/toxcore/tox_api.c b/toxcore/tox_api.c index 02bb8e15..d92c98b0 100644 --- a/toxcore/tox_api.c +++ b/toxcore/tox_api.c @@ -138,33 +138,33 @@ uint32_t tox_dht_node_public_key_size(void) //!TOKSTYLE- -#define ACCESSORS(type, ns, name) \ -type tox_options_get_##ns##name(const struct Tox_Options *options) \ +#define ACCESSORS(type, name) \ +type tox_options_get_##name(const struct Tox_Options *options) \ { \ - return options->ns##name; \ + return options->name; \ } \ -void tox_options_set_##ns##name(struct Tox_Options *options, type name) \ +void tox_options_set_##name(struct Tox_Options *options, type name) \ { \ - options->ns##name = name; \ + options->name = name; \ } -ACCESSORS(bool,, ipv6_enabled) -ACCESSORS(bool,, udp_enabled) -ACCESSORS(Tox_Proxy_Type, proxy_, type) -ACCESSORS(const char *, proxy_, host) -ACCESSORS(uint16_t, proxy_, port) -ACCESSORS(uint16_t,, start_port) -ACCESSORS(uint16_t,, end_port) -ACCESSORS(uint16_t,, tcp_port) -ACCESSORS(bool,, hole_punching_enabled) -ACCESSORS(Tox_Savedata_Type, savedata_, type) -ACCESSORS(size_t, savedata_, length) -ACCESSORS(tox_log_cb *, log_, callback) -ACCESSORS(void *, log_, user_data) -ACCESSORS(bool,, local_discovery_enabled) -ACCESSORS(bool,, dht_announcements_enabled) -ACCESSORS(bool,, experimental_thread_safety) -ACCESSORS(const Tox_System *,, operating_system) +ACCESSORS(bool, ipv6_enabled) +ACCESSORS(bool, udp_enabled) +ACCESSORS(Tox_Proxy_Type, proxy_type) +ACCESSORS(const char *, proxy_host) +ACCESSORS(uint16_t, proxy_port) +ACCESSORS(uint16_t, start_port) +ACCESSORS(uint16_t, end_port) +ACCESSORS(uint16_t, tcp_port) +ACCESSORS(bool, hole_punching_enabled) +ACCESSORS(Tox_Savedata_Type, savedata_type) +ACCESSORS(size_t, savedata_length) +ACCESSORS(tox_log_cb *, log_callback) +ACCESSORS(void *, log_user_data) +ACCESSORS(bool, local_discovery_enabled) +ACCESSORS(bool, dht_announcements_enabled) +ACCESSORS(bool, experimental_thread_safety) +ACCESSORS(const Tox_System *, operating_system) //!TOKSTYLE+ @@ -173,9 +173,9 @@ const uint8_t *tox_options_get_savedata_data(const struct Tox_Options *options) return options->savedata_data; } -void tox_options_set_savedata_data(struct Tox_Options *options, const uint8_t *data, size_t length) +void tox_options_set_savedata_data(struct Tox_Options *options, const uint8_t *savedata_data, size_t length) { - options->savedata_data = data; + options->savedata_data = savedata_data; options->savedata_length = length; }