Merge pull request #2053 from profanity-im/some-improvements

Some improvements
This commit is contained in:
Michael Vetter
2025-08-20 18:21:46 +02:00
committed by GitHub
55 changed files with 121 additions and 253 deletions

View File

@@ -124,6 +124,7 @@ unittest_sources = \
src/event/server_events.c src/event/server_events.h \
src/event/client_events.c src/event/client_events.h \
src/ui/tray.h src/ui/tray.c \
tests/prof_cmocka.h \
tests/unittests/xmpp/stub_vcard.c \
tests/unittests/xmpp/stub_avatar.c \
tests/unittests/xmpp/stub_ox.c \
@@ -169,6 +170,7 @@ unittest_sources = \
tests/unittests/unittests.c
functionaltest_sources = \
tests/prof_cmocka.h \
tests/functionaltests/proftest.c tests/functionaltests/proftest.h \
tests/functionaltests/test_connect.c tests/functionaltests/test_connect.h \
tests/functionaltests/test_ping.c tests/functionaltests/test_ping.h \
@@ -283,6 +285,7 @@ endif
TESTS = tests/unittests/unittests
check_PROGRAMS = tests/unittests/unittests
tests_unittests_unittests_CPPFLAGS = -Itests/
tests_unittests_unittests_SOURCES = $(unittest_sources)
tests_unittests_unittests_LDADD = -lcmocka
@@ -346,9 +349,13 @@ endif
.PHONY: my-prof.supp
my-prof.supp:
@sed '/^# AUTO-GENERATED START/q' prof.supp > $@
@printf "\n\n# glib\n" >> $@
@cat /usr/share/glib-2.0/valgrind/glib.supp >> $@
@printf "\n\n# Python\n" >> $@
@wget -O- https://raw.githubusercontent.com/python/cpython/refs/tags/v`python3 --version | cut -d' ' -f2`/Misc/valgrind-python.supp >> $@
@printf "\n\n# gtk\n" >> $@
@test -z "@GTK_VERSION@" || wget -O- https://raw.githubusercontent.com/GNOME/gtk/refs/tags/@GTK_VERSION@/gtk.supp >> $@
@printf "\n\n# more gtk\n" >> $@
@test -z "@GTK_VERSION@" || cat /usr/share/gtk-3.0/valgrind/gtk.supp >> $@
check-unit: tests/unittests/unittests

View File

@@ -1662,7 +1662,7 @@ char*
cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean previous)
{
unsigned int output_off = 0;
char* tmp;
char* tmp = NULL;
// strip command
char* inpcp = (char*)input + strlen(startstr);
@@ -1674,38 +1674,36 @@ cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean
// strip quotes
if (*inpcp == '"') {
tmp = strchr(inpcp + 1, '"');
tmp = strrchr(inpcp + 1, '"');
if (tmp) {
*tmp = '\0';
}
tmp = strdup(inpcp + 1);
free(inpcp);
inpcp = tmp;
tmp = NULL;
}
// expand ~ to $HOME
if (inpcp[0] == '~' && inpcp[1] == '/') {
tmp = g_strdup_printf("%s/%sfoo", getenv("HOME"), inpcp + 2);
if (!tmp) {
char* home = getenv("HOME");
if (!home) {
free(inpcp);
return NULL;
}
output_off = strlen(getenv("HOME")) + 1;
tmp = g_strdup_printf("%s/%sfoo", home, inpcp + 2);
output_off = strlen(home) + 1;
} else {
tmp = g_strdup_printf("%sfoo", inpcp);
if (!tmp) {
free(inpcp);
return NULL;
}
}
free(inpcp);
inpcp = tmp;
if (!tmp) {
return NULL;
}
char* inpcp2 = strdup(inpcp);
char* foofile = strdup(basename(inpcp2));
char* directory = strdup(dirname(inpcp));
free(inpcp);
free(inpcp2);
char* foofile = strdup(basename(tmp));
char* directory = strdup(dirname(tmp));
g_free(tmp);
GArray* files = g_array_new(TRUE, FALSE, sizeof(char*));
g_array_set_clear_func(files, (GDestroyNotify)_filepath_item_free);
@@ -1724,40 +1722,26 @@ cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean
continue;
}
char* acstring;
char* acstring = NULL;
if (output_off) {
tmp = g_strdup_printf("%s/%s", directory, dir->d_name);
if (!tmp) {
free(directory);
free(foofile);
return NULL;
if (tmp) {
acstring = g_strdup_printf("~/%s", tmp + output_off);
g_free(tmp);
}
acstring = g_strdup_printf("~/%s", tmp + output_off);
if (!acstring) {
free(directory);
free(foofile);
return NULL;
}
free(tmp);
} else if (strcmp(directory, "/") == 0) {
acstring = g_strdup_printf("/%s", dir->d_name);
if (!acstring) {
free(directory);
free(foofile);
return NULL;
}
} else {
acstring = g_strdup_printf("%s/%s", directory, dir->d_name);
if (!acstring) {
free(directory);
free(foofile);
return NULL;
}
}
if (!acstring) {
g_array_free(files, TRUE);
free(foofile);
free(directory);
return NULL;
}
char* acstring_cpy = strdup(acstring);
g_array_append_val(files, acstring_cpy);
free(acstring);
g_array_append_val(files, acstring);
}
closedir(d);
}

View File

@@ -8565,19 +8565,20 @@ cmd_omemo_trust_mode(ProfWin* window, const char* const command, gchar** args)
{
#ifdef HAVE_OMEMO
auto_gchar gchar* trust_mode = prefs_get_string(PREF_OMEMO_TRUST_MODE);
if (!args[1]) {
cons_show("Current trust mode is %s", prefs_get_string(PREF_OMEMO_TRUST_MODE));
cons_show("Current trust mode is %s", trust_mode);
return TRUE;
}
if (g_strcmp0(args[1], "manual") == 0) {
cons_show("Current trust mode is %s - setting to %s", prefs_get_string(PREF_OMEMO_TRUST_MODE), args[1]);
cons_show("Current trust mode is %s - setting to %s", trust_mode, args[1]);
cons_show("You need to trust all OMEMO fingerprints manually");
} else if (g_strcmp0(args[1], "firstusage") == 0) {
cons_show("Current trust mode is %s - setting to %s", prefs_get_string(PREF_OMEMO_TRUST_MODE), args[1]);
cons_show("Current trust mode is %s - setting to %s", trust_mode, args[1]);
cons_show("The first seen OMEMO fingerprints will be trusted automatically - new keys must be trusted manually");
} else if (g_strcmp0(args[1], "blind") == 0) {
cons_show("Current trust mode is %s - setting to %s", prefs_get_string(PREF_OMEMO_TRUST_MODE), args[1]);
cons_show("Current trust mode is %s - setting to %s", trust_mode, args[1]);
cons_show("ALL OMEMO fingerprints will be trusted automatically");
} else {
cons_bad_cmd_usage(command);

View File

@@ -86,10 +86,16 @@ python_get_version_number(void)
return version_number;
}
static void
_unref_module(PyObject* module)
{
Py_XDECREF(module);
}
void
python_env_init(void)
{
loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)Py_XDECREF);
loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_unref_module);
python_init_prof();

View File

@@ -170,6 +170,29 @@ create_input_window(void)
_inp_win_update_virtual();
}
static gboolean
_inp_slashguard_check(void)
{
if (get_password)
return false;
/* ignore empty and quoted messages */
if (inp_line == NULL || inp_line[0] == '\0' || inp_line[0] == '>')
return false;
if (!prefs_get_boolean(PREF_SLASH_GUARD))
return false;
size_t n = 1;
while (inp_line[n] != '\0' && n < 4) {
if (inp_line[n] == '/') {
cons_show("Your text contains a slash in the first 4 characters");
free(inp_line);
inp_line = NULL;
return true;
}
n++;
}
return false;
}
char*
inp_readline(void)
{
@@ -203,17 +226,7 @@ inp_readline(void)
chat_state_idle();
}
if (inp_line) {
if (!get_password && prefs_get_boolean(PREF_SLASH_GUARD)) {
// ignore quoted messages
if (strlen(inp_line) > 1 && inp_line[0] != '>') {
char* res = (char*)memchr(inp_line + 1, '/', 3);
if (res) {
cons_show("Your text contains a slash in the first 4 characters");
return NULL;
}
}
}
if (inp_line && !_inp_slashguard_check()) {
char* ret = inp_line;
inp_line = NULL;
return ret;

View File

@@ -1,10 +1,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <sys/stat.h>
#include "config.h"

View File

@@ -2,11 +2,8 @@
#include <sys/wait.h>
#include <glib.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdio.h>
#include <unistd.h>
#include <errno.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,8 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

5
tests/prof_cmocka.h Normal file
View File

@@ -0,0 +1,5 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>

View File

@@ -21,8 +21,7 @@
*/
#include <glib.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <xmpp/xmpp.h>

View File

@@ -1,8 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include "common.h"
#include "config/account.h"

View File

@@ -21,8 +21,7 @@
*/
#include <glib.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include "database.h"

View File

@@ -1,8 +1,5 @@
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <glib.h>
#include <stdio.h>
#include <unistd.h>

View File

@@ -20,10 +20,8 @@
*
*/
#include <stdint.h>
#include <glib.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include "log.h"

View File

@@ -2,10 +2,7 @@
#include <libotr/message.h>
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include "config/account.h"

View File

@@ -1,9 +1,5 @@
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include "xmpp/contact.h"

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,10 +1,6 @@
#include <stdarg.h>
#include <string.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <stdint.h>
#include "xmpp/chat_session.h"

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,11 +1,7 @@
#include "xmpp/resource.h"
#include "common.h"
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <stdint.h>
void
replace_one_substr(void** state)

View File

@@ -1,9 +1,6 @@
#include <glib.h>
#include <stdarg.h>
#include <string.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include "xmpp/contact.h"

View File

@@ -1,8 +1,5 @@
#include <stdarg.h>
#include <string.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include "xmpp/form.h"

View File

@@ -1,8 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include "xmpp/jid.h"

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include "xmpp/muc.h"

View File

@@ -1,8 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include "tools/parser.h"

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include "plugins/disco.h"

View File

@@ -1,8 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -1,11 +1,7 @@
#include <glib.h>
#include <stdarg.h>
#include <string.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <stdint.h>
#include "xmpp/contact.h"
#include "xmpp/roster_list.h"

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>

View File

@@ -3,8 +3,7 @@
#include <glib.h>
#include <wchar.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include "ui/window.h"
#include "ui/ui.h"

View File

@@ -1,10 +1,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include <sys/stat.h>
#include <stdlib.h>
#include <locale.h>

View File

@@ -1,7 +1,4 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "prof_cmocka.h"
#include "xmpp/xmpp.h"