diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command/cmd_ac.c | 2 | ||||
-rw-r--r-- | src/command/cmd_defs.c | 5 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 26 | ||||
-rw-r--r-- | src/config/account.c | 6 | ||||
-rw-r--r-- | src/config/account.h | 4 | ||||
-rw-r--r-- | src/config/accounts.c | 19 | ||||
-rw-r--r-- | src/config/accounts.h | 2 | ||||
-rw-r--r-- | src/ui/console.c | 3 | ||||
-rw-r--r-- | src/xmpp/iq.c | 102 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 24 |
10 files changed, 125 insertions, 68 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index bb204935..3561449e 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -481,6 +481,7 @@ cmd_ac_init(void) autocomplete_add(account_set_ac, "otr"); autocomplete_add(account_set_ac, "pgpkeyid"); autocomplete_add(account_set_ac, "startscript"); + autocomplete_add(account_set_ac, "clientid"); autocomplete_add(account_set_ac, "tls"); autocomplete_add(account_set_ac, "auth"); autocomplete_add(account_set_ac, "theme"); @@ -493,6 +494,7 @@ cmd_ac_init(void) autocomplete_add(account_clear_ac, "otr"); autocomplete_add(account_clear_ac, "pgpkeyid"); autocomplete_add(account_clear_ac, "startscript"); + autocomplete_add(account_clear_ac, "clientid"); autocomplete_add(account_clear_ac, "theme"); autocomplete_add(account_clear_ac, "muc"); autocomplete_add(account_clear_ac, "resource"); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index fd90fdca..6f30652b 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2066,6 +2066,7 @@ static const struct cmd_t command_defs[] = { "/account set <account> otr <policy>", "/account set <account> pgpkeyid <pgpkeyid>", "/account set <account> startscript <script>", + "/account set <account> clientid \"<name> <version>\"", "/account set <account> tls force|allow|trust|legacy|disable", "/account set <account> auth default|legacy", "/account set <account> theme <theme>", @@ -2076,6 +2077,7 @@ static const struct cmd_t command_defs[] = { "/account clear <account> otr", "/account clear <account> pgpkeyid", "/account clear <account> startscript", + "/account clear <account> clientid", "/account clear <account> muc", "/account clear <account> resource") CMD_DESC( @@ -2105,6 +2107,7 @@ static const struct cmd_t command_defs[] = { { "set <account> otr <policy>", "Override global OTR policy for this account, see /otr." }, { "set <account> pgpkeyid <pgpkeyid>", "Set the ID of the PGP key for this account, see /pgp." }, { "set <account> startscript <script>", "Set the script to execute after connecting." }, + { "set <account> clientid \"<name> <version>\"", "[EXPERIMENTAL] Set XMPP client name according for discovery according to XEP-0092. Use with caution." }, { "set <account> tls force", "Force TLS connection, and fail if one cannot be established, this is default behaviour." }, { "set <account> tls allow", "Use TLS for the connection if it is available." }, { "set <account> tls trust", "Force TLS connection and trust server's certificate." }, @@ -2120,6 +2123,7 @@ static const struct cmd_t command_defs[] = { { "clear <account> otr", "Remove the OTR policy setting for this account." }, { "clear <account> pgpkeyid", "Remove pgpkeyid associated with this account." }, { "clear <account> startscript", "Remove startscript associated with this account." }, + { "clear <account> clientid", "Reset client's name to default." }, { "clear <account> theme", "Clear the theme setting for the account, the global theme will be used." }, { "clear <account> resource", "Remove the resource setting for this account." }, { "clear <account> muc", "Remove the default MUC service setting." }) @@ -2132,6 +2136,7 @@ static const struct cmd_t command_defs[] = { "/account set me nick dennis", "/account set me status dnd", "/account set me dnd -1", + "/account set me clientid \"Profanity 0.42 (Dev)\"", "/account rename me chattyme", "/account clear me pgpkeyid") }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index c0506793..f6736156 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -841,6 +841,14 @@ _account_set_startscript(char* account_name, char* script) } gboolean +_account_set_client(char* account_name, char* new_client) +{ + accounts_set_client(account_name, new_client); + cons_show("Client name for account %s has been set to %s", account_name, new_client); + return TRUE; +} + +gboolean _account_set_theme(char* account_name, char* theme) { if (!theme_exists(theme)) { @@ -981,6 +989,8 @@ cmd_account_set(ProfWin* window, const char* const command, gchar** args) return _account_set_pgpkeyid(account_name, value); if (strcmp(property, "startscript") == 0) return _account_set_startscript(account_name, value); + if (strcmp(property, "clientid") == 0) + return _account_set_client(account_name, value); if (strcmp(property, "theme") == 0) return _account_set_theme(account_name, value); if (strcmp(property, "tls") == 0) @@ -1017,48 +1027,40 @@ cmd_account_clear(ProfWin* window, const char* const command, gchar** args) if (strcmp(property, "password") == 0) { accounts_clear_password(account_name); cons_show("Removed password for account %s", account_name); - cons_show(""); } else if (strcmp(property, "eval_password") == 0) { accounts_clear_eval_password(account_name); cons_show("Removed eval password for account %s", account_name); - cons_show(""); } else if (strcmp(property, "server") == 0) { accounts_clear_server(account_name); cons_show("Removed server for account %s", account_name); - cons_show(""); } else if (strcmp(property, "port") == 0) { accounts_clear_port(account_name); cons_show("Removed port for account %s", account_name); - cons_show(""); } else if (strcmp(property, "otr") == 0) { accounts_clear_otr(account_name); cons_show("OTR policy removed for account %s", account_name); - cons_show(""); } else if (strcmp(property, "pgpkeyid") == 0) { accounts_clear_pgp_keyid(account_name); cons_show("Removed PGP key ID for account %s", account_name); - cons_show(""); } else if (strcmp(property, "startscript") == 0) { accounts_clear_script_start(account_name); cons_show("Removed start script for account %s", account_name); - cons_show(""); + } else if (strcmp(property, "clientid") == 0) { + accounts_clear_client(account_name); + cons_show("Reset client name for account %s", account_name); } else if (strcmp(property, "theme") == 0) { accounts_clear_theme(account_name); cons_show("Removed theme for account %s", account_name); - cons_show(""); } else if (strcmp(property, "muc") == 0) { accounts_clear_muc(account_name); cons_show("Removed MUC service for account %s", account_name); - cons_show(""); } else if (strcmp(property, "resource") == 0) { accounts_clear_resource(account_name); cons_show("Removed resource for account %s", account_name); - cons_show(""); } else { cons_show("Invalid property: %s", property); - cons_show(""); } - + cons_show(""); return TRUE; } diff --git a/src/config/account.c b/src/config/account.c index 89436f9a..73740b3a 100644 --- a/src/config/account.c +++ b/src/config/account.c @@ -56,7 +56,8 @@ account_new(gchar* name, gchar* jid, gchar* password, gchar* eval_password, gboo gchar* otr_policy, GList* otr_manual, GList* otr_opportunistic, GList* otr_always, gchar* omemo_policy, GList* omemo_enabled, GList* omemo_disabled, GList* ox_enabled, GList* pgp_enabled, gchar* pgp_keyid, - gchar* startscript, gchar* theme, gchar* tls_policy, gchar* auth_policy) + gchar* startscript, gchar* theme, gchar* tls_policy, gchar* auth_policy, + gchar* client) { ProfAccount* new_account = calloc(1, sizeof(ProfAccount)); @@ -131,6 +132,8 @@ account_new(gchar* name, gchar* jid, gchar* password, gchar* eval_password, gboo new_account->startscript = startscript; + new_account->client = client; + new_account->theme = theme; new_account->tls_policy = tls_policy; @@ -226,6 +229,7 @@ account_free(ProfAccount* account) free(account->omemo_policy); free(account->pgp_keyid); free(account->startscript); + free(account->client); free(account->theme); free(account->tls_policy); free(account->auth_policy); diff --git a/src/config/account.h b/src/config/account.h index a469e068..f82a3e11 100644 --- a/src/config/account.h +++ b/src/config/account.h @@ -71,6 +71,7 @@ typedef struct prof_account_t gchar* theme; gchar* tls_policy; gchar* auth_policy; + gchar* client; } ProfAccount; ProfAccount* account_new(gchar* name, gchar* jid, gchar* password, gchar* eval_password, gboolean enabled, @@ -80,7 +81,8 @@ ProfAccount* account_new(gchar* name, gchar* jid, gchar* password, gchar* eval_p gchar* otr_policy, GList* otr_manual, GList* otr_opportunistic, GList* otr_always, gchar* omemo_policy, GList* omemo_enabled, GList* omemo_disabled, GList* ox_enabled, GList* pgp_enabled, gchar* pgp_keyid, - gchar* startscript, gchar* theme, gchar* tls_policy, gchar* auth_policy); + gchar* startscript, gchar* theme, gchar* tls_policy, gchar* auth_policy, + gchar* client); char* account_create_connect_jid(ProfAccount* account); gboolean account_eval_password(ProfAccount* account); void account_free(ProfAccount* account); diff --git a/src/config/accounts.c b/src/config/accounts.c index 9c7eddf9..f7e6e456 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -329,6 +329,11 @@ accounts_get_account(const char* const name) startscript = g_key_file_get_string(accounts, name, "script.start", NULL); } + gchar* client = NULL; + if (g_key_file_has_key(accounts, name, "client.name", NULL)) { + client = g_key_file_get_string(accounts, name, "client.name", NULL); + } + gchar* theme = NULL; if (g_key_file_has_key(accounts, name, "theme", NULL)) { theme = g_key_file_get_string(accounts, name, "theme", NULL); @@ -348,7 +353,7 @@ accounts_get_account(const char* const name) priority_dnd, muc_service, muc_nick, otr_policy, otr_manual, otr_opportunistic, otr_always, omemo_policy, omemo_enabled, omemo_disabled, ox_enabled, pgp_enabled, pgp_keyid, - startscript, theme, tls_policy, auth_policy); + startscript, theme, tls_policy, auth_policy, client); return new_account; } @@ -552,6 +557,12 @@ 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); +} + +void accounts_set_theme(const char* const account_name, const char* const value) { _accounts_set_string_option(account_name, "theme", value); @@ -594,6 +605,12 @@ 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"); +} + +void accounts_clear_theme(const char* const account_name) { _accounts_clear_string_option(account_name, "theme"); diff --git a/src/config/accounts.h b/src/config/accounts.h index 2f594a2f..c5b829c0 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -87,6 +87,7 @@ gint accounts_get_priority_for_presence_type(const char* const account_name, resource_presence_t presence_type); void accounts_set_pgp_keyid(const char* const account_name, const char* const value); void accounts_set_script_start(const char* const account_name, const char* const value); +void accounts_set_client(const char* const account_name, const char* const value); void accounts_set_theme(const char* const account_name, const char* const value); void accounts_clear_password(const char* const account_name); void accounts_clear_eval_password(const char* const account_name); @@ -95,6 +96,7 @@ void accounts_clear_port(const char* const account_name); void accounts_clear_otr(const char* const account_name); void accounts_clear_pgp_keyid(const char* const account_name); void accounts_clear_script_start(const char* const account_name); +void accounts_clear_client(const char* const account_name); void accounts_clear_theme(const char* const account_name); void accounts_clear_muc(const char* const account_name); void accounts_clear_resource(const char* const account_name); diff --git a/src/ui/console.c b/src/ui/console.c index 72aad7b6..d26e559f 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1064,6 +1064,9 @@ cons_show_account(ProfAccount* account) if (account->startscript) { cons_show("Start script : %s", account->startscript); } + if (account->client) { + cons_show("Client name : %s", account->client); + } if (account->theme) { cons_show("Theme : %s", account->theme); } diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index b7beafaf..e48d187a 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -1612,6 +1612,17 @@ _version_get_handler(xmpp_stanza_t* const stanza) xmpp_ctx_t* const ctx = connection_get_ctx(); const char* id = xmpp_stanza_get_id(stanza); const char* from = xmpp_stanza_get_from(stanza); + ProfAccount* account = accounts_get_account(session_get_account_name()); + auto_char char* client = account->client != NULL ? strdup(account->client) : NULL; + bool is_custom_client = client != NULL; + gchar* custom_version_str = NULL; + if (is_custom_client) { + custom_version_str = strstr(client, " "); + if (custom_version_str != NULL) { + *custom_version_str = '\0'; // Split string on name and version + custom_version_str++; + } + } if (id) { log_debug("IQ version get handler fired, id: %s.", id); @@ -1619,28 +1630,35 @@ _version_get_handler(xmpp_stanza_t* const stanza) log_debug("IQ version get handler fired."); } - if (from) { - if (prefs_get_boolean(PREF_ADV_NOTIFY_DISCO_OR_VERSION)) { - cons_show("Received IQ version request (XEP-0092) from %s", from); - } + if (!from) + return; - xmpp_stanza_t* response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, id); - xmpp_stanza_set_to(response, from); + if (prefs_get_boolean(PREF_ADV_NOTIFY_DISCO_OR_VERSION)) { + cons_show("Received IQ version request (XEP-0092) from %s", from); + } - xmpp_stanza_t* query = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(query, STANZA_NAME_QUERY); - xmpp_stanza_set_ns(query, STANZA_NS_VERSION); - - 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, "Profanity"); - xmpp_stanza_add_child(name, name_txt); - - xmpp_stanza_t* version = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(version, "version"); - xmpp_stanza_t* version_txt = xmpp_stanza_new(ctx); - GString* version_str = g_string_new(PACKAGE_VERSION); + xmpp_stanza_t* response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, id); + xmpp_stanza_set_to(response, from); + + xmpp_stanza_t* query = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(query, STANZA_NAME_QUERY); + xmpp_stanza_set_ns(query, STANZA_NS_VERSION); + + 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_add_child(name, name_txt); + xmpp_stanza_add_child(query, name); + bool include_os = prefs_get_boolean(PREF_REVEAL_OS) && !is_custom_client; + xmpp_stanza_t* os; + xmpp_stanza_t* os_txt; + xmpp_stanza_t* version = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(version, "version"); + xmpp_stanza_t* version_txt = xmpp_stanza_new(ctx); + GString* version_str = g_string_new(PACKAGE_VERSION); + + if (!is_custom_client) { if (strcmp(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION g_string_append(version_str, "dev."); @@ -1653,11 +1671,8 @@ _version_get_handler(xmpp_stanza_t* const stanza) } xmpp_stanza_set_text(version_txt, version_str->str); xmpp_stanza_add_child(version, version_txt); + xmpp_stanza_add_child(query, version); - xmpp_stanza_t* os; - xmpp_stanza_t* os_txt; - - bool include_os = prefs_get_boolean(PREF_REVEAL_OS); if (include_os) { os = xmpp_stanza_new(ctx); xmpp_stanza_set_name(os, "os"); @@ -1680,31 +1695,30 @@ _version_get_handler(xmpp_stanza_t* const stanza) xmpp_stanza_set_text(os_txt, "Unknown"); #endif xmpp_stanza_add_child(os, os_txt); - } - - xmpp_stanza_add_child(query, name); - xmpp_stanza_add_child(query, version); - if (include_os) { xmpp_stanza_add_child(query, os); } - xmpp_stanza_add_child(response, query); + } + if (is_custom_client && custom_version_str != NULL) { + xmpp_stanza_set_text(version_txt, custom_version_str); + xmpp_stanza_add_child(version, version_txt); + xmpp_stanza_add_child(query, version); + } - iq_send_stanza(response); + xmpp_stanza_add_child(response, query); + iq_send_stanza(response); - g_string_free(version_str, TRUE); - xmpp_stanza_release(name_txt); - xmpp_stanza_release(version_txt); - if (include_os) { - xmpp_stanza_release(os_txt); - } - xmpp_stanza_release(name); - xmpp_stanza_release(version); - if (include_os) { - xmpp_stanza_release(os); - } - xmpp_stanza_release(query); - xmpp_stanza_release(response); + // Cleanup + g_string_free(version_str, TRUE); + xmpp_stanza_release(version_txt); + xmpp_stanza_release(name_txt); + if (include_os) { + xmpp_stanza_release(os_txt); + xmpp_stanza_release(os); } + xmpp_stanza_release(name); + xmpp_stanza_release(version); + xmpp_stanza_release(query); + xmpp_stanza_release(response); } static void diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index fab6c5e4..bf353113 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -975,19 +975,25 @@ 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_attribute(identity, "category", "client"); - xmpp_stanza_set_type(identity, "console"); - GString* name_str = g_string_new("Profanity "); - g_string_append(name_str, PACKAGE_VERSION); - if (g_strcmp0(PACKAGE_STATUS, "development") == 0) { + 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"); + g_string_append(name_str, PACKAGE_VERSION); + if (g_strcmp0(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION - g_string_append(name_str, "dev."); - g_string_append(name_str, PROF_GIT_BRANCH); - g_string_append(name_str, "."); - g_string_append(name_str, PROF_GIT_REVISION); + g_string_append(name_str, "dev."); + g_string_append(name_str, PROF_GIT_BRANCH); + g_string_append(name_str, "."); + g_string_append(name_str, PROF_GIT_REVISION); #else - g_string_append(name_str, "dev"); + g_string_append(name_str, "dev"); #endif + } } xmpp_stanza_set_attribute(identity, "name", name_str->str); g_string_free(name_str, TRUE); |