about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2017-01-18 22:46:29 +0000
committerJames Booth <boothj5@gmail.com>2017-01-18 22:46:29 +0000
commitfccf56be1059a2c254b9ed08fc385ee4e0513dee (patch)
treefd0a65c17b7a5e1186643c2f5a7b1aceab979998 /src
parent70e831e08b803fe894296fc1f6b0f4157198a833 (diff)
downloadprofani-tty-fccf56be1059a2c254b9ed08fc385ee4e0513dee.tar.gz
Add prof.encryption_reset to Plugins API
issue #885
Diffstat (limited to 'src')
-rw-r--r--src/plugins/api.c22
-rw-r--r--src/plugins/api.h2
-rw-r--r--src/plugins/c_api.c7
-rw-r--r--src/plugins/profapi.c2
-rw-r--r--src/plugins/profapi.h2
-rw-r--r--src/plugins/python_api.c19
6 files changed, 54 insertions, 0 deletions
diff --git a/src/plugins/api.c b/src/plugins/api.c
index 8ebb0bb8..d65a07ba 100644
--- a/src/plugins/api.c
+++ b/src/plugins/api.c
@@ -497,3 +497,25 @@ api_disco_add_feature(char *plugin_name, char *feature)
     }
 }
 
+void
+api_encryption_reset(const char *const barejid)
+{
+    if (barejid == NULL) {
+        return;
+    }
+
+    ProfChatWin *chatwin = wins_get_chat(barejid);
+    if (chatwin == NULL) {
+        return;
+    }
+
+    if (chatwin->pgp_send) {
+        chatwin->pgp_send = FALSE;
+        win_println((ProfWin*)chatwin, THEME_DEFAULT, '!', "PGP encryption disabled.");
+    }
+
+    if (chatwin->is_otr) {
+        chatwin_otr_unsecured(chatwin);
+        otr_end_session(chatwin->barejid);
+    }
+}
diff --git a/src/plugins/api.h b/src/plugins/api.h
index 806de7f6..c05e7038 100644
--- a/src/plugins/api.h
+++ b/src/plugins/api.h
@@ -96,4 +96,6 @@ void api_incoming_message(const char *const barejid, const char *const resource,
 
 void api_disco_add_feature(char *plugin_name, char *feature);
 
+void api_encryption_reset(const char *const barejid);
+
 #endif
diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c
index 1d3a73e9..ed613389 100644
--- a/src/plugins/c_api.c
+++ b/src/plugins/c_api.c
@@ -341,6 +341,12 @@ c_api_disco_add_feature(const char *filename, char *feature)
     free(plugin_name);
 }
 
+static void
+c_api_encryption_reset(const char *barejid)
+{
+    api_encryption_reset(barejid);
+}
+
 void
 c_command_callback(PluginCommand *command, gchar **args)
 {
@@ -408,6 +414,7 @@ c_api_init(void)
     prof_settings_string_list_clear = c_api_settings_string_list_clear;
     prof_incoming_message = c_api_incoming_message;
     _prof_disco_add_feature = c_api_disco_add_feature;
+    prof_encryption_reset = c_api_encryption_reset;
 }
 
 static char *
diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c
index f3fd7e6f..8a6ef5aa 100644
--- a/src/plugins/profapi.c
+++ b/src/plugins/profapi.c
@@ -92,3 +92,5 @@ int (*prof_settings_string_list_clear)(char *group, char *key) = NULL;
 void (*prof_incoming_message)(char *barejid, char *resource, char *message) = NULL;
 
 void (*_prof_disco_add_feature)(const char *filename, char *feature) = NULL;
+
+void (*prof_encryption_reset)(const char *barejid) = NULL;
diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h
index d6fd78ed..223af77f 100644
--- a/src/plugins/profapi.h
+++ b/src/plugins/profapi.h
@@ -105,4 +105,6 @@ void (*prof_incoming_message)(char *barejid, char *resource, char *message);
 
 void (*_prof_disco_add_feature)(const char *filename, char *feature);
 
+void (*prof_encryption_reset)(const char *barejid);
+
 #endif
diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c
index b7145ecc..b92cdc88 100644
--- a/src/plugins/python_api.c
+++ b/src/plugins/python_api.c
@@ -1031,6 +1031,24 @@ python_api_disco_add_feature(PyObject *self, PyObject *args)
     Py_RETURN_NONE;
 }
 
+static PyObject*
+python_api_encryption_reset(PyObject *self, PyObject *args)
+{
+    PyObject *barejid = NULL;
+    if (!PyArg_ParseTuple(args, "O", &barejid)) {
+        Py_RETURN_NONE;
+    }
+
+    char *barejid_str = python_str_or_unicode_to_string(barejid);
+
+    allow_python_threads();
+    api_encryption_reset(barejid_str);
+    free(barejid_str);
+    disable_python_threads();
+
+    Py_RETURN_NONE;
+}
+
 void
 python_command_callback(PluginCommand *command, gchar **args)
 {
@@ -1139,6 +1157,7 @@ static PyMethodDef apiMethods[] = {
     { "settings_string_list_clear", python_api_settings_string_list_clear, METH_VARARGS, "Remove all items from string list setting." },
     { "incoming_message", python_api_incoming_message, METH_VARARGS, "Show an incoming message." },
     { "disco_add_feature", python_api_disco_add_feature, METH_VARARGS, "Add a feature to disco info response." },
+    { "encryption_reset", python_api_encryption_reset, METH_VARARGS, "End encrypted chat session with barejid, if one exists" },
     { NULL, NULL, 0, NULL }
 };