mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-24 11:36:21 +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:
@@ -5,33 +5,7 @@
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
* Copyright (C) 2020 William Wennerström <william@wstrm.dev>
|
||||
*
|
||||
* 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 "config.h"
|
||||
@@ -69,7 +43,7 @@ aesgcm_file_get(void* userdata)
|
||||
// and tag stored in the URL fragment.
|
||||
if (omemo_parse_aesgcm_url(aesgcm_dl->url, &https_url, &fragment) != 0) {
|
||||
cons_show_error("Download failed: Cannot parse URL '%s'.", aesgcm_dl->url);
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, THEME_ERROR, ENTRY_ERROR,
|
||||
"Download failed: Cannot parse URL '%s'.",
|
||||
aesgcm_dl->url);
|
||||
return NULL;
|
||||
@@ -80,7 +54,7 @@ aesgcm_file_get(void* userdata)
|
||||
auto_gchar gchar* tmpname = NULL;
|
||||
auto_gfd gint tmpfd = 0;
|
||||
if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) {
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, THEME_ERROR, ENTRY_ERROR,
|
||||
"Downloading '%s' failed: Unable to create "
|
||||
"temporary ciphertext file for writing "
|
||||
"(%s).",
|
||||
@@ -91,7 +65,7 @@ aesgcm_file_get(void* userdata)
|
||||
// Open the target file for storing the cleartext.
|
||||
auto_FILE FILE* outfh = fopen(aesgcm_dl->filename, "wb");
|
||||
if (outfh == NULL) {
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, THEME_ERROR, ENTRY_ERROR,
|
||||
"Downloading '%s' failed: Unable to open "
|
||||
"output file at '%s' for writing (%s).",
|
||||
https_url, aesgcm_dl->filename,
|
||||
@@ -101,14 +75,16 @@ aesgcm_file_get(void* userdata)
|
||||
|
||||
// We wrap the HTTPDownload tool and use it for retrieving the ciphertext
|
||||
// and storing it in the temporary file previously opened.
|
||||
HTTPDownload* http_dl = calloc(1, sizeof(HTTPDownload));
|
||||
HTTPDownload* http_dl = g_new0(HTTPDownload, 1);
|
||||
http_dl->window = aesgcm_dl->window;
|
||||
http_dl->worker = aesgcm_dl->worker;
|
||||
http_dl->id = strdup(aesgcm_dl->id);
|
||||
http_dl->url = strdup(https_url);
|
||||
http_dl->display_url = strdup(aesgcm_dl->url);
|
||||
http_dl->filename = strdup(tmpname);
|
||||
http_dl->cmd_template = NULL;
|
||||
http_dl->silent = FALSE;
|
||||
http_dl->silent_done = TRUE;
|
||||
http_dl->return_bytes_received = TRUE;
|
||||
aesgcm_dl->http_dl = http_dl;
|
||||
|
||||
@@ -121,7 +97,7 @@ aesgcm_file_get(void* userdata)
|
||||
|
||||
FILE* tmpfh = fopen(tmpname, "rb");
|
||||
if (tmpfh == NULL) {
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, THEME_ERROR, ENTRY_ERROR,
|
||||
"Downloading '%s' failed: Unable to open "
|
||||
"temporary file at '%s' for reading (%s).",
|
||||
aesgcm_dl->url, tmpname,
|
||||
@@ -136,13 +112,15 @@ aesgcm_file_get(void* userdata)
|
||||
remove(tmpname);
|
||||
|
||||
if (crypt_res != GPG_ERR_NO_ERROR) {
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, THEME_ERROR, ENTRY_ERROR,
|
||||
"Downloading '%s' failed: Failed to decrypt "
|
||||
"file (%s).",
|
||||
https_url, gcry_strerror(crypt_res));
|
||||
} else {
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||
"Decrypted file saved to '%s'", aesgcm_dl->filename);
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, THEME_ONLINE, ENTRY_COMPLETED,
|
||||
"Downloading '%s': done\nSaved to '%s'",
|
||||
aesgcm_dl->url, aesgcm_dl->filename);
|
||||
win_mark_received(aesgcm_dl->window, aesgcm_dl->id);
|
||||
}
|
||||
|
||||
if (aesgcm_dl->cmd_template != NULL) {
|
||||
@@ -152,7 +130,7 @@ aesgcm_file_get(void* userdata)
|
||||
|
||||
// TODO: Log the error.
|
||||
if (!call_external(argv)) {
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id, THEME_ERROR, ENTRY_ERROR,
|
||||
"Downloading '%s' failed: Unable to call "
|
||||
"command '%s' with file at '%s' (%s).",
|
||||
aesgcm_dl->url,
|
||||
|
||||
@@ -5,33 +5,7 @@
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
* Copyright (C) 2020 William Wennerström <william@wstrm.dev>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_AESGCM_DOWNLOAD_H
|
||||
@@ -50,7 +24,7 @@
|
||||
|
||||
typedef struct aesgcm_download_t
|
||||
{
|
||||
char* id;
|
||||
gchar* id;
|
||||
char* url;
|
||||
char* filename;
|
||||
char* cmd_template;
|
||||
|
||||
@@ -4,33 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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 "config.h"
|
||||
@@ -62,7 +36,7 @@ static gchar* _search(Autocomplete ac, GList* curr, gboolean quote, search_direc
|
||||
Autocomplete
|
||||
autocomplete_new(void)
|
||||
{
|
||||
return calloc(1, sizeof(struct autocomplete_t));
|
||||
return g_new0(struct autocomplete_t, 1);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -175,7 +149,7 @@ autocomplete_add(Autocomplete ac, const char* item)
|
||||
void
|
||||
autocomplete_add_all(Autocomplete ac, char** items)
|
||||
{
|
||||
for (int i = 0; i < g_strv_length(items); i++) {
|
||||
for (guint i = 0; i < g_strv_length(items); i++) {
|
||||
autocomplete_add(ac, items[i]);
|
||||
}
|
||||
}
|
||||
@@ -205,7 +179,7 @@ autocomplete_remove(Autocomplete ac, const char* const item)
|
||||
void
|
||||
autocomplete_remove_all(Autocomplete ac, char** items)
|
||||
{
|
||||
for (int i = 0; i < g_strv_length(items); i++) {
|
||||
for (guint i = 0; i < g_strv_length(items); i++) {
|
||||
autocomplete_remove(ac, items[i]);
|
||||
}
|
||||
}
|
||||
@@ -260,7 +234,16 @@ autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote,
|
||||
FREE_SET_NULL(ac->search_str);
|
||||
}
|
||||
|
||||
ac->search_str = strdup(search_str);
|
||||
// unescape search string
|
||||
GString* unescaped = g_string_new("");
|
||||
for (const char* p = search_str; *p; p++) {
|
||||
if (*p == '\\' && (*(p + 1) != '\0')) {
|
||||
p++;
|
||||
}
|
||||
g_string_append_c(unescaped, *p);
|
||||
}
|
||||
ac->search_str = g_string_free(unescaped, FALSE);
|
||||
|
||||
found = _search(ac, ac->items, quote, NEXT);
|
||||
|
||||
return found;
|
||||
@@ -396,22 +379,48 @@ autocomplete_remove_older_than_max_reverse(Autocomplete ac, int maxsize)
|
||||
static gchar*
|
||||
_search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction)
|
||||
{
|
||||
auto_gchar gchar* search_str_fold = g_utf8_casefold(ac->search_str, -1);
|
||||
auto_gchar gchar* search_str_ascii = g_str_to_ascii(ac->search_str, NULL);
|
||||
auto_gchar gchar* search_str_lower = g_ascii_strdown(search_str_ascii, -1);
|
||||
auto_gchar gchar* search_str_ascii_lower = g_ascii_strdown(search_str_ascii, -1);
|
||||
|
||||
while (curr) {
|
||||
auto_gchar gchar* curr_ascii = g_str_to_ascii(curr->data, NULL);
|
||||
auto_gchar gchar* curr_lower = g_ascii_strdown(curr_ascii, -1);
|
||||
gboolean match = FALSE;
|
||||
|
||||
// match found
|
||||
if (strncmp(curr_lower, search_str_lower, strlen(search_str_lower)) == 0) {
|
||||
// Try exact UTF-8 case insensitive match
|
||||
auto_gchar gchar* curr_fold = g_utf8_casefold(curr->data, -1);
|
||||
if (g_str_has_prefix(curr_fold, search_str_fold)) {
|
||||
match = TRUE;
|
||||
}
|
||||
|
||||
// Try transliterated match (allow typing 'e' for 'è')
|
||||
if (!match) {
|
||||
auto_gchar gchar* curr_ascii = g_str_to_ascii(curr->data, NULL);
|
||||
auto_gchar gchar* curr_ascii_lower = g_ascii_strdown(curr_ascii, -1);
|
||||
|
||||
// We only use transliterated match if the search string conversion didn't result
|
||||
// in unknown characters ('?'), to avoid false matches between different scripts.
|
||||
if (strchr(search_str_ascii_lower, '?') == NULL) {
|
||||
if (g_str_has_prefix(curr_ascii_lower, search_str_ascii_lower)) {
|
||||
match = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (match) {
|
||||
// set pointer to last found
|
||||
ac->last_found = curr;
|
||||
|
||||
// if contains space, quote before returning
|
||||
if (quote && g_strrstr(curr->data, " ")) {
|
||||
return g_strdup_printf("\"%s\"", (gchar*)curr->data);
|
||||
GString* escaped = g_string_new("\"");
|
||||
for (const char* p = curr->data; *p; p++) {
|
||||
if (*p == '"' || *p == '\\') {
|
||||
g_string_append_c(escaped, '\\');
|
||||
}
|
||||
g_string_append_c(escaped, *p);
|
||||
}
|
||||
g_string_append_c(escaped, '"');
|
||||
return g_string_free(escaped, FALSE);
|
||||
// otherwise just return the string
|
||||
} else {
|
||||
return strdup(curr->data);
|
||||
|
||||
@@ -4,33 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_AUTOCOMPLETE_H
|
||||
|
||||
@@ -2,35 +2,9 @@
|
||||
* bookmark_ignore.c
|
||||
* vim: expandtab:ts=4:sts=4:sw=4
|
||||
*
|
||||
* Copyright (C) 2020 - 2025 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 2020 - 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@@ -73,7 +47,7 @@ bookmark_ignore_on_connect(const char* const barejid)
|
||||
}
|
||||
|
||||
void
|
||||
bookmark_ignore_on_disconnect()
|
||||
bookmark_ignore_on_disconnect(void)
|
||||
{
|
||||
free_keyfile(&bookmark_ignore_prof_keyfile);
|
||||
bookmark_ignore_keyfile = NULL;
|
||||
|
||||
@@ -2,42 +2,16 @@
|
||||
* bookmark_ignore.h
|
||||
* vim: expandtab:ts=4:sts=4:sw=4
|
||||
*
|
||||
* Copyright (C) 2020 - 2025 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 2020 - 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#ifndef BOOKMARK_IGNORE_H
|
||||
#define BOOKMARK_IGNORE_H
|
||||
|
||||
void bookmark_ignore_on_connect();
|
||||
void bookmark_ignore_on_disconnect();
|
||||
void bookmark_ignore_on_connect(const char* const barejid);
|
||||
void bookmark_ignore_on_disconnect(void);
|
||||
gboolean bookmark_ignored(Bookmark* bookmark);
|
||||
gchar** bookmark_ignore_list(gsize* len);
|
||||
void bookmark_ignore_add(const char* const barejid);
|
||||
|
||||
@@ -2,35 +2,9 @@
|
||||
* clipboard.c
|
||||
* vim: expandtab:ts=4:sts=4:sw=4
|
||||
*
|
||||
* Copyright (C) 2019 - 2025 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 2019 - 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@@ -41,6 +15,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "ui/tray.h"
|
||||
|
||||
/*
|
||||
For now we rely on tray_init(void)
|
||||
@@ -53,6 +28,9 @@ void clipboard_init(int argc, char **argv) {
|
||||
char*
|
||||
clipboard_get(void)
|
||||
{
|
||||
if (!tray_gtk_ready()) {
|
||||
return NULL;
|
||||
}
|
||||
gchar* clip;
|
||||
|
||||
GtkClipboard* cl = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
|
||||
|
||||
@@ -2,35 +2,9 @@
|
||||
* clipboard.h
|
||||
* vim: expandtab:ts=4:sts=4:sw=4
|
||||
*
|
||||
* Copyright (C) 2019 - 2025 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 2019 - 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#ifndef UI_CLIPBOARD_H
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,36 +2,10 @@
|
||||
* editor.h
|
||||
* 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>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_EDITOR_H
|
||||
@@ -56,5 +30,6 @@ extern EditorTask editor_task;
|
||||
gboolean get_message_from_editor(gchar* message, gchar** returned_message);
|
||||
gboolean get_message_from_editor_async(gchar* message);
|
||||
void editor_process(ProfWin* window);
|
||||
gboolean launch_editor(gchar* initial_content, void (*callback)(gchar* content, void* data), void* user_data);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,33 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 2020 William Wennerström <william@wstrm.dev>
|
||||
*
|
||||
* 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 "config.h"
|
||||
@@ -45,7 +19,7 @@
|
||||
#define FALLBACK_MSG ""
|
||||
|
||||
void
|
||||
http_print_transfer_update(ProfWin* window, char* id, const char* fmt, ...)
|
||||
http_print_transfer_update(ProfWin* window, char* id, theme_item_t theme_item, int flags, const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
@@ -55,7 +29,7 @@ http_print_transfer_update(ProfWin* window, char* id, const char* fmt, ...)
|
||||
va_end(args);
|
||||
|
||||
if (window->type != WIN_CONSOLE) {
|
||||
win_update_entry_message(window, id, msg->str);
|
||||
win_update_entry(window, id, msg->str, theme_item, flags);
|
||||
} else {
|
||||
cons_show("%s", msg->str);
|
||||
}
|
||||
@@ -64,7 +38,7 @@ http_print_transfer_update(ProfWin* window, char* id, const char* fmt, ...)
|
||||
}
|
||||
|
||||
void
|
||||
http_print_transfer(ProfWin* window, char* id, const char* fmt, ...)
|
||||
http_print_transfer(ProfWin* window, char* id, theme_item_t theme_item, const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
@@ -73,7 +47,7 @@ http_print_transfer(ProfWin* window, char* id, const char* fmt, ...)
|
||||
g_string_vprintf(msg, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
win_print_http_transfer(window, msg->str, id);
|
||||
win_print_status_with_id(window, msg->str, id, theme_item, 0);
|
||||
|
||||
g_string_free(msg, TRUE);
|
||||
}
|
||||
|
||||
@@ -4,33 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 2020 William Wennerström <william@wstrm.dev>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_HTTP_COMMON_H
|
||||
@@ -39,9 +13,9 @@
|
||||
#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, ...);
|
||||
G_GNUC_PRINTF(4, 5)
|
||||
void http_print_transfer(ProfWin* window, char* id, theme_item_t theme_item, const char* fmt, ...);
|
||||
G_GNUC_PRINTF(5, 6)
|
||||
void http_print_transfer_update(ProfWin* window, char* id, theme_item_t theme_item, int flags, const char* fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,35 +4,9 @@
|
||||
*
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
* Copyright (C) 2020 William Wennerström <william@wstrm.dev>
|
||||
* Copyright (C) 2019 - 2025 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 2019 - 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@@ -58,7 +32,6 @@
|
||||
#include "common.h"
|
||||
|
||||
GSList* download_processes = NULL;
|
||||
gboolean silent = FALSE;
|
||||
|
||||
static int
|
||||
_xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||
@@ -84,9 +57,18 @@ _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot
|
||||
dlperc = (100 * dlnow) / dltotal;
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
http_print_transfer_update(download->window, download->url,
|
||||
"Downloading '%s': %d%%", download->url, dlperc);
|
||||
if (!download->silent) {
|
||||
const char* url = download->display_url ? download->display_url : download->url;
|
||||
if (dlnow == dltotal && dltotal > 0) {
|
||||
if (!download->silent_done) {
|
||||
http_print_transfer_update(download->window, download->id, THEME_ONLINE, ENTRY_COMPLETED,
|
||||
"Downloading '%s': done", url);
|
||||
}
|
||||
} else {
|
||||
http_print_transfer_update(download->window, download->id, THEME_DEFAULT, 0,
|
||||
"Downloading '%s': %d%%", url, dlperc);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&lock);
|
||||
|
||||
@@ -111,20 +93,20 @@ http_file_get(void* userdata)
|
||||
|
||||
CURL* curl;
|
||||
CURLcode res;
|
||||
silent = download->silent;
|
||||
|
||||
download->cancel = 0;
|
||||
download->bytes_received = 0;
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
if (!silent) {
|
||||
http_print_transfer(download->window, download->id,
|
||||
"Downloading '%s': 0%%", download->url);
|
||||
const char* display_url = download->display_url ? download->display_url : download->url;
|
||||
if (!download->silent) {
|
||||
http_print_transfer(download->window, download->id, THEME_DEFAULT,
|
||||
"Downloading '%s': 0%%", display_url);
|
||||
}
|
||||
|
||||
FILE* outfh = fopen(download->filename, "wb");
|
||||
if (outfh == NULL) {
|
||||
http_print_transfer_update(download->window, download->id,
|
||||
http_print_transfer_update(download->window, download->id, THEME_ERROR, ENTRY_ERROR,
|
||||
"Downloading '%s' failed: Unable to open "
|
||||
"output file at '%s' for writing (%s).",
|
||||
download->url, download->filename,
|
||||
@@ -177,7 +159,7 @@ http_file_get(void* userdata)
|
||||
err = strdup(curl_easy_strerror(res));
|
||||
}
|
||||
|
||||
if (ftell(outfh) == 0) {
|
||||
if (!err && ftell(outfh) == 0) {
|
||||
err = strdup("Output file is empty.");
|
||||
}
|
||||
|
||||
@@ -185,7 +167,9 @@ http_file_get(void* userdata)
|
||||
curl_global_cleanup();
|
||||
|
||||
if (fclose(outfh) == EOF) {
|
||||
err = strdup(g_strerror(errno));
|
||||
if (!err) {
|
||||
err = strdup(g_strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
@@ -193,25 +177,29 @@ http_file_get(void* userdata)
|
||||
g_free(cert_path);
|
||||
if (err) {
|
||||
if (download->cancel) {
|
||||
http_print_transfer_update(download->window, download->id,
|
||||
http_print_transfer_update(download->window, download->id, THEME_ERROR, ENTRY_ERROR,
|
||||
"Downloading '%s' failed: "
|
||||
"Download was canceled",
|
||||
download->url);
|
||||
display_url);
|
||||
} else {
|
||||
http_print_transfer_update(download->window, download->id,
|
||||
http_print_transfer_update(download->window, download->id, THEME_ERROR, ENTRY_ERROR,
|
||||
"Downloading '%s' failed: %s",
|
||||
download->url, err);
|
||||
display_url, err);
|
||||
}
|
||||
free(err);
|
||||
} else {
|
||||
if (!download->cancel && !silent) {
|
||||
http_print_transfer_update(download->window, download->id,
|
||||
"Downloading '%s': done\nSaved to '%s'",
|
||||
download->url, download->filename);
|
||||
win_mark_received(download->window, download->id);
|
||||
if (!download->cancel) {
|
||||
if (!download->silent && !download->silent_done) {
|
||||
http_print_transfer_update(download->window, download->id, THEME_ONLINE, ENTRY_COMPLETED,
|
||||
"Downloading '%s': done\nSaved to '%s'",
|
||||
display_url, download->filename);
|
||||
win_mark_received(download->window, download->id);
|
||||
}
|
||||
if (download->return_bytes_received) {
|
||||
ret = malloc(sizeof(*ret));
|
||||
*ret = download->bytes_received;
|
||||
if (ret) {
|
||||
*ret = download->bytes_received;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,10 +211,10 @@ http_file_get(void* userdata)
|
||||
|
||||
// TODO: Log the error.
|
||||
if (!call_external(argv)) {
|
||||
http_print_transfer_update(download->window, download->id,
|
||||
http_print_transfer_update(download->window, download->id, THEME_ERROR, ENTRY_ERROR,
|
||||
"Downloading '%s' failed: Unable to call "
|
||||
"command '%s' with file at '%s' (%s).",
|
||||
download->url,
|
||||
display_url,
|
||||
download->cmd_template,
|
||||
download->filename,
|
||||
"TODO: Log the error");
|
||||
@@ -243,6 +231,7 @@ out:
|
||||
|
||||
free(download->filename);
|
||||
free(download->url);
|
||||
free(download->display_url);
|
||||
free(download->id);
|
||||
free(download);
|
||||
|
||||
|
||||
@@ -5,33 +5,7 @@
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
* Copyright (C) 2020 William Wennerström <william@wstrm.dev>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_HTTP_DOWNLOAD_H
|
||||
@@ -51,6 +25,7 @@ typedef struct http_download_t
|
||||
{
|
||||
char* id;
|
||||
char* url;
|
||||
char* display_url;
|
||||
char* filename;
|
||||
char* cmd_template;
|
||||
curl_off_t bytes_received;
|
||||
@@ -58,6 +33,7 @@ typedef struct http_download_t
|
||||
pthread_t worker;
|
||||
int cancel;
|
||||
gboolean silent;
|
||||
gboolean silent_done;
|
||||
gboolean return_bytes_received;
|
||||
} HTTPDownload;
|
||||
|
||||
|
||||
@@ -4,33 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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 "config.h"
|
||||
@@ -91,11 +65,21 @@ _xferinfo(void* userdata, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultot
|
||||
ulperc = (100 * ulnow) / ultotal;
|
||||
}
|
||||
|
||||
gchar* msg = g_strdup_printf("Uploading '%s': %d%%", upload->filename, ulperc);
|
||||
gchar* msg = NULL;
|
||||
theme_item_t theme = THEME_DEFAULT;
|
||||
int flags = 0;
|
||||
if (ulnow == ultotal && ultotal > 0) {
|
||||
msg = g_strdup_printf("Uploading '%s': done", upload->filename);
|
||||
theme = THEME_ONLINE;
|
||||
flags = ENTRY_COMPLETED;
|
||||
} else {
|
||||
msg = g_strdup_printf("Uploading '%s': %d%%", upload->filename, ulperc);
|
||||
}
|
||||
|
||||
if (!msg) {
|
||||
msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, msg);
|
||||
win_update_entry(upload->window, upload->put_url, msg, theme, flags);
|
||||
g_free(msg);
|
||||
|
||||
pthread_mutex_unlock(&lock);
|
||||
@@ -176,7 +160,7 @@ http_file_put(void* userdata)
|
||||
if (!msg) {
|
||||
msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_print_http_transfer(upload->window, msg, upload->put_url);
|
||||
win_print_status_with_id(upload->window, msg, upload->put_url, THEME_DEFAULT, 0);
|
||||
|
||||
auto_gchar gchar* cert_path = prefs_get_string(PREF_TLS_CERTPATH);
|
||||
auto_gchar gchar* cafile = cafile_get_name();
|
||||
@@ -304,21 +288,22 @@ http_file_put(void* userdata)
|
||||
if (!err_msg) {
|
||||
err_msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry(upload->window, upload->put_url, err_msg, THEME_ERROR, ENTRY_ERROR);
|
||||
} else {
|
||||
err_msg = g_strdup_printf("Uploading '%s' failed: %s", upload->filename, err);
|
||||
if (!err_msg) {
|
||||
err_msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, err_msg);
|
||||
win_update_entry(upload->window, upload->put_url, err_msg, THEME_ERROR, ENTRY_ERROR);
|
||||
}
|
||||
cons_show_error("%s", err_msg);
|
||||
} else {
|
||||
if (!upload->cancel) {
|
||||
auto_gchar gchar* status_msg = g_strdup_printf("Uploading '%s': 100%%", upload->filename);
|
||||
auto_gchar gchar* status_msg = g_strdup_printf("Uploading '%s': done", upload->filename);
|
||||
if (!status_msg) {
|
||||
status_msg = g_strdup(FALLBACK_MSG);
|
||||
}
|
||||
win_update_entry_message(upload->window, upload->put_url, status_msg);
|
||||
win_update_entry(upload->window, upload->put_url, status_msg, THEME_ONLINE, ENTRY_COMPLETED);
|
||||
win_mark_received(upload->window, upload->put_url);
|
||||
|
||||
char* url = NULL;
|
||||
|
||||
@@ -4,33 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_HTTP_UPLOAD_H
|
||||
|
||||
@@ -4,33 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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 "config.h"
|
||||
@@ -58,8 +32,7 @@ _parse_args_helper(const char* const inp, int min, int max, gboolean* result, gb
|
||||
gboolean in_token = FALSE;
|
||||
gboolean in_freetext = FALSE;
|
||||
gboolean in_quotes = FALSE;
|
||||
char* token_start = ©[0];
|
||||
int token_size = 0;
|
||||
GString* current_token = g_string_new("");
|
||||
int num_tokens = 0;
|
||||
GSList* tokens = NULL;
|
||||
|
||||
@@ -68,6 +41,23 @@ _parse_args_helper(const char* const inp, int min, int max, gboolean* result, gb
|
||||
gchar* curr_ch = g_utf8_offset_to_pointer(copy, i);
|
||||
gunichar curr_uni = g_utf8_get_char(curr_ch);
|
||||
|
||||
if (curr_uni == '\\' && (i + 1 < inp_size)) {
|
||||
if (!in_token) {
|
||||
in_token = TRUE;
|
||||
if (with_freetext) {
|
||||
num_tokens++;
|
||||
}
|
||||
if (with_freetext && (num_tokens == max + 1)) {
|
||||
in_freetext = TRUE;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
gchar* next_ch = g_utf8_offset_to_pointer(copy, i);
|
||||
gunichar next_uni = g_utf8_get_char(next_ch);
|
||||
g_string_append_unichar(current_token, next_uni);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!in_token) {
|
||||
if (curr_uni == ' ') {
|
||||
continue;
|
||||
@@ -81,58 +71,61 @@ _parse_args_helper(const char* const inp, int min, int max, gboolean* result, gb
|
||||
} else if (curr_uni == '"') {
|
||||
in_quotes = TRUE;
|
||||
i++;
|
||||
gchar* next_ch = g_utf8_next_char(curr_ch);
|
||||
gunichar next_uni = g_utf8_get_char(next_ch);
|
||||
if (i < inp_size) {
|
||||
gchar* next_ch = g_utf8_offset_to_pointer(copy, i);
|
||||
gunichar next_uni = g_utf8_get_char(next_ch);
|
||||
|
||||
if (next_uni == '"') {
|
||||
tokens = g_slist_append(tokens, g_strndup(curr_ch,
|
||||
0));
|
||||
token_size = 0;
|
||||
if (next_uni == '"') {
|
||||
tokens = g_slist_append(tokens, g_strdup(""));
|
||||
in_token = FALSE;
|
||||
in_quotes = FALSE;
|
||||
} else if (next_uni == '\\' && (i + 1 < inp_size)) {
|
||||
i++;
|
||||
gchar* escaped_ch = g_utf8_offset_to_pointer(copy, i);
|
||||
gunichar escaped_uni = g_utf8_get_char(escaped_ch);
|
||||
g_string_append_unichar(current_token, escaped_uni);
|
||||
} else {
|
||||
g_string_append_unichar(current_token, next_uni);
|
||||
}
|
||||
} else {
|
||||
// trailing quote
|
||||
tokens = g_slist_append(tokens, g_strdup(""));
|
||||
in_token = FALSE;
|
||||
in_quotes = FALSE;
|
||||
} else {
|
||||
token_start = next_ch;
|
||||
token_size += g_unichar_to_utf8(next_uni, NULL);
|
||||
}
|
||||
}
|
||||
if (curr_uni == '"') {
|
||||
gchar* next_ch = g_utf8_next_char(curr_ch);
|
||||
token_start = next_ch;
|
||||
} else {
|
||||
token_start = curr_ch;
|
||||
token_size += g_unichar_to_utf8(curr_uni, NULL);
|
||||
if (in_token && curr_uni != '"') {
|
||||
g_string_append_unichar(current_token, curr_uni);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (in_quotes) {
|
||||
if (curr_uni == '"') {
|
||||
tokens = g_slist_append(tokens, g_strndup(token_start,
|
||||
token_size));
|
||||
token_size = 0;
|
||||
tokens = g_slist_append(tokens, g_string_free(current_token, FALSE));
|
||||
current_token = g_string_new("");
|
||||
in_token = FALSE;
|
||||
in_quotes = FALSE;
|
||||
} else {
|
||||
if (curr_uni != '"') {
|
||||
token_size += g_unichar_to_utf8(curr_uni, NULL);
|
||||
}
|
||||
g_string_append_unichar(current_token, curr_uni);
|
||||
}
|
||||
} else {
|
||||
if (with_freetext && in_freetext) {
|
||||
token_size += g_unichar_to_utf8(curr_uni, NULL);
|
||||
g_string_append_unichar(current_token, curr_uni);
|
||||
} else if (curr_uni == ' ') {
|
||||
tokens = g_slist_append(tokens, g_strndup(token_start,
|
||||
token_size));
|
||||
token_size = 0;
|
||||
tokens = g_slist_append(tokens, g_string_free(current_token, FALSE));
|
||||
current_token = g_string_new("");
|
||||
in_token = FALSE;
|
||||
} else {
|
||||
token_size += g_unichar_to_utf8(curr_uni, NULL);
|
||||
g_string_append_unichar(current_token, curr_uni);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (in_token) {
|
||||
tokens = g_slist_append(tokens, g_strndup(token_start, token_size));
|
||||
tokens = g_slist_append(tokens, g_string_free(current_token, FALSE));
|
||||
} else {
|
||||
g_string_free(current_token, TRUE);
|
||||
}
|
||||
|
||||
int num = g_slist_length(tokens) - 1;
|
||||
@@ -271,9 +264,23 @@ count_tokens(const char* const string)
|
||||
gchar* curr_ch = g_utf8_offset_to_pointer(string, i);
|
||||
gunichar curr_uni = g_utf8_get_char(curr_ch);
|
||||
|
||||
if (curr_uni == '\\' && (i + 1 < length)) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (curr_uni == ' ') {
|
||||
if (!in_quotes) {
|
||||
num_tokens++;
|
||||
while (i + 1 < length) {
|
||||
gchar* next_ch = g_utf8_offset_to_pointer(string, i + 1);
|
||||
gunichar next_uni = g_utf8_get_char(next_ch);
|
||||
if (next_uni == ' ') {
|
||||
i++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (curr_uni == '"') {
|
||||
if (in_quotes) {
|
||||
@@ -302,15 +309,37 @@ get_start(const char* const string, int tokens)
|
||||
gchar* curr_ch = g_utf8_offset_to_pointer(string, i);
|
||||
gunichar curr_uni = g_utf8_get_char(curr_ch);
|
||||
|
||||
if (curr_uni == '\\' && (i + 1 < length)) {
|
||||
if (num_tokens < tokens) {
|
||||
g_string_append_unichar(result, curr_uni);
|
||||
}
|
||||
i++;
|
||||
curr_ch = g_utf8_offset_to_pointer(string, i);
|
||||
curr_uni = g_utf8_get_char(curr_ch);
|
||||
if (num_tokens < tokens) {
|
||||
g_string_append_unichar(result, curr_uni);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (num_tokens < tokens) {
|
||||
auto_gchar gchar* uni_char = g_malloc(7);
|
||||
int len = g_unichar_to_utf8(curr_uni, uni_char);
|
||||
uni_char[len] = '\0';
|
||||
g_string_append(result, uni_char);
|
||||
g_string_append_unichar(result, curr_uni);
|
||||
}
|
||||
if (curr_uni == ' ') {
|
||||
if (!in_quotes) {
|
||||
num_tokens++;
|
||||
while (i + 1 < length) {
|
||||
gchar* next_ch = g_utf8_offset_to_pointer(string, i + 1);
|
||||
gunichar next_uni = g_utf8_get_char(next_ch);
|
||||
if (next_uni == ' ') {
|
||||
if (num_tokens <= tokens) {
|
||||
g_string_append_unichar(result, next_uni);
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (curr_uni == '"') {
|
||||
if (in_quotes) {
|
||||
@@ -328,7 +357,7 @@ GHashTable*
|
||||
parse_options(gchar** args, gchar** opt_keys, gboolean* res)
|
||||
{
|
||||
GList* keys = NULL;
|
||||
for (int i = 0; i < g_strv_length(opt_keys); i++) {
|
||||
for (guint i = 0; i < g_strv_length(opt_keys); i++) {
|
||||
keys = g_list_append(keys, opt_keys[i]);
|
||||
}
|
||||
|
||||
@@ -344,7 +373,7 @@ parse_options(gchar** args, gchar** opt_keys, gboolean* res)
|
||||
|
||||
// validate options
|
||||
GList* found_keys = NULL;
|
||||
for (int curr = 0; curr < g_strv_length(args); curr += 2) {
|
||||
for (guint curr = 0; curr < g_strv_length(args); curr += 2) {
|
||||
// check if option valid
|
||||
if (g_list_find_custom(keys, args[curr], (GCompareFunc)g_strcmp0) == NULL) {
|
||||
*res = FALSE;
|
||||
@@ -377,7 +406,7 @@ parse_options(gchar** args, gchar** opt_keys, gboolean* res)
|
||||
// create map
|
||||
options = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
*res = TRUE;
|
||||
for (int curr = 0; curr < g_strv_length(args); curr += 2) {
|
||||
for (guint curr = 0; curr < g_strv_length(args); curr += 2) {
|
||||
g_hash_table_insert(options, args[curr], args[curr + 1]);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,33 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_PARSER_H
|
||||
|
||||
@@ -3,35 +3,9 @@
|
||||
* vim: expandtab:ts=4:sts=4:sw=4
|
||||
*
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
* Copyright (C) 2019 - 2025 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 2019 - 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@@ -3,35 +3,9 @@
|
||||
* vim: expandtab:ts=4:sts=4:sw=4
|
||||
*
|
||||
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
||||
* Copyright (C) 2019 - 2025 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 2019 - 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_PLUGIN_DOWNLOAD_H
|
||||
|
||||
132
src/tools/spellcheck.c
Normal file
132
src/tools/spellcheck.c
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* spellcheck.c
|
||||
* vim: expandtab:ts=4:sts=4:sw=4
|
||||
*
|
||||
* Copyright (C) 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_SPELLCHECK
|
||||
|
||||
#include <enchant.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "tools/spellcheck.h"
|
||||
#include "config/preferences.h"
|
||||
#include "log.h"
|
||||
#include "common.h"
|
||||
|
||||
static EnchantBroker* broker = NULL;
|
||||
static EnchantDict* dict = NULL;
|
||||
static char* current_lang = NULL;
|
||||
|
||||
void
|
||||
spellcheck_init(void)
|
||||
{
|
||||
if (broker) {
|
||||
return;
|
||||
}
|
||||
|
||||
broker = enchant_broker_init();
|
||||
if (!broker) {
|
||||
log_error("Failed to initialize Enchant broker");
|
||||
return;
|
||||
}
|
||||
|
||||
prof_add_shutdown_routine(spellcheck_deinit);
|
||||
|
||||
char* lang = prefs_get_string(PREF_SPELLCHECK_LANG);
|
||||
spellcheck_set_lang(lang);
|
||||
g_free(lang);
|
||||
}
|
||||
|
||||
void
|
||||
spellcheck_deinit(void)
|
||||
{
|
||||
if (dict) {
|
||||
enchant_broker_free_dict(broker, dict);
|
||||
dict = NULL;
|
||||
}
|
||||
if (broker) {
|
||||
enchant_broker_free(broker);
|
||||
broker = NULL;
|
||||
}
|
||||
g_free(current_lang);
|
||||
current_lang = NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
spellcheck_set_lang(const char* lang)
|
||||
{
|
||||
if (!broker || !lang) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (current_lang && strcmp(current_lang, lang) == 0 && dict) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
EnchantDict* new_dict = enchant_broker_request_dict(broker, lang);
|
||||
if (!new_dict) {
|
||||
log_error("Failed to request Enchant dictionary for language: %s", lang);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (dict) {
|
||||
enchant_broker_free_dict(broker, dict);
|
||||
}
|
||||
|
||||
dict = new_dict;
|
||||
g_free(current_lang);
|
||||
current_lang = g_strdup(lang);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const char*
|
||||
spellcheck_get_lang(void)
|
||||
{
|
||||
return current_lang;
|
||||
}
|
||||
|
||||
static void
|
||||
_list_dicts_cb(const char* const lang_tag,
|
||||
const char* const provider_name,
|
||||
const char* const provider_desc,
|
||||
const char* const provider_file,
|
||||
void* user_data)
|
||||
{
|
||||
GList** list = (GList**)user_data;
|
||||
if (g_list_find_custom(*list, lang_tag, (GCompareFunc)g_strcmp0) == NULL) {
|
||||
*list = g_list_append(*list, g_strdup(lang_tag));
|
||||
}
|
||||
}
|
||||
|
||||
GList*
|
||||
spellcheck_get_available_langs(void)
|
||||
{
|
||||
if (!broker) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GList* list = NULL;
|
||||
enchant_broker_list_dicts(broker, _list_dicts_cb, &list);
|
||||
return g_list_sort(list, (GCompareFunc)g_strcmp0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
spellcheck_is_misspelled(const char* word)
|
||||
{
|
||||
if (!dict || !word || word[0] == '\0') {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int result = enchant_dict_check(dict, word, strlen(word));
|
||||
return (result != 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
58
src/tools/spellcheck.h
Normal file
58
src/tools/spellcheck.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* spellcheck.h
|
||||
* vim: expandtab:ts=4:sts=4:sw=4
|
||||
*
|
||||
* Copyright (C) 2026 Michael Vetter <jubalh@iodoru.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#ifndef TOOLS_SPELLCHECK_H
|
||||
#define TOOLS_SPELLCHECK_H
|
||||
|
||||
#include "config.h"
|
||||
#include <glib.h>
|
||||
|
||||
#ifdef HAVE_SPELLCHECK
|
||||
|
||||
void spellcheck_init(void);
|
||||
void spellcheck_deinit(void);
|
||||
gboolean spellcheck_is_misspelled(const char* word);
|
||||
gboolean spellcheck_set_lang(const char* lang);
|
||||
const char* spellcheck_get_lang(void);
|
||||
GList* spellcheck_get_available_langs(void);
|
||||
|
||||
#else
|
||||
|
||||
static inline void
|
||||
spellcheck_init(void)
|
||||
{
|
||||
}
|
||||
static inline void
|
||||
spellcheck_deinit(void)
|
||||
{
|
||||
}
|
||||
static inline gboolean
|
||||
spellcheck_is_misspelled(const char* word)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
static inline gboolean
|
||||
spellcheck_set_lang(const char* lang)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
static inline const char*
|
||||
spellcheck_get_lang(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
static inline GList*
|
||||
spellcheck_get_available_langs(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user