Compare commits
14 Commits
feat/autop
...
feat/disco
| Author | SHA1 | Date | |
|---|---|---|---|
|
b7dec705c3
|
|||
|
b208e48ee1
|
|||
|
c5dd0cf9df
|
|||
|
b34faa2099
|
|||
|
756d4e18cf
|
|||
|
5d7b7bb23d
|
|||
|
fa6857f4c8
|
|||
|
9913344bbf
|
|||
|
91631aa91a
|
|||
|
622054fc6d
|
|||
|
ca92d29179
|
|||
|
72aa603147
|
|||
|
15dfc2bdb4
|
|||
|
02e679c277
|
@@ -186,6 +186,22 @@ ai_json_escape(const gchar* str)
|
||||
return g_string_free(result, FALSE);
|
||||
}
|
||||
|
||||
/* Keys emitted as fixed payload fields; custom settings must not duplicate them */
|
||||
static gboolean
|
||||
_is_reserved_payload_key(const gchar* key)
|
||||
{
|
||||
return g_strcmp0(key, "model") == 0 || g_strcmp0(key, "messages") == 0 || g_strcmp0(key, "stream") == 0;
|
||||
}
|
||||
|
||||
/* RFC 8259 scalars (number/true/false/null) may be emitted bare in a JSON payload */
|
||||
static gboolean
|
||||
_is_json_bare_token(const gchar* value)
|
||||
{
|
||||
if (g_strcmp0(value, "true") == 0 || g_strcmp0(value, "false") == 0 || g_strcmp0(value, "null") == 0)
|
||||
return TRUE;
|
||||
return g_regex_match_simple("^-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][+-]?[0-9]+)?$", value, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a 4-hex-digit sequence at @p to a 16-bit code point.
|
||||
* Returns -1 on invalid hex.
|
||||
@@ -392,6 +408,7 @@ ai_provider_new(const gchar* name, const gchar* api_url)
|
||||
provider->models = NULL;
|
||||
provider->models_fresh = FALSE;
|
||||
provider->ref_count = 1;
|
||||
pthread_mutex_init(&provider->settings_lock, NULL);
|
||||
return provider;
|
||||
}
|
||||
|
||||
@@ -419,6 +436,7 @@ ai_provider_unref(AIProvider* provider)
|
||||
g_free(provider->project_id);
|
||||
g_free(provider->default_model);
|
||||
g_hash_table_destroy(provider->settings);
|
||||
pthread_mutex_destroy(&provider->settings_lock);
|
||||
|
||||
GList* curr = provider->models;
|
||||
while (curr) {
|
||||
@@ -729,31 +747,44 @@ ai_get_provider_default_model(const gchar* provider_name)
|
||||
return provider->default_model;
|
||||
}
|
||||
|
||||
void
|
||||
gboolean
|
||||
ai_set_provider_setting(const gchar* provider_name, const gchar* setting, const gchar* value)
|
||||
{
|
||||
if (!provider_name || !setting)
|
||||
return;
|
||||
return FALSE;
|
||||
|
||||
if (_is_reserved_payload_key(setting)) {
|
||||
log_warning("Setting '%s' for provider '%s' rejected: reserved payload key", setting, provider_name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
AIProvider* provider = ai_get_provider(provider_name);
|
||||
if (!provider) {
|
||||
log_warning("Provider '%s' not found for setting '%s'", provider_name, setting);
|
||||
return;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* settings is iterated by the request thread; mutate under settings_lock */
|
||||
pthread_mutex_lock(&provider->settings_lock);
|
||||
if (!provider->settings) {
|
||||
provider->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
}
|
||||
|
||||
if (value) {
|
||||
g_hash_table_insert(provider->settings, g_strdup(setting), g_strdup(value));
|
||||
} else {
|
||||
g_hash_table_remove(provider->settings, setting);
|
||||
}
|
||||
pthread_mutex_unlock(&provider->settings_lock);
|
||||
|
||||
if (value) {
|
||||
prefs_ai_set_setting(provider_name, setting, value);
|
||||
log_info("Setting '%s' for provider '%s' set to: %s", setting, provider_name, value);
|
||||
} else {
|
||||
g_hash_table_remove(provider->settings, setting);
|
||||
prefs_ai_remove_setting(provider_name, setting);
|
||||
log_info("Setting '%s' removed for provider '%s'", setting, provider_name);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gchar*
|
||||
@@ -766,8 +797,10 @@ ai_get_provider_setting(const gchar* provider_name, const gchar* setting)
|
||||
if (!provider || !provider->settings)
|
||||
return NULL;
|
||||
|
||||
gchar* value = g_hash_table_lookup(provider->settings, setting);
|
||||
return g_strdup(value);
|
||||
pthread_mutex_lock(&provider->settings_lock);
|
||||
gchar* value = g_strdup(g_hash_table_lookup(provider->settings, setting));
|
||||
pthread_mutex_unlock(&provider->settings_lock);
|
||||
return value;
|
||||
}
|
||||
|
||||
/* ========================================================================
|
||||
@@ -1435,13 +1468,19 @@ 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 "messages": scalar values
|
||||
* (number/true/false/null) are emitted bare, anything else as a JSON string;
|
||||
* reserved keys (model/messages/stream) are skipped.
|
||||
*
|
||||
* @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(const gchar* model, GList* history, const gchar* prompt)
|
||||
_build_json_payload_from_list(AIProvider* provider, const gchar* model, GList* history, const gchar* prompt)
|
||||
{
|
||||
GString* messages_json = g_string_new("");
|
||||
GList* curr = history;
|
||||
@@ -1468,11 +1507,50 @@ _build_json_payload_from_list(const gchar* model, GList* history, const gchar* p
|
||||
g_string_append_printf(messages_json, "{\"role\":\"user\",\"content\":\"%s\"}", escaped_prompt);
|
||||
|
||||
auto_gchar gchar* escaped_model = ai_json_escape(model);
|
||||
gchar* json_payload = g_strdup_printf(
|
||||
"{\"model\":\"%s\",\"input\":[%s],\"stream\":false,\"store\":false}",
|
||||
escaped_model, messages_json->str);
|
||||
|
||||
/* Build custom settings JSON fragment; settings is mutated on the main
|
||||
* thread (/ai set custom), so iterate under settings_lock */
|
||||
GString* custom_json = g_string_new("");
|
||||
if (provider) {
|
||||
pthread_mutex_lock(&provider->settings_lock);
|
||||
if (provider->settings) {
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
g_hash_table_iter_init(&iter, provider->settings);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
if (_is_reserved_payload_key((gchar*)key)) {
|
||||
continue; /* fixed payload fields stay authoritative */
|
||||
}
|
||||
auto_gchar gchar* escaped_key = ai_json_escape((gchar*)key);
|
||||
if (custom_json->len > 0) {
|
||||
g_string_append_c(custom_json, ',');
|
||||
}
|
||||
if (_is_json_bare_token((gchar*)value)) {
|
||||
g_string_append_printf(custom_json, "\"%s\": %s", escaped_key, (gchar*)value);
|
||||
} else {
|
||||
/* non-scalar values must be quoted, else the payload is invalid JSON */
|
||||
auto_gchar gchar* escaped_val = ai_json_escape((gchar*)value);
|
||||
g_string_append_printf(custom_json, "\"%s\": \"%s\"", escaped_key, escaped_val);
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&provider->settings_lock);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
g_string_free(messages_json, TRUE);
|
||||
g_string_free(custom_json, TRUE);
|
||||
return json_payload;
|
||||
}
|
||||
|
||||
@@ -1482,12 +1560,7 @@ ai_parse_response(const gchar* response_json)
|
||||
if (!response_json || strlen(response_json) == 0)
|
||||
return NULL;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* OpenAI /v1/chat/completions: {"choices":[{"message":{"content":"..."}}]} */
|
||||
return _extract_json_string(response_json, "content");
|
||||
}
|
||||
|
||||
@@ -1566,7 +1639,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_model, session->history, prompt);
|
||||
auto_gchar gchar* json_payload = _build_json_payload_from_list(local_provider, 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);
|
||||
@@ -1587,7 +1660,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/responses", api_url, g_str_has_suffix(api_url, "/") ? "" : "/");
|
||||
auto_gchar gchar* request_url = g_strdup_printf("%s%sv1/chat/completions", 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);
|
||||
|
||||
@@ -17,14 +17,15 @@ typedef struct ai_message_t
|
||||
*/
|
||||
typedef struct ai_provider_t
|
||||
{
|
||||
gchar* name; /* Provider name (e.g., "openai", "perplexity") */
|
||||
gchar* api_url; /* API endpoint URL */
|
||||
gchar* project_id; /* Optional project ID (for some providers) */
|
||||
gchar* default_model; /* Default model for this provider */
|
||||
GHashTable* settings; /* Extensible per-provider settings (e.g., tools=enabled, search=disabled) */
|
||||
GList* models; /* Cached models (gchar*) */
|
||||
gboolean models_fresh; /* Whether models cache is current */
|
||||
gint32 ref_count; /* Reference count (atomic) */
|
||||
gchar* name; /* Provider name (e.g., "openai", "perplexity") */
|
||||
gchar* api_url; /* API endpoint URL */
|
||||
gchar* project_id; /* Optional project ID (for some providers) */
|
||||
gchar* default_model; /* Default model for this provider */
|
||||
pthread_mutex_t settings_lock; /* Protects settings (iterated by the request thread) */
|
||||
GHashTable* settings; /* Extensible per-provider settings (e.g., temperature=0.7) */
|
||||
GList* models; /* Cached models (gchar*) */
|
||||
gboolean models_fresh; /* Whether models cache is current */
|
||||
gint32 ref_count; /* Reference count (atomic) */
|
||||
} AIProvider;
|
||||
|
||||
/**
|
||||
@@ -142,11 +143,13 @@ const gchar* ai_get_provider_default_model(const gchar* provider_name);
|
||||
|
||||
/**
|
||||
* Set a custom setting for a provider.
|
||||
* Reserved payload keys (model, messages, stream) are rejected.
|
||||
* @param provider_name The provider name
|
||||
* @param setting The setting key (e.g., "tools", "search")
|
||||
* @param value The setting value
|
||||
* @param setting The setting key (e.g., "temperature")
|
||||
* @param value The setting value, or NULL to remove
|
||||
* @return TRUE on success, FALSE on unknown provider or reserved key
|
||||
*/
|
||||
void ai_set_provider_setting(const gchar* provider_name, const gchar* setting, const gchar* value);
|
||||
gboolean ai_set_provider_setting(const gchar* provider_name, const gchar* setting, const gchar* value);
|
||||
|
||||
/**
|
||||
* Get a custom setting for a provider.
|
||||
@@ -184,9 +187,9 @@ gboolean ai_models_are_fresh(const gchar* provider_name);
|
||||
void ai_parse_models_from_json(AIProvider* provider, const gchar* json);
|
||||
|
||||
/**
|
||||
* Extract assistant content from an LLM response body. Tries Perplexity
|
||||
* /v1/responses "text" first, falls back to OpenAI "content". Decodes
|
||||
* the \" and \n escape sequences only.
|
||||
* Extract assistant content from an OpenAI chat-completions response body
|
||||
* ({"choices":[{"message":{"content":"..."}}]}). Decodes the \" and \n
|
||||
* escape sequences only.
|
||||
* @param response_json The JSON body from the provider
|
||||
* @return Newly allocated content string, or NULL if not found (caller frees)
|
||||
*/
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include "ai/ai_client.h"
|
||||
|
||||
static char* _caps_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _sub_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _notify_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _theme_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
@@ -109,6 +110,8 @@ static char* _software_autocomplete(ProfWin* window, const char* const input, gb
|
||||
static char* _url_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _executable_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _lastactivity_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _disco_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _roster_jid_autocomplete(const char* const input, const char* const prefix, gboolean previous);
|
||||
static char* _intype_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _mood_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
static char* _strophe_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||
@@ -121,6 +124,7 @@ static char* _ai_autocomplete(ProfWin* window, const char* const input, gboolean
|
||||
static char* _script_autocomplete_func(const char* const prefix, gboolean previous, void* context);
|
||||
|
||||
static char* _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previous);
|
||||
static gboolean _is_connected(void);
|
||||
|
||||
static Autocomplete commands_ac;
|
||||
static Autocomplete who_room_ac;
|
||||
@@ -151,6 +155,7 @@ static Autocomplete account_clear_ac;
|
||||
static Autocomplete account_default_ac;
|
||||
static Autocomplete account_status_ac;
|
||||
static Autocomplete disco_ac;
|
||||
static Autocomplete caps_subcommands_ac;
|
||||
static Autocomplete wins_ac;
|
||||
static Autocomplete roster_ac;
|
||||
static Autocomplete roster_show_ac;
|
||||
@@ -321,6 +326,7 @@ static Autocomplete* all_acs[] = {
|
||||
&account_default_ac,
|
||||
&account_status_ac,
|
||||
&disco_ac,
|
||||
&caps_subcommands_ac,
|
||||
&wins_ac,
|
||||
&roster_ac,
|
||||
&roster_show_ac,
|
||||
@@ -597,6 +603,8 @@ cmd_ac_init(void)
|
||||
autocomplete_add(disco_ac, "info");
|
||||
autocomplete_add(disco_ac, "items");
|
||||
|
||||
autocomplete_add(caps_subcommands_ac, "clear");
|
||||
|
||||
autocomplete_add(account_ac, "list");
|
||||
autocomplete_add(account_ac, "show");
|
||||
autocomplete_add(account_ac, "add");
|
||||
@@ -1414,12 +1422,14 @@ cmd_ac_init(void)
|
||||
g_hash_table_insert(ac_funcs, "/ban", _ban_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/blocked", _blocked_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/bookmark", _bookmark_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/caps", _caps_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/clear", _clear_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/close", _close_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/cmd", _adhoc_cmd_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/color", _color_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/connect", _connect_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/console", _console_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/disco", _disco_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/correct", _correct_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/correction", _correction_autocomplete);
|
||||
g_hash_table_insert(ac_funcs, "/executable", _executable_autocomplete);
|
||||
@@ -1856,10 +1866,12 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
|
||||
}
|
||||
|
||||
gchar* history_jid_subcmds[] = { "/history verify", "/history export", "/history import" };
|
||||
for (size_t i = 0; i < ARRAY_SIZE(history_jid_subcmds); i++) {
|
||||
result = autocomplete_param_with_func(input, history_jid_subcmds[i], roster_barejid_autocomplete, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
for (size_t i = 0; i < ARRAY_SIZE(history_jid_subcmds); i++) {
|
||||
result = autocomplete_param_with_func(input, history_jid_subcmds[i], roster_barejid_autocomplete, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1935,7 +1947,6 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
|
||||
Autocomplete completer;
|
||||
} ac_cmds[] = {
|
||||
{ "/prefs", prefs_ac },
|
||||
{ "/disco", disco_ac },
|
||||
{ "/room", room_ac },
|
||||
{ "/mainwin", winpos_ac },
|
||||
{ "/inputwin", winpos_ac },
|
||||
@@ -1985,6 +1996,69 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_is_connected(void)
|
||||
{
|
||||
return connection_get_status() == JABBER_CONNECTED;
|
||||
}
|
||||
|
||||
static char*
|
||||
_roster_jid_autocomplete(const char* const input, const char* const prefix, gboolean previous)
|
||||
{
|
||||
if (!_is_connected()) {
|
||||
return NULL;
|
||||
}
|
||||
char* result = NULL;
|
||||
result = autocomplete_param_with_func(input, prefix, roster_contact_autocomplete, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, prefix, roster_barejid_autocomplete, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, prefix, roster_fulljid_autocomplete, previous, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
static char*
|
||||
_caps_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
{
|
||||
char* result = NULL;
|
||||
result = autocomplete_param_with_ac(input, "/caps", caps_subcommands_ac, TRUE, previous);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
if (window->type == WIN_MUC) {
|
||||
ProfMucWin* mucwin = (ProfMucWin*)window;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
|
||||
if (nick_ac) {
|
||||
result = autocomplete_param_with_ac(input, "/caps", nick_ac, TRUE, previous);
|
||||
}
|
||||
} else {
|
||||
result = _roster_jid_autocomplete(input, "/caps", previous);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static char*
|
||||
_disco_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
{
|
||||
char* result = NULL;
|
||||
result = autocomplete_param_with_ac(input, "/disco", disco_ac, TRUE, previous);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = _roster_jid_autocomplete(input, "/disco info", previous);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = _roster_jid_autocomplete(input, "/disco items", previous);
|
||||
return result;
|
||||
}
|
||||
|
||||
static char*
|
||||
_sub_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
{
|
||||
@@ -3663,7 +3737,7 @@ _win_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
}
|
||||
|
||||
char* unquoted = strip_arg_quotes(input);
|
||||
result = autocomplete_param_with_func(unquoted, "/win", roster_contact_autocomplete, previous, NULL);
|
||||
result = _roster_jid_autocomplete(input, "/win", previous);
|
||||
free(unquoted);
|
||||
return result;
|
||||
}
|
||||
@@ -3997,18 +4071,14 @@ _invite_autocomplete(ProfWin* window, const char* const input, gboolean previous
|
||||
return result;
|
||||
}
|
||||
|
||||
jabber_conn_status_t conn_status = connection_get_status();
|
||||
result = _roster_jid_autocomplete(input, "/invite send", previous);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
result = autocomplete_param_with_func(input, "/invite send", roster_contact_autocomplete, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = autocomplete_param_with_func(input, "/invite decline", muc_invites_find, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/invite decline", muc_invites_find, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -4024,43 +4094,38 @@ _status_autocomplete(ProfWin* window, const char* const input, gboolean previous
|
||||
return result;
|
||||
}
|
||||
|
||||
jabber_conn_status_t conn_status = connection_get_status();
|
||||
// complete with: online, away etc.
|
||||
result = autocomplete_param_with_ac(input, "/status set", account_status_ac, TRUE, previous);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
// Remove quote character before and after names when doing autocomplete
|
||||
char* unquoted = strip_arg_quotes(input);
|
||||
|
||||
// complete with: online, away etc.
|
||||
result = autocomplete_param_with_ac(input, "/status set", account_status_ac, TRUE, previous);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Remove quote character before and after names when doing autocomplete
|
||||
char* unquoted = strip_arg_quotes(input);
|
||||
|
||||
// MUC completion with nicknames
|
||||
if (window->type == WIN_MUC) {
|
||||
ProfMucWin* mucwin = (ProfMucWin*)window;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
|
||||
if (nick_ac) {
|
||||
result = autocomplete_param_with_ac(unquoted, "/status get", nick_ac, TRUE, previous);
|
||||
if (result) {
|
||||
free(unquoted);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// roster completion
|
||||
} else {
|
||||
result = autocomplete_param_with_func(unquoted, "/status get", roster_contact_autocomplete, previous, NULL);
|
||||
// MUC completion with nicknames
|
||||
if (window->type == WIN_MUC) {
|
||||
ProfMucWin* mucwin = (ProfMucWin*)window;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
|
||||
if (nick_ac) {
|
||||
result = autocomplete_param_with_ac(unquoted, "/status get", nick_ac, TRUE, previous);
|
||||
if (result) {
|
||||
free(unquoted);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
free(unquoted);
|
||||
// roster completion
|
||||
} else {
|
||||
result = _roster_jid_autocomplete(input, "/status get", previous);
|
||||
if (result) {
|
||||
free(unquoted);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
free(unquoted);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -4167,14 +4232,12 @@ _software_autocomplete(ProfWin* window, const char* const input, gboolean previo
|
||||
{
|
||||
char* result = NULL;
|
||||
|
||||
if (window->type == WIN_CHAT) {
|
||||
if (window->type == WIN_CHAT && _is_connected()) {
|
||||
ProfChatWin* chatwin = (ProfChatWin*)window;
|
||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||
|
||||
GString* search_str = g_string_new("/software ");
|
||||
g_string_append(search_str, chatwin->barejid);
|
||||
result = autocomplete_param_with_func(search_str->str, "/software", roster_fulljid_autocomplete, previous, NULL);
|
||||
g_string_free(search_str, TRUE);
|
||||
auto_gchar gchar* search_str = g_strdup_printf("/software %s", chatwin->barejid);
|
||||
result = autocomplete_param_with_func(search_str, "/software", roster_fulljid_autocomplete, previous, NULL);
|
||||
} else if (window->type == WIN_MUC) {
|
||||
ProfMucWin* mucwin = (ProfMucWin*)window;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
@@ -4188,10 +4251,7 @@ _software_autocomplete(ProfWin* window, const char* const input, gboolean previo
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = autocomplete_param_with_func(input, "/software", roster_fulljid_autocomplete, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = _roster_jid_autocomplete(input, "/software", previous);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -4290,16 +4350,11 @@ _lastactivity_autocomplete(ProfWin* window, const char* const input, gboolean pr
|
||||
return result;
|
||||
}
|
||||
|
||||
jabber_conn_status_t conn_status = connection_get_status();
|
||||
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
|
||||
result = autocomplete_param_with_func(input, "/lastactivity set", prefs_autocomplete_boolean_choice, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/lastactivity get", roster_barejid_autocomplete, previous, NULL);
|
||||
result = autocomplete_param_with_func(input, "/lastactivity set", prefs_autocomplete_boolean_choice, previous, NULL);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = _roster_jid_autocomplete(input, "/lastactivity get", previous);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -4479,19 +4534,19 @@ _vcard_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
} else {
|
||||
char* unquoted = strip_arg_quotes(input);
|
||||
|
||||
result = autocomplete_param_with_func(unquoted, "/vcard get", roster_contact_autocomplete, previous, NULL);
|
||||
result = _roster_jid_autocomplete(input, "/vcard get", previous);
|
||||
if (result) {
|
||||
free(unquoted);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = autocomplete_param_with_func(unquoted, "/vcard photo open", roster_contact_autocomplete, previous, NULL);
|
||||
result = _roster_jid_autocomplete(input, "/vcard photo open", previous);
|
||||
if (result) {
|
||||
free(unquoted);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = autocomplete_param_with_func(unquoted, "/vcard photo save", roster_contact_autocomplete, previous, NULL);
|
||||
result = _roster_jid_autocomplete(input, "/vcard photo save", previous);
|
||||
if (result) {
|
||||
free(unquoted);
|
||||
return result;
|
||||
|
||||
@@ -427,17 +427,21 @@ static const struct cmd_t command_defs[] = {
|
||||
CMD_TAG_GROUPCHAT)
|
||||
CMD_SYN(
|
||||
"/caps",
|
||||
"/caps <fulljid>|<nick>")
|
||||
"/caps <fulljid>|<nick>",
|
||||
"/caps clear")
|
||||
CMD_DESC(
|
||||
"Find out a contacts, or room members client software capabilities. "
|
||||
"If in private chat initiated from a chat room, no parameter is required.")
|
||||
"If in private chat initiated from a chat room, no parameter is required. "
|
||||
"Use clear to remove all cached capabilities.")
|
||||
CMD_ARGS(
|
||||
{ "<fulljid>", "If in the console or a chat window, the full JID for which you wish to see capabilities." },
|
||||
{ "<nick>", "If in a chat room, nickname for which you wish to see capabilities." })
|
||||
{ "<nick>", "If in a chat room, nickname for which you wish to see capabilities." },
|
||||
{ "clear", "Clear all cached capabilities." })
|
||||
CMD_EXAMPLES(
|
||||
"/caps ran@cold.sea.org/laptop",
|
||||
"/caps ran@cold.sea.org/phone",
|
||||
"/caps aegir")
|
||||
"/caps aegir",
|
||||
"/caps clear")
|
||||
},
|
||||
|
||||
{ CMD_PREAMBLE("/software",
|
||||
@@ -2833,7 +2837,7 @@ static const struct cmd_t command_defs[] = {
|
||||
{ "set provider <name> <url>", "Add or update a provider with custom API endpoint" },
|
||||
{ "set token <provider> <token>", "Set API token for a provider (e.g., openai, perplexity)" },
|
||||
{ "set default-model <provider> <model>", "Set default model for a provider" },
|
||||
{ "set custom <provider> <setting> <value>", "Set provider-level setting (e.g., tools, search)" },
|
||||
{ "set custom <provider> <setting> <value>", "Set provider-level setting (e.g., temperature, max_tokens)" },
|
||||
{ "remove provider <name>", "Remove a custom provider" },
|
||||
{ "providers", "List configured providers with full details" },
|
||||
{ "start <provider> [<model>]", "Start new AI chat (space-separated, uses defaults if omitted)" },
|
||||
@@ -2846,7 +2850,7 @@ static const struct cmd_t command_defs[] = {
|
||||
"/ai set token perplexity pplx-xxx",
|
||||
"/ai set provider custom https://my-api.com/v1/chat/completions",
|
||||
"/ai set default-model perplexity sonar",
|
||||
"/ai set custom perplexity tools enabled",
|
||||
"/ai set custom perplexity temperature 0.7",
|
||||
"/ai remove provider custom",
|
||||
"/ai start",
|
||||
"/ai start perplexity",
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
#include "xmpp/stanza.h"
|
||||
#include "xmpp/vcard_funcs.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "xmpp/capabilities.h"
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
#include "otr/otr.h"
|
||||
@@ -109,6 +110,15 @@ static gboolean _cmd_execute_default(ProfWin* window, const char* inp);
|
||||
static gboolean _cmd_execute_alias(ProfWin* window, const char* const inp, gboolean* ran);
|
||||
static gboolean
|
||||
_download_install_plugin(ProfWin* window, gchar* url, gchar* path);
|
||||
static const gchar*
|
||||
_resolve_contact_jid(const char* const name)
|
||||
{
|
||||
char* barejid = roster_barejid_from_name(name);
|
||||
if (barejid == NULL) {
|
||||
barejid = (char*)name;
|
||||
}
|
||||
return barejid;
|
||||
}
|
||||
|
||||
static void
|
||||
_vcard_editor_finished_cb(gchar* message, void* user_data)
|
||||
@@ -3387,6 +3397,12 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "clear") == 0) {
|
||||
caps_cache_clear();
|
||||
cons_show("Capabilities cache cleared.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
switch (window->type) {
|
||||
case WIN_MUC:
|
||||
if (args[0]) {
|
||||
@@ -3405,8 +3421,9 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
|
||||
break;
|
||||
case WIN_CHAT:
|
||||
case WIN_CONSOLE:
|
||||
case WIN_XML:
|
||||
if (args[0]) {
|
||||
auto_jid Jid* jid = jid_create(args[0]);
|
||||
auto_jid Jid* jid = jid_create(_resolve_contact_jid(args[0]));
|
||||
|
||||
if (jid == NULL || jid->fulljid == NULL) {
|
||||
cons_show("You must provide a full jid to the /caps command.");
|
||||
@@ -3448,7 +3465,7 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
|
||||
static void
|
||||
_send_software_version_iq_to_fulljid(char* request)
|
||||
_send_software_version_iq_to_fulljid(const gchar* const request)
|
||||
{
|
||||
auto_jid Jid* jid = jid_create(request);
|
||||
|
||||
@@ -3489,7 +3506,7 @@ cmd_software(ProfWin* window, const char* const command, gchar** args)
|
||||
break;
|
||||
case WIN_CHAT:
|
||||
if (args[0]) {
|
||||
_send_software_version_iq_to_fulljid(args[0]);
|
||||
_send_software_version_iq_to_fulljid(_resolve_contact_jid(args[0]));
|
||||
break;
|
||||
} else {
|
||||
ProfChatWin* chatwin = (ProfChatWin*)window;
|
||||
@@ -3513,7 +3530,7 @@ cmd_software(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
case WIN_CONSOLE:
|
||||
if (args[0]) {
|
||||
_send_software_version_iq_to_fulljid(args[0]);
|
||||
_send_software_version_iq_to_fulljid(_resolve_contact_jid(args[0]));
|
||||
} else {
|
||||
cons_show("You must provide a jid to the /software command.");
|
||||
}
|
||||
@@ -4823,7 +4840,7 @@ cmd_disco(ProfWin* window, const char* const command, gchar** args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto_gchar gchar* jid = g_strdup_printf("%s", args[1] ?: connection_get_jid()->domainpart);
|
||||
auto_gchar gchar* jid = g_strdup_printf("%s", args[1] ? _resolve_contact_jid(args[1]) : connection_get_jid()->domainpart);
|
||||
|
||||
if (g_strcmp0(args[0], "info") == 0) {
|
||||
iq_disco_info_request(jid);
|
||||
@@ -5045,7 +5062,7 @@ cmd_lastactivity(ProfWin* window, const char* const command, gchar** args)
|
||||
if (args[1] == NULL) {
|
||||
iq_last_activity_request(connection_get_jid()->domainpart);
|
||||
} else {
|
||||
iq_last_activity_request(args[1]);
|
||||
iq_last_activity_request(_resolve_contact_jid(args[1]));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -6398,17 +6415,17 @@ cmd_ping(ProfWin* window, const char* const command, gchar** args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (args[0] != NULL && caps_jid_has_feature(args[0], XMPP_FEATURE_PING) == FALSE) {
|
||||
cons_show("%s does not support ping requests.", args[0]);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
iq_send_ping(args[0]);
|
||||
|
||||
if (args[0] == NULL) {
|
||||
cons_show("Pinged server…");
|
||||
if (args[0] != NULL) {
|
||||
const gchar* ping_target = _resolve_contact_jid(args[0]);
|
||||
if (caps_jid_has_feature(ping_target, XMPP_FEATURE_PING) == FALSE) {
|
||||
cons_show("%s does not support ping requests.", ping_target);
|
||||
return TRUE;
|
||||
}
|
||||
iq_send_ping(ping_target);
|
||||
cons_show("Pinged %s…", ping_target);
|
||||
} else {
|
||||
cons_show("Pinged %s…", args[0]);
|
||||
iq_send_ping(NULL);
|
||||
cons_show("Pinged server…");
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -10787,8 +10804,11 @@ cmd_ai_set(ProfWin* window, const char* const command, gchar** args)
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
ai_set_provider_setting(args[2], args[3], args[4]);
|
||||
cons_show("Setting '%s' for provider '%s' set to: %s", args[3], args[2], args[4]);
|
||||
if (ai_set_provider_setting(args[2], args[3], args[4])) {
|
||||
cons_show("Setting '%s' for provider '%s' set to: %s", args[3], args[2], args[4]);
|
||||
} else {
|
||||
cons_show_error("Cannot set '%s' for provider '%s': unknown provider or reserved key (model, messages, stream).", args[3], args[2]);
|
||||
}
|
||||
cons_show("");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -921,7 +921,7 @@ prof_date_time_format_iso8601(GDateTime* dt)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* build profanity version string.
|
||||
/* build CProof version string.
|
||||
* example: 0.13.1dev.master.69d8c1f9
|
||||
*/
|
||||
gchar*
|
||||
|
||||
@@ -522,7 +522,7 @@ accounts_set_script_start(const char* const account_name, const char* const valu
|
||||
void
|
||||
accounts_set_client(const char* const account_name, const char* const value)
|
||||
{
|
||||
_accounts_set_string_option(account_name, "client.name", value);
|
||||
_accounts_set_string_option(account_name, "client.account_name", value);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -576,7 +576,7 @@ accounts_clear_script_start(const char* const account_name)
|
||||
void
|
||||
accounts_clear_client(const char* const account_name)
|
||||
{
|
||||
_accounts_clear_string_option(account_name, "client.name");
|
||||
_accounts_clear_string_option(account_name, "client.account_name");
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -2689,7 +2689,6 @@ _get_default_boolean(preference_t pref)
|
||||
case PREF_STATUSBAR_SHOW_NUMBER:
|
||||
case PREF_STATUSBAR_SHOW_READ:
|
||||
case PREF_STATUSBAR_SHOW_DBBACKEND:
|
||||
case PREF_REVEAL_OS:
|
||||
case PREF_CORRECTION_ALLOW:
|
||||
case PREF_RECEIPTS_SEND:
|
||||
case PREF_CARBONS:
|
||||
@@ -2704,6 +2703,7 @@ _get_default_boolean(preference_t pref)
|
||||
case PREF_STROPHE_SM_RESEND:
|
||||
case PREF_AUTOPING_WARNING:
|
||||
return TRUE;
|
||||
case PREF_REVEAL_OS:
|
||||
case PREF_SPELLCHECK_ENABLE:
|
||||
case PREF_PGP_PUBKEY_AUTOIMPORT:
|
||||
case PREF_FORCE_ENCRYPTION:
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef PROF_GIT_BRANCH
|
||||
#define PROF_GIT_BRANCH @PROF_GIT_BRANCH@
|
||||
#endif
|
||||
#ifndef PROF_GIT_REVISION
|
||||
#define PROF_GIT_REVISION @PROF_GIT_REVISION@
|
||||
#endif
|
||||
@@ -77,7 +77,7 @@ main(int argc, char** argv)
|
||||
|
||||
if (version == TRUE) {
|
||||
auto_gchar gchar* prof_version = prof_get_version();
|
||||
g_print("Profanity, version %s\n", prof_version);
|
||||
g_print("CProof, version %s\n", prof_version);
|
||||
|
||||
// lets use fixed email instead of PACKAGE_BUGREPORT
|
||||
g_print("Copyright (C) 2012 - 2019 James Booth <boothj5web@gmail.com>.\n");
|
||||
|
||||
@@ -519,13 +519,15 @@ 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)
|
||||
p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gchar* const fp, gchar** err)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -538,6 +540,7 @@ 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;
|
||||
}
|
||||
@@ -545,6 +548,7 @@ 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;
|
||||
@@ -554,8 +558,10 @@ 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;
|
||||
@@ -574,7 +580,8 @@ p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gcha
|
||||
gpgme_key_unref(sender_key);
|
||||
|
||||
if (error) {
|
||||
log_error("GPG: Failed to encrypt message. %s %s", gpgme_strsource(error), gpgme_strerror(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));
|
||||
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* p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gchar* const fp, gchar** err);
|
||||
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);
|
||||
|
||||
@@ -253,7 +253,7 @@ _init(char* log_level, char* config_file, char* log_file, char* theme_name)
|
||||
log_stderr_init(PROF_LEVEL_ERROR);
|
||||
|
||||
auto_gchar gchar* prof_version = prof_get_version();
|
||||
log_info("Starting Profanity (%s)…", prof_version);
|
||||
log_info("Starting CProof (%s)…", prof_version);
|
||||
|
||||
chatlog_init();
|
||||
accounts_load();
|
||||
|
||||
@@ -2830,8 +2830,7 @@ cons_privacy_setting(void)
|
||||
if (account->client) {
|
||||
cons_show("Client name (/account set <account> clientid) : %s", account->client);
|
||||
} else {
|
||||
auto_gchar gchar* prof_version = prof_get_version();
|
||||
cons_show("Client name (/account set <account> clientid) : Profanity %s", prof_version);
|
||||
cons_show("Client name (/account set <account> clientid) : Pidgin");
|
||||
}
|
||||
if (account->max_sessions > 0) {
|
||||
cons_show("Max sessions alarm (/account set <account> session_alarm) : %d", account->max_sessions);
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include "ai/ai_client.h"
|
||||
|
||||
static const int PAD_MIN_HEIGHT = 100;
|
||||
static const int PAD_THRESHOLD = 12000; // above buffer cap (~9000): reclaims dead pad space, never fires while scrolling
|
||||
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 gboolean _in_redraw = FALSE;
|
||||
|
||||
static void
|
||||
@@ -56,9 +56,10 @@ _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) {
|
||||
// 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) {
|
||||
// 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) {
|
||||
win_redraw(window);
|
||||
} else {
|
||||
// resize to required lines + some buffer for next messages
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "plugins/plugins.h"
|
||||
#include "config/files.h"
|
||||
#include "config/preferences.h"
|
||||
#include "xmpp/connection.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "xmpp/stanza.h"
|
||||
#include "xmpp/form.h"
|
||||
@@ -271,6 +272,19 @@ caps_map_jid_to_ver(const char* const jid, const char* const ver)
|
||||
g_hash_table_insert(jid_to_ver, strdup(jid), strdup(ver));
|
||||
}
|
||||
|
||||
void
|
||||
caps_cache_clear(void)
|
||||
{
|
||||
g_hash_table_remove_all(jid_to_ver);
|
||||
g_hash_table_remove_all(jid_to_caps);
|
||||
if (caps_prof_keyfile.keyfile) {
|
||||
g_key_file_free(caps_prof_keyfile.keyfile);
|
||||
}
|
||||
caps_prof_keyfile.keyfile = g_key_file_new();
|
||||
cache = caps_prof_keyfile.keyfile;
|
||||
save_keyfile(&caps_prof_keyfile);
|
||||
}
|
||||
|
||||
gboolean
|
||||
caps_cache_contains(const char* const ver)
|
||||
{
|
||||
|
||||
@@ -28,5 +28,6 @@ void caps_map_jid_to_ver(const char* const jid, const char* const ver);
|
||||
gboolean caps_cache_contains(const char* const ver);
|
||||
GList* caps_get_features(void);
|
||||
char* caps_get_my_sha1(xmpp_ctx_t* const ctx);
|
||||
void caps_cache_clear(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1681,7 +1681,7 @@ _version_get_handler(xmpp_stanza_t* const stanza)
|
||||
xmpp_stanza_t* name = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(name, "name");
|
||||
xmpp_stanza_t* name_txt = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(name_txt, is_custom_client ? client : "Profanity");
|
||||
xmpp_stanza_set_text(name_txt, is_custom_client ? client : "Pidgin");
|
||||
xmpp_stanza_add_child(name, name_txt);
|
||||
xmpp_stanza_add_child(query, name);
|
||||
bool include_os = prefs_get_boolean(PREF_REVEAL_OS) && !is_custom_client;
|
||||
@@ -1690,7 +1690,7 @@ _version_get_handler(xmpp_stanza_t* const stanza)
|
||||
xmpp_stanza_t* version = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(version, "version");
|
||||
xmpp_stanza_t* version_txt = xmpp_stanza_new(ctx);
|
||||
auto_gchar gchar* prof_version = prof_get_version();
|
||||
auto_gchar gchar* prof_version = g_strdup("");
|
||||
|
||||
if (!is_custom_client) {
|
||||
xmpp_stanza_set_text(version_txt, prof_version);
|
||||
@@ -2432,7 +2432,8 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t* const stanza, void* con
|
||||
}
|
||||
|
||||
// Prevent repetitions by avoiding checks of disco items (from connection_set_disco_items)
|
||||
if (from && g_ascii_strcasecmp(from, connection_get_domain()) == 0) {
|
||||
const char* domain = connection_get_domain();
|
||||
if (from && domain && g_ascii_strcasecmp(from, domain) == 0) {
|
||||
_disco_autoping_warning_message(features);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,9 +280,13 @@ jid_fulljid_or_barejid(Jid* jid)
|
||||
gchar*
|
||||
jid_random_resource(void)
|
||||
{
|
||||
auto_gchar gchar* rand = get_random_string(4);
|
||||
gchar* rand = g_malloc0(29);
|
||||
const gchar* digits = "0123456789";
|
||||
|
||||
gchar* result = g_strdup_printf("profanity.%s", rand);
|
||||
for (int i = 0; i < 28; i++) {
|
||||
rand[i] = digits[g_random_int_range(0, 10)];
|
||||
}
|
||||
rand[28] = '\0';
|
||||
|
||||
return result;
|
||||
return rand;
|
||||
}
|
||||
|
||||
@@ -467,12 +467,15 @@ 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* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid);
|
||||
auto_gchar gchar* err = NULL;
|
||||
auto_gchar gchar* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid, &err);
|
||||
if (encrypted) {
|
||||
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
||||
xmpp_message_set_body(message, "This message is encrypted (XEP-0027).");
|
||||
@@ -486,18 +489,31 @@ message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean
|
||||
xmpp_stanza_add_child(message, x);
|
||||
xmpp_stanza_release(x);
|
||||
} else {
|
||||
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
||||
xmpp_message_set_body(message, msg);
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
||||
xmpp_message_set_body(message, msg);
|
||||
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;
|
||||
}
|
||||
account_free(account);
|
||||
#else
|
||||
// ?
|
||||
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
||||
xmpp_message_set_body(message, msg);
|
||||
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;
|
||||
#endif
|
||||
|
||||
if (state) {
|
||||
@@ -546,7 +562,10 @@ 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) {
|
||||
cons_show("Unable to send OX message. Check log file and profanity-ox-setup man page for details.");
|
||||
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.");
|
||||
}
|
||||
log_error("Message not signcrypted.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
|
||||
saved_details.auth_policy = NULL;
|
||||
}
|
||||
|
||||
// use 'profanity' when no resourcepart in provided jid
|
||||
// use random string when no resourcepart in provided jid
|
||||
auto_jid Jid* jidp = jid_create(jid);
|
||||
if (jidp->resourcepart == NULL) {
|
||||
auto_gchar gchar* resource = jid_random_resource();
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
static void _stanza_add_unique_id(xmpp_stanza_t* stanza);
|
||||
static gchar* _stanza_create_sha1_hash(char* str);
|
||||
static const char* _stanza_get_caps_node(const char* const client);
|
||||
|
||||
#if 0
|
||||
xmpp_stanza_t*
|
||||
@@ -930,23 +931,22 @@ stanza_create_caps_query_element(xmpp_ctx_t* ctx)
|
||||
|
||||
xmpp_stanza_t* identity = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(identity, "identity");
|
||||
xmpp_stanza_set_type(identity, "pc");
|
||||
xmpp_stanza_set_attribute(identity, "category", "client");
|
||||
|
||||
ProfAccount* account = accounts_get_account(session_get_account_name());
|
||||
gchar* client = account->client;
|
||||
bool is_custom_client = client != NULL;
|
||||
|
||||
GString* name_str = g_string_new(is_custom_client ? client : "Profanity ");
|
||||
if (!is_custom_client) {
|
||||
xmpp_stanza_set_type(identity, "console");
|
||||
auto_gchar gchar* prof_version = prof_get_version();
|
||||
g_string_append(name_str, prof_version);
|
||||
auto_gchar gchar* name = g_strdup(account->client ? account->client : "Pidgin");
|
||||
|
||||
if (account->client) {
|
||||
gchar* space = strchr(name, ' ');
|
||||
if (space) {
|
||||
*space = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
account_free(account);
|
||||
|
||||
xmpp_stanza_set_attribute(identity, "name", name_str->str);
|
||||
g_string_free(name_str, TRUE);
|
||||
xmpp_stanza_set_attribute(identity, "name", name);
|
||||
xmpp_stanza_add_child(query, identity);
|
||||
xmpp_stanza_release(identity);
|
||||
|
||||
@@ -1994,6 +1994,42 @@ stanza_attach_last_activity(xmpp_ctx_t* const ctx,
|
||||
xmpp_stanza_release(query);
|
||||
}
|
||||
|
||||
static const char*
|
||||
_stanza_get_caps_node(const char* const client)
|
||||
{
|
||||
if (!client || g_strcmp0(client, "") == 0) {
|
||||
return "http://pidgin.im";
|
||||
}
|
||||
|
||||
auto_gchar gchar* lower = g_ascii_strdown(client, -1);
|
||||
|
||||
if (g_str_has_prefix(lower, "pidgin")) {
|
||||
return "http://pidgin.im";
|
||||
}
|
||||
|
||||
if (g_str_has_prefix(lower, "gajim")) {
|
||||
return "https://gajim.org";
|
||||
}
|
||||
|
||||
if (g_str_has_prefix(lower, "conversations")) {
|
||||
return "https://conversations.im";
|
||||
}
|
||||
|
||||
if (g_str_has_prefix(lower, "psi+")) {
|
||||
return "http://psi-plus.com";
|
||||
}
|
||||
|
||||
if (g_str_has_prefix(lower, "psi")) {
|
||||
return "http://psi-im.org";
|
||||
}
|
||||
|
||||
if (g_str_has_prefix(lower, "profanity")) {
|
||||
return "http://profanity-im.github.io";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void
|
||||
stanza_attach_caps(xmpp_ctx_t* const ctx, xmpp_stanza_t* const presence)
|
||||
{
|
||||
@@ -2002,9 +2038,13 @@ stanza_attach_caps(xmpp_ctx_t* const ctx, xmpp_stanza_t* const presence)
|
||||
xmpp_stanza_set_ns(caps, STANZA_NS_CAPS);
|
||||
xmpp_stanza_t* query = stanza_create_caps_query_element(ctx);
|
||||
|
||||
ProfAccount* account = accounts_get_account(session_get_account_name());
|
||||
const char* node = _stanza_get_caps_node(account->client);
|
||||
account_free(account);
|
||||
|
||||
char* sha1 = caps_get_my_sha1(ctx);
|
||||
xmpp_stanza_set_attribute(caps, STANZA_ATTR_HASH, "sha-1");
|
||||
xmpp_stanza_set_attribute(caps, STANZA_ATTR_NODE, "http://profanity-im.github.io");
|
||||
xmpp_stanza_set_attribute(caps, STANZA_ATTR_NODE, node);
|
||||
xmpp_stanza_set_attribute(caps, STANZA_ATTR_VER, sha1);
|
||||
xmpp_stanza_add_child(presence, caps);
|
||||
xmpp_stanza_release(caps);
|
||||
|
||||
@@ -601,11 +601,11 @@ prof_connect_with_roster(const char* roster)
|
||||
assert_true(prof_output_regex(".+online.+ \\(priority 0\\)\\."));
|
||||
|
||||
expect_timeout = EXPECT_TIMEOUT_CONNECT;
|
||||
// Wait for presence stanza to be sent (content-based, not ID-based)
|
||||
// Wait for presence stanza to be sent
|
||||
// Match the actual attribute order from stanza_attach_caps
|
||||
assert_true(stbbr_received(
|
||||
"<presence id=\"*\">"
|
||||
"<c xmlns=\"http://jabber.org/protocol/caps\" hash=\"sha-1\" node=\"http://profanity-im.github.io\" ver=\"*\"/>"
|
||||
"<c xmlns=\"http://jabber.org/protocol/caps\" hash=\"sha-1\" node=\"*\" ver=\"*\"/>"
|
||||
"</presence>"));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ connect_jid_sends_presence_after_receiving_roster(void **state)
|
||||
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='*'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -1289,7 +1289,7 @@ _join_muc(const char* room)
|
||||
snprintf(presence, sizeof(presence),
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='%s/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' "
|
||||
"node='http://profanity-im.github.io' ver='*'/>"
|
||||
"node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
|
||||
@@ -26,7 +26,7 @@ sends_room_join(void **state)
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='*' to='testroom@conference.localhost/stabber'>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -41,7 +41,7 @@ sends_room_join_with_nick(void **state)
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='*' to='testroom@conference.localhost/testnick'>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -58,7 +58,7 @@ sends_room_join_with_password(void **state)
|
||||
"<x xmlns='http://jabber.org/protocol/muc'>"
|
||||
"<password>testpassword</password>"
|
||||
"</x>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -75,7 +75,7 @@ sends_room_join_with_nick_and_password(void **state)
|
||||
"<x xmlns='http://jabber.org/protocol/muc'>"
|
||||
"<password>testpassword</password>"
|
||||
"</x>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -87,7 +87,7 @@ shows_role_and_affiliation_on_join(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
@@ -107,7 +107,7 @@ shows_subject_on_join(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
@@ -135,7 +135,7 @@ shows_history_message(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
@@ -170,7 +170,7 @@ shows_occupant_join(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
@@ -200,7 +200,7 @@ shows_message(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
@@ -227,7 +227,7 @@ shows_me_message_from_occupant(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
@@ -254,7 +254,7 @@ shows_me_message_from_self(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
@@ -281,7 +281,7 @@ shows_all_messages_in_console_when_window_not_focussed(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
@@ -322,7 +322,7 @@ shows_first_message_in_console_when_window_not_focussed(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
@@ -369,7 +369,7 @@ shows_no_message_in_console_when_window_not_focussed(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='participant' jid='stabber@localhost/profanity' affiliation='none'/>"
|
||||
"</x>"
|
||||
@@ -401,7 +401,7 @@ sends_affiliation_list_request(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='moderator' jid='stabber@localhost/profanity' affiliation='owner'/>"
|
||||
"</x>"
|
||||
@@ -434,7 +434,7 @@ sends_kick_request(void **state)
|
||||
|
||||
stbbr_for_presence_to("testroom@conference.localhost/stabber",
|
||||
"<presence id='*' lang='en' to='stabber@localhost/profanity' from='testroom@conference.localhost/stabber'>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='http://profanity-im.github.io' ver='*'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' node='*' ver='*'/>"
|
||||
"<x xmlns='http://jabber.org/protocol/muc#user'>"
|
||||
"<item role='moderator' jid='stabber@localhost/profanity' affiliation='admin'/>"
|
||||
"</x>"
|
||||
|
||||
@@ -19,7 +19,7 @@ presence_online(void **state)
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='*'>"
|
||||
"<status>online</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -36,7 +36,7 @@ presence_online_with_message(void **state)
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='*'>"
|
||||
"<status>Hi there</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -54,7 +54,7 @@ presence_away(void **state)
|
||||
"<presence id='*'>"
|
||||
"<show>away</show>"
|
||||
"<status>away</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -72,7 +72,7 @@ presence_away_with_message(void **state)
|
||||
"<presence id='*'>"
|
||||
"<show>away</show>"
|
||||
"<status>I'm not here for a bit</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -90,7 +90,7 @@ presence_xa(void **state)
|
||||
"<presence id='*'>"
|
||||
"<show>xa</show>"
|
||||
"<status>xa</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -108,7 +108,7 @@ presence_xa_with_message(void **state)
|
||||
"<presence id='*'>"
|
||||
"<show>xa</show>"
|
||||
"<status>Gone to the shops</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -126,7 +126,7 @@ presence_dnd(void **state)
|
||||
"<presence id='*'>"
|
||||
"<show>dnd</show>"
|
||||
"<status>dnd</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -144,7 +144,7 @@ presence_dnd_with_message(void **state)
|
||||
"<presence id='*'>"
|
||||
"<show>dnd</show>"
|
||||
"<status>Working</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -162,7 +162,7 @@ presence_chat(void **state)
|
||||
"<presence id='*'>"
|
||||
"<show>chat</show>"
|
||||
"<status>chat</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -180,7 +180,7 @@ presence_chat_with_message(void **state)
|
||||
"<presence id='*'>"
|
||||
"<show>chat</show>"
|
||||
"<status>Free to talk</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -197,7 +197,7 @@ presence_set_priority(void **state)
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='*'>"
|
||||
"<priority>25</priority>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -212,7 +212,7 @@ presence_includes_priority(void **state)
|
||||
assert_true(stbbr_received(
|
||||
"<presence id='*'>"
|
||||
"<priority>25</priority>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
|
||||
@@ -223,7 +223,7 @@ presence_includes_priority(void **state)
|
||||
"<priority>25</priority>"
|
||||
"<show>chat</show>"
|
||||
"<status>Free to talk</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
@@ -239,7 +239,7 @@ presence_keeps_status(void **state)
|
||||
"<presence id='*'>"
|
||||
"<show>chat</show>"
|
||||
"<status>Free to talk</status>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
|
||||
@@ -250,7 +250,7 @@ presence_keeps_status(void **state)
|
||||
"<show>chat</show>"
|
||||
"<status>Free to talk</status>"
|
||||
"<priority>25</priority>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
|
||||
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='*'/>"
|
||||
"</presence>"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -614,6 +614,24 @@ test_ai_set_provider_setting(void** state)
|
||||
assert_null(ai_get_provider_setting("p_set_settings", "nonexistent_setting"));
|
||||
}
|
||||
|
||||
void
|
||||
test_ai_set_provider_setting_reserved_key(void** state)
|
||||
{
|
||||
ai_add_provider("p_reserved_keys", "https://example.test/rk/");
|
||||
|
||||
/* Reserved payload keys are rejected (would duplicate fixed fields) */
|
||||
assert_false(ai_set_provider_setting("p_reserved_keys", "model", "x"));
|
||||
assert_false(ai_set_provider_setting("p_reserved_keys", "messages", "[]"));
|
||||
assert_false(ai_set_provider_setting("p_reserved_keys", "stream", "true"));
|
||||
assert_null(ai_get_provider_setting("p_reserved_keys", "model"));
|
||||
|
||||
/* Ordinary keys still work */
|
||||
assert_true(ai_set_provider_setting("p_reserved_keys", "temperature", "0.7"));
|
||||
auto_gchar gchar* temp = ai_get_provider_setting("p_reserved_keys", "temperature");
|
||||
assert_non_null(temp);
|
||||
assert_string_equal("0.7", temp);
|
||||
}
|
||||
|
||||
void
|
||||
test_ai_get_provider_setting(void** state)
|
||||
{
|
||||
@@ -919,22 +937,22 @@ test_ai_parse_response_openai_content(void** state)
|
||||
}
|
||||
|
||||
void
|
||||
test_ai_parse_response_perplexity_text(void** state)
|
||||
test_ai_parse_response_legacy_text_format_unsupported(void** state)
|
||||
{
|
||||
/* Legacy Perplexity /v1/agent format: "content" is an array, not a string.
|
||||
* Dropped with the chat-completions alignment, so parsing yields NULL. */
|
||||
const gchar* json = "{\"output\":[{\"content\":[{\"text\":\"Search result\",\"type\":\"output_text\"}]}]}";
|
||||
auto_gchar gchar* out = ai_parse_response(json);
|
||||
assert_non_null(out);
|
||||
assert_string_equal("Search result", out);
|
||||
assert_null(ai_parse_response(json));
|
||||
}
|
||||
|
||||
void
|
||||
test_ai_parse_response_text_preferred_over_content(void** state)
|
||||
test_ai_parse_response_content_preferred_over_text(void** state)
|
||||
{
|
||||
/* When both formats are present, "text" wins (Perplexity path tried first). */
|
||||
/* Chat-completions "content" is extracted; a stray "text" field is ignored. */
|
||||
const gchar* json = "{\"text\":\"from text field\",\"content\":\"from content field\"}";
|
||||
auto_gchar gchar* out = ai_parse_response(json);
|
||||
assert_non_null(out);
|
||||
assert_string_equal("from text field", out);
|
||||
assert_string_equal("from content field", out);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -43,6 +43,7 @@ void test_ai_providers_find_case_insensitive(void** state);
|
||||
void test_ai_set_provider_default_model(void** state);
|
||||
void test_ai_get_provider_default_model(void** state);
|
||||
void test_ai_set_provider_setting(void** state);
|
||||
void test_ai_set_provider_setting_reserved_key(void** state);
|
||||
void test_ai_get_provider_setting(void** state);
|
||||
/* Model caching tests */
|
||||
void test_ai_models_are_fresh_initial(void** state);
|
||||
@@ -64,8 +65,8 @@ int ai_client_teardown_with_prefs(void** state);
|
||||
|
||||
/* Chat response parser tests (ai_parse_response) */
|
||||
void test_ai_parse_response_openai_content(void** state);
|
||||
void test_ai_parse_response_perplexity_text(void** state);
|
||||
void test_ai_parse_response_text_preferred_over_content(void** state);
|
||||
void test_ai_parse_response_legacy_text_format_unsupported(void** state);
|
||||
void test_ai_parse_response_content_preferred_over_text(void** state);
|
||||
void test_ai_parse_response_escaped_quote(void** state);
|
||||
void test_ai_parse_response_newline_escape(void** state);
|
||||
void test_ai_parse_response_empty_content(void** state);
|
||||
|
||||
@@ -752,6 +752,7 @@ main(int argc, char* argv[])
|
||||
cmocka_unit_test_setup_teardown(test_ai_set_provider_default_model, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_get_provider_default_model, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_set_provider_setting, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_set_provider_setting_reserved_key, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_get_provider_setting, ai_client_setup, ai_client_teardown),
|
||||
/* Model caching tests */
|
||||
cmocka_unit_test_setup_teardown(test_ai_models_are_fresh_initial, ai_client_setup, ai_client_teardown),
|
||||
@@ -774,8 +775,8 @@ main(int argc, char* argv[])
|
||||
cmocka_unit_test(test_ai_json_escape_backslash_quote),
|
||||
/* Chat response parser */
|
||||
cmocka_unit_test(test_ai_parse_response_openai_content),
|
||||
cmocka_unit_test(test_ai_parse_response_perplexity_text),
|
||||
cmocka_unit_test(test_ai_parse_response_text_preferred_over_content),
|
||||
cmocka_unit_test(test_ai_parse_response_legacy_text_format_unsupported),
|
||||
cmocka_unit_test(test_ai_parse_response_content_preferred_over_text),
|
||||
cmocka_unit_test(test_ai_parse_response_escaped_quote),
|
||||
cmocka_unit_test(test_ai_parse_response_newline_escape),
|
||||
cmocka_unit_test(test_ai_parse_response_empty_content),
|
||||
|
||||
@@ -500,6 +500,11 @@ caps_jid_has_feature(const char* const jid, const char* const feature)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
caps_cache_clear(void)
|
||||
{
|
||||
}
|
||||
|
||||
gboolean
|
||||
bookmark_add(const char* jid, const char* nick, const char* password, const char* autojoin_str, const char* name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user