static PyObject * python_api_log_error(PyObject *self, PyObject *args) { PyObject *message = NULL; if (!PyArg_ParseTuple(args, "O", &message)) { Py_RETURN_NONE; } char *message_str = python_str_or_unicode_to_string(message); allow_python_threads(); api_log_error(message_str); free(message_str); disable_python_threads(); Py_RETURN_NONE; }
static PyObject* python_api_cons_bad_cmd_usage(PyObject *self, PyObject *args) { PyObject *cmd = NULL; if (!PyArg_ParseTuple(args, "O", &cmd)) { Py_RETURN_NONE; } char *cmd_str = python_str_or_unicode_to_string(cmd); allow_python_threads(); api_cons_bad_cmd_usage(cmd_str); free(cmd_str); disable_python_threads(); Py_RETURN_NONE; }
static PyObject* python_api_send_line(PyObject *self, PyObject *args) { PyObject *line = NULL; if (!PyArg_ParseTuple(args, "O", &line)) { Py_RETURN_NONE; } char *line_str = python_str_or_unicode_to_string(line); allow_python_threads(); api_send_line(line_str); free(line_str); disable_python_threads(); 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_on_shutdown_hook(ProfPlugin *plugin) { disable_python_threads(); PyObject *p_function; PyObject *p_module = plugin->module; if (PyObject_HasAttrString(p_module, "prof_on_shutdown")) { p_function = PyObject_GetAttrString(p_module, "prof_on_shutdown"); python_check_error(); if (p_function && PyCallable_Check(p_function)) { PyObject_CallObject(p_function, NULL); python_check_error(); Py_XDECREF(p_function); } } allow_python_threads(); }
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_win_focus(PyObject *self, PyObject *args) { PyObject *tag = NULL; if (!PyArg_ParseTuple(args, "O", &tag)) { Py_RETURN_NONE; } char *tag_str = python_str_or_unicode_to_string(tag); allow_python_threads(); api_win_focus(tag_str); free(tag_str); disable_python_threads(); Py_RETURN_NONE; }
void python_on_disconnect_hook(ProfPlugin *plugin, const char *const account_name, const char *const fulljid) { disable_python_threads(); PyObject *p_args = Py_BuildValue("ss", account_name, fulljid); PyObject *p_function; PyObject *p_module = plugin->module; if (PyObject_HasAttrString(p_module, "prof_on_disconnect")) { p_function = PyObject_GetAttrString(p_module, "prof_on_disconnect"); python_check_error(); if (p_function && PyCallable_Check(p_function)) { PyObject_CallObject(p_function, p_args); python_check_error(); Py_XDECREF(p_function); } } allow_python_threads(); }
void python_command_callback(PluginCommand *command, gchar **args) { disable_python_threads(); PyObject *p_args = NULL; int num_args = g_strv_length(args); if (num_args == 0) { if (command->max_args == 1) { p_args = Py_BuildValue("(O)", Py_BuildValue("")); PyObject_CallObject(command->callback, p_args); Py_XDECREF(p_args); } else { PyObject_CallObject(command->callback, p_args); } } else if (num_args == 1) { p_args = Py_BuildValue("(s)", args[0]); PyObject_CallObject(command->callback, p_args); Py_XDECREF(p_args); } else if (num_args == 2) { p_args = Py_BuildValue("ss", args[0], args[1]); PyObject_CallObject(command->callback, p_args); Py_XDECREF(p_args); } else if (num_args == 3) { p_args = Py_BuildValue("sss", args[0], args[1], args[2]); PyObject_CallObject(command->callback, p_args); Py_XDECREF(p_args); } else if (num_args == 4) { p_args = Py_BuildValue("ssss", args[0], args[1], args[2], args[3]); PyObject_CallObject(command->callback, p_args); Py_XDECREF(p_args); } else if (num_args == 5) { p_args = Py_BuildValue("sssss", args[0], args[1], args[2], args[3], args[4]); PyObject_CallObject(command->callback, p_args); Py_XDECREF(p_args); } if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); } allow_python_threads(); }
void python_post_room_message_send_hook(ProfPlugin *plugin, const char *const room, const char *message) { disable_python_threads(); PyObject *p_args = Py_BuildValue("ss", room, message); PyObject *p_function; PyObject *p_module = plugin->module; if (PyObject_HasAttrString(p_module, "prof_post_room_message_send")) { p_function = PyObject_GetAttrString(p_module, "prof_post_room_message_send"); python_check_error(); if (p_function && PyCallable_Check(p_function)) { PyObject_CallObject(p_function, p_args); python_check_error(); Py_XDECREF(p_function); } } allow_python_threads(); }
void python_post_chat_message_display_hook(ProfPlugin *plugin, const char *const barejid, const char *const resource, const char *message) { disable_python_threads(); PyObject *p_args = Py_BuildValue("sss", barejid, resource, message); PyObject *p_function; PyObject *p_module = plugin->module; if (PyObject_HasAttrString(p_module, "prof_post_chat_message_display")) { p_function = PyObject_GetAttrString(p_module, "prof_post_chat_message_display"); python_check_error(); if (p_function && PyCallable_Check(p_function)) { PyObject_CallObject(p_function, p_args); python_check_error(); Py_XDECREF(p_function); } } Py_XDECREF(p_args); allow_python_threads(); }
static PyObject* python_api_get_room_nick(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 *nick = api_get_room_nick(barejid_str); free(barejid_str); disable_python_threads(); if (nick) { return Py_BuildValue("s", nick); } else { Py_RETURN_NONE; } }
static PyObject* python_api_send_stanza(PyObject *self, PyObject *args) { PyObject *stanza = NULL; if (!PyArg_ParseTuple(args, "O", &stanza)) { return Py_BuildValue("O", Py_False); } char *stanza_str = python_str_or_unicode_to_string(stanza); allow_python_threads(); int res = api_send_stanza(stanza_str); free(stanza_str); disable_python_threads(); if (res) { return Py_BuildValue("O", Py_True); } else { return Py_BuildValue("O", Py_False); } }
static PyObject* python_api_disco_add_feature(PyObject *self, PyObject *args) { PyObject *feature = NULL; if (!PyArg_ParseTuple(args, "O", &feature)) { Py_RETURN_NONE; } char *feature_str = python_str_or_unicode_to_string(feature); char *plugin_name = _python_plugin_name(); allow_python_threads(); api_disco_add_feature(plugin_name, feature_str); free(feature_str); disable_python_threads(); free(plugin_name); Py_RETURN_NONE; }
void python_on_room_win_focus_hook(ProfPlugin *plugin, const char *const roomjid) { disable_python_threads(); PyObject *p_args = Py_BuildValue("(s)", roomjid); PyObject *p_function; PyObject *p_module = plugin->module; if (PyObject_HasAttrString(p_module, "prof_on_room_win_focus")) { p_function = PyObject_GetAttrString(p_module, "prof_on_room_win_focus"); python_check_error(); if (p_function && PyCallable_Check(p_function)) { PyObject_CallObject(p_function, p_args); python_check_error(); Py_XDECREF(p_function); } } allow_python_threads(); }
static PyObject* python_api_room_unset_message_char(PyObject *self, PyObject *args) { PyObject *roomjid = NULL; if (!PyArg_ParseTuple(args, "O", &roomjid)) { Py_RETURN_NONE; } char *roomjid_str = python_str_or_unicode_to_string(roomjid); allow_python_threads(); int res = api_room_unset_message_char(roomjid_str); free(roomjid_str); disable_python_threads(); if (res) { return Py_BuildValue("O", Py_True); } else { return Py_BuildValue("O", Py_False); } }
static PyObject * python_api_win_exists(PyObject *self, PyObject *args) { PyObject *tag = NULL; if (!PyArg_ParseTuple(args, "O", &tag)) { Py_RETURN_NONE; } char *tag_str = python_str_or_unicode_to_string(tag); allow_python_threads(); gboolean exists = api_win_exists(tag_str); free(tag_str); disable_python_threads(); if (exists) { return Py_BuildValue("O", Py_True); } else { return Py_BuildValue("O", Py_False); } }
static PyObject* python_api_chat_unset_titlebar_enctext(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(); int res = api_chat_unset_titlebar_enctext(barejid_str); free(barejid_str); disable_python_threads(); if (res) { return Py_BuildValue("O", Py_True); } else { return Py_BuildValue("O", Py_False); } }
void python_on_contact_presence_hook(ProfPlugin *plugin, const char *const barejid, const char *const resource, const char *const presence, const char *const status, const int priority) { disable_python_threads(); PyObject *p_args = Py_BuildValue("ssssi", barejid, resource, presence, status, priority); PyObject *p_function; PyObject *p_module = plugin->module; if (PyObject_HasAttrString(p_module, "prof_on_contact_presence")) { p_function = PyObject_GetAttrString(p_module, "prof_on_contact_presence"); python_check_error(); if (p_function && PyCallable_Check(p_function)) { PyObject_CallObject(p_function, p_args); python_check_error(); Py_XDECREF(p_function); } } allow_python_threads(); }
void python_on_room_history_message_hook(ProfPlugin *plugin, const char *const room, const char *const nick, const char *const message, const char *const timestamp) { disable_python_threads(); PyObject *p_args = Py_BuildValue("ssss", room, nick, message, timestamp); PyObject *p_function; PyObject *p_module = plugin->module; if (PyObject_HasAttrString(p_module, "prof_on_room_history_message")) { p_function = PyObject_GetAttrString(p_module, "prof_on_room_history_message"); python_check_error(); if (p_function && PyCallable_Check(p_function)) { PyObject_CallObject(p_function, p_args); python_check_error(); Py_XDECREF(p_function); } } allow_python_threads(); }
static PyObject* python_api_settings_string_list_get(PyObject *self, PyObject *args) { PyObject *group = NULL; PyObject *key = NULL; if (!PyArg_ParseTuple(args, "OO", &group, &key)) { Py_RETURN_NONE; } char *group_str = python_str_or_unicode_to_string(group); char *key_str = python_str_or_unicode_to_string(key); allow_python_threads(); char** c_list = api_settings_string_list_get(group_str, key_str); free(group_str); free(key_str); disable_python_threads(); if (!c_list) { Py_RETURN_NONE; } int len = g_strv_length(c_list); PyObject *py_list = PyList_New(0); int i = 0; for (i = 0; i < len; i++) { PyObject *py_curr = Py_BuildValue("s", c_list[i]); int res = PyList_Append(py_list, py_curr); if (res != 0) { g_strfreev(c_list); Py_RETURN_NONE; } } g_strfreev(c_list); return Py_BuildValue("O", py_list); }
static PyObject* python_api_settings_int_set(PyObject *self, PyObject *args) { PyObject *group = NULL; PyObject *key = NULL; int val = 0; if (!PyArg_ParseTuple(args, "OOi", &group, &key, &val)) { Py_RETURN_NONE; } char *group_str = python_str_or_unicode_to_string(group); char *key_str = python_str_or_unicode_to_string(key); allow_python_threads(); api_settings_int_set(group_str, key_str, val); free(group_str); free(key_str); disable_python_threads(); Py_RETURN_NONE; }
static PyObject* python_api_notify(PyObject *self, PyObject *args) { PyObject *message = NULL; PyObject *category = NULL; int timeout_ms = 5000; if (!PyArg_ParseTuple(args, "OiO", &message, &timeout_ms, &category)) { Py_RETURN_NONE; } char *message_str = python_str_or_unicode_to_string(message); char *category_str = python_str_or_unicode_to_string(category); allow_python_threads(); api_notify(message_str, category_str, timeout_ms); free(message_str); free(category_str); disable_python_threads(); Py_RETURN_NONE; }
static PyObject * python_api_completer_add(PyObject *self, PyObject *args) { PyObject *key = NULL; PyObject *items = NULL; if (!PyArg_ParseTuple(args, "OO", &key, &items)) { Py_RETURN_NONE; } char *key_str = python_str_or_unicode_to_string(key); char *plugin_name = _python_plugin_name(); log_debug("Autocomplete add %s for %s", key_str, plugin_name); Py_ssize_t len = PyList_Size(items); char *c_items[len]; Py_ssize_t i = 0; for (i = 0; i < len; i++) { PyObject *item = PyList_GetItem(items, i); char *c_item = python_str_or_unicode_to_string(item); c_items[i] = c_item; } c_items[len] = NULL; allow_python_threads(); api_completer_add(plugin_name, key_str, c_items); free(key_str); i = 0; while (c_items[i] != NULL) { free(c_items[i++]); } disable_python_threads(); free(plugin_name); Py_RETURN_NONE; }
static PyObject* python_api_settings_int_get(PyObject *self, PyObject *args) { PyObject *group = NULL; PyObject *key = NULL; int def = 0; if (!PyArg_ParseTuple(args, "OOi", &group, &key, &def)) { Py_RETURN_NONE; } char *group_str = python_str_or_unicode_to_string(group); char *key_str = python_str_or_unicode_to_string(key); allow_python_threads(); int res = api_settings_int_get(group_str, key_str, def); free(group_str); free(key_str); disable_python_threads(); return Py_BuildValue("i", res); }
static PyObject* python_api_settings_boolean_set(PyObject *self, PyObject *args) { PyObject *group = NULL; PyObject *key = NULL; PyObject *valobj = NULL; if (!PyArg_ParseTuple(args, "OOO!", &group, &key, &PyBool_Type, &valobj)) { Py_RETURN_NONE; } char *group_str = python_str_or_unicode_to_string(group); char *key_str = python_str_or_unicode_to_string(key); int val = PyObject_IsTrue(valobj); allow_python_threads(); api_settings_boolean_set(group_str, key_str, val); free(group_str); free(key_str); disable_python_threads(); Py_RETURN_NONE; }
gboolean python_on_iq_stanza_receive_hook(ProfPlugin *plugin, const char *const text) { disable_python_threads(); PyObject *p_args = Py_BuildValue("(s)", text); PyObject *p_function; PyObject *p_module = plugin->module; if (PyObject_HasAttrString(p_module, "prof_on_iq_stanza_receive")) { p_function = PyObject_GetAttrString(p_module, "prof_on_iq_stanza_receive"); python_check_error(); if (p_function && PyCallable_Check(p_function)) { PyObject *result = PyObject_CallObject(p_function, p_args); python_check_error(); Py_XDECREF(p_function); Py_XDECREF(p_args); return _handle_boolean_result(plugin, result, "prof_on_iq_stanza_receive"); } } Py_XDECREF(p_args); allow_python_threads(); return TRUE; }
static PyObject * python_api_register_timed(PyObject *self, PyObject *args) { PyObject *p_callback = NULL; int interval_seconds = 0; if (!PyArg_ParseTuple(args, "Oi", &p_callback, &interval_seconds)) { Py_RETURN_NONE; } char *plugin_name = _python_plugin_name(); log_debug("Register timed for %s", plugin_name); if (p_callback && PyCallable_Check(p_callback)) { allow_python_threads(); api_register_timed(plugin_name, p_callback, interval_seconds, python_timed_callback, NULL); disable_python_threads(); } free(plugin_name); Py_RETURN_NONE; }
static PyObject * python_api_completer_clear(PyObject *self, PyObject *args) { PyObject *key = NULL; if (!PyArg_ParseTuple(args, "O", &key)) { Py_RETURN_NONE; } char *key_str = python_str_or_unicode_to_string(key); char *plugin_name = _python_plugin_name(); log_debug("Autocomplete clear %s for %s", key_str, plugin_name); allow_python_threads(); api_completer_clear(plugin_name, key_str); free(key_str); disable_python_threads(); free(plugin_name); Py_RETURN_NONE; }
static PyObject* python_api_filepath_completer_add(PyObject *self, PyObject *args) { PyObject *prefix = NULL; if (!PyArg_ParseTuple(args, "O", &prefix)) { Py_RETURN_NONE; } char *prefix_str = python_str_or_unicode_to_string(prefix); char *plugin_name = _python_plugin_name(); log_debug("Filepath autocomplete added '%s' for %s", prefix_str, plugin_name); allow_python_threads(); api_filepath_completer_add(plugin_name, prefix_str); free(prefix_str); disable_python_threads(); free(plugin_name); Py_RETURN_NONE; }