mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge pull request #1858 from H3rnand3zzz/cleanup/auto_char
Major cleanup
This commit is contained in:
commit
4814887730
@ -406,7 +406,7 @@ _get_log_filename(const char* const other, const char* const login, GDateTime* d
|
||||
{
|
||||
auto_gchar gchar* chatlogs_dir = files_file_in_account_data_path(DIR_CHATLOGS, login, is_room ? "rooms" : NULL);
|
||||
auto_gchar gchar* logfile_name = g_date_time_format(dt, "%Y_%m_%d.log");
|
||||
auto_gchar gchar* other_ = str_replace(other, "@", "_at_");
|
||||
auto_char char* other_ = str_replace(other, "@", "_at_");
|
||||
auto_gchar gchar* logs_path = g_strdup_printf("%s/%s", chatlogs_dir, other_);
|
||||
gchar* logfile_path = NULL;
|
||||
|
||||
|
@ -3210,14 +3210,14 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gchar** split = g_strsplit(input, " ", 0);
|
||||
auto_gcharv gchar** split = g_strsplit(input, " ", 0);
|
||||
|
||||
if (g_strv_length(split) == 3) {
|
||||
char* field_tag = split[0] + 1;
|
||||
if (form_tag_exists(form, field_tag)) {
|
||||
form_field_type_t field_type = form_get_field_type(form, field_tag);
|
||||
Autocomplete value_ac = form_get_value_ac(form, field_tag);
|
||||
;
|
||||
|
||||
GString* beginning = g_string_new(split[0]);
|
||||
g_string_append(beginning, " ");
|
||||
g_string_append(beginning, split[1]);
|
||||
@ -3225,10 +3225,8 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
|
||||
if (((g_strcmp0(split[1], "add") == 0) || (g_strcmp0(split[1], "remove") == 0))
|
||||
&& field_type == FIELD_LIST_MULTI) {
|
||||
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
|
||||
|
||||
} else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_TEXT_MULTI) {
|
||||
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
|
||||
|
||||
} else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_JID_MULTI) {
|
||||
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
|
||||
}
|
||||
@ -3241,7 +3239,6 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
|
||||
if (form_tag_exists(form, field_tag)) {
|
||||
form_field_type_t field_type = form_get_field_type(form, field_tag);
|
||||
Autocomplete value_ac = form_get_value_ac(form, field_tag);
|
||||
;
|
||||
|
||||
switch (field_type) {
|
||||
case FIELD_BOOLEAN:
|
||||
@ -3261,8 +3258,6 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(split);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
@ -4387,9 +4382,8 @@ _url_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
if ((num_args == 1 && space_at_end) || (num_args == 2 && !space_at_end)) {
|
||||
result = autocomplete_param_with_func(input, "/url save", wins_get_url, previous, window);
|
||||
} else if ((num_args == 2 && space_at_end) || (num_args == 3 && !space_at_end)) {
|
||||
gchar* cmd = g_strdup_printf("/url save %s", args[1]);
|
||||
auto_gchar gchar* cmd = g_strdup_printf("/url save %s", args[1]);
|
||||
result = cmd_ac_complete_filepath(input, cmd, previous);
|
||||
g_free(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2768,7 +2768,7 @@ _cmd_index(const Command* cmd)
|
||||
index_source = g_string_append(index_source, " ");
|
||||
}
|
||||
|
||||
gchar** tokens = g_str_tokenize_and_fold(index_source->str, NULL, NULL);
|
||||
auto_gcharv gchar** tokens = g_str_tokenize_and_fold(index_source->str, NULL, NULL);
|
||||
g_string_free(index_source, TRUE);
|
||||
|
||||
GString* index = g_string_new("");
|
||||
@ -2776,7 +2776,6 @@ _cmd_index(const Command* cmd)
|
||||
index = g_string_append(index, tokens[i]);
|
||||
index = g_string_append(index, " ");
|
||||
}
|
||||
g_strfreev(tokens);
|
||||
|
||||
return g_string_free(index, FALSE);
|
||||
}
|
||||
@ -2786,7 +2785,7 @@ cmd_search_index_any(char* term)
|
||||
{
|
||||
GList* results = NULL;
|
||||
|
||||
gchar** processed_terms = g_str_tokenize_and_fold(term, NULL, NULL);
|
||||
auto_gcharv gchar** processed_terms = g_str_tokenize_and_fold(term, NULL, NULL);
|
||||
int terms_len = g_strv_length(processed_terms);
|
||||
|
||||
for (int i = 0; i < terms_len; i++) {
|
||||
@ -2802,8 +2801,6 @@ cmd_search_index_any(char* term)
|
||||
g_list_free(index_keys);
|
||||
}
|
||||
|
||||
g_strfreev(processed_terms);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -2812,7 +2809,7 @@ cmd_search_index_all(char* term)
|
||||
{
|
||||
GList* results = NULL;
|
||||
|
||||
gchar** terms = g_str_tokenize_and_fold(term, NULL, NULL);
|
||||
auto_gcharv gchar** terms = g_str_tokenize_and_fold(term, NULL, NULL);
|
||||
int terms_len = g_strv_length(terms);
|
||||
|
||||
GList* commands = g_hash_table_get_keys(search_index);
|
||||
@ -2833,7 +2830,6 @@ cmd_search_index_all(char* term)
|
||||
}
|
||||
|
||||
g_list_free(commands);
|
||||
g_strfreev(terms);
|
||||
|
||||
return results;
|
||||
}
|
||||
@ -3039,14 +3035,13 @@ command_mangen(void)
|
||||
create_dir("docs");
|
||||
|
||||
GDateTime* now = g_date_time_new_now_local();
|
||||
gchar* date = g_date_time_format(now, "%F");
|
||||
gchar* header = g_strdup_printf(".TH man 1 \"%s\" \"" PACKAGE_VERSION "\" \"Profanity XMPP client\"\n", date);
|
||||
auto_gchar gchar* date = g_date_time_format(now, "%F");
|
||||
auto_gchar gchar* header = g_strdup_printf(".TH man 1 \"%s\" \"" PACKAGE_VERSION "\" \"Profanity XMPP client\"\n", date);
|
||||
if (!header) {
|
||||
log_error("command_mangen(): could not allocate memory");
|
||||
return;
|
||||
}
|
||||
g_date_time_unref(now);
|
||||
g_free(date);
|
||||
|
||||
GList* curr = cmds;
|
||||
while (curr) {
|
||||
@ -3098,6 +3093,5 @@ command_mangen(void)
|
||||
|
||||
printf("\nProcessed %d commands.\n\n", g_list_length(cmds));
|
||||
|
||||
g_free(header);
|
||||
g_list_free(cmds);
|
||||
}
|
||||
|
@ -505,9 +505,8 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args)
|
||||
gboolean
|
||||
cmd_account_list(ProfWin* window, const char* const command, gchar** args)
|
||||
{
|
||||
gchar** accounts = accounts_get_list();
|
||||
auto_gcharv gchar** accounts = accounts_get_list();
|
||||
cons_show_account_list(accounts);
|
||||
g_strfreev(accounts);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -675,7 +674,7 @@ cmd_account_default(ProfWin* window, const char* const command, gchar** args)
|
||||
gboolean
|
||||
_account_set_jid(char* account_name, char* jid)
|
||||
{
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
if (jidp == NULL) {
|
||||
cons_show("Malformed jid: %s", jid);
|
||||
} else {
|
||||
@ -687,7 +686,6 @@ _account_set_jid(char* account_name, char* jid)
|
||||
}
|
||||
cons_show("");
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -1259,7 +1257,7 @@ cmd_sub(ProfWin* window, const char* const command, gchar** args)
|
||||
jid = chatwin->barejid;
|
||||
}
|
||||
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
|
||||
if (strcmp(subcmd, "allow") == 0) {
|
||||
presence_subscription(jidp->barejid, PRESENCE_SUBSCRIBED);
|
||||
@ -1304,8 +1302,6 @@ cmd_sub(ProfWin* window, const char* const command, gchar** args)
|
||||
cons_bad_cmd_usage(command);
|
||||
}
|
||||
|
||||
jid_destroy(jidp);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -2203,13 +2199,11 @@ cmd_msg(ProfWin* window, const char* const command, gchar** args)
|
||||
if (occupant) {
|
||||
// in case of non-anon muc send regular chatmessage
|
||||
if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS) {
|
||||
Jid* jidp = jid_create(occupant->jid);
|
||||
auto_jid Jid* jidp = jid_create(occupant->jid);
|
||||
|
||||
_cmd_msg_chatwin(jidp->barejid, msg);
|
||||
win_println(window, THEME_DEFAULT, "-", "Starting direct message with occupant \"%s\" from room \"%s\" as \"%s\".", usr, mucwin->roomjid, jidp->barejid);
|
||||
cons_show("Starting direct message with occupant \"%s\" from room \"%s\" as \"%s\".", usr, mucwin->roomjid, jidp->barejid);
|
||||
|
||||
jid_destroy(jidp);
|
||||
} else {
|
||||
// otherwise send mucpm
|
||||
GString* full_jid = g_string_new(mucwin->roomjid);
|
||||
@ -3299,14 +3293,13 @@ cmd_status_get(ProfWin* window, const char* const command, gchar** args)
|
||||
} else {
|
||||
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
|
||||
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
||||
Jid* jid = jid_create(privatewin->fulljid);
|
||||
auto_jid Jid* jid = jid_create(privatewin->fulljid);
|
||||
Occupant* occupant = muc_roster_item(jid->barejid, jid->resourcepart);
|
||||
if (occupant) {
|
||||
win_show_occupant(window, occupant);
|
||||
} else {
|
||||
win_println(window, THEME_DEFAULT, "-", "Error getting contact info.");
|
||||
}
|
||||
jid_destroy(jid);
|
||||
}
|
||||
break;
|
||||
case WIN_CONSOLE:
|
||||
@ -3389,14 +3382,13 @@ cmd_info(ProfWin* window, const char* const command, gchar** args)
|
||||
} else {
|
||||
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
|
||||
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
||||
Jid* jid = jid_create(privatewin->fulljid);
|
||||
auto_jid Jid* jid = jid_create(privatewin->fulljid);
|
||||
Occupant* occupant = muc_roster_item(jid->barejid, jid->resourcepart);
|
||||
if (occupant) {
|
||||
win_show_occupant_info(window, jid->barejid, occupant);
|
||||
} else {
|
||||
win_println(window, THEME_DEFAULT, "-", "Error getting contact info.");
|
||||
}
|
||||
jid_destroy(jid);
|
||||
}
|
||||
break;
|
||||
case WIN_CONSOLE:
|
||||
@ -3431,9 +3423,8 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
occupant = muc_roster_item(mucwin->roomjid, args[0]);
|
||||
if (occupant) {
|
||||
Jid* jidp = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
|
||||
cons_show_caps(jidp->fulljid, occupant->presence);
|
||||
jid_destroy(jidp);
|
||||
} else {
|
||||
cons_show("No such participant \"%s\" in room.", args[0]);
|
||||
}
|
||||
@ -3444,7 +3435,7 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
|
||||
case WIN_CHAT:
|
||||
case WIN_CONSOLE:
|
||||
if (args[0]) {
|
||||
Jid* jid = jid_create(args[0]);
|
||||
auto_jid Jid* jid = jid_create(args[0]);
|
||||
|
||||
if (jid->fulljid == NULL) {
|
||||
cons_show("You must provide a full jid to the /caps command.");
|
||||
@ -3461,7 +3452,6 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
}
|
||||
}
|
||||
jid_destroy(jid);
|
||||
} else {
|
||||
cons_show("You must provide a jid to the /caps command.");
|
||||
}
|
||||
@ -3472,11 +3462,10 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
|
||||
} else {
|
||||
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
|
||||
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
|
||||
Jid* jid = jid_create(privatewin->fulljid);
|
||||
auto_jid Jid* jid = jid_create(privatewin->fulljid);
|
||||
if (jid) {
|
||||
occupant = muc_roster_item(jid->barejid, jid->resourcepart);
|
||||
cons_show_caps(jid->resourcepart, occupant->presence);
|
||||
jid_destroy(jid);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -3491,7 +3480,7 @@ static void
|
||||
_send_software_version_iq_to_fulljid(char* request)
|
||||
{
|
||||
auto_char char* mybarejid = connection_get_barejid();
|
||||
Jid* jid = jid_create(request);
|
||||
auto_jid Jid* jid = jid_create(request);
|
||||
|
||||
if (jid == NULL || jid->fulljid == NULL) {
|
||||
cons_show("You must provide a full jid to the /software command.");
|
||||
@ -3500,7 +3489,6 @@ _send_software_version_iq_to_fulljid(char* request)
|
||||
} else {
|
||||
iq_send_software_version(jid->fulljid);
|
||||
}
|
||||
jid_destroy(jid);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -3520,9 +3508,8 @@ cmd_software(ProfWin* window, const char* const command, gchar** args)
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
Occupant* occupant = muc_roster_item(mucwin->roomjid, args[0]);
|
||||
if (occupant) {
|
||||
Jid* jid = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
|
||||
auto_jid Jid* jid = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
|
||||
iq_send_software_version(jid->fulljid);
|
||||
jid_destroy(jid);
|
||||
} else {
|
||||
cons_show("No such participant \"%s\" in room.", args[0]);
|
||||
}
|
||||
@ -3628,14 +3615,14 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Jid* room_arg = jid_create(args[0]);
|
||||
auto_jid Jid* room_arg = jid_create(args[0]);
|
||||
if (room_arg == NULL) {
|
||||
cons_show_error("Specified room has incorrect format.");
|
||||
cons_show("");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char* room = NULL;
|
||||
auto_gchar gchar* room = NULL;
|
||||
char* nick = NULL;
|
||||
char* passwd = NULL;
|
||||
char* account_name = session_get_account_name();
|
||||
@ -3663,8 +3650,6 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
|
||||
if (!parsed) {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
g_free(room);
|
||||
jid_destroy(room_arg);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -3693,8 +3678,6 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
|
||||
ui_switch_to_room(room);
|
||||
}
|
||||
|
||||
g_free(room);
|
||||
jid_destroy(room_arg);
|
||||
account_free(account);
|
||||
|
||||
return TRUE;
|
||||
@ -4578,8 +4561,8 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gchar* service = NULL;
|
||||
gchar* filter = NULL;
|
||||
auto_gchar gchar* service = NULL;
|
||||
auto_gchar gchar* filter = NULL;
|
||||
if (args[0] != NULL) {
|
||||
if (g_strcmp0(args[0], "service") == 0) {
|
||||
if (args[1] == NULL) {
|
||||
@ -4628,8 +4611,6 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
|
||||
if (args[3] == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
g_free(service);
|
||||
g_free(filter);
|
||||
return TRUE;
|
||||
}
|
||||
g_free(service);
|
||||
@ -4638,8 +4619,6 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
|
||||
if (args[3] == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
g_free(service);
|
||||
g_free(filter);
|
||||
return TRUE;
|
||||
}
|
||||
g_free(filter);
|
||||
@ -4647,8 +4626,6 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
|
||||
} else {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
g_free(service);
|
||||
g_free(filter);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@ -4661,8 +4638,6 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
|
||||
} else {
|
||||
cons_show("Account MUC service property not found.");
|
||||
account_free(account);
|
||||
g_free(service);
|
||||
g_free(filter);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@ -4675,9 +4650,6 @@ cmd_rooms(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
iq_room_list_request(service, filter);
|
||||
|
||||
g_free(service);
|
||||
g_free(filter);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4866,9 +4838,8 @@ cmd_bookmark_ignore(ProfWin* window, const char* const command, gchar** args)
|
||||
// `/bookmark ignore` lists them
|
||||
if (args[1] == NULL) {
|
||||
gsize len = 0;
|
||||
gchar** list = bookmark_ignore_list(&len);
|
||||
auto_gcharv gchar** list = bookmark_ignore_list(&len);
|
||||
cons_show_bookmarks_ignore(list, len);
|
||||
g_strfreev(list);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4902,9 +4873,8 @@ cmd_disco(ProfWin* window, const char* const command, gchar** args)
|
||||
if (args[1]) {
|
||||
jid = g_string_append(jid, args[1]);
|
||||
} else {
|
||||
Jid* jidp = jid_create(connection_get_fulljid());
|
||||
auto_jid Jid* jidp = jid_create(connection_get_fulljid());
|
||||
jid = g_string_append(jid, jidp->domainpart);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "info") == 0) {
|
||||
@ -5102,13 +5072,12 @@ cmd_lastactivity(ProfWin* window, const char* const command, gchar** args)
|
||||
|
||||
if ((g_strcmp0(args[0], "get") == 0)) {
|
||||
if (args[1] == NULL) {
|
||||
Jid* jidp = jid_create(connection_get_fulljid());
|
||||
auto_jid Jid* jidp = jid_create(connection_get_fulljid());
|
||||
GString* jid = g_string_new(jidp->domainpart);
|
||||
|
||||
iq_last_activity_request(jid->str);
|
||||
|
||||
g_string_free(jid, TRUE);
|
||||
jid_destroy(jidp);
|
||||
|
||||
return TRUE;
|
||||
} else {
|
||||
@ -8508,18 +8477,16 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
|
||||
{
|
||||
if (g_str_has_prefix(command, "/field") && window->type == WIN_CONFIG) {
|
||||
gboolean result = FALSE;
|
||||
gchar** args = parse_args_with_freetext(inp, 1, 2, &result);
|
||||
auto_gcharv gchar** args = parse_args_with_freetext(inp, 1, 2, &result);
|
||||
if (!result) {
|
||||
win_println(window, THEME_DEFAULT, "!", "Invalid command, see /form help");
|
||||
result = TRUE;
|
||||
} else {
|
||||
gchar** tokens = g_strsplit(inp, " ", 2);
|
||||
auto_gcharv gchar** tokens = g_strsplit(inp, " ", 2);
|
||||
char* field = tokens[0] + 1;
|
||||
result = cmd_form_field(window, field, args);
|
||||
g_strfreev(tokens);
|
||||
}
|
||||
|
||||
g_strfreev(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -8527,7 +8494,7 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
|
||||
gboolean result = FALSE;
|
||||
|
||||
if (cmd) {
|
||||
gchar** args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
|
||||
auto_gcharv gchar** args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
|
||||
if (result == FALSE) {
|
||||
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
|
||||
return TRUE;
|
||||
@ -8536,20 +8503,17 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
|
||||
int i = 0;
|
||||
while (cmd->sub_funcs[i].cmd) {
|
||||
if (g_strcmp0(args[0], (char*)cmd->sub_funcs[i].cmd) == 0) {
|
||||
result = cmd->sub_funcs[i].func(window, command, args);
|
||||
goto out;
|
||||
return cmd->sub_funcs[i].func(window, command, args);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (!cmd->func) {
|
||||
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
|
||||
result = TRUE;
|
||||
goto out;
|
||||
return TRUE;
|
||||
}
|
||||
result = cmd->func(window, command, args);
|
||||
out:
|
||||
g_strfreev(args);
|
||||
|
||||
return result;
|
||||
} else if (plugins_run_command(inp)) {
|
||||
return TRUE;
|
||||
@ -9270,15 +9234,15 @@ gboolean
|
||||
cmd_stamp(ProfWin* window, const char* const command, gchar** args)
|
||||
{
|
||||
if (g_strv_length(args) == 0) {
|
||||
auto_gchar gchar* def = prefs_get_string(PREF_OUTGOING_STAMP);
|
||||
if (def) {
|
||||
cons_show("The outgoing stamp is: %s", def);
|
||||
auto_gchar gchar* def_incoming = prefs_get_string(PREF_OUTGOING_STAMP);
|
||||
if (def_incoming) {
|
||||
cons_show("The outgoing stamp is: %s", def_incoming);
|
||||
} else {
|
||||
cons_show("The default outgoing stamp is used.");
|
||||
}
|
||||
def = prefs_get_string(PREF_INCOMING_STAMP);
|
||||
if (def) {
|
||||
cons_show("The incoming stamp is: %s", def);
|
||||
auto_gchar gchar* def_outgoing = prefs_get_string(PREF_INCOMING_STAMP);
|
||||
if (def_outgoing) {
|
||||
cons_show("The incoming stamp is: %s", def_outgoing);
|
||||
} else {
|
||||
cons_show("The default incoming stamp is used.");
|
||||
}
|
||||
@ -9572,15 +9536,13 @@ _url_http_method(ProfWin* window, const char* cmd_template, gchar* url, gchar* p
|
||||
void
|
||||
_url_external_method(const char* cmd_template, const char* url, gchar* filename)
|
||||
{
|
||||
gchar** argv = format_call_external_argv(cmd_template, url, filename);
|
||||
auto_gcharv gchar** argv = format_call_external_argv(cmd_template, url, filename);
|
||||
|
||||
if (!call_external(argv)) {
|
||||
cons_show_error("Unable to call external executable for url: check the logs for more information.");
|
||||
} else {
|
||||
cons_show("URL '%s' has been called with '%s'.", url, cmd_template);
|
||||
}
|
||||
|
||||
g_strfreev(argv);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -9680,19 +9642,16 @@ _cmd_executable_template(const preference_t setting, const char* command, gchar*
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[1], "set") == 0 && num_args >= 3) {
|
||||
gchar* str = g_strjoinv(" ", &args[2]);
|
||||
auto_gchar gchar* str = g_strjoinv(" ", &args[2]);
|
||||
prefs_set_string(setting, str);
|
||||
cons_show("`%s` command set to invoke '%s'", command, str);
|
||||
g_free(str);
|
||||
|
||||
} else if (g_strcmp0(args[1], "default") == 0) {
|
||||
prefs_set_string(setting, NULL);
|
||||
gchar* def = prefs_get_string(setting);
|
||||
auto_gchar gchar* def = prefs_get_string(setting);
|
||||
if (def == NULL) {
|
||||
def = g_strdup("built-in method");
|
||||
}
|
||||
cons_show("`%s` command set to invoke %s (default)", command, def);
|
||||
g_free(def);
|
||||
} else {
|
||||
cons_bad_cmd_usage(command);
|
||||
}
|
||||
@ -10073,10 +10032,9 @@ cmd_vcard_get(ProfWin* window, const char* const command, gchar** args)
|
||||
if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS) {
|
||||
// non-anon muc: get the user's jid and send vcard request to them
|
||||
Occupant* occupant = muc_roster_item(mucwin->roomjid, user);
|
||||
Jid* jid_occupant = jid_create(occupant->jid);
|
||||
auto_jid Jid* jid_occupant = jid_create(occupant->jid);
|
||||
|
||||
vcard_print(ctx, window, jid_occupant->barejid);
|
||||
jid_destroy(jid_occupant);
|
||||
} else {
|
||||
// anon muc: send the vcard request through the MUC's server
|
||||
GString* full_jid = g_string_new(mucwin->roomjid);
|
||||
@ -10130,7 +10088,7 @@ cmd_vcard_photo(ProfWin* window, const char* const command, gchar** args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char* jid = NULL;
|
||||
auto_gchar gchar* jid = NULL;
|
||||
char* filepath = NULL;
|
||||
int index = 0;
|
||||
|
||||
@ -10142,10 +10100,9 @@ cmd_vcard_photo(ProfWin* window, const char* const command, gchar** args)
|
||||
if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS) {
|
||||
// non-anon muc: get the user's jid and send vcard request to them
|
||||
Occupant* occupant = muc_roster_item(mucwin->roomjid, user);
|
||||
Jid* jid_occupant = jid_create(occupant->jid);
|
||||
auto_jid Jid* jid_occupant = jid_create(occupant->jid);
|
||||
|
||||
jid = g_strdup(jid_occupant->barejid);
|
||||
jid_destroy(jid_occupant);
|
||||
} else {
|
||||
// anon muc: send the vcard request through the MUC's server
|
||||
jid = g_strdup_printf("%s/%s", mucwin->roomjid, user);
|
||||
@ -10242,9 +10199,6 @@ cmd_vcard_photo(ProfWin* window, const char* const command, gchar** args)
|
||||
cons_bad_cmd_usage(command);
|
||||
}
|
||||
|
||||
if (!jidless) {
|
||||
g_free(jid);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
95
src/common.c
95
src/common.c
@ -70,6 +70,11 @@ struct curl_data_t
|
||||
|
||||
static size_t _data_callback(void* ptr, size_t size, size_t nmemb, void* data);
|
||||
|
||||
/**
|
||||
* Frees the memory allocated for a gchar* string.
|
||||
*
|
||||
* @param str Pointer to the gchar* string to be freed. If NULL, no action is taken.
|
||||
*/
|
||||
void
|
||||
auto_free_gchar(gchar** str)
|
||||
{
|
||||
@ -78,6 +83,25 @@ auto_free_gchar(gchar** str)
|
||||
g_free(*str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the memory allocated for a guchar* string.
|
||||
*
|
||||
* @param str Pointer to the guchar* string to be freed. If NULL, no action is taken.
|
||||
*/
|
||||
void
|
||||
auto_free_guchar(guchar** ptr)
|
||||
{
|
||||
if (ptr == NULL) {
|
||||
return;
|
||||
}
|
||||
g_free(*ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the memory allocated for a gchar** string array.
|
||||
*
|
||||
* @param args Pointer to the gchar** string array to be freed. If NULL, no action is taken.
|
||||
*/
|
||||
void
|
||||
auto_free_gcharv(gchar*** args)
|
||||
{
|
||||
@ -86,6 +110,11 @@ auto_free_gcharv(gchar*** args)
|
||||
g_strfreev(*args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the memory allocated for a char* string.
|
||||
*
|
||||
* @param str Pointer to the char* string to be freed. If NULL, no action is taken.
|
||||
*/
|
||||
void
|
||||
auto_free_char(char** str)
|
||||
{
|
||||
@ -125,6 +154,18 @@ copy_file(const char* const sourcepath, const char* const targetpath, const gboo
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Replaces all occurrences of a substring with a replacement in a string.
|
||||
*
|
||||
* @param string The input string to perform replacement on.
|
||||
* @param substr The substring to be replaced.
|
||||
* @param replacement The replacement string.
|
||||
* @return The modified string with replacements, or NULL on failure.
|
||||
*
|
||||
* @note Remember to free returned value using `auto_char` or `free()` when it is no longer needed.
|
||||
* @note If 'string' is NULL, the function returns NULL.
|
||||
* @note If 'substr' or 'replacement' is NULL or an empty string, a duplicate of 'string' is returned.
|
||||
*/
|
||||
char*
|
||||
str_replace(const char* string, const char* substr,
|
||||
const char* replacement)
|
||||
@ -487,6 +528,18 @@ call_external(gchar** argv)
|
||||
return is_successful;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Formats an argument vector for calling an external command with placeholders.
|
||||
*
|
||||
* This function constructs an argument vector (argv) based on the provided template string, replacing placeholders ("%u" and "%p") with the provided URL and filename, respectively.
|
||||
*
|
||||
* @param template The template string with placeholders.
|
||||
* @param url The URL to replace "%u" (or NULL to skip).
|
||||
* @param filename The filename to replace "%p" (or NULL to skip).
|
||||
* @return The constructed argument vector (argv) as a null-terminated array of strings.
|
||||
*
|
||||
* @note Remember to free the returned argument vector using `auto_gcharv` or `g_strfreev()`.
|
||||
*/
|
||||
gchar**
|
||||
format_call_external_argv(const char* template, const char* url, const char* filename)
|
||||
{
|
||||
@ -539,24 +592,38 @@ _has_directory_suffix(const char* path)
|
||||
|| g_str_has_suffix(path, G_DIR_SEPARATOR_S));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Extracts the basename from a given URL.
|
||||
*
|
||||
* @param url The URL to extract the basename from.
|
||||
* @return The extracted basename or a default name ("index") if the basename has a directory suffix.
|
||||
*
|
||||
* @note The returned string must be freed by the caller using `auto_free` or `free()`.
|
||||
*/
|
||||
char*
|
||||
basename_from_url(const char* url)
|
||||
{
|
||||
const char* default_name = "index";
|
||||
|
||||
GFile* file = g_file_new_for_commandline_arg(url);
|
||||
char* basename = g_file_get_basename(file);
|
||||
|
||||
if (_has_directory_suffix(basename)) {
|
||||
g_free(basename);
|
||||
basename = strdup(default_name);
|
||||
}
|
||||
|
||||
auto_gchar gchar* basename = g_file_get_basename(file);
|
||||
g_object_unref(file);
|
||||
|
||||
return basename;
|
||||
if (_has_directory_suffix(basename)) {
|
||||
return strdup(default_name);
|
||||
}
|
||||
|
||||
return strdup(basename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands the provided path by resolving special characters like '~' and 'file://'.
|
||||
*
|
||||
* @param path The path to expand.
|
||||
* @return The expanded path.
|
||||
*
|
||||
* @note Remember to free the returned value using `auto_gchar` or `g_free()`.
|
||||
*/
|
||||
gchar*
|
||||
get_expanded_path(const char* path)
|
||||
{
|
||||
@ -570,6 +637,15 @@ get_expanded_path(const char* path)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a unique filename based on the provided URL and path.
|
||||
*
|
||||
* @param url The URL to derive the basename from.
|
||||
* @param path The path to prepend to the generated filename. If NULL, the current directory is used.
|
||||
* @return A unique filename combining the path and derived basename from the URL.
|
||||
*
|
||||
* @note Remember to free the returned value using `auto_gchar` or `g_free()`.
|
||||
*/
|
||||
gchar*
|
||||
unique_filename_from_url(const char* url, const char* path)
|
||||
{
|
||||
@ -589,9 +665,8 @@ unique_filename_from_url(const char* url, const char* path)
|
||||
if (_has_directory_suffix(realpath) || g_file_test(realpath, G_FILE_TEST_IS_DIR)) {
|
||||
// The target should be used as a directory. Assume that the basename
|
||||
// should be derived from the URL.
|
||||
char* basename = basename_from_url(url);
|
||||
auto_char char* basename = basename_from_url(url);
|
||||
filename = g_build_filename(g_file_peek_path(target), basename, NULL);
|
||||
g_free(basename);
|
||||
} else {
|
||||
// Just use the target as filename.
|
||||
filename = g_build_filename(g_file_peek_path(target), NULL);
|
||||
|
47
src/common.h
47
src/common.h
@ -31,6 +31,9 @@
|
||||
* statement from your version. If you delete this exception statement from all
|
||||
* source files in the program, then also delete it here.
|
||||
*
|
||||
* @file common.h
|
||||
*
|
||||
* @brief Common utilities for the project.
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H
|
||||
@ -51,12 +54,56 @@
|
||||
#define PROF_STRINGIFY(n) PROF_STRINGIFY_(n)
|
||||
|
||||
void auto_free_gchar(gchar** str);
|
||||
|
||||
/**
|
||||
* Macro for automatically freeing a gchar* string when it goes out of scope.
|
||||
*
|
||||
* Example usage:
|
||||
* ```
|
||||
* auto_gchar gchar* myString = g_strdup("Hello, world!");
|
||||
* ```
|
||||
*/
|
||||
#define auto_gchar __attribute__((__cleanup__(auto_free_gchar)))
|
||||
|
||||
void auto_free_gcharv(gchar*** args);
|
||||
|
||||
/**
|
||||
* Macro for automatically freeing a gchar** string array when it goes out of scope.
|
||||
*
|
||||
* Example usage:
|
||||
* ```
|
||||
* auto_gcharv gchar** stringArray = g_strsplit("Hello, world!", " ", -1);
|
||||
* ```
|
||||
*/
|
||||
#define auto_gcharv __attribute__((__cleanup__(auto_free_gcharv)))
|
||||
|
||||
void auto_free_char(char** str);
|
||||
|
||||
/**
|
||||
* Macro for automatically freeing a char* string when it goes out of scope.
|
||||
*
|
||||
* Example usage:
|
||||
* ```
|
||||
* auto_char char* myString = strdup("Hello, world!");
|
||||
* ```
|
||||
*/
|
||||
#define auto_char __attribute__((__cleanup__(auto_free_char)))
|
||||
|
||||
void auto_free_guchar(guchar** str);
|
||||
|
||||
/**
|
||||
* @brief Macro for automatically freeing a guchar* string when it goes out of scope.
|
||||
*
|
||||
* This macro is used to automatically free a guchar* string when it goes out of scope.
|
||||
* It utilizes the `auto_free_guchar` function and should be placed before the variable declaration.
|
||||
*
|
||||
* Example usage:
|
||||
* ```
|
||||
* auto_guchar guchar* myString = g_base64_decode("SGVsbG8sIHdvcmxkIQ==", NULL);
|
||||
* ```
|
||||
*/
|
||||
#define auto_guchar __attribute__((__cleanup__(auto_free_guchar)))
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
#define STR_MAYBE_NULL(p) (p) ?: "(null)"
|
||||
#else
|
||||
|
@ -108,9 +108,8 @@ account_new(gchar* name, gchar* jid, gchar* password, gchar* eval_password, gboo
|
||||
new_account->muc_service = muc_service;
|
||||
|
||||
if (muc_nick == NULL) {
|
||||
Jid* jidp = jid_create(new_account->jid);
|
||||
auto_jid Jid* jidp = jid_create(new_account->jid);
|
||||
new_account->muc_nick = strdup(jidp->domainpart);
|
||||
jid_destroy(jidp);
|
||||
} else {
|
||||
new_account->muc_nick = muc_nick;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ accounts_load(void)
|
||||
|
||||
// create the logins searchable list for autocompletion
|
||||
gsize naccounts;
|
||||
gchar** account_names = g_key_file_get_groups(accounts, &naccounts);
|
||||
auto_gcharv gchar** account_names = g_key_file_get_groups(accounts, &naccounts);
|
||||
|
||||
for (gsize i = 0; i < naccounts; i++) {
|
||||
autocomplete_add(all_ac, account_names[i]);
|
||||
@ -86,8 +86,6 @@ accounts_load(void)
|
||||
autocomplete_add(enabled_ac, account_names[i]);
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(account_names);
|
||||
}
|
||||
|
||||
void
|
||||
@ -127,8 +125,8 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
|
||||
{
|
||||
// set account name and resource
|
||||
const char* barejid = account_name;
|
||||
char* resource = jid_random_resource();
|
||||
Jid* jid = jid_create(account_name);
|
||||
auto_gchar gchar* resource = jid_random_resource();
|
||||
auto_jid Jid* jid = jid_create(account_name);
|
||||
if (jid) {
|
||||
barejid = jid->barejid;
|
||||
if (jid->resourcepart) {
|
||||
@ -137,8 +135,6 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
|
||||
}
|
||||
|
||||
if (g_key_file_has_group(accounts, account_name)) {
|
||||
g_free(resource);
|
||||
jid_destroy(jid);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -158,7 +154,7 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
|
||||
g_key_file_set_string(accounts, account_name, "auth.policy", auth_policy);
|
||||
}
|
||||
|
||||
Jid* jidp = jid_create(barejid);
|
||||
auto_jid Jid* jidp = jid_create(barejid);
|
||||
|
||||
if (jidp->localpart == NULL) {
|
||||
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart);
|
||||
@ -166,8 +162,6 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
|
||||
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart);
|
||||
}
|
||||
|
||||
jid_destroy(jidp);
|
||||
|
||||
g_key_file_set_string(accounts, account_name, "presence.last", "online");
|
||||
g_key_file_set_string(accounts, account_name, "presence.login", "online");
|
||||
g_key_file_set_integer(accounts, account_name, "priority.online", 0);
|
||||
@ -179,9 +173,6 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
|
||||
_save_accounts();
|
||||
autocomplete_add(all_ac, account_name);
|
||||
autocomplete_add(enabled_ac, account_name);
|
||||
|
||||
jid_destroy(jid);
|
||||
g_free(resource);
|
||||
}
|
||||
|
||||
int
|
||||
@ -252,30 +243,27 @@ accounts_get_account(const char* const name)
|
||||
|
||||
gsize length;
|
||||
GList* otr_manual = NULL;
|
||||
gchar** manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
|
||||
auto_gcharv gchar** manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
|
||||
if (manual) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
otr_manual = g_list_append(otr_manual, strdup(manual[i]));
|
||||
}
|
||||
g_strfreev(manual);
|
||||
}
|
||||
|
||||
GList* otr_opportunistic = NULL;
|
||||
gchar** opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
|
||||
auto_gcharv gchar** opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
|
||||
if (opportunistic) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i]));
|
||||
}
|
||||
g_strfreev(opportunistic);
|
||||
}
|
||||
|
||||
GList* otr_always = NULL;
|
||||
gchar** always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
|
||||
auto_gcharv gchar** always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
|
||||
if (always) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
otr_always = g_list_append(otr_always, strdup(always[i]));
|
||||
}
|
||||
g_strfreev(always);
|
||||
}
|
||||
|
||||
gchar* omemo_policy = NULL;
|
||||
@ -284,39 +272,35 @@ accounts_get_account(const char* const name)
|
||||
}
|
||||
|
||||
GList* omemo_enabled = NULL;
|
||||
gchar** omemo_enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL);
|
||||
auto_gcharv gchar** omemo_enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL);
|
||||
if (omemo_enabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
omemo_enabled = g_list_append(omemo_enabled, strdup(omemo_enabled_list[i]));
|
||||
}
|
||||
g_strfreev(omemo_enabled_list);
|
||||
}
|
||||
|
||||
GList* omemo_disabled = NULL;
|
||||
gchar** omemo_disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL);
|
||||
auto_gcharv gchar** omemo_disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL);
|
||||
if (omemo_disabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
omemo_disabled = g_list_append(omemo_disabled, strdup(omemo_disabled_list[i]));
|
||||
}
|
||||
g_strfreev(omemo_disabled_list);
|
||||
}
|
||||
|
||||
GList* ox_enabled = NULL;
|
||||
gchar** ox_enabled_list = g_key_file_get_string_list(accounts, name, "ox.enabled", &length, NULL);
|
||||
auto_gcharv gchar** ox_enabled_list = g_key_file_get_string_list(accounts, name, "ox.enabled", &length, NULL);
|
||||
if (ox_enabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
ox_enabled = g_list_append(ox_enabled, strdup(ox_enabled_list[i]));
|
||||
}
|
||||
g_strfreev(ox_enabled_list);
|
||||
}
|
||||
|
||||
GList* pgp_enabled = NULL;
|
||||
gchar** pgp_enabled_list = g_key_file_get_string_list(accounts, name, "pgp.enabled", &length, NULL);
|
||||
auto_gcharv gchar** pgp_enabled_list = g_key_file_get_string_list(accounts, name, "pgp.enabled", &length, NULL);
|
||||
if (pgp_enabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
pgp_enabled = g_list_append(pgp_enabled, strdup(pgp_enabled_list[i]));
|
||||
}
|
||||
g_strfreev(pgp_enabled_list);
|
||||
}
|
||||
|
||||
gchar* pgp_keyid = NULL;
|
||||
@ -433,10 +417,9 @@ accounts_rename(const char* const account_name, const char* const new_name)
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(string_keys); i++) {
|
||||
char* value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
|
||||
auto_gchar gchar* value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
|
||||
if (value) {
|
||||
g_key_file_set_string(accounts, new_name, string_keys[i], value);
|
||||
g_free(value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -462,7 +445,7 @@ accounts_account_exists(const char* const account_name)
|
||||
void
|
||||
accounts_set_jid(const char* const account_name, const char* const value)
|
||||
{
|
||||
Jid* jid = jid_create(value);
|
||||
auto_jid Jid* jid = jid_create(value);
|
||||
if (jid) {
|
||||
if (accounts_account_exists(account_name)) {
|
||||
g_key_file_set_string(accounts, account_name, "jid", jid->barejid);
|
||||
@ -478,8 +461,6 @@ accounts_set_jid(const char* const account_name, const char* const value)
|
||||
|
||||
_save_accounts();
|
||||
}
|
||||
|
||||
jid_destroy(jid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -868,7 +849,7 @@ accounts_set_last_activity(const char* const account_name)
|
||||
}
|
||||
}
|
||||
|
||||
char*
|
||||
gchar*
|
||||
accounts_get_last_activity(const char* const account_name)
|
||||
{
|
||||
if (accounts_account_exists(account_name)) {
|
||||
@ -878,7 +859,7 @@ accounts_get_last_activity(const char* const account_name)
|
||||
}
|
||||
}
|
||||
|
||||
char*
|
||||
gchar*
|
||||
accounts_get_resource(const char* const account_name)
|
||||
{
|
||||
if (!accounts_account_exists(account_name)) {
|
||||
@ -909,7 +890,7 @@ resource_presence_t
|
||||
accounts_get_last_presence(const char* const account_name)
|
||||
{
|
||||
resource_presence_t result;
|
||||
gchar* setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
|
||||
auto_gchar gchar* setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
|
||||
|
||||
if (setting == NULL || (strcmp(setting, "online") == 0)) {
|
||||
result = RESOURCE_ONLINE;
|
||||
@ -927,7 +908,6 @@ accounts_get_last_presence(const char* const account_name)
|
||||
result = RESOURCE_ONLINE;
|
||||
}
|
||||
|
||||
g_free(setting);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ void accounts_set_jid(const char* const account_name, const char* const value);
|
||||
void accounts_set_server(const char* const account_name, const char* const value);
|
||||
void accounts_set_port(const char* const account_name, const int value);
|
||||
void accounts_set_resource(const char* const account_name, const char* const value);
|
||||
char* accounts_get_resource(const char* const account_name);
|
||||
gchar* accounts_get_resource(const char* const account_name);
|
||||
void accounts_set_password(const char* const account_name, const char* const value);
|
||||
void accounts_set_eval_password(const char* const account_name, const char* const value);
|
||||
void accounts_set_muc_service(const char* const account_name, const char* const value);
|
||||
@ -72,7 +72,7 @@ void accounts_set_auth_policy(const char* const account_name, const char* const
|
||||
void accounts_set_last_presence(const char* const account_name, const char* const value);
|
||||
void accounts_set_last_status(const char* const account_name, const char* const value);
|
||||
void accounts_set_last_activity(const char* const account_name);
|
||||
char* accounts_get_last_activity(const char* const account_name);
|
||||
gchar* accounts_get_last_activity(const char* const account_name);
|
||||
void accounts_set_login_presence(const char* const account_name, const char* const value);
|
||||
resource_presence_t accounts_get_login_presence(const char* const account_name);
|
||||
char* accounts_get_last_status(const char* const account_name);
|
||||
|
@ -64,30 +64,27 @@ cafile_add(const TLSCertificate* cert)
|
||||
log_error("[CAfile] can't store cert with fingerprint %s: PEM is empty", cert->fingerprint);
|
||||
return;
|
||||
}
|
||||
gchar* cafile = _cafile_name();
|
||||
auto_gchar gchar* cafile = _cafile_name();
|
||||
if (!cafile)
|
||||
return;
|
||||
gchar *contents = NULL, *new_contents = NULL;
|
||||
auto_gchar gchar* contents = NULL;
|
||||
auto_gchar gchar* new_contents = NULL;
|
||||
gsize length;
|
||||
GError* glib_error = NULL;
|
||||
if (g_file_test(cafile, G_FILE_TEST_EXISTS)) {
|
||||
if (!g_file_get_contents(cafile, &contents, &length, &glib_error)) {
|
||||
log_error("[CAfile] could not read from %s: %s", cafile, glib_error ? glib_error->message : "No GLib error given");
|
||||
goto out;
|
||||
return;
|
||||
}
|
||||
if (strstr(contents, cert->fingerprint)) {
|
||||
log_debug("[CAfile] fingerprint %s already stored", cert->fingerprint);
|
||||
goto out;
|
||||
return;
|
||||
}
|
||||
}
|
||||
const char* header = "# Profanity CAfile\n# DO NOT EDIT - this file is automatically generated";
|
||||
new_contents = g_strdup_printf("%s\n\n# %s\n%s", contents ? contents : header, cert->fingerprint, cert->pem);
|
||||
if (!g_file_set_contents(cafile, new_contents, -1, &glib_error))
|
||||
log_error("[CAfile] could not write to %s: %s", cafile, glib_error ? glib_error->message : "No GLib error given");
|
||||
out:
|
||||
g_free(new_contents);
|
||||
g_free(contents);
|
||||
g_free(cafile);
|
||||
}
|
||||
|
||||
gchar*
|
||||
|
@ -34,6 +34,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
@ -42,7 +43,7 @@ gboolean
|
||||
conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* const key, const char* const item)
|
||||
{
|
||||
gsize length;
|
||||
gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
|
||||
auto_gcharv gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
|
||||
GList* glist = NULL;
|
||||
|
||||
// list found
|
||||
@ -81,7 +82,6 @@ conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* con
|
||||
g_key_file_set_string_list(keyfile, group, key, new_list, 1);
|
||||
}
|
||||
|
||||
g_strfreev(list);
|
||||
g_list_free_full(glist, g_free);
|
||||
|
||||
return TRUE;
|
||||
@ -91,44 +91,43 @@ gboolean
|
||||
conf_string_list_remove(GKeyFile* keyfile, const char* const group, const char* const key, const char* const item)
|
||||
{
|
||||
gsize length;
|
||||
gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
|
||||
auto_gcharv gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
|
||||
|
||||
gboolean deleted = FALSE;
|
||||
if (list) {
|
||||
int i = 0;
|
||||
GList* glist = NULL;
|
||||
if (!list) {
|
||||
return FALSE;
|
||||
}
|
||||
int i = 0;
|
||||
GList* glist = NULL;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
// item found, mark as deleted
|
||||
if (strcmp(list[i], item) == 0) {
|
||||
deleted = TRUE;
|
||||
} else {
|
||||
// add item to our g_list
|
||||
glist = g_list_append(glist, strdup(list[i]));
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
// item found, mark as deleted
|
||||
if (strcmp(list[i], item) == 0) {
|
||||
deleted = TRUE;
|
||||
} else {
|
||||
// add item to our g_list
|
||||
glist = g_list_append(glist, strdup(list[i]));
|
||||
}
|
||||
|
||||
if (deleted) {
|
||||
if (g_list_length(glist) == 0) {
|
||||
g_key_file_remove_key(keyfile, group, key, NULL);
|
||||
} else {
|
||||
// create the new list entry
|
||||
const gchar* new_list[g_list_length(glist) + 1];
|
||||
GList* curr = glist;
|
||||
i = 0;
|
||||
while (curr) {
|
||||
new_list[i++] = curr->data;
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
new_list[i] = NULL;
|
||||
g_key_file_set_string_list(keyfile, group, key, new_list, g_list_length(glist));
|
||||
}
|
||||
}
|
||||
|
||||
g_list_free_full(glist, g_free);
|
||||
}
|
||||
|
||||
g_strfreev(list);
|
||||
if (deleted) {
|
||||
if (g_list_length(glist) == 0) {
|
||||
g_key_file_remove_key(keyfile, group, key, NULL);
|
||||
} else {
|
||||
// create the new list entry
|
||||
const gchar* new_list[g_list_length(glist) + 1];
|
||||
GList* curr = glist;
|
||||
i = 0;
|
||||
while (curr) {
|
||||
new_list[i++] = curr->data;
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
new_list[i] = NULL;
|
||||
g_key_file_set_string_list(keyfile, group, key, new_list, g_list_length(glist));
|
||||
}
|
||||
}
|
||||
|
||||
g_list_free_full(glist, g_free);
|
||||
|
||||
return deleted;
|
||||
}
|
||||
|
@ -53,8 +53,8 @@ static char* _files_get_xdg_data_home(void);
|
||||
void
|
||||
files_create_directories(void)
|
||||
{
|
||||
gchar* xdg_config = _files_get_xdg_config_home();
|
||||
gchar* xdg_data = _files_get_xdg_data_home();
|
||||
auto_gchar gchar* xdg_config = _files_get_xdg_config_home();
|
||||
auto_gchar gchar* xdg_data = _files_get_xdg_data_home();
|
||||
|
||||
GString* themes_dir = g_string_new(xdg_config);
|
||||
g_string_append(themes_dir, "/profanity/themes");
|
||||
@ -88,17 +88,13 @@ files_create_directories(void)
|
||||
g_string_free(chatlogs_dir, TRUE);
|
||||
g_string_free(logs_dir, TRUE);
|
||||
g_string_free(plugins_dir, TRUE);
|
||||
|
||||
g_free(xdg_config);
|
||||
g_free(xdg_data);
|
||||
}
|
||||
|
||||
gchar*
|
||||
files_get_inputrc_file(void)
|
||||
{
|
||||
gchar* xdg_config = _files_get_xdg_config_home();
|
||||
auto_gchar gchar* xdg_config = _files_get_xdg_config_home();
|
||||
GString* inputrc_file = g_string_new(xdg_config);
|
||||
g_free(xdg_config);
|
||||
|
||||
g_string_append(inputrc_file, "/profanity/inputrc");
|
||||
|
||||
@ -121,11 +117,10 @@ files_get_log_file(const char* const log_file)
|
||||
GString* logfile;
|
||||
|
||||
if (log_file) {
|
||||
gchar* log_path = g_path_get_dirname(log_file);
|
||||
auto_gchar gchar* log_path = g_path_get_dirname(log_file);
|
||||
if (!create_dir(log_path)) {
|
||||
log_error("Error while creating directory %s", log_path);
|
||||
}
|
||||
g_free(log_path);
|
||||
|
||||
logfile = g_string_new(log_file);
|
||||
} else {
|
||||
@ -149,9 +144,8 @@ files_get_log_file(const char* const log_file)
|
||||
gchar*
|
||||
files_get_config_path(const char* const config_base)
|
||||
{
|
||||
gchar* xdg_config = _files_get_xdg_config_home();
|
||||
auto_gchar gchar* xdg_config = _files_get_xdg_config_home();
|
||||
gchar* result = g_strdup_printf("%s/profanity/%s", xdg_config, config_base);
|
||||
g_free(xdg_config);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -161,8 +155,7 @@ files_get_config_path(const char* const config_base)
|
||||
* @param location The location (directory or file) to append to the project base path.
|
||||
* @return The full path obtained by appending the location to the project base path.
|
||||
*
|
||||
* @note The returned value must be freed using g_free when it is no longer needed
|
||||
* to prevent memory leaks.
|
||||
* @note Remember to free returned string using `auto_gchar` or `g_free()` when it is no longer needed to prevent memory leaks.
|
||||
*/
|
||||
gchar*
|
||||
files_get_data_path(const char* const location)
|
||||
@ -176,7 +169,7 @@ gchar*
|
||||
files_get_account_data_path(const char* const specific_dir, const char* const jid)
|
||||
{
|
||||
auto_gchar gchar* data_dir = files_get_data_path(specific_dir);
|
||||
auto_gchar gchar* account_dir = str_replace(jid, "@", "_at_");
|
||||
auto_char char* account_dir = str_replace(jid, "@", "_at_");
|
||||
|
||||
return g_strdup_printf("%s/%s", data_dir, account_dir);
|
||||
}
|
||||
|
@ -216,12 +216,11 @@ _prefs_load(void)
|
||||
|
||||
room_trigger_ac = autocomplete_new();
|
||||
gsize len = 0;
|
||||
gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
auto_gcharv gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
autocomplete_add(room_trigger_ac, triggers[i]);
|
||||
}
|
||||
g_strfreev(triggers);
|
||||
}
|
||||
|
||||
/* Clean up after _prefs_load() */
|
||||
@ -333,7 +332,7 @@ prefs_message_get_triggers(const char* const message)
|
||||
|
||||
auto_gchar gchar* message_lower = g_utf8_strdown(message, -1);
|
||||
gsize len = 0;
|
||||
gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
auto_gcharv gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
auto_gchar gchar* trigger_lower = g_utf8_strdown(triggers[i], -1);
|
||||
@ -342,8 +341,6 @@ prefs_message_get_triggers(const char* const message)
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(triggers);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -520,6 +517,14 @@ prefs_set_boolean(preference_t pref, gboolean value)
|
||||
g_key_file_set_boolean(prefs, group, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieves a string preference value.
|
||||
*
|
||||
* @param pref The preference identifier.
|
||||
* @return The string preference value or `NULL` if not found.
|
||||
*
|
||||
* @note Remember to free the returned string using `auto_gchar` or `g_free()`.
|
||||
*/
|
||||
gchar*
|
||||
prefs_get_string(preference_t pref)
|
||||
{
|
||||
@ -540,14 +545,23 @@ prefs_get_string(preference_t pref)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieves a localized string preference value.
|
||||
*
|
||||
* @param pref The preference to retrieve the value for.
|
||||
* @param locale The option to consider.
|
||||
* @return Returns the value associated with pref translated in the given locale if available.
|
||||
*
|
||||
* @note Remember to free the returned string using `auto_gchar` or `g_free()`.
|
||||
*/
|
||||
gchar*
|
||||
prefs_get_string_with_option(preference_t pref, gchar* option)
|
||||
prefs_get_string_with_locale(preference_t pref, gchar* locale)
|
||||
{
|
||||
const char* group = _get_group(pref);
|
||||
const char* key = _get_key(pref);
|
||||
char* def = _get_default_string(pref);
|
||||
|
||||
gchar* result = g_key_file_get_locale_string(prefs, group, key, option, NULL);
|
||||
gchar* result = g_key_file_get_locale_string(prefs, group, key, locale, NULL);
|
||||
|
||||
if (result == NULL) {
|
||||
// check for user set default
|
||||
@ -565,15 +579,21 @@ prefs_get_string_with_option(preference_t pref, gchar* option)
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets or deletes a string value for the given preference in the preference file.
|
||||
*
|
||||
* @param pref The preference to set the value for.
|
||||
* @param new_value The new string value to set. Pass NULL to remove the key.
|
||||
*/
|
||||
void
|
||||
prefs_set_string(preference_t pref, char* value)
|
||||
prefs_set_string(preference_t pref, gchar* new_value)
|
||||
{
|
||||
const char* group = _get_group(pref);
|
||||
const char* key = _get_key(pref);
|
||||
if (value == NULL) {
|
||||
if (new_value == NULL) {
|
||||
g_key_file_remove_key(prefs, group, key, NULL);
|
||||
} else {
|
||||
g_key_file_set_string(prefs, group, key, value);
|
||||
g_key_file_set_string(prefs, group, key, new_value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -862,12 +882,6 @@ prefs_remove_plugin(const char* const name)
|
||||
_save_prefs();
|
||||
}
|
||||
|
||||
void
|
||||
prefs_free_plugins(gchar** plugins)
|
||||
{
|
||||
g_strfreev(plugins);
|
||||
}
|
||||
|
||||
void
|
||||
prefs_set_occupants_size(gint value)
|
||||
{
|
||||
@ -1316,14 +1330,12 @@ prefs_get_room_notify_triggers(void)
|
||||
{
|
||||
GList* result = NULL;
|
||||
gsize len = 0;
|
||||
gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
auto_gcharv gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
result = g_list_append(result, strdup(triggers[i]));
|
||||
}
|
||||
|
||||
g_strfreev(triggers);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1665,7 +1677,7 @@ prefs_get_aliases(void)
|
||||
} else {
|
||||
GList* result = NULL;
|
||||
gsize len;
|
||||
gchar** keys = g_key_file_get_keys(prefs, PREF_GROUP_ALIAS, &len, NULL);
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(prefs, PREF_GROUP_ALIAS, &len, NULL);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
char* name = keys[i];
|
||||
@ -1680,8 +1692,6 @@ prefs_get_aliases(void)
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(keys);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -253,7 +253,6 @@ gint prefs_get_autoxa_time(void);
|
||||
void prefs_set_autoxa_time(gint value);
|
||||
|
||||
gchar** prefs_get_plugins(void);
|
||||
void prefs_free_plugins(gchar** plugins);
|
||||
void prefs_add_plugin(const char* const name);
|
||||
void prefs_remove_plugin(const char* const name);
|
||||
|
||||
@ -336,8 +335,8 @@ void prefs_save_win_placement(ProfWinPlacement* placement);
|
||||
gboolean prefs_get_boolean(preference_t pref);
|
||||
void prefs_set_boolean(preference_t pref, gboolean value);
|
||||
gchar* prefs_get_string(preference_t pref);
|
||||
gchar* prefs_get_string_with_option(preference_t pref, gchar* option);
|
||||
void prefs_set_string(preference_t pref, char* value);
|
||||
gchar* prefs_get_string_with_locale(preference_t pref, gchar* locale);
|
||||
void prefs_set_string(preference_t pref, gchar* new_value);
|
||||
void prefs_set_string_with_option(preference_t pref, char* option, char* value);
|
||||
void prefs_set_string_list_with_option(preference_t pref, char* option, const gchar* const* values);
|
||||
|
||||
|
@ -237,10 +237,9 @@ GSList*
|
||||
theme_list(void)
|
||||
{
|
||||
GSList* result = NULL;
|
||||
gchar* themes_dir = files_get_config_path(DIR_THEMES);
|
||||
auto_gchar gchar* themes_dir = files_get_config_path(DIR_THEMES);
|
||||
|
||||
_theme_list_dir(themes_dir, &result);
|
||||
g_free(themes_dir);
|
||||
|
||||
#ifdef THEMES_PATH
|
||||
_theme_list_dir(THEMES_PATH, &result);
|
||||
@ -281,9 +280,8 @@ static void
|
||||
_set_string_preference(char* prefstr, preference_t pref)
|
||||
{
|
||||
if (g_key_file_has_key(theme, "ui", prefstr, NULL)) {
|
||||
gchar* val = g_key_file_get_string(theme, "ui", prefstr, NULL);
|
||||
auto_gchar gchar* val = g_key_file_get_string(theme, "ui", prefstr, NULL);
|
||||
prefs_set_string(pref, val);
|
||||
g_free(val);
|
||||
}
|
||||
}
|
||||
|
||||
@ -408,100 +406,88 @@ _load_preferences(void)
|
||||
// load chars from theme and set them to prefs
|
||||
// with custom set functions
|
||||
if (g_key_file_has_key(theme, "ui", "occupants.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "occupants.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "occupants.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_occupants_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "occupants.header.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "occupants.header.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "occupants.header.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_occupants_header_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "roster.header.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "roster.header.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.header.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_roster_header_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "roster.contact.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "roster.contact.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.contact.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_roster_contact_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "roster.resource.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "roster.resource.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.resource.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_roster_resource_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
} else {
|
||||
prefs_clear_roster_resource_char();
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "roster.rooms.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_roster_room_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "roster.rooms.private.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.private.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.rooms.private.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_roster_room_private_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "roster.private.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "roster.private.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "roster.private.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_roster_private_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "otr.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "otr.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "otr.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_otr_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "pgp.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "pgp.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "pgp.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_pgp_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "omemo.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "omemo.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "omemo.char", NULL);
|
||||
if (ch && g_utf8_strlen(ch, 4) == 1) {
|
||||
prefs_set_omemo_char(ch);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_key_file_has_key(theme, "ui", "correction.char", NULL)) {
|
||||
gchar* ch = g_key_file_get_string(theme, "ui", "correction.char", NULL);
|
||||
auto_gchar gchar* ch = g_key_file_get_string(theme, "ui", "correction.char", NULL);
|
||||
if (ch && strlen(ch) > 0) {
|
||||
prefs_set_correction_char(ch[0]);
|
||||
g_free(ch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -538,11 +524,10 @@ static GString*
|
||||
_theme_find(const char* const theme_name)
|
||||
{
|
||||
GString* path = NULL;
|
||||
gchar* themes_dir = files_get_config_path(DIR_THEMES);
|
||||
auto_gchar gchar* themes_dir = files_get_config_path(DIR_THEMES);
|
||||
|
||||
if (themes_dir) {
|
||||
path = g_string_new(themes_dir);
|
||||
g_free(themes_dir);
|
||||
g_string_append(path, "/");
|
||||
g_string_append(path, theme_name);
|
||||
if (!g_file_test(path->str, G_FILE_TEST_EXISTS)) {
|
||||
@ -641,7 +626,7 @@ theme_main_presence_attrs(const char* const presence)
|
||||
static void
|
||||
_theme_prep_bgnd(char* setting, char* def, GString* lookup_str)
|
||||
{
|
||||
gchar* val = g_key_file_get_string(theme, "colours", setting, NULL);
|
||||
auto_gchar gchar* val = g_key_file_get_string(theme, "colours", setting, NULL);
|
||||
if (!val) {
|
||||
g_string_append(lookup_str, def);
|
||||
} else {
|
||||
@ -651,7 +636,6 @@ _theme_prep_bgnd(char* setting, char* def, GString* lookup_str)
|
||||
g_string_append(lookup_str, val);
|
||||
}
|
||||
}
|
||||
g_free(val);
|
||||
}
|
||||
|
||||
/* return value needs to be freed */
|
||||
@ -666,7 +650,7 @@ theme_get_bkgnd(void)
|
||||
static void
|
||||
_theme_prep_fgnd(char* setting, GString* lookup_str, gboolean* bold)
|
||||
{
|
||||
gchar* conf_str = g_key_file_get_string(theme, "colours", setting, NULL);
|
||||
auto_gchar gchar* conf_str = g_key_file_get_string(theme, "colours", setting, NULL);
|
||||
gchar* val = conf_str;
|
||||
|
||||
if (!val)
|
||||
@ -679,8 +663,6 @@ _theme_prep_fgnd(char* setting, GString* lookup_str, gboolean* bold)
|
||||
g_string_append(lookup_str, val);
|
||||
*bold = FALSE;
|
||||
}
|
||||
|
||||
g_free(conf_str);
|
||||
}
|
||||
|
||||
char*
|
||||
|
@ -71,12 +71,11 @@ tlscerts_init(void)
|
||||
|
||||
certs_ac = autocomplete_new();
|
||||
gsize len = 0;
|
||||
gchar** groups = g_key_file_get_groups(tlscerts, &len);
|
||||
auto_gcharv gchar** groups = g_key_file_get_groups(tlscerts, &len);
|
||||
|
||||
for (int i = 0; i < g_strv_length(groups); i++) {
|
||||
autocomplete_add(certs_ac, groups[i]);
|
||||
}
|
||||
g_strfreev(groups);
|
||||
|
||||
current_fp = NULL;
|
||||
}
|
||||
@ -116,7 +115,7 @@ tlscerts_list(void)
|
||||
{
|
||||
GList* res = NULL;
|
||||
gsize len = 0;
|
||||
gchar** groups = g_key_file_get_groups(tlscerts, &len);
|
||||
auto_gcharv gchar** groups = g_key_file_get_groups(tlscerts, &len);
|
||||
|
||||
for (int i = 0; i < g_strv_length(groups); i++) {
|
||||
char* fingerprint = strdup(groups[i]);
|
||||
@ -135,10 +134,6 @@ tlscerts_list(void)
|
||||
res = g_list_append(res, cert);
|
||||
}
|
||||
|
||||
if (groups) {
|
||||
g_strfreev(groups);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -178,9 +173,9 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria
|
||||
cert->pem = strdup(pem);
|
||||
}
|
||||
|
||||
gchar** fields = g_strsplit(subjectname, "/", 0);
|
||||
auto_gcharv gchar** fields = g_strsplit(subjectname, "/", 0);
|
||||
for (int i = 0; i < g_strv_length(fields); i++) {
|
||||
gchar** keyval = g_strsplit(fields[i], "=", 2);
|
||||
auto_gcharv gchar** keyval = g_strsplit(fields[i], "=", 2);
|
||||
if (g_strv_length(keyval) == 2) {
|
||||
if ((g_strcmp0(keyval[0], "C") == 0) || (g_strcmp0(keyval[0], "countryName") == 0)) {
|
||||
cert->subject_country = strdup(keyval[1]);
|
||||
@ -207,13 +202,11 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria
|
||||
cert->subject_email = strdup(keyval[1]);
|
||||
}
|
||||
}
|
||||
g_strfreev(keyval);
|
||||
}
|
||||
g_strfreev(fields);
|
||||
|
||||
fields = g_strsplit(issuername, "/", 0);
|
||||
for (int i = 0; i < g_strv_length(fields); i++) {
|
||||
gchar** keyval = g_strsplit(fields[i], "=", 2);
|
||||
auto_gcharv gchar** fields2 = g_strsplit(issuername, "/", 0);
|
||||
for (int i = 0; i < g_strv_length(fields2); i++) {
|
||||
auto_gcharv gchar** keyval = g_strsplit(fields2[i], "=", 2);
|
||||
if (g_strv_length(keyval) == 2) {
|
||||
if ((g_strcmp0(keyval[0], "C") == 0) || (g_strcmp0(keyval[0], "countryName") == 0)) {
|
||||
cert->issuer_country = strdup(keyval[1]);
|
||||
@ -240,9 +233,7 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria
|
||||
cert->issuer_email = strdup(keyval[1]);
|
||||
}
|
||||
}
|
||||
g_strfreev(keyval);
|
||||
}
|
||||
g_strfreev(fields);
|
||||
|
||||
return cert;
|
||||
}
|
||||
@ -387,8 +378,7 @@ static void
|
||||
_save_tlscerts(void)
|
||||
{
|
||||
gsize g_data_size;
|
||||
gchar* g_tlscerts_data = g_key_file_to_data(tlscerts, &g_data_size, NULL);
|
||||
auto_gchar gchar* g_tlscerts_data = g_key_file_to_data(tlscerts, &g_data_size, NULL);
|
||||
g_file_set_contents(tlscerts_loc, g_tlscerts_data, g_data_size, NULL);
|
||||
g_chmod(tlscerts_loc, S_IRUSR | S_IWUSR);
|
||||
g_free(g_tlscerts_data);
|
||||
}
|
||||
|
@ -153,11 +153,9 @@ log_database_add_incoming(ProfMessage* message)
|
||||
if (message->to_jid) {
|
||||
_add_to_db(message, NULL, message->from_jid, message->to_jid);
|
||||
} else {
|
||||
Jid* myjid = jid_create(connection_get_fulljid());
|
||||
auto_jid Jid* myjid = jid_create(connection_get_fulljid());
|
||||
|
||||
_add_to_db(message, NULL, message->from_jid, myjid);
|
||||
|
||||
jid_destroy(myjid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,11 +171,10 @@ _log_database_add_outgoing(char* type, const char* const id, const char* const b
|
||||
msg->timestamp = g_date_time_new_now_local(); // TODO: get from outside. best to have whole ProfMessage from outside
|
||||
msg->enc = enc;
|
||||
|
||||
Jid* myjid = jid_create(connection_get_fulljid());
|
||||
auto_jid Jid* myjid = jid_create(connection_get_fulljid());
|
||||
|
||||
_add_to_db(msg, type, myjid, msg->from_jid); // TODO: myjid now in profmessage
|
||||
|
||||
jid_destroy(myjid);
|
||||
message_free(msg);
|
||||
}
|
||||
|
||||
@ -206,7 +203,7 @@ log_database_get_limits_info(const gchar* const contact_barejid, gboolean is_las
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
gchar* query;
|
||||
const char* jid = connection_get_fulljid();
|
||||
Jid* myjid = jid_create(jid);
|
||||
auto_jid Jid* myjid = jid_create(jid);
|
||||
if (!myjid)
|
||||
return NULL;
|
||||
|
||||
@ -221,8 +218,6 @@ log_database_get_limits_info(const gchar* const contact_barejid, gboolean is_las
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jid_destroy(myjid);
|
||||
|
||||
int rc = sqlite3_prepare_v2(g_chatlog_database, query, -1, &stmt, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
log_error("log_database_get_last_info(): unknown SQLite error");
|
||||
@ -252,7 +247,7 @@ log_database_get_previous_chat(const gchar* const contact_barejid, const char* s
|
||||
{
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
const char* jid = connection_get_fulljid();
|
||||
Jid* myjid = jid_create(jid);
|
||||
auto_jid Jid* myjid = jid_create(jid);
|
||||
if (!myjid)
|
||||
return NULL;
|
||||
|
||||
@ -260,19 +255,16 @@ log_database_get_previous_chat(const gchar* const contact_barejid, const char* s
|
||||
gchar* sort1 = from_start ? "ASC" : "DESC";
|
||||
gchar* sort2 = !flip ? "ASC" : "DESC";
|
||||
GDateTime* now = g_date_time_new_now_local();
|
||||
gchar* end_date_fmt = end_time ? end_time : g_date_time_format_iso8601(now);
|
||||
auto_gchar gchar* end_date_fmt = end_time ? end_time : g_date_time_format_iso8601(now);
|
||||
auto_sqlite gchar* query = sqlite3_mprintf("SELECT * FROM (SELECT COALESCE(B.`message`, A.`message`) AS message, A.`timestamp`, A.`from_jid`, A.`type`, A.`encryption` from `ChatLogs` AS A LEFT JOIN `ChatLogs` AS B ON A.`stanza_id` = B.`replace_id` WHERE A.`replace_id` = '' AND ((A.`from_jid` = '%q' AND A.`to_jid` = '%q') OR (A.`from_jid` = '%q' AND A.`to_jid` = '%q')) AND A.`timestamp` < '%q' AND (%Q IS NULL OR A.`timestamp` > %Q) ORDER BY A.`timestamp` %s LIMIT %d) ORDER BY `timestamp` %s;", contact_barejid, myjid->barejid, myjid->barejid, contact_barejid, end_date_fmt, start_time, start_time, sort1, MESSAGES_TO_RETRIEVE, sort2);
|
||||
|
||||
g_date_time_unref(now);
|
||||
g_free(end_date_fmt);
|
||||
|
||||
if (!query) {
|
||||
log_error("log_database_get_previous_chat(): SQL query. could not allocate memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jid_destroy(myjid);
|
||||
|
||||
int rc = sqlite3_prepare_v2(g_chatlog_database, query, -1, &stmt, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
log_error("log_database_get_previous_chat(): unknown SQLite error");
|
||||
@ -389,7 +381,7 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
|
||||
|
||||
char* err_msg;
|
||||
gchar* query;
|
||||
gchar* date_fmt;
|
||||
auto_gchar gchar* date_fmt;
|
||||
|
||||
if (message->timestamp) {
|
||||
date_fmt = g_date_time_format_iso8601(message->timestamp);
|
||||
@ -423,7 +415,6 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
|
||||
log_error("log_database_add(): SQL query. could not allocate memory");
|
||||
return;
|
||||
}
|
||||
g_free(date_fmt);
|
||||
|
||||
if (SQLITE_OK != sqlite3_exec(g_chatlog_database, query, NULL, 0, &err_msg)) {
|
||||
if (err_msg) {
|
||||
|
@ -169,8 +169,8 @@ sv_ev_roster_received(void)
|
||||
|
||||
// send initial presence
|
||||
resource_presence_t conn_presence = accounts_get_login_presence(account_name);
|
||||
char* last_activity_str = accounts_get_last_activity(account_name);
|
||||
char* status_message = accounts_get_login_status(account_name);
|
||||
auto_gchar gchar* last_activity_str = accounts_get_last_activity(account_name);
|
||||
auto_gchar gchar* status_message = accounts_get_login_status(account_name);
|
||||
int diff_secs = 0;
|
||||
|
||||
if (prefs_get_boolean(PREF_LASTACTIVITY) && last_activity_str) {
|
||||
@ -190,9 +190,6 @@ sv_ev_roster_received(void)
|
||||
connection_set_presence_msg(status_message);
|
||||
cl_ev_presence_send(conn_presence, diff_secs);
|
||||
|
||||
g_free(status_message);
|
||||
g_free(last_activity_str);
|
||||
|
||||
const char* fulljid = connection_get_fulljid();
|
||||
plugins_on_connect(account_name, fulljid);
|
||||
}
|
||||
@ -278,7 +275,7 @@ sv_ev_room_history(ProfMessage* message)
|
||||
// check if this message was sent while we were offline.
|
||||
// if so, treat it as a new message rather than a history event.
|
||||
char* account_name = session_get_account_name();
|
||||
char* last_activity = accounts_get_last_activity(account_name);
|
||||
auto_gchar gchar* last_activity = accounts_get_last_activity(account_name);
|
||||
int msg_is_new = 0;
|
||||
|
||||
if (last_activity) {
|
||||
@ -292,7 +289,6 @@ sv_ev_room_history(ProfMessage* message)
|
||||
msg_is_new = (time_diff > 0);
|
||||
g_date_time_unref(lastdt);
|
||||
}
|
||||
g_free(last_activity);
|
||||
|
||||
if (msg_is_new) {
|
||||
sv_ev_room_message(message);
|
||||
@ -399,10 +395,9 @@ sv_ev_room_message(ProfMessage* message)
|
||||
mucwin->last_msg_timestamp = g_date_time_new_now_local();
|
||||
|
||||
if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, message->from_jid->resourcepart, message->plain, mention, triggers != NULL)) {
|
||||
Jid* jidp = jid_create(mucwin->roomjid);
|
||||
auto_jid Jid* jidp = jid_create(mucwin->roomjid);
|
||||
if (jidp) {
|
||||
notify_room_message(message->from_jid->resourcepart, jidp->localpart, num, message->plain);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -906,9 +901,8 @@ sv_ev_room_occupant_offline(const char* const room, const char* const nick,
|
||||
mucwin_occupant_offline(mucwin, nick);
|
||||
}
|
||||
|
||||
Jid* jidp = jid_create_from_bare_and_resource(room, nick);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(room, nick);
|
||||
ProfPrivateWin* privwin = wins_get_private(jidp->fulljid);
|
||||
jid_destroy(jidp);
|
||||
if (privwin != NULL) {
|
||||
privwin_occupant_offline(privwin);
|
||||
}
|
||||
@ -927,9 +921,8 @@ sv_ev_room_occupent_kicked(const char* const room, const char* const nick, const
|
||||
mucwin_occupant_kicked(mucwin, nick, actor, reason);
|
||||
}
|
||||
|
||||
Jid* jidp = jid_create_from_bare_and_resource(room, nick);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(room, nick);
|
||||
ProfPrivateWin* privwin = wins_get_private(jidp->fulljid);
|
||||
jid_destroy(jidp);
|
||||
if (privwin != NULL) {
|
||||
privwin_occupant_kicked(privwin, actor, reason);
|
||||
}
|
||||
@ -948,13 +941,11 @@ sv_ev_room_occupent_banned(const char* const room, const char* const nick, const
|
||||
mucwin_occupant_banned(mucwin, nick, actor, reason);
|
||||
}
|
||||
|
||||
Jid* jidp = jid_create_from_bare_and_resource(room, nick);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(room, nick);
|
||||
|
||||
muc_members_remove(room, jidp->fulljid);
|
||||
ProfPrivateWin* privwin = wins_get_private(jidp->fulljid);
|
||||
|
||||
jid_destroy(jidp);
|
||||
|
||||
if (privwin != NULL) {
|
||||
privwin_occupant_banned(privwin, actor, reason);
|
||||
}
|
||||
@ -1007,11 +998,10 @@ sv_ev_muc_self_online(const char* const room, const char* const nick, gboolean c
|
||||
ui_room_join(room, TRUE);
|
||||
}
|
||||
|
||||
Jid* jidp = jid_create(room);
|
||||
auto_jid Jid* jidp = jid_create(room);
|
||||
if (jidp->domainpart) {
|
||||
muc_confserver_add(jidp->domainpart);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
|
||||
iq_room_info_request(room, FALSE);
|
||||
|
||||
@ -1126,9 +1116,8 @@ sv_ev_muc_occupant_online(const char* const room, const char* const nick, const
|
||||
}
|
||||
|
||||
if (mucwin) {
|
||||
Jid* jidp = jid_create_from_bare_and_resource(mucwin->roomjid, nick);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(mucwin->roomjid, nick);
|
||||
ProfPrivateWin* privwin = wins_get_private(jidp->fulljid);
|
||||
jid_destroy(jidp);
|
||||
if (privwin) {
|
||||
privwin_occupant_online(privwin);
|
||||
}
|
||||
@ -1234,7 +1223,7 @@ sv_ev_certfail(const char* const errormsg, const TLSCertificate* cert)
|
||||
void
|
||||
sv_ev_lastactivity_response(const char* const from, const int seconds, const char* const msg)
|
||||
{
|
||||
Jid* jidp = jid_create(from);
|
||||
auto_jid Jid* jidp = jid_create(from);
|
||||
|
||||
if (!jidp) {
|
||||
return;
|
||||
@ -1296,7 +1285,6 @@ sv_ev_lastactivity_response(const char* const from, const int seconds, const cha
|
||||
|
||||
g_date_time_unref(now);
|
||||
g_date_time_unref(active);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1331,10 +1319,9 @@ static void
|
||||
_cut(ProfMessage* message, const char* cut)
|
||||
{
|
||||
if (strstr(message->plain, cut)) {
|
||||
gchar** split = g_strsplit(message->plain, cut, -1);
|
||||
auto_gcharv gchar** split = g_strsplit(message->plain, cut, -1);
|
||||
free(message->plain);
|
||||
message->plain = g_strjoinv("", split);
|
||||
g_strfreev(split);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,13 +214,12 @@ log_msg(log_level_t level, const char* const area, const char* const msg)
|
||||
|
||||
char* level_str = _log_abbreviation_string_from_level(level);
|
||||
|
||||
gchar* date_fmt = g_date_time_format_iso8601(dt);
|
||||
auto_gchar gchar* date_fmt = g_date_time_format_iso8601(dt);
|
||||
|
||||
fprintf(logp, "%s: %s: %s: %s\n", date_fmt, area, level_str, msg);
|
||||
g_date_time_unref(dt);
|
||||
|
||||
fflush(logp);
|
||||
g_free(date_fmt);
|
||||
|
||||
if (prefs_get_boolean(PREF_LOG_ROTATE) && !user_provided_log) {
|
||||
long result = ftell(logp);
|
||||
|
@ -230,7 +230,7 @@ omemo_on_connect(ProfAccount* account)
|
||||
omemo_ctx.device_list_handler = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
omemo_ctx.known_devices = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)glib_hash_table_free);
|
||||
|
||||
gchar* omemo_dir = files_file_in_account_data_path(DIR_OMEMO, account->jid, NULL);
|
||||
auto_gchar gchar* omemo_dir = files_file_in_account_data_path(DIR_OMEMO, account->jid, NULL);
|
||||
if (!omemo_dir) {
|
||||
log_error("[OMEMO] failed creating directory");
|
||||
return;
|
||||
@ -245,8 +245,6 @@ omemo_on_connect(ProfAccount* account)
|
||||
omemo_ctx.known_devices_filename = g_string_new(omemo_dir);
|
||||
g_string_append(omemo_ctx.known_devices_filename, "/known_devices.txt");
|
||||
|
||||
g_free(omemo_dir);
|
||||
|
||||
omemo_devicelist_subscribe();
|
||||
|
||||
omemo_ctx.identity_keyfile = g_key_file_new();
|
||||
@ -449,9 +447,8 @@ omemo_start_muc_sessions(const char* const roomjid)
|
||||
GList* members = muc_members(roomjid);
|
||||
GList* iter;
|
||||
for (iter = members; iter != NULL; iter = iter->next) {
|
||||
Jid* jid = jid_create(iter->data);
|
||||
auto_jid Jid* jid = jid_create(iter->data);
|
||||
omemo_start_session(jid->barejid);
|
||||
jid_destroy(jid);
|
||||
}
|
||||
g_list_free(members);
|
||||
}
|
||||
@ -549,7 +546,7 @@ void
|
||||
omemo_set_device_list(const char* const from, GList* device_list)
|
||||
{
|
||||
log_debug("[OMEMO] Setting device list for %s", STR_MAYBE_NULL(from));
|
||||
Jid* jid;
|
||||
auto_jid Jid* jid;
|
||||
if (from) {
|
||||
jid = jid_create(from);
|
||||
} else {
|
||||
@ -597,7 +594,6 @@ omemo_set_device_list(const char* const from, GList* device_list)
|
||||
}
|
||||
}
|
||||
}
|
||||
jid_destroy(jid);
|
||||
}
|
||||
|
||||
GKeyFile*
|
||||
@ -756,7 +752,7 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
|
||||
{
|
||||
char* id = NULL;
|
||||
int res;
|
||||
Jid* jid = jid_create(connection_get_fulljid());
|
||||
auto_jid Jid* jid = jid_create(connection_get_fulljid());
|
||||
GList* keys = NULL;
|
||||
|
||||
unsigned char* key;
|
||||
@ -792,9 +788,8 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
|
||||
GList* members = muc_members(mucwin->roomjid);
|
||||
GList* iter;
|
||||
for (iter = members; iter != NULL; iter = iter->next) {
|
||||
Jid* jid = jid_create(iter->data);
|
||||
recipients = g_list_append(recipients, strdup(jid->barejid));
|
||||
jid_destroy(jid);
|
||||
auto_jid Jid* jidp = jid_create(iter->data);
|
||||
recipients = g_list_append(recipients, strdup(jidp->barejid));
|
||||
}
|
||||
g_list_free(members);
|
||||
} else {
|
||||
@ -934,7 +929,6 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
|
||||
}
|
||||
|
||||
out:
|
||||
jid_destroy(jid);
|
||||
g_list_free_full(keys, (GDestroyNotify)omemo_key_free);
|
||||
free(ciphertext);
|
||||
gcry_free(key);
|
||||
@ -951,11 +945,11 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
|
||||
const unsigned char* const payload, size_t payload_len, gboolean muc, gboolean* trusted)
|
||||
{
|
||||
unsigned char* plaintext = NULL;
|
||||
Jid* sender = NULL;
|
||||
Jid* from = jid_create(from_jid);
|
||||
auto_jid Jid* sender = NULL;
|
||||
auto_jid Jid* from = jid_create(from_jid);
|
||||
if (!from) {
|
||||
log_error("[OMEMO][RECV] Invalid jid %s", from_jid);
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int res;
|
||||
@ -970,7 +964,7 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
|
||||
|
||||
if (!key) {
|
||||
log_warning("[OMEMO][RECV] received a message with no corresponding key");
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (muc) {
|
||||
@ -986,7 +980,7 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
|
||||
g_list_free(roster);
|
||||
if (!sender) {
|
||||
log_warning("[OMEMO][RECV] cannot find MUC message sender fulljid");
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
sender = jid_create(from->barejid);
|
||||
@ -1003,7 +997,7 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
|
||||
res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal);
|
||||
if (res != 0) {
|
||||
log_error("[OMEMO][RECV] cannot create session cipher");
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (key->prekey) {
|
||||
@ -1062,13 +1056,13 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
|
||||
session_cipher_free(cipher);
|
||||
if (res != 0) {
|
||||
log_error("[OMEMO][RECV] cannot decrypt message key");
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (signal_buffer_len(plaintext_key) != AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH) {
|
||||
log_error("[OMEMO][RECV] invalid key length");
|
||||
signal_buffer_free(plaintext_key);
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t plaintext_len = payload_len;
|
||||
@ -1080,15 +1074,11 @@ omemo_on_message_recv(const char* const from_jid, uint32_t sid,
|
||||
if (res != 0) {
|
||||
log_error("[OMEMO][RECV] cannot decrypt message: %s", gcry_strerror(res));
|
||||
free(plaintext);
|
||||
plaintext = NULL;
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
plaintext[plaintext_len] = '\0';
|
||||
|
||||
out:
|
||||
jid_destroy(from);
|
||||
jid_destroy(sender);
|
||||
return (char*)plaintext;
|
||||
}
|
||||
|
||||
@ -1535,7 +1525,7 @@ _load_identity(void)
|
||||
}
|
||||
|
||||
size_t identity_key_public_len;
|
||||
unsigned char* identity_key_public = g_base64_decode(identity_key_public_b64, &identity_key_public_len);
|
||||
auto_guchar guchar* identity_key_public = g_base64_decode(identity_key_public_b64, &identity_key_public_len);
|
||||
omemo_ctx.identity_key_store.public = signal_buffer_create(identity_key_public, identity_key_public_len);
|
||||
|
||||
error = NULL;
|
||||
@ -1546,7 +1536,7 @@ _load_identity(void)
|
||||
}
|
||||
|
||||
size_t identity_key_private_len;
|
||||
unsigned char* identity_key_private = g_base64_decode(identity_key_private_b64, &identity_key_private_len);
|
||||
auto_guchar guchar* identity_key_private = g_base64_decode(identity_key_private_b64, &identity_key_private_len);
|
||||
omemo_ctx.identity_key_store.private = signal_buffer_create(identity_key_private, identity_key_private_len);
|
||||
|
||||
ec_public_key* public_key;
|
||||
@ -1555,9 +1545,6 @@ _load_identity(void)
|
||||
curve_decode_private_point(&private_key, identity_key_private, identity_key_private_len, omemo_ctx.signal);
|
||||
ratchet_identity_key_pair_create(&omemo_ctx.identity_key_pair, public_key, private_key);
|
||||
|
||||
g_free(identity_key_public);
|
||||
g_free(identity_key_private);
|
||||
|
||||
char** keys = NULL;
|
||||
int i;
|
||||
/* Pre keys */
|
||||
@ -1567,9 +1554,8 @@ _load_identity(void)
|
||||
for (i = 0; keys[i] != NULL; i++) {
|
||||
auto_gchar gchar* pre_key_b64 = g_key_file_get_string(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_PREKEYS, keys[i], NULL);
|
||||
size_t pre_key_len;
|
||||
unsigned char* pre_key = g_base64_decode(pre_key_b64, &pre_key_len);
|
||||
auto_guchar guchar* pre_key = g_base64_decode(pre_key_b64, &pre_key_len);
|
||||
signal_buffer* buffer = signal_buffer_create(pre_key, pre_key_len);
|
||||
g_free(pre_key);
|
||||
g_hash_table_insert(omemo_ctx.pre_key_store, GINT_TO_POINTER(strtoul(keys[i], NULL, 10)), buffer);
|
||||
}
|
||||
|
||||
@ -1588,9 +1574,8 @@ _load_identity(void)
|
||||
for (i = 0; keys[i] != NULL; i++) {
|
||||
auto_gchar gchar* signed_pre_key_b64 = g_key_file_get_string(omemo_ctx.identity_keyfile, OMEMO_STORE_GROUP_SIGNED_PREKEYS, keys[i], NULL);
|
||||
size_t signed_pre_key_len;
|
||||
unsigned char* signed_pre_key = g_base64_decode(signed_pre_key_b64, &signed_pre_key_len);
|
||||
auto_guchar guchar* signed_pre_key = g_base64_decode(signed_pre_key_b64, &signed_pre_key_len);
|
||||
signal_buffer* buffer = signal_buffer_create(signed_pre_key, signed_pre_key_len);
|
||||
g_free(signed_pre_key);
|
||||
g_hash_table_insert(omemo_ctx.signed_pre_key_store, GINT_TO_POINTER(strtoul(keys[i], NULL, 10)), buffer);
|
||||
omemo_ctx.signed_pre_key_id = strtoul(keys[i], NULL, 10);
|
||||
}
|
||||
@ -1612,62 +1597,59 @@ _load_identity(void)
|
||||
static void
|
||||
_load_trust(void)
|
||||
{
|
||||
char** keys = NULL;
|
||||
gchar** groups = g_key_file_get_groups(omemo_ctx.trust_keyfile, NULL);
|
||||
if (groups) {
|
||||
int i;
|
||||
for (i = 0; groups[i] != NULL; i++) {
|
||||
GHashTable* trusted;
|
||||
auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.trust_keyfile, NULL);
|
||||
|
||||
trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, groups[i]);
|
||||
if (!trusted) {
|
||||
trusted = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
||||
g_hash_table_insert(omemo_ctx.identity_key_store.trusted, strdup(groups[i]), trusted);
|
||||
}
|
||||
if (!groups) {
|
||||
return;
|
||||
}
|
||||
|
||||
keys = g_key_file_get_keys(omemo_ctx.trust_keyfile, groups[i], NULL, NULL);
|
||||
int j;
|
||||
for (j = 0; keys[j] != NULL; j++) {
|
||||
auto_gchar gchar* key_b64 = g_key_file_get_string(omemo_ctx.trust_keyfile, groups[i], keys[j], NULL);
|
||||
size_t key_len;
|
||||
unsigned char* key = g_base64_decode(key_b64, &key_len);
|
||||
signal_buffer* buffer = signal_buffer_create(key, key_len);
|
||||
g_free(key);
|
||||
uint32_t device_id = strtoul(keys[j], NULL, 10);
|
||||
g_hash_table_insert(trusted, GINT_TO_POINTER(device_id), buffer);
|
||||
}
|
||||
g_strfreev(keys);
|
||||
for (int i = 0; groups[i] != NULL; i++) {
|
||||
GHashTable* trusted;
|
||||
|
||||
trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, groups[i]);
|
||||
if (!trusted) {
|
||||
trusted = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
||||
g_hash_table_insert(omemo_ctx.identity_key_store.trusted, strdup(groups[i]), trusted);
|
||||
}
|
||||
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.trust_keyfile, groups[i], NULL, NULL);
|
||||
for (int j = 0; keys[j] != NULL; j++) {
|
||||
auto_gchar gchar* key_b64 = g_key_file_get_string(omemo_ctx.trust_keyfile, groups[i], keys[j], NULL);
|
||||
size_t key_len;
|
||||
auto_guchar guchar* key = g_base64_decode(key_b64, &key_len);
|
||||
signal_buffer* buffer = signal_buffer_create(key, key_len);
|
||||
uint32_t device_id = strtoul(keys[j], NULL, 10);
|
||||
g_hash_table_insert(trusted, GINT_TO_POINTER(device_id), buffer);
|
||||
}
|
||||
g_strfreev(groups);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_load_sessions(void)
|
||||
{
|
||||
int i;
|
||||
auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.sessions_keyfile, NULL);
|
||||
if (groups) {
|
||||
for (i = 0; groups[i] != NULL; i++) {
|
||||
int j;
|
||||
GHashTable* device_store = NULL;
|
||||
|
||||
device_store = g_hash_table_lookup(omemo_ctx.session_store, groups[i]);
|
||||
if (!device_store) {
|
||||
device_store = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
||||
g_hash_table_insert(omemo_ctx.session_store, strdup(groups[i]), device_store);
|
||||
}
|
||||
if (!groups) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.sessions_keyfile, groups[i], NULL, NULL);
|
||||
for (j = 0; keys[j] != NULL; j++) {
|
||||
uint32_t id = strtoul(keys[j], NULL, 10);
|
||||
auto_gchar gchar* record_b64 = g_key_file_get_string(omemo_ctx.sessions_keyfile, groups[i], keys[j], NULL);
|
||||
size_t record_len;
|
||||
unsigned char* record = g_base64_decode(record_b64, &record_len);
|
||||
signal_buffer* buffer = signal_buffer_create(record, record_len);
|
||||
g_free(record);
|
||||
g_hash_table_insert(device_store, GINT_TO_POINTER(id), buffer);
|
||||
}
|
||||
for (int i = 0; groups[i] != NULL; i++) {
|
||||
GHashTable* device_store = NULL;
|
||||
|
||||
device_store = g_hash_table_lookup(omemo_ctx.session_store, groups[i]);
|
||||
if (!device_store) {
|
||||
device_store = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
||||
g_hash_table_insert(omemo_ctx.session_store, strdup(groups[i]), device_store);
|
||||
}
|
||||
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.sessions_keyfile, groups[i], NULL, NULL);
|
||||
for (int j = 0; keys[j] != NULL; j++) {
|
||||
uint32_t id = strtoul(keys[j], NULL, 10);
|
||||
auto_gchar gchar* record_b64 = g_key_file_get_string(omemo_ctx.sessions_keyfile, groups[i], keys[j], NULL);
|
||||
size_t record_len;
|
||||
auto_guchar guchar* record = g_base64_decode(record_b64, &record_len);
|
||||
signal_buffer* buffer = signal_buffer_create(record, record_len);
|
||||
g_hash_table_insert(device_store, GINT_TO_POINTER(id), buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1675,25 +1657,26 @@ _load_sessions(void)
|
||||
static void
|
||||
_load_known_devices(void)
|
||||
{
|
||||
int i;
|
||||
auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.known_devices_keyfile, NULL);
|
||||
if (groups) {
|
||||
for (i = 0; groups[i] != NULL; i++) {
|
||||
int j;
|
||||
GHashTable* known_identities = NULL;
|
||||
|
||||
known_identities = g_hash_table_lookup(omemo_ctx.known_devices, groups[i]);
|
||||
if (!known_identities) {
|
||||
known_identities = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
g_hash_table_insert(omemo_ctx.known_devices, strdup(groups[i]), known_identities);
|
||||
}
|
||||
if (!groups) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.known_devices_keyfile, groups[i], NULL, NULL);
|
||||
for (j = 0; keys[j] != NULL; j++) {
|
||||
uint32_t device_id = strtoul(keys[j], NULL, 10);
|
||||
auto_gchar gchar* fingerprint = g_key_file_get_string(omemo_ctx.known_devices_keyfile, groups[i], keys[j], NULL);
|
||||
g_hash_table_insert(known_identities, strdup(fingerprint), GINT_TO_POINTER(device_id));
|
||||
}
|
||||
for (int i = 0; groups[i] != NULL; i++) {
|
||||
GHashTable* known_identities = NULL;
|
||||
|
||||
known_identities = g_hash_table_lookup(omemo_ctx.known_devices, groups[i]);
|
||||
if (!known_identities) {
|
||||
known_identities = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
g_hash_table_insert(omemo_ctx.known_devices, strdup(groups[i]), known_identities);
|
||||
}
|
||||
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.known_devices_keyfile, groups[i], NULL, NULL);
|
||||
for (int j = 0; keys[j] != NULL; j++) {
|
||||
uint32_t device_id = strtoul(keys[j], NULL, 10);
|
||||
auto_gchar gchar* fingerprint = g_key_file_get_string(omemo_ctx.known_devices_keyfile, groups[i], keys[j], NULL);
|
||||
g_hash_table_insert(known_identities, strdup(fingerprint), GINT_TO_POINTER(device_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ otr_on_connect(ProfAccount* account)
|
||||
jid = strdup(account->jid);
|
||||
log_info("Loading OTR key for %s", jid);
|
||||
|
||||
gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
|
||||
auto_gchar gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
|
||||
if (!otr_dir) {
|
||||
log_error("Could not create directory for account %s.", jid);
|
||||
cons_show_error("Could not create directory for account %s.", jid);
|
||||
@ -236,7 +236,6 @@ otr_on_connect(ProfAccount* account)
|
||||
if (err != GPG_ERR_NO_ERROR) {
|
||||
log_warning("Failed to read OTR private key file: %s", keysfilename->str);
|
||||
cons_show_error("Failed to read OTR private key file: %s", keysfilename->str);
|
||||
g_free(otr_dir);
|
||||
g_string_free(keysfilename, TRUE);
|
||||
return;
|
||||
}
|
||||
@ -245,7 +244,6 @@ otr_on_connect(ProfAccount* account)
|
||||
if (!privkey) {
|
||||
log_warning("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str);
|
||||
cons_show_error("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str);
|
||||
g_free(otr_dir);
|
||||
g_string_free(keysfilename, TRUE);
|
||||
return;
|
||||
}
|
||||
@ -263,7 +261,6 @@ otr_on_connect(ProfAccount* account)
|
||||
err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL);
|
||||
if (err != GPG_ERR_NO_ERROR) {
|
||||
log_error("Failed to load OTR fingerprints file: %s", fpsfilename->str);
|
||||
g_free(otr_dir);
|
||||
g_string_free(keysfilename, TRUE);
|
||||
g_string_free(fpsfilename, TRUE);
|
||||
return;
|
||||
@ -277,7 +274,6 @@ otr_on_connect(ProfAccount* account)
|
||||
cons_show("Loaded OTR private key for %s", jid);
|
||||
}
|
||||
|
||||
g_free(otr_dir);
|
||||
g_string_free(keysfilename, TRUE);
|
||||
g_string_free(fpsfilename, TRUE);
|
||||
return;
|
||||
@ -373,7 +369,7 @@ otr_keygen(ProfAccount* account)
|
||||
jid = strdup(account->jid);
|
||||
log_info("Generating OTR key for %s", jid);
|
||||
|
||||
gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
|
||||
auto_gchar gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
|
||||
|
||||
if (!otr_dir) {
|
||||
log_error("Could not create directory for account %s.", jid);
|
||||
@ -391,7 +387,6 @@ otr_keygen(ProfAccount* account)
|
||||
ui_update();
|
||||
err = otrl_privkey_generate(user_state, keysfilename->str, account->jid, "xmpp");
|
||||
if (err != GPG_ERR_NO_ERROR) {
|
||||
g_free(otr_dir);
|
||||
g_string_free(keysfilename, TRUE);
|
||||
log_error("Failed to generate private key");
|
||||
cons_show_error("Failed to generate private key");
|
||||
@ -406,7 +401,6 @@ otr_keygen(ProfAccount* account)
|
||||
log_debug("Generating fingerprints file %s for %s", fpsfilename->str, jid);
|
||||
err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str);
|
||||
if (err != GPG_ERR_NO_ERROR) {
|
||||
g_free(otr_dir);
|
||||
g_string_free(keysfilename, TRUE);
|
||||
log_error("Failed to create fingerprints file");
|
||||
cons_show_error("Failed to create fingerprints file");
|
||||
@ -416,7 +410,6 @@ otr_keygen(ProfAccount* account)
|
||||
|
||||
err = otrl_privkey_read(user_state, keysfilename->str);
|
||||
if (err != GPG_ERR_NO_ERROR) {
|
||||
g_free(otr_dir);
|
||||
g_string_free(keysfilename, TRUE);
|
||||
log_error("Failed to load private key");
|
||||
data_loaded = FALSE;
|
||||
@ -425,7 +418,6 @@ otr_keygen(ProfAccount* account)
|
||||
|
||||
err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL);
|
||||
if (err != GPG_ERR_NO_ERROR) {
|
||||
g_free(otr_dir);
|
||||
g_string_free(keysfilename, TRUE);
|
||||
log_error("Failed to load fingerprints");
|
||||
data_loaded = FALSE;
|
||||
@ -434,7 +426,6 @@ otr_keygen(ProfAccount* account)
|
||||
|
||||
data_loaded = TRUE;
|
||||
|
||||
g_free(otr_dir);
|
||||
g_string_free(keysfilename, TRUE);
|
||||
g_string_free(fpsfilename, TRUE);
|
||||
return;
|
||||
|
@ -177,25 +177,23 @@ p_gpg_on_connect(const char* const barejid)
|
||||
|
||||
// load each keyid
|
||||
gsize len = 0;
|
||||
gchar** jids = g_key_file_get_groups(pubkeyfile, &len);
|
||||
auto_gcharv gchar** jids = g_key_file_get_groups(pubkeyfile, &len);
|
||||
|
||||
gpgme_ctx_t ctx;
|
||||
gpgme_error_t error = gpgme_new(&ctx);
|
||||
|
||||
if (error) {
|
||||
log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error));
|
||||
g_strfreev(jids);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
GError* gerr = NULL;
|
||||
gchar* jid = jids[i];
|
||||
gchar* keyid = g_key_file_get_string(pubkeyfile, jid, "keyid", &gerr);
|
||||
auto_gchar gchar* keyid = g_key_file_get_string(pubkeyfile, jid, "keyid", &gerr);
|
||||
if (gerr) {
|
||||
log_error("Error loading PGP key id for %s", jid);
|
||||
g_error_free(gerr);
|
||||
g_free(keyid);
|
||||
} else {
|
||||
gpgme_key_t key = NULL;
|
||||
error = gpgme_get_key(ctx, keyid, &key, 0);
|
||||
@ -208,13 +206,11 @@ p_gpg_on_connect(const char* const barejid)
|
||||
pubkeyid->id = strdup(keyid);
|
||||
pubkeyid->received = FALSE;
|
||||
g_hash_table_replace(pubkeys, strdup(jid), pubkeyid);
|
||||
g_free(keyid);
|
||||
gpgme_key_unref(key);
|
||||
}
|
||||
}
|
||||
|
||||
gpgme_release(ctx);
|
||||
g_strfreev(jids);
|
||||
|
||||
_save_pubkeys();
|
||||
}
|
||||
@ -978,8 +974,7 @@ static void
|
||||
_save_pubkeys(void)
|
||||
{
|
||||
gsize g_data_size;
|
||||
gchar* g_pubkeys_data = g_key_file_to_data(pubkeyfile, &g_data_size, NULL);
|
||||
auto_gchar gchar* g_pubkeys_data = g_key_file_to_data(pubkeyfile, &g_data_size, NULL);
|
||||
g_file_set_contents(pubsloc, g_pubkeys_data, g_data_size, NULL);
|
||||
g_chmod(pubsloc, S_IRUSR | S_IWUSR);
|
||||
g_free(g_pubkeys_data);
|
||||
}
|
||||
|
@ -525,9 +525,8 @@ c_api_init(void)
|
||||
static char*
|
||||
_c_plugin_name(const char* filename)
|
||||
{
|
||||
gchar* name = g_strndup(filename, strlen(filename) - 1);
|
||||
auto_gchar gchar* name = g_strndup(filename, strlen(filename) - 1);
|
||||
gchar* result = g_strdup_printf("%sso", name);
|
||||
g_free(name);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ callbacks_get_window_handler(const char* tag)
|
||||
gboolean
|
||||
plugins_run_command(const char* const input)
|
||||
{
|
||||
gchar** split = g_strsplit(input, " ", -1);
|
||||
auto_gcharv gchar** split = g_strsplit(input, " ", -1);
|
||||
|
||||
GList* command_hashes = g_hash_table_get_values(p_commands);
|
||||
GList* curr_hash = command_hashes;
|
||||
@ -283,26 +283,20 @@ plugins_run_command(const char* const input)
|
||||
PluginCommand* command = g_hash_table_lookup(command_hash, split[0]);
|
||||
if (command) {
|
||||
gboolean result;
|
||||
gchar** args = parse_args_with_freetext(input, command->min_args, command->max_args, &result);
|
||||
auto_gcharv gchar** args = parse_args_with_freetext(input, command->min_args, command->max_args, &result);
|
||||
if (result == FALSE) {
|
||||
ui_invalid_command_usage(command->command_name, NULL);
|
||||
g_strfreev(split);
|
||||
g_list_free(command_hashes);
|
||||
return TRUE;
|
||||
} else {
|
||||
command->callback_exec(command, args);
|
||||
g_strfreev(split);
|
||||
g_strfreev(args);
|
||||
g_list_free(command_hashes);
|
||||
return TRUE;
|
||||
}
|
||||
g_list_free(command_hashes);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
curr_hash = g_list_next(curr_hash);
|
||||
}
|
||||
|
||||
g_list_free(command_hashes);
|
||||
g_strfreev(split);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -82,50 +82,47 @@ plugins_init(void)
|
||||
#endif
|
||||
|
||||
// load plugins
|
||||
gchar** plugins_pref = prefs_get_plugins();
|
||||
if (plugins_pref) {
|
||||
for (int i = 0; i < g_strv_length(plugins_pref); i++) {
|
||||
gboolean loaded = FALSE;
|
||||
gchar* filename = plugins_pref[i];
|
||||
auto_gcharv gchar** plugins_pref = prefs_get_plugins();
|
||||
if (!plugins_pref) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < g_strv_length(plugins_pref); i++) {
|
||||
gboolean loaded = FALSE;
|
||||
gchar* filename = plugins_pref[i];
|
||||
#ifdef HAVE_PYTHON
|
||||
if (g_str_has_suffix(filename, ".py")) {
|
||||
ProfPlugin* plugin = python_plugin_create(filename);
|
||||
if (plugin) {
|
||||
g_hash_table_insert(plugins, strdup(filename), plugin);
|
||||
loaded = TRUE;
|
||||
}
|
||||
if (g_str_has_suffix(filename, ".py")) {
|
||||
ProfPlugin* plugin = python_plugin_create(filename);
|
||||
if (plugin) {
|
||||
g_hash_table_insert(plugins, strdup(filename), plugin);
|
||||
loaded = TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_C
|
||||
if (g_str_has_suffix(filename, ".so")) {
|
||||
ProfPlugin* plugin = c_plugin_create(filename);
|
||||
if (plugin) {
|
||||
g_hash_table_insert(plugins, strdup(filename), plugin);
|
||||
loaded = TRUE;
|
||||
}
|
||||
if (g_str_has_suffix(filename, ".so")) {
|
||||
ProfPlugin* plugin = c_plugin_create(filename);
|
||||
if (plugin) {
|
||||
g_hash_table_insert(plugins, strdup(filename), plugin);
|
||||
loaded = TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (loaded) {
|
||||
log_info("Loaded plugin: %s", filename);
|
||||
} else {
|
||||
log_info("Failed to load plugin: %s", filename);
|
||||
}
|
||||
if (loaded) {
|
||||
log_info("Loaded plugin: %s", filename);
|
||||
} else {
|
||||
log_info("Failed to load plugin: %s", filename);
|
||||
}
|
||||
|
||||
// initialise plugins
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList* curr = values;
|
||||
while (curr) {
|
||||
ProfPlugin* plugin = curr->data;
|
||||
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, NULL, NULL);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(values);
|
||||
}
|
||||
|
||||
prefs_free_plugins(plugins_pref);
|
||||
|
||||
return;
|
||||
// initialise plugins
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList* curr = values;
|
||||
while (curr) {
|
||||
ProfPlugin* plugin = curr->data;
|
||||
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, NULL, NULL);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(values);
|
||||
}
|
||||
|
||||
void
|
||||
@ -660,7 +657,7 @@ plugins_on_room_history_message(const char* const barejid, const char* const nic
|
||||
char*
|
||||
plugins_pre_priv_message_display(const char* const fulljid, const char* message)
|
||||
{
|
||||
Jid* jidp = jid_create(fulljid);
|
||||
auto_jid Jid* jidp = jid_create(fulljid);
|
||||
char* new_message = NULL;
|
||||
char* curr_message = strdup(message);
|
||||
|
||||
@ -677,15 +674,13 @@ plugins_pre_priv_message_display(const char* const fulljid, const char* message)
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(values);
|
||||
|
||||
jid_destroy(jidp);
|
||||
return curr_message;
|
||||
}
|
||||
|
||||
void
|
||||
plugins_post_priv_message_display(const char* const fulljid, const char* message)
|
||||
{
|
||||
Jid* jidp = jid_create(fulljid);
|
||||
auto_jid Jid* jidp = jid_create(fulljid);
|
||||
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList* curr = values;
|
||||
@ -695,14 +690,12 @@ plugins_post_priv_message_display(const char* const fulljid, const char* message
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(values);
|
||||
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
char*
|
||||
plugins_pre_priv_message_send(const char* const fulljid, const char* const message)
|
||||
{
|
||||
Jid* jidp = jid_create(fulljid);
|
||||
auto_jid Jid* jidp = jid_create(fulljid);
|
||||
char* new_message = NULL;
|
||||
char* curr_message = strdup(message);
|
||||
|
||||
@ -719,7 +712,6 @@ plugins_pre_priv_message_send(const char* const fulljid, const char* const messa
|
||||
} else {
|
||||
free(curr_message);
|
||||
g_list_free(values);
|
||||
jid_destroy(jidp);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -728,14 +720,13 @@ plugins_pre_priv_message_send(const char* const fulljid, const char* const messa
|
||||
}
|
||||
g_list_free(values);
|
||||
|
||||
jid_destroy(jidp);
|
||||
return curr_message;
|
||||
}
|
||||
|
||||
void
|
||||
plugins_post_priv_message_send(const char* const fulljid, const char* const message)
|
||||
{
|
||||
Jid* jidp = jid_create(fulljid);
|
||||
auto_jid Jid* jidp = jid_create(fulljid);
|
||||
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList* curr = values;
|
||||
@ -744,9 +735,8 @@ plugins_post_priv_message_send(const char* const fulljid, const char* const mess
|
||||
plugin->post_priv_message_send(plugin, jidp->barejid, jidp->resourcepart, message);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(values);
|
||||
|
||||
jid_destroy(jidp);
|
||||
g_list_free(values);
|
||||
}
|
||||
|
||||
char*
|
||||
|
@ -75,7 +75,7 @@ theme_item_t
|
||||
plugin_themes_get(const char* const group, const char* const key, const char* const def)
|
||||
{
|
||||
if (group && key && g_key_file_has_key(themes, group, key, NULL)) {
|
||||
gchar* result = g_key_file_get_string(themes, group, key, NULL);
|
||||
auto_gchar gchar* result = g_key_file_get_string(themes, group, key, NULL);
|
||||
|
||||
theme_item_t ret;
|
||||
|
||||
@ -148,8 +148,6 @@ plugin_themes_get(const char* const group, const char* const key, const char* co
|
||||
else
|
||||
ret = THEME_TEXT;
|
||||
|
||||
g_free(result);
|
||||
|
||||
return ret;
|
||||
|
||||
} else {
|
||||
|
@ -303,11 +303,10 @@ get_start(const char* const string, int tokens)
|
||||
gunichar curr_uni = g_utf8_get_char(curr_ch);
|
||||
|
||||
if (num_tokens < tokens) {
|
||||
gchar* uni_char = g_malloc(7);
|
||||
auto_gchar gchar* uni_char = g_malloc(7);
|
||||
int len = g_unichar_to_utf8(curr_uni, uni_char);
|
||||
uni_char[len] = '\0';
|
||||
g_string_append(result, uni_char);
|
||||
g_free(uni_char);
|
||||
}
|
||||
if (curr_uni == ' ') {
|
||||
if (!in_quotes) {
|
||||
|
@ -1141,9 +1141,8 @@ cons_show_account(ProfAccount* account)
|
||||
win_append(console, presence_colour, ", \"%s\"", resource->status);
|
||||
}
|
||||
win_appendln(console, THEME_DEFAULT, "");
|
||||
Jid* jidp = jid_create_from_bare_and_resource(account->jid, resource->name);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(account->jid, resource->name);
|
||||
EntityCapabilities* caps = caps_lookup(jidp->fulljid);
|
||||
jid_destroy(jidp);
|
||||
|
||||
if (caps) {
|
||||
// show identity
|
||||
@ -2198,30 +2197,25 @@ cons_correction_setting(void)
|
||||
void
|
||||
cons_executable_setting(void)
|
||||
{
|
||||
gchar* avatar = prefs_get_string(PREF_AVATAR_CMD);
|
||||
auto_gchar gchar* avatar = prefs_get_string(PREF_AVATAR_CMD);
|
||||
cons_show("Default '/avatar open' command (/executable avatar) : %s", avatar);
|
||||
g_free(avatar);
|
||||
|
||||
// TODO: there needs to be a way to get all the "locales"/schemes so we can
|
||||
// display the default openers for all filetypes
|
||||
gchar* urlopen = prefs_get_string(PREF_URL_OPEN_CMD);
|
||||
auto_gchar gchar* urlopen = prefs_get_string(PREF_URL_OPEN_CMD);
|
||||
cons_show("Default '/url open' command (/executable urlopen) : %s", urlopen);
|
||||
g_free(urlopen);
|
||||
|
||||
gchar* urlsave = prefs_get_string(PREF_URL_SAVE_CMD);
|
||||
auto_gchar gchar* urlsave = prefs_get_string(PREF_URL_SAVE_CMD);
|
||||
if (urlsave == NULL) {
|
||||
urlsave = g_strdup("(built-in)");
|
||||
}
|
||||
cons_show("Default '/url save' command (/executable urlsave) : %s", urlsave);
|
||||
g_free(urlsave);
|
||||
|
||||
gchar* editor = prefs_get_string(PREF_COMPOSE_EDITOR);
|
||||
auto_gchar gchar* editor = prefs_get_string(PREF_COMPOSE_EDITOR);
|
||||
cons_show("Default '/editor' command (/executable editor) : %s", editor);
|
||||
g_free(editor);
|
||||
|
||||
gchar* vcard_cmd = prefs_get_string(PREF_VCARD_PHOTO_CMD);
|
||||
auto_gchar gchar* vcard_cmd = prefs_get_string(PREF_VCARD_PHOTO_CMD);
|
||||
cons_show("Default '/vcard photo open' command (/executable vcard_photo) : %s", vcard_cmd);
|
||||
g_free(vcard_cmd);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1045,7 +1045,6 @@ ui_contact_offline(char* barejid, char* resource, char* status)
|
||||
{
|
||||
auto_gchar gchar* show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
|
||||
auto_gchar gchar* show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
|
||||
Jid* jid = jid_create_from_bare_and_resource(barejid, resource);
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
if (p_contact_subscription(contact)) {
|
||||
if (strcmp(p_contact_subscription(contact), "none") != 0) {
|
||||
@ -1080,8 +1079,6 @@ ui_contact_offline(char* barejid, char* resource, char* status)
|
||||
if (chatwin && chatwin->resource_override && (g_strcmp0(resource, chatwin->resource_override) == 0)) {
|
||||
FREE_SET_NULL(chatwin->resource_override);
|
||||
}
|
||||
|
||||
jid_destroy(jid);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1261,13 +1258,12 @@ void
|
||||
ui_show_software_version(const char* const jid, const char* const presence,
|
||||
const char* const name, const char* const version, const char* const os)
|
||||
{
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
ProfWin* window = NULL;
|
||||
ProfWin* chatwin = (ProfWin*)wins_get_chat(jidp->barejid);
|
||||
ProfWin* mucwin = (ProfWin*)wins_get_muc(jidp->barejid);
|
||||
ProfWin* privwin = (ProfWin*)wins_get_private(jidp->fulljid);
|
||||
ProfWin* console = wins_get_console();
|
||||
jid_destroy(jidp);
|
||||
|
||||
if (chatwin) {
|
||||
if (wins_is_current(chatwin)) {
|
||||
|
@ -562,10 +562,9 @@ _inp_rl_startup_hook(void)
|
||||
rl_variable_bind("disable-completion", "on");
|
||||
|
||||
// check for and load ~/.config/profanity/inputrc
|
||||
gchar* inputrc = files_get_inputrc_file();
|
||||
auto_gchar gchar* inputrc = files_get_inputrc_file();
|
||||
if (inputrc) {
|
||||
rl_read_init_file(inputrc);
|
||||
g_free(inputrc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -948,7 +947,7 @@ _inp_rl_send_to_editor(int count, int key)
|
||||
return 0;
|
||||
}
|
||||
|
||||
gchar* message = NULL;
|
||||
auto_gchar gchar* message = NULL;
|
||||
|
||||
if (get_message_from_editor(rl_line_buffer, &message)) {
|
||||
return 0;
|
||||
@ -958,7 +957,6 @@ _inp_rl_send_to_editor(int count, int key)
|
||||
ui_resize();
|
||||
rl_point = rl_end;
|
||||
rl_forced_update_display();
|
||||
g_free(message);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -77,9 +77,8 @@ notifier_uninit(void)
|
||||
void
|
||||
notify_typing(const char* const name)
|
||||
{
|
||||
gchar* message = g_strdup_printf("%s: typing…", name);
|
||||
auto_gchar gchar* message = g_strdup_printf("%s: typing…", name);
|
||||
notify(message, 10000, "Incoming message");
|
||||
g_free(message);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -85,9 +85,8 @@ _occuptantswin_occupant(ProfLayoutSplit* layout, GList* item, gboolean showjid,
|
||||
gboolean wrap = prefs_get_boolean(PREF_OCCUPANTS_WRAP);
|
||||
|
||||
if (isoffline) {
|
||||
Jid* jid = jid_create(item->data);
|
||||
auto_jid Jid* jid = jid_create(item->data);
|
||||
g_string_append(msg, jid->barejid);
|
||||
jid_destroy(jid);
|
||||
} else {
|
||||
g_string_append(msg, occupant->nick);
|
||||
}
|
||||
@ -208,7 +207,7 @@ occupantswin_occupants(const char* const roomjid)
|
||||
g_string_free(role, TRUE);
|
||||
roster_curr = members;
|
||||
while (roster_curr) {
|
||||
Jid* jid = jid_create(roster_curr->data);
|
||||
auto_jid Jid* jid = jid_create(roster_curr->data);
|
||||
gboolean found = false;
|
||||
GList* iter = online_occupants;
|
||||
for (; iter != NULL; iter = iter->next) {
|
||||
@ -223,7 +222,6 @@ occupantswin_occupants(const char* const roomjid)
|
||||
offline_occupants = g_list_append(offline_occupants, jid->barejid);
|
||||
}
|
||||
|
||||
jid_destroy(jid);
|
||||
roster_curr = g_list_next(roster_curr);
|
||||
}
|
||||
g_list_free(members);
|
||||
|
@ -59,7 +59,7 @@ privwin_incoming_msg(ProfPrivateWin* privatewin, ProfMessage* message)
|
||||
ProfWin* window = (ProfWin*)privatewin;
|
||||
int num = wins_get_num(window);
|
||||
|
||||
Jid* jidp = jid_create(privatewin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privatewin->fulljid);
|
||||
if (jidp == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -97,8 +97,6 @@ privwin_incoming_msg(ProfPrivateWin* privatewin, ProfMessage* message)
|
||||
if (notify) {
|
||||
notify_message(jidp->resourcepart, num, message->plain);
|
||||
}
|
||||
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
void
|
||||
@ -133,9 +131,8 @@ privwin_occupant_offline(ProfPrivateWin* privwin)
|
||||
assert(privwin != NULL);
|
||||
|
||||
privwin->occupant_offline = TRUE;
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
win_println((ProfWin*)privwin, THEME_OFFLINE, "-", "<- %s has left the room.", jidp->resourcepart);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
void
|
||||
@ -144,9 +141,8 @@ privwin_occupant_kicked(ProfPrivateWin* privwin, const char* const actor, const
|
||||
assert(privwin != NULL);
|
||||
|
||||
privwin->occupant_offline = TRUE;
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
GString* message = g_string_new(jidp->resourcepart);
|
||||
jid_destroy(jidp);
|
||||
g_string_append(message, " has been kicked from the room");
|
||||
if (actor) {
|
||||
g_string_append(message, " by ");
|
||||
@ -167,9 +163,8 @@ privwin_occupant_banned(ProfPrivateWin* privwin, const char* const actor, const
|
||||
assert(privwin != NULL);
|
||||
|
||||
privwin->occupant_offline = TRUE;
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
GString* message = g_string_new(jidp->resourcepart);
|
||||
jid_destroy(jidp);
|
||||
g_string_append(message, " has been banned from the room");
|
||||
if (actor) {
|
||||
g_string_append(message, " by ");
|
||||
@ -190,9 +185,8 @@ privwin_occupant_online(ProfPrivateWin* privwin)
|
||||
assert(privwin != NULL);
|
||||
|
||||
privwin->occupant_offline = FALSE;
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
win_println((ProfWin*)privwin, THEME_ONLINE, "-", "-- %s has joined the room.", jidp->resourcepart);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
void
|
||||
@ -201,9 +195,8 @@ privwin_room_destroyed(ProfPrivateWin* privwin)
|
||||
assert(privwin != NULL);
|
||||
|
||||
privwin->room_left = TRUE;
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
win_println((ProfWin*)privwin, THEME_OFFLINE, "!", "-- %s has been destroyed.", jidp->barejid);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
void
|
||||
@ -212,9 +205,8 @@ privwin_room_joined(ProfPrivateWin* privwin)
|
||||
assert(privwin != NULL);
|
||||
|
||||
privwin->room_left = FALSE;
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
win_println((ProfWin*)privwin, THEME_OFFLINE, "!", "-- You have joined %s.", jidp->barejid);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
void
|
||||
@ -223,9 +215,8 @@ privwin_room_left(ProfPrivateWin* privwin)
|
||||
assert(privwin != NULL);
|
||||
|
||||
privwin->room_left = TRUE;
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
win_println((ProfWin*)privwin, THEME_OFFLINE, "!", "-- You have left %s.", jidp->barejid);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
void
|
||||
@ -235,9 +226,8 @@ privwin_room_kicked(ProfPrivateWin* privwin, const char* const actor, const char
|
||||
|
||||
privwin->room_left = TRUE;
|
||||
GString* message = g_string_new("Kicked from ");
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
g_string_append(message, jidp->barejid);
|
||||
jid_destroy(jidp);
|
||||
if (actor) {
|
||||
g_string_append(message, " by ");
|
||||
g_string_append(message, actor);
|
||||
@ -258,9 +248,8 @@ privwin_room_banned(ProfPrivateWin* privwin, const char* const actor, const char
|
||||
|
||||
privwin->room_left = TRUE;
|
||||
GString* message = g_string_new("Banned from ");
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
g_string_append(message, jidp->barejid);
|
||||
jid_destroy(jidp);
|
||||
if (actor) {
|
||||
g_string_append(message, " by ");
|
||||
g_string_append(message, actor);
|
||||
|
@ -113,11 +113,10 @@ rosterwin_roster(void)
|
||||
GList* curr = privchats;
|
||||
while (curr) {
|
||||
ProfPrivateWin* privwin = curr->data;
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
if (!muc_active(jidp->barejid)) {
|
||||
orphaned_privchats = g_list_append(orphaned_privchats, privwin);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
|
||||
@ -163,11 +162,10 @@ rosterwin_roster(void)
|
||||
GList* curr = privchats;
|
||||
while (curr) {
|
||||
ProfPrivateWin* privwin = curr->data;
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
if (!muc_active(jidp->barejid)) {
|
||||
orphaned_privchats = g_list_append(orphaned_privchats, privwin);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
|
||||
@ -677,13 +675,12 @@ _rosterwin_rooms_by_service(ProfLayoutSplit* layout)
|
||||
GList* services = NULL;
|
||||
while (curr) {
|
||||
char* roomjid = curr->data;
|
||||
Jid* jidp = jid_create(roomjid);
|
||||
auto_jid Jid* jidp = jid_create(roomjid);
|
||||
|
||||
if (!g_list_find_custom(services, jidp->domainpart, (GCompareFunc)g_strcmp0)) {
|
||||
services = g_list_insert_sorted(services, strdup(jidp->domainpart), (GCompareFunc)g_strcmp0);
|
||||
}
|
||||
|
||||
jid_destroy(jidp);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
|
||||
@ -695,13 +692,12 @@ _rosterwin_rooms_by_service(ProfLayoutSplit* layout)
|
||||
curr = rooms;
|
||||
while (curr) {
|
||||
char* roomjid = curr->data;
|
||||
Jid* jidp = jid_create(roomjid);
|
||||
auto_jid Jid* jidp = jid_create(roomjid);
|
||||
|
||||
if (g_strcmp0(curr_service->data, jidp->domainpart) == 0) {
|
||||
filtered_rooms = g_list_append(filtered_rooms, strdup(jidp->barejid));
|
||||
}
|
||||
|
||||
jid_destroy(jidp);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
|
||||
@ -754,9 +750,8 @@ _rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin)
|
||||
|
||||
if (g_strcmp0(roombypref, "service") == 0) {
|
||||
if (mucwin->room_name == NULL || (g_strcmp0(use_as_name, "jid") == 0)) {
|
||||
Jid* jidp = jid_create(mucwin->roomjid);
|
||||
auto_jid Jid* jidp = jid_create(mucwin->roomjid);
|
||||
g_string_append(msg, jidp->localpart);
|
||||
jid_destroy(jidp);
|
||||
} else {
|
||||
g_string_append(msg, mucwin->room_name);
|
||||
}
|
||||
@ -770,15 +765,13 @@ _rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin)
|
||||
g_string_append(msg, mucwin->room_name);
|
||||
}
|
||||
} else {
|
||||
Jid* jidp = jid_create(mucwin->roomjid);
|
||||
auto_jid Jid* jidp = jid_create(mucwin->roomjid);
|
||||
|
||||
if (mucwin->room_name == NULL || (g_strcmp0(use_as_name, "jid") == 0)) {
|
||||
g_string_append(msg, jidp->localpart);
|
||||
} else {
|
||||
g_string_append(msg, mucwin->room_name);
|
||||
}
|
||||
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -830,8 +823,8 @@ _rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin)
|
||||
}
|
||||
}
|
||||
|
||||
unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
|
||||
if ((g_strcmp0(unreadpos, "before") == 0) && privwin->unread > 0) {
|
||||
auto_gchar gchar* unreadpos2 = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD);
|
||||
if ((g_strcmp0(unreadpos2, "before") == 0) && privwin->unread > 0) {
|
||||
g_string_append_printf(privmsg, "(%d) ", privwin->unread);
|
||||
}
|
||||
|
||||
@ -843,7 +836,7 @@ _rosterwin_room(ProfLayoutSplit* layout, ProfMucWin* mucwin)
|
||||
char* nick = privwin->fulljid + strlen(mucwin->roomjid) + 1;
|
||||
g_string_append(privmsg, nick);
|
||||
|
||||
if ((g_strcmp0(unreadpos, "after") == 0) && privwin->unread > 0) {
|
||||
if ((g_strcmp0(unreadpos2, "after") == 0) && privwin->unread > 0) {
|
||||
g_string_append_printf(privmsg, " (%d)", privwin->unread);
|
||||
}
|
||||
|
||||
@ -937,9 +930,8 @@ _rosterwin_private_chats(ProfLayoutSplit* layout, GList* orphaned_privchats)
|
||||
g_string_append_printf(privmsg, " (%d)", privwin->unread);
|
||||
}
|
||||
|
||||
Jid* jidp = jid_create(privwin->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(privwin->fulljid);
|
||||
Occupant* occupant = muc_roster_item(jidp->barejid, jidp->resourcepart);
|
||||
jid_destroy(jidp);
|
||||
|
||||
const char* presence = "offline";
|
||||
if (occupant) {
|
||||
|
@ -201,10 +201,9 @@ _create_tab(const int win, win_type_t wintype, char* identifier, gboolean highli
|
||||
if (pcontact_name) {
|
||||
tab->display_name = strdup(pcontact_name);
|
||||
} else {
|
||||
Jid* jidp = jid_create(tab->identifier);
|
||||
auto_jid Jid* jidp = jid_create(tab->identifier);
|
||||
if (jidp) {
|
||||
tab->display_name = jidp->localpart != NULL ? strdup(jidp->localpart) : strdup(jidp->barejid);
|
||||
jid_destroy(jidp);
|
||||
} else {
|
||||
tab->display_name = strdup(tab->identifier);
|
||||
}
|
||||
@ -543,15 +542,13 @@ _status_bar_draw_maintext(int pos)
|
||||
return pos;
|
||||
}
|
||||
if (g_strcmp0(pref, "user") == 0) {
|
||||
Jid* jidp = jid_create(statusbar->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(statusbar->fulljid);
|
||||
mvwprintw(statusbar_win, 0, pos, "%s", jidp->localpart);
|
||||
jid_destroy(jidp);
|
||||
return pos;
|
||||
}
|
||||
if (g_strcmp0(pref, "barejid") == 0) {
|
||||
Jid* jidp = jid_create(statusbar->fulljid);
|
||||
auto_jid Jid* jidp = jid_create(statusbar->fulljid);
|
||||
mvwprintw(statusbar_win, 0, pos, "%s", jidp->barejid);
|
||||
jid_destroy(jidp);
|
||||
return pos;
|
||||
}
|
||||
|
||||
@ -655,9 +652,8 @@ _display_name(StatusBarTab* tab)
|
||||
} else if (tab->window_type == WIN_MUC) {
|
||||
auto_gchar gchar* pref = prefs_get_string(PREF_STATUSBAR_ROOM);
|
||||
if (g_strcmp0("room", pref) == 0) {
|
||||
Jid* jidp = jid_create(tab->identifier);
|
||||
auto_jid Jid* jidp = jid_create(tab->identifier);
|
||||
char* room = strdup(jidp->localpart);
|
||||
jid_destroy(jidp);
|
||||
fullname = room;
|
||||
} else {
|
||||
fullname = strdup(tab->identifier);
|
||||
@ -667,9 +663,8 @@ _display_name(StatusBarTab* tab)
|
||||
GString* display_str = g_string_new("");
|
||||
|
||||
if (g_strcmp0("room", pref) == 0) {
|
||||
Jid* jidp = jid_create(tab->identifier);
|
||||
auto_jid Jid* jidp = jid_create(tab->identifier);
|
||||
g_string_append(display_str, jidp->localpart);
|
||||
jid_destroy(jidp);
|
||||
} else {
|
||||
g_string_append(display_str, tab->identifier);
|
||||
}
|
||||
@ -682,11 +677,10 @@ _display_name(StatusBarTab* tab)
|
||||
auto_gchar gchar* pref = prefs_get_string(PREF_STATUSBAR_ROOM);
|
||||
if (g_strcmp0("room", pref) == 0) {
|
||||
GString* display_str = g_string_new("");
|
||||
Jid* jidp = jid_create(tab->identifier);
|
||||
auto_jid Jid* jidp = jid_create(tab->identifier);
|
||||
g_string_append(display_str, jidp->localpart);
|
||||
g_string_append(display_str, "/");
|
||||
g_string_append(display_str, jidp->resourcepart);
|
||||
jid_destroy(jidp);
|
||||
char* result = strdup(display_str->str);
|
||||
g_string_free(display_str, TRUE);
|
||||
fullname = result;
|
||||
|
@ -79,9 +79,8 @@ _get_icons(void)
|
||||
|
||||
#endif /* ICONS_PATH */
|
||||
|
||||
gchar* icons_dir_s = files_get_config_path(DIR_ICONS);
|
||||
auto_gchar gchar* icons_dir_s = files_get_config_path(DIR_ICONS);
|
||||
icons_dir = g_string_new(icons_dir_s);
|
||||
g_free(icons_dir_s);
|
||||
GError* err = NULL;
|
||||
|
||||
if (!g_file_test(icons_dir->str, G_FILE_TEST_IS_DIR)) {
|
||||
|
@ -691,12 +691,12 @@ win_page_down(ProfWin* window)
|
||||
if ((*page_start == y || (*page_start == page_space && *page_start >= y)) && window->type == WIN_CHAT) {
|
||||
int bf_size = buffer_size(window->layout->buffer);
|
||||
if (bf_size > 0) {
|
||||
char* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time);
|
||||
auto_gchar gchar* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time);
|
||||
GDateTime* now = g_date_time_new_now_local();
|
||||
char* end = g_date_time_format_iso8601(now);
|
||||
gchar* end = g_date_time_format_iso8601(now);
|
||||
// end is free'd inside
|
||||
chatwin_db_history((ProfChatWin*)window, start, end, FALSE);
|
||||
|
||||
g_free(start);
|
||||
g_date_time_unref(now);
|
||||
}
|
||||
}
|
||||
@ -976,9 +976,8 @@ win_show_occupant_info(ProfWin* window, const char* const room, Occupant* occupa
|
||||
win_println(window, THEME_DEFAULT, "!", " Affiliation: %s", occupant_affiliation);
|
||||
win_println(window, THEME_DEFAULT, "!", " Role: %s", occupant_role);
|
||||
|
||||
Jid* jidp = jid_create_from_bare_and_resource(room, occupant->nick);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(room, occupant->nick);
|
||||
EntityCapabilities* caps = caps_lookup(jidp->fulljid);
|
||||
jid_destroy(jidp);
|
||||
|
||||
if (caps) {
|
||||
// show identity
|
||||
@ -1099,9 +1098,8 @@ win_show_info(ProfWin* window, PContact contact)
|
||||
}
|
||||
win_newline(window);
|
||||
|
||||
Jid* jidp = jid_create_from_bare_and_resource(barejid, resource->name);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(barejid, resource->name);
|
||||
EntityCapabilities* caps = caps_lookup(jidp->fulljid);
|
||||
jid_destroy(jidp);
|
||||
|
||||
if (caps) {
|
||||
// show identity
|
||||
@ -1496,7 +1494,7 @@ win_print_history(ProfWin* window, const ProfMessage* const message)
|
||||
auto_gchar gchar* display_name;
|
||||
int flags = 0;
|
||||
const char* jid = connection_get_fulljid();
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
|
||||
if (g_strcmp0(jidp->barejid, message->from_jid->barejid) == 0) {
|
||||
display_name = strdup("me");
|
||||
@ -1505,8 +1503,6 @@ win_print_history(ProfWin* window, const ProfMessage* const message)
|
||||
flags = NO_ME;
|
||||
}
|
||||
|
||||
jid_destroy(jidp);
|
||||
|
||||
buffer_append(window->layout->buffer, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
|
||||
wins_add_urls_ac(window, message, FALSE);
|
||||
wins_add_quotes_ac(window, message->plain, FALSE);
|
||||
@ -1521,10 +1517,10 @@ win_print_old_history(ProfWin* window, const ProfMessage* const message)
|
||||
{
|
||||
g_date_time_ref(message->timestamp);
|
||||
|
||||
auto_gchar gchar* display_name;
|
||||
auto_char char* display_name;
|
||||
int flags = 0;
|
||||
const char* jid = connection_get_fulljid();
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
|
||||
if (g_strcmp0(jidp->barejid, message->from_jid->barejid) == 0) {
|
||||
display_name = strdup("me");
|
||||
@ -1533,8 +1529,6 @@ win_print_old_history(ProfWin* window, const ProfMessage* const message)
|
||||
flags = NO_ME;
|
||||
}
|
||||
|
||||
jid_destroy(jidp);
|
||||
|
||||
buffer_prepend(window->layout->buffer, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
|
||||
wins_add_urls_ac(window, message, TRUE);
|
||||
wins_add_quotes_ac(window, message->plain, TRUE);
|
||||
@ -1788,7 +1782,7 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
|
||||
int colour = theme_attrs(THEME_ME);
|
||||
size_t indent = 0;
|
||||
|
||||
char* time_pref = NULL;
|
||||
auto_gchar gchar* time_pref = NULL;
|
||||
switch (window->type) {
|
||||
case WIN_CHAT:
|
||||
time_pref = prefs_get_string(PREF_TIME_CHAT);
|
||||
@ -1810,13 +1804,12 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
|
||||
break;
|
||||
}
|
||||
|
||||
gchar* date_fmt = NULL;
|
||||
auto_gchar gchar* date_fmt = NULL;
|
||||
if (g_strcmp0(time_pref, "off") == 0 || time == NULL) {
|
||||
date_fmt = g_strdup("");
|
||||
} else {
|
||||
date_fmt = g_date_time_format(time, time_pref);
|
||||
}
|
||||
g_free(time_pref);
|
||||
assert(date_fmt != NULL);
|
||||
|
||||
if (strlen(date_fmt) != 0) {
|
||||
@ -1903,8 +1896,6 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
|
||||
wattroff(window->layout->win, theme_attrs(theme_item));
|
||||
}
|
||||
}
|
||||
|
||||
g_free(date_fmt);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -2309,21 +2300,17 @@ win_quote_autocomplete(ProfWin* window, const char* const input, gboolean previo
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* result = autocomplete_complete(window->quotes_ac, input + 1, FALSE, previous);
|
||||
auto_gchar gchar* result = autocomplete_complete(window->quotes_ac, input + 1, FALSE, previous);
|
||||
if (result == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gchar** parts = g_strsplit(result, "\n", -1);
|
||||
gchar* quoted_result = g_strjoinv("\n> ", parts);
|
||||
auto_gcharv gchar** parts = g_strsplit(result, "\n", -1);
|
||||
auto_gchar gchar* quoted_result = g_strjoinv("\n> ", parts);
|
||||
|
||||
GString* replace_with = g_string_new("> ");
|
||||
g_string_append(replace_with, quoted_result);
|
||||
g_string_append(replace_with, "\n");
|
||||
|
||||
g_free(result);
|
||||
g_free(quoted_result);
|
||||
g_strfreev(parts);
|
||||
|
||||
return g_string_free(replace_with, FALSE);
|
||||
}
|
||||
|
@ -276,13 +276,13 @@ wins_get_private_chats(const char* const roomjid)
|
||||
void
|
||||
wins_private_nick_change(const char* const roomjid, const char* const oldnick, const char* const newnick)
|
||||
{
|
||||
Jid* oldjid = jid_create_from_bare_and_resource(roomjid, oldnick);
|
||||
auto_jid Jid* oldjid = jid_create_from_bare_and_resource(roomjid, oldnick);
|
||||
|
||||
ProfPrivateWin* privwin = wins_get_private(oldjid->fulljid);
|
||||
if (privwin) {
|
||||
free(privwin->fulljid);
|
||||
|
||||
Jid* newjid = jid_create_from_bare_and_resource(roomjid, newnick);
|
||||
auto_jid Jid* newjid = jid_create_from_bare_and_resource(roomjid, newnick);
|
||||
privwin->fulljid = strdup(newjid->fulljid);
|
||||
win_println((ProfWin*)privwin, THEME_THEM, "!", "** %s is now known as %s.", oldjid->resourcepart, newjid->resourcepart);
|
||||
|
||||
@ -290,11 +290,7 @@ wins_private_nick_change(const char* const roomjid, const char* const oldnick, c
|
||||
autocomplete_remove(wins_close_ac, oldjid->fulljid);
|
||||
autocomplete_add(wins_ac, newjid->fulljid);
|
||||
autocomplete_add(wins_close_ac, newjid->fulljid);
|
||||
|
||||
jid_destroy(newjid);
|
||||
}
|
||||
|
||||
jid_destroy(oldjid);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1318,7 +1314,7 @@ wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message, con
|
||||
g_regex_match(regex, message->plain, 0, &match_info);
|
||||
|
||||
while (g_match_info_matches(match_info)) {
|
||||
gchar* word = g_match_info_fetch(match_info, 0);
|
||||
auto_gchar gchar* word = g_match_info_fetch(match_info, 0);
|
||||
|
||||
if (flip) {
|
||||
autocomplete_add_unsorted(win->urls_ac, word, FALSE);
|
||||
@ -1328,7 +1324,6 @@ wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message, con
|
||||
// for people who run profanity a long time, we don't want to waste a lot of memory
|
||||
autocomplete_remove_older_than_max_reverse(win->urls_ac, 20);
|
||||
|
||||
g_free(word);
|
||||
g_match_info_next(match_info, NULL);
|
||||
}
|
||||
|
||||
|
@ -317,7 +317,7 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use
|
||||
}
|
||||
}
|
||||
|
||||
auto_gchar gchar* from = str_replace(from_attr, "@", "_at_");
|
||||
auto_char char* from = str_replace(from_attr, "@", "_at_");
|
||||
g_string_append(filename, from);
|
||||
|
||||
avatar_metadata* data = (avatar_metadata*)userdata;
|
||||
@ -345,18 +345,16 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use
|
||||
|
||||
// if we shall open it
|
||||
if (g_hash_table_contains(shall_open, from_attr)) {
|
||||
gchar* cmdtemplate = prefs_get_string(PREF_AVATAR_CMD);
|
||||
auto_gchar gchar* cmdtemplate = prefs_get_string(PREF_AVATAR_CMD);
|
||||
|
||||
if (cmdtemplate == NULL) {
|
||||
cons_show_error("No default `avatar open` command found in executables preferences.");
|
||||
} else {
|
||||
gchar** argv = format_call_external_argv(cmdtemplate, NULL, filename->str);
|
||||
auto_gcharv gchar** argv = format_call_external_argv(cmdtemplate, NULL, filename->str);
|
||||
|
||||
if (!call_external(argv)) {
|
||||
cons_show_error("Unable to display avatar: check the logs for more information.");
|
||||
}
|
||||
|
||||
g_strfreev(argv);
|
||||
}
|
||||
|
||||
g_hash_table_remove(shall_open, from_attr);
|
||||
|
@ -93,11 +93,10 @@ bookmark_add(const char* jid, const char* nick, const char* password, const char
|
||||
{
|
||||
assert(jid != NULL);
|
||||
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
if (jidp->domainpart) {
|
||||
muc_confserver_add(jidp->domainpart);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
|
||||
if (g_hash_table_contains(bookmarks, jid)) {
|
||||
return FALSE;
|
||||
@ -334,11 +333,10 @@ _bookmark_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
sv_ev_bookmark_autojoin(bookmark);
|
||||
}
|
||||
|
||||
Jid* jidp = jid_create(barejid);
|
||||
auto_jid Jid* jidp = jid_create(barejid);
|
||||
if (jidp->domainpart) {
|
||||
muc_confserver_add(jidp->domainpart);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
|
||||
child = xmpp_stanza_get_next(child);
|
||||
}
|
||||
@ -387,11 +385,10 @@ _send_bookmarks(void)
|
||||
xmpp_stanza_set_attribute(conference, STANZA_ATTR_NAME, bookmark->name);
|
||||
} else {
|
||||
// use localpart of JID by if no name is specified
|
||||
Jid* jidp = jid_create(bookmark->barejid);
|
||||
auto_jid Jid* jidp = jid_create(bookmark->barejid);
|
||||
if (jidp->localpart) {
|
||||
xmpp_stanza_set_attribute(conference, STANZA_ATTR_NAME, jidp->localpart);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
|
||||
if (bookmark->autojoin) {
|
||||
|
@ -65,7 +65,7 @@ static GHashTable* jid_to_ver;
|
||||
static GHashTable* jid_to_caps;
|
||||
|
||||
static GHashTable* prof_features;
|
||||
static char* my_sha1;
|
||||
static gchar* my_sha1;
|
||||
|
||||
static void _save_cache(void);
|
||||
static EntityCapabilities* _caps_by_ver(const char* const ver);
|
||||
@ -378,7 +378,7 @@ _caps_by_ver(const char* const ver)
|
||||
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);
|
||||
auto_gcharv gchar** features_list = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL);
|
||||
GSList* features = NULL;
|
||||
if (features_list && features_len > 0) {
|
||||
for (int i = 0; i < features_len; i++) {
|
||||
@ -391,9 +391,6 @@ _caps_by_ver(const char* const ver)
|
||||
software, software_version, os, os_version,
|
||||
features);
|
||||
|
||||
if (features_list) {
|
||||
g_strfreev(features_list);
|
||||
}
|
||||
g_slist_free(features);
|
||||
|
||||
return result;
|
||||
@ -464,8 +461,7 @@ static void
|
||||
_save_cache(void)
|
||||
{
|
||||
gsize g_data_size;
|
||||
gchar* g_cache_data = g_key_file_to_data(cache, &g_data_size, NULL);
|
||||
auto_gchar gchar* g_cache_data = g_key_file_to_data(cache, &g_data_size, NULL);
|
||||
g_file_set_contents(cache_loc, g_cache_data, g_data_size, NULL);
|
||||
g_chmod(cache_loc, S_IRUSR | S_IWUSR);
|
||||
g_free(g_cache_data);
|
||||
}
|
||||
|
@ -110,9 +110,8 @@ chat_session_get_jid(const char* const barejid)
|
||||
ChatSession* session = chat_session_get(barejid);
|
||||
char* jid = NULL;
|
||||
if (session) {
|
||||
Jid* jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
|
||||
jid = strdup(jidp->fulljid);
|
||||
jid_destroy(jidp);
|
||||
} else {
|
||||
jid = strdup(barejid);
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ connection_shutdown(void)
|
||||
static gboolean
|
||||
_conn_apply_settings(const char* const jid, const char* const passwd, const char* const tls_policy, const char* const auth_policy)
|
||||
{
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
if (jidp == NULL) {
|
||||
log_error("Malformed JID not able to connect: %s", jid);
|
||||
conn.conn_status = JABBER_DISCONNECTED;
|
||||
@ -189,7 +189,6 @@ _conn_apply_settings(const char* const jid, const char* const passwd, const char
|
||||
}
|
||||
|
||||
_compute_identifier(jidp->barejid);
|
||||
jid_destroy(jidp);
|
||||
|
||||
xmpp_ctx_set_verbosity(conn.xmpp_ctx, 0);
|
||||
xmpp_conn_set_jid(conn.xmpp_conn, jid);
|
||||
|
@ -877,9 +877,9 @@ _caps_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
}
|
||||
|
||||
// validate sha1
|
||||
gchar** split = g_strsplit(node, "#", -1);
|
||||
auto_gcharv gchar** split = g_strsplit(node, "#", -1);
|
||||
char* given_sha1 = split[1];
|
||||
char* generated_sha1 = stanza_create_caps_sha1_from_query(query);
|
||||
auto_gchar gchar* generated_sha1 = stanza_create_caps_sha1_from_query(query);
|
||||
|
||||
if (g_strcmp0(given_sha1, generated_sha1) != 0) {
|
||||
log_warning("Generated sha-1 does not match given:");
|
||||
@ -901,9 +901,6 @@ _caps_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
caps_map_jid_to_ver(from, given_sha1);
|
||||
}
|
||||
|
||||
g_free(generated_sha1);
|
||||
g_strfreev(split);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1079,16 +1076,15 @@ _room_list_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
const char* stanza_name = xmpp_stanza_get_name(child);
|
||||
if (stanza_name && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) {
|
||||
const char* item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
|
||||
gchar* item_jid_lower = NULL;
|
||||
auto_gchar gchar* item_jid_lower = NULL;
|
||||
if (item_jid) {
|
||||
Jid* jidp = jid_create(item_jid);
|
||||
auto_jid Jid* jidp = jid_create(item_jid);
|
||||
if (jidp && jidp->localpart) {
|
||||
item_jid_lower = g_utf8_strdown(jidp->localpart, -1);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
const char* item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
|
||||
gchar* item_name_lower = NULL;
|
||||
auto_gchar gchar* item_name_lower = NULL;
|
||||
if (item_name) {
|
||||
item_name_lower = g_utf8_strdown(item_name, -1);
|
||||
}
|
||||
@ -1106,8 +1102,6 @@ _room_list_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
cons_show(" %s", item->str);
|
||||
g_string_free(item, TRUE);
|
||||
}
|
||||
g_free(item_jid_lower);
|
||||
g_free(item_name_lower);
|
||||
}
|
||||
child = xmpp_stanza_get_next(child);
|
||||
}
|
||||
@ -1508,7 +1502,7 @@ _version_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
|
||||
xmpp_ctx_t* ctx = connection_get_ctx();
|
||||
|
||||
Jid* jidp = jid_create((char*)userdata);
|
||||
auto_jid Jid* jidp = jid_create((char*)userdata);
|
||||
|
||||
const char* presence = NULL;
|
||||
|
||||
@ -1546,8 +1540,6 @@ _version_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
ui_show_software_version(jidp->barejid, "online", name_str, version_str, os_str);
|
||||
}
|
||||
|
||||
jid_destroy(jidp);
|
||||
|
||||
if (name_str)
|
||||
xmpp_free(ctx, name_str);
|
||||
if (version_str)
|
||||
@ -2594,7 +2586,7 @@ iq_mam_request_older(ProfChatWin* win)
|
||||
|
||||
ProfMessage* first_msg = log_database_get_limits_info(win->barejid, FALSE);
|
||||
char* firstid = NULL;
|
||||
char* enddate = NULL;
|
||||
auto_gchar gchar* enddate = NULL;
|
||||
|
||||
// If first message found
|
||||
if (first_msg->timestamp) {
|
||||
@ -2608,7 +2600,6 @@ iq_mam_request_older(ProfChatWin* win)
|
||||
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, win->barejid, NULL, enddate, firstid, NULL);
|
||||
iq_id_handler_add(xmpp_stanza_get_id(iq), _mam_buffer_commit_handler, NULL, win);
|
||||
|
||||
g_free(enddate);
|
||||
message_free(first_msg);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
|
@ -163,9 +163,8 @@ jid_is_valid_room_form(Jid* jid)
|
||||
char*
|
||||
create_fulljid(const char* const barejid, const char* const resource)
|
||||
{
|
||||
gchar* barejidlower = g_utf8_strdown(barejid, -1);
|
||||
auto_gchar gchar* barejidlower = g_utf8_strdown(barejid, -1);
|
||||
GString* full_jid = g_string_new(barejidlower);
|
||||
g_free(barejidlower);
|
||||
g_string_append(full_jid, "/");
|
||||
g_string_append(full_jid, resource);
|
||||
|
||||
@ -209,7 +208,7 @@ jid_fulljid_or_barejid(Jid* jid)
|
||||
}
|
||||
}
|
||||
|
||||
char*
|
||||
gchar*
|
||||
jid_random_resource(void)
|
||||
{
|
||||
auto_char char* rand = get_random_string(4);
|
||||
|
@ -64,6 +64,6 @@ char* create_fulljid(const char* const barejid, const char* const resource);
|
||||
char* get_nick_from_full_jid(const char* const full_room_jid);
|
||||
|
||||
char* jid_fulljid_or_barejid(Jid* jid);
|
||||
char* jid_random_resource(void);
|
||||
gchar* jid_random_resource(void);
|
||||
|
||||
#endif
|
||||
|
@ -647,10 +647,9 @@ message_send_chat_omemo(const char* const jid, uint32_t sid, GList* keys,
|
||||
xmpp_stanza_set_attribute(key_stanza, "prekey", "true");
|
||||
}
|
||||
|
||||
gchar* key_raw = g_base64_encode(key->data, key->length);
|
||||
auto_gchar gchar* key_raw = g_base64_encode(key->data, key->length);
|
||||
xmpp_stanza_t* key_text = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(key_text, key_raw);
|
||||
g_free(key_raw);
|
||||
|
||||
xmpp_stanza_add_child(key_stanza, key_text);
|
||||
xmpp_stanza_add_child(header, key_stanza);
|
||||
@ -661,10 +660,9 @@ message_send_chat_omemo(const char* const jid, uint32_t sid, GList* keys,
|
||||
xmpp_stanza_t* iv_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(iv_stanza, "iv");
|
||||
|
||||
gchar* iv_raw = g_base64_encode(iv, iv_len);
|
||||
auto_gchar gchar* iv_raw = g_base64_encode(iv, iv_len);
|
||||
xmpp_stanza_t* iv_text = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(iv_text, iv_raw);
|
||||
g_free(iv_raw);
|
||||
|
||||
xmpp_stanza_add_child(iv_stanza, iv_text);
|
||||
xmpp_stanza_add_child(header, iv_stanza);
|
||||
@ -677,10 +675,9 @@ message_send_chat_omemo(const char* const jid, uint32_t sid, GList* keys,
|
||||
xmpp_stanza_t* payload = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(payload, "payload");
|
||||
|
||||
gchar* ciphertext_raw = g_base64_encode(ciphertext, ciphertext_len);
|
||||
auto_gchar gchar* ciphertext_raw = g_base64_encode(ciphertext, ciphertext_len);
|
||||
xmpp_stanza_t* payload_text = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(payload_text, ciphertext_raw);
|
||||
g_free(ciphertext_raw);
|
||||
|
||||
xmpp_stanza_add_child(payload, payload_text);
|
||||
xmpp_stanza_add_child(encrypted, payload);
|
||||
|
@ -495,11 +495,10 @@ muc_roster_add(const char* const room, const char* const nick, const char* const
|
||||
g_hash_table_replace(chat_room->roster, strdup(nick), occupant);
|
||||
|
||||
if (jid) {
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
if (jidp->barejid) {
|
||||
autocomplete_add(chat_room->jid_ac, jidp->barejid);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -737,7 +736,7 @@ muc_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
}
|
||||
}
|
||||
|
||||
char* result = autocomplete_complete(chat_room->nick_ac, search_str, FALSE, previous);
|
||||
auto_gchar gchar* result = autocomplete_complete(chat_room->nick_ac, search_str, FALSE, previous);
|
||||
if (result == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -748,7 +747,6 @@ muc_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
if (strlen(chat_room->autocomplete_prefix) == 0) {
|
||||
g_string_append(replace_with, ": ");
|
||||
}
|
||||
g_free(result);
|
||||
return g_string_free(replace_with, FALSE);
|
||||
}
|
||||
|
||||
@ -772,13 +770,12 @@ muc_jid_autocomplete_add_all(const char* const room, GSList* jids)
|
||||
GSList* curr_jid = jids;
|
||||
while (curr_jid) {
|
||||
const char* jid = curr_jid->data;
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
if (jidp) {
|
||||
if (jidp->barejid) {
|
||||
autocomplete_add(chat_room->jid_ac, jidp->barejid);
|
||||
}
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
curr_jid = g_slist_next(curr_jid);
|
||||
}
|
||||
}
|
||||
|
@ -389,21 +389,21 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
size_t iv_len;
|
||||
iv_raw = g_base64_decode(iv_text, &iv_len);
|
||||
if (!iv_raw) {
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xmpp_stanza_t* payload = xmpp_stanza_get_child_by_name(encrypted, "payload");
|
||||
if (!payload) {
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
payload_text = xmpp_stanza_get_text(payload);
|
||||
if (!payload_text) {
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
size_t payload_len;
|
||||
payload_raw = g_base64_decode(payload_text, &payload_len);
|
||||
if (!payload_raw) {
|
||||
goto out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xmpp_stanza_t* key_stanza;
|
||||
@ -415,27 +415,26 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
omemo_key_t* key = malloc(sizeof(omemo_key_t));
|
||||
char* key_text = xmpp_stanza_get_text(key_stanza);
|
||||
if (!key_text) {
|
||||
goto skip;
|
||||
free(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
const char* rid_text = xmpp_stanza_get_attribute(key_stanza, "rid");
|
||||
key->device_id = strtoul(rid_text, NULL, 10);
|
||||
if (!key->device_id) {
|
||||
goto skip;
|
||||
free(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
key->data = g_base64_decode(key_text, &key->length);
|
||||
free(key_text);
|
||||
if (!key->data) {
|
||||
goto skip;
|
||||
free(key);
|
||||
continue;
|
||||
}
|
||||
key->prekey = g_strcmp0(xmpp_stanza_get_attribute(key_stanza, "prekey"), "true") == 0
|
||||
|| g_strcmp0(xmpp_stanza_get_attribute(key_stanza, "prekey"), "1") == 0;
|
||||
keys = g_list_append(keys, key);
|
||||
continue;
|
||||
|
||||
skip:
|
||||
free(key);
|
||||
}
|
||||
|
||||
const char* from = xmpp_stanza_get_from(stanza);
|
||||
@ -444,7 +443,6 @@ skip:
|
||||
keys, payload_raw, payload_len,
|
||||
g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0, trusted);
|
||||
|
||||
out:
|
||||
if (keys) {
|
||||
g_list_free_full(keys, (GDestroyNotify)omemo_key_free);
|
||||
}
|
||||
@ -610,8 +608,8 @@ _omemo_devicelist_configure_submit(xmpp_stanza_t* const stanza, void* const user
|
||||
form_set_value(form, "pubsub#access_model", "open");
|
||||
|
||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||
Jid* jid = jid_create(connection_get_fulljid());
|
||||
char* id = connection_create_stanza_id();
|
||||
auto_jid Jid* jid = jid_create(connection_get_fulljid());
|
||||
auto_char char* id = connection_create_stanza_id();
|
||||
xmpp_stanza_t* iq = stanza_create_pubsub_configure_submit(ctx, id, jid->barejid, STANZA_NS_OMEMO_DEVICELIST, form);
|
||||
|
||||
iq_id_handler_add(id, _omemo_devicelist_configure_result, NULL, NULL);
|
||||
@ -619,8 +617,6 @@ _omemo_devicelist_configure_submit(xmpp_stanza_t* const stanza, void* const user
|
||||
iq_send_stanza(iq);
|
||||
|
||||
xmpp_stanza_release(iq);
|
||||
free(id);
|
||||
jid_destroy(jid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -664,8 +660,8 @@ _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
|
||||
log_debug("[OMEMO] cannot publish bundle with open access model, trying to configure node");
|
||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||
Jid* jid = jid_create(connection_get_fulljid());
|
||||
char* id = connection_create_stanza_id();
|
||||
auto_jid Jid* jid = jid_create(connection_get_fulljid());
|
||||
auto_char char* id = connection_create_stanza_id();
|
||||
auto_gchar gchar* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id());
|
||||
log_debug("[OMEMO] node: %s", node);
|
||||
|
||||
@ -676,8 +672,6 @@ _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
iq_send_stanza(iq);
|
||||
|
||||
xmpp_stanza_release(iq);
|
||||
free(id);
|
||||
jid_destroy(jid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -706,8 +700,8 @@ _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdat
|
||||
form_set_value(form, "pubsub#access_model", "open");
|
||||
|
||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||
Jid* jid = jid_create(connection_get_fulljid());
|
||||
char* id = connection_create_stanza_id();
|
||||
auto_jid Jid* jid = jid_create(connection_get_fulljid());
|
||||
auto_char char* id = connection_create_stanza_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);
|
||||
|
||||
@ -716,8 +710,6 @@ _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdat
|
||||
iq_send_stanza(iq);
|
||||
|
||||
xmpp_stanza_release(iq);
|
||||
free(id);
|
||||
jid_destroy(jid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ presence_subscription(const char* const jid, const jabber_subscr_t action)
|
||||
{
|
||||
assert(jid != NULL);
|
||||
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
autocomplete_remove(sub_requests_ac, jidp->barejid);
|
||||
|
||||
const char* type = NULL;
|
||||
@ -129,7 +129,6 @@ presence_subscription(const char* const jid, const jabber_subscr_t action)
|
||||
|
||||
xmpp_stanza_set_type(presence, type);
|
||||
xmpp_stanza_set_to(presence, jidp->barejid);
|
||||
jid_destroy(jidp);
|
||||
|
||||
_send_presence_stanza(presence);
|
||||
|
||||
@ -278,7 +277,7 @@ _send_room_presence(xmpp_stanza_t* presence)
|
||||
void
|
||||
presence_join_room(const char* const room, const char* const nick, const char* const passwd)
|
||||
{
|
||||
Jid* jid = jid_create_from_bare_and_resource(room, nick);
|
||||
auto_jid Jid* jid = jid_create_from_bare_and_resource(room, nick);
|
||||
log_debug("Sending room join presence to: %s", jid->fulljid);
|
||||
|
||||
resource_presence_t presence_type = accounts_get_last_presence(session_get_account_name());
|
||||
@ -296,7 +295,6 @@ presence_join_room(const char* const room, const char* const nick, const char* c
|
||||
_send_presence_stanza(presence);
|
||||
|
||||
xmpp_stanza_release(presence);
|
||||
jid_destroy(jid);
|
||||
}
|
||||
|
||||
void
|
||||
@ -415,13 +413,12 @@ _presence_error_handler(xmpp_stanza_t* const stanza)
|
||||
error_cond = "unknown";
|
||||
}
|
||||
|
||||
Jid* fulljid = jid_create(from);
|
||||
auto_jid Jid* fulljid = jid_create(from);
|
||||
log_info("Error joining room: %s, reason: %s", fulljid->barejid, error_cond);
|
||||
if (muc_active(fulljid->barejid)) {
|
||||
muc_leave(fulljid->barejid);
|
||||
}
|
||||
cons_show_error("Error joining room %s, reason: %s", fulljid->barejid, error_cond);
|
||||
jid_destroy(fulljid);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -472,11 +469,9 @@ _unsubscribed_handler(xmpp_stanza_t* const stanza)
|
||||
}
|
||||
log_debug("Unsubscribed presence handler fired for %s", from);
|
||||
|
||||
Jid* from_jid = jid_create(from);
|
||||
auto_jid Jid* from_jid = jid_create(from);
|
||||
sv_ev_subscription(from_jid->barejid, PRESENCE_UNSUBSCRIBED);
|
||||
autocomplete_remove(sub_requests_ac, from_jid->barejid);
|
||||
|
||||
jid_destroy(from_jid);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -489,11 +484,9 @@ _subscribed_handler(xmpp_stanza_t* const stanza)
|
||||
}
|
||||
log_debug("Subscribed presence handler fired for %s", from);
|
||||
|
||||
Jid* from_jid = jid_create(from);
|
||||
auto_jid Jid* from_jid = jid_create(from);
|
||||
sv_ev_subscription(from_jid->barejid, PRESENCE_SUBSCRIBED);
|
||||
autocomplete_remove(sub_requests_ac, from_jid->barejid);
|
||||
|
||||
jid_destroy(from_jid);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -505,15 +498,13 @@ _subscribe_handler(xmpp_stanza_t* const stanza)
|
||||
}
|
||||
log_debug("Subscribe presence handler fired for %s", from);
|
||||
|
||||
Jid* from_jid = jid_create(from);
|
||||
auto_jid Jid* from_jid = jid_create(from);
|
||||
if (from_jid == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
sv_ev_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE);
|
||||
autocomplete_add(sub_requests_ac, from_jid->barejid);
|
||||
|
||||
jid_destroy(from_jid);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -529,11 +520,9 @@ _unavailable_handler(xmpp_stanza_t* const stanza)
|
||||
}
|
||||
log_debug("Unavailable presence handler fired for %s", from);
|
||||
|
||||
Jid* my_jid = jid_create(jid);
|
||||
Jid* from_jid = jid_create(from);
|
||||
auto_jid Jid* my_jid = jid_create(jid);
|
||||
auto_jid Jid* from_jid = jid_create(from);
|
||||
if (my_jid == NULL || from_jid == NULL) {
|
||||
jid_destroy(my_jid);
|
||||
jid_destroy(from_jid);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -551,9 +540,6 @@ _unavailable_handler(xmpp_stanza_t* const stanza)
|
||||
connection_remove_available_resource(from_jid->resourcepart);
|
||||
}
|
||||
}
|
||||
|
||||
jid_destroy(my_jid);
|
||||
jid_destroy(from_jid);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -634,7 +620,7 @@ _available_handler(xmpp_stanza_t* const stanza)
|
||||
|
||||
xmpp_conn_t* conn = connection_get_conn();
|
||||
const char* my_jid_str = xmpp_conn_get_jid(conn);
|
||||
Jid* my_jid = jid_create(my_jid_str);
|
||||
auto_jid Jid* my_jid = jid_create(my_jid_str);
|
||||
|
||||
XMPPCaps* caps = stanza_parse_caps(stanza);
|
||||
if ((g_strcmp0(my_jid->fulljid, xmpp_presence->jid->fulljid) != 0) && caps) {
|
||||
@ -651,7 +637,7 @@ _available_handler(xmpp_stanza_t* const stanza)
|
||||
const char* account_name = session_get_account_name();
|
||||
int max_sessions = accounts_get_max_sessions(account_name);
|
||||
if (max_sessions > 0) {
|
||||
const char* cur_resource = accounts_get_resource(account_name);
|
||||
const gchar* cur_resource = accounts_get_resource(account_name);
|
||||
int res_count = connection_count_available_resources();
|
||||
if (res_count > max_sessions && g_strcmp0(cur_resource, resource->name)) {
|
||||
ProfWin* console = wins_get_console();
|
||||
@ -721,7 +707,6 @@ _available_handler(xmpp_stanza_t* const stanza)
|
||||
xmpp_free(ctx, pgpsig);
|
||||
}
|
||||
|
||||
jid_destroy(my_jid);
|
||||
stanza_free_presence(xmpp_presence);
|
||||
}
|
||||
|
||||
@ -752,7 +737,7 @@ static void
|
||||
_muc_user_self_handler(xmpp_stanza_t* stanza)
|
||||
{
|
||||
const char* from = xmpp_stanza_get_from(stanza);
|
||||
Jid* from_jid = jid_create(from);
|
||||
auto_jid Jid* from_jid = jid_create(from);
|
||||
|
||||
log_debug("Room self presence received from %s", from_jid->fulljid);
|
||||
|
||||
@ -823,8 +808,6 @@ _muc_user_self_handler(xmpp_stanza_t* stanza)
|
||||
}
|
||||
sv_ev_muc_self_online(room, nick, config_required, role, affiliation, actor, reason, jid, show_str, status_str);
|
||||
}
|
||||
|
||||
jid_destroy(from_jid);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -921,13 +904,11 @@ _muc_user_handler(xmpp_stanza_t* const stanza)
|
||||
return;
|
||||
}
|
||||
|
||||
Jid* from_jid = jid_create(from);
|
||||
auto_jid Jid* from_jid = jid_create(from);
|
||||
if (from_jid == NULL || from_jid->resourcepart == NULL) {
|
||||
log_warning("MUC User stanza received with invalid from attribute: %s", from);
|
||||
jid_destroy(from_jid);
|
||||
return;
|
||||
}
|
||||
jid_destroy(from_jid);
|
||||
|
||||
if (stanza_is_muc_self_presence(stanza, connection_get_fulljid())) {
|
||||
_muc_user_self_handler(stanza);
|
||||
|
@ -268,7 +268,7 @@ roster_result_handler(xmpp_stanza_t* const stanza)
|
||||
|
||||
while (item) {
|
||||
const char* barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID);
|
||||
gchar* barejid_lower = g_utf8_strdown(barejid, -1);
|
||||
auto_gchar gchar* barejid_lower = g_utf8_strdown(barejid, -1);
|
||||
const char* name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME);
|
||||
const char* sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION);
|
||||
|
||||
@ -289,7 +289,6 @@ roster_result_handler(xmpp_stanza_t* const stanza)
|
||||
log_warning("Attempt to add contact twice: %s", barejid_lower);
|
||||
}
|
||||
|
||||
g_free(barejid_lower);
|
||||
item = xmpp_stanza_get_next(item);
|
||||
}
|
||||
|
||||
|
@ -151,9 +151,8 @@ roster_update_presence(const char* const barejid, Resource* resource, GDateTime*
|
||||
p_contact_set_last_activity(contact, last_activity);
|
||||
}
|
||||
p_contact_set_presence(contact, resource);
|
||||
Jid* jid = jid_create_from_bare_and_resource(barejid, resource->name);
|
||||
auto_jid Jid* jid = jid_create_from_bare_and_resource(barejid, resource->name);
|
||||
autocomplete_add(roster->fulljid_ac, jid->fulljid);
|
||||
jid_destroy(jid);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -163,9 +162,8 @@ roster_get_contact(const char* const barejid)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
gchar* barejidlower = g_utf8_strdown(barejid, -1);
|
||||
auto_gchar gchar* barejidlower = g_utf8_strdown(barejid, -1);
|
||||
PContact contact = g_hash_table_lookup(roster->contacts, barejidlower);
|
||||
g_free(barejidlower);
|
||||
|
||||
return contact;
|
||||
}
|
||||
@ -238,9 +236,8 @@ roster_contact_offline(const char* const barejid, const char* const resource, co
|
||||
} else {
|
||||
gboolean result = p_contact_remove_resource(contact, resource);
|
||||
if (result == TRUE) {
|
||||
Jid* jid = jid_create_from_bare_and_resource(barejid, resource);
|
||||
auto_jid Jid* jid = jid_create_from_bare_and_resource(barejid, resource);
|
||||
autocomplete_remove(roster->fulljid_ac, jid->fulljid);
|
||||
jid_destroy(jid);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -123,9 +123,8 @@ session_connect_with_account(const ProfAccount* const account)
|
||||
|
||||
auto_char char* jid = NULL;
|
||||
if (account->resource) {
|
||||
Jid* jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
|
||||
jid = strdup(jidp->fulljid);
|
||||
jid_destroy(jidp);
|
||||
} else {
|
||||
jid = strdup(account->jid);
|
||||
}
|
||||
@ -175,16 +174,15 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
|
||||
}
|
||||
|
||||
// use 'profanity' when no resourcepart in provided jid
|
||||
Jid* jidp = jid_create(jid);
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
if (jidp->resourcepart == NULL) {
|
||||
auto_gchar gchar* resource = jid_random_resource();
|
||||
jid_destroy(jidp);
|
||||
auto_char char* resource = jid_random_resource();
|
||||
jidp = jid_create_from_bare_and_resource(jid, resource);
|
||||
saved_details.jid = strdup(jidp->fulljid);
|
||||
} else {
|
||||
saved_details.jid = strdup(jid);
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
|
||||
// connect with fulljid
|
||||
log_info("Connecting without account, JID: %s", saved_details.jid);
|
||||
|
@ -61,7 +61,7 @@
|
||||
#include "database.h"
|
||||
|
||||
static void _stanza_add_unique_id(xmpp_stanza_t* stanza);
|
||||
static char* _stanza_create_sha1_hash(char* str);
|
||||
static gchar* _stanza_create_sha1_hash(char* str);
|
||||
|
||||
#if 0
|
||||
xmpp_stanza_t*
|
||||
@ -233,10 +233,9 @@ stanza_create_http_upload_request(xmpp_ctx_t* ctx, const char* const id,
|
||||
}
|
||||
xmpp_stanza_set_attribute(request, STANZA_ATTR_FILENAME, basename(filename_cpy));
|
||||
|
||||
gchar* filesize = g_strdup_printf("%jd", (intmax_t)(upload->filesize));
|
||||
auto_gchar gchar* filesize = g_strdup_printf("%jd", (intmax_t)(upload->filesize));
|
||||
if (filesize) {
|
||||
xmpp_stanza_set_attribute(request, STANZA_ATTR_SIZE, filesize);
|
||||
g_free(filesize);
|
||||
}
|
||||
|
||||
xmpp_stanza_set_attribute(request, STANZA_ATTR_CONTENTTYPE, upload->mime_type);
|
||||
@ -1026,7 +1025,7 @@ stanza_create_ping_iq(xmpp_ctx_t* ctx, const char* const target)
|
||||
return iq;
|
||||
}
|
||||
|
||||
char*
|
||||
gchar*
|
||||
stanza_create_caps_sha1_from_query(xmpp_stanza_t* const query)
|
||||
{
|
||||
GSList* identities = NULL;
|
||||
@ -1116,7 +1115,7 @@ stanza_create_caps_sha1_from_query(xmpp_stanza_t* const query)
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
char* result = _stanza_create_sha1_hash(s->str);
|
||||
gchar* result = _stanza_create_sha1_hash(s->str);
|
||||
|
||||
g_string_free(s, TRUE);
|
||||
g_slist_free_full(identities, g_free);
|
||||
@ -1396,11 +1395,10 @@ stanza_is_muc_self_presence(xmpp_stanza_t* const stanza,
|
||||
// check if 'from' attribute identifies this user
|
||||
const char* from = xmpp_stanza_get_from(stanza);
|
||||
if (from) {
|
||||
Jid* from_jid = jid_create(from);
|
||||
auto_jid Jid* from_jid = jid_create(from);
|
||||
if (muc_active(from_jid->barejid)) {
|
||||
char* nick = muc_nick(from_jid->barejid);
|
||||
if (g_strcmp0(from_jid->resourcepart, nick) == 0) {
|
||||
jid_destroy(from_jid);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@ -1412,13 +1410,10 @@ stanza_is_muc_self_presence(xmpp_stanza_t* const stanza,
|
||||
char* nick = muc_nick(from_jid->barejid);
|
||||
char* old_nick = muc_old_nick(from_jid->barejid, new_nick);
|
||||
if (g_strcmp0(old_nick, nick) == 0) {
|
||||
jid_destroy(from_jid);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jid_destroy(from_jid);
|
||||
}
|
||||
|
||||
// self presence not found
|
||||
@ -2353,9 +2348,8 @@ stanza_create_omemo_bundle_publish(xmpp_ctx_t* ctx, const char* const id,
|
||||
xmpp_stanza_set_attribute(signed_prekey_public_stanza, "signedPreKeyId", "1");
|
||||
|
||||
xmpp_stanza_t* signed_prekey_public_stanza_text = xmpp_stanza_new(ctx);
|
||||
char* signed_prekey_b64 = g_base64_encode(signed_prekey, signed_prekey_length);
|
||||
auto_gchar gchar* signed_prekey_b64 = g_base64_encode(signed_prekey, signed_prekey_length);
|
||||
xmpp_stanza_set_text(signed_prekey_public_stanza_text, signed_prekey_b64);
|
||||
g_free(signed_prekey_b64);
|
||||
xmpp_stanza_add_child(signed_prekey_public_stanza, signed_prekey_public_stanza_text);
|
||||
xmpp_stanza_release(signed_prekey_public_stanza_text);
|
||||
|
||||
@ -2363,9 +2357,8 @@ stanza_create_omemo_bundle_publish(xmpp_ctx_t* ctx, const char* const id,
|
||||
xmpp_stanza_set_name(signed_prekey_signature_stanza, "signedPreKeySignature");
|
||||
|
||||
xmpp_stanza_t* signed_prekey_signature_stanza_text = xmpp_stanza_new(ctx);
|
||||
char* signed_prekey_signature_b64 = g_base64_encode(signed_prekey_signature, signed_prekey_signature_length);
|
||||
auto_gchar gchar* signed_prekey_signature_b64 = g_base64_encode(signed_prekey_signature, signed_prekey_signature_length);
|
||||
xmpp_stanza_set_text(signed_prekey_signature_stanza_text, signed_prekey_signature_b64);
|
||||
g_free(signed_prekey_signature_b64);
|
||||
xmpp_stanza_add_child(signed_prekey_signature_stanza, signed_prekey_signature_stanza_text);
|
||||
xmpp_stanza_release(signed_prekey_signature_stanza_text);
|
||||
|
||||
@ -2373,9 +2366,8 @@ stanza_create_omemo_bundle_publish(xmpp_ctx_t* ctx, const char* const id,
|
||||
xmpp_stanza_set_name(identity_key_stanza, "identityKey");
|
||||
|
||||
xmpp_stanza_t* identity_key_stanza_text = xmpp_stanza_new(ctx);
|
||||
char* identity_key_b64 = g_base64_encode(identity_key, identity_key_length);
|
||||
auto_gchar gchar* identity_key_b64 = g_base64_encode(identity_key, identity_key_length);
|
||||
xmpp_stanza_set_text(identity_key_stanza_text, identity_key_b64);
|
||||
g_free(identity_key_b64);
|
||||
xmpp_stanza_add_child(identity_key_stanza, identity_key_stanza_text);
|
||||
xmpp_stanza_release(identity_key_stanza_text);
|
||||
|
||||
@ -2390,9 +2382,8 @@ stanza_create_omemo_bundle_publish(xmpp_ctx_t* ctx, const char* const id,
|
||||
xmpp_stanza_set_attribute(prekey, "preKeyId", id);
|
||||
|
||||
xmpp_stanza_t* prekey_text = xmpp_stanza_new(ctx);
|
||||
char* prekey_b64 = g_base64_encode(p->data, GPOINTER_TO_INT(l->data));
|
||||
auto_gchar gchar* prekey_b64 = g_base64_encode(p->data, GPOINTER_TO_INT(l->data));
|
||||
xmpp_stanza_set_text(prekey_text, prekey_b64);
|
||||
g_free(prekey_b64);
|
||||
|
||||
xmpp_stanza_add_child(prekey, prekey_text);
|
||||
xmpp_stanza_add_child(prekeys_stanza, prekey);
|
||||
@ -2517,7 +2508,7 @@ _stanza_add_unique_id(xmpp_stanza_t* stanza)
|
||||
xmpp_stanza_set_id(stanza, id);
|
||||
}
|
||||
|
||||
static char*
|
||||
static gchar*
|
||||
_stanza_create_sha1_hash(char* str)
|
||||
{
|
||||
unsigned char* digest = (unsigned char*)malloc(XMPP_SHA1_DIGEST_SIZE);
|
||||
@ -2525,7 +2516,7 @@ _stanza_create_sha1_hash(char* str)
|
||||
|
||||
xmpp_sha1_digest((unsigned char*)str, strlen(str), digest);
|
||||
|
||||
char* b64 = g_base64_encode(digest, XMPP_SHA1_DIGEST_SIZE);
|
||||
gchar* b64 = g_base64_encode(digest, XMPP_SHA1_DIGEST_SIZE);
|
||||
assert(b64 != NULL);
|
||||
free(digest);
|
||||
|
||||
|
@ -380,7 +380,7 @@ void stanza_attach_show(xmpp_ctx_t* const ctx, xmpp_stanza_t* const presence, co
|
||||
void stanza_attach_status(xmpp_ctx_t* const ctx, xmpp_stanza_t* const presence, const char* const status);
|
||||
|
||||
xmpp_stanza_t* stanza_create_caps_query_element(xmpp_ctx_t* ctx);
|
||||
char* stanza_create_caps_sha1_from_query(xmpp_stanza_t* const query);
|
||||
gchar* stanza_create_caps_sha1_from_query(xmpp_stanza_t* const query);
|
||||
EntityCapabilities* stanza_create_caps_from_query_element(xmpp_stanza_t* query);
|
||||
|
||||
const char* stanza_get_presence_string_from_type(resource_presence_t presence_type);
|
||||
|
@ -757,10 +757,9 @@ vcard_to_xml(xmpp_ctx_t* const ctx, vCard* vcard)
|
||||
xmpp_stanza_t* binval = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(binval, "BINVAL");
|
||||
|
||||
gchar* base64 = g_base64_encode(element->photo.data, element->photo.length);
|
||||
auto_gchar gchar* base64 = g_base64_encode(element->photo.data, element->photo.length);
|
||||
xmpp_stanza_t* binval_text = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(binval_text, base64);
|
||||
g_free(base64);
|
||||
xmpp_stanza_add_child(binval, binval_text);
|
||||
xmpp_stanza_release(binval_text);
|
||||
|
||||
@ -789,10 +788,9 @@ vcard_to_xml(xmpp_ctx_t* const ctx, vCard* vcard)
|
||||
xmpp_stanza_t* birthday = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(birthday, "BDAY");
|
||||
|
||||
gchar* bday_text = g_date_time_format(element->birthday, "%Y-%m-%d");
|
||||
auto_gchar gchar* bday_text = g_date_time_format(element->birthday, "%Y-%m-%d");
|
||||
xmpp_stanza_t* birthday_text = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(birthday_text, bday_text);
|
||||
g_free(bday_text);
|
||||
xmpp_stanza_add_child(birthday, birthday_text);
|
||||
xmpp_stanza_release(birthday_text);
|
||||
|
||||
@ -1322,12 +1320,10 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
|
||||
g_string_free(filename, TRUE);
|
||||
}
|
||||
}
|
||||
gchar* from1 = str_replace(from, "@", "_at_");
|
||||
gchar* from2 = str_replace(from1, "/", "_slash_");
|
||||
g_free(from1);
|
||||
auto_char char* from1 = str_replace(from, "@", "_at_");
|
||||
auto_char char* from2 = str_replace(from1, "/", "_slash_");
|
||||
|
||||
g_string_append(filename, from2);
|
||||
g_free(from2);
|
||||
} else {
|
||||
filename = g_string_new(data->filename);
|
||||
}
|
||||
@ -1354,25 +1350,22 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
|
||||
}
|
||||
|
||||
if (data->open) {
|
||||
gchar** argv;
|
||||
auto_gcharv gchar** argv;
|
||||
gint argc;
|
||||
|
||||
gchar* cmdtemplate = prefs_get_string(PREF_VCARD_PHOTO_CMD);
|
||||
auto_gchar gchar* cmdtemplate = prefs_get_string(PREF_VCARD_PHOTO_CMD);
|
||||
|
||||
// this makes it work with filenames that contain spaces
|
||||
g_string_prepend(filename, "\"");
|
||||
g_string_append(filename, "\"");
|
||||
gchar* cmd = str_replace(cmdtemplate, "%p", filename->str);
|
||||
g_free(cmdtemplate);
|
||||
auto_char char* cmd = str_replace(cmdtemplate, "%p", filename->str);
|
||||
|
||||
if (g_shell_parse_argv(cmd, &argc, &argv, &err) == FALSE) {
|
||||
cons_show_error("Failed to parse command template");
|
||||
g_free(cmd);
|
||||
} else {
|
||||
if (!call_external(argv)) {
|
||||
cons_show_error("Unable to execute command");
|
||||
}
|
||||
g_strfreev(argv);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -325,7 +325,7 @@ void
|
||||
accounts_add_otr_policy(const char* const account_name, const char* const contact_jid, const char* const policy)
|
||||
{
|
||||
}
|
||||
char*
|
||||
gchar*
|
||||
accounts_get_last_activity(const char* const account_name)
|
||||
{
|
||||
return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user