Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
static PyObject *
python_api_log_debug(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_debug(message_str);
    free(message_str);
    disable_python_threads();

    Py_RETURN_NONE;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
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);
    }
}
Ejemplo n.º 7
0
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;
    }
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
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);
    }
}
Ejemplo n.º 10
0
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);
    }
}
Ejemplo n.º 11
0
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);
    }
}
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 14
0
static PyObject*
python_api_room_show_themed(PyObject *self, PyObject *args)
{
    PyObject *roomjid = NULL;
    PyObject *group = NULL;
    PyObject *key = NULL;
    PyObject *def = NULL;
    PyObject *ch = NULL;
    PyObject *message = NULL;
    if (!PyArg_ParseTuple(args, "OOOOOO", &roomjid, &group, &key, &def, &ch, &message)) {
        Py_RETURN_NONE;
    }

    char *roomjid_str = python_str_or_unicode_to_string(roomjid);
    char *group_str = python_str_or_unicode_to_string(group);
    char *key_str = python_str_or_unicode_to_string(key);
    char *def_str = python_str_or_unicode_to_string(def);
    char *ch_str = python_str_or_unicode_to_string(ch);
    char *message_str = python_str_or_unicode_to_string(message);

    allow_python_threads();
    int res = api_room_show_themed(roomjid_str, group_str, key_str, def_str, ch_str, message_str);
    free(roomjid_str);
    free(group_str);
    free(key_str);
    free(def_str);
    free(ch_str);
    free(message_str);
    disable_python_threads();

    if (res) {
        return Py_BuildValue("O", Py_True);
    } else {
        return Py_BuildValue("O", Py_False);
    }
}
Ejemplo n.º 15
0
static PyObject*
python_api_register_command(PyObject *self, PyObject *args)
{
    PyObject *command_name = NULL;
    int min_args = 0;
    int max_args = 0;
    PyObject *synopsis = NULL;
    PyObject *description = NULL;
    PyObject *arguments = NULL;
    PyObject *examples = NULL;
    PyObject *p_callback = NULL;

    if (!PyArg_ParseTuple(args, "OiiOOOOO", &command_name, &min_args, &max_args,
            &synopsis, &description, &arguments, &examples, &p_callback)) {
        Py_RETURN_NONE;
    }

    char *command_name_str = python_str_or_unicode_to_string(command_name);
    char *description_str = python_str_or_unicode_to_string(description);

    char *plugin_name = _python_plugin_name();
    log_debug("Register command %s for %s", command_name_str, plugin_name);

    if (p_callback && PyCallable_Check(p_callback)) {
        Py_ssize_t len = PyList_Size(synopsis);
        char *c_synopsis[len == 0 ? 0 : len+1];
        Py_ssize_t i = 0;
        for (i = 0; i < len; i++) {
            PyObject *item = PyList_GetItem(synopsis, i);
            char *c_item = python_str_or_unicode_to_string(item);
            c_synopsis[i] = c_item;
        }
        c_synopsis[len] = NULL;

        Py_ssize_t args_len = PyList_Size(arguments);
        char *c_arguments[args_len == 0 ? 0 : args_len+1][2];
        i = 0;
        for (i = 0; i < args_len; i++) {
            PyObject *item = PyList_GetItem(arguments, i);
            Py_ssize_t len2 = PyList_Size(item);
            if (len2 != 2) {
                Py_RETURN_NONE;
            }
            PyObject *arg = PyList_GetItem(item, 0);
            char *c_arg = python_str_or_unicode_to_string(arg);
            c_arguments[i][0] = c_arg;

            PyObject *desc = PyList_GetItem(item, 1);
            char *c_desc = python_str_or_unicode_to_string(desc);
            c_arguments[i][1] = c_desc;
        }

        c_arguments[args_len][0] = NULL;
        c_arguments[args_len][1] = NULL;

        len = PyList_Size(examples);
        char *c_examples[len == 0 ? 0 : len+1];
        i = 0;
        for (i = 0; i < len; i++) {
            PyObject *item = PyList_GetItem(examples, i);
            char *c_item = python_str_or_unicode_to_string(item);
            c_examples[i] = c_item;
        }
        c_examples[len] = NULL;

        allow_python_threads();
        api_register_command(plugin_name, command_name_str, min_args, max_args, c_synopsis,
            description_str, c_arguments, c_examples, p_callback, python_command_callback, NULL);
        free(command_name_str);
        free(description_str);
        i = 0;
        while (c_synopsis[i] != NULL) {
            free(c_synopsis[i++]);
        }
        i = 0;
        while (c_arguments[i] != NULL && c_arguments[i][0] != NULL) {
            free(c_arguments[i][0]);
            free(c_arguments[i][1]);
            i++;
        }
        i = 0;
        while (c_examples[i] != NULL) {
            free(c_examples[i++]);
        }
        disable_python_threads();
    }

    free(plugin_name);

    Py_RETURN_NONE;
}