merge: sync upstream profanity-im/profanity
All checks were successful
CI Code / Check spelling (push) Successful in 18s
CI Code / Check coding style (push) Successful in 34s
CI Code / Code Coverage (push) Successful in 2m36s
CI Code / Linux (debian) (push) Successful in 4m41s
CI Code / Linux (ubuntu) (push) Successful in 4m52s
CI Code / Linux (arch) (push) Successful in 5m40s

Sync with upstream profanity-im/profanity.

Major upstream changes incorporated:

Memory management
  - Replace malloc+memset with g_new0 throughout codebase
  - Adopt auto_gchar / auto_gcharv / auto_gerror / auto_jid cleanup macros
  - Replace free() with g_free() for GAlloc'd memory

Editor rewrite
  - Remove pthread-based async editor; use GChildWatch callback API
  - New launch_editor(initial_content, callback, user_data) interface
  - Proper signal handling (SIGINT, SIGTSTP, SIGPIPE reset in child)
  - ui_suspend()/ui_resume() integration for TTY management

OMEMO improvements
  - Dual backend support: libsignal-protocol-c and libomemo-c
  - Proper pre-key removal after use (XEP-0384 compliance)
  - Automatic pre-key regeneration when store drops below threshold
  - New functions: omemo_is_device_active(), omemo_is_jid_trusted()
  - omemo_get_jid_untrusted_fingerprints() for better error messages
  - Fingerprint notifications on new device identity discovery
  - Deterministic pre-key ID generation tracking max_pre_key_id
  - omemo_trust_changed() UI updates on trust state changes

JID validation
  - RFC 6122-compliant validation in jid_is_valid()
  - Character-level checks (RFC 6122 forbidden chars: & ' / : < > @)
  - Length limits: 1023 per component, 3071 total
  - New jid_is_valid_user_jid() for user vs. service JID distinction

Database
  - Schema migration v3: UNIQUE constraint on archive_id for deduplication
  - Triggers for corrected message tracking (replaces_db_id / replaced_by_db_id)
  - db_history_result_t return type, _truncate_datetime_suffix()

UI / console
  - win_warn_needed() / win_warn_sent() warning deduplication hash table
  - PAD_MIN_HEIGHT dynamic pad sizing with PAD_THRESHOLD auto-cleanup
  - Spellcheck integration in input field with Unicode word detection
  - cons_spellcheck_setting() for /settings ui output
  - /[command]? shortcut for command help

Account config
  - Account name sanitization for GKeyFile special chars ([ ] = # \n \r)
  - Replace popen() with g_spawn_sync() for eval_password
  - TLS policy: add "direct" option alongside legacy

Connection
  - Port validation with g_assert (0–65535)
  - SHA-256 certificate fingerprint support (XMPP_CERT_PUBKEY_FINGERPRINT_SHA256)
  - "direct" TLS policy alias for legacy SSL

Common utilities
  - str_xml_sanitize() for XML 1.0 illegal character removal
  - string_matches_one_of() with formatted error messages
  - valid_tls_policy_option() helper
  - prof_date_time_format_iso8601() utility
  - Improved strip_arg_quotes() with backslash unescaping
  - prof_occurrences() uses g_slist_prepend + reverse for performance

PGP / OX
  - Proper GPGME resource cleanup with goto-cleanup pattern
  - g_string_free(xmppuri) leak fix in _ox_key_lookup

CSV export
  - Use GString + g_file_set_contents instead of raw write() syscalls

Tests
  - Restructured into subdirectories: command/, config/, xmpp/, ui/, omemo/, otr/, pgp/
  - New test_cmd_ac.c for autocompleter unit tests
  - Updated stubs for new UI suspend/resume functions

License headers
  - Migrate to SPDX-3.0 identifiers (GPL-3.0-or-later WITH OpenSSL-exception)

────────────────────────────────────────────────────
cproof-specific preservations:

  - XEP-0308 LMC: replace_id ?: id logic in message/stanza/omemo
  - Force encryption: cmd_force_encryption, test_forced_encryption
  - CWE-134: format string protection (cons_show("%s", ...))
  - y_start_pos-based paging in window.c
  - db_history_result_t return type, _truncate_datetime_suffix()

Merge-time fixes:

  - common.c: format-security (-Werror) — cons_show(errmsg) → cons_show("%s", errmsg)
  - database.c: null-deref guard — !msg->timestamp → msg && !msg->timestamp
  - console.c: implicit size_t → int cast — (int)(maxlen + 1)
  - tlscerts.c: %d for size_t — %zu

Build system:
  - Kept autotools (Makefile.am, configure.ac); upstream uses Meson
  - Restored deleted files: bootstrap.sh, autogen.sh, ax_valgrind_check.m4, configure-debug
  - Updated Makefile.am test paths for subdirectory structure
  - Added test_cmd_ac, test_forced_encryption to test sources

Functional tests:
  - Use cproof version; upstream requires stbbr_for_xmlns from updated stabber
  - Not yet available in devs/stabber fork

Closes #64

Merge author: jabber.developer2
Commits authors:
 Michael Vetter <jubalh@iodoru.org>
& Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
2026-05-26 17:48:14 +00:00
parent 3b673150b4
commit 72f4f186da
303 changed files with 10658 additions and 9857 deletions

View File

@@ -2,35 +2,9 @@
* avatar.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"
@@ -110,11 +84,11 @@ avatar_set(const char* path)
{
auto_char char* expanded_path = get_expanded_path(path);
GError* err = NULL;
auto_gerror GError* err = NULL;
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(expanded_path, &err);
if (pixbuf == NULL) {
cons_show_error("An error occurred while opening %s: %s.", expanded_path, err ? err->message : "No error message given");
cons_show_error("An error occurred while opening %s: %s.", expanded_path, PROF_GERROR_MESSAGE(err));
return FALSE;
}
@@ -123,12 +97,12 @@ avatar_set(const char* path)
int h = gdk_pixbuf_get_height(pixbuf);
if (w >= h && w > MAX_PIXEL) {
int dest_height = (int)((float)MAX_PIXEL / w * h);
int dest_height = (int)((float)MAX_PIXEL / (float)w * (float)h);
GdkPixbuf* new_pixbuf = gdk_pixbuf_scale_simple(pixbuf, MAX_PIXEL, dest_height, GDK_INTERP_BILINEAR);
g_object_unref(pixbuf);
pixbuf = new_pixbuf;
} else if (h > w && w > MAX_PIXEL) {
int dest_width = (int)((float)MAX_PIXEL / h * w);
int dest_width = (int)((float)MAX_PIXEL / (float)h * (float)w);
GdkPixbuf* new_pixbuf = gdk_pixbuf_scale_simple(pixbuf, dest_width, MAX_PIXEL, GDK_INTERP_BILINEAR);
g_object_unref(pixbuf);
pixbuf = new_pixbuf;
@@ -138,7 +112,7 @@ avatar_set(const char* path)
gsize len = -1;
if (!gdk_pixbuf_save_to_buffer(pixbuf, &img_data, &len, "png", &err, NULL)) {
cons_show_error("Unable to scale and convert avatar.");
cons_show_error("Unable to scale and convert avatar: %s.", PROF_GERROR_MESSAGE(err));
return FALSE;
}
@@ -232,7 +206,7 @@ _avatar_metadata_handler(xmpp_stanza_t* const stanza, void* const userdata)
if (id && type) {
log_debug("Avatar ID for %s is: %s", from, id);
avatar_metadata* data = malloc(sizeof(avatar_metadata));
avatar_metadata* data = g_new0(avatar_metadata, 1);
if (data) {
data->type = strdup(type);
data->id = strdup(id);
@@ -342,11 +316,10 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use
g_string_append(filename, ".webp");
}
GError* err = NULL;
auto_gerror GError* err = NULL;
if (g_file_set_contents(filename->str, de, size, &err) == FALSE) {
log_error("Unable to save picture: %s", err->message);
cons_show("Unable to save picture %s", err->message);
g_error_free(err);
} else {
cons_show("Avatar saved as %s", filename->str);
}

View File

@@ -2,35 +2,9 @@
* avatar.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 XMPP_AVATAR_H

View File

@@ -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"
@@ -142,9 +116,26 @@ blocked_add(char* jid, blocked_report reportkind, const char* const message)
xmpp_stanza_set_attribute(report, STANZA_ATTR_REASON, STANZA_REPORTING_SPAM);
}
xmpp_stanza_t* origin = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(origin, STANZA_NAME_REPORT_ORIGIN);
xmpp_stanza_set_attribute(origin, STANZA_ATTR_JID, connection_get_fulljid());
xmpp_stanza_add_child(report, origin);
xmpp_stanza_release(origin);
xmpp_stanza_t* third_party = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(third_party, STANZA_NAME_THIRD_PARTY);
xmpp_stanza_set_attribute(third_party, STANZA_ATTR_JID, jid);
xmpp_stanza_add_child(report, third_party);
xmpp_stanza_release(third_party);
if (message) {
xmpp_stanza_t* text = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(text, STANZA_NAME_TEXT);
if (reportkind == BLOCKED_REPORT_SPAM) {
xmpp_stanza_set_name(text, STANZA_NAME_BODY);
xmpp_stanza_set_ns(text, "jabber:client");
} else {
xmpp_stanza_set_name(text, STANZA_NAME_TEXT);
}
xmpp_stanza_t* txt = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(txt, message);
@@ -340,3 +331,83 @@ _blocklist_result_handler(xmpp_stanza_t* const stanza, void* const userdata)
return 0;
}
int
reporting_set_handler(xmpp_stanza_t* stanza)
{
const char* from = xmpp_stanza_get_from(stanza);
xmpp_stanza_t* report = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_REPORTING);
if (!report) {
return 1;
}
const char* reason = xmpp_stanza_get_attribute(report, STANZA_ATTR_REASON);
const char* display_reason = "unknown";
if (g_strcmp0(reason, STANZA_REPORTING_SPAM) == 0) {
display_reason = "spam";
} else if (g_strcmp0(reason, STANZA_REPORTING_ABUSE) == 0) {
display_reason = "abuse";
}
char* message = NULL;
xmpp_stanza_t* body = xmpp_stanza_get_child_by_name(report, STANZA_NAME_BODY);
if (body) {
message = xmpp_stanza_get_text(body);
} else {
xmpp_stanza_t* text = xmpp_stanza_get_child_by_name(report, STANZA_NAME_TEXT);
if (text) {
message = xmpp_stanza_get_text(text);
}
}
// Attempt to find the reported JID if it's wrapped in an item (sync push style)
const char* reported_jid = NULL;
xmpp_stanza_t* block = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_BLOCKING);
if (block) {
xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(block, STANZA_NAME_ITEM);
if (item) {
reported_jid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID);
}
}
xmpp_stanza_t* third_party = xmpp_stanza_get_child_by_name(report, STANZA_NAME_THIRD_PARTY);
if (third_party) {
reported_jid = xmpp_stanza_get_attribute(third_party, STANZA_ATTR_JID);
}
const char* reported_by = NULL;
xmpp_stanza_t* origin = xmpp_stanza_get_child_by_name(report, STANZA_NAME_REPORT_ORIGIN);
if (origin) {
reported_by = xmpp_stanza_get_attribute(origin, STANZA_ATTR_JID);
}
auto_gchar gchar* report_origin_str = NULL;
if (reported_by) {
report_origin_str = g_strdup_printf(" (origin: %s)", reported_by);
} else {
report_origin_str = g_strdup("");
}
if (reported_jid) {
if (message) {
cons_show("Incoming %s report%s from %s: User %s reported for %s. Content: \"%s\"",
display_reason, report_origin_str, from, reported_jid, display_reason, message);
} else {
cons_show("Incoming %s report%s from %s: User %s reported for %s.",
display_reason, report_origin_str, from, reported_jid, display_reason);
}
} else {
if (message) {
cons_show("Incoming %s report%s from %s. Content: \"%s\"",
display_reason, report_origin_str, from, message);
} else {
cons_show("Incoming %s report%s from %s.", display_reason, report_origin_str, from);
}
}
if (message) {
xmpp_free(xmpp_stanza_get_context(stanza), message);
}
return 1;
}

View File

@@ -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 XMPP_BLOCKING_H
@@ -38,5 +12,6 @@
void blocking_request(void);
int blocked_set_handler(xmpp_stanza_t* stanza);
int reporting_set_handler(xmpp_stanza_t* stanza);
#endif

View File

@@ -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"
@@ -112,7 +86,7 @@ bookmark_add(const char* jid, const char* nick, const char* password, const char
return FALSE;
}
Bookmark* bookmark = malloc(sizeof(Bookmark));
Bookmark* bookmark = g_new0(Bookmark, 1);
bookmark->barejid = strdup(jid);
if (nick) {
bookmark->nick = strdup(nick);
@@ -329,7 +303,7 @@ _bookmark_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
}
autocomplete_add(bookmark_ac, barejid);
Bookmark* bookmark = malloc(sizeof(Bookmark));
Bookmark* bookmark = g_new0(Bookmark, 1);
bookmark->barejid = strdup(barejid);
bookmark->nick = nick;
bookmark->password = password;

View File

@@ -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 XMPP_BOOKMARK_H

View File

@@ -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"
@@ -196,10 +170,10 @@ caps_create(const char* const category, const char* const type, const char* cons
const char* const os, const char* const os_version,
GSList* features)
{
EntityCapabilities* result = (EntityCapabilities*)malloc(sizeof(EntityCapabilities));
EntityCapabilities* result = g_new0(EntityCapabilities, 1);
if (category || type || name) {
DiscoIdentity* identity = (DiscoIdentity*)malloc(sizeof(DiscoIdentity));
DiscoIdentity* identity = g_new0(DiscoIdentity, 1);
identity->category = category ? strdup(category) : NULL;
identity->type = type ? strdup(type) : NULL;
identity->name = name ? strdup(name) : NULL;
@@ -209,7 +183,7 @@ caps_create(const char* const category, const char* const type, const char* cons
}
if (software || software_version || os || os_version) {
SoftwareVersion* software_versionp = (SoftwareVersion*)malloc(sizeof(SoftwareVersion));
SoftwareVersion* software_versionp = g_new0(SoftwareVersion, 1);
software_versionp->software = software ? strdup(software) : NULL;
software_versionp->software_version = software_version ? strdup(software_version) : NULL;
software_versionp->os = os ? strdup(os) : NULL;
@@ -383,7 +357,7 @@ _caps_by_ver(const char* const ver)
auto_gcharv gchar** features_list = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL);
GSList* features = NULL;
if (features_list && features_len > 0) {
for (int i = 0; i < features_len; i++) {
for (gsize i = 0; i < features_len; i++) {
features = g_slist_append(features, features_list[i]);
}
}

View File

@@ -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 XMPP_CAPABILITIES_H

View File

@@ -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"
@@ -56,7 +30,7 @@ _chat_session_new(const char* const barejid, const char* const resource, gboolea
assert(barejid != NULL);
assert(resource != NULL);
ChatSession* new_session = calloc(1, sizeof(*new_session));
ChatSession* new_session = g_new0(ChatSession, 1);
new_session->barejid = strdup(barejid);
new_session->resource = strdup(resource);
new_session->resource_override = resource_override;

View File

@@ -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 XMPP_CHAT_SESSION_H

View File

@@ -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"
@@ -55,7 +29,7 @@ static void _send_if_supported(const char* const barejid, void (*send_func)(cons
ChatState*
chat_state_new(void)
{
ChatState* new_state = malloc(sizeof(struct prof_chat_state_t));
ChatState* new_state = g_new0(struct prof_chat_state_t, 1);
new_state->type = CHAT_STATE_GONE;
new_state->timer = g_timer_new();

View File

@@ -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 XMPP_CHAT_STATE_H

View File

@@ -3,35 +3,9 @@
* vim: expandtab:ts=4:sts=4:sw=4
*
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
* Copyright (C) 2018 - 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) 2018 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
*/
#include "config.h"
@@ -215,7 +189,7 @@ _conn_apply_settings(const char* const jid, const char* const passwd, const char
flags |= XMPP_CONN_FLAG_TRUST_TLS;
} else if (g_strcmp0(tls_policy, "disable") == 0) {
flags |= XMPP_CONN_FLAG_DISABLE_TLS;
} else if (g_strcmp0(tls_policy, "legacy") == 0) {
} else if (g_strcmp0(tls_policy, "direct") == 0 || g_strcmp0(tls_policy, "legacy") == 0) {
flags |= XMPP_CONN_FLAG_LEGACY_SSL;
}
@@ -244,7 +218,7 @@ _conn_apply_settings(const char* const jid, const char* const passwd, const char
return FALSE;
}
auto_char char* cert_path = prefs_get_tls_certpath();
auto_gchar gchar* cert_path = prefs_get_tls_certpath();
if (cert_path) {
xmpp_conn_set_capath(conn.xmpp_conn, cert_path);
}
@@ -271,10 +245,13 @@ connection_connect(const char* const jid, const char* const passwd, const char*
_conn_apply_settings(jid, passwd, tls_policy, auth_policy);
// TCP ports are 16-bit; the account-layer validator must enforce this
// range before we reach libstrophe.
g_assert(port >= 0 && port <= UINT16_MAX);
int connect_status = xmpp_connect_client(
conn.xmpp_conn,
altdomain,
port,
(unsigned short)port,
_connection_handler,
conn.xmpp_ctx);
@@ -529,10 +506,11 @@ connection_register(const char* const altdomain, int port, const char* const tls
reg->username = strdup(username);
reg->password = strdup(password);
g_assert(port >= 0 && port <= UINT16_MAX);
int connect_status = xmpp_connect_raw(
conn.xmpp_conn,
altdomain,
port,
(unsigned short)port,
_register_handler,
reg);
@@ -824,10 +802,10 @@ connection_free_uuid(char* uuid)
}
}
char*
gchar*
connection_create_stanza_id(void)
{
auto_char char* rndid = get_random_string(CON_RAND_ID_LEN);
auto_gchar gchar* rndid = get_random_string(CON_RAND_ID_LEN);
assert(rndid != NULL);
auto_gchar gchar* hmac = g_compute_hmac_for_string(G_CHECKSUM_SHA1,
@@ -1025,8 +1003,12 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
conn.sm_state = xmpp_conn_get_sm_state(conn.xmpp_conn);
if (send_queue_len > 0 && prefs_get_boolean(PREF_STROPHE_SM_RESEND)) {
conn.queued_messages = calloc(send_queue_len + 1, sizeof(*conn.queued_messages));
for (int n = 0; n < send_queue_len; ++n) {
conn.queued_messages[n] = xmpp_conn_send_queue_drop_element(conn.xmpp_conn, XMPP_QUEUE_OLDEST);
if (conn.queued_messages == NULL) {
log_error("Failed to allocate memory for queued messages during disconnection.");
} else {
for (int n = 0; n < send_queue_len; ++n) {
conn.queued_messages[n] = xmpp_conn_send_queue_drop_element(conn.xmpp_conn, XMPP_QUEUE_OLDEST);
}
}
} else if (send_queue_len > 0) {
log_debug("Connection handler: dropping those messages since SM RESEND is disabled");
@@ -1040,7 +1022,8 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
gchar* host;
int port;
if (stream_error && stream_error->stanza && _get_other_host(stream_error->stanza, &host, &port)) {
session_reconnect(host, port);
g_assert(port >= 0 && port <= UINT16_MAX);
session_reconnect(host, (unsigned short)port);
log_debug("Connection handler: Forcing a re-connect to \"%s\"", host);
conn.conn_status = JABBER_RECONNECT;
return;
@@ -1080,6 +1063,10 @@ _connection_certfail_cb(const xmpp_tlscert_t* xmpptlscert, const char* errormsg)
TLSCertificate*
_xmppcert_to_profcert(const xmpp_tlscert_t* xmpptlscert)
{
const char* pubkey_fp = NULL;
#ifdef HAVE_XMPP_CERT_PUBKEY_FINGERPRINT_SHA256
pubkey_fp = xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_PUBKEY_FINGERPRINT_SHA256);
#endif
int version = (int)strtol(
xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_VERSION), NULL, 10);
return tlscerts_new(
@@ -1092,7 +1079,9 @@ _xmppcert_to_profcert(const xmpp_tlscert_t* xmpptlscert)
xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_NOTAFTER),
xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_KEYALG),
xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_SIGALG),
xmpp_tlscert_get_pem(xmpptlscert));
xmpp_tlscert_get_pem(xmpptlscert),
xmpp_tlscert_get_string(xmpptlscert, XMPP_CERT_FINGERPRINT_SHA256),
pubkey_fp);
}
static void

View File

@@ -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 XMPP_CONNECTION_H

View File

@@ -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"
@@ -66,7 +40,7 @@ p_contact_new(const char* const barejid, const char* const name,
GSList* groups, const char* const subscription,
const char* const offline_message, gboolean pending_out)
{
PContact contact = malloc(sizeof(struct p_contact_t));
PContact contact = g_new0(struct p_contact_t, 1);
contact->barejid = strdup(barejid);
contact->barejid_collate_key = g_utf8_collate_key(contact->barejid, -1);

View File

@@ -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 XMPP_CONTACT_H

View File

@@ -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"
@@ -74,7 +48,7 @@ _is_valid_form_element(xmpp_stanza_t* stanza)
static DataForm*
_form_new(void)
{
DataForm* form = calloc(1, sizeof(DataForm));
DataForm* form = g_new0(DataForm, 1);
return form;
}
@@ -82,7 +56,7 @@ _form_new(void)
static FormField*
_field_new(void)
{
FormField* field = calloc(1, sizeof(FormField));
FormField* field = g_new0(FormField, 1);
return field;
}
@@ -237,7 +211,7 @@ form_create(xmpp_stanza_t* const form_stanza)
// handle options
} else if (g_strcmp0(child_name, "option") == 0) {
FormOption* option = malloc(sizeof(FormOption));
FormOption* option = g_new0(FormOption, 1);
option->label = _get_attr(field_child, "label");
option->value = _get_property(field_child, "value");
@@ -466,16 +440,13 @@ form_set_value(DataForm* form, const char* const tag, const char* value)
while (curr) {
FormField* field = curr->data;
if (g_strcmp0(field->var, var) == 0) {
if (g_slist_length(field->values) == 0) {
field->values = g_slist_append(field->values, strdup(value));
form->modified = TRUE;
return;
} else if (g_slist_length(field->values) == 1) {
free(field->values->data);
field->values->data = strdup(value);
form->modified = TRUE;
return;
if (field->values) {
g_slist_free_full(field->values, free);
field->values = NULL;
}
field->values = g_slist_append(NULL, strdup(value));
form->modified = TRUE;
return;
}
curr = g_slist_next(curr);
}

View File

@@ -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 XMPP_FORM_H

View File

@@ -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"
@@ -234,6 +208,11 @@ _iq_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const us
blocked_set_handler(stanza);
}
xmpp_stanza_t* reporting = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_REPORTING);
if (reporting && (g_strcmp0(type, STANZA_TYPE_SET) == 0)) {
reporting_set_handler(stanza);
}
const char* id = xmpp_stanza_get_id(stanza);
if (id) {
ProfIqHandler* handler = g_hash_table_lookup(id_handlers, id);
@@ -248,6 +227,12 @@ _iq_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const us
return 1;
}
static void
_xmpp_stanza_release_destroy_notify(gpointer data)
{
xmpp_stanza_release((xmpp_stanza_t*)data);
}
void
iq_handlers_init(void)
{
@@ -264,7 +249,7 @@ iq_handlers_init(void)
iq_handlers_clear();
id_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_iq_id_handler_free);
rooms_cache = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)xmpp_stanza_release);
rooms_cache = g_hash_table_new_full(g_str_hash, g_str_equal, free, _xmpp_stanza_release_destroy_notify);
}
struct iq_win_finder
@@ -302,7 +287,7 @@ _free_late_delivery_userdata(LateDeliveryUserdata* d)
void
iq_handlers_remove_win(ProfWin* window)
{
log_debug("Remove window %p of type %d", window, window ? window->type : -1);
log_debug("Remove window %p of type %d", window, window ? window->type : (win_type_t)-1);
if (!window)
return;
GSList *cur = late_delivery_windows, *next;
@@ -358,14 +343,19 @@ _iq_id_handler_free(ProfIqHandler* handler)
void
iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata)
{
ProfIqHandler* handler = malloc(sizeof(ProfIqHandler));
if (handler) {
handler->func = func;
handler->free_func = free_func;
handler->userdata = userdata;
g_hash_table_insert(id_handlers, strdup(id), handler);
if (id == NULL) {
if (free_func) {
free_func(userdata);
}
return;
}
ProfIqHandler* handler = g_new0(ProfIqHandler, 1);
handler->func = func;
handler->free_func = free_func;
handler->userdata = userdata;
g_hash_table_insert(id_handlers, strdup(id), handler);
}
void
@@ -394,7 +384,7 @@ iq_autoping_check(void)
}
gdouble elapsed = g_timer_elapsed(autoping_time, NULL);
unsigned long seconds_elapsed = elapsed * 1.0;
gint seconds_elapsed = (gint)elapsed;
gint timeout = prefs_get_autoping_timeout();
if (timeout > 0 && seconds_elapsed >= timeout) {
cons_show("Autoping response timed out after %u seconds.", timeout);
@@ -545,7 +535,7 @@ iq_room_info_request(const char* const room, gboolean display_result)
auto_char char* id = connection_create_stanza_id();
xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, id, room, NULL);
ProfRoomInfoData* cb_data = malloc(sizeof(ProfRoomInfoData));
ProfRoomInfoData* cb_data = g_new0(ProfRoomInfoData, 1);
if (cb_data) {
cb_data->room = strdup(room);
cb_data->display = display_result;
@@ -729,7 +719,7 @@ iq_room_affiliation_list(const char* const room, char* affiliation, bool show_ui
const char* id = xmpp_stanza_get_id(iq);
ProfAffiliationList* affiliation_list = malloc(sizeof(ProfAffiliationList));
ProfAffiliationList* affiliation_list = g_new0(ProfAffiliationList, 1);
if (affiliation_list) {
affiliation_list->affiliation = strdup(affiliation);
affiliation_list->show_ui_message = show_ui_message;
@@ -763,7 +753,7 @@ iq_room_affiliation_set(const char* const room, const char* const jid, char* aff
const char* id = xmpp_stanza_get_id(iq);
ProfPrivilegeSet* affiliation_set = malloc(sizeof(struct privilege_set_t));
ProfPrivilegeSet* affiliation_set = g_new0(struct privilege_set_t, 1);
if (affiliation_set) {
affiliation_set->item = strdup(jid);
affiliation_set->privilege = strdup(affiliation);
@@ -784,7 +774,7 @@ iq_room_role_set(const char* const room, const char* const nick, char* role,
const char* id = xmpp_stanza_get_id(iq);
struct privilege_set_t* role_set = malloc(sizeof(ProfPrivilegeSet));
struct privilege_set_t* role_set = g_new0(ProfPrivilegeSet, 1);
if (role_set) {
role_set->item = strdup(nick);
role_set->privilege = strdup(role);
@@ -1148,7 +1138,7 @@ _room_list_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
if (item_name) {
item_name_lower = g_utf8_strdown(item_name, -1);
}
if ((item_jid_lower) && ((glob == NULL) || ((g_pattern_match(glob, strlen(item_jid_lower), item_jid_lower, NULL)) || (item_name_lower && g_pattern_match(glob, strlen(item_name_lower), item_name_lower, NULL))))) {
if ((item_jid_lower) && ((glob == NULL) || ((g_pattern_match(glob, (guint)strlen(item_jid_lower), item_jid_lower, NULL)) || (item_name_lower && g_pattern_match(glob, (guint)strlen(item_name_lower), item_name_lower, NULL))))) {
if (glob) {
matched = TRUE;
@@ -1327,7 +1317,7 @@ _command_exec_response_handler(xmpp_stanza_t* const stanza, void* const userdata
const char* sessionid = xmpp_stanza_get_attribute(cmd, "sessionid");
DataForm* form = form_create(x);
CommandConfigData* data = malloc(sizeof(CommandConfigData));
CommandConfigData* data = g_new0(CommandConfigData, 1);
if (sessionid == NULL) {
data->sessionid = NULL;
} else {
@@ -1404,7 +1394,7 @@ _manual_pong_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
GDateTime* now = g_date_time_new_now_local();
GTimeSpan elapsed = g_date_time_difference(now, sent);
int elapsed_millis = elapsed / 1000;
int elapsed_millis = (int)(elapsed / 1000);
g_date_time_unref(now);
@@ -1791,7 +1781,7 @@ _last_activity_get_handler(xmpp_stanza_t* const stanza)
}
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
int idls_secs = ui_get_idle_time() / 1000;
int idls_secs = (int)(ui_get_idle_time() / 1000);
char str[50];
sprintf(str, "%d", idls_secs);
@@ -2211,7 +2201,7 @@ _room_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata
const char* category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY);
if (name || category || type) {
DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t));
DiscoIdentity* identity = g_new0(struct disco_identity_t, 1);
if (identity) {
if (name) {
@@ -2356,7 +2346,7 @@ _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdat
const char* category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY);
if (name || category || child_type) {
DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t));
DiscoIdentity* identity = g_new0(struct disco_identity_t, 1);
if (identity) {
if (name) {
@@ -2538,7 +2528,7 @@ _disco_items_result_handler(xmpp_stanza_t* const stanza)
if (stanza_name && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) {
const char* item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
if (item_jid) {
DiscoItem* item = malloc(sizeof(struct disco_item_t));
DiscoItem* item = g_new0(struct disco_item_t, 1);
if (item) {
item->jid = strdup(item_jid);
const char* item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
@@ -2649,10 +2639,13 @@ iq_mam_request_older(ProfChatWin* win)
auto_gchar gchar* enddate = NULL;
// If first message found
if (first_msg->timestamp) {
if (first_msg && first_msg->timestamp) {
firstid = first_msg->stanzaid;
enddate = g_date_time_format(first_msg->timestamp, mam_timestamp_format_string);
} else {
if (first_msg) {
message_free(first_msg);
}
return;
}
@@ -2686,8 +2679,10 @@ _iq_mam_request(ProfChatWin* win, GDateTime* startdate, GDateTime* enddate)
if (connection_supports(XMPP_FEATURE_MAM2) == FALSE) {
log_warning("Server doesn't advertise %s feature.", XMPP_FEATURE_MAM2);
cons_show_error("Server doesn't support MAM (%s).", XMPP_FEATURE_MAM2);
g_date_time_unref(startdate);
g_date_time_unref(enddate);
if (startdate)
g_date_time_unref(startdate);
if (enddate)
g_date_time_unref(enddate);
return;
}
@@ -2715,7 +2710,7 @@ _iq_mam_request(ProfChatWin* win, GDateTime* startdate, GDateTime* enddate)
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, win->barejid, startdate_str, enddate_str, firstid, NULL);
MamRsmUserdata* data = malloc(sizeof(MamRsmUserdata));
MamRsmUserdata* data = g_new0(MamRsmUserdata, 1);
if (data) {
data->start_datestr = startdate_str;
data->end_datestr = enddate_str;
@@ -2736,12 +2731,16 @@ void
iq_mam_request(ProfChatWin* win, GDateTime* enddate)
{
ProfMessage* last_msg = log_database_get_limits_info(win->barejid, TRUE);
GDateTime* startdate = g_date_time_ref(last_msg->timestamp);
message_free(last_msg);
GDateTime* startdate = NULL;
if (last_msg) {
if (last_msg->timestamp)
startdate = g_date_time_ref(last_msg->timestamp);
message_free(last_msg);
}
// Save request for later if disco items haven't been received yet
if (!received_disco_items) {
LateDeliveryUserdata* cur_del_data = malloc(sizeof(LateDeliveryUserdata));
LateDeliveryUserdata* cur_del_data = g_new0(LateDeliveryUserdata, 1);
cur_del_data->win = win;
cur_del_data->enddate = enddate;
cur_del_data->startdate = startdate;
@@ -2830,7 +2829,7 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
}
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, data->barejid, data->start_datestr, NULL, firstid, NULL);
MamRsmUserdata* ndata = malloc(sizeof(*ndata));
MamRsmUserdata* ndata = g_new0(MamRsmUserdata, 1);
*ndata = *data;
if (data->end_datestr)
ndata->end_datestr = strdup(data->end_datestr);

View File

@@ -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 XMPP_IQ_H

View File

@@ -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"
@@ -41,75 +15,163 @@
#include <glib.h>
#include "common.h"
#include "log.h"
#include "xmpp/jid.h"
#define JID_MAX_PART_LEN 1023
#define JID_MAX_TOTAL_LEN 3071
static gboolean
_is_invalid_local_char(gunichar c)
{
// RFC 6122: " & ' / : < > @
// Also space is forbidden.
return (c == ' ' || c == '"' || c == '&' || c == '\'' || c == '/' || c == ':' || c == '<' || c == '>' || c == '@');
}
Jid*
jid_create(const gchar* const str)
{
Jid* result = NULL;
if (!jid_is_valid(str)) {
log_debug("[JID] invalid JID: '%s'", str ?: "(null)");
return NULL;
}
/* if str is NULL g_strdup returns NULL */
gchar* trimmed = g_strdup(str);
if (trimmed == NULL) {
return NULL;
}
if (strlen(trimmed) == 0) {
g_free(trimmed);
return NULL;
}
if (g_str_has_prefix(trimmed, "/") || g_str_has_prefix(trimmed, "@")) {
g_free(trimmed);
return NULL;
}
if (!g_utf8_validate(trimmed, -1, NULL)) {
g_free(trimmed);
return NULL;
}
result = malloc(sizeof(struct jid_t));
result->str = NULL;
result->localpart = NULL;
result->domainpart = NULL;
result->resourcepart = NULL;
result->barejid = NULL;
result->fulljid = NULL;
Jid* result = g_new0(Jid, 1);
result->refcnt = 1;
result->str = trimmed;
gchar* atp = g_utf8_strchr(trimmed, -1, '@');
gchar* slashp = g_utf8_strchr(trimmed, -1, '/');
gchar* domain_start = trimmed;
auto_gchar gchar* bare = NULL;
if (slashp) {
if (strlen(slashp + 1) > 0) {
result->resourcepart = g_strdup(slashp + 1);
result->fulljid = g_strdup(trimmed);
}
bare = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, slashp));
} else {
bare = g_strdup(trimmed);
}
gchar* atp = g_utf8_strchr(bare, -1, '@');
gchar* domain_start = bare;
if (atp) {
result->localpart = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, atp));
if (g_utf8_pointer_to_offset(bare, atp) > 0) {
result->localpart = g_utf8_substring(bare, 0, g_utf8_pointer_to_offset(bare, atp));
}
domain_start = atp + 1;
}
if (slashp) {
result->resourcepart = g_strdup(slashp + 1);
result->domainpart = g_utf8_substring(domain_start, 0, g_utf8_pointer_to_offset(domain_start, slashp));
auto_gchar gchar* barejidraw = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, slashp));
result->barejid = g_utf8_strdown(barejidraw, -1);
result->fulljid = g_strdup(trimmed);
} else {
if (strlen(domain_start) > 0) {
result->domainpart = g_strdup(domain_start);
result->barejid = g_utf8_strdown(trimmed, -1);
}
if (result->domainpart == NULL) {
jid_destroy(result);
return NULL;
}
result->str = trimmed;
result->barejid = g_utf8_strdown(bare, -1);
return result;
}
gboolean
jid_is_valid(const gchar* const str)
{
if (str == NULL) {
return FALSE;
}
size_t total_len = strlen(str);
if (total_len == 0 || total_len > JID_MAX_TOTAL_LEN) {
return FALSE;
}
if (!g_utf8_validate(str, -1, NULL)) {
return FALSE;
}
const gchar* slash = g_utf8_strchr(str, -1, '/');
const gchar* at = NULL;
// Find the first '@' that is NOT in the resourcepart
// and ensure there is at most one '@' in the bare JID
const gchar* p = str;
while (*p && (!slash || p < slash)) {
if (g_utf8_get_char(p) == '@') {
if (at == NULL) {
at = p;
} else {
// More than one '@' in bare JID
return FALSE;
}
}
p = g_utf8_next_char(p);
}
const gchar* domain_start = str;
size_t domain_len = 0;
// Localpart validation
if (at) {
size_t local_len = at - str;
if (local_len == 0 || local_len > JID_MAX_PART_LEN) {
return FALSE;
}
const gchar* lp = str;
while (lp < at) {
gunichar c = g_utf8_get_char(lp);
if (_is_invalid_local_char(c)) {
return FALSE;
}
lp = g_utf8_next_char(lp);
}
domain_start = at + 1;
}
// Resourcepart validation if present
if (slash) {
domain_len = slash - domain_start;
size_t resource_len = strlen(slash + 1);
if (resource_len > JID_MAX_PART_LEN) {
return FALSE;
}
} else {
domain_len = strlen(domain_start);
}
// Domainpart validation
if (domain_len == 0 || domain_len > JID_MAX_PART_LEN) {
return FALSE;
}
return TRUE;
}
gboolean
jid_is_valid_user_jid(const gchar* const str)
{
if (!jid_is_valid(str)) {
return FALSE;
}
const gchar* slash = g_utf8_strchr(str, -1, '/');
const gchar* at = g_utf8_strchr(str, -1, '@');
// A user JID must have an '@' before any '/'
if (at && (!slash || at < slash)) {
return TRUE;
}
return FALSE;
}
Jid*
jid_create_from_bare_and_resource(const char* const barejid, const char* const resource)
jid_create_from_bare_and_resource(const gchar* const barejid, const gchar* const resource)
{
// NULL, empty, or the literal "(null)" (legacy artefact from earlier
// builds where g_strdup_printf("%s", NULL) leaked the glibc placeholder
@@ -122,7 +184,7 @@ jid_create_from_bare_and_resource(const char* const barejid, const char* const r
if (!resource || !*resource || g_strcmp0(resource, "(null)") == 0) {
return jid_create(barejid);
}
auto_char char* jid = create_fulljid(barejid, resource);
auto_gchar gchar* jid = create_fulljid(barejid, resource);
return jid_create(jid);
}
@@ -157,7 +219,7 @@ jid_destroy(Jid* jid)
g_free(jid->resourcepart);
g_free(jid->barejid);
g_free(jid->fulljid);
free(jid);
g_free(jid);
}
gboolean
@@ -171,11 +233,15 @@ jid_is_valid_room_form(Jid* jid)
* barejid/resourcepart
* Will return a newly created string that must be freed by the caller
*/
char*
create_fulljid(const char* const barejid, const char* const resource)
gchar*
create_fulljid(const gchar* const barejid, const gchar* const resource)
{
auto_gchar gchar* barejidlower = g_utf8_strdown(barejid, -1);
return g_strdup_printf("%s/%s", barejidlower, resource);
if (resource && strlen(resource) > 0) {
return g_strdup_printf("%s/%s", barejidlower, resource);
} else {
return g_strdup(barejidlower);
}
}
/*
@@ -183,11 +249,11 @@ create_fulljid(const char* const barejid, const char* const resource)
* Full JID = "test@conference.server/person"
* returns "person"
*/
char*
get_nick_from_full_jid(const char* const full_room_jid)
gchar*
get_nick_from_full_jid(const gchar* const full_room_jid)
{
auto_gcharv gchar** tokens = g_strsplit(full_room_jid, "/", 0);
char* nick_part = NULL;
gchar* nick_part = NULL;
if (tokens) {
if (tokens[0] && tokens[1]) {
@@ -201,7 +267,7 @@ get_nick_from_full_jid(const char* const full_room_jid)
/*
* get the fulljid, fall back to the barejid
*/
const char*
const gchar*
jid_fulljid_or_barejid(Jid* jid)
{
if (jid->fulljid) {
@@ -214,7 +280,7 @@ jid_fulljid_or_barejid(Jid* jid)
gchar*
jid_random_resource(void)
{
auto_char char* rand = get_random_string(4);
auto_gchar gchar* rand = get_random_string(4);
gchar* result = g_strdup_printf("profanity.%s", rand);

View File

@@ -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 XMPP_JID_H
@@ -41,18 +15,20 @@
struct jid_t
{
unsigned int refcnt;
char* str;
char* localpart;
char* domainpart;
char* resourcepart;
char* barejid;
char* fulljid;
gchar* str;
gchar* localpart;
gchar* domainpart;
gchar* resourcepart;
gchar* barejid;
gchar* fulljid;
};
typedef struct jid_t Jid;
Jid* jid_create(const gchar* const str);
Jid* jid_create_from_bare_and_resource(const char* const barejid, const char* const resource);
gboolean jid_is_valid(const gchar* const str);
gboolean jid_is_valid_user_jid(const gchar* const str);
Jid* jid_create_from_bare_and_resource(const gchar* const barejid, const gchar* const resource);
void jid_destroy(Jid* jid);
void jid_ref(Jid* jid);
@@ -60,10 +36,10 @@ void jid_auto_destroy(Jid** str);
#define auto_jid __attribute__((__cleanup__(jid_auto_destroy)))
gboolean jid_is_valid_room_form(Jid* jid);
char* create_fulljid(const char* const barejid, const char* const resource);
char* get_nick_from_full_jid(const char* const full_room_jid);
gchar* create_fulljid(const gchar* const barejid, const gchar* const resource);
gchar* get_nick_from_full_jid(const gchar* const full_room_jid);
const char* jid_fulljid_or_barejid(Jid* jid);
const gchar* jid_fulljid_or_barejid(Jid* jid);
gchar* jid_random_resource(void);
#endif

View File

@@ -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"
@@ -91,18 +65,37 @@ static void _handle_pubsub(xmpp_stanza_t* const stanza, xmpp_stanza_t* const eve
static gboolean _handle_form(xmpp_stanza_t* const stanza);
static gboolean _handle_jingle_message(xmpp_stanza_t* const stanza);
static gboolean _should_ignore_based_on_silence(xmpp_stanza_t* const stanza);
#ifdef HAVE_OMEMO
static void _receive_omemo(xmpp_stanza_t* const stanza, ProfMessage* message);
#endif
#ifdef HAVE_LIBGPGME
static xmpp_stanza_t* _ox_openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const to, const char* const text);
#endif // HAVE_LIBGPGME
#ifdef HAVE_OMEMO
static void
_receive_omemo(xmpp_stanza_t* const stanza, ProfMessage* message)
{
message->plain = omemo_receive_message(stanza, &message->trusted, &message->omemo_err);
if (message->omemo_err != OMEMO_ERR_NONE) {
message->enc = PROF_MSG_ENC_OMEMO;
if (message->plain == NULL) {
message->plain = omemo_error_to_string(message->omemo_err);
}
} else if (message->plain != NULL) {
message->enc = PROF_MSG_ENC_OMEMO;
}
}
#endif // HAVE_OMEMO
static GHashTable* pubsub_event_handlers;
gchar*
get_display_name(const ProfMessage* const message, int* flags)
{
if (equals_our_barejid(message->from_jid->barejid)) {
return g_strdup("me");
return prefs_get_string(PREF_OUTGOING_STAMP);
} else {
if (flags)
*flags = NO_ME;
@@ -353,9 +346,10 @@ message_handlers_init(void)
ProfMessage*
message_init(void)
{
ProfMessage* message = calloc(1, sizeof(ProfMessage));
ProfMessage* message = g_new0(ProfMessage, 1);
message->enc = PROF_MSG_ENC_NONE;
message->omemo_err = OMEMO_ERR_NONE;
message->trusted = true;
message->type = PROF_MSG_TYPE_UNINITIALIZED;
message->marked_read = -1;
@@ -421,7 +415,7 @@ message_handlers_clear(void)
void
message_pubsub_event_handler_add(const char* const node, ProfMessageCallback func, ProfMessageFreeCallback free_func, void* userdata)
{
ProfMessageHandler* handler = malloc(sizeof(ProfMessageHandler));
ProfMessageHandler* handler = g_new(ProfMessageHandler, 1);
handler->func = func;
handler->free_func = free_func;
handler->userdata = userdata;
@@ -477,7 +471,7 @@ message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean
ProfAccount* account = accounts_get_account(session_get_account_name());
if (account->pgp_keyid) {
auto_jid Jid* jidp = jid_create(jid);
auto_char char* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid);
auto_gchar gchar* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid);
if (encrypted) {
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
xmpp_message_set_body(message, "This message is encrypted (XEP-0027).");
@@ -1093,9 +1087,12 @@ _handle_groupchat(xmpp_stanza_t* const stanza)
char* stanzaid = NULL;
xmpp_stanza_t* stanzaidst = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_STANZA_ID, STANZA_NS_STABLE_ID);
if (stanzaidst) {
stanzaid = (char*)xmpp_stanza_get_attribute(stanzaidst, STANZA_ATTR_ID);
if (stanzaid) {
message->stanzaid = strdup(stanzaid);
const char* by = xmpp_stanza_get_attribute(stanzaidst, "by");
if (by && (g_strcmp0(by, from_jid->barejid) == 0)) {
stanzaid = (char*)xmpp_stanza_get_attribute(stanzaidst, STANZA_ATTR_ID);
if (stanzaid) {
message->stanzaid = strdup(stanzaid);
}
}
}
@@ -1111,10 +1108,7 @@ _handle_groupchat(xmpp_stanza_t* const stanza)
// check omemo encryption
#ifdef HAVE_OMEMO
message->plain = omemo_receive_message(stanza, &message->trusted);
if (message->plain != NULL) {
message->enc = PROF_MSG_ENC_OMEMO;
}
_receive_omemo(stanza, message);
#endif
if (!message->plain && !message->body) {
@@ -1271,10 +1265,7 @@ _handle_muc_private_message(xmpp_stanza_t* const stanza)
// check omemo encryption
#ifdef HAVE_OMEMO
message->plain = omemo_receive_message(stanza, &message->trusted);
if (message->plain != NULL) {
message->enc = PROF_MSG_ENC_OMEMO;
}
_receive_omemo(stanza, message);
#endif
message->timestamp = stanza_get_delay(stanza);
@@ -1405,9 +1396,12 @@ _handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, c
char* stanzaid = NULL;
xmpp_stanza_t* stanzaidst = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_STANZA_ID, STANZA_NS_STABLE_ID);
if (stanzaidst) {
stanzaid = (char*)xmpp_stanza_get_attribute(stanzaidst, STANZA_ATTR_ID);
if (stanzaid) {
message->stanzaid = strdup(stanzaid);
const char* by = xmpp_stanza_get_attribute(stanzaidst, "by");
if (by && equals_our_barejid(by)) {
stanzaid = (char*)xmpp_stanza_get_attribute(stanzaidst, STANZA_ATTR_ID);
if (stanzaid) {
message->stanzaid = strdup(stanzaid);
}
}
}
}
@@ -1438,10 +1432,7 @@ _handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, c
#ifdef HAVE_OMEMO
// check omemo encryption
message->plain = omemo_receive_message(stanza, &message->trusted);
if (message->plain != NULL) {
message->enc = PROF_MSG_ENC_OMEMO;
}
_receive_omemo(stanza, message);
#endif
xmpp_stanza_t* encrypted = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_ENCRYPTED);
@@ -1535,6 +1526,20 @@ _handle_mam(xmpp_stanza_t* const stanza)
// <result xmlns='urn:xmpp:mam:2' queryid='f27' id='5d398-28273-f7382'>
// same as <stanza-id> from XEP-0359 for live messages
const char* by = xmpp_stanza_get_attribute(result, "by");
const char* from = xmpp_stanza_get_from(stanza);
if (by) {
if (g_strcmp0(by, from) != 0) {
log_warning("MAM result 'by' attribute (%s) does not match 'from' (%s)", by, from);
return TRUE;
}
} else {
if (from && !equals_our_barejid(from)) {
log_warning("MAM result from %s with no 'by' attribute (expected our own JID)", from);
return TRUE;
}
}
const char* result_id = xmpp_stanza_get_id(result);
GDateTime* timestamp = stanza_get_delay_from(forwarded, NULL);
@@ -1636,7 +1641,7 @@ _ox_openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const to, const char* const t
char rpad_data[randnr];
for (int i = 0; i < randnr; i++) {
int rchar = (rand() % 52) + 65;
rpad_data[i] = rchar;
rpad_data[i] = (char)rchar;
}
rpad_data[randnr - 1] = '\0';

View File

@@ -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 XMPP_MESSAGE_H

View File

@@ -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"
@@ -214,7 +188,7 @@ muc_confserver_clear(void)
void
muc_join(const char* const room, const char* const nick, const char* const password, gboolean autojoin)
{
ChatRoom* new_room = malloc(sizeof(ChatRoom));
ChatRoom* new_room = g_new0(ChatRoom, 1);
new_room->room = strdup(room);
new_room->nick = strdup(nick);
new_room->role = MUC_ROLE_NONE;
@@ -1046,7 +1020,7 @@ static Occupant*
_muc_occupant_new(const char* const nick, const char* const jid, muc_role_t role, muc_affiliation_t affiliation,
resource_presence_t presence, const char* const status)
{
Occupant* occupant = malloc(sizeof(Occupant));
Occupant* occupant = g_new0(Occupant, 1);
if (nick) {
occupant->nick = strdup(nick);

View File

@@ -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 XMPP_MUC_H

View File

@@ -4,33 +4,7 @@
*
* Copyright (C) 2019 Paul Fariello <paul@fariello.eu>
*
* 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"
@@ -116,6 +90,11 @@ omemo_devicelist_request(const char* const jid)
void
omemo_bundle_publish(gboolean first)
{
if (!connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) {
cons_show("OMEMO: Cannot publish bundle: no PUBSUB feature announced");
log_debug("[OMEMO] Cannot publish bundle: no PUBSUB feature announced");
return;
}
log_debug("[OMEMO] publish own OMEMO bundle");
xmpp_ctx_t* const ctx = connection_get_ctx();
unsigned char* identity_key = NULL;
@@ -141,14 +120,10 @@ omemo_bundle_publish(gboolean first)
g_list_free(lengths);
g_list_free(ids);
if (connection_supports(XMPP_FEATURE_PUBSUB_PUBLISH_OPTIONS)) {
stanza_attach_publish_options_va(ctx, iq,
4, // 2 * number of key-value pairs
"pubsub#persist_items", "true",
"pubsub#access_model", "open");
} else {
log_debug("[OMEMO] Cannot publish bundle: no PUBSUB feature announced");
}
stanza_attach_publish_options_va(ctx, iq,
4, // 2 * number of key-value pairs
"pubsub#persist_items", "true",
"pubsub#access_model", "open");
iq_id_handler_add(id, _omemo_bundle_publish_result, NULL, GINT_TO_POINTER(first));
@@ -219,7 +194,7 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t* const stanza, void* cons
goto out;
}
uint32_t device_id = strtoul(++device_id_str, NULL, 10);
uint32_t device_id = (uint32_t)strtoul(++device_id_str, NULL, 10);
log_debug("[OMEMO] omemo_start_device_session_handle_bundle: %d", device_id);
xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(items, "item");
@@ -243,7 +218,7 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t* const stanza, void* cons
continue;
}
omemo_key_t* key = malloc(sizeof(omemo_key_t));
omemo_key_t* key = g_new0(omemo_key_t, 1);
key->data = NULL;
const char* prekey_id_text = xmpp_stanza_get_attribute(prekey, "preKeyId");
@@ -252,7 +227,7 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t* const stanza, void* cons
continue;
}
key->id = strtoul(prekey_id_text, NULL, 10);
key->id = (uint32_t)strtoul(prekey_id_text, NULL, 10);
xmpp_stanza_t* prekey_text = xmpp_stanza_get_children(prekey);
if (!prekey_text) {
@@ -282,7 +257,7 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t* const stanza, void* cons
goto out;
}
uint32_t signed_prekey_id = strtoul(signed_prekey_id_text, NULL, 10);
uint32_t signed_prekey_id = (uint32_t)strtoul(signed_prekey_id_text, NULL, 10);
xmpp_stanza_t* signed_prekey_text = xmpp_stanza_get_children(signed_prekey);
if (!signed_prekey_text) {
goto out;
@@ -349,8 +324,12 @@ out:
}
char*
omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted, omemo_error_t* error)
{
if (!stanza || !trusted || !error) {
return NULL;
}
char* plaintext = NULL;
const char* type = xmpp_stanza_get_type(stanza);
const char* from = xmpp_stanza_get_from(stanza);
@@ -359,6 +338,9 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
unsigned char* payload_raw = NULL;
char* iv_text = NULL;
char* payload_text = NULL;
size_t payload_len = 0;
*error = OMEMO_ERR_NONE;
xmpp_stanza_t* encrypted = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_OMEMO);
if (!encrypted) {
@@ -367,41 +349,44 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
xmpp_stanza_t* header = xmpp_stanza_get_child_by_name(encrypted, "header");
if (!header) {
*error = OMEMO_ERR_OTHER;
return NULL;
}
const char* sid_text = xmpp_stanza_get_attribute(header, "sid");
if (!sid_text) {
*error = OMEMO_ERR_OTHER;
return NULL;
}
uint32_t sid = strtoul(sid_text, NULL, 10);
uint32_t sid = (uint32_t)strtoul(sid_text, NULL, 10);
xmpp_stanza_t* iv = xmpp_stanza_get_child_by_name(header, "iv");
if (!iv) {
*error = OMEMO_ERR_OTHER;
return NULL;
}
iv_text = xmpp_stanza_get_text(iv);
if (!iv_text) {
*error = OMEMO_ERR_OTHER;
return NULL;
}
size_t iv_len;
iv_raw = g_base64_decode(iv_text, &iv_len);
if (!iv_raw) {
*error = OMEMO_ERR_OTHER;
return NULL;
}
xmpp_stanza_t* payload = xmpp_stanza_get_child_by_name(encrypted, "payload");
if (!payload) {
goto quit;
}
payload_text = xmpp_stanza_get_text(payload);
if (!payload_text) {
goto quit;
}
size_t payload_len;
payload_raw = g_base64_decode(payload_text, &payload_len);
if (!payload_raw) {
goto quit;
if (payload) {
payload_text = xmpp_stanza_get_text(payload);
if (payload_text) {
payload_raw = g_base64_decode(payload_text, &payload_len);
if (!payload_raw) {
*error = OMEMO_ERR_OTHER;
goto quit;
}
}
}
xmpp_stanza_t* key_stanza;
@@ -410,7 +395,7 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
continue;
}
omemo_key_t* key = malloc(sizeof(omemo_key_t));
omemo_key_t* key = g_new0(omemo_key_t, 1);
char* key_text = xmpp_stanza_get_text(key_stanza);
if (!key_text) {
free(key);
@@ -418,7 +403,7 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
}
const char* rid_text = xmpp_stanza_get_attribute(key_stanza, "rid");
key->device_id = strtoul(rid_text, NULL, 10);
key->device_id = (uint32_t)strtoul(rid_text, NULL, 10);
if (!key->device_id) {
free(key);
continue;
@@ -437,7 +422,7 @@ omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted)
plaintext = omemo_on_message_recv(from, sid, iv_raw, iv_len,
keys, payload_raw, payload_len,
g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0, trusted);
g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0, trusted, error);
if (keys) {
g_list_free_full(keys, (GDestroyNotify)omemo_key_free);
@@ -722,3 +707,24 @@ _omemo_bundle_publish_configure_result(xmpp_stanza_t* const stanza, void* const
return 0;
}
gchar*
omemo_error_to_string(omemo_error_t error)
{
switch (error) {
case OMEMO_ERR_NO_KEY:
return g_strdup("OMEMO message received but no key for this device found.");
case OMEMO_ERR_NOT_TRUSTED:
return g_strdup("OMEMO message received but sender identity is untrusted.");
case OMEMO_ERR_NO_SESSION:
return g_strdup("OMEMO message received but no session found. Try '/omemo start'.");
case OMEMO_ERR_DECRYPT_FAILED:
return g_strdup("OMEMO message received but decryption failed.");
case OMEMO_ERR_KEY_TRANSPORT:
return NULL;
case OMEMO_ERR_NONE:
return NULL;
default:
return g_strdup("OMEMO message received but could not be decrypted.");
}
}

View File

@@ -4,33 +4,7 @@
*
* Copyright (C) 2019 Paul Fariello <paul@fariello.eu>
*
* 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 <glib.h>
@@ -43,4 +17,6 @@ void omemo_devicelist_request(const char* const jid);
void omemo_bundle_publish(gboolean first);
void omemo_bundle_request(const char* const jid, uint32_t device_id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata);
int omemo_start_device_session_handle_bundle(xmpp_stanza_t* const stanza, void* const userdata);
char* omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted);
char* omemo_receive_message(xmpp_stanza_t* const stanza, gboolean* trusted, omemo_error_t* error) __attribute__((nonnull(2, 3)));
gchar* omemo_error_to_string(omemo_error_t error);

View File

@@ -4,33 +4,7 @@
*
* Copyright (C) 2020 Stefan Kropp <stefan@debxwoody.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 "config.h"

View File

@@ -4,33 +4,7 @@
*
* Copyright (C) 2020 Stefan Kropp <stefan@debxwoody.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
*/
/*!

View File

@@ -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"
@@ -268,7 +242,7 @@ _send_room_presence(xmpp_stanza_t* presence)
const char* const nick = muc_nick(room);
if (nick) {
auto_char char* full_room_jid = create_fulljid(room, nick);
auto_gchar gchar* full_room_jid = create_fulljid(room, nick);
xmpp_stanza_set_to(presence, full_room_jid);
log_debug("Sending presence to room: %s", full_room_jid);
@@ -314,7 +288,7 @@ presence_change_room_nick(const char* const room, const char* const nick)
const char* show = stanza_get_presence_string_from_type(presence_type);
const char* status = connection_get_presence_msg();
int pri = accounts_get_priority_for_presence_type(session_get_account_name(), presence_type);
auto_char char* full_room_jid = create_fulljid(room, nick);
auto_gchar gchar* full_room_jid = create_fulljid(room, nick);
xmpp_ctx_t* ctx = connection_get_ctx();
xmpp_stanza_t* presence = stanza_create_room_newnick_presence(ctx, full_room_jid);
@@ -533,8 +507,8 @@ _unavailable_handler(xmpp_stanza_t* const stanza)
return;
}
auto_char char* status_str = stanza_get_status(stanza, NULL);
if (strcmp(my_jid->barejid, from_jid->barejid) != 0) {
auto_char char* status_str = stanza_get_status(stanza, NULL);
if (from_jid->resourcepart) {
sv_ev_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str);
@@ -544,6 +518,7 @@ _unavailable_handler(xmpp_stanza_t* const stanza)
}
} else {
if (from_jid->resourcepart) {
sv_ev_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str);
connection_remove_available_resource(from_jid->resourcepart);
}
}
@@ -621,7 +596,7 @@ _available_handler(xmpp_stanza_t* const stanza)
}
return;
} else {
const char* jid = jid_fulljid_or_barejid(xmpp_presence->jid);
const gchar* jid = jid_fulljid_or_barejid(xmpp_presence->jid);
log_debug("Presence available handler fired for: %s", jid);
}
@@ -632,15 +607,23 @@ _available_handler(xmpp_stanza_t* const stanza)
XMPPCaps* caps = stanza_parse_caps(stanza);
if ((g_strcmp0(my_jid->fulljid, xmpp_presence->jid->fulljid) != 0) && caps) {
log_debug("Presence contains capabilities.");
const char* jid = jid_fulljid_or_barejid(xmpp_presence->jid);
const gchar* jid = jid_fulljid_or_barejid(xmpp_presence->jid);
_handle_caps(jid, caps);
}
stanza_free_caps(caps);
Resource* resource = stanza_resource_from_presence(xmpp_presence);
char* pgpsig = NULL;
xmpp_stanza_t* x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_SIGNED);
if (x) {
pgpsig = xmpp_stanza_get_text(x);
}
if (g_strcmp0(xmpp_presence->jid->barejid, my_jid->barejid) == 0) {
connection_add_available_resource(resource);
Resource* resource_for_roster = resource_copy(resource);
sv_ev_contact_online(xmpp_presence->jid->barejid, resource_for_roster, xmpp_presence->last_activity, pgpsig);
const char* account_name = session_get_account_name();
int max_sessions = accounts_get_max_sessions(account_name);
if (max_sessions > 0) {
@@ -704,16 +687,11 @@ _available_handler(xmpp_stanza_t* const stanza)
}
}
} else {
char* pgpsig = NULL;
xmpp_stanza_t* x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_SIGNED);
if (x) {
pgpsig = xmpp_stanza_get_text(x);
}
sv_ev_contact_online(xmpp_presence->jid->barejid, resource, xmpp_presence->last_activity, pgpsig);
xmpp_ctx_t* ctx = connection_get_ctx();
xmpp_free(ctx, pgpsig);
}
xmpp_ctx_t* ctx = connection_get_ctx();
xmpp_free(ctx, pgpsig);
stanza_free_presence(xmpp_presence);
}
@@ -813,7 +791,12 @@ _muc_user_self_handler(xmpp_stanza_t* stanza)
affiliation = xmpp_stanza_get_attribute(item, "affiliation");
}
}
sv_ev_muc_self_online(room, nick, config_required, role, affiliation, actor, reason, jid, show_str, status_str);
if (muc_active(room)) {
sv_ev_muc_self_online(room, nick, config_required, role, affiliation, actor, reason, jid, show_str, status_str);
} else {
log_debug("presence: self-presence received for untracked room: %s", room);
}
}
}

View File

@@ -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 XMPP_PRESENCE_H

View File

@@ -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"
@@ -39,18 +13,20 @@
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "common.h"
#include "xmpp/resource.h"
Resource*
resource_new(const char* const name, resource_presence_t presence, const char* const status, const int priority)
resource_new(const gchar* const name, resource_presence_t presence, const gchar* const status, const int priority)
{
assert(name != NULL);
Resource* new_resource = malloc(sizeof(struct resource_t));
new_resource->name = strdup(name);
Resource* new_resource = g_new(Resource, 1);
new_resource->name = g_strdup(name);
new_resource->presence = presence;
if (status) {
new_resource->status = strdup(status);
new_resource->status = g_strdup(status);
} else {
new_resource->status = NULL;
}
@@ -93,14 +69,26 @@ void
resource_destroy(Resource* resource)
{
if (resource) {
free(resource->name);
free(resource->status);
free(resource);
g_free(resource->name);
resource->name = NULL;
g_free(resource->status);
resource->status = NULL;
g_free(resource);
}
}
Resource*
resource_copy(Resource* resource)
{
if (resource == NULL) {
return NULL;
}
return resource_new(resource->name, resource->presence, resource->status, resource->priority);
}
gboolean
valid_resource_presence_string(const char* const str)
valid_resource_presence_string(const gchar* const str)
{
assert(str != NULL);
if ((strcmp(str, "online") == 0) || (strcmp(str, "chat") == 0) || (strcmp(str, "away") == 0) || (strcmp(str, "xa") == 0) || (strcmp(str, "dnd") == 0)) {
@@ -110,7 +98,7 @@ valid_resource_presence_string(const char* const str)
}
}
const char*
const gchar*
string_from_resource_presence(resource_presence_t presence)
{
switch (presence) {
@@ -128,7 +116,7 @@ string_from_resource_presence(resource_presence_t presence)
}
resource_presence_t
resource_presence_from_string(const char* const str)
resource_presence_from_string(const gchar* const str)
{
if (str == NULL) {
return RESOURCE_ONLINE;

View File

@@ -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 XMPP_RESOURCE_H
@@ -40,20 +14,21 @@
typedef struct resource_t
{
char* name;
gchar* name;
resource_presence_t presence;
char* status;
gchar* status;
int priority;
} Resource;
Resource* resource_new(const char* const name, resource_presence_t presence, const char* const status,
Resource* resource_new(const gchar* const name, resource_presence_t presence, const gchar* const status,
const int priority);
Resource* resource_copy(Resource* resource);
void resource_destroy(Resource* resource);
int resource_compare_availability(Resource* first, Resource* second);
gboolean valid_resource_presence_string(const char* const str);
const char* string_from_resource_presence(resource_presence_t presence);
resource_presence_t resource_presence_from_string(const char* const str);
gboolean valid_resource_presence_string(const gchar* const str);
const gchar* string_from_resource_presence(resource_presence_t presence);
resource_presence_t resource_presence_from_string(const gchar* const str);
contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence);
#endif

View File

@@ -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"
@@ -122,7 +96,7 @@ roster_send_add_to_group(const char* const group, PContact contact)
new_groups = g_slist_append(new_groups, strdup(group));
// add an id handler to handle the response
auto_char char* unique_id = connection_create_stanza_id();
GroupData* data = malloc(sizeof(GroupData));
GroupData* data = g_new0(GroupData, 1);
data->group = strdup(group);
if (p_contact_name(contact)) {
data->name = strdup(p_contact_name(contact));
@@ -164,7 +138,7 @@ roster_send_remove_from_group(const char* const group, PContact contact)
// add an id handler to handle the response
auto_char char* unique_id = connection_create_stanza_id();
GroupData* data = malloc(sizeof(GroupData));
GroupData* data = g_new0(GroupData, 1);
data->group = strdup(group);
if (p_contact_name(contact)) {
data->name = strdup(p_contact_name(contact));

View File

@@ -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 XMPP_ROSTER_H

View File

@@ -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"
@@ -47,6 +21,7 @@
#include "xmpp/resource.h"
#include "xmpp/contact.h"
#include "xmpp/jid.h"
#include "xmpp/xmpp.h"
typedef struct prof_roster_t
{
@@ -91,7 +66,7 @@ roster_create(void)
{
assert(roster == NULL);
roster = malloc(sizeof(ProfRoster));
roster = g_new0(ProfRoster, 1);
roster->contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free, (GDestroyNotify)p_contact_free);
roster->name_ac = autocomplete_new();
roster->barejid_ac = autocomplete_new();
@@ -112,6 +87,8 @@ _pendingPresence_free(ProfPendingPresence* presence)
if (presence->last_activity)
g_date_time_unref(presence->last_activity);
free(presence->barejid);
resource_destroy(presence->resource);
presence->resource = NULL;
free(presence);
}
@@ -136,6 +113,7 @@ roster_destroy(void)
roster_pending_presence = NULL;
}
// Consumes `resource` on every return path. Callers must null their own pointer afterwards.
gboolean
roster_update_presence(const char* const barejid, Resource* resource, GDateTime* last_activity)
{
@@ -145,7 +123,7 @@ roster_update_presence(const char* const barejid, Resource* resource, GDateTime*
assert(resource != NULL);
if (!roster_received) {
ProfPendingPresence* presence = malloc(sizeof(ProfPendingPresence));
ProfPendingPresence* presence = g_new0(ProfPendingPresence, 1);
presence->barejid = strdup(barejid);
presence->resource = resource;
presence->last_activity = last_activity;
@@ -158,7 +136,6 @@ roster_update_presence(const char* const barejid, Resource* resource, GDateTime*
PContact contact = roster_get_contact(barejid);
if (contact == NULL) {
/* Don't lose resource when there is no owner. */
resource_destroy(resource);
return FALSE;
}
@@ -391,6 +368,19 @@ roster_add(const char* const barejid, const char* const name, GSList* groups, co
}
g_hash_table_insert(roster->contacts, strdup(barejid), contact);
if (equals_our_barejid(barejid)) {
GList* resources = connection_get_available_resources();
GList* curr = resources;
while (curr) {
Resource* res = curr->data;
Resource* res_copy = resource_copy(res);
p_contact_set_presence(contact, res_copy);
curr = g_list_next(curr);
}
g_list_free(resources);
}
autocomplete_add(roster->barejid_ac, barejid);
_add_name_and_barejid(name, barejid);
@@ -711,6 +701,7 @@ roster_process_pending_presence(void)
for (iter = roster_pending_presence; iter != NULL; iter = iter->next) {
ProfPendingPresence* presence = iter->data;
roster_update_presence(presence->barejid, presence->resource, presence->last_activity);
presence->resource = NULL;
}
g_slist_free_full(roster_pending_presence, (GDestroyNotify)_pendingPresence_free);

View File

@@ -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 XMPP_ROSTER_LIST_H

View File

@@ -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"
@@ -73,7 +47,7 @@ static struct
char* passwd;
} saved_account;
static struct
static struct session_details
{
char* name;
char* jid;
@@ -143,7 +117,7 @@ session_connect_with_account(const ProfAccount* const account)
auto_char char* jid = NULL;
if (account->resource) {
auto_jid Jid* jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
jid = strdup(jidp->fulljid);
jid = strdup(jid_fulljid_or_barejid(jidp));
} else {
jid = strdup(account->jid);
}
@@ -159,6 +133,18 @@ session_connect_with_account(const ProfAccount* const account)
return result;
}
static jabber_conn_status_t
_session_connect(struct session_details* details)
{
return connection_connect(
details->jid,
details->passwd,
details->altdomain,
details->port,
details->tls_policy,
details->auth_policy);
}
jabber_conn_status_t
session_connect_with_details(const char* const jid, const char* const passwd, const char* const altdomain,
const int port, const char* const tls_policy, const char* const auth_policy)
@@ -206,13 +192,7 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
// connect with fulljid
log_info("Connecting without account, JID: %s", saved_details.jid);
return connection_connect(
saved_details.jid,
passwd,
saved_details.altdomain,
saved_details.port,
saved_details.tls_policy,
saved_details.auth_policy);
return _session_connect(&saved_details);
}
void
@@ -263,7 +243,7 @@ session_process_events(void)
case JABBER_DISCONNECTED:
reconnect_sec = prefs_get_reconnect();
if ((reconnect_sec != 0) && reconnect_timer) {
int elapsed_sec = g_timer_elapsed(reconnect_timer, NULL);
int elapsed_sec = (int)g_timer_elapsed(reconnect_timer, NULL);
if (elapsed_sec > reconnect_sec) {
log_debug("[CONNDBG] session_process_events: auto-reconnect triggered after %d seconds (threshold=%d)",
elapsed_sec, reconnect_sec);
@@ -426,8 +406,8 @@ session_check_autoaway(void)
gboolean check = prefs_get_boolean(PREF_AUTOAWAY_CHECK);
gint away_time = prefs_get_autoaway_time();
gint xa_time = prefs_get_autoxa_time();
int away_time_ms = away_time * 60000;
int xa_time_ms = xa_time * 60000;
unsigned long away_time_ms = away_time * 60000;
unsigned long xa_time_ms = xa_time * 60000;
const char* account = session_get_account_name();
resource_presence_t curr_presence = accounts_get_last_presence(account);
@@ -457,7 +437,7 @@ session_check_autoaway(void)
auto_gchar gchar* message = prefs_get_string(PREF_AUTOAWAY_MESSAGE);
connection_set_presence_msg(message);
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(RESOURCE_AWAY, idle_ms / 1000);
cl_ev_presence_send(RESOURCE_AWAY, (int)(idle_ms / 1000));
} else {
cl_ev_presence_send(RESOURCE_AWAY, 0);
}
@@ -476,7 +456,7 @@ session_check_autoaway(void)
// send current presence with last activity
connection_set_presence_msg(curr_status);
cl_ev_presence_send(curr_presence, idle_ms / 1000);
cl_ev_presence_send(curr_presence, (int)(idle_ms / 1000));
}
}
break;
@@ -499,7 +479,7 @@ session_check_autoaway(void)
auto_gchar gchar* message = prefs_get_string(PREF_AUTOXA_MESSAGE);
connection_set_presence_msg(message);
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(RESOURCE_XA, idle_ms / 1000);
cl_ev_presence_send(RESOURCE_XA, (int)(idle_ms / 1000));
} else {
cl_ev_presence_send(RESOURCE_XA, 0);
}
@@ -560,31 +540,36 @@ void
session_reconnect_now(void)
{
// reconnect with account.
ProfAccount* account = accounts_get_account(saved_account.name);
if (account == NULL) {
log_error("Unable to reconnect, account no longer exists: %s", saved_account.name);
return;
}
if (saved_account.name) {
ProfAccount* account = accounts_get_account(saved_account.name);
if (account == NULL) {
log_error("Unable to reconnect, account no longer exists: %s", saved_account.name);
return;
}
auto_char char* jid = NULL;
if (account->resource) {
jid = create_fulljid(account->jid, account->resource);
} else {
jid = strdup(account->jid);
}
const char* server;
unsigned short port;
if (reconnect.altdomain) {
server = reconnect.altdomain;
port = reconnect.altport;
} else {
server = account->server;
port = account->port;
}
auto_gchar gchar* jid = NULL;
if (account->resource) {
jid = create_fulljid(account->jid, account->resource);
} else {
jid = g_strdup(account->jid);
}
const char* server;
unsigned short port;
if (reconnect.altdomain) {
server = reconnect.altdomain;
port = reconnect.altport;
} else {
server = account->server;
g_assert(account->port >= 0 && account->port <= UINT16_MAX);
port = (unsigned short)account->port;
}
log_debug("Attempting reconnect with account %s", account->name);
connection_connect(jid, saved_account.passwd, server, port, account->tls_policy, account->auth_policy);
account_free(account);
log_debug("Attempting reconnect with account %s", account->name);
connection_connect(jid, saved_account.passwd, server, port, account->tls_policy, account->auth_policy);
account_free(account);
} else {
_session_connect(&saved_details);
}
if (reconnect_timer)
g_timer_start(reconnect_timer);
}

View File

@@ -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 XMPP_SESSION_H

View File

@@ -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"
@@ -221,8 +195,14 @@ stanza_create_http_upload_request(xmpp_ctx_t* ctx, const char* const id,
xmpp_stanza_set_ns(request, STANZA_NS_HTTP_UPLOAD);
auto_char char* filename_cpy = strdup(upload->filename);
if (!filename_cpy) {
xmpp_stanza_release(iq);
xmpp_stanza_release(request);
return NULL;
}
// strip spaces from filename (servers don't spaces)
for (int i = 0; i < strlen(filename_cpy); i++) {
for (size_t i = 0; i < strlen(filename_cpy); i++) {
if (filename_cpy[i] == ' ') {
filename_cpy[i] = '_';
}
@@ -1690,7 +1670,7 @@ stanza_parse_caps(xmpp_stanza_t* const stanza)
const char* node = xmpp_stanza_get_attribute(caps_st, STANZA_ATTR_NODE);
const char* ver = xmpp_stanza_get_attribute(caps_st, STANZA_ATTR_VER);
XMPPCaps* caps = (XMPPCaps*)malloc(sizeof(XMPPCaps));
XMPPCaps* caps = g_new0(XMPPCaps, 1);
caps->hash = hash ? strdup(hash) : NULL;
caps->node = node ? strdup(node) : NULL;
caps->ver = ver ? strdup(ver) : NULL;
@@ -1863,7 +1843,7 @@ stanza_get_error_message(xmpp_stanza_t* stanza)
STANZA_NAME_UNEXPECTED_REQUEST
};
for (int i = 0; i < ARRAY_SIZE(defined_conditions); i++) {
for (size_t i = 0; i < ARRAY_SIZE(defined_conditions); i++) {
xmpp_stanza_t* cond_stanza = xmpp_stanza_get_child_by_name(error_stanza, defined_conditions[i]);
if (cond_stanza) {
char* result = strdup(xmpp_stanza_get_name(cond_stanza));
@@ -2134,7 +2114,7 @@ stanza_parse_presence(xmpp_stanza_t* stanza, int* err)
return NULL;
}
XMPPPresence* result = (XMPPPresence*)malloc(sizeof(XMPPPresence));
XMPPPresence* result = g_new0(XMPPPresence, 1);
result->jid = from_jid;
result->show = stanza_get_show(stanza, "online");

View File

@@ -2,35 +2,9 @@
* stanza.h
*
* 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 XMPP_STANZA_H
@@ -122,6 +96,8 @@
#define STANZA_NAME_USERNAME "username"
#define STANZA_NAME_PROPOSE "propose"
#define STANZA_NAME_REPORT "report"
#define STANZA_NAME_REPORT_ORIGIN "report-origin"
#define STANZA_NAME_THIRD_PARTY "third-party"
#define STANZA_NAME_EVENT "event"
#define STANZA_NAME_MOOD "mood"
#define STANZA_NAME_RECEIVED "received"

View File

@@ -4,33 +4,7 @@
*
* Copyright (C) 2022 Marouane L. <techmetx11@disroot.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.
*
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
*/
#include <assert.h>
@@ -59,7 +33,7 @@ typedef struct
// for photo
int photo_index;
gboolean open;
char* filename;
gchar* filename;
} _userdata;
static void
@@ -209,7 +183,7 @@ vcard_free_full(vCard* vcard)
vCard*
vcard_new(void)
{
vCard* vcard = calloc(1, sizeof(vCard));
vCard* vcard = g_new0(vCard, 1);
if (!vcard) {
return NULL;
@@ -238,10 +212,10 @@ _free_userdata(_userdata* data)
vcard_free(data->vcard);
if (data->filename) {
free(data->filename);
g_free(data->filename);
}
free(data);
g_free(data);
}
// Function must be called with <vCard> root element
@@ -287,7 +261,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
vcard->name.suffix = child_pointer2 ? stanza_text_strdup(child_pointer2) : NULL;
flags |= 2;
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "NICKNAME")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -304,7 +278,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
g_queue_push_tail(vcard->elements, element);
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "PHOTO")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -346,7 +320,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
}
g_queue_push_tail(vcard->elements, element);
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "BDAY")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -392,7 +366,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
}
g_queue_push_tail(vcard->elements, element);
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "ADR")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -438,7 +412,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
element->address.country = child_pointer2 ? stanza_text_strdup(child_pointer2) : NULL;
g_queue_push_tail(vcard->elements, element);
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "TEL")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -494,7 +468,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
element->telephone.number = stanza_text_strdup(child_pointer2);
g_queue_push_tail(vcard->elements, element);
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "EMAIL")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -526,7 +500,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
element->email.userid = stanza_text_strdup(child_pointer2);
g_queue_push_tail(vcard->elements, element);
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "JABBERID")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -543,7 +517,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
g_queue_push_tail(vcard->elements, element);
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "TITLE")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -560,7 +534,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
g_queue_push_tail(vcard->elements, element);
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "ROLE")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -577,7 +551,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
g_queue_push_tail(vcard->elements, element);
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "NOTE")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -594,7 +568,7 @@ vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard)
g_queue_push_tail(vcard->elements, element);
} else if (!g_strcmp0(xmpp_stanza_get_name(child_pointer), "URL")) {
vcard_element_t* element = calloc(1, sizeof(vcard_element_t));
vcard_element_t* element = g_new0(vcard_element_t, 1);
if (!element) {
// Allocation failed
continue;
@@ -1227,12 +1201,10 @@ vcard_print(xmpp_ctx_t* ctx, ProfWin* window, char* jid)
return;
}
_userdata* data = calloc(1, sizeof(_userdata));
_userdata* data = g_new0(_userdata, 1);
data->vcard = vcard_new();
if (!data || !data->vcard) {
if (data) {
free(data);
}
if (!data->vcard) {
g_free(data);
cons_show("vCard allocation failed");
return;
@@ -1338,7 +1310,7 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
g_string_append(filename, ".webp");
}
GError* err = NULL;
auto_gerror GError* err = NULL;
if (!filename) {
cons_show_error("Unable to determine filename for photo");
@@ -1346,8 +1318,7 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
}
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);
cons_show_error("Unable to save photo: %s", PROF_GERROR_MESSAGE(err));
g_string_free(filename, TRUE);
return 1;
} else {
@@ -1365,7 +1336,7 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
g_string_append(filename, "\"");
auto_char char* cmd = str_replace(cmdtemplate, "%p", filename->str);
if (g_shell_parse_argv(cmd, &argc, &argv, &err) == FALSE) {
if (g_shell_parse_argv(cmd, &argc, &argv, NULL) == FALSE) {
cons_show_error("Failed to parse command template");
} else {
if (!call_external(argv)) {
@@ -1382,13 +1353,11 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
void
vcard_photo(xmpp_ctx_t* ctx, char* jid, char* filename, int index, gboolean open)
{
_userdata* data = calloc(1, sizeof(_userdata));
_userdata* data = g_new0(_userdata, 1);
data->vcard = vcard_new();
if (!data || !data->vcard) {
if (data) {
free(data);
}
if (!data->vcard) {
g_free(data);
cons_show("vCard allocation failed");
return;
@@ -1398,7 +1367,7 @@ vcard_photo(xmpp_ctx_t* ctx, char* jid, char* filename, int index, gboolean open
data->open = open;
if (filename) {
data->filename = strdup(filename);
data->filename = g_strdup(filename);
}
auto_char char* id = connection_create_stanza_id();

View File

@@ -4,33 +4,7 @@
*
* Copyright (C) 2022 Marouane L. <techmetx11@disroot.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.
*
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
*/
#ifndef XMPP_VCARD_H

View File

@@ -4,33 +4,7 @@
*
* Copyright (C) 2022 Marouane L. <techmetx11@disroot.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.
*
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
*/
#ifndef XMPP_VCARD_FUNCS_H

View File

@@ -2,35 +2,9 @@
* xmpp.h
*
* 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 XMPP_XMPP_H
@@ -150,6 +124,18 @@ typedef enum {
PROF_MSG_TYPE_MUCPM
} prof_msg_type_t;
typedef enum {
OMEMO_ERR_NONE = 0,
OMEMO_ERR_NO_KEY,
OMEMO_ERR_NOT_TRUSTED,
OMEMO_ERR_NO_SESSION,
OMEMO_ERR_DECRYPT_FAILED,
OMEMO_ERR_INVALID_JID,
OMEMO_ERR_MUC_SENDER_NOT_FOUND,
OMEMO_ERR_KEY_TRANSPORT,
OMEMO_ERR_OTHER
} omemo_error_t;
typedef struct prof_message_t
{
Jid* from_jid;
@@ -172,6 +158,7 @@ typedef struct prof_message_t
char* plain;
GDateTime* timestamp;
prof_enc_t enc;
omemo_error_t omemo_err;
gboolean trusted;
gboolean is_mam;
prof_msg_type_t type;