Compare commits
6 Commits
feat/ai-cu
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
| f63bf57872 | |||
| f16b26bd6d | |||
| a4e6419faf | |||
| 7eb9668068 | |||
| 7404e7092a | |||
| 62361676fe |
@@ -1435,17 +1435,13 @@ ai_session_switch(AISession* session, const gchar* provider_name,
|
||||
* This is the thread-safe variant used by _ai_request_thread() which holds
|
||||
* the session lock while calling it.
|
||||
*
|
||||
* Custom provider settings are merged into the payload as additional JSON
|
||||
* key-value pairs alongside "model" and "input".
|
||||
*
|
||||
* @param provider The AI provider (for custom settings)
|
||||
* @param model The model identifier
|
||||
* @param history GList of AIMessage* (must be held under session lock)
|
||||
* @param prompt The new user prompt to append
|
||||
* @return Newly allocated JSON string (caller must free)
|
||||
*/
|
||||
static gchar*
|
||||
_build_json_payload_from_list(AIProvider* provider, const gchar* model, GList* history, const gchar* prompt)
|
||||
_build_json_payload_from_list(const gchar* model, GList* history, const gchar* prompt)
|
||||
{
|
||||
GString* messages_json = g_string_new("");
|
||||
GList* curr = history;
|
||||
@@ -1472,37 +1468,11 @@ _build_json_payload_from_list(AIProvider* provider, const gchar* model, GList* h
|
||||
g_string_append_printf(messages_json, "{\"role\":\"user\",\"content\":\"%s\"}", escaped_prompt);
|
||||
|
||||
auto_gchar gchar* escaped_model = ai_json_escape(model);
|
||||
|
||||
/* Build custom settings JSON fragment */
|
||||
GString* custom_json = g_string_new("");
|
||||
if (provider && provider->settings) {
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
g_hash_table_iter_init(&iter, provider->settings);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
auto_gchar gchar* escaped_key = ai_json_escape((gchar*)key);
|
||||
auto_gchar gchar* escaped_val = ai_json_escape((gchar*)value);
|
||||
if (custom_json->len > 0) {
|
||||
g_string_append_c(custom_json, ',');
|
||||
}
|
||||
g_string_append_printf(custom_json, "\"%s\": %s", escaped_key, escaped_val);
|
||||
}
|
||||
}
|
||||
|
||||
/* Assemble final payload: model, messages, custom settings, then fixed keys */
|
||||
gchar* json_payload;
|
||||
if (custom_json->len > 0) {
|
||||
json_payload = g_strdup_printf(
|
||||
"{\"model\":\"%s\",\"messages\":[%s],%s,\"stream\":false}",
|
||||
escaped_model, messages_json->str, custom_json->str);
|
||||
} else {
|
||||
json_payload = g_strdup_printf(
|
||||
"{\"model\":\"%s\",\"messages\":[%s],\"stream\":false}",
|
||||
escaped_model, messages_json->str);
|
||||
}
|
||||
gchar* json_payload = g_strdup_printf(
|
||||
"{\"model\":\"%s\",\"input\":[%s],\"stream\":false,\"store\":false}",
|
||||
escaped_model, messages_json->str);
|
||||
|
||||
g_string_free(messages_json, TRUE);
|
||||
g_string_free(custom_json, TRUE);
|
||||
return json_payload;
|
||||
}
|
||||
|
||||
@@ -1512,7 +1482,12 @@ ai_parse_response(const gchar* response_json)
|
||||
if (!response_json || strlen(response_json) == 0)
|
||||
return NULL;
|
||||
|
||||
/* OpenAI /v1/chat/completions: {"choices":[{"message":{"content":"..."}}]} */
|
||||
/* Perplexity /v1/agent: {"output":[{"content":[{"text":"...","type":"output_text"}]}]}
|
||||
* Legacy OpenAI: {"choices":[{"message":{"content":"..."}}]} */
|
||||
gchar* text = _extract_json_string(response_json, "text");
|
||||
if (text)
|
||||
return text;
|
||||
|
||||
return _extract_json_string(response_json, "content");
|
||||
}
|
||||
|
||||
@@ -1591,7 +1566,7 @@ _ai_request_thread(gpointer data)
|
||||
/* Build JSON payload from history + prompt (under lock), then add user message to history */
|
||||
log_debug("[AI-THREAD] Building JSON payload...");
|
||||
pthread_mutex_lock(&session->lock);
|
||||
auto_gchar gchar* json_payload = _build_json_payload_from_list(local_provider, local_model, session->history, prompt);
|
||||
auto_gchar gchar* json_payload = _build_json_payload_from_list(local_model, session->history, prompt);
|
||||
|
||||
/* Add user message to history now (it's in JSON but not yet in history) */
|
||||
AIMessage* user_msg = g_new0(AIMessage, 1);
|
||||
@@ -1612,7 +1587,7 @@ _ai_request_thread(gpointer data)
|
||||
|
||||
/* Build request URL */
|
||||
const gchar* api_url = local_provider->api_url;
|
||||
auto_gchar gchar* request_url = g_strdup_printf("%s%sv1/chat/completions", api_url, g_str_has_suffix(api_url, "/") ? "" : "/");
|
||||
auto_gchar gchar* request_url = g_strdup_printf("%s%sv1/responses", api_url, g_str_has_suffix(api_url, "/") ? "" : "/");
|
||||
log_debug("[AI-THREAD] API URL: %s", api_url);
|
||||
log_debug("[AI-THREAD] API Request URL: %s", request_url);
|
||||
log_debug("[AI-THREAD] Model: %s", local_model);
|
||||
|
||||
@@ -47,7 +47,6 @@ static char* _notify_autocomplete(ProfWin* window, const char* const input, gboo
|
||||
static char* _theme_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _spellcheck_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _autoaway_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _autoping_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _autoconnect_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _account_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _who_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
@@ -1057,7 +1056,6 @@ cmd_ac_init(void)
|
||||
|
||||
autocomplete_add(autoping_ac, "set");
|
||||
autocomplete_add(autoping_ac, "timeout");
|
||||
autocomplete_add(autoping_ac, "warning");
|
||||
|
||||
autocomplete_add(plugins_ac, "install");
|
||||
autocomplete_add(plugins_ac, "update");
|
||||
@@ -1409,7 +1407,6 @@ cmd_ac_init(void)
|
||||
g_hash_table_insert(ac_funcs, "/alias", _alias_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/autoaway", _autoaway_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/autoconnect", _autoconnect_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/autoping", _autoping_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/avatar", _avatar_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/ban", _ban_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/blocked", _blocked_autocomplete);
|
||||
@@ -1937,6 +1934,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
|
||||
{ "/prefs", prefs_ac },
|
||||
{ "/disco", disco_ac },
|
||||
{ "/room", room_ac },
|
||||
{ "/autoping", autoping_ac },
|
||||
{ "/mainwin", winpos_ac },
|
||||
{ "/inputwin", winpos_ac },
|
||||
};
|
||||
@@ -4266,20 +4264,6 @@ _executable_autocomplete(ProfWin* window, const char* const input, gboolean prev
|
||||
return result;
|
||||
}
|
||||
|
||||
static char*
|
||||
_autoping_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
{
|
||||
char* result = NULL;
|
||||
|
||||
result = autocomplete_param_with_ac(input, "/autoping", autoping_ac, TRUE, previous);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = autocomplete_param_with_func(input, "/autoping warning", prefs_autocomplete_boolean_choice, previous, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
static char*
|
||||
_lastactivity_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
{
|
||||
|
||||
@@ -1964,14 +1964,12 @@ static const struct cmd_t command_defs[] = {
|
||||
CMD_TAG_CONNECTION)
|
||||
CMD_SYN(
|
||||
"/autoping set <seconds>",
|
||||
"/autoping timeout <seconds>",
|
||||
"/autoping warning on|off")
|
||||
"/autoping timeout <seconds>")
|
||||
CMD_DESC(
|
||||
"Set the interval between sending ping requests to the server to ensure the connection is kept alive.")
|
||||
CMD_ARGS(
|
||||
{ "set <seconds>", "Number of seconds between sending pings, a value of 0 disables autoping." },
|
||||
{ "timeout <seconds>", "Seconds to wait for autoping responses, after which the connection is considered broken." },
|
||||
{ "warning on|off", "Enable or disable autoping availability warning." })
|
||||
{ "timeout <seconds>", "Seconds to wait for autoping responses, after which the connection is considered broken." })
|
||||
},
|
||||
|
||||
{ CMD_PREAMBLE("/ping",
|
||||
|
||||
@@ -6374,8 +6374,6 @@ cmd_autoping(ProfWin* window, const char* const command, gchar** args)
|
||||
cons_bad_cmd_usage(command);
|
||||
}
|
||||
|
||||
} else if (g_strcmp0(cmd, "warning") == 0) {
|
||||
_cmd_set_boolean_preference(value, "Autoping availability warning", PREF_AUTOPING_WARNING);
|
||||
} else {
|
||||
cons_bad_cmd_usage(command);
|
||||
}
|
||||
|
||||
@@ -2290,7 +2290,6 @@ _get_group(preference_t pref)
|
||||
case PREF_TRAY:
|
||||
case PREF_TRAY_READ:
|
||||
case PREF_ADV_NOTIFY_DISCO_OR_VERSION:
|
||||
case PREF_AUTOPING_WARNING:
|
||||
return PREF_GROUP_NOTIFICATIONS;
|
||||
case PREF_DBLOG:
|
||||
case PREF_CHLOG:
|
||||
@@ -2647,8 +2646,6 @@ _get_key(preference_t pref)
|
||||
return "enabled";
|
||||
case PREF_SPELLCHECK_LANG:
|
||||
return "lang";
|
||||
case PREF_AUTOPING_WARNING:
|
||||
return "autoping.warning";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@@ -2702,7 +2699,6 @@ _get_default_boolean(preference_t pref)
|
||||
case PREF_MOOD:
|
||||
case PREF_STROPHE_SM_ENABLED:
|
||||
case PREF_STROPHE_SM_RESEND:
|
||||
case PREF_AUTOPING_WARNING:
|
||||
return TRUE;
|
||||
case PREF_SPELLCHECK_ENABLE:
|
||||
case PREF_PGP_PUBKEY_AUTOIMPORT:
|
||||
|
||||
@@ -169,7 +169,6 @@ typedef enum {
|
||||
PREF_FORCE_ENCRYPTION_MODE,
|
||||
PREF_SPELLCHECK_ENABLE,
|
||||
PREF_SPELLCHECK_LANG,
|
||||
PREF_AUTOPING_WARNING
|
||||
} preference_t;
|
||||
|
||||
typedef struct prof_alias_t
|
||||
|
||||
6
src/gitversion.h.in
Normal file
6
src/gitversion.h.in
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef PROF_GIT_BRANCH
|
||||
#define PROF_GIT_BRANCH @PROF_GIT_BRANCH@
|
||||
#endif
|
||||
#ifndef PROF_GIT_REVISION
|
||||
#define PROF_GIT_REVISION @PROF_GIT_REVISION@
|
||||
#endif
|
||||
@@ -519,15 +519,13 @@ p_gpg_sign(const gchar* const str, const gchar* const fp)
|
||||
}
|
||||
|
||||
gchar*
|
||||
p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gchar* const fp, gchar** err)
|
||||
p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gchar* const fp)
|
||||
{
|
||||
ProfPGPPubKeyId* pubkeyid = g_hash_table_lookup(pubkeys, barejid);
|
||||
if (!pubkeyid) {
|
||||
*err = g_strdup("No PGP key found for recipient");
|
||||
return NULL;
|
||||
}
|
||||
if (!pubkeyid->id) {
|
||||
*err = g_strdup("No key ID found for recipient");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -540,7 +538,6 @@ p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gcha
|
||||
gpgme_ctx_t ctx;
|
||||
gpgme_error_t error = gpgme_new(&ctx);
|
||||
if (error) {
|
||||
*err = g_strdup_printf("Failed to create GPGME context: %s %s", gpgme_strsource(error), gpgme_strerror(error));
|
||||
log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error));
|
||||
return NULL;
|
||||
}
|
||||
@@ -548,7 +545,6 @@ p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gcha
|
||||
gpgme_key_t receiver_key;
|
||||
error = gpgme_get_key(ctx, pubkeyid->id, &receiver_key, 0);
|
||||
if (error || receiver_key == NULL) {
|
||||
*err = g_strdup_printf("Failed to get receiver key '%s': %s %s", pubkeyid->id, gpgme_strsource(error), gpgme_strerror(error));
|
||||
log_error("GPG: Failed to get receiver_key. %s %s", gpgme_strsource(error), gpgme_strerror(error));
|
||||
gpgme_release(ctx);
|
||||
return NULL;
|
||||
@@ -558,10 +554,8 @@ p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gcha
|
||||
gpgme_key_t sender_key = NULL;
|
||||
error = gpgme_get_key(ctx, fp, &sender_key, 0);
|
||||
if (error || sender_key == NULL) {
|
||||
*err = g_strdup_printf("Failed to get sender key '%s': %s %s", fp, gpgme_strsource(error), gpgme_strerror(error));
|
||||
log_error("GPG: Failed to get sender_key. %s %s", gpgme_strsource(error), gpgme_strerror(error));
|
||||
gpgme_release(ctx);
|
||||
gpgme_key_unref(receiver_key);
|
||||
return NULL;
|
||||
}
|
||||
keys[1] = sender_key;
|
||||
@@ -580,8 +574,7 @@ p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gcha
|
||||
gpgme_key_unref(sender_key);
|
||||
|
||||
if (error) {
|
||||
*err = g_strdup_printf("Encryption failed: (%s) %s", gpgme_strsource(error), gpgme_strerror(error));
|
||||
log_error("GPG: Failed to encrypt message. (%s) %s", gpgme_strsource(error), gpgme_strerror(error));
|
||||
log_error("GPG: Failed to encrypt message. %s %s", gpgme_strsource(error), gpgme_strerror(error));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ gboolean p_gpg_available(const gchar* const barejid);
|
||||
const gchar* p_gpg_libver(void);
|
||||
gchar* p_gpg_sign(const gchar* const str, const gchar* const fp);
|
||||
void p_gpg_verify(const gchar* const barejid, const gchar* const sign);
|
||||
gchar* p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gchar* const fp, gchar** err);
|
||||
gchar* p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gchar* const fp);
|
||||
gchar* p_gpg_decrypt(const gchar* const cipher);
|
||||
void p_gpg_free_decrypted(gchar* decrypted);
|
||||
gchar* p_gpg_autocomplete_key(const gchar* const search_str, gboolean previous, void* context);
|
||||
|
||||
@@ -1703,11 +1703,6 @@ cons_notify_setting(void)
|
||||
else
|
||||
cons_show("Subscription requests (/notify sub) : OFF");
|
||||
|
||||
if (prefs_get_boolean(PREF_AUTOPING_WARNING))
|
||||
cons_show("Autoping warning (/autoping warning): ON");
|
||||
else
|
||||
cons_show("Autoping warning (/autoping warning): OFF");
|
||||
|
||||
gint remind_period = prefs_get_notify_remind();
|
||||
if (remind_period == 0) {
|
||||
cons_show("Reminder period (/notify remind) : OFF");
|
||||
@@ -2008,26 +2003,21 @@ cons_autoping_setting(void)
|
||||
{
|
||||
gint autoping_interval = prefs_get_autoping();
|
||||
if (autoping_interval == 0) {
|
||||
cons_show("Autoping interval (/autoping) : OFF");
|
||||
cons_show("Autoping interval (/autoping) : OFF");
|
||||
} else if (autoping_interval == 1) {
|
||||
cons_show("Autoping interval (/autoping) : 1 second");
|
||||
cons_show("Autoping interval (/autoping) : 1 second");
|
||||
} else {
|
||||
cons_show("Autoping interval (/autoping) : %d seconds", autoping_interval);
|
||||
cons_show("Autoping interval (/autoping) : %d seconds", autoping_interval);
|
||||
}
|
||||
|
||||
gint autoping_timeout = prefs_get_autoping_timeout();
|
||||
if (autoping_timeout == 0) {
|
||||
cons_show("Autoping timeout (/autoping) : OFF");
|
||||
cons_show("Autoping timeout (/autoping) : OFF");
|
||||
} else if (autoping_timeout == 1) {
|
||||
cons_show("Autoping timeout (/autoping) : 1 second");
|
||||
cons_show("Autoping timeout (/autoping) : 1 second");
|
||||
} else {
|
||||
cons_show("Autoping timeout (/autoping) : %d seconds", autoping_timeout);
|
||||
cons_show("Autoping timeout (/autoping) : %d seconds", autoping_timeout);
|
||||
}
|
||||
|
||||
if (prefs_get_boolean(PREF_AUTOPING_WARNING))
|
||||
cons_show("Autoping warning (/autoping warning): ON");
|
||||
else
|
||||
cons_show("Autoping warning (/autoping warning): OFF");
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include "ai/ai_client.h"
|
||||
|
||||
static const int PAD_MIN_HEIGHT = 100;
|
||||
static const int PAD_DEAD_SPACE_LIMIT = 2000; // reclaim once the pad holds this much dead space (cursor past live buffer); size-independent, so it never fires while scrolling
|
||||
static const int PAD_THRESHOLD = 12000; // above buffer cap (~9000): reclaims dead pad space, never fires while scrolling
|
||||
static gboolean _in_redraw = FALSE;
|
||||
|
||||
static void
|
||||
@@ -56,10 +56,9 @@ _win_ensure_pad_capacity(ProfWin* window, WINDOW* win, int lines_needed)
|
||||
int cur_height = getmaxy(win);
|
||||
int cur_width = getmaxx(win);
|
||||
if (lines_needed >= cur_height - 1) {
|
||||
// redraw to reclaim dead pad space (cursor far past live buffer, e.g. a long
|
||||
// append-only session); dead space never accrues while scrolling, only here
|
||||
int dead = window ? getcury(win) - window->layout->buffer->lines : 0;
|
||||
if (window && dead > PAD_DEAD_SPACE_LIMIT && !_in_redraw) {
|
||||
// If we are getting too large, trigger a redraw to clean up old lines
|
||||
// but only if we are not already in a redraw process.
|
||||
if (window && cur_height >= PAD_THRESHOLD && !_in_redraw) {
|
||||
win_redraw(window);
|
||||
} else {
|
||||
// resize to required lines + some buffer for next messages
|
||||
@@ -68,20 +67,6 @@ _win_ensure_pad_capacity(ProfWin* window, WINDOW* win, int lines_needed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// upper-bound estimate of rows a message body occupies (hard newlines + soft-wrap), to reserve pad space before printing so a tall message isn't clipped (a clipped height desyncs the scroll offset)
|
||||
static int
|
||||
_win_estimated_lines(WINDOW* win, const char* const message, int indent, int pad_indent)
|
||||
{
|
||||
int usable = MAX(1, getmaxx(win) - (indent + pad_indent));
|
||||
int newlines = 0;
|
||||
for (const char* p = message; *p; p++) {
|
||||
if (*p == '\n') {
|
||||
newlines++;
|
||||
}
|
||||
}
|
||||
return newlines + utf8_display_len(message) / usable + 2;
|
||||
}
|
||||
static const char* LOADING_MESSAGE = "Loading older messages…";
|
||||
static const char* CONS_WIN_TITLE = "CProof. Type /help for help information.";
|
||||
static const char* XML_WIN_TITLE = "XML Console";
|
||||
@@ -2016,7 +2001,7 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
|
||||
}
|
||||
}
|
||||
|
||||
_win_ensure_pad_capacity(window, window->layout->win, getcury(window->layout->win) + _win_estimated_lines(window->layout->win, message + offset, indent, pad_indent));
|
||||
_win_ensure_pad_capacity(window, window->layout->win, getcury(window->layout->win));
|
||||
|
||||
if (prefs_get_boolean(PREF_WRAP)) {
|
||||
_win_print_wrapped(window->layout->win, message + offset, indent, pad_indent);
|
||||
|
||||
@@ -99,7 +99,6 @@ static void _disco_items_result_handler(xmpp_stanza_t* const stanza);
|
||||
static void _last_activity_get_handler(xmpp_stanza_t* const stanza);
|
||||
static void _version_get_handler(xmpp_stanza_t* const stanza);
|
||||
static void _ping_get_handler(xmpp_stanza_t* const stanza);
|
||||
static void _disco_autoping_warning_message(GHashTable* features);
|
||||
|
||||
static int _version_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
@@ -2430,12 +2429,6 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t* const stanza, void* con
|
||||
}
|
||||
child = xmpp_stanza_get_next(child);
|
||||
}
|
||||
|
||||
// Prevent repetitions by avoiding checks of disco items (from connection_set_disco_items)
|
||||
const char* domain = connection_get_domain();
|
||||
if (from && domain && g_ascii_strcasecmp(from, domain) == 0) {
|
||||
_disco_autoping_warning_message(features);
|
||||
}
|
||||
}
|
||||
|
||||
connection_features_received(from);
|
||||
@@ -2443,21 +2436,6 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t* const stanza, void* con
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
_disco_autoping_warning_message(GHashTable* features)
|
||||
{
|
||||
gboolean server_supports_ping = g_hash_table_contains(features, "urn:xmpp:ping");
|
||||
gboolean user_prefers_warning = prefs_get_boolean(PREF_AUTOPING_WARNING);
|
||||
gboolean is_autoping_enabled = prefs_get_autoping() != 0;
|
||||
|
||||
if (!is_autoping_enabled && server_supports_ping && user_prefers_warning) {
|
||||
cons_show("This server supports XEP-0199: XMPP Ping (better keepalive detection),\n"
|
||||
"but autoping feature is currently disabled in settings.\n"
|
||||
"Consider enabling it (e.g., `/autoping set 30`) for improved connection stability.\n"
|
||||
"Use `/autoping warning off` to disable this message.");
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
_http_upload_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
{
|
||||
|
||||
@@ -467,15 +467,12 @@ message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean
|
||||
auto_char char* jid = chat_session_get_jid(barejid);
|
||||
char* id = connection_create_stanza_id();
|
||||
|
||||
ProfWin* current = wins_get_current();
|
||||
|
||||
xmpp_stanza_t* message = NULL;
|
||||
#ifdef HAVE_LIBGPGME
|
||||
ProfAccount* account = accounts_get_account(session_get_account_name());
|
||||
if (account->pgp_keyid) {
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
auto_gchar gchar* err = NULL;
|
||||
auto_gchar gchar* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid, &err);
|
||||
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).");
|
||||
@@ -489,31 +486,18 @@ message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean
|
||||
xmpp_stanza_add_child(message, x);
|
||||
xmpp_stanza_release(x);
|
||||
} else {
|
||||
if (current) {
|
||||
win_println(current, THEME_ERROR, "-", "Unable to encrypt message for %s: %s.", jid, err);
|
||||
}
|
||||
log_error("Message not encrypted for %s: %s.", jid, err);
|
||||
account_free(account);
|
||||
free(id);
|
||||
return NULL;
|
||||
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
||||
xmpp_message_set_body(message, msg);
|
||||
}
|
||||
} else {
|
||||
if (current) {
|
||||
win_println(current, THEME_ERROR, "-", "No PGP key configured for this account.");
|
||||
}
|
||||
log_error("No PGP key configured, message not sent.");
|
||||
account_free(account);
|
||||
free(id);
|
||||
return NULL;
|
||||
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
||||
xmpp_message_set_body(message, msg);
|
||||
}
|
||||
account_free(account);
|
||||
#else
|
||||
if (current) {
|
||||
win_println(current, THEME_ERROR, "-", "LibGPGME not available, message not sent.");
|
||||
}
|
||||
log_error("LibGPGME not available, message not sent.");
|
||||
free(id);
|
||||
return NULL;
|
||||
// ?
|
||||
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
||||
xmpp_message_set_body(message, msg);
|
||||
#endif
|
||||
|
||||
if (state) {
|
||||
@@ -562,10 +546,7 @@ message_send_chat_ox(const char* const barejid, const char* const msg, gboolean
|
||||
xmpp_stanza_to_text(signcrypt, &c, &s);
|
||||
char* signcrypt_e = p_ox_gpg_signcrypt(account->jid, barejid, c);
|
||||
if (signcrypt_e == NULL) {
|
||||
ProfWin* current = wins_get_current();
|
||||
if (current) {
|
||||
win_println(current, THEME_ERROR, "-", "Unable to send OX message. Check log file and profanity-ox-setup man page for details.");
|
||||
}
|
||||
cons_show("Unable to send OX message. Check log file and profanity-ox-setup man page for details.");
|
||||
log_error("Message not signcrypted.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -150,14 +150,6 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(autoping_sends_ping_after_interval),
|
||||
PROF_FUNC_TEST(autoping_server_not_supporting_ping),
|
||||
|
||||
/* Autoping availability warning - negative cases wait ~3s */
|
||||
PROF_FUNC_TEST(autoping_warning_shown_when_disabled),
|
||||
PROF_FUNC_TEST(autoping_warning_not_shown_when_server_unsupported),
|
||||
PROF_FUNC_TEST(autoping_warning_not_shown_when_autoping_enabled),
|
||||
PROF_FUNC_TEST(autoping_warning_not_shown_when_user_disabled),
|
||||
PROF_FUNC_TEST(autoping_warning_not_shown_for_user_jid),
|
||||
PROF_FUNC_TEST(autoping_warning_not_shown_for_subdomain_service),
|
||||
|
||||
/* Service Discovery - XEP-0030 */
|
||||
PROF_FUNC_TEST(disco_info_shows_identity),
|
||||
PROF_FUNC_TEST(disco_info_shows_features),
|
||||
|
||||
@@ -112,144 +112,3 @@ autoping_server_not_supporting_ping(void** state)
|
||||
// Should show error about ping not being supported
|
||||
assert_true(prof_output_regex("Server ping not supported"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Autoping availability warning.
|
||||
*
|
||||
* The warning fires from the on-connect disco handler, so the three inputs
|
||||
* (server ping support, autoping interval, warning preference) must all be
|
||||
* set before prof_connect().
|
||||
*/
|
||||
|
||||
/* Stable substring of the warning text emitted by iq.c. */
|
||||
#define AUTOPING_WARNING_MATCH "This server supports XEP-0199"
|
||||
|
||||
static void
|
||||
_stub_server_disco(gboolean with_ping)
|
||||
{
|
||||
if (with_ping) {
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='Stabber'/>"
|
||||
"<feature var='urn:xmpp:ping'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
} else {
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='Stabber'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
autoping_warning_shown_when_disabled(void** state)
|
||||
{
|
||||
// All conditions met: server supports ping, autoping off, warning on (default).
|
||||
_stub_server_disco(TRUE);
|
||||
|
||||
prof_input("/autoping set 0");
|
||||
assert_true(prof_output_exact("Autoping disabled."));
|
||||
|
||||
prof_connect();
|
||||
|
||||
assert_true(prof_output_regex(AUTOPING_WARNING_MATCH));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_warning_not_shown_when_server_unsupported(void** state)
|
||||
{
|
||||
// Server does not advertise urn:xmpp:ping -> no warning even with autoping off.
|
||||
_stub_server_disco(FALSE);
|
||||
|
||||
prof_input("/autoping set 0");
|
||||
assert_true(prof_output_exact("Autoping disabled."));
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
||||
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_warning_not_shown_when_autoping_enabled(void** state)
|
||||
{
|
||||
// Warning is suppressed while autoping is enabled.
|
||||
_stub_server_disco(TRUE);
|
||||
|
||||
prof_input("/autoping set 30");
|
||||
assert_true(prof_output_exact("Autoping interval set to 30 seconds."));
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
||||
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_warning_not_shown_when_user_disabled(void** state)
|
||||
{
|
||||
// User opted out -> no warning.
|
||||
_stub_server_disco(TRUE);
|
||||
|
||||
prof_input("/autoping set 0");
|
||||
assert_true(prof_output_exact("Autoping disabled."));
|
||||
|
||||
prof_input("/autoping warning off");
|
||||
assert_true(prof_output_exact("Autoping availability warning disabled."));
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
||||
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_warning_not_shown_for_user_jid(void** state)
|
||||
{
|
||||
// disco#info from a user JID (with '@') should not trigger the warning,
|
||||
// only server responses (no '@') should.
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='buddy1@localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='person' type='chat' name='Buddy1'/>"
|
||||
"<feature var='urn:xmpp:ping'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_input("/autoping set 0");
|
||||
assert_true(prof_output_exact("Autoping disabled."));
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
||||
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_warning_not_shown_for_subdomain_service(void** state)
|
||||
{
|
||||
// disco#info from a subdomain service should not trigger the warning, only the server's own domain should
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='conf.localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='conference' type='text' name='Conference Service'/>"
|
||||
"<feature var='urn:xmpp:ping'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_input("/autoping set 0");
|
||||
assert_true(prof_output_exact("Autoping disabled."));
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
||||
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
||||
}
|
||||
|
||||
@@ -4,9 +4,3 @@ void autoping_timeout_set(void** state);
|
||||
void autoping_timeout_zero_disables(void** state);
|
||||
void autoping_sends_ping_after_interval(void** state);
|
||||
void autoping_server_not_supporting_ping(void** state);
|
||||
void autoping_warning_shown_when_disabled(void** state);
|
||||
void autoping_warning_not_shown_when_server_unsupported(void** state);
|
||||
void autoping_warning_not_shown_when_autoping_enabled(void** state);
|
||||
void autoping_warning_not_shown_when_user_disabled(void** state);
|
||||
void autoping_warning_not_shown_for_user_jid(void** state);
|
||||
void autoping_warning_not_shown_for_subdomain_service(void** state);
|
||||
|
||||
Reference in New Issue
Block a user