1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-10-27 20:30:13 -04:00

Ensure instances of auto types are initialized

Follow-up of #1913

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel 2023-11-06 20:56:48 +01:00
parent 716c068325
commit 4c26462827
13 changed files with 47 additions and 73 deletions

View File

@ -41,6 +41,13 @@ jobs:
continue-on-error: true continue-on-error: true
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
# if this check fails, you have to update the number of auto types known and the list of auto types in the check below
- name: Check auto types are up-to-date
run: |
[[ "$(find src -type f -name '*.[ch]' -exec awk '/^#define auto_[\W]*/ {print $2}' '{}' \; | sort -u | wc -l)" == "6" ]] || exit -1
- name: Check auto types are initialized
run: |
grep -P 'auto_(char|gchar|gcharv|guchar|jid|sqlite)[\w *]*;$' -r src && exit -1 || true
- name: Run clang-format - name: Run clang-format
uses: jidicula/clang-format-action@v4.11.0 uses: jidicula/clang-format-action@v4.11.0
with: with:

View File

@ -4900,13 +4900,11 @@ gboolean
cmd_sendfile(ProfWin* window, const char* const command, gchar** args) cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
{ {
jabber_conn_status_t conn_status = connection_get_status(); jabber_conn_status_t conn_status = connection_get_status();
auto_gchar gchar* filename; // expand ~ to $HOME
auto_gchar gchar* filename = get_expanded_path(args[0]);
char* alt_scheme = NULL; char* alt_scheme = NULL;
char* alt_fragment = NULL; char* alt_fragment = NULL;
// expand ~ to $HOME
filename = get_expanded_path(args[0]);
if (access(filename, R_OK) != 0) { if (access(filename, R_OK) != 0) {
cons_show_error("Uploading '%s' failed: File not found!", filename); cons_show_error("Uploading '%s' failed: File not found!", filename);
goto out; goto out;

View File

@ -391,7 +391,7 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji
} }
char* err_msg; char* err_msg;
auto_gchar gchar* date_fmt; auto_gchar gchar* date_fmt = NULL;
if (message->timestamp) { if (message->timestamp) {
date_fmt = g_date_time_format_iso8601(message->timestamp); date_fmt = g_date_time_format_iso8601(message->timestamp);

View File

@ -495,12 +495,7 @@ void
omemo_set_device_list(const char* const from, GList* device_list) omemo_set_device_list(const char* const from, GList* device_list)
{ {
log_debug("[OMEMO] Setting device list for %s", STR_MAYBE_NULL(from)); log_debug("[OMEMO] Setting device list for %s", STR_MAYBE_NULL(from));
auto_jid Jid* jid; auto_jid Jid* jid = jid_create(from ?: connection_get_fulljid());
if (from) {
jid = jid_create(from);
} else {
jid = jid_create(connection_get_fulljid());
}
g_hash_table_insert(omemo_ctx.device_list, strdup(jid->barejid), device_list); g_hash_table_insert(omemo_ctx.device_list, strdup(jid->barejid), device_list);

View File

@ -328,13 +328,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
ProfWin* window = (ProfWin*)chatwin; ProfWin* window = (ProfWin*)chatwin;
int num = wins_get_num(window); int num = wins_get_num(window);
auto_gchar gchar* display_name; auto_gchar gchar* display_name = get_display_name(message, NULL);
auto_char char* mybarejid = connection_get_barejid();
if (g_strcmp0(mybarejid, message->from_jid->barejid) == 0) {
display_name = strdup("me");
} else {
display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
}
#ifdef HAVE_LIBGPGME #ifdef HAVE_LIBGPGME
if (prefs_get_boolean(PREF_PGP_PUBKEY_AUTOIMPORT)) { if (prefs_get_boolean(PREF_PGP_PUBKEY_AUTOIMPORT)) {
@ -430,12 +424,7 @@ chatwin_outgoing_msg(ProfChatWin* chatwin, const char* const message, char* id,
ProfWin* window = (ProfWin*)chatwin; ProfWin* window = (ProfWin*)chatwin;
wins_add_quotes_ac(window, message, FALSE); wins_add_quotes_ac(window, message, FALSE);
auto_char char* enc_char; auto_char char* enc_char = get_enc_char(enc_mode, chatwin->outgoing_char);
if (chatwin->outgoing_char) {
enc_char = chatwin->outgoing_char;
} else {
enc_char = get_show_char(enc_mode);
}
if (request_receipt && id) { if (request_receipt && id) {
win_print_outgoing_with_receipt((ProfWin*)chatwin, enc_char, "me", message, id, replace_id); win_print_outgoing_with_receipt((ProfWin*)chatwin, enc_char, "me", message, id, replace_id);
@ -454,7 +443,7 @@ chatwin_outgoing_carbon(ProfChatWin* chatwin, ProfMessage* message)
{ {
assert(chatwin != NULL); assert(chatwin != NULL);
auto_char char* enc_char; auto_char char* enc_char = NULL;
if (message->enc == PROF_MSG_ENC_PGP) { if (message->enc == PROF_MSG_ENC_PGP) {
enc_char = prefs_get_pgp_char(); enc_char = prefs_get_pgp_char();
} else if (message->enc == PROF_MSG_ENC_OMEMO) { } else if (message->enc == PROF_MSG_ENC_OMEMO) {

View File

@ -2518,12 +2518,7 @@ cons_alert(ProfWin* alert_origin_window)
if (current->type != WIN_CONSOLE) { if (current->type != WIN_CONSOLE) {
status_bar_new(1, WIN_CONSOLE, "console"); status_bar_new(1, WIN_CONSOLE, "console");
auto_gchar gchar* win_name; auto_gchar gchar* win_name = alert_origin_window ? win_to_string(alert_origin_window) : g_strdup("console");
if (alert_origin_window) {
win_name = win_to_string(alert_origin_window);
} else {
win_name = g_strdup("console");
}
GList* item = g_list_find_custom(alert_list, win_name, (GCompareFunc)g_strcmp0); GList* item = g_list_find_custom(alert_list, win_name, (GCompareFunc)g_strcmp0);
if (!item) { if (!item) {

View File

@ -515,12 +515,7 @@ mucwin_outgoing_msg(ProfMucWin* mucwin, const char* const message, const char* c
char* mynick = muc_nick(mucwin->roomjid); char* mynick = muc_nick(mucwin->roomjid);
// displayed message char // displayed message char
auto_char char* ch; auto_char char* ch = get_enc_char(enc_mode, mucwin->message_char);
if (mucwin->message_char) {
ch = strdup(mucwin->message_char);
} else {
ch = get_show_char(enc_mode);
}
win_print_outgoing_muc_msg(window, ch, mynick, id, replace_id, message); win_print_outgoing_muc_msg(window, ch, mynick, id, replace_id, message);
@ -555,12 +550,7 @@ mucwin_incoming_msg(ProfMucWin* mucwin, const ProfMessage* const message, GSList
ProfWin* window = (ProfWin*)mucwin; ProfWin* window = (ProfWin*)mucwin;
char* mynick = muc_nick(mucwin->roomjid); char* mynick = muc_nick(mucwin->roomjid);
auto_char char* ch; auto_char char* ch = get_enc_char(message->enc, mucwin->message_char);
if (mucwin->message_char) {
ch = strdup(mucwin->message_char);
} else {
ch = get_show_char(message->enc);
}
win_insert_last_read_position_marker((ProfWin*)mucwin, mucwin->roomjid); win_insert_last_read_position_marker((ProfWin*)mucwin, mucwin->roomjid);
wins_add_urls_ac(window, message, FALSE); wins_add_urls_ac(window, message, FALSE);

View File

@ -1389,14 +1389,8 @@ win_print_incoming(ProfWin* window, const char* const display_name_from, ProfMes
switch (window->type) { switch (window->type) {
case WIN_CHAT: case WIN_CHAT:
{ {
auto_char char* enc_char;
ProfChatWin* chatwin = (ProfChatWin*)window; ProfChatWin* chatwin = (ProfChatWin*)window;
auto_char char* enc_char = get_enc_char(message->enc, chatwin->incoming_char);
if (chatwin->incoming_char) {
enc_char = strdup(chatwin->incoming_char);
} else {
enc_char = get_show_char(message->enc);
}
if (prefs_get_boolean(PREF_CORRECTION_ALLOW) && message->replace_id) { if (prefs_get_boolean(PREF_CORRECTION_ALLOW) && message->replace_id) {
_win_correct(window, message->plain, message->id, message->replace_id, message->from_jid->barejid); _win_correct(window, message->plain, message->id, message->replace_id, message->from_jid->barejid);
@ -1472,18 +1466,8 @@ win_print_history(ProfWin* window, const ProfMessage* const message)
{ {
g_date_time_ref(message->timestamp); g_date_time_ref(message->timestamp);
auto_gchar gchar* display_name;
int flags = 0; int flags = 0;
const char* jid = connection_get_fulljid(); auto_gchar gchar* display_name = get_display_name(message, &flags);
auto_jid Jid* jidp = jid_create(jid);
if (g_strcmp0(jidp->barejid, message->from_jid->barejid) == 0) {
display_name = strdup("me");
} else {
display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
flags = NO_ME;
}
auto_char char* ch = get_show_char(message->enc); auto_char char* ch = get_show_char(message->enc);
buffer_append(window->layout->buffer, ch, 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL); buffer_append(window->layout->buffer, ch, 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
@ -1500,17 +1484,8 @@ win_print_old_history(ProfWin* window, const ProfMessage* const message)
{ {
g_date_time_ref(message->timestamp); g_date_time_ref(message->timestamp);
auto_char char* display_name;
int flags = 0; int flags = 0;
const char* jid = connection_get_fulljid(); auto_gchar gchar* display_name = get_display_name(message, &flags);
auto_jid Jid* jidp = jid_create(jid);
if (g_strcmp0(jidp->barejid, message->from_jid->barejid) == 0) {
display_name = strdup("me");
} else {
display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
flags = NO_ME;
}
auto_char char* ch = get_show_char(message->enc); auto_char char* ch = get_show_char(message->enc);
@ -2256,3 +2231,12 @@ get_show_char(prof_enc_t encryption_mode)
return enc_char; return enc_char;
} }
char*
get_enc_char(prof_enc_t enc_mode, const char* alt)
{
if (alt)
return strdup(alt);
else
return get_show_char(enc_mode);
}

View File

@ -99,5 +99,6 @@ void win_remove_entry_message(ProfWin* window, const char* const id);
char* win_quote_autocomplete(ProfWin* window, const char* const input, gboolean previous); char* win_quote_autocomplete(ProfWin* window, const char* const input, gboolean previous);
char* get_show_char(prof_enc_t encryption_mode); char* get_show_char(prof_enc_t encryption_mode);
char* get_enc_char(prof_enc_t enc_mode, const char* alt);
#endif #endif

View File

@ -126,7 +126,7 @@ avatar_set(const char* path)
pixbuf = new_pixbuf; pixbuf = new_pixbuf;
} }
auto_gchar gchar* img_data; auto_gchar gchar* img_data = NULL;
gsize len = -1; gsize len = -1;
if (!gdk_pixbuf_save_to_buffer(pixbuf, &img_data, &len, "png", &err, NULL)) { if (!gdk_pixbuf_save_to_buffer(pixbuf, &img_data, &len, "png", &err, NULL)) {

View File

@ -98,6 +98,20 @@ static xmpp_stanza_t* _ox_openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const t
static GHashTable* pubsub_event_handlers; static GHashTable* pubsub_event_handlers;
gchar*
get_display_name(const ProfMessage* const message, int* flags)
{
auto_char char* barejid = connection_get_barejid();
if (g_strcmp0(barejid, message->from_jid->barejid) == 0) {
return g_strdup("me");
} else {
if (flags)
*flags = NO_ME;
return roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
}
}
static gboolean static gboolean
_handled_by_plugin(xmpp_stanza_t* const stanza) _handled_by_plugin(xmpp_stanza_t* const stanza)
{ {

View File

@ -1350,7 +1350,7 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
} }
if (data->open) { if (data->open) {
auto_gcharv gchar** argv; auto_gcharv gchar** argv = NULL;
gint argc; gint argc;
auto_gchar gchar* cmdtemplate = prefs_get_string(PREF_VCARD_PHOTO_CMD); auto_gchar gchar* cmdtemplate = prefs_get_string(PREF_VCARD_PHOTO_CMD);

View File

@ -317,4 +317,5 @@ void form_reset_autocompleters(DataForm* form);
void publish_user_mood(const char* const mood, const char* const text); void publish_user_mood(const char* const mood, const char* const text);
gchar* get_display_name(const ProfMessage* const message, int* flags);
#endif #endif