about summary refs log tree commit diff stats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/api.c36
-rw-r--r--src/plugins/api.h2
-rw-r--r--src/plugins/c_api.c16
-rw-r--r--src/plugins/profapi.c2
-rw-r--r--src/plugins/profapi.h2
-rw-r--r--src/plugins/python_api.c34
-rw-r--r--src/plugins/python_plugins.c6
7 files changed, 94 insertions, 4 deletions
diff --git a/src/plugins/api.c b/src/plugins/api.c
index c4130498..1aedee1f 100644
--- a/src/plugins/api.c
+++ b/src/plugins/api.c
@@ -211,6 +211,42 @@ api_get_current_muc(void)
     }
 }
 
+char *
+api_get_current_nick(void)
+{
+    ProfWin *current = wins_get_current();
+    if (current->type == WIN_MUC) {
+        ProfMucWin *mucwin = (ProfMucWin*)current;
+        assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+        return muc_nick(mucwin->roomjid);
+    } else {
+        return NULL;
+    }
+}
+
+char**
+api_get_current_occupants(void)
+{
+    ProfWin *current = wins_get_current();
+    if (current->type == WIN_MUC) {
+        ProfMucWin *mucwin = (ProfMucWin*)current;
+        assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+        GList *occupants_list = muc_roster(mucwin->roomjid);
+        char **result = malloc((g_list_length(occupants_list) + 1) * sizeof(char*));
+        GList *curr = occupants_list;
+        int i = 0;
+        while (curr) {
+            Occupant *occupant = curr->data;
+            result[i++] = strdup(occupant->nick);
+            curr = g_list_next(curr);
+        }
+        result[i] = NULL;
+        return result;
+    } else {
+        return NULL;
+    }
+}
+
 int
 api_current_win_is_console(void)
 {
diff --git a/src/plugins/api.h b/src/plugins/api.h
index fd6dba26..c22fb217 100644
--- a/src/plugins/api.h
+++ b/src/plugins/api.h
@@ -47,6 +47,8 @@ void api_send_line(char *line);
 char * api_get_current_recipient(void);
 char * api_get_current_muc(void);
 gboolean api_current_win_is_console(void);
+char* api_get_current_nick(void);
+char** api_get_current_occupants(void);
 
 void api_register_command(const char *command_name, int min_args, int max_args,
     const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c
index 74b5d92d..464bf39b 100644
--- a/src/plugins/c_api.c
+++ b/src/plugins/c_api.c
@@ -139,11 +139,23 @@ c_api_get_current_muc(void)
 }
 
 static int
-c_api_current_win_is_console()
+c_api_current_win_is_console(void)
 {
     return api_current_win_is_console();
 }
 
+static char*
+c_api_get_current_nick(void)
+{
+    return api_get_current_nick();
+}
+
+static char**
+c_api_get_current_occupants(void)
+{
+    return api_get_current_occupants();
+}
+
 static void
 c_api_log_debug(const char *message)
 {
@@ -289,6 +301,8 @@ c_api_init(void)
     prof_get_current_recipient = c_api_get_current_recipient;
     prof_get_current_muc = c_api_get_current_muc;
     prof_current_win_is_console = c_api_current_win_is_console;
+    prof_get_current_nick = c_api_get_current_nick;
+    prof_get_current_occupants = c_api_get_current_occupants;
     prof_log_debug = c_api_log_debug;
     prof_log_info = c_api_log_info;
     prof_log_warning = c_api_log_warning;
diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c
index 207f5e69..6e8637b0 100644
--- a/src/plugins/profapi.c
+++ b/src/plugins/profapi.c
@@ -59,6 +59,8 @@ void (*prof_send_line)(char *line) = NULL;
 char* (*prof_get_current_recipient)(void) = NULL;
 char* (*prof_get_current_muc)(void) = NULL;
 int (*prof_current_win_is_console)(void) = NULL;
+char* (*prof_get_current_nick)(void) = NULL;
+char** (*prof_get_current_occupants)(void) = NULL;
 
 void (*prof_log_debug)(const char *message) = NULL;
 void (*prof_log_info)(const char *message) = NULL;
diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h
index 043a1548..7d0ed6e5 100644
--- a/src/plugins/profapi.h
+++ b/src/plugins/profapi.h
@@ -59,6 +59,8 @@ void (*prof_send_line)(char *line);
 char* (*prof_get_current_recipient)(void);
 char* (*prof_get_current_muc)(void);
 int (*prof_current_win_is_console)(void);
+char* (*prof_get_current_nick)(void);
+char** (*prof_get_current_occupants)(void);
 
 void (*prof_log_debug)(const char *message);
 void (*prof_log_info)(const char *message);
diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c
index d3f684b1..34e81f11 100644
--- a/src/plugins/python_api.c
+++ b/src/plugins/python_api.c
@@ -316,6 +316,38 @@ python_api_get_current_muc(PyObject *self, PyObject *args)
     }
 }
 
+static PyObject *
+python_api_get_current_nick(PyObject *self, PyObject *args)
+{
+    allow_python_threads();
+    char *nick = api_get_current_nick();
+    disable_python_threads();
+    if (nick) {
+        return Py_BuildValue("s", nick);
+    } else {
+        return Py_BuildValue("");
+    }
+}
+
+static PyObject*
+python_api_get_current_occupants(PyObject *self, PyObject *args)
+{
+    allow_python_threads();
+    char **occupants = api_get_current_occupants();
+    disable_python_threads();
+    PyObject *result = PyList_New(0);
+    if (occupants) {
+        int len = g_strv_length(occupants);
+        int i = 0;
+        for (i = 0; i < len; i++) {
+            PyList_Append(result, Py_BuildValue("s", occupants[i]));
+        }
+        return result;
+    } else {
+        return result;
+    }
+}
+
 static PyObject*
 python_api_current_win_is_console(PyObject *self, PyObject *args)
 {
@@ -714,6 +746,8 @@ static PyMethodDef apiMethods[] = {
     { "notify", python_api_notify, METH_VARARGS, "Send desktop notification." },
     { "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_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." },
     { "log_debug", python_api_log_debug, METH_VARARGS, "Log a debug message" },
     { "log_info", python_api_log_info, METH_VARARGS, "Log an info message" },
diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c
index c927c7a9..7861f484 100644
--- a/src/plugins/python_plugins.c
+++ b/src/plugins/python_plugins.c
@@ -646,7 +646,7 @@ python_on_message_stanza_receive_hook(ProfPlugin *plugin, const char *const text
             PyObject *result = PyObject_CallObject(p_function, p_args);
             python_check_error();
             Py_XDECREF(p_function);
-            if (PyBool_Check(result)) {
+            if (PyObject_IsTrue(result)) {
                 allow_python_threads();
                 return TRUE;
             } else {
@@ -711,7 +711,7 @@ python_on_presence_stanza_receive_hook(ProfPlugin *plugin, const char *const tex
             PyObject *result = PyObject_CallObject(p_function, p_args);
             python_check_error();
             Py_XDECREF(p_function);
-            if (PyBool_Check(result)) {
+            if (PyObject_IsTrue(result)) {
                 allow_python_threads();
                 return TRUE;
             } else {
@@ -776,7 +776,7 @@ python_on_iq_stanza_receive_hook(ProfPlugin *plugin, const char *const text)
             PyObject *result = PyObject_CallObject(p_function, p_args);
             python_check_error();
             Py_XDECREF(p_function);
-            if (PyBool_Check(result)) {
+            if (PyObject_IsTrue(result)) {
                 allow_python_threads();
                 return TRUE;
             } else {