about summary refs log tree commit diff stats
path: root/src/plugins/python_api.c
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-07-01 09:41:07 +0200
committerGitHub <noreply@github.com>2021-07-01 09:41:07 +0200
commitaae252e1b54c147bcf9404031e7862c0e955f571 (patch)
tree66844e760babe0b15f561b41165d1db8cb9d9ca6 /src/plugins/python_api.c
parentdc79c514be403cff93a1165b47d456182a03fd05 (diff)
parente4bf7335d889d82dedf962f2a2590f1a1b7455b6 (diff)
downloadprofani-tty-aae252e1b54c147bcf9404031e7862c0e955f571.tar.gz
Merge pull request #1529 from dustinlagoy/access-roster-from-plugins
Access roster from plugins
Diffstat (limited to 'src/plugins/python_api.c')
-rw-r--r--src/plugins/python_api.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c
index fe66d99e..8ea54514 100644
--- a/src/plugins/python_api.c
+++ b/src/plugins/python_api.c
@@ -46,6 +46,7 @@
 #include "plugins/python_plugins.h"
 #include "plugins/callbacks.h"
 #include "plugins/autocompleters.h"
+#include "xmpp/roster_list.h"
 
 static char* _python_plugin_name(void);
 
@@ -441,6 +442,48 @@ python_api_get_current_nick(PyObject* self, PyObject* args)
 }
 
 static PyObject*
+python_api_get_name_from_roster(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();
+    char* name = roster_get_display_name(barejid_str);
+    free(barejid_str);
+    disable_python_threads();
+    if (name) {
+        return Py_BuildValue("s", name);
+    } else {
+        Py_RETURN_NONE;
+    }
+}
+
+static PyObject*
+python_api_get_barejid_from_roster(PyObject* self, PyObject* args)
+{
+    PyObject* name = NULL;
+    if (!PyArg_ParseTuple(args, "O", &name)) {
+        Py_RETURN_NONE;
+    }
+
+    char* name_str = python_str_or_unicode_to_string(name);
+
+    allow_python_threads();
+    char* barejid = roster_barejid_from_name(name_str);
+    free(name_str);
+    disable_python_threads();
+    if (barejid) {
+        return Py_BuildValue("s", barejid);
+    } else {
+        Py_RETURN_NONE;
+    }
+}
+
+static PyObject*
 python_api_get_current_occupants(PyObject* self, PyObject* args)
 {
     allow_python_threads();
@@ -1487,6 +1530,8 @@ static PyMethodDef apiMethods[] = {
     { "get_current_recipient", python_api_get_current_recipient, METH_VARARGS, "Return the jid of the recipient of the current window." },
     { "get_current_muc", python_api_get_current_muc, METH_VARARGS, "Return the jid of the room of the current window." },
     { "get_current_nick", python_api_get_current_nick, METH_VARARGS, "Return nickname in current room." },
+    { "get_name_from_roster", python_api_get_name_from_roster, METH_VARARGS, "Return nickname in roster of barejid." },
+    { "get_barejid_from_roster", python_api_get_barejid_from_roster, METH_VARARGS, "Return nickname in roster of barejid." },
     { "get_current_occupants", python_api_get_current_occupants, METH_VARARGS, "Return list of occupants in current room." },
     { "current_win_is_console", python_api_current_win_is_console, METH_VARARGS, "Returns whether the current window is the console." },
     { "get_room_nick", python_api_get_room_nick, METH_VARARGS, "Return the nickname used in the specified room, or None if not in the room." },