1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Improve const correctness

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel 2023-12-09 15:08:47 +01:00
parent bac24601da
commit b4c088232e
11 changed files with 44 additions and 60 deletions

View File

@ -5037,17 +5037,11 @@ cmd_lastactivity(ProfWin* window, const char* const command, gchar** args)
if ((g_strcmp0(args[0], "get") == 0)) {
if (args[1] == NULL) {
GString* jid = g_string_new(connection_get_jid()->domainpart);
iq_last_activity_request(jid->str);
g_string_free(jid, TRUE);
return TRUE;
iq_last_activity_request(connection_get_jid()->domainpart);
} else {
iq_last_activity_request(args[1]);
return TRUE;
}
return TRUE;
}
cons_bad_cmd_usage(command);
@ -8330,7 +8324,7 @@ cmd_command_list(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
char* jid = args[1];
const char* jid = args[1];
if (jid == NULL) {
switch (window->type) {
case WIN_MUC:
@ -8391,7 +8385,7 @@ cmd_command_exec(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
char* jid = args[2];
const char* jid = args[2];
if (jid == NULL) {
switch (window->type) {
case WIN_MUC:
@ -9668,12 +9662,11 @@ cmd_change_password(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
auto_char char* user = connection_get_user();
auto_char char* passwd = ui_ask_password(false);
auto_char char* confirm_passwd = ui_ask_password(true);
if (g_strcmp0(passwd, confirm_passwd) == 0) {
iq_register_change_password(user, passwd);
iq_register_change_password(connection_get_user(), passwd);
} else {
cons_show("Aborted! The new password and the confirmed password do not match.");
}

View File

@ -223,7 +223,7 @@ accounts_get_account(const char* const name)
} else {
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status == JABBER_CONNECTED) {
char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC);
const char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC);
if (conf_jid) {
muc_service = strdup(conf_jid);
}

View File

@ -122,8 +122,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
if (account->pgp_keyid) {
char* msg = connection_get_presence_msg();
signed_status = p_gpg_sign(msg, account->pgp_keyid);
signed_status = p_gpg_sign(connection_get_presence_msg(), account->pgp_keyid);
}
account_free(account);
#endif

View File

@ -648,7 +648,7 @@ connection_supports(const char* const feature)
return ret;
}
char*
const char*
connection_jid_for_feature(const char* const feature)
{
if (conn.features_by_jid == NULL) {
@ -765,18 +765,10 @@ equals_our_barejid(const char* cmp)
return g_strcmp0(connection_get_jid()->barejid, cmp) == 0;
}
char*
const char*
connection_get_user(void)
{
const char* jid = connection_get_fulljid();
if (!jid)
return NULL;
char* result = strdup(jid);
char* split = strchr(result, '@');
*split = '\0';
return result;
return connection_get_jid()->localpart;
}
void
@ -845,13 +837,13 @@ connection_create_stanza_id(void)
return g_strdup_printf("%s%s", rndid, hmac);
}
char*
const char*
connection_get_domain(void)
{
return conn.domain;
}
char*
const char*
connection_get_presence_msg(void)
{
return conn.presence_message;

View File

@ -56,7 +56,7 @@ void connection_set_disco_items(GSList* items);
xmpp_conn_t* connection_get_conn(void);
xmpp_ctx_t* connection_get_ctx(void);
char* connection_get_domain(void);
const char* connection_get_domain(void);
void connection_request_features(void);
void connection_features_received(const char* const jid);
GHashTable* connection_get_features(const char* const jid);

View File

@ -417,7 +417,7 @@ iq_rooms_cache_clear(void)
}
void
iq_room_list_request(gchar* conferencejid, gchar* filter)
iq_room_list_request(const char* conferencejid, char* filter)
{
if (g_hash_table_contains(rooms_cache, conferencejid)) {
log_debug("Rooms request cached for: %s", conferencejid);
@ -466,7 +466,7 @@ iq_disable_carbons(void)
void
iq_http_upload_request(HTTPUpload* upload)
{
char* jid = connection_jid_for_feature(STANZA_NS_HTTP_UPLOAD);
const char* jid = connection_jid_for_feature(STANZA_NS_HTTP_UPLOAD);
if (jid == NULL) {
cons_show_error("XEP-0363 HTTP File Upload is not supported by the server");
return;
@ -484,7 +484,7 @@ iq_http_upload_request(HTTPUpload* upload)
}
void
iq_disco_info_request(gchar* jid)
iq_disco_info_request(const char* jid)
{
xmpp_ctx_t* const ctx = connection_get_ctx();
auto_char char* id = connection_create_stanza_id();
@ -497,7 +497,7 @@ iq_disco_info_request(gchar* jid)
}
void
iq_disco_info_request_onconnect(gchar* jid)
iq_disco_info_request_onconnect(const char* jid)
{
xmpp_ctx_t* const ctx = connection_get_ctx();
auto_char char* id = connection_create_stanza_id();
@ -510,7 +510,7 @@ iq_disco_info_request_onconnect(gchar* jid)
}
void
iq_last_activity_request(gchar* jid)
iq_last_activity_request(const char* jid)
{
xmpp_ctx_t* const ctx = connection_get_ctx();
auto_char char* id = connection_create_stanza_id();
@ -618,7 +618,7 @@ iq_send_caps_request_legacy(const char* const to, const char* const id,
}
void
iq_disco_items_request(gchar* jid)
iq_disco_items_request(const char* jid)
{
xmpp_ctx_t* const ctx = connection_get_ctx();
xmpp_stanza_t* iq = stanza_create_disco_items_iq(ctx, "discoitemsreq", jid, NULL);
@ -627,7 +627,7 @@ iq_disco_items_request(gchar* jid)
}
void
iq_disco_items_request_onconnect(gchar* jid)
iq_disco_items_request_onconnect(const char* jid)
{
xmpp_ctx_t* const ctx = connection_get_ctx();
xmpp_stanza_t* iq = stanza_create_disco_items_iq(ctx, "discoitemsreq_onconnect", jid, NULL);
@ -1078,7 +1078,7 @@ _caps_response_legacy_id_handler(xmpp_stanza_t* const stanza, void* const userda
static int
_room_list_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
{
gchar* filter = (gchar*)userdata;
const char* filter = userdata;
const char* id = xmpp_stanza_get_id(stanza);
const char* from = xmpp_stanza_get_from(stanza);

View File

@ -42,8 +42,8 @@ typedef void (*ProfIqFreeCallback)(void* userdata);
void iq_handlers_init(void);
void iq_send_stanza(xmpp_stanza_t* const stanza);
void iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata);
void iq_disco_info_request_onconnect(gchar* jid);
void iq_disco_items_request_onconnect(gchar* jid);
void iq_disco_info_request_onconnect(const char* jid);
void iq_disco_items_request_onconnect(const char* jid);
void iq_send_caps_request(const char* const to, const char* const id, const char* const node, const char* const ver);
void iq_send_caps_request_for_jid(const char* const to, const char* const id, const char* const node,
const char* const ver);

View File

@ -192,7 +192,7 @@ presence_send(const resource_presence_t presence_type, const int idle, char* sig
return;
}
char* msg = connection_get_presence_msg();
const char* msg = connection_get_presence_msg();
if (msg) {
log_debug("Updating presence: %s, \"%s\"", string_from_resource_presence(presence_type), msg);
} else {
@ -282,7 +282,7 @@ presence_join_room(const char* const room, const char* const nick, const char* c
resource_presence_t presence_type = accounts_get_last_presence(session_get_account_name());
const char* show = stanza_get_presence_string_from_type(presence_type);
char* status = connection_get_presence_msg();
const char* status = connection_get_presence_msg();
int pri = accounts_get_priority_for_presence_type(session_get_account_name(), presence_type);
xmpp_ctx_t* ctx = connection_get_ctx();
@ -306,7 +306,7 @@ presence_change_room_nick(const char* const room, const char* const nick)
log_debug("Sending room nickname change to: %s, nick: %s", room, nick);
resource_presence_t presence_type = accounts_get_last_presence(session_get_account_name());
const char* show = stanza_get_presence_string_from_type(presence_type);
char* status = connection_get_presence_msg();
const char* status = connection_get_presence_msg();
int pri = accounts_get_priority_for_presence_type(session_get_account_name(), presence_type);
auto_char char* full_room_jid = create_fulljid(room, nick);

View File

@ -345,7 +345,7 @@ session_login_success(gboolean secured)
// items discovery
connection_request_features();
char* domain = connection_get_domain();
const char* domain = connection_get_domain();
iq_disco_items_request_onconnect(domain);
if (prefs_get_boolean(PREF_CARBONS)) {

View File

@ -190,13 +190,13 @@ void session_reconnect_now(void);
void connection_disconnect(void);
jabber_conn_status_t connection_get_status(void);
char* connection_get_presence_msg(void);
const char* connection_get_presence_msg(void);
void connection_set_presence_msg(const char* const message);
const char* connection_get_fulljid(void);
const Jid* connection_get_jid(void);
const char* connection_get_barejid(void);
gboolean equals_our_barejid(const char* cmp);
char* connection_get_user(void);
const char* connection_get_user(void);
char* connection_create_uuid(void);
void connection_free_uuid(char* uuid);
TLSCertificate* connection_get_tls_peer_cert(void);
@ -205,7 +205,7 @@ gboolean connection_send_stanza(const char* const stanza);
GList* connection_get_available_resources(void);
int connection_count_available_resources(void);
gboolean connection_supports(const char* const feature);
char* connection_jid_for_feature(const char* const feature);
const char* connection_jid_for_feature(const char* const feature);
const char* connection_get_profanity_identifier(void);
@ -244,10 +244,10 @@ void iq_send_software_version(const char* const fulljid);
void iq_rooms_cache_clear(void);
void iq_handlers_remove_win(ProfWin* window);
void iq_handlers_clear(void);
void iq_room_list_request(gchar* conferencejid, gchar* filter);
void iq_disco_info_request(gchar* jid);
void iq_disco_items_request(gchar* jid);
void iq_last_activity_request(gchar* jid);
void iq_room_list_request(const char* conferencejid, char* filter);
void iq_disco_info_request(const char* jid);
void iq_disco_items_request(const char* jid);
void iq_last_activity_request(const char* jid);
void iq_set_autoping(int seconds);
void iq_confirm_instant_room(const char* const room_jid);
void iq_destroy_room(const char* const room_jid);

View File

@ -69,10 +69,10 @@ connection_get_fulljid(void)
return mock_ptr_type(char*);
}
char*
const char*
connection_get_barejid(void)
{
return mock_ptr_type(char*);
return mock_ptr_type(const char*);
}
gboolean
@ -81,10 +81,10 @@ equals_our_barejid(const char* cmp)
return TRUE;
}
char*
const char*
connection_get_user(void)
{
return mock_ptr_type(char*);
return mock_ptr_type(const char*);
}
const char*
@ -122,10 +122,10 @@ connection_get_status(void)
return mock_type(jabber_conn_status_t);
}
char*
const char*
connection_get_presence_msg(void)
{
return mock_ptr_type(char*);
return mock_ptr_type(const char*);
}
char*
@ -324,18 +324,18 @@ iq_send_software_version(const char* const fulljid)
}
void
iq_room_list_request(gchar* conferencejid, gchar* filter)
iq_room_list_request(const char* conferencejid, char* filter)
{
check_expected(conferencejid);
check_expected(filter);
}
void
iq_disco_info_request(gchar* jid)
iq_disco_info_request(const char* jid)
{
}
void
iq_disco_items_request(gchar* jid)
iq_disco_items_request(const char* jid)
{
}
void
@ -412,7 +412,7 @@ iq_room_role_list(const char* const room, char* role)
{
}
void
iq_last_activity_request(gchar* jid)
iq_last_activity_request(const char* jid)
{
}
void