mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-24 09:36:20 +00:00
Merge upstream/master into merge/upstream-full
Merge profanity-im/profanity master (373 commits) into cproof fork.
Source changes (manual merge):
- src/command/: cmd_defs, cmd_funcs, cmd_ac — upstream g_new0, auto_gchar,
launch_editor callback; keep our XEP-0308 LMC, force-encryption, CWE-134
- src/config/: preferences, tlscerts, account — upstream UNIQUE dedup,
dynamic pad capacity; keep our db_history_result_t, scroll logic
- src/database.*: upstream g_new0 memory mgmt; keep our return types,
add null-check fix for msg->timestamp
- src/omemo/, src/pgp/: upstream _gpgme_key_get_email, g_new0;
keep our replace_id in omemo_on_message_send
- src/tools/: editor, http_upload, bookmark_ignore — upstream launch_editor
callback API
- src/ui/: console, window, chatwin, mucwin, inputwin, buffer —
upstream win_warn_needed/sent dedup, PAD_MIN_HEIGHT dynamic pads;
keep our y_start_pos scroll, _truncate_datetime_suffix
- src/xmpp/: message, stanza, presence, roster_list, iq, session —
upstream connection_get_available_resources; keep our LMC stanza logic
- src/common.c: fix format-security (cons_show)
Build system:
- Makefile.am: updated test paths to subdirectory structure, added
test_cmd_ac, test_forced_encryption
- Restored autotools files deleted by upstream meson migration:
bootstrap.sh, autogen.sh, m4/ax_valgrind_check.m4, configure-debug
Tests:
- Unit tests: upstream unittests.c base + our forced_encryption tests
(482 passed, 0 failed across all 4 configurations)
- Functional tests: kept our version (93 passed, 0 failed)
upstream version requires stbbr_for_xmlns not yet in our stabber fork
- Updated test stubs: stub_xmpp.c, stub_omemo.c from upstream
Compile fixes:
- src/common.c: cons_show(errmsg) -> cons_show("%s", errmsg)
- src/database.c: null-check before msg->timestamp access
- src/ui/console.c: size_t -> (int) cast for format width
- src/config/tlscerts.c: %d -> %zu for size_t
This commit is contained in:
@@ -2,37 +2,11 @@
|
||||
* editor.c
|
||||
* vim: expandtab:ts=4:sts=4:sw=4
|
||||
*
|
||||
* Copyright (C) 2022 - 2025 Michael Vetter <jubalh@iodoru.org>
|
||||
* Copyright (C) 2022 - 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
* Copyright (C) 2022 MarcoPolo PasTonMolo <marcopolopastonmolo@protonmail.com>
|
||||
* Copyright (C) 2022 Steffen Jaeckel <jaeckel-floss@eyet-services.de>
|
||||
*
|
||||
* This file is part of Profanity.
|
||||
*
|
||||
* Profanity is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Profanity is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link the code of portions of this program with the OpenSSL library under
|
||||
* certain conditions as described in each individual source file, and
|
||||
* distribute linked combinations including the two.
|
||||
*
|
||||
* You must obey the GNU General Public License in all respects for all of the
|
||||
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
||||
* may extend this exception to your version of the file(s), but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version. If you delete this exception statement from all
|
||||
* source files in the program, then also delete it here.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
@@ -52,6 +26,47 @@
|
||||
#include "ncurses.h"
|
||||
#include "ui/ui.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
typedef struct EditorContext
|
||||
{
|
||||
gchar* filename;
|
||||
void (*callback)(gchar* content, void* user_data);
|
||||
void* user_data;
|
||||
} EditorContext;
|
||||
|
||||
static void
|
||||
_editor_exit_cb(GPid pid, gint status, gpointer data)
|
||||
{
|
||||
EditorContext* ctx = data;
|
||||
gchar* contents = NULL;
|
||||
GError* error = NULL;
|
||||
|
||||
ui_resume();
|
||||
ui_resize();
|
||||
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
|
||||
if (g_file_get_contents(ctx->filename, &contents, NULL, &error)) {
|
||||
g_strchomp(contents);
|
||||
ctx->callback(contents, ctx->user_data);
|
||||
g_free(contents);
|
||||
} else {
|
||||
log_error("[Editor] could not read from %s: %s", ctx->filename, error->message);
|
||||
cons_show_error("Could not read edited content: %s", error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
} else {
|
||||
cons_show_error("Editor exited with error status %d", WEXITSTATUS(status));
|
||||
}
|
||||
|
||||
if (remove(ctx->filename) != 0) {
|
||||
log_error("[Editor] error during file deletion of %s", ctx->filename);
|
||||
}
|
||||
|
||||
g_free(ctx->filename);
|
||||
g_free(ctx);
|
||||
g_spawn_close_pid(pid);
|
||||
}
|
||||
|
||||
EditorTask editor_task = { 0, FALSE, NULL, NULL, PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL };
|
||||
|
||||
@@ -234,13 +249,10 @@ editor_process(ProfWin* window)
|
||||
// Please avoid using it, since it blocks execution of the message handling and other important functionality until the editor is closed.
|
||||
// Returns true if an error occurred
|
||||
gboolean
|
||||
get_message_from_editor(gchar* message, gchar** returned_message)
|
||||
launch_editor(gchar* initial_content, void (*callback)(gchar* content, void* data), void* user_data)
|
||||
{
|
||||
/* Make sure that there's no junk in the return-pointer in error cases */
|
||||
*returned_message = NULL;
|
||||
|
||||
auto_gchar gchar* filename = NULL;
|
||||
GError* glib_error = NULL;
|
||||
auto_gerror GError* glib_error = NULL;
|
||||
const char* jid = connection_get_barejid();
|
||||
if (jid) {
|
||||
filename = files_file_in_account_data_path(DIR_EDITOR, jid, "compose.md");
|
||||
@@ -248,64 +260,67 @@ get_message_from_editor(gchar* message, gchar** returned_message)
|
||||
log_debug("[Editor] could not get JID");
|
||||
auto_gchar gchar* data_dir = files_get_data_path(DIR_EDITOR);
|
||||
if (!create_dir(data_dir)) {
|
||||
cons_show_error("Could not create editor directory.");
|
||||
return TRUE;
|
||||
}
|
||||
filename = g_strdup_printf("%s/compose.md", data_dir);
|
||||
}
|
||||
if (!filename) {
|
||||
log_error("[Editor] something went wrong while creating compose file");
|
||||
cons_show_error("Could not create compose file.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gsize messagelen = 0;
|
||||
if (message != NULL) {
|
||||
messagelen = strlen(message);
|
||||
if (initial_content != NULL) {
|
||||
messagelen = strlen(initial_content);
|
||||
}
|
||||
|
||||
if (!g_file_set_contents(filename, message, messagelen, &glib_error)) {
|
||||
log_error("[Editor] could not write to %s: %s", filename, glib_error ? glib_error->message : "No GLib error given");
|
||||
if (glib_error) {
|
||||
g_error_free(glib_error);
|
||||
}
|
||||
if (!g_file_set_contents(filename, initial_content, messagelen, &glib_error)) {
|
||||
log_error("[Editor] could not write to %s: %s", filename, PROF_GERROR_MESSAGE(glib_error));
|
||||
cons_show_error("Could not write to compose file: %s", PROF_GERROR_MESSAGE(glib_error));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto_gchar gchar* editor = prefs_get_string(PREF_COMPOSE_EDITOR);
|
||||
auto_gchar gchar* editor_with_filename = g_strdup_printf("%s %s", editor, filename);
|
||||
auto_gcharv gchar** editor_argv = g_strsplit(editor_with_filename, " ", 0);
|
||||
gchar** editor_argv = NULL;
|
||||
GError* error = NULL;
|
||||
|
||||
// Fork / exec
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
int x = execvp(editor_argv[0], editor_argv);
|
||||
if (x == -1) {
|
||||
log_error("[Editor] Failed to exec %s", editor);
|
||||
}
|
||||
_exit(EXIT_FAILURE);
|
||||
} else {
|
||||
if (pid == -1) {
|
||||
return TRUE;
|
||||
}
|
||||
waitpid(pid, NULL, 0);
|
||||
|
||||
gchar* contents;
|
||||
gsize length;
|
||||
if (!g_file_get_contents(filename, &contents, &length, &glib_error)) {
|
||||
log_error("[Editor] could not read from %s: %s", filename, glib_error ? glib_error->message : "No GLib error given");
|
||||
if (glib_error) {
|
||||
g_error_free(glib_error);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
/* Remove all trailing new-line characters */
|
||||
g_strchomp(contents);
|
||||
*returned_message = contents;
|
||||
if (remove(filename) != 0) {
|
||||
log_error("[Editor] error during file deletion of %s", filename);
|
||||
} else {
|
||||
log_debug("[Editor] deleted file: %s", filename);
|
||||
}
|
||||
auto_gchar gchar* full_cmd = g_strdup_printf("%s %s", editor, filename);
|
||||
if (!g_shell_parse_argv(full_cmd, NULL, &editor_argv, &error)) {
|
||||
log_error("[Editor] Failed to parse editor command: %s", error->message);
|
||||
cons_show_error("Failed to parse editor command: %s", error->message);
|
||||
g_error_free(error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
EditorContext* ctx = g_new0(EditorContext, 1);
|
||||
ctx->filename = g_steal_pointer(&filename);
|
||||
ctx->callback = callback;
|
||||
ctx->user_data = user_data;
|
||||
|
||||
ui_suspend();
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid == -1) {
|
||||
log_error("[Editor] Failed to fork: %s", strerror(errno));
|
||||
ui_resume();
|
||||
ui_resize();
|
||||
cons_show_error("Failed to start editor: %s", strerror(errno));
|
||||
g_strfreev(editor_argv);
|
||||
g_free(ctx->filename);
|
||||
g_free(ctx);
|
||||
return TRUE;
|
||||
} else if (pid == 0) {
|
||||
// Child process: Inherits TTY from parent
|
||||
if (editor_argv && editor_argv[0]) {
|
||||
execvp(editor_argv[0], editor_argv);
|
||||
}
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Parent process: Watch the child asynchronously
|
||||
g_child_watch_add((GPid)pid, _editor_exit_cb, ctx);
|
||||
g_strfreev(editor_argv);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user