mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge pull request #1705 from profanity-im/feat/ox-improvements2
Improvements for OX part 2
This commit is contained in:
commit
b82a9e1c7f
@ -234,7 +234,6 @@ static Autocomplete pgp_log_ac;
|
||||
static Autocomplete pgp_sendfile_ac;
|
||||
static Autocomplete ox_ac;
|
||||
static Autocomplete ox_log_ac;
|
||||
static Autocomplete ox_sendfile_ac;
|
||||
#endif
|
||||
static Autocomplete tls_ac;
|
||||
static Autocomplete titlebar_ac;
|
||||
@ -317,6 +316,7 @@ cmd_ac_init(void)
|
||||
#endif
|
||||
#ifdef HAVE_LIBGPGME
|
||||
autocomplete_add(prefs_ac, "pgp");
|
||||
autocomplete_add(prefs_ac, "ox");
|
||||
#endif
|
||||
#ifdef HAVE_OMEMO
|
||||
autocomplete_add(prefs_ac, "omemo");
|
||||
@ -889,10 +889,14 @@ cmd_ac_init(void)
|
||||
autocomplete_add(ox_ac, "end");
|
||||
autocomplete_add(ox_ac, "log");
|
||||
autocomplete_add(ox_ac, "char");
|
||||
autocomplete_add(ox_ac, "sendfile");
|
||||
autocomplete_add(ox_ac, "announce");
|
||||
autocomplete_add(ox_ac, "discover");
|
||||
autocomplete_add(ox_ac, "request");
|
||||
|
||||
ox_log_ac = autocomplete_new();
|
||||
autocomplete_add(ox_log_ac, "on");
|
||||
autocomplete_add(ox_log_ac, "off");
|
||||
autocomplete_add(ox_log_ac, "redact");
|
||||
#endif
|
||||
|
||||
tls_ac = autocomplete_new();
|
||||
@ -1443,6 +1447,7 @@ cmd_ac_reset(ProfWin* window)
|
||||
autocomplete_reset(pgp_log_ac);
|
||||
autocomplete_reset(pgp_sendfile_ac);
|
||||
autocomplete_reset(ox_ac);
|
||||
autocomplete_reset(ox_log_ac);
|
||||
#endif
|
||||
autocomplete_reset(tls_ac);
|
||||
autocomplete_reset(titlebar_ac);
|
||||
@ -1606,7 +1611,6 @@ cmd_ac_uninit(void)
|
||||
autocomplete_free(pgp_sendfile_ac);
|
||||
autocomplete_free(ox_ac);
|
||||
autocomplete_free(ox_log_ac);
|
||||
autocomplete_free(ox_sendfile_ac);
|
||||
#endif
|
||||
autocomplete_free(tls_ac);
|
||||
autocomplete_free(titlebar_ac);
|
||||
@ -2617,11 +2621,6 @@ _ox_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
return found;
|
||||
}
|
||||
|
||||
found = autocomplete_param_with_ac(input, "/ox sendfile", ox_sendfile_ac, TRUE, previous);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
|
||||
if (strncmp(input, "/ox announce ", 13) == 0) {
|
||||
return cmd_ac_complete_filepath(input, "/ox announce", previous);
|
||||
}
|
||||
|
@ -1715,7 +1715,8 @@ static struct cmd_t command_defs[] = {
|
||||
#ifdef HAVE_LIBGPGME
|
||||
{ "/ox",
|
||||
parse_args, 1, 3, NULL,
|
||||
CMD_NOSUBFUNCS
|
||||
CMD_SUBFUNCS(
|
||||
{ "log", cmd_ox_log })
|
||||
CMD_MAINFUNC(cmd_ox)
|
||||
CMD_TAGS(
|
||||
CMD_TAG_CHAT,
|
||||
@ -1727,7 +1728,6 @@ static struct cmd_t command_defs[] = {
|
||||
"/ox end",
|
||||
"/ox log on|off|redact",
|
||||
"/ox char <char>",
|
||||
"/ox sendfile on|off",
|
||||
"/ox announce <file>",
|
||||
"/ox discover <jid>",
|
||||
"/ox request <jid> <keyid>")
|
||||
@ -1746,8 +1746,7 @@ static struct cmd_t command_defs[] = {
|
||||
{ "char <char>", "Set the character to be displayed next to PGP encrypted messages." },
|
||||
{ "announce <file>", "Announce a public key by pushing it on the XMPP Server" },
|
||||
{ "discover <jid>", "Discover public keys of a jid. The OpenPGP Key IDs will be displayed" },
|
||||
{ "request <jid> <keyid>", "Request public key. See /ox discover to to get available key IDs." },
|
||||
{ "sendfile on|off", "Allow /sendfile to send unencrypted files while otherwise using PGP." })
|
||||
{ "request <jid> <keyid>", "Request public key. See /ox discover to to get available key IDs." })
|
||||
CMD_EXAMPLES(
|
||||
"/ox log off",
|
||||
"/ox start odin@valhalla.edda",
|
||||
|
@ -1743,6 +1743,10 @@ cmd_prefs(ProfWin* window, const char* const command, gchar** args)
|
||||
cons_show("");
|
||||
cons_show_omemo_prefs();
|
||||
cons_show("");
|
||||
} else if (strcmp(args[0], "ox") == 0) {
|
||||
cons_show("");
|
||||
cons_show_ox_prefs();
|
||||
cons_show("");
|
||||
} else {
|
||||
cons_bad_cmd_usage(command);
|
||||
}
|
||||
@ -7725,6 +7729,31 @@ cmd_ox(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_ox_log(ProfWin* window, const char* const command, gchar** args)
|
||||
{
|
||||
char* choice = args[1];
|
||||
if (g_strcmp0(choice, "on") == 0) {
|
||||
prefs_set_string(PREF_OX_LOG, "on");
|
||||
cons_show("OX messages will be logged as plaintext.");
|
||||
if (!prefs_get_boolean(PREF_CHLOG)) {
|
||||
cons_show("Chat logging is currently disabled, use '/logging chat on' to enable.");
|
||||
}
|
||||
} else if (g_strcmp0(choice, "off") == 0) {
|
||||
prefs_set_string(PREF_OX_LOG, "off");
|
||||
cons_show("OX message logging disabled.");
|
||||
} else if (g_strcmp0(choice, "redact") == 0) {
|
||||
prefs_set_string(PREF_OX_LOG, "redact");
|
||||
cons_show("OX messages will be logged as '[redacted]'.");
|
||||
if (!prefs_get_boolean(PREF_CHLOG)) {
|
||||
cons_show("Chat logging is currently disabled, use '/logging chat on' to enable.");
|
||||
}
|
||||
} else {
|
||||
cons_bad_cmd_usage(command);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#endif // HAVE_LIBGPGME
|
||||
|
||||
gboolean
|
||||
|
@ -110,6 +110,7 @@ gboolean cmd_notify(ProfWin* window, const char* const command, gchar** args);
|
||||
gboolean cmd_pgp(ProfWin* window, const char* const command, gchar** args);
|
||||
#ifdef HAVE_LIBGPGME
|
||||
gboolean cmd_ox(ProfWin* window, const char* const command, gchar** args);
|
||||
gboolean cmd_ox_log(ProfWin* window, const char* const command, gchar** args);
|
||||
#endif // HAVE_LIBGPGME
|
||||
gboolean cmd_outtype(ProfWin* window, const char* const command, gchar** args);
|
||||
gboolean cmd_prefs(ProfWin* window, const char* const command, gchar** args);
|
||||
|
@ -1882,6 +1882,8 @@ _get_group(preference_t pref)
|
||||
case PREF_OMEMO_POLICY:
|
||||
case PREF_OMEMO_TRUST_MODE:
|
||||
return PREF_GROUP_OMEMO;
|
||||
case PREF_OX_LOG:
|
||||
return PREF_GROUP_OX;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@ -2153,6 +2155,8 @@ _get_key(preference_t pref)
|
||||
return "stamp.outgoing";
|
||||
case PREF_INCOMING_STAMP:
|
||||
return "stamp.incoming";
|
||||
case PREF_OX_LOG:
|
||||
return "log";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@ -2297,6 +2301,8 @@ _get_default_string(preference_t pref)
|
||||
return NULL;
|
||||
case PREF_URL_SAVE_CMD:
|
||||
return NULL; // Default to built-in method.
|
||||
case PREF_OX_LOG:
|
||||
return "redact";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
@ -179,6 +179,7 @@ typedef enum {
|
||||
PREF_OUTGOING_STAMP,
|
||||
PREF_INCOMING_STAMP,
|
||||
PREF_NOTIFY_ROOM_OFFLINE,
|
||||
PREF_OX_LOG,
|
||||
} preference_t;
|
||||
|
||||
typedef struct prof_alias_t
|
||||
|
@ -2314,6 +2314,29 @@ cons_show_omemo_prefs(void)
|
||||
cons_alert(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
cons_show_ox_prefs(void)
|
||||
{
|
||||
cons_show("OX preferences:");
|
||||
cons_show("");
|
||||
|
||||
char* log_value = prefs_get_string(PREF_OX_LOG);
|
||||
if (strcmp(log_value, "on") == 0) {
|
||||
cons_show("OX logging (/ox log) : ON");
|
||||
} else if (strcmp(log_value, "off") == 0) {
|
||||
cons_show("OX logging (/ox log) : OFF");
|
||||
} else {
|
||||
cons_show("OX logging (/ox log) : Redacted");
|
||||
}
|
||||
g_free(log_value);
|
||||
|
||||
char* ch = prefs_get_ox_char();
|
||||
cons_show("OX char (/ox char) : %s", ch);
|
||||
free(ch);
|
||||
|
||||
cons_alert(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
cons_show_themes(GSList* themes)
|
||||
{
|
||||
@ -2390,6 +2413,8 @@ cons_prefs(void)
|
||||
cons_show("");
|
||||
cons_show_omemo_prefs();
|
||||
cons_show("");
|
||||
cons_show_ox_prefs();
|
||||
cons_show("");
|
||||
|
||||
cons_alert(NULL);
|
||||
}
|
||||
|
@ -252,6 +252,7 @@ void cons_show_connection_prefs(void);
|
||||
void cons_show_otr_prefs(void);
|
||||
void cons_show_pgp_prefs(void);
|
||||
void cons_show_omemo_prefs(void);
|
||||
void cons_show_ox_prefs(void);
|
||||
void cons_show_account(ProfAccount* account);
|
||||
void cons_debug(const char* const msg, ...);
|
||||
void cons_show_error(const char* const cmd, ...);
|
||||
|
@ -91,7 +91,7 @@ static gboolean _handle_jingle_message(xmpp_stanza_t* const stanza);
|
||||
static gboolean _should_ignore_based_on_silence(xmpp_stanza_t* const stanza);
|
||||
|
||||
#ifdef HAVE_LIBGPGME
|
||||
static xmpp_stanza_t* _openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const to, const char* const text);
|
||||
static xmpp_stanza_t* _ox_openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const to, const char* const text);
|
||||
#endif // HAVE_LIBGPGME
|
||||
|
||||
static GHashTable* pubsub_event_handlers;
|
||||
@ -540,7 +540,7 @@ message_send_chat_ox(const char* const barejid, const char* const msg, gboolean
|
||||
xmpp_stanza_set_name(openpgp, STANZA_NAME_OPENPGP);
|
||||
xmpp_stanza_set_ns(openpgp, STANZA_NS_OPENPGP_0);
|
||||
|
||||
xmpp_stanza_t* signcrypt = _openpgp_signcrypt(ctx, barejid, msg);
|
||||
xmpp_stanza_t* signcrypt = _ox_openpgp_signcrypt(ctx, barejid, msg);
|
||||
char* c;
|
||||
size_t s;
|
||||
xmpp_stanza_to_text(signcrypt, &c, &s);
|
||||
@ -1467,14 +1467,13 @@ _handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_m
|
||||
#ifdef HAVE_LIBGPGME
|
||||
xmpp_stanza_t* ox = xmpp_stanza_get_child_by_name_and_ns(stanza, "openpgp", STANZA_NS_OPENPGP_0);
|
||||
if (ox) {
|
||||
message->plain = p_ox_gpg_decrypt(xmpp_stanza_get_text(ox));
|
||||
if (message->plain) {
|
||||
xmpp_stanza_t* x = xmpp_stanza_new_from_string(connection_get_ctx(), message->plain);
|
||||
if (x) {
|
||||
xmpp_stanza_t* p = xmpp_stanza_get_child_by_name(x, "payload");
|
||||
gchar* decrypted = p_ox_gpg_decrypt(xmpp_stanza_get_text(ox));
|
||||
if (decrypted) {
|
||||
xmpp_stanza_t* decrypted_stanza = xmpp_stanza_new_from_string(connection_get_ctx(), decrypted);
|
||||
if (decrypted_stanza) {
|
||||
xmpp_stanza_t* p = xmpp_stanza_get_child_by_name(decrypted_stanza, "payload");
|
||||
if (!p) {
|
||||
log_warning("OX Stanza - no Payload");
|
||||
message->plain = "OX error: No payload found";
|
||||
return;
|
||||
}
|
||||
xmpp_stanza_t* b = xmpp_stanza_get_child_by_name(p, "body");
|
||||
@ -1484,18 +1483,18 @@ _handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_m
|
||||
}
|
||||
message->plain = xmpp_stanza_get_text(b);
|
||||
message->encrypted = xmpp_stanza_get_text(ox);
|
||||
if (message->plain == NULL) {
|
||||
message->plain = xmpp_stanza_get_text(stanza);
|
||||
}
|
||||
} else {
|
||||
message->plain = "Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)";
|
||||
cons_show("Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)");
|
||||
log_warning("OX Stanza text to stanza failed");
|
||||
}
|
||||
} else {
|
||||
message->plain = "Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)";
|
||||
// get alternative text from message body
|
||||
xmpp_stanza_t* b = xmpp_stanza_get_child_by_name(stanza, "body");
|
||||
if (b) {
|
||||
message->plain = xmpp_stanza_get_text(b);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
message->plain = "OX stanza without openpgp name";
|
||||
log_warning("OX Stanza without openpgp stanza");
|
||||
}
|
||||
#endif // HAVE_LIBGPGME
|
||||
@ -1610,7 +1609,7 @@ message_is_sent_by_us(const ProfMessage* const message, bool checkOID)
|
||||
|
||||
#ifdef HAVE_LIBGPGME
|
||||
static xmpp_stanza_t*
|
||||
_openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const to, const char* const text)
|
||||
_ox_openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const to, const char* const text)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
struct tm* tm = localtime(&now);
|
||||
|
@ -790,6 +790,10 @@ void
|
||||
cons_show_omemo_prefs(void)
|
||||
{
|
||||
}
|
||||
void
|
||||
cons_show_ox_prefs(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
cons_show_account(ProfAccount* account)
|
||||
|
Loading…
Reference in New Issue
Block a user