about summary refs log tree commit diff stats
path: root/src/plugins/python_api.c
diff options
context:
space:
mode:
authorDustin Lagoy <dustin@lagoy.org>2021-04-29 13:50:57 -0400
committerDustin Lagoy <dustin@lagoy.org>2021-04-29 13:50:57 -0400
commit2350a94c4411635f15173ec9c7964ea89e3fb2b1 (patch)
treee36802b027519d2dcd95ca674b1e03ba0a1a1926 /src/plugins/python_api.c
parent802442fffc86397870e1f37f901b63b9521b042d (diff)
downloadprofani-tty-2350a94c4411635f15173ec9c7964ea89e3fb2b1.tar.gz
Add plugin get_barejid_from_roster function
Diffstat (limited to 'src/plugins/python_api.c')
-rw-r--r--src/plugins/python_api.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c
index c33d4667..8ea54514 100644
--- a/src/plugins/python_api.c
+++ b/src/plugins/python_api.c
@@ -463,6 +463,27 @@ python_api_get_name_from_roster(PyObject* self, PyObject* args)
 }
 
 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();
@@ -1510,6 +1531,7 @@ static PyMethodDef apiMethods[] = {
     { "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." },