diff options
author | John Hernandez <129467592+H3rnand3zzz@users.noreply.github.com> | 2023-04-19 02:44:19 +0200 |
---|---|---|
committer | John Hernandez <129467592+H3rnand3zzz@users.noreply.github.com> | 2023-05-04 16:15:09 +0200 |
commit | 7f3fca2bd081a729d425184f7a0484025862257e (patch) | |
tree | 20f1cd78bf48f7d6ceb95bb0262faf691001bcf9 /src/xmpp | |
parent | faccf24c759d7bddb4d3062c7f044e0c7640ffe7 (diff) | |
download | profani-tty-7f3fca2bd081a729d425184f7a0484025862257e.tar.gz |
Cleanup: gchar as gchar instead of char
Use gchar instead of char in most of the cases where gchar is intended. Reason: improve compatibility and stability. Issue #1819 Minor refactoring.
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/capabilities.c | 21 | ||||
-rw-r--r-- | src/xmpp/jid.c | 7 | ||||
-rw-r--r-- | src/xmpp/message.c | 17 | ||||
-rw-r--r-- | src/xmpp/omemo.c | 6 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 27 |
5 files changed, 26 insertions, 52 deletions
diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index 638b2c90..3bd567cd 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -368,14 +368,14 @@ _caps_by_ver(const char* const ver) return NULL; } - char* category = g_key_file_get_string(cache, ver, "category", NULL); - char* type = g_key_file_get_string(cache, ver, "type", NULL); - char* name = g_key_file_get_string(cache, ver, "name", NULL); + auto_gchar gchar* category = g_key_file_get_string(cache, ver, "category", NULL); + auto_gchar gchar* type = g_key_file_get_string(cache, ver, "type", NULL); + auto_gchar gchar* name = g_key_file_get_string(cache, ver, "name", NULL); - char* software = g_key_file_get_string(cache, ver, "software", NULL); - char* software_version = g_key_file_get_string(cache, ver, "software_version", NULL); - char* os = g_key_file_get_string(cache, ver, "os", NULL); - char* os_version = g_key_file_get_string(cache, ver, "os_version", NULL); + auto_gchar gchar* software = g_key_file_get_string(cache, ver, "software", NULL); + auto_gchar gchar* software_version = g_key_file_get_string(cache, ver, "software_version", NULL); + auto_gchar gchar* os = g_key_file_get_string(cache, ver, "os", NULL); + auto_gchar gchar* os_version = g_key_file_get_string(cache, ver, "os_version", NULL); gsize features_len = 0; gchar** features_list = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL); @@ -391,13 +391,6 @@ _caps_by_ver(const char* const ver) software, software_version, os, os_version, features); - g_free(category); - g_free(type); - g_free(name); - g_free(software); - g_free(software_version); - g_free(os); - g_free(os_version); if (features_list) { g_strfreev(features_list); } diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c index af0a606b..745f069d 100644 --- a/src/xmpp/jid.c +++ b/src/xmpp/jid.c @@ -90,10 +90,9 @@ jid_create(const gchar* const str) if (slashp) { result->resourcepart = g_strdup(slashp + 1); result->domainpart = g_utf8_substring(domain_start, 0, g_utf8_pointer_to_offset(domain_start, slashp)); - char* barejidraw = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, slashp)); + auto_gchar gchar* barejidraw = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, slashp)); result->barejid = g_utf8_strdown(barejidraw, -1); result->fulljid = g_strdup(trimmed); - g_free(barejidraw); } else { result->domainpart = g_strdup(domain_start); result->barejid = g_utf8_strdown(trimmed, -1); @@ -189,15 +188,13 @@ create_fulljid(const char* const barejid, const char* const resource) char* get_nick_from_full_jid(const char* const full_room_jid) { - char** tokens = g_strsplit(full_room_jid, "/", 0); + auto_gcharv gchar** tokens = g_strsplit(full_room_jid, "/", 0); char* nick_part = NULL; if (tokens) { if (tokens[0] && tokens[1]) { nick_part = strdup(tokens[1]); } - - g_strfreev(tokens); } return nick_part; diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 28997474..a6372c4a 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -638,10 +638,9 @@ message_send_chat_omemo(const char* const jid, uint32_t sid, GList* keys, xmpp_stanza_t* header = xmpp_stanza_new(ctx); xmpp_stanza_set_name(header, "header"); - char* sid_text = g_strdup_printf("%d", sid); + auto_gchar gchar* sid_text = g_strdup_printf("%d", sid); log_debug("[OMEMO] Sending from device sid %s", sid_text); xmpp_stanza_set_attribute(header, "sid", sid_text); - g_free(sid_text); GList* key_iter; for (key_iter = keys; key_iter != NULL; key_iter = key_iter->next) { @@ -649,10 +648,9 @@ message_send_chat_omemo(const char* const jid, uint32_t sid, GList* keys, xmpp_stanza_t* key_stanza = xmpp_stanza_new(ctx); xmpp_stanza_set_name(key_stanza, "key"); - char* rid = g_strdup_printf("%d", key->device_id); + auto_gchar gchar* rid = g_strdup_printf("%d", key->device_id); log_debug("[OMEMO] Sending to device rid %s", STR_MAYBE_NULL(rid)); xmpp_stanza_set_attribute(key_stanza, "rid", rid); - g_free(rid); if (key->prekey) { xmpp_stanza_set_attribute(key_stanza, "prekey", "true"); } @@ -1625,19 +1623,16 @@ message_is_sent_by_us(const ProfMessage* const message, bool checkOID) // our client sents at CON_RAND_ID_LEN + identifier if (tmp_len > CON_RAND_ID_LEN) { - char* uuid = g_strndup(tmp_id, CON_RAND_ID_LEN); + auto_gchar gchar* uuid = g_strndup(tmp_id, CON_RAND_ID_LEN); const char* prof_identifier = connection_get_profanity_identifier(); - gchar* hmac = g_compute_hmac_for_string(G_CHECKSUM_SHA1, - (guchar*)prof_identifier, strlen(prof_identifier), - uuid, strlen(uuid)); + auto_gchar gchar* hmac = g_compute_hmac_for_string(G_CHECKSUM_SHA1, + (guchar*)prof_identifier, strlen(prof_identifier), + uuid, strlen(uuid)); if (g_strcmp0(&tmp_id[CON_RAND_ID_LEN], hmac) == 0) { ret = TRUE; } - - g_free(uuid); - g_free(hmac); } } } diff --git a/src/xmpp/omemo.c b/src/xmpp/omemo.c index e1bdbc3e..23c3d375 100644 --- a/src/xmpp/omemo.c +++ b/src/xmpp/omemo.c @@ -669,11 +669,10 @@ _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata) xmpp_ctx_t* const ctx = connection_get_ctx(); Jid* jid = jid_create(connection_get_fulljid()); char* id = connection_create_stanza_id(); - char* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id()); + auto_gchar gchar* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id()); log_debug("[OMEMO] node: %s", node); xmpp_stanza_t* iq = stanza_create_pubsub_configure_request(ctx, id, jid->barejid, node); - g_free(node); iq_id_handler_add(id, _omemo_bundle_publish_configure, NULL, userdata); @@ -712,9 +711,8 @@ _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdat xmpp_ctx_t* const ctx = connection_get_ctx(); Jid* jid = jid_create(connection_get_fulljid()); char* id = connection_create_stanza_id(); - char* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id()); + auto_gchar gchar* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id()); xmpp_stanza_t* iq = stanza_create_pubsub_configure_submit(ctx, id, jid->barejid, node, form); - g_free(node); iq_id_handler_add(id, _omemo_bundle_publish_configure_result, NULL, userdata); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 0fe3966c..88a7ab6c 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -2329,9 +2329,8 @@ stanza_create_omemo_devicelist_publish(xmpp_ctx_t* ctx, GList* const ids) for (GList* i = ids; i != NULL; i = i->next) { xmpp_stanza_t* device = xmpp_stanza_new(ctx); xmpp_stanza_set_name(device, "device"); - char* id = g_strdup_printf("%d", GPOINTER_TO_INT(i->data)); + auto_gchar gchar* id = g_strdup_printf("%d", GPOINTER_TO_INT(i->data)); xmpp_stanza_set_attribute(device, "id", id); - g_free(id); xmpp_stanza_add_child(list, device); xmpp_stanza_release(device); @@ -2366,9 +2365,8 @@ stanza_create_omemo_bundle_publish(xmpp_ctx_t* ctx, const char* const id, xmpp_stanza_t* publish = xmpp_stanza_new(ctx); xmpp_stanza_set_name(publish, STANZA_NAME_PUBLISH); - char* node = g_strdup_printf("%s:%d", "eu.siacs.conversations.axolotl.bundles", device_id); + auto_gchar gchar* node = g_strdup_printf("%s:%d", "eu.siacs.conversations.axolotl.bundles", device_id); xmpp_stanza_set_attribute(publish, STANZA_ATTR_NODE, node); - g_free(node); xmpp_stanza_t* item = xmpp_stanza_new(ctx); xmpp_stanza_set_name(item, STANZA_NAME_ITEM); @@ -2416,9 +2414,8 @@ stanza_create_omemo_bundle_publish(xmpp_ctx_t* ctx, const char* const id, for (p = prekeys, i = prekeys_id, l = prekeys_length; p != NULL; p = p->next, i = i->next, l = l->next) { xmpp_stanza_t* prekey = xmpp_stanza_new(ctx); xmpp_stanza_set_name(prekey, "preKeyPublic"); - char* id = g_strdup_printf("%d", GPOINTER_TO_INT(i->data)); + auto_gchar gchar* id = g_strdup_printf("%d", GPOINTER_TO_INT(i->data)); xmpp_stanza_set_attribute(prekey, "preKeyId", id); - g_free(id); xmpp_stanza_t* prekey_text = xmpp_stanza_new(ctx); char* prekey_b64 = g_base64_encode(p->data, GPOINTER_TO_INT(l->data)); @@ -2464,9 +2461,8 @@ stanza_create_omemo_bundle_request(xmpp_ctx_t* ctx, const char* const id, const xmpp_stanza_t* items = xmpp_stanza_new(ctx); xmpp_stanza_set_name(items, "items"); - char* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, device_id); + auto_gchar gchar* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, device_id); xmpp_stanza_set_attribute(items, STANZA_ATTR_NODE, node); - g_free(node); xmpp_stanza_add_child(pubsub, items); xmpp_stanza_add_child(iq, pubsub); @@ -2577,9 +2573,8 @@ stanza_create_avatar_retrieve_data_request(xmpp_ctx_t* ctx, const char* stanza_i xmpp_stanza_t* items = xmpp_stanza_new(ctx); xmpp_stanza_set_name(items, "items"); - char* node = g_strdup_printf("%s", STANZA_NS_USER_AVATAR_DATA); + auto_gchar gchar* node = g_strdup_printf("%s", STANZA_NS_USER_AVATAR_DATA); xmpp_stanza_set_attribute(items, STANZA_ATTR_NODE, node); - g_free(node); xmpp_stanza_t* item = xmpp_stanza_new(ctx); xmpp_stanza_set_name(item, STANZA_NAME_ITEM); @@ -2671,16 +2666,13 @@ stanza_create_avatar_metadata_publish_iq(xmpp_ctx_t* ctx, const char* img_data, xmpp_stanza_set_name(info, STANZA_NAME_INFO); xmpp_stanza_set_attribute(info, "id", sha1); xmpp_free(ctx, sha1); - char* bytes = g_strdup_printf("%" G_GSIZE_FORMAT, len); - char* h = g_strdup_printf("%d", height); - char* w = g_strdup_printf("%d", width); + auto_gchar gchar* bytes = g_strdup_printf("%" G_GSIZE_FORMAT, len); + auto_gchar gchar* h = g_strdup_printf("%d", height); + auto_gchar gchar* w = g_strdup_printf("%d", width); xmpp_stanza_set_attribute(info, "bytes", bytes); xmpp_stanza_set_attribute(info, "type", "img/png"); xmpp_stanza_set_attribute(info, "height", h); xmpp_stanza_set_attribute(info, "width", w); - g_free(bytes); - g_free(h); - g_free(w); xmpp_stanza_add_child(metadata, info); xmpp_stanza_add_child(item, metadata); @@ -2854,9 +2846,8 @@ stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const s xmpp_stanza_set_name(max, STANZA_NAME_MAX); max_text = xmpp_stanza_new(ctx); - char* txt = g_strdup_printf("%d", MESSAGES_TO_RETRIEVE); + auto_gchar gchar* txt = g_strdup_printf("%d", MESSAGES_TO_RETRIEVE); xmpp_stanza_set_text(max_text, txt); - g_free(txt); xmpp_stanza_add_child(max, max_text); xmpp_stanza_add_child(set, max); |