Compare commits
1 Commits
fix/cwe-13
...
be06d33125
| Author | SHA1 | Date | |
|---|---|---|---|
|
be06d33125
|
@@ -185,6 +185,7 @@ functionaltest_sources = \
|
||||
tests/functionaltests/test_software.c tests/functionaltests/test_software.h \
|
||||
tests/functionaltests/test_muc.c tests/functionaltests/test_muc.h \
|
||||
tests/functionaltests/test_disconnect.c tests/functionaltests/test_disconnect.h \
|
||||
tests/functionaltests/test_history.c tests/functionaltests/test_history.h \
|
||||
tests/functionaltests/test_lastactivity.c tests/functionaltests/test_lastactivity.h \
|
||||
tests/functionaltests/functionaltests.c
|
||||
|
||||
|
||||
124
check-cwe134.sh
124
check-cwe134.sh
@@ -1,14 +1,8 @@
|
||||
#!/bin/bash
|
||||
# check-cwe134.sh - Verify __attribute__((format)) on printf-like wrappers
|
||||
# check-cwe134.sh - Static analysis for CWE-134 format string vulnerabilities
|
||||
#
|
||||
# CWE-134 format string vulnerabilities are caught at compile time by
|
||||
# -Wformat=2 (includes -Wformat-security + -Wformat-nonliteral), BUT only
|
||||
# for functions annotated with __attribute__((format(printf, N, M))) or
|
||||
# G_GNUC_PRINTF(N, M).
|
||||
#
|
||||
# This script ensures every variadic function whose last fixed parameter
|
||||
# looks like a format string has the annotation. Without it, the compiler
|
||||
# silently ignores format misuse.
|
||||
# This script detects potentially unsafe usage of format string functions
|
||||
# where user-controlled data may be passed without "%s" wrapper.
|
||||
#
|
||||
# Usage: ./check-cwe134.sh [directory]
|
||||
|
||||
@@ -16,103 +10,59 @@ set -e
|
||||
|
||||
DIR="${1:-src}"
|
||||
|
||||
echo "=== CWE-134: format attribute audit ==="
|
||||
echo "=== CWE-134 Format String Vulnerability Check ==="
|
||||
echo "Scanning: $DIR"
|
||||
echo ""
|
||||
|
||||
# Functions that accept format strings
|
||||
FORMAT_FUNCS="cons_show|cons_debug|cons_show_error|log_info|log_error|log_warning|log_debug|win_println|win_print"
|
||||
|
||||
ERRORS=0
|
||||
|
||||
# --------------------------------------------------------------------- #
|
||||
# Known printf-like wrappers that MUST have the attribute #
|
||||
# --------------------------------------------------------------------- #
|
||||
REQUIRED_ATTRIBUTED=(
|
||||
"cons_show"
|
||||
"cons_debug"
|
||||
"cons_show_error"
|
||||
"cons_show_padded"
|
||||
"log_debug"
|
||||
"log_info"
|
||||
"log_warning"
|
||||
"log_error"
|
||||
"win_print"
|
||||
"win_println"
|
||||
"win_println_indent"
|
||||
"win_println_va"
|
||||
"win_append"
|
||||
"win_appendln"
|
||||
"win_append_highlight"
|
||||
"win_appendln_highlight"
|
||||
"win_command_exec_error"
|
||||
)
|
||||
|
||||
echo "Check 1: Known wrappers must have G_GNUC_PRINTF / __attribute__((format))"
|
||||
echo "Checking for unsafe format string usage..."
|
||||
echo ""
|
||||
|
||||
for func in "${REQUIRED_ATTRIBUTED[@]}"; do
|
||||
HAS_ATTR=$(grep -B1 --include="*.h" -rn "void ${func}\s*(" "$DIR" 2>/dev/null \
|
||||
| grep -Ec "format\(printf|G_GNUC_PRINTF" || true)
|
||||
if [ "$HAS_ATTR" -eq 0 ]; then
|
||||
echo " ❌ $func — missing format attribute"
|
||||
ERRORS=$((ERRORS + 1))
|
||||
fi
|
||||
done
|
||||
# Pattern 1: function call with single variable argument (no format string)
|
||||
# Example: cons_show(variable); - BAD
|
||||
# Example: cons_show("%s", variable); - OK
|
||||
# Matches: func(identifier) or func(identifier->member) or func(identifier[index])
|
||||
RESULTS=$(grep -rn --include="*.c" -P "($FORMAT_FUNCS)\s*\(\s*[a-zA-Z_][a-zA-Z0-9_]*(\s*->\s*\w+|\s*\[\s*\w+\s*\])?\s*\)\s*;" "$DIR" 2>/dev/null || true)
|
||||
|
||||
if [ "$ERRORS" -eq 0 ]; then
|
||||
echo " ✅ All known wrappers annotated."
|
||||
fi
|
||||
# Filter out function definitions, declarations, and safe api_* wrappers
|
||||
RESULTS=$(echo "$RESULTS" | grep -v "const char\|void \|^[^:]*:[0-9]*:[a-z_]*(\|api_cons_show\|api_log_" || true)
|
||||
|
||||
# --------------------------------------------------------------------- #
|
||||
# Auto-detect new variadic functions that look like printf wrappers #
|
||||
# but are NOT in the known list and NOT annotated. #
|
||||
# Heuristic: declaration has (... const char* ..., ...) and no attribute #
|
||||
# --------------------------------------------------------------------- #
|
||||
echo ""
|
||||
echo "Check 2: Detect unannotated printf-like variadic declarations in headers"
|
||||
echo ""
|
||||
|
||||
KNOWN_RE=$(IFS="|"; echo "${REQUIRED_ATTRIBUTED[*]}")
|
||||
|
||||
# Find variadic declarations with a const char* / gchar* parameter followed by ...)
|
||||
# that do NOT have a format attribute on the preceding line
|
||||
NEW_ISSUES=$(grep -B1 -rn --include="*.h" \
|
||||
'const g\?char\s*\*.*,\s*\.\.\.)' "$DIR" 2>/dev/null \
|
||||
| awk '
|
||||
/format\(printf|G_GNUC_PRINTF/ { skip=1; next }
|
||||
/const g?char.*,.*\.\.\.\)/ {
|
||||
if (skip) { skip=0; next }
|
||||
print
|
||||
}
|
||||
{ skip=0 }
|
||||
' \
|
||||
| grep -E "void\s+\w+\s*\(" \
|
||||
| grep -Ev "($KNOWN_RE)" \
|
||||
|| true)
|
||||
|
||||
if [ -n "$NEW_ISSUES" ]; then
|
||||
echo " ⚠️ Possibly unannotated new printf-like functions:"
|
||||
if [ -n "$RESULTS" ]; then
|
||||
echo "❌ POTENTIAL CWE-134 VULNERABILITIES FOUND:"
|
||||
echo ""
|
||||
echo "$NEW_ISSUES"
|
||||
echo "$RESULTS"
|
||||
echo ""
|
||||
NEW_COUNT=$(echo "$NEW_ISSUES" | wc -l)
|
||||
ERRORS=$((ERRORS + NEW_COUNT))
|
||||
ERRORS=$(echo "$RESULTS" | wc -l)
|
||||
else
|
||||
echo " ✅ No unannotated variadic printf-like functions found."
|
||||
echo "✅ No obvious CWE-134 issues found."
|
||||
fi
|
||||
|
||||
# Additional check: GString->str passed directly (not as %s argument)
|
||||
echo ""
|
||||
echo "Checking for GString->str passed to format functions..."
|
||||
|
||||
GSTRING_RESULTS=$(grep -rn --include="*.c" -P "($FORMAT_FUNCS)\s*\([^)]*->str\s*\)" "$DIR" 2>/dev/null | grep -v '"%s"' || true)
|
||||
|
||||
if [ -n "$GSTRING_RESULTS" ]; then
|
||||
echo "⚠️ GString->str passed without \"%s\" (review manually):"
|
||||
echo ""
|
||||
echo "$GSTRING_RESULTS"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# --------------------------------------------------------------------- #
|
||||
# Summary #
|
||||
# --------------------------------------------------------------------- #
|
||||
echo ""
|
||||
echo "=== Summary ==="
|
||||
echo "Issues: $ERRORS"
|
||||
echo ""
|
||||
echo "Critical issues: $ERRORS"
|
||||
|
||||
if [ "$ERRORS" -gt 0 ]; then
|
||||
echo "Fix: add the attribute before the declaration in the .h file:"
|
||||
echo " G_GNUC_PRINTF(N, M) // N = format arg, M = first vararg"
|
||||
echo " void my_func(ProfWin* w, const char* fmt, ...);"
|
||||
echo ""
|
||||
echo "The compiler flag -Wformat=2 will then catch all misuse automatically."
|
||||
echo "Fix by adding \"%s\" format specifier:"
|
||||
echo " BAD: cons_show(variable);"
|
||||
echo " GOOD: cons_show(\"%s\", variable);"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
36
configure.ac
36
configure.ac
@@ -385,41 +385,9 @@ AC_CHECK_LIB([util], [forkpty], [AM_CONDITIONAL([HAVE_FORKPTY], [true]) FORKPTY_
|
||||
AC_SUBST([FORKPTY_LIB])
|
||||
|
||||
## Default parameters
|
||||
AM_CFLAGS="$AM_CFLAGS -Wall -Wextra -Wformat=2 -Wno-format-zero-length"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wno-deprecated-declarations -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-cast-function-type"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wnull-dereference -Wpointer-arith"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wimplicit-function-declaration"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wundef"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wfloat-equal -Wredundant-decls"
|
||||
AM_CFLAGS="$AM_CFLAGS -fstack-protector-strong -fno-common"
|
||||
AM_CFLAGS="$AM_CFLAGS -D_FORTIFY_SOURCE=2"
|
||||
AM_CFLAGS="$AM_CFLAGS -std=gnu99 -ggdb3"
|
||||
|
||||
# GCC-specific warnings (not supported by clang) — test each one
|
||||
saved_CFLAGS="$CFLAGS"
|
||||
for _flag in -Wlogical-op -Wduplicated-cond -Wduplicated-branches \
|
||||
-Wstringop-overflow -Warray-bounds=2 -Walloc-zero; do
|
||||
AC_MSG_CHECKING([whether $CC supports $_flag])
|
||||
CFLAGS="$saved_CFLAGS $_flag -Werror"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
|
||||
[AC_MSG_RESULT([yes]); AM_CFLAGS="$AM_CFLAGS $_flag"],
|
||||
[AC_MSG_RESULT([no])])
|
||||
done
|
||||
CFLAGS="$saved_CFLAGS"
|
||||
|
||||
AM_CFLAGS="$AM_CFLAGS -Wall -Wno-deprecated-declarations -std=gnu99 -ggdb3"
|
||||
AM_LDFLAGS="$AM_LDFLAGS -export-dynamic"
|
||||
|
||||
# Linker hardening (RELRO + immediate binding)
|
||||
saved_LDFLAGS="$LDFLAGS"
|
||||
for _flag in -Wl,-z,relro -Wl,-z,now; do
|
||||
AC_MSG_CHECKING([whether linker supports $_flag])
|
||||
LDFLAGS="$saved_LDFLAGS $_flag"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM()],
|
||||
[AC_MSG_RESULT([yes]); AM_LDFLAGS="$AM_LDFLAGS $_flag"],
|
||||
[AC_MSG_RESULT([no])])
|
||||
done
|
||||
LDFLAGS="$saved_LDFLAGS"
|
||||
|
||||
AS_IF([test "x$enable_coverage" = xyes],
|
||||
[AM_CFLAGS="$AM_CFLAGS --coverage -O0"
|
||||
AM_LDFLAGS="$AM_LDFLAGS --coverage"
|
||||
@@ -433,7 +401,7 @@ AS_IF([test "x$PLATFORM" = xosx],
|
||||
AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS $glib_CFLAGS $gio_CFLAGS $curl_CFLAGS ${SQLITE_CFLAGS}"
|
||||
AM_CFLAGS="$AM_CFLAGS $libnotify_CFLAGS ${GTK_CFLAGS} $python_CFLAGS"
|
||||
AM_CFLAGS="$AM_CFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\" -DICONS_PATH=\"\\\"$ICONS_PATH\\\"\" -DGLOBAL_PYTHON_PLUGINS_PATH=\"\\\"$GLOBAL_PYTHON_PLUGINS_PATH\\\"\" -DGLOBAL_C_PLUGINS_PATH=\"\\\"$GLOBAL_C_PLUGINS_PATH\\\"\""
|
||||
|
||||
AM_CFLAGS="$AM_CFLAGS $CFLAGS"
|
||||
LIBS="$glib_LIBS $gio_LIBS $PTHREAD_LIBS $curl_LIBS $libnotify_LIBS $python_LIBS ${GTK_LIBS} ${SQLITE_LIBS} $LIBS"
|
||||
|
||||
AC_SUBST(AM_LDFLAGS)
|
||||
|
||||
@@ -204,7 +204,7 @@ chat_log_omemo_msg_in(ProfMessage* message)
|
||||
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
||||
_chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
|
||||
} else {
|
||||
_chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
|
||||
_chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3067,7 +3067,7 @@ command_docgen(void)
|
||||
|
||||
fclose(toc_fragment);
|
||||
fclose(main_fragment);
|
||||
printf("\nProcessed %u commands.\n\n", g_list_length(cmds));
|
||||
printf("\nProcessed %d commands.\n\n", g_list_length(cmds));
|
||||
g_list_free(cmds);
|
||||
}
|
||||
|
||||
@@ -3145,7 +3145,7 @@ command_mangen(void)
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
|
||||
printf("\nProcessed %u commands.\n\n", g_list_length(cmds));
|
||||
printf("\nProcessed %d commands.\n\n", g_list_length(cmds));
|
||||
|
||||
g_list_free(cmds);
|
||||
}
|
||||
|
||||
@@ -2271,7 +2271,7 @@ cmd_group(ProfWin* window, const char* const command, gchar** args)
|
||||
if (curr) {
|
||||
cons_show("Groups:");
|
||||
while (curr) {
|
||||
cons_show(" %s", (char*)curr->data);
|
||||
cons_show(" %s", curr->data);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
|
||||
@@ -3109,7 +3109,7 @@ cmd_blocked(ProfWin* window, const char* const command, gchar** args)
|
||||
if (curr) {
|
||||
cons_show("Blocked users:");
|
||||
while (curr) {
|
||||
cons_show(" %s", (char*)curr->data);
|
||||
cons_show(" %s", curr->data);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
} else {
|
||||
@@ -5190,7 +5190,7 @@ cmd_charset(ProfWin* window, const char* const command, gchar** args)
|
||||
if (codeset) {
|
||||
cons_show(" CODESET: %s", codeset);
|
||||
}
|
||||
cons_show(" MB_CUR_MAX: %zu", MB_CUR_MAX);
|
||||
cons_show(" MB_CUR_MAX: %d", MB_CUR_MAX);
|
||||
cons_show(" MB_LEN_MAX: %d", MB_LEN_MAX);
|
||||
|
||||
return TRUE;
|
||||
@@ -5624,7 +5624,7 @@ cmd_notify(ProfWin* window, const char* const command, gchar** args)
|
||||
cons_show("No room notification triggers");
|
||||
}
|
||||
while (curr) {
|
||||
cons_show(" %s", (char*)curr->data);
|
||||
cons_show(" %s", curr->data);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free_full(triggers, free);
|
||||
@@ -6299,7 +6299,7 @@ cmd_reconnect(ProfWin* window, const char* const command, gchar** args)
|
||||
} else if (strtoi_range(value, &intval, 0, INT_MAX, &err_msg)) {
|
||||
prefs_set_reconnect(intval);
|
||||
if (intval == 0) {
|
||||
cons_show("Reconnect disabled.");
|
||||
cons_show("Reconnect disabled.", intval);
|
||||
} else {
|
||||
cons_show("Reconnect interval set to %d seconds.", intval);
|
||||
}
|
||||
@@ -6858,7 +6858,7 @@ cmd_plugins_install(ProfWin* window, const char* const command, gchar** args)
|
||||
cons_show("");
|
||||
cons_show("Installed and loaded plugins (%u):", g_slist_length(curr));
|
||||
while (curr) {
|
||||
cons_show(" %s", (char*)curr->data);
|
||||
cons_show(" %s", curr->data);
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
}
|
||||
@@ -6867,7 +6867,7 @@ cmd_plugins_install(ProfWin* window, const char* const command, gchar** args)
|
||||
cons_show("");
|
||||
cons_show("Failed installs (%u):", g_slist_length(curr));
|
||||
while (curr) {
|
||||
cons_show(" %s", (char*)curr->data);
|
||||
cons_show(" %s", curr->data);
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
}
|
||||
@@ -6969,7 +6969,7 @@ cmd_plugins_load(ProfWin* window, const char* const command, gchar** args)
|
||||
cons_show("Loaded plugins:");
|
||||
GSList* curr = loaded;
|
||||
while (curr) {
|
||||
cons_show(" %s", (char*)curr->data);
|
||||
cons_show(" %s", curr->data);
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
g_slist_free_full(loaded, g_free);
|
||||
@@ -7101,7 +7101,7 @@ cmd_plugins(ProfWin* window, const char* const command, gchar** args)
|
||||
GSList* curr = unloaded_plugins;
|
||||
cons_show("The following plugins already installed and can be loaded:");
|
||||
while (curr) {
|
||||
cons_show(" %s", (char*)curr->data);
|
||||
cons_show(" %s", curr->data);
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
g_slist_free_full(unloaded_plugins, g_free);
|
||||
@@ -7111,7 +7111,7 @@ cmd_plugins(ProfWin* window, const char* const command, gchar** args)
|
||||
GList* curr = plugins;
|
||||
cons_show("Loaded plugins:");
|
||||
while (curr) {
|
||||
cons_show(" %s", (char*)curr->data);
|
||||
cons_show(" %s", curr->data);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(plugins);
|
||||
|
||||
@@ -383,7 +383,7 @@ utf8_display_len(const char* const str)
|
||||
char*
|
||||
release_get_latest(void)
|
||||
{
|
||||
const char* url = "https://profanity-im.github.io/profanity_version.txt";
|
||||
char* url = "https://profanity-im.github.io/profanity_version.txt";
|
||||
|
||||
CURL* handle = curl_easy_init();
|
||||
struct curl_data_t output;
|
||||
|
||||
@@ -189,7 +189,7 @@ account_eval_password(ProfAccount* account)
|
||||
|
||||
int exit_status = pclose(stream);
|
||||
if (exit_status > 0) {
|
||||
log_error("Command for `eval_password` returned error status (%d).",
|
||||
log_error("Command for `eval_password` returned error status (%s).",
|
||||
exit_status);
|
||||
return FALSE;
|
||||
} else if (exit_status < 0) {
|
||||
|
||||
@@ -114,26 +114,30 @@ gchar*
|
||||
files_get_log_file(const char* const log_file)
|
||||
{
|
||||
auto_gchar gchar* xdg_data = _files_get_xdg_data_home();
|
||||
GString* logfile;
|
||||
|
||||
if (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);
|
||||
}
|
||||
return g_strdup(log_file);
|
||||
|
||||
logfile = g_string_new(log_file);
|
||||
} else {
|
||||
logfile = g_string_new(xdg_data);
|
||||
g_string_append(logfile, "/profanity/logs/profanity");
|
||||
|
||||
if (!prefs_get_boolean(PREF_LOG_SHARED)) {
|
||||
g_string_append_printf(logfile, "%d", getpid());
|
||||
}
|
||||
|
||||
g_string_append(logfile, ".log");
|
||||
}
|
||||
|
||||
GString* logfile = g_string_new(xdg_data);
|
||||
g_string_append(logfile, "/profanity/logs/profanity");
|
||||
|
||||
if (!prefs_get_boolean(PREF_LOG_SHARED)) {
|
||||
g_string_append_printf(logfile, "%d", getpid());
|
||||
}
|
||||
|
||||
g_string_append(logfile, ".log");
|
||||
|
||||
gchar* result = g_strdup(logfile->str);
|
||||
|
||||
g_string_free(logfile, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
static sqlite3* g_chatlog_database;
|
||||
|
||||
static void _add_to_db(ProfMessage* message, const char* type, const Jid* const from_jid, const Jid* const to_jid);
|
||||
static void _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Jid* const to_jid);
|
||||
static char* _get_db_filename(ProfAccount* account);
|
||||
static prof_msg_type_t _get_message_type_type(const char* const type);
|
||||
static prof_enc_t _get_message_enc_type(const char* const encstr);
|
||||
@@ -167,22 +167,22 @@ log_database_init(ProfAccount* account)
|
||||
// replace_id is the ID from XEP-0308: Last Message Correction
|
||||
// replaces_db_id is ID (primary key) of the original message that LMC message corrects/replaces
|
||||
// replaced_by_db_id is ID (primary key) of the last correcting (LMC) message for the original message
|
||||
const char* query = "CREATE TABLE IF NOT EXISTS `ChatLogs` ("
|
||||
"`id` INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
"`from_jid` TEXT NOT NULL, "
|
||||
"`to_jid` TEXT NOT NULL, "
|
||||
"`from_resource` TEXT, "
|
||||
"`to_resource` TEXT, "
|
||||
"`message` TEXT, "
|
||||
"`timestamp` TEXT, "
|
||||
"`type` TEXT, "
|
||||
"`stanza_id` TEXT, "
|
||||
"`archive_id` TEXT, "
|
||||
"`encryption` TEXT, "
|
||||
"`marked_read` INTEGER, "
|
||||
"`replace_id` TEXT, "
|
||||
"`replaces_db_id` INTEGER, "
|
||||
"`replaced_by_db_id` INTEGER)";
|
||||
char* query = "CREATE TABLE IF NOT EXISTS `ChatLogs` ("
|
||||
"`id` INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
"`from_jid` TEXT NOT NULL, "
|
||||
"`to_jid` TEXT NOT NULL, "
|
||||
"`from_resource` TEXT, "
|
||||
"`to_resource` TEXT, "
|
||||
"`message` TEXT, "
|
||||
"`timestamp` TEXT, "
|
||||
"`type` TEXT, "
|
||||
"`stanza_id` TEXT, "
|
||||
"`archive_id` TEXT, "
|
||||
"`encryption` TEXT, "
|
||||
"`marked_read` INTEGER, "
|
||||
"`replace_id` TEXT, "
|
||||
"`replaces_db_id` INTEGER, "
|
||||
"`replaced_by_db_id` INTEGER)";
|
||||
if (SQLITE_OK != sqlite3_exec(g_chatlog_database, query, NULL, 0, &err_msg)) {
|
||||
goto out;
|
||||
}
|
||||
@@ -272,7 +272,7 @@ log_database_add_incoming(ProfMessage* message)
|
||||
}
|
||||
|
||||
static void
|
||||
_log_database_add_outgoing(const char* type, const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc)
|
||||
_log_database_add_outgoing(char* type, const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc)
|
||||
{
|
||||
ProfMessage* msg = message_init();
|
||||
|
||||
@@ -379,8 +379,8 @@ log_database_get_previous_chat(const gchar* const contact_barejid, const gchar*
|
||||
}
|
||||
|
||||
// Flip order when querying older pages
|
||||
const gchar* sort1 = from_start ? "ASC" : "DESC";
|
||||
const gchar* sort2 = !flip ? "ASC" : "DESC";
|
||||
gchar* sort1 = from_start ? "ASC" : "DESC";
|
||||
gchar* sort2 = !flip ? "ASC" : "DESC";
|
||||
GDateTime* now = g_date_time_new_now_local();
|
||||
auto_gchar gchar* end_date_fmt = end_time ? g_strdup(end_time) : g_date_time_format_iso8601(now);
|
||||
auto_sqlite gchar* query = sqlite3_mprintf("SELECT * FROM ("
|
||||
@@ -499,7 +499,7 @@ _get_message_enc_type(const char* const encstr)
|
||||
}
|
||||
|
||||
static void
|
||||
_add_to_db(ProfMessage* message, const char* type, const Jid* const from_jid, const Jid* const to_jid)
|
||||
_add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Jid* const to_jid)
|
||||
{
|
||||
auto_gchar gchar* pref_dblog = prefs_get_string(PREF_DBLOG);
|
||||
sqlite_int64 original_message_id = -1;
|
||||
|
||||
@@ -54,13 +54,9 @@ void log_init(log_level_t filter, const char* const log_file);
|
||||
log_level_t log_get_filter(void);
|
||||
void log_close(void);
|
||||
const gchar* get_log_file_location(void);
|
||||
G_GNUC_PRINTF(1, 2)
|
||||
void log_debug(const char* const msg, ...);
|
||||
G_GNUC_PRINTF(1, 2)
|
||||
void log_info(const char* const msg, ...);
|
||||
G_GNUC_PRINTF(1, 2)
|
||||
void log_warning(const char* const msg, ...);
|
||||
G_GNUC_PRINTF(1, 2)
|
||||
void log_error(const char* const msg, ...);
|
||||
void log_msg(log_level_t level, const char* const area, const char* const msg);
|
||||
int log_level_from_string(char* log_level, log_level_t* level);
|
||||
|
||||
@@ -537,7 +537,7 @@ omemo_set_device_list(const char* const from, GList* device_list)
|
||||
g_hash_table_iter_init(&iter, known_identities);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
if (device_id->data == value) {
|
||||
cons_show("OMEMO: Adding firstusage trust for %s device %d - Fingerprint %s", jid->barejid, GPOINTER_TO_INT(device_id->data), omemo_format_fingerprint(key));
|
||||
cons_show("OMEMO: Adding firstusage trust for %s device %d - Fingerprint %s", jid->barejid, device_id->data, omemo_format_fingerprint(key));
|
||||
omemo_trust(jid->barejid, omemo_format_fingerprint(key));
|
||||
}
|
||||
}
|
||||
@@ -744,8 +744,8 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
|
||||
GList* recipient_device_id = NULL;
|
||||
recipient_device_id = g_hash_table_lookup(omemo_ctx.device_list, recipients_iter->data);
|
||||
if (!recipient_device_id) {
|
||||
log_warning("[OMEMO][SEND] cannot find device ids for %s", (char*)recipients_iter->data);
|
||||
win_println(win, THEME_ERROR, "!", "Can't find a OMEMO device id for %s.\n", (char*)recipients_iter->data);
|
||||
log_warning("[OMEMO][SEND] cannot find device ids for %s", recipients_iter->data);
|
||||
win_println(win, THEME_ERROR, "!", "Can't find a OMEMO device id for %s.\n", recipients_iter->data);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -769,7 +769,7 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
|
||||
}
|
||||
}
|
||||
|
||||
log_debug("[OMEMO][SEND] recipients with device id %d for %s", GPOINTER_TO_INT(device_ids_iter->data), (char*)recipients_iter->data);
|
||||
log_debug("[OMEMO][SEND] recipients with device id %d for %s", GPOINTER_TO_INT(device_ids_iter->data), recipients_iter->data);
|
||||
res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal);
|
||||
if (res != SG_SUCCESS) {
|
||||
log_error("[OMEMO][SEND] cannot create cipher for %s device id %d - code: %d", address.name, address.device_id, res);
|
||||
@@ -1304,7 +1304,7 @@ _handle_own_device_list(const char* const jid, GList* device_list)
|
||||
{
|
||||
// We didn't find the own device id -> publish
|
||||
if (!g_list_find(device_list, GINT_TO_POINTER(omemo_ctx.device_id))) {
|
||||
cons_show("Could not find own OMEMO device ID. Going to publish own device ID: %d", omemo_ctx.device_id);
|
||||
cons_show("Could not find own OMEMO device ID. Going to publish own device ID: %d", GINT_TO_POINTER(omemo_ctx.device_id));
|
||||
log_debug("[OMEMO] No device ID for our device. Publishing device list");
|
||||
device_list = g_list_copy(device_list);
|
||||
device_list = g_list_append(device_list, GINT_TO_POINTER(omemo_ctx.device_id));
|
||||
@@ -1406,6 +1406,8 @@ omemo_automatic_start(const char* const recipient)
|
||||
case PROF_OMEMOPOLICY_AUTOMATIC:
|
||||
if (g_list_find_custom(account->omemo_enabled, recipient, (GCompareFunc)g_strcmp0)) {
|
||||
result = TRUE;
|
||||
} else if (g_list_find_custom(account->omemo_disabled, recipient, (GCompareFunc)g_strcmp0)) {
|
||||
result = FALSE;
|
||||
} else {
|
||||
result = FALSE;
|
||||
}
|
||||
|
||||
@@ -532,7 +532,7 @@ api_encryption_reset(const char* const barejid)
|
||||
|
||||
ProfChatWin* chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("api_encryption_reset failed, could not find chat window for %s", barejid);
|
||||
log_warning("%s", "api_encryption_reset failed, could not find chat window for %s", barejid);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -566,7 +566,7 @@ api_chat_set_titlebar_enctext(const char* const barejid, const char* const encte
|
||||
|
||||
ProfChatWin* chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("api_chat_set_titlebar_enctext failed, could not find chat window for %s", barejid);
|
||||
log_warning("%s", "api_chat_set_titlebar_enctext failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -585,7 +585,7 @@ api_chat_unset_titlebar_enctext(const char* const barejid)
|
||||
|
||||
ProfChatWin* chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("api_chat_unset_titlebar_enctext failed, could not find chat window for %s", barejid);
|
||||
log_warning("%s", "api_chat_unset_titlebar_enctext failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -614,7 +614,7 @@ api_chat_set_incoming_char(const char* const barejid, const char* const ch)
|
||||
|
||||
ProfChatWin* chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("api_chat_set_incoming_char failed, could not find chat window for %s", barejid);
|
||||
log_warning("%s", "api_chat_set_incoming_char failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -633,7 +633,7 @@ api_chat_unset_incoming_char(const char* const barejid)
|
||||
|
||||
ProfChatWin* chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("api_chat_unset_incoming_char failed, could not find chat window for %s", barejid);
|
||||
log_warning("%s", "api_chat_unset_incoming_char failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -662,7 +662,7 @@ api_chat_set_outgoing_char(const char* const barejid, const char* const ch)
|
||||
|
||||
ProfChatWin* chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("api_chat_set_outgoing_char failed, could not find chat window for %s", barejid);
|
||||
log_warning("%s", "api_chat_set_outgoing_char failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -681,7 +681,7 @@ api_chat_unset_outgoing_char(const char* const barejid)
|
||||
|
||||
ProfChatWin* chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("api_chat_unset_outgoing_char failed, could not find chat window for %s", barejid);
|
||||
log_warning("%s", "api_chat_unset_outgoing_char failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -705,7 +705,7 @@ api_room_set_titlebar_enctext(const char* const roomjid, const char* const encte
|
||||
|
||||
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("api_room_set_titlebar_enctext failed, could not find room window for %s", roomjid);
|
||||
log_warning("%s", "api_room_set_titlebar_enctext failed, could not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -724,7 +724,7 @@ api_room_unset_titlebar_enctext(const char* const roomjid)
|
||||
|
||||
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("api_room_unset_titlebar_enctext failed, could not find room window for %s", roomjid);
|
||||
log_warning("%s", "api_room_unset_titlebar_enctext failed, could not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -753,7 +753,7 @@ api_room_set_message_char(const char* const roomjid, const char* const ch)
|
||||
|
||||
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("api_room_set_message_char failed, could not find room window for %s", roomjid);
|
||||
log_warning("%s", "api_room_set_message_char failed, could not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -772,7 +772,7 @@ api_room_unset_message_char(const char* const roomjid)
|
||||
|
||||
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("api_room_unset_message_char failed, could not find room window for %s", roomjid);
|
||||
log_warning("%s", "api_room_unset_message_char failed, could not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -796,7 +796,7 @@ api_chat_show(const char* const barejid, const char* message)
|
||||
|
||||
ProfChatWin* chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("api_chat_show failed, could not find chat window for %s", barejid);
|
||||
log_warning("%s", "api_chat_show failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -832,7 +832,7 @@ api_chat_show_themed(const char* const barejid, const char* const group, const c
|
||||
|
||||
ProfChatWin* chatwin = wins_get_chat(barejid);
|
||||
if (chatwin == NULL) {
|
||||
log_warning("api_chat_show_themed failed, could not find chat window for %s", barejid);
|
||||
log_warning("%s", "api_chat_show_themed failed, could not find chat window for %s", barejid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -859,7 +859,7 @@ api_room_show(const char* const roomjid, const char* message)
|
||||
|
||||
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("api_room_show failed, could not find room window for %s", roomjid);
|
||||
log_warning("%s", "api_room_show failed, could not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -895,7 +895,7 @@ api_room_show_themed(const char* const roomjid, const char* const group, const c
|
||||
|
||||
ProfMucWin* mucwin = wins_get_muc(roomjid);
|
||||
if (mucwin == NULL) {
|
||||
log_warning("api_room_show_themed failed, could not find room window for %s", roomjid);
|
||||
log_warning("%s", "api_room_show_themed failed, could not find room window for %s", roomjid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,12 +36,9 @@
|
||||
#ifndef TOOLS_HTTP_COMMON_H
|
||||
#define TOOLS_HTTP_COMMON_H
|
||||
|
||||
#include <glib.h>
|
||||
#include "ui/window.h"
|
||||
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void http_print_transfer(ProfWin* window, char* id, const char* fmt, ...);
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void http_print_transfer_update(ProfWin* window, char* id, const char* fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -303,7 +303,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
|
||||
assert(chatwin != NULL);
|
||||
|
||||
if (message->plain == NULL) {
|
||||
log_error("chatwin_incoming_msg: Message with no plain field from: %s", message->from_jid->fulljid);
|
||||
log_error("chatwin_incoming_msg: Message with no plain field from: %s", message->from_jid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -470,10 +470,10 @@ cons_show_wins(gboolean unread)
|
||||
|
||||
GSList* curr = window_strings;
|
||||
while (curr) {
|
||||
if (g_strstr_len((char*)curr->data, strlen((char*)curr->data), " unread") != NULL) {
|
||||
win_println(console, THEME_CMD_WINS_UNREAD, "-", "%s", (char*)curr->data);
|
||||
if (g_strstr_len(curr->data, strlen(curr->data), " unread") > 0) {
|
||||
win_println(console, THEME_CMD_WINS_UNREAD, "-", "%s", curr->data);
|
||||
} else {
|
||||
win_println(console, THEME_DEFAULT, "-", "%s", (char*)curr->data);
|
||||
win_println(console, THEME_DEFAULT, "-", "%s", curr->data);
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
@@ -491,10 +491,10 @@ cons_show_wins_attention()
|
||||
|
||||
GSList* curr = window_strings;
|
||||
while (curr) {
|
||||
if (g_strstr_len((char*)curr->data, strlen((char*)curr->data), " unread") != NULL) {
|
||||
win_println(console, THEME_CMD_WINS_UNREAD, "-", "%s", (char*)curr->data);
|
||||
if (g_strstr_len(curr->data, strlen(curr->data), " unread") > 0) {
|
||||
win_println(console, THEME_CMD_WINS_UNREAD, "-", "%s", curr->data);
|
||||
} else {
|
||||
win_println(console, THEME_DEFAULT, "-", "%s", (char*)curr->data);
|
||||
win_println(console, THEME_DEFAULT, "-", "%s", curr->data);
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
@@ -512,7 +512,7 @@ cons_show_room_invites(GList* invites)
|
||||
} else {
|
||||
cons_show("Chat room invites, use /join or /decline commands:");
|
||||
while (invites) {
|
||||
cons_show(" %s", (char*)invites->data);
|
||||
cons_show(" %s", invites->data);
|
||||
invites = g_list_next(invites);
|
||||
}
|
||||
}
|
||||
@@ -591,7 +591,7 @@ cons_show_caps(const char* const fulljid, resource_presence_t presence)
|
||||
win_println(console, THEME_DEFAULT, "-", "Features:");
|
||||
GSList* feature = caps->features;
|
||||
while (feature) {
|
||||
win_println(console, THEME_DEFAULT, "-", " %s", (char*)feature->data);
|
||||
win_println(console, THEME_DEFAULT, "-", " %s", feature->data);
|
||||
feature = g_slist_next(feature);
|
||||
}
|
||||
}
|
||||
@@ -611,10 +611,10 @@ cons_show_received_subs(void)
|
||||
if (received == NULL) {
|
||||
cons_show("No outstanding subscription requests.");
|
||||
} else {
|
||||
cons_show("Outstanding subscription requests from (%d):",
|
||||
cons_show("Outstanding subscription requests from:",
|
||||
g_list_length(received));
|
||||
while (received) {
|
||||
cons_show(" %s", (char*)received->data);
|
||||
cons_show(" %s", received->data);
|
||||
received = g_list_next(received);
|
||||
}
|
||||
g_list_free_full(received, g_free);
|
||||
@@ -782,7 +782,7 @@ cons_show_disco_info(const char* jid, GSList* identities, GSList* features)
|
||||
cons_show(" Features:");
|
||||
}
|
||||
while (features) {
|
||||
cons_show(" %s", (char*)features->data);
|
||||
cons_show(" %s", features->data);
|
||||
features = g_slist_next(features);
|
||||
}
|
||||
|
||||
@@ -2297,7 +2297,7 @@ cons_show_themes(GSList* themes)
|
||||
} else {
|
||||
cons_show("Available themes:");
|
||||
while (themes) {
|
||||
cons_show("%s", (char*)themes->data);
|
||||
cons_show("%s", themes->data);
|
||||
themes = g_slist_next(themes);
|
||||
}
|
||||
}
|
||||
@@ -2315,7 +2315,7 @@ cons_show_scripts(GSList* scripts)
|
||||
} else {
|
||||
cons_show("Scripts:");
|
||||
while (scripts) {
|
||||
cons_show("%s", (char*)scripts->data);
|
||||
cons_show("%s", scripts->data);
|
||||
scripts = g_slist_next(scripts);
|
||||
}
|
||||
}
|
||||
@@ -2333,7 +2333,7 @@ cons_show_script(const char* const script, GSList* commands)
|
||||
} else {
|
||||
cons_show("%s:", script);
|
||||
while (commands) {
|
||||
cons_show(" %s", (char*)commands->data);
|
||||
cons_show(" %s", commands->data);
|
||||
commands = g_slist_next(commands);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ mucwin_room_disco_info(ProfMucWin* mucwin, GSList* identities, GSList* features)
|
||||
win_println(window, THEME_DEFAULT, "!", "Features:");
|
||||
}
|
||||
while (features) {
|
||||
win_println(window, THEME_DEFAULT, "!", " %s", (char*)features->data);
|
||||
win_println(window, THEME_DEFAULT, "!", " %s", features->data);
|
||||
features = g_slist_next(features);
|
||||
}
|
||||
win_println(window, THEME_DEFAULT, "-", "");
|
||||
@@ -534,7 +534,7 @@ mucwin_incoming_msg(ProfMucWin* mucwin, const ProfMessage* const message, GSList
|
||||
int flags = 0;
|
||||
|
||||
if (message->plain == NULL) {
|
||||
log_error("mucwin_incoming_msg: Message with no plain field from: %s", message->from_jid->fulljid);
|
||||
log_error("mucwin_incoming_msg: Message with no plain field from: %s", message->from_jid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ privwin_incoming_msg(ProfPrivateWin* privatewin, ProfMessage* message)
|
||||
assert(privatewin != NULL);
|
||||
|
||||
if (message->plain == NULL) {
|
||||
log_error("privwin_incoming_msg: Message with no plain field from: %s", message->from_jid->fulljid);
|
||||
log_error("privwin_incoming_msg: Message with no plain field from: %s", message->from_jid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -981,7 +981,9 @@ _rosterwin_unsubscribed_header(ProfLayoutSplit* layout, GList* wins)
|
||||
auto_gchar gchar* countpref = prefs_get_string(PREF_ROSTER_COUNT);
|
||||
if (g_strcmp0(countpref, "items") == 0) {
|
||||
int itemcount = g_list_length(wins);
|
||||
if (itemcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
if (itemcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", itemcount);
|
||||
} else {
|
||||
g_string_append_printf(header, " (%d)", itemcount);
|
||||
}
|
||||
} else if (g_strcmp0(countpref, "unread") == 0) {
|
||||
@@ -992,7 +994,9 @@ _rosterwin_unsubscribed_header(ProfLayoutSplit* layout, GList* wins)
|
||||
unreadcount += chatwin->unread;
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
if (unreadcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
if (unreadcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", unreadcount);
|
||||
} else if (unreadcount > 0) {
|
||||
g_string_append_printf(header, " (%d)", unreadcount);
|
||||
}
|
||||
}
|
||||
@@ -1022,7 +1026,9 @@ _rosterwin_contacts_header(ProfLayoutSplit* layout, const char* const title, GSL
|
||||
auto_gchar gchar* countpref = prefs_get_string(PREF_ROSTER_COUNT);
|
||||
if (g_strcmp0(countpref, "items") == 0) {
|
||||
int itemcount = g_slist_length(contacts);
|
||||
if (itemcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
if (itemcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", itemcount);
|
||||
} else {
|
||||
g_string_append_printf(header, " (%d)", itemcount);
|
||||
}
|
||||
} else if (g_strcmp0(countpref, "unread") == 0) {
|
||||
@@ -1037,7 +1043,9 @@ _rosterwin_contacts_header(ProfLayoutSplit* layout, const char* const title, GSL
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
if (unreadcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
if (unreadcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(header, " (%d)", unreadcount);
|
||||
} else if (unreadcount > 0) {
|
||||
g_string_append_printf(header, " (%d)", unreadcount);
|
||||
}
|
||||
}
|
||||
@@ -1128,7 +1136,9 @@ _rosterwin_private_header(ProfLayoutSplit* layout, GList* privs)
|
||||
auto_gchar gchar* countpref = prefs_get_string(PREF_ROSTER_COUNT);
|
||||
if (g_strcmp0(countpref, "items") == 0) {
|
||||
int itemcount = g_list_length(privs);
|
||||
if (itemcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
if (itemcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(title_str, " (%d)", itemcount);
|
||||
} else if (itemcount > 0) {
|
||||
g_string_append_printf(title_str, " (%d)", itemcount);
|
||||
}
|
||||
} else if (g_strcmp0(countpref, "unread") == 0) {
|
||||
@@ -1139,7 +1149,9 @@ _rosterwin_private_header(ProfLayoutSplit* layout, GList* privs)
|
||||
unreadcount += privwin->unread;
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
if (unreadcount != 0 || prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
if (unreadcount == 0 && prefs_get_boolean(PREF_ROSTER_COUNT_ZERO)) {
|
||||
g_string_append_printf(title_str, " (%d)", unreadcount);
|
||||
} else if (unreadcount > 0) {
|
||||
g_string_append_printf(title_str, " (%d)", unreadcount);
|
||||
}
|
||||
}
|
||||
|
||||
14
src/ui/ui.h
14
src/ui/ui.h
@@ -244,9 +244,7 @@ char* inp_readline(void);
|
||||
void inp_nonblocking(gboolean reset);
|
||||
|
||||
// Console window
|
||||
G_GNUC_PRINTF(1, 2)
|
||||
void cons_show(const char* const msg, ...);
|
||||
G_GNUC_PRINTF(2, 3)
|
||||
void cons_show_padded(int pad, const char* const msg, ...);
|
||||
void cons_about(void);
|
||||
void cons_help(void);
|
||||
@@ -265,9 +263,7 @@ void cons_show_pgp_prefs(void);
|
||||
void cons_show_omemo_prefs(void);
|
||||
void cons_show_ox_prefs(void);
|
||||
void cons_show_account(ProfAccount* account);
|
||||
G_GNUC_PRINTF(1, 2)
|
||||
void cons_debug(const char* const msg, ...);
|
||||
G_GNUC_PRINTF(1, 2)
|
||||
void cons_show_error(const char* const cmd, ...);
|
||||
void cons_show_contacts(GSList* list);
|
||||
void cons_show_roster(GSList* list);
|
||||
@@ -322,6 +318,7 @@ void cons_wrap_setting(void);
|
||||
void cons_time_setting(void);
|
||||
void cons_wintitle_setting(void);
|
||||
void cons_notify_setting(void);
|
||||
void cons_show_desktop_prefs(void);
|
||||
void cons_states_setting(void);
|
||||
void cons_outtype_setting(void);
|
||||
void cons_intype_setting(void);
|
||||
@@ -396,24 +393,16 @@ void win_show_subwin(ProfWin* window);
|
||||
void win_refresh_without_subwin(ProfWin* window);
|
||||
void win_refresh_with_subwin(ProfWin* window);
|
||||
|
||||
G_GNUC_PRINTF(4, 5)
|
||||
void win_print(ProfWin* window, theme_item_t theme_item, const char* show_char, const char* const message, ...);
|
||||
G_GNUC_PRINTF(4, 5)
|
||||
void win_println(ProfWin* window, theme_item_t theme_item, const char* show_char, const char* const message, ...);
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_println_indent(ProfWin* window, int pad, const char* const message, ...);
|
||||
|
||||
G_GNUC_PRINTF(4, 0)
|
||||
void win_println_va(ProfWin* window, theme_item_t theme_item, const char* show_char, const char* const message, va_list arg);
|
||||
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_append(ProfWin* window, theme_item_t theme_item, const char* const message, ...);
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_appendln(ProfWin* window, theme_item_t theme_item, const char* const message, ...);
|
||||
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_append_highlight(ProfWin* window, theme_item_t theme_item, const char* const message, ...);
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_appendln_highlight(ProfWin* window, theme_item_t theme_item, const char* const message, ...);
|
||||
|
||||
gchar* win_get_title(ProfWin* window);
|
||||
@@ -427,7 +416,6 @@ void win_clear(ProfWin* window);
|
||||
char* win_get_tab_identifier(ProfWin* window);
|
||||
gchar* win_to_string(ProfWin* window);
|
||||
void win_command_list_error(ProfWin* window, const char* const error);
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void win_command_exec_error(ProfWin* window, const char* const command, const char* const error, ...);
|
||||
void win_handle_command_list(ProfWin* window, GSList* cmds);
|
||||
void win_handle_command_exec_status(ProfWin* window, const char* const type, const char* const value);
|
||||
|
||||
@@ -239,7 +239,7 @@ _conn_apply_settings(const char* const jid, const char* const passwd, const char
|
||||
}
|
||||
|
||||
if (xmpp_conn_set_flags(conn.xmpp_conn, flags)) {
|
||||
log_error("libstrophe doesn't accept this combination of flags: 0x%lx", flags);
|
||||
log_error("libstrophe doesn't accept this combination of flags: 0x%x", flags);
|
||||
conn.conn_status = JABBER_DISCONNECTED;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ jabber_conn_status_t connection_register(const char* const altdomain, int port,
|
||||
void connection_set_disconnected(void);
|
||||
|
||||
void connection_set_priority(const int priority);
|
||||
void connection_set_priority(int priority);
|
||||
void connection_set_disco_items(GSList* items);
|
||||
|
||||
xmpp_conn_t* connection_get_conn(void);
|
||||
|
||||
@@ -458,7 +458,7 @@ form_get_field_type(DataForm* form, const char* const tag)
|
||||
}
|
||||
|
||||
void
|
||||
form_set_value(DataForm* form, const char* const tag, const char* value)
|
||||
form_set_value(DataForm* form, const char* const tag, char* value)
|
||||
{
|
||||
char* var = g_hash_table_lookup(form->tag_to_var, tag);
|
||||
if (var) {
|
||||
|
||||
@@ -921,7 +921,7 @@ _caps_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
// handle error responses
|
||||
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||
auto_char char* error_message = stanza_get_error_message(stanza);
|
||||
log_warning("Error received for capabilities response from %s: %s", from, error_message);
|
||||
log_warning("Error received for capabilities response from %s: ", from, error_message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -996,7 +996,7 @@ _caps_response_for_jid_id_handler(xmpp_stanza_t* const stanza, void* const userd
|
||||
// handle error responses
|
||||
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||
auto_char char* error_message = stanza_get_error_message(stanza);
|
||||
log_warning("Error received for capabilities response from %s: %s", from, error_message);
|
||||
log_warning("Error received for capabilities response from %s: ", from, error_message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1054,7 +1054,7 @@ _caps_response_legacy_id_handler(xmpp_stanza_t* const stanza, void* const userda
|
||||
// handle error responses
|
||||
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||
auto_char char* error_message = stanza_get_error_message(stanza);
|
||||
log_warning("Error received for capabilities response from %s: %s", from, error_message);
|
||||
log_warning("Error received for capabilities response from %s: ", from, error_message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1254,7 +1254,7 @@ _command_exec_response_handler(xmpp_stanza_t* const stanza, void* const userdata
|
||||
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||
auto_char char* error_message = stanza_get_error_message(stanza);
|
||||
log_debug("Error executing command %s for %s: %s", command, from, error_message);
|
||||
win_command_exec_error(win, command, "%s", error_message);
|
||||
win_command_exec_error(win, command, error_message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -427,7 +427,7 @@ muc_rooms(void)
|
||||
* Return current users nickname for the specified room
|
||||
* The nickname is owned by the chat room and should not be modified or freed
|
||||
*/
|
||||
const char*
|
||||
const char* const
|
||||
muc_nick(const char* const room)
|
||||
{
|
||||
ChatRoom* chat_room = g_hash_table_lookup(rooms, room);
|
||||
|
||||
@@ -93,7 +93,7 @@ GList* muc_rooms(void);
|
||||
|
||||
void muc_set_features(const char* const room, GSList* features);
|
||||
|
||||
const char* muc_nick(const char* const room);
|
||||
const char* const muc_nick(const char* const room);
|
||||
char* muc_password(const char* const room);
|
||||
|
||||
void muc_nick_change_start(const char* const room, const char* const new_nick);
|
||||
|
||||
@@ -353,7 +353,6 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
{
|
||||
char* plaintext = NULL;
|
||||
const char* type = xmpp_stanza_get_type(stanza);
|
||||
const char* from = xmpp_stanza_get_from(stanza);
|
||||
GList* keys = NULL;
|
||||
unsigned char* iv_raw = NULL;
|
||||
unsigned char* payload_raw = NULL;
|
||||
@@ -435,6 +434,8 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
|
||||
keys = g_list_append(keys, key);
|
||||
}
|
||||
|
||||
const char* from = xmpp_stanza_get_from(stanza);
|
||||
|
||||
plaintext = omemo_on_message_recv(from, sid, iv_raw, iv_len,
|
||||
keys, payload_raw, payload_len,
|
||||
g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0, trusted);
|
||||
@@ -470,8 +471,7 @@ _omemo_receive_devicelist(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
|
||||
const char* code = xmpp_stanza_get_attribute(error, "code");
|
||||
if (g_strcmp0(code, "404") == 0) {
|
||||
omemo_set_device_list(from, NULL);
|
||||
return 1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,8 +517,7 @@ _omemo_receive_devicelist(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
log_warning("[OMEMO] User %s has a non 'current' device item list: %s.", from, xmpp_stanza_get_id(first));
|
||||
item = first;
|
||||
} else {
|
||||
omemo_set_device_list(from, device_list);
|
||||
return 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
xmpp_stanza_t* list = xmpp_stanza_get_child_by_ns(item, STANZA_NS_OMEMO);
|
||||
@@ -540,6 +539,7 @@ _omemo_receive_devicelist(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
omemo_set_device_list(from, device_list);
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "xmpp/iq.h"
|
||||
|
||||
void omemo_devicelist_subscribe(void);
|
||||
void omemo_devicelist_configure_and_request(void);
|
||||
void omemo_devicelist_publish(GList* device_list);
|
||||
void omemo_devicelist_request(const char* const jid);
|
||||
void omemo_bundle_publish(gboolean first);
|
||||
|
||||
@@ -501,7 +501,7 @@ _subscribe_handler(xmpp_stanza_t* const stanza)
|
||||
{
|
||||
const char* from = xmpp_stanza_get_from(stanza);
|
||||
if (!from) {
|
||||
log_warning("Subscribe presence handler received with no from attribute");
|
||||
log_warning("Subscribe presence handler received with no from attribute", from);
|
||||
}
|
||||
log_debug("Subscribe presence handler fired for %s", from);
|
||||
|
||||
|
||||
@@ -1948,7 +1948,7 @@ stanza_attach_priority(xmpp_ctx_t* const ctx, xmpp_stanza_t* const presence, con
|
||||
return;
|
||||
}
|
||||
|
||||
char pri_str[12];
|
||||
char pri_str[10];
|
||||
snprintf(pri_str, sizeof(pri_str), "%d", pri);
|
||||
|
||||
xmpp_stanza_t* priority = xmpp_stanza_new(ctx);
|
||||
@@ -2007,7 +2007,7 @@ stanza_attach_last_activity(xmpp_ctx_t* const ctx,
|
||||
xmpp_stanza_t* query = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
|
||||
xmpp_stanza_set_ns(query, STANZA_NS_LASTACTIVITY);
|
||||
char idle_str[12];
|
||||
char idle_str[10];
|
||||
snprintf(idle_str, sizeof(idle_str), "%d", idle);
|
||||
xmpp_stanza_set_attribute(query, STANZA_ATTR_SECONDS, idle_str);
|
||||
xmpp_stanza_add_child(presence, query);
|
||||
|
||||
@@ -1300,7 +1300,7 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
|
||||
return 1;
|
||||
}
|
||||
|
||||
GString* filename = NULL;
|
||||
GString* filename;
|
||||
|
||||
if (!data->filename) {
|
||||
auto_gchar gchar* path = files_get_data_path(DIR_PHOTOS);
|
||||
@@ -1340,11 +1340,6 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
|
||||
|
||||
GError* err = NULL;
|
||||
|
||||
if (!filename) {
|
||||
cons_show_error("Unable to determine filename for photo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (g_file_set_contents(filename->str, (gchar*)photo->data, photo->length, &err) == FALSE) {
|
||||
cons_show_error("Unable to save photo: %s", err->message);
|
||||
g_error_free(err);
|
||||
|
||||
@@ -305,7 +305,7 @@ char* blocked_ac_find(const char* const search_str, gboolean previous, void* con
|
||||
void blocked_ac_reset(void);
|
||||
|
||||
void form_destroy(DataForm* form);
|
||||
void form_set_value(DataForm* form, const char* const tag, const char* value);
|
||||
void form_set_value(DataForm* form, const char* const tag, char* value);
|
||||
gboolean form_add_unique_value(DataForm* form, const char* const tag, char* value);
|
||||
void form_add_value(DataForm* form, const char* const tag, char* value);
|
||||
gboolean form_remove_value(DataForm* form, const char* const tag, char* value);
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
* functional tests run less frequently than unit tests.
|
||||
*
|
||||
* Tests are organized into groups for better maintainability and parallel execution:
|
||||
* Group 1: Connect, Ping, Rooms, Software
|
||||
* Group 2: Message, Receipts, Roster, Chat Session
|
||||
* Group 3: Presence, Disconnect
|
||||
* Group 4: MUC, Carbons
|
||||
* Group 1: Connect, Ping, Rooms, Software, Last Activity (19 tests)
|
||||
* Group 2: Message, Receipts, Roster, DB History (23 tests)
|
||||
* Group 3: Chat Session, Presence, Disconnect (22 tests)
|
||||
* Group 4: MUC, Carbons (21 tests)
|
||||
*
|
||||
* Parallel execution:
|
||||
* ./functionaltests - run all tests sequentially
|
||||
@@ -53,6 +53,7 @@
|
||||
#include "test_muc.h"
|
||||
#include "test_disconnect.h"
|
||||
#include "test_lastactivity.h"
|
||||
#include "test_history.h"
|
||||
|
||||
/* Macro to wrap each test with setup/teardown functions */
|
||||
#define PROF_FUNC_TEST(test) cmocka_unit_test_setup_teardown(test, init_prof_test, close_prof_test)
|
||||
@@ -77,8 +78,9 @@ main(int argc, char* argv[])
|
||||
fprintf(stderr, "[PROF_TEST] Starting functional tests, group=%d\n", group);
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 1: Connect, Ping, Rooms, Software
|
||||
* GROUP 1: Connect, Ping, Rooms, Software, Last Activity
|
||||
* Basic XMPP session establishment and server queries
|
||||
* (19 tests)
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group1_tests[] = {
|
||||
/* Connection tests - verify login, roster, bookmarks */
|
||||
@@ -112,8 +114,9 @@ main(int argc, char* argv[])
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 2: Message, Receipts, Roster, Chat Session
|
||||
* GROUP 2: Message, Receipts, Roster, DB History
|
||||
* Core messaging and contact management
|
||||
* (23 tests)
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group2_tests[] = {
|
||||
/* Basic message send/receive */
|
||||
@@ -133,6 +136,27 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(sends_remove_item_nick),
|
||||
PROF_FUNC_TEST(sends_nick_change),
|
||||
|
||||
/* Database persistence - message write+read round-trip */
|
||||
PROF_FUNC_TEST(message_db_history_on_reopen),
|
||||
PROF_FUNC_TEST(message_db_history_multiple),
|
||||
PROF_FUNC_TEST(message_db_history_contact_isolation),
|
||||
PROF_FUNC_TEST(message_db_history_special_chars),
|
||||
PROF_FUNC_TEST(message_db_history_outgoing),
|
||||
PROF_FUNC_TEST(message_db_history_dialog),
|
||||
PROF_FUNC_TEST(message_db_history_empty),
|
||||
PROF_FUNC_TEST(message_db_history_long_message),
|
||||
PROF_FUNC_TEST(message_db_history_newline),
|
||||
PROF_FUNC_TEST(message_db_history_service_chars),
|
||||
PROF_FUNC_TEST(message_db_history_verify),
|
||||
PROF_FUNC_TEST(message_db_history_lmc),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 3: Chat Session, Presence, Disconnect
|
||||
* Session routing, status management, clean teardown
|
||||
* (22 tests)
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group3_tests[] = {
|
||||
/* Chat session management - bare/full JID routing */
|
||||
PROF_FUNC_TEST(sends_message_to_barejid_when_contact_offline),
|
||||
PROF_FUNC_TEST(sends_message_to_barejid_when_contact_online),
|
||||
@@ -140,13 +164,8 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(sends_subsequent_messages_to_fulljid),
|
||||
PROF_FUNC_TEST(resets_to_barejid_after_presence_received),
|
||||
PROF_FUNC_TEST(new_session_when_message_received_from_different_fulljid),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 3: Presence, Disconnect
|
||||
* Online/away/xa/dnd/chat status management
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group3_tests[] = {
|
||||
/* Presence - online/away/xa/dnd/chat status management */
|
||||
PROF_FUNC_TEST(presence_online),
|
||||
PROF_FUNC_TEST(presence_online_with_message),
|
||||
PROF_FUNC_TEST(presence_away),
|
||||
@@ -170,6 +189,7 @@ main(int argc, char* argv[])
|
||||
/* ============================================================
|
||||
* GROUP 4: MUC, Carbons
|
||||
* Multi-user chat and message synchronization
|
||||
* (21 tests)
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group4_tests[] = {
|
||||
/* MUC room join with various options - XEP-0045 */
|
||||
@@ -212,9 +232,9 @@ main(int argc, char* argv[])
|
||||
const struct CMUnitTest* tests;
|
||||
size_t count;
|
||||
} groups[] = {
|
||||
{ "Group 1: Connect/Ping/Rooms/Software", group1_tests, ARRAY_SIZE(group1_tests) },
|
||||
{ "Group 2: Message/Receipts/Roster/Session", group2_tests, ARRAY_SIZE(group2_tests) },
|
||||
{ "Group 3: Presence/Disconnect", group3_tests, ARRAY_SIZE(group3_tests) },
|
||||
{ "Group 1: Connect/Ping/Rooms/Software/LastActivity", group1_tests, ARRAY_SIZE(group1_tests) },
|
||||
{ "Group 2: Message/Receipts/Roster/DBHistory", group2_tests, ARRAY_SIZE(group2_tests) },
|
||||
{ "Group 3: Session/Presence/Disconnect", group3_tests, ARRAY_SIZE(group3_tests) },
|
||||
{ "Group 4: MUC/Carbons", group4_tests, ARRAY_SIZE(group4_tests) },
|
||||
};
|
||||
const int num_groups = ARRAY_SIZE(groups);
|
||||
|
||||
473
tests/functionaltests/test_history.c
Normal file
473
tests/functionaltests/test_history.c
Normal file
@@ -0,0 +1,473 @@
|
||||
/*
|
||||
* test_history.c
|
||||
*
|
||||
* Functional test for database message persistence.
|
||||
* Verifies that a received chat message is written to the database
|
||||
* and loaded back as history when the chat window is reopened.
|
||||
*
|
||||
* These tests only exercise the public log_database API through normal
|
||||
* profanity UI operations, so they work with any storage backend.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stabber.h>
|
||||
|
||||
#include "proftest.h"
|
||||
|
||||
/*
|
||||
* Test: message written to DB is loaded as history on chat window reopen.
|
||||
*
|
||||
* Flow:
|
||||
* 1. Connect and enable /history on (enables PREF_CHLOG + PREF_HISTORY)
|
||||
* 2. Receive a chat message while on the console window — the message
|
||||
* body is NOT rendered to the terminal (only a console notification
|
||||
* "<< chat message: ... (win N)" appears), but the message IS
|
||||
* written to the database via chat_log_msg_in()
|
||||
* 3. Close the auto-created chat window (destroying its in-memory buffer)
|
||||
* 4. Reopen the chat window with /msg — chatwin_new() calls
|
||||
* _chatwin_history() which reads from log_database_get_previous_chat()
|
||||
* 5. Assert the message body appears in the terminal output, proving
|
||||
* it was persisted to and read back from the database
|
||||
*/
|
||||
void
|
||||
message_db_history_on_reopen(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
/* Enable chat logging and history display */
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Receive a message while on the console window.
|
||||
* The body text is NOT printed to the visible terminal — only the
|
||||
* console notification appears. The message is logged to the DB. */
|
||||
stbbr_send(
|
||||
"<message id='hist-db-test-1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>persistence-roundtrip-check-42</body>"
|
||||
"</message>");
|
||||
|
||||
/* Wait for the console notification (proves message was received).
|
||||
* buddy1@localhost is in the roster as "Buddy1", and PREF_RESOURCE_MESSAGE
|
||||
* is on by default, so the display name is "Buddy1/phone". */
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
/* Close the chat window that was auto-created for the incoming message.
|
||||
* This destroys its in-memory buffer so the text is gone from UI. */
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
/* Reopen the chat window — chatwin_new() will load history from DB.
|
||||
* The message body should now appear on screen for the first time. */
|
||||
prof_input("/msg buddy1@localhost");
|
||||
|
||||
/* The history-loaded message must contain the body we sent earlier.
|
||||
* Since the body was never rendered to the terminal before (it was
|
||||
* only in the hidden window's ncurses buffer which was destroyed),
|
||||
* finding it now proves the database write+read round-trip works. */
|
||||
assert_true(prof_output_exact("persistence-roundtrip-check-42"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: multiple messages from the same contact are all preserved.
|
||||
*
|
||||
* Uses different resources so each console notification is unique and
|
||||
* we can reliably synchronise on each delivery before proceeding.
|
||||
*/
|
||||
void
|
||||
message_db_history_multiple(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Three messages from different resources → distinct notifications */
|
||||
stbbr_send(
|
||||
"<message id='multi1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>db-multi-first-aaa</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='multi2' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/laptop' type='chat'>"
|
||||
"<body>db-multi-second-bbb</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/laptop (win 2)"));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='multi3' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/tablet' type='chat'>"
|
||||
"<body>db-multi-third-ccc</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/tablet (win 2)"));
|
||||
|
||||
/* Close and reopen */
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
prof_input("/msg buddy1@localhost");
|
||||
|
||||
/* All three must be present in history */
|
||||
assert_true(prof_output_exact("db-multi-first-aaa"));
|
||||
assert_true(prof_output_exact("db-multi-second-bbb"));
|
||||
assert_true(prof_output_exact("db-multi-third-ccc"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: messages are stored per-contact — buddy1's history does not
|
||||
* leak into buddy2's window.
|
||||
*
|
||||
* 1. Receive from buddy1 and buddy2 while on console (bodies hidden)
|
||||
* 2. Close all chat windows
|
||||
* 3. Open buddy1 → verify buddy1's body present, buddy2's body absent
|
||||
*/
|
||||
void
|
||||
message_db_history_contact_isolation(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Receive from buddy1 */
|
||||
stbbr_send(
|
||||
"<message id='iso1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>isolation-buddy1-only-xyzzy</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
/* Receive from buddy2 */
|
||||
stbbr_send(
|
||||
"<message id='iso2' to='stabber@localhost' "
|
||||
"from='buddy2@localhost/phone' type='chat'>"
|
||||
"<body>isolation-buddy2-only-plugh</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy2/phone (win 3)"));
|
||||
|
||||
/* Close all chat windows at once */
|
||||
prof_input("/close all");
|
||||
assert_true(prof_output_exact("Closed 2 windows."));
|
||||
|
||||
/* Open buddy1 — history should contain ONLY buddy1's message */
|
||||
prof_input("/msg buddy1@localhost");
|
||||
assert_true(prof_output_exact("isolation-buddy1-only-xyzzy"));
|
||||
|
||||
/* buddy2's body was never printed to the terminal (received on
|
||||
* console), so finding it now would mean cross-contact leakage */
|
||||
prof_timeout(3);
|
||||
assert_false(prof_output_exact("isolation-buddy2-only-plugh"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: special characters survive the DB write+read round-trip.
|
||||
*
|
||||
* The XMPP body uses XML entities (& < > ") which the
|
||||
* XML parser decodes before storage. The DB must preserve the decoded
|
||||
* characters and return them unchanged.
|
||||
*/
|
||||
void
|
||||
message_db_history_special_chars(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='spec1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>chars: & <tag> "quoted"</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
prof_input("/msg buddy1@localhost");
|
||||
|
||||
/* The decoded text must appear exactly as-is */
|
||||
assert_true(prof_output_exact("chars: & <tag> \"quoted\""));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: outgoing message (sent via /msg) persists in DB.
|
||||
*
|
||||
* NOTE: The outgoing body IS rendered to the terminal when sent. Since
|
||||
* prof_output_exact searches the cumulative buffer, the assertion alone
|
||||
* does not conclusively prove DB persistence. However, combined with
|
||||
* the incoming tests, this verifies the end-to-end outgoing write path
|
||||
* and catches crashes in the outgoing DB code.
|
||||
*/
|
||||
void
|
||||
message_db_history_outgoing(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Send outgoing — opens and focuses chat window */
|
||||
prof_input("/msg buddy1@localhost db-outgoing-sent-42");
|
||||
assert_true(prof_output_regex("me: .+db-outgoing-sent-42"));
|
||||
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
/* Reopen — history should load the outgoing message */
|
||||
prof_input("/msg buddy1@localhost");
|
||||
assert_true(prof_output_exact("db-outgoing-sent-42"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: a dialog (outgoing + incoming) is fully preserved in history.
|
||||
*
|
||||
* Sends an outgoing message, then closes the window. A reply arrives
|
||||
* while on the console (body never rendered). After reopen, both sides
|
||||
* of the conversation appear — proving the incoming read from DB works
|
||||
* and the outgoing write path completed without error.
|
||||
*/
|
||||
void
|
||||
message_db_history_dialog(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Phase 1: send outgoing (renders to terminal) */
|
||||
prof_input("/msg buddy1@localhost dialog-out-msg-42");
|
||||
assert_true(prof_output_regex("me: .+dialog-out-msg-42"));
|
||||
|
||||
/* Return to console */
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
/* Phase 2: receive reply on console (body NOT in terminal buffer) */
|
||||
stbbr_send(
|
||||
"<message id='dlg-in' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>dialog-in-reply-77</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
/* Close the auto-created window */
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
/* Phase 3: reopen — history should have both directions */
|
||||
prof_input("/msg buddy1@localhost");
|
||||
|
||||
/* Incoming body conclusively proves DB round-trip */
|
||||
assert_true(prof_output_exact("dialog-in-reply-77"));
|
||||
/* Outgoing body is consistent with DB persistence */
|
||||
assert_true(prof_output_exact("dialog-out-msg-42"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: opening a chat window for a contact with no prior messages
|
||||
* does not crash and the window is usable.
|
||||
*/
|
||||
void
|
||||
message_db_history_empty(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* buddy2 has never exchanged messages — history is empty */
|
||||
prof_input("/msg buddy2@localhost");
|
||||
assert_true(prof_output_exact("buddy2@localhost"));
|
||||
|
||||
/* Verify the window is functional by sending a message */
|
||||
prof_input("empty-history-smoke-test");
|
||||
assert_true(prof_output_regex("me: .+empty-history-smoke-test"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: a long message (1000+ characters) is not truncated by the DB.
|
||||
*/
|
||||
void
|
||||
message_db_history_long_message(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Build a 1020-character body: 1000 x 'A' + unique suffix */
|
||||
char body[1100];
|
||||
memset(body, 'A', 1000);
|
||||
strcpy(body + 1000, "-long-db-end-MARKER");
|
||||
|
||||
char xml[1500];
|
||||
snprintf(xml, sizeof(xml),
|
||||
"<message id='long1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>%s</body>"
|
||||
"</message>", body);
|
||||
stbbr_send(xml);
|
||||
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
prof_input("/msg buddy1@localhost");
|
||||
assert_true(prof_output_exact("-long-db-end-MARKER"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: message body containing embedded newlines (LF) is stored and
|
||||
* loaded correctly.
|
||||
*
|
||||
* Uses XML character reference for literal newline in body.
|
||||
*/
|
||||
void
|
||||
message_db_history_newline(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='nl1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>nl-first-line-7k nl-second-line-9m nl-third-line-2p</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
prof_input("/msg buddy1@localhost");
|
||||
/* Each fragment must survive the round-trip */
|
||||
assert_true(prof_output_exact("nl-first-line-7k"));
|
||||
assert_true(prof_output_exact("nl-second-line-9m"));
|
||||
assert_true(prof_output_exact("nl-third-line-2p"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: characters that could break storage format (backslash, pipe,
|
||||
* percent, braces, brackets, equals) survive DB round-trip.
|
||||
*/
|
||||
void
|
||||
message_db_history_service_chars(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='svc1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>svc: a\\b c|d e%f {g} [h] i=j</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
prof_input("/msg buddy1@localhost");
|
||||
assert_true(prof_output_exact("svc: a\\b c|d e%f {g} [h] i=j"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: /history verify reports no issues after normal message writes.
|
||||
*/
|
||||
void
|
||||
message_db_history_verify(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Write a few messages to create non-trivial DB state */
|
||||
stbbr_send(
|
||||
"<message id='ver1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>verify-msg-one</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='ver2' to='stabber@localhost' "
|
||||
"from='buddy2@localhost/phone' type='chat'>"
|
||||
"<body>verify-msg-two</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy2/phone (win 3)"));
|
||||
|
||||
/* Run verify — should find no issues */
|
||||
prof_input("/history verify");
|
||||
assert_true(prof_output_exact("Verification complete: no issues found."));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: LMC (Last Message Correction, XEP-0308) — incoming correction
|
||||
* replaces the original in DB history.
|
||||
*
|
||||
* Both messages arrive while focused on the console so their bodies
|
||||
* are never rendered to the terminal. After reopen, only the corrected
|
||||
* text should appear — the original should be absent.
|
||||
*/
|
||||
void
|
||||
message_db_history_lmc(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Original message (body never displayed — received on console) */
|
||||
stbbr_send(
|
||||
"<message id='lmc-orig-1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>lmc-before-correction-aaa</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
/* Correction replacing the original (XEP-0308).
|
||||
* Use buddy2 message as sync barrier to ensure correction is processed. */
|
||||
stbbr_send(
|
||||
"<message id='lmc-corr-1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>lmc-after-correction-zzz</body>"
|
||||
"<replace id='lmc-orig-1' xmlns='urn:xmpp:message-correct:0'/>"
|
||||
"</message>");
|
||||
|
||||
/* Sync barrier: send from buddy2, wait for its notification */
|
||||
stbbr_send(
|
||||
"<message id='lmc-sync' to='stabber@localhost' "
|
||||
"from='buddy2@localhost/phone' type='chat'>"
|
||||
"<body>lmc-sync-barrier</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy2/phone (win 3)"));
|
||||
|
||||
/* Close buddy1 and buddy2 windows */
|
||||
prof_input("/close all");
|
||||
assert_true(prof_output_exact("Closed 2 windows."));
|
||||
|
||||
/* Reopen buddy1 — should have corrected text only */
|
||||
prof_input("/msg buddy1@localhost");
|
||||
assert_true(prof_output_exact("lmc-after-correction-zzz"));
|
||||
|
||||
/* Original body was never in the terminal buffer (received on console).
|
||||
* Its absence in history proves the correction was applied in the DB. */
|
||||
prof_timeout(3);
|
||||
assert_false(prof_output_exact("lmc-before-correction-aaa"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
12
tests/functionaltests/test_history.h
Normal file
12
tests/functionaltests/test_history.h
Normal file
@@ -0,0 +1,12 @@
|
||||
void message_db_history_on_reopen(void **state);
|
||||
void message_db_history_multiple(void **state);
|
||||
void message_db_history_contact_isolation(void **state);
|
||||
void message_db_history_special_chars(void **state);
|
||||
void message_db_history_outgoing(void **state);
|
||||
void message_db_history_dialog(void **state);
|
||||
void message_db_history_empty(void **state);
|
||||
void message_db_history_long_message(void **state);
|
||||
void message_db_history_newline(void **state);
|
||||
void message_db_history_service_chars(void **state);
|
||||
void message_db_history_verify(void **state);
|
||||
void message_db_history_lmc(void **state);
|
||||
@@ -515,7 +515,7 @@ _lists_equal(GSList* a, GSList* b)
|
||||
GSList* curra = a;
|
||||
GSList* currb = b;
|
||||
|
||||
while (curra && currb) {
|
||||
while (curra) {
|
||||
int aval = GPOINTER_TO_INT(curra->data);
|
||||
int bval = GPOINTER_TO_INT(currb->data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user