1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Move ID generation to xmpp folder

create_unique_id() was changed to use UUIDs instead of a counter in the
last commit. Since now it depends on connection_create_uuid() which is
in the xmpp subfolder the function should also be moved there.

Renamed it to connection_create_stanza_id() and moved it to
src/xmpp/connection.c.

Discussion happened in https://github.com/boothj5/profanity/pull/1010
This commit is contained in:
Michael Vetter 2018-08-30 11:01:28 +02:00
parent f4fb61b0c8
commit 6d80700329
11 changed files with 68 additions and 68 deletions

View File

@ -56,7 +56,6 @@
#include "log.h"
#include "common.h"
#include "tools/p_sha1.h"
#include "xmpp/xmpp.h"
struct curl_data_t
{
@ -331,27 +330,6 @@ release_is_new(char *found_version)
}
}
char*
create_unique_id(char *prefix)
{
char *result = NULL;
GString *result_str = g_string_new("");
char *uuid = connection_create_uuid();
if (prefix) {
g_string_printf(result_str, "prof_%s_%s", prefix, uuid);
} else {
g_string_printf(result_str, "prof_%s", uuid);
}
connection_free_uuid(uuid);
result = result_str->str;
g_string_free(result_str, FALSE);
return result;
}
char*
p_sha1_hash(char *str)
{

View File

@ -93,7 +93,6 @@ char* release_get_latest(void);
gboolean release_is_new(char *found_version);
char* p_sha1_hash(char *str);
char* create_unique_id(char *prefix);
char* get_file_or_linked(char *loc, char *basedir);
char* strip_arg_quotes(const char *const input);

View File

@ -73,7 +73,7 @@ blocking_request(void)
}
blocked_ac = autocomplete_new();
char *id = create_unique_id("blocked_list_request");
char *id = connection_create_stanza_id("blocked_list_request");
iq_id_handler_add(id, _blocklist_result_handler, NULL, NULL);
xmpp_ctx_t *ctx = connection_get_ctx();
@ -115,7 +115,7 @@ blocked_add(char *jid)
xmpp_ctx_t *ctx = connection_get_ctx();
char *id = create_unique_id("block");
char *id = connection_create_stanza_id("block");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
xmpp_stanza_t *block = xmpp_stanza_new(ctx);
@ -151,7 +151,7 @@ blocked_remove(char *jid)
xmpp_ctx_t *ctx = connection_get_ctx();
char *id = create_unique_id("unblock");
char *id = connection_create_stanza_id("unblock");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
xmpp_stanza_t *block = xmpp_stanza_new(ctx);

View File

@ -333,7 +333,7 @@ _send_bookmarks(void)
{
xmpp_ctx_t *ctx = connection_get_ctx();
char *id = create_unique_id("bookmarks_update");
char *id = connection_create_stanza_id("bookmarks_update");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);

View File

@ -392,6 +392,27 @@ connection_free_uuid(char *uuid)
}
}
char*
connection_create_stanza_id(char *prefix)
{
char *result = NULL;
GString *result_str = g_string_new("");
char *uuid = connection_create_uuid();
if (prefix) {
g_string_printf(result_str, "prof_%s_%s", prefix, uuid);
} else {
g_string_printf(result_str, "prof_%s", uuid);
}
connection_free_uuid(uuid);
result = result_str->str;
g_string_free(result_str, FALSE);
return result;
}
char*
connection_get_domain(void)
{

View File

@ -60,4 +60,6 @@ void connection_clear_data(void);
void connection_add_available_resource(Resource *resource);
void connection_remove_available_resource(const char *const resource);
char* connection_create_stanza_id(char *prefix);
#endif

View File

@ -318,7 +318,7 @@ iq_room_list_request(gchar *conferencejid, gchar *filter)
log_debug("Rooms request not cached for: %s", conferencejid);
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("confreq");
char *id = connection_create_stanza_id("confreq");
xmpp_stanza_t *iq = stanza_create_disco_items_iq(ctx, id, conferencejid);
iq_id_handler_add(id, _room_list_id_handler, NULL, filter);
@ -363,7 +363,7 @@ iq_http_upload_request(HTTPUpload *upload)
}
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("http_upload_request");
char *id = connection_create_stanza_id("http_upload_request");
xmpp_stanza_t *iq = stanza_create_http_upload_request(ctx, id, jid, upload);
// TODO add free func
iq_id_handler_add(id, _http_upload_response_id_handler, NULL, upload);
@ -379,7 +379,7 @@ void
iq_disco_info_request(gchar *jid)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("disco_info");
char *id = connection_create_stanza_id("disco_info");
xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, jid, NULL);
iq_id_handler_add(id, _disco_info_response_id_handler, NULL, NULL);
@ -394,7 +394,7 @@ void
iq_disco_info_request_onconnect(gchar *jid)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("disco_info_onconnect");
char *id = connection_create_stanza_id("disco_info_onconnect");
xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, jid, NULL);
iq_id_handler_add(id, _disco_info_response_id_handler_onconnect, NULL, NULL);
@ -409,7 +409,7 @@ void
iq_last_activity_request(gchar *jid)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("lastactivity");
char *id = connection_create_stanza_id("lastactivity");
xmpp_stanza_t *iq = stanza_create_last_activity_iq(ctx, id, jid);
iq_id_handler_add(id, _last_activity_response_id_handler, NULL, NULL);
@ -424,7 +424,7 @@ void
iq_room_info_request(const char *const room, gboolean display_result)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("room_disco_info");
char *id = connection_create_stanza_id("room_disco_info");
xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, room, NULL);
ProfRoomInfoData *cb_data = malloc(sizeof(ProfRoomInfoData));

View File

@ -139,7 +139,7 @@ message_send_chat(const char *const barejid, const char *const msg, const char *
char *state = chat_session_get_state(barejid);
char *jid = chat_session_get_jid(barejid);
char *id = create_unique_id("msg");
char *id = connection_create_stanza_id("msg");
xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
xmpp_message_set_body(message, msg);
@ -170,7 +170,7 @@ message_send_chat_pgp(const char *const barejid, const char *const msg, gboolean
char *state = chat_session_get_state(barejid);
char *jid = chat_session_get_jid(barejid);
char *id = create_unique_id("msg");
char *id = connection_create_stanza_id("msg");
xmpp_stanza_t *message = NULL;
#ifdef HAVE_LIBGPGME
@ -229,7 +229,7 @@ message_send_chat_otr(const char *const barejid, const char *const msg, gboolean
char *state = chat_session_get_state(barejid);
char *jid = chat_session_get_jid(barejid);
char *id = create_unique_id("msg");
char *id = connection_create_stanza_id("msg");
xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, barejid, id);
xmpp_message_set_body(message, msg);
@ -258,7 +258,7 @@ void
message_send_private(const char *const fulljid, const char *const msg, const char *const oob_url)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("prv");
char *id = connection_create_stanza_id("prv");
xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, fulljid, id);
xmpp_message_set_body(message, msg);
@ -277,7 +277,7 @@ void
message_send_groupchat(const char *const roomjid, const char *const msg, const char *const oob_url)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("muc");
char *id = connection_create_stanza_id("muc");
xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_GROUPCHAT, roomjid, id);
xmpp_message_set_body(message, msg);
@ -584,7 +584,7 @@ _message_send_receipt(const char *const fulljid, const char *const message_id)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("receipt");
char *id = connection_create_stanza_id("receipt");
xmpp_stanza_t *message = xmpp_message_new(ctx, NULL, fulljid, id);
free(id);

View File

@ -128,7 +128,7 @@ presence_subscription(const char *const jid, const jabber_subscr_t action)
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *presence = xmpp_presence_new(ctx);
char *id = create_unique_id("sub");
char *id = connection_create_stanza_id("sub");
xmpp_stanza_set_id(presence, id);
free(id);
@ -211,7 +211,7 @@ presence_send(const resource_presence_t presence_type, const int idle, char *sig
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *presence = xmpp_presence_new(ctx);
char *id = create_unique_id("presence");
char *id = connection_create_stanza_id("presence");
xmpp_stanza_set_id(presence, id);
free(id);
@ -579,7 +579,7 @@ _handle_caps(const char *const jid, XMPPCaps *caps)
caps_map_jid_to_ver(jid, caps->ver);
} else {
log_info("Capabilities cache miss: %s, for %s, sending service discovery request", caps->ver, jid);
char *id = create_unique_id("caps");
char *id = connection_create_stanza_id("caps");
iq_send_caps_request(jid, id, caps->node, caps->ver);
free(id);
}
@ -588,14 +588,14 @@ _handle_caps(const char *const jid, XMPPCaps *caps)
// unsupported hash, xep-0115, associate with JID, no cache
} else if (caps->hash) {
log_info("Hash %s not supported: %s, sending service discovery request", caps->hash, jid);
char *id = create_unique_id("caps");
char *id = connection_create_stanza_id("caps");
iq_send_caps_request_for_jid(jid, id, caps->node, caps->ver);
free(id);
// no hash, legacy caps, cache against node#ver
} else if (caps->node && caps->ver) {
log_info("No hash specified: %s, legacy request made for %s#%s", jid, caps->node, caps->ver);
char *id = create_unique_id("caps");
char *id = connection_create_stanza_id("caps");
iq_send_caps_request_legacy(jid, id, caps->node, caps->ver);
free(id);
} else {

View File

@ -91,7 +91,7 @@ void
roster_send_add_new(const char *const barejid, const char *const name)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("roster");
char *id = connection_create_stanza_id("roster");
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, id, barejid, name, NULL);
free(id);
iq_send_stanza(iq);
@ -111,7 +111,7 @@ void
roster_send_name_change(const char *const barejid, const char *const new_name, GSList *groups)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("roster");
char *id = connection_create_stanza_id("roster");
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, id, barejid, new_name, groups);
free(id);
iq_send_stanza(iq);
@ -130,7 +130,7 @@ roster_send_add_to_group(const char *const group, PContact contact)
new_groups = g_slist_append(new_groups, strdup(group));
// add an id handler to handle the response
char *unique_id = create_unique_id(NULL);
char *unique_id = connection_create_stanza_id(NULL);
GroupData *data = malloc(sizeof(GroupData));
data->group = strdup(group);
if (p_contact_name(contact)) {
@ -174,7 +174,7 @@ roster_send_remove_from_group(const char *const group, PContact contact)
xmpp_ctx_t * const ctx = connection_get_ctx();
// add an id handler to handle the response
char *unique_id = create_unique_id(NULL);
char *unique_id = connection_create_stanza_id(NULL);
GroupData *data = malloc(sizeof(GroupData));
data->group = strdup(group);
if (p_contact_name(contact)) {

View File

@ -132,7 +132,7 @@ xmpp_stanza_t*
stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char *const jid,
const gboolean autojoin, const char *const nick)
{
char *id = create_unique_id("bookmark_add");
char *id = connection_create_stanza_id("bookmark_add");
xmpp_stanza_t *stanza = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
@ -278,7 +278,7 @@ stanza_create_http_upload_request(xmpp_ctx_t *ctx, const char *const id,
xmpp_stanza_t*
stanza_enable_carbons(xmpp_ctx_t *ctx)
{
char *id = create_unique_id("carbons");
char *id = connection_create_stanza_id("carbons");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
@ -295,7 +295,7 @@ stanza_enable_carbons(xmpp_ctx_t *ctx)
xmpp_stanza_t*
stanza_disable_carbons(xmpp_ctx_t *ctx)
{
char *id = create_unique_id("carbons");
char *id = connection_create_stanza_id("carbons");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
@ -312,7 +312,7 @@ stanza_disable_carbons(xmpp_ctx_t *ctx)
xmpp_stanza_t*
stanza_create_chat_state(xmpp_ctx_t *ctx, const char *const fulljid, const char *const state)
{
char *id = create_unique_id(NULL);
char *id = connection_create_stanza_id(NULL);
xmpp_stanza_t *msg = xmpp_message_new(ctx, STANZA_TYPE_CHAT, fulljid, id);
free(id);
@ -432,7 +432,7 @@ stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *cons
xmpp_stanza_t*
stanza_create_roster_remove_set(xmpp_ctx_t *ctx, const char *const barejid)
{
char *id = create_unique_id("roster");
char *id = connection_create_stanza_id("roster");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
@ -498,7 +498,7 @@ xmpp_stanza_t*
stanza_create_invite(xmpp_ctx_t *ctx, const char *const room,
const char *const contact, const char *const reason, const char *const password)
{
char *id = create_unique_id(NULL);
char *id = connection_create_stanza_id(NULL);
xmpp_stanza_t *message = xmpp_message_new(ctx, NULL, contact, id);
free(id);
@ -524,7 +524,7 @@ xmpp_stanza_t*
stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char *const room,
const char *const contact, const char *const reason)
{
char *id = create_unique_id(NULL);
char *id = connection_create_stanza_id(NULL);
xmpp_stanza_t *message = xmpp_message_new(ctx, NULL, room, id);
free(id);
@ -616,7 +616,7 @@ stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char *const room,
xmpp_stanza_t*
stanza_create_instant_room_request_iq(xmpp_ctx_t *ctx, const char *const room_jid)
{
char *id = create_unique_id("room");
char *id = connection_create_stanza_id("room");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
xmpp_stanza_set_to(iq, room_jid);
@ -642,7 +642,7 @@ stanza_create_instant_room_request_iq(xmpp_ctx_t *ctx, const char *const room_ji
xmpp_stanza_t*
stanza_create_instant_room_destroy_iq(xmpp_ctx_t *ctx, const char *const room_jid)
{
char *id = create_unique_id("room");
char *id = connection_create_stanza_id("room");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
xmpp_stanza_set_to(iq, room_jid);
@ -666,7 +666,7 @@ stanza_create_instant_room_destroy_iq(xmpp_ctx_t *ctx, const char *const room_ji
xmpp_stanza_t*
stanza_create_room_config_request_iq(xmpp_ctx_t *ctx, const char *const room_jid)
{
char *id = create_unique_id("room");
char *id = connection_create_stanza_id("room");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
free(id);
xmpp_stanza_set_to(iq, room_jid);
@ -684,7 +684,7 @@ stanza_create_room_config_request_iq(xmpp_ctx_t *ctx, const char *const room_jid
xmpp_stanza_t*
stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx, const char *const room_jid)
{
char *id = create_unique_id("room");
char *id = connection_create_stanza_id("room");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
xmpp_stanza_set_to(iq, room_jid);
@ -710,7 +710,7 @@ stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx, const char *const room_jid)
xmpp_stanza_t*
stanza_create_room_affiliation_list_iq(xmpp_ctx_t *ctx, const char *const room, const char *const affiliation)
{
char *id = create_unique_id("affiliation_get");
char *id = connection_create_stanza_id("affiliation_get");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
free(id);
xmpp_stanza_set_to(iq, room);
@ -734,7 +734,7 @@ stanza_create_room_affiliation_list_iq(xmpp_ctx_t *ctx, const char *const room,
xmpp_stanza_t*
stanza_create_room_role_list_iq(xmpp_ctx_t *ctx, const char *const room, const char *const role)
{
char *id = create_unique_id("role_get");
char *id = connection_create_stanza_id("role_get");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
free(id);
xmpp_stanza_set_to(iq, room);
@ -759,7 +759,7 @@ xmpp_stanza_t*
stanza_create_room_affiliation_set_iq(xmpp_ctx_t *ctx, const char *const room, const char *const jid,
const char *const affiliation, const char *const reason)
{
char *id = create_unique_id("affiliation_set");
char *id = connection_create_stanza_id("affiliation_set");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
xmpp_stanza_set_to(iq, room);
@ -797,7 +797,7 @@ xmpp_stanza_t*
stanza_create_room_role_set_iq(xmpp_ctx_t *const ctx, const char *const room, const char *const nick,
const char *const role, const char *const reason)
{
char *id = create_unique_id("role_set");
char *id = connection_create_stanza_id("role_set");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
xmpp_stanza_set_to(iq, room);
@ -835,7 +835,7 @@ xmpp_stanza_t*
stanza_create_room_kick_iq(xmpp_ctx_t *const ctx, const char *const room, const char *const nick,
const char *const reason)
{
char *id = create_unique_id("room_kick");
char *id = connection_create_stanza_id("room_kick");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
xmpp_stanza_set_to(iq, room);
@ -872,7 +872,7 @@ stanza_create_room_kick_iq(xmpp_ctx_t *const ctx, const char *const room, const
xmpp_stanza_t*
stanza_create_software_version_iq(xmpp_ctx_t *ctx, const char *const fulljid)
{
char *id = create_unique_id("sv");
char *id = connection_create_stanza_id("sv");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
free(id);
xmpp_stanza_set_to(iq, fulljid);
@ -958,7 +958,7 @@ stanza_create_last_activity_iq(xmpp_ctx_t *ctx, const char *const id, const char
xmpp_stanza_t*
stanza_create_room_config_submit_iq(xmpp_ctx_t *ctx, const char *const room, DataForm *form)
{
char *id = create_unique_id("roomconf_submit");
char *id = connection_create_stanza_id("roomconf_submit");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
free(id);
xmpp_stanza_set_to(iq, room);
@ -1035,7 +1035,7 @@ stanza_contains_chat_state(xmpp_stanza_t *stanza)
xmpp_stanza_t*
stanza_create_ping_iq(xmpp_ctx_t *ctx, const char *const target)
{
char *id = create_unique_id("ping");
char *id = connection_create_stanza_id("ping");
xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
free(id);
if (target) {
@ -2041,7 +2041,7 @@ stanza_parse_presence(xmpp_stanza_t *stanza, int *err)
static void
_stanza_add_unique_id(xmpp_stanza_t *stanza, char *prefix)
{
char *id = create_unique_id(prefix);
char *id = connection_create_stanza_id(prefix);
xmpp_stanza_set_id(stanza, id);
free(id);
}