From ed4d2fcfb2b99a049164c602feea7ccf4d0d8bea Mon Sep 17 00:00:00 2001 From: Dustin Lagoy Date: Wed, 28 Apr 2021 09:17:02 -0400 Subject: Add plugin prof_get_nick_from_roster function --- src/plugins/profapi.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/plugins/profapi.c') diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index 75475631..c44eb95d 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -64,6 +64,7 @@ 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_nick_from_roster)(const char *barejid) = NULL; char** (*prof_get_current_occupants)(void) = NULL; char* (*prof_get_room_nick)(const char *barejid) = NULL; -- cgit 1.4.1-2-gfad0 From 802442fffc86397870e1f37f901b63b9521b042d Mon Sep 17 00:00:00 2001 From: Dustin Lagoy Date: Wed, 28 Apr 2021 09:32:20 -0400 Subject: Change nick to name in api to match convention Change all instances of *get_nick_from_roster to *get_name_from_roster to match the convention of names in the roster itself. --- apidocs/c/profapi.h | 2 +- apidocs/python/src/prof.py | 2 +- src/plugins/api.c | 2 +- src/plugins/api.h | 2 +- src/plugins/c_api.c | 6 +++--- src/plugins/profapi.c | 2 +- src/plugins/profapi.h | 2 +- src/plugins/python_api.c | 10 +++++----- 8 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/plugins/profapi.c') diff --git a/apidocs/c/profapi.h b/apidocs/c/profapi.h index e6562895..a8c8673c 100644 --- a/apidocs/c/profapi.h +++ b/apidocs/c/profapi.h @@ -142,7 +142,7 @@ char* prof_get_current_nick(void); Retrieve the nickname for a given barejid if it is in the roster. @return the users nickname e.g. "eddie", or NULLL if the barejid is not in the roster. */ -char* prof_get_nick_from_roster(const char *barejid); +char* prof_get_name_from_roster(const char *barejid); /** Retrieve nicknames of all occupants in a chat room, when in a chat room window. diff --git a/apidocs/python/src/prof.py b/apidocs/python/src/prof.py index aeec3604..7ee282a9 100644 --- a/apidocs/python/src/prof.py +++ b/apidocs/python/src/prof.py @@ -253,7 +253,7 @@ def get_current_nick(): pass -def get_nick_from_roster(barejid): +def get_name_from_roster(barejid): """Retrieve a nickname from a barejid if it is in the roster. :return: the users nickname e.g. ``"eddie"``, or ``None`` if the barejid is not in the roster. diff --git a/src/plugins/api.c b/src/plugins/api.c index c3207175..541e14fd 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -241,7 +241,7 @@ api_get_current_nick(void) } char* -api_get_nick_from_roster(const char* barejid) +api_get_name_from_roster(const char* barejid) { return roster_get_display_name(barejid); } diff --git a/src/plugins/api.h b/src/plugins/api.h index 5496aca9..c94751d2 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -49,7 +49,7 @@ 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_nick_from_roster(const char* barejid); +char* api_get_name_from_roster(const char* barejid); char** api_get_current_occupants(void); char* api_get_room_nick(const char* barejid); diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 3b369e78..1d36f0ba 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -196,9 +196,9 @@ c_api_get_current_nick(void) } static char* -c_api_get_nick_from_roster(const char* barejid) +c_api_get_name_from_roster(const char* barejid) { - return api_get_nick_from_roster(barejid); + return api_get_name_from_roster(barejid); } static char** @@ -489,7 +489,7 @@ c_api_init(void) 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_nick_from_roster = c_api_get_nick_from_roster; + prof_get_name_from_roster = c_api_get_name_from_roster; prof_get_current_occupants = c_api_get_current_occupants; prof_get_room_nick = c_api_get_room_nick; prof_log_debug = c_api_log_debug; diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index c44eb95d..34c074d4 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -64,7 +64,7 @@ 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_nick_from_roster)(const char *barejid) = NULL; +char* (*prof_get_name_from_roster)(const char *barejid) = NULL; char** (*prof_get_current_occupants)(void) = NULL; char* (*prof_get_room_nick)(const char *barejid) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index b2305477..755e6e0f 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -74,7 +74,7 @@ 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_nick_from_roster)(const char *barejid); +char* (*prof_get_name_from_roster)(const char *barejid); char** (*prof_get_current_occupants)(void); char* (*prof_get_room_nick)(const char *barejid); diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index 5eacb56d..c33d4667 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -442,7 +442,7 @@ python_api_get_current_nick(PyObject* self, PyObject* args) } static PyObject* -python_api_get_nick_from_roster(PyObject* self, PyObject* args) +python_api_get_name_from_roster(PyObject* self, PyObject* args) { PyObject* barejid = NULL; if (!PyArg_ParseTuple(args, "O", &barejid)) { @@ -452,11 +452,11 @@ python_api_get_nick_from_roster(PyObject* self, PyObject* args) char* barejid_str = python_str_or_unicode_to_string(barejid); allow_python_threads(); - char* nick = roster_get_display_name(barejid_str); + char* name = roster_get_display_name(barejid_str); free(barejid_str); disable_python_threads(); - if (nick) { - return Py_BuildValue("s", nick); + if (name) { + return Py_BuildValue("s", name); } else { Py_RETURN_NONE; } @@ -1509,7 +1509,7 @@ 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_nick_from_roster", python_api_get_nick_from_roster, METH_VARARGS, "Return nickname in roster of barejid." }, + { "get_name_from_roster", python_api_get_name_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." }, -- cgit 1.4.1-2-gfad0 From 2350a94c4411635f15173ec9c7964ea89e3fb2b1 Mon Sep 17 00:00:00 2001 From: Dustin Lagoy Date: Thu, 29 Apr 2021 13:50:57 -0400 Subject: Add plugin get_barejid_from_roster function --- apidocs/c/profapi.h | 6 ++++++ apidocs/python/src/prof.py | 9 +++++++++ src/plugins/api.c | 6 ++++++ src/plugins/api.h | 1 + src/plugins/c_api.c | 7 +++++++ src/plugins/profapi.c | 1 + src/plugins/profapi.h | 1 + src/plugins/python_api.c | 22 ++++++++++++++++++++++ 8 files changed, 53 insertions(+) (limited to 'src/plugins/profapi.c') diff --git a/apidocs/c/profapi.h b/apidocs/c/profapi.h index a8c8673c..04da8a4e 100644 --- a/apidocs/c/profapi.h +++ b/apidocs/c/profapi.h @@ -144,6 +144,12 @@ Retrieve the nickname for a given barejid if it is in the roster. */ char* prof_get_name_from_roster(const char *barejid); +/** +Retrieve the barejid for a given nickname if it is in the roster. +@return the users barejid e.g. "eddie@server.tld", or NULLL if the nickname is not in the roster. +*/ +char* prof_get_barejid_from_roster(const char *name); + /** Retrieve nicknames of all occupants in a chat room, when in a chat room window. @return nicknames of all occupants in the current room or an empty list if not in a chat room window. diff --git a/apidocs/python/src/prof.py b/apidocs/python/src/prof.py index 7ee282a9..eafaeeb7 100644 --- a/apidocs/python/src/prof.py +++ b/apidocs/python/src/prof.py @@ -262,6 +262,15 @@ def get_name_from_roster(barejid): pass +def get_barejid_from_roster(name): + """Retrieve the barejid for a given nickname if it is in the roster. + + :return: the users barejid e.g. "eddie@server.tld", or ``None`` if the nickname is not in the roster. + :rtype: str + """ + pass + + def get_current_occupants(): """Retrieve nicknames of all occupants in a chat room, when in a chat room window. diff --git a/src/plugins/api.c b/src/plugins/api.c index 541e14fd..de286d96 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -246,6 +246,12 @@ api_get_name_from_roster(const char* barejid) return roster_get_display_name(barejid); } +char* +api_get_barejid_from_roster(const char* name) +{ + return roster_barejid_from_name(name); +} + char** api_get_current_occupants(void) { diff --git a/src/plugins/api.h b/src/plugins/api.h index c94751d2..fcd068e2 100644 --- a/src/plugins/api.h +++ b/src/plugins/api.h @@ -50,6 +50,7 @@ char* api_get_current_muc(void); gboolean api_current_win_is_console(void); char* api_get_current_nick(void); char* api_get_name_from_roster(const char* barejid); +char* api_get_barejid_from_roster(const char* name); char** api_get_current_occupants(void); char* api_get_room_nick(const char* barejid); diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c index 1d36f0ba..9f54d94d 100644 --- a/src/plugins/c_api.c +++ b/src/plugins/c_api.c @@ -201,6 +201,12 @@ c_api_get_name_from_roster(const char* barejid) return api_get_name_from_roster(barejid); } +static char* +c_api_get_barejid_from_roster(const char* name) +{ + return api_get_barejid_from_roster(name); +} + static char** c_api_get_current_occupants(void) { @@ -490,6 +496,7 @@ c_api_init(void) prof_current_win_is_console = c_api_current_win_is_console; prof_get_current_nick = c_api_get_current_nick; prof_get_name_from_roster = c_api_get_name_from_roster; + prof_get_barejid_from_roster = c_api_get_barejid_from_roster; prof_get_current_occupants = c_api_get_current_occupants; prof_get_room_nick = c_api_get_room_nick; prof_log_debug = c_api_log_debug; diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c index 34c074d4..9011f1a2 100644 --- a/src/plugins/profapi.c +++ b/src/plugins/profapi.c @@ -65,6 +65,7 @@ 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_name_from_roster)(const char *barejid) = NULL; +char* (*prof_get_barejid_from_roster)(const char *name) = NULL; char** (*prof_get_current_occupants)(void) = NULL; char* (*prof_get_room_nick)(const char *barejid) = NULL; diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h index 755e6e0f..7e607f09 100644 --- a/src/plugins/profapi.h +++ b/src/plugins/profapi.h @@ -75,6 +75,7 @@ char* (*prof_get_current_muc)(void); int (*prof_current_win_is_console)(void); char* (*prof_get_current_nick)(void); char* (*prof_get_name_from_roster)(const char *barejid); +char* (*prof_get_barejid_from_roster)(const char *name); char** (*prof_get_current_occupants)(void); char* (*prof_get_room_nick)(const char *barejid); 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 @@ -462,6 +462,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) { @@ -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." }, -- cgit 1.4.1-2-gfad0