diff options
author | ToolsDevler <info@toolsdevler.net> | 2020-10-11 18:59:18 +0300 |
---|---|---|
committer | ToolsDevler <info@toolsdevler.net> | 2020-12-31 03:03:24 +0300 |
commit | bd42c4051e1943b7ac8d7fb2f3bf3d99a91473ea (patch) | |
tree | aa6e0b4b7fccc96ab3b7a7d5a5c1c562dfce18be | |
parent | c2d7c99c61d7b5f8879f14b073dc51d1603facdc (diff) |
WIP: Established instance identification
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/include/remmina/plugin.h | 2 | ||||
-rw-r--r-- | src/remmina_plugin_python.c | 3 | ||||
-rw-r--r-- | src/remmina_plugin_python_module.c | 26 | ||||
-rw-r--r-- | src/remmina_plugin_python_plugin.c | 153 | ||||
-rw-r--r-- | src/remmina_plugin_python_plugin.h | 1 | ||||
-rw-r--r-- | src/remmina_protocol_widget.c | 1 | ||||
-rw-r--r-- | src/remmina_protocol_widget.h | 2 |
8 files changed, 125 insertions, 64 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 116bdc41a..e17ce8c20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,6 +185,7 @@ if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang") endif() endif() endif() +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) check_include_files(arpa/inet.h HAVE_ARPA_INET_H) diff --git a/src/include/remmina/plugin.h b/src/include/remmina/plugin.h index 5ad75ce28..20e67bfd6 100644 --- a/src/include/remmina/plugin.h +++ b/src/include/remmina/plugin.h @@ -36,6 +36,7 @@ #pragma once +#include <stdarg.h> #include <remmina/types.h> #include "remmina/remmina_trace_calls.h" @@ -58,6 +59,7 @@ typedef struct _RemminaPlugin { const gchar * version; } RemminaPlugin; +typedef struct _RemminaProtocolPlugin _RemminaProtocolPlugin; typedef struct _RemminaProtocolPlugin { RemminaPluginType type; const gchar * name; diff --git a/src/remmina_plugin_python.c b/src/remmina_plugin_python.c index 43257175b..e3b6a5de9 100644 --- a/src/remmina_plugin_python.c +++ b/src/remmina_plugin_python.c @@ -17,8 +17,7 @@ void remmina_plugin_python_init(void) { TRACE_CALL(__FUNC__); // Initialize Python environment - PyTypeObject* plugin_object = remmina_plugin_python_plugin_create(); - remmina_plugin_python_module_register_object(plugin_object); + remmina_plugin_python_module_register_object(remmina_plugin_python_plugin_create()); remmina_plugin_python_module_init(); Py_Initialize(); diff --git a/src/remmina_plugin_python_module.c b/src/remmina_plugin_python_module.c index fc1e25f53..d1c13217c 100644 --- a/src/remmina_plugin_python_module.c +++ b/src/remmina_plugin_python_module.c @@ -12,15 +12,33 @@ static GPtrArray* remmina_python_module_object_table = NULL; static GPtrArray* remmina_python_module_member_table = NULL; +static PyObject* remmina_plugin_python_log_printf_wrapper(PyObject* self, PyObject* n) { + PyObject* fmt = NULL; + if (!PyArg_ParseTuple(n, "S", &fmt)) { + g_print("Failed to load.\n"); + PyErr_Print(); + return NULL; + } + + remmina_log_printf(fmt); + + return NULL; +} + +static PyMethodDef remmina_python_module_type_methods[] = { + {"log_print", (PyCFunction)remmina_plugin_python_log_printf_wrapper, METH_VARARGS, NULL }, + {NULL} /* Sentinel */ +}; static PyModuleDef remmina_python_module_type = { PyModuleDef_HEAD_INIT, - "remmina", - "Remmina API.", - -1, - NULL + .m_name = "remmina", + .m_doc = "Remmina API.", + .m_size = -1, + .m_methods = remmina_python_module_type_methods }; + /** * */ diff --git a/src/remmina_plugin_python_plugin.c b/src/remmina_plugin_python_plugin.c index a25df8026..8d9f8f682 100644 --- a/src/remmina_plugin_python_plugin.c +++ b/src/remmina_plugin_python_plugin.c @@ -9,13 +9,7 @@ #include "remmina_plugin_manager.h" #include "remmina/plugin.h" #include "remmina_plugin_python_plugin.h" - -static const gchar* STR_REMMINA_PLUGIN_TYPE_PROTOCOL = "remmina.plugin_type.protocol"; -static const gchar* STR_REMMINA_PLUGIN_TYPE_ENTRY = "remmina.plugin_type.entry"; -static const gchar* STR_REMMINA_PLUGIN_TYPE_FILE = "remmina.plugin_type.file"; -static const gchar* STR_REMMINA_PLUGIN_TYPE_TOOL = "remmina.plugin_type.tool"; -static const gchar* STR_REMMINA_PLUGIN_TYPE_PREF = "remmina.plugin_type.pref"; -static const gchar* STR_REMMINA_PLUGIN_TYPE_SECRET = "remmina.plugin_type.secret"; +#include "remmina_protocol_widget.h" GPtrArray* remmina_plugin_registry = NULL; @@ -31,20 +25,20 @@ typedef struct { PyObject * ssh_setting; PyObject * features; RemminaProtocolWidget* widget; -} RemminaPluginPythonProtocolPlugin; +} RemminaPluginPythonPlugin; static PyMemberDef remmina_plugin_python_protocol_plugin_members[] = { - {"name", T_OBJECT_EX, offsetof(RemminaPluginPythonProtocolPlugin, name), 0, "plugin name"}, - {"description", T_OBJECT_EX, offsetof(RemminaPluginPythonProtocolPlugin, description), 0, "plugin description"}, - {"version", T_OBJECT_EX, offsetof(RemminaPluginPythonProtocolPlugin, version), 0, "plugin version"}, - {"appicon", T_OBJECT_EX, offsetof(RemminaPluginPythonProtocolPlugin, appicon), 0, "plugin app-icon name"}, - {"icon_name", T_OBJECT_EX, offsetof(RemminaPluginPythonProtocolPlugin, icon_name), 0, "icon_name"}, - {"icon_name_ssh", T_OBJECT_EX, offsetof(RemminaPluginPythonProtocolPlugin, icon_name_ssh), 0, "icon_name_ssh"}, - {"basic_settings", T_OBJECT_EX, offsetof(RemminaPluginPythonProtocolPlugin, basic_settings), 0, "basic_settings"}, - {"advanced_settings", T_INT, offsetof(RemminaPluginPythonProtocolPlugin, advanced_settings), 0, "advanced_settings"}, - {"ssh_setting", T_INT, offsetof(RemminaPluginPythonProtocolPlugin, ssh_setting), 0, "ssh_setting"}, - {"features", T_OBJECT_EX, offsetof(RemminaPluginPythonProtocolPlugin, features), 0, "features"}, + {"name", T_OBJECT_EX, offsetof(RemminaPluginPythonPlugin, name), 0, "plugin name"}, + {"description", T_OBJECT_EX, offsetof(RemminaPluginPythonPlugin, description), 0, "plugin description"}, + {"version", T_OBJECT_EX, offsetof(RemminaPluginPythonPlugin, version), 0, "plugin version"}, + {"appicon", T_OBJECT_EX, offsetof(RemminaPluginPythonPlugin, appicon), 0, "plugin app-icon name"}, + {"icon_name", T_OBJECT_EX, offsetof(RemminaPluginPythonPlugin, icon_name), 0, "icon_name"}, + {"icon_name_ssh", T_OBJECT_EX, offsetof(RemminaPluginPythonPlugin, icon_name_ssh), 0, "icon_name_ssh"}, + {"basic_settings", T_OBJECT_EX, offsetof(RemminaPluginPythonPlugin, basic_settings), 0, "basic_settings"}, + {"advanced_settings", T_INT, offsetof(RemminaPluginPythonPlugin, advanced_settings), 0, "advanced_settings"}, + {"ssh_setting", T_INT, offsetof(RemminaPluginPythonPlugin, ssh_setting), 0, "ssh_setting"}, + {"features", T_OBJECT_EX, offsetof(RemminaPluginPythonPlugin, features), 0, "features"}, {NULL} /* Sentinel */ }; @@ -55,17 +49,22 @@ static const RemminaProtocolFeature remmina_protocol_python_plugin_features[] = { REMMINA_PROTOCOL_FEATURE_TYPE_END, 0, NULL, NULL, NULL } }; +static PyMethodDef remmina_plugin_python_protocol_plugin_methods[] = { + {"init", METH_NOARGS, NULL }, + {"open_connection", METH_NOARGS, NULL }, + {"close_connection", METH_NOARGS, NULL }, + {"query_feature", METH_NOARGS, NULL }, + {"call_feature", METH_NOARGS, NULL }, + {"send_keystrokes", METH_NOARGS, NULL }, + {"get_plugin_screenshot", METH_NOARGS, NULL }, + {NULL} /* Sentinel */ +}; -PyMethodDef remmina_plugin_python_protocol_plugin_methods[] = { - {"init", METH_VARARGS, NULL }, - {"open_connection", METH_VARARGS, NULL }, - {"close_connection", METH_VARARGS, NULL }, - {"query_feature", METH_VARARGS, NULL }, - {"call_feature", METH_VARARGS, NULL }, - {"send_keystrokes", METH_VARARGS, NULL }, - {"get_plugin_screenshot", METH_VARARGS, NULL } +static PyMemberDef remmina_plugin_python_manager_service_members[] = { + {NULL} /* Sentinel */ }; + /* void (*init)(RemminaProtocolWidget *gp); gboolean (*open_connection)(RemminaProtocolWidget *gp); @@ -78,16 +77,16 @@ PyMethodDef remmina_plugin_python_protocol_plugin_methods[] = { static void remmina_protocol_plugin_wrapper_init(RemminaProtocolWidget *gp); static gboolean remmina_protocol_plugin_wrapper_open_connection(RemminaProtocolWidget *gp); static gboolean remmina_protocol_plugin_wrapper_close_connection(RemminaProtocolWidget *gp); -static gboolean remmina_protocol_plugin_wrapper_query_feature(RemminaProtocolWidget *gp, const RemminaProtocolFeature *feature); -static void remmina_protocol_plugin_wrapper_call_feature(RemminaProtocolWidget *gp, const RemminaProtocolFeature *feature); -static void remmina_protocol_plugin_wrapper_send_keystrokes(RemminaProtocolWidget *gp, const guint keystrokes[], const gint keylen); -static gboolean remmina_protocol_plugin_wrapper_get_plugin_screenshot(RemminaProtocolWidget *gp, RemminaPluginScreenshotData *rpsd); +static gboolean remmina_protocol_plugin_wrapper_query_feature(RemminaProtocolPlugin* plugin, RemminaProtocolWidget *gp, const RemminaProtocolFeature *feature); +static void remmina_protocol_plugin_wrapper_call_feature(RemminaProtocolPlugin* plugin, RemminaProtocolWidget *gp, const RemminaProtocolFeature *feature); +static void remmina_protocol_plugin_wrapper_send_keystrokes(RemminaProtocolPlugin* plugin, RemminaProtocolWidget *gp, const guint keystrokes[], const gint keylen); +static gboolean remmina_protocol_plugin_wrapper_get_plugin_screenshot(RemminaProtocolPlugin* plugin, RemminaProtocolWidget *gp, RemminaPluginScreenshotData *rpsd); static void -remmina_plugin_python_init_protocol_plugin(RemminaProtocolPlugin* plugin, RemminaPluginPythonProtocolPlugin* pythonObject); +remmina_plugin_python_init_protocol_plugin(RemminaProtocolPlugin* plugin, RemminaPluginPythonPlugin* pythonObject); static int -remmina_protocol_plugin_init(RemminaPluginPythonProtocolPlugin *self, PyObject *args, PyObject *kwds); +remmina_protocol_plugin_init(RemminaPluginPythonPlugin *self, PyObject *args, PyObject *kwds); static PyObject * remmina_protocol_plugin_new(PyTypeObject *type, PyObject *args, PyObject *kwds); @@ -96,8 +95,8 @@ static PyTypeObject RemminaProtocolPluginPythonType = { PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "remmina.ProtocolPlugin", .tp_doc = "Custom objects", - .tp_basicsize = sizeof(RemminaPluginPythonProtocolPlugin), - .tp_itemsize = sizeof(RemminaPluginPythonProtocolPlugin), + .tp_basicsize = sizeof(RemminaPluginPythonPlugin), + .tp_itemsize = sizeof(RemminaPluginPythonPlugin), .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .tp_members = remmina_plugin_python_protocol_plugin_members, .tp_methods = remmina_plugin_python_protocol_plugin_methods, @@ -106,7 +105,7 @@ static PyTypeObject RemminaProtocolPluginPythonType = { }; static void -RemminaPluginPython_dealloc(RemminaPluginPythonProtocolPlugin *self){ +RemminaPluginPython_dealloc(RemminaPluginPythonPlugin *self){ Py_XDECREF(self->name); Py_XDECREF(self->description); Py_XDECREF(self->version); @@ -115,27 +114,30 @@ RemminaPluginPython_dealloc(RemminaPluginPythonProtocolPlugin *self){ } static void -remmina_plugin_python_init_protocol_plugin(RemminaProtocolPlugin* plugin, RemminaPluginPythonProtocolPlugin* pythonObject) { +remmina_plugin_python_init_protocol_plugin(RemminaProtocolPlugin* plugin, RemminaPluginPythonPlugin* pythonObject) { } -struct PyPlugin { +typedef struct { PyObject_HEAD - RemminaPluginPythonProtocolPlugin* internal; -}; + RemminaPluginPythonPlugin* internal; + RemminaPlugin* plugin; +} PyPlugin; PyTypeObject* remmina_plugin_python_plugin_create(void) { return &RemminaProtocolPluginPythonType; } static PyObject * remmina_protocol_plugin_new(PyTypeObject *type, PyObject *parent, PyObject *args) { - struct PyPlugin *state; + PyPlugin *state; PyObject *self; - self = PyType_GenericNew(type, parent, args); + self = (PyObject*)type->tp_alloc(type, 0); if (self == NULL) return NULL; // Cast the object to the appropriate type - state = (struct PyPlugin *) self; + state = (PyPlugin *) self; + state->plugin = NULL; + // Initialize your internal structure state->internal = malloc(sizeof(*state->internal)); if (state->internal == NULL) @@ -144,77 +146,86 @@ remmina_protocol_plugin_new(PyTypeObject *type, PyObject *parent, PyObject *args // This means no error occurred state->internal->name = PyUnicode_FromString(""); - if (!state->internal->name) { - Py_DECREF(self); - return NULL; - } - - state->internal->name = PyUnicode_FromString(""); + Py_INCREF(state->internal->name); if (!state->internal->name) { Py_DECREF(self); return NULL; } state->internal->description = PyUnicode_FromString(""); + Py_INCREF(state->internal->description); if (!state->internal->description) { Py_DECREF(self); return NULL; } state->internal->version = PyUnicode_FromString(""); + Py_INCREF(state->internal->version); if (!state->internal->version) { Py_DECREF(self); return NULL; } state->internal->appicon = PyUnicode_FromString(""); + Py_INCREF(state->internal->appicon); if (!state->internal->appicon) { Py_DECREF(self); return NULL; } state->internal->icon_name = PyUnicode_FromString(""); + Py_INCREF(state->internal->icon_name); if (!state->internal->icon_name) { Py_DECREF(self); return NULL; } state->internal->icon_name_ssh = PyUnicode_FromString(""); + Py_INCREF(state->internal->icon_name_ssh); if (!state->internal->icon_name_ssh) { Py_DECREF(self); return NULL; } state->internal->basic_settings = PyUnicode_FromString(""); + Py_INCREF(state->internal->basic_settings); if (!state->internal->basic_settings) { Py_DECREF(self); return NULL; } state->internal->advanced_settings = PyUnicode_FromString(""); + Py_INCREF(state->internal->advanced_settings); if (!state->internal->advanced_settings) { Py_DECREF(self); return NULL; } state->internal->ssh_setting = PyUnicode_FromString(""); + Py_INCREF(state->internal->ssh_setting); if (!state->internal->ssh_setting) { Py_DECREF(self); return NULL; } state->internal->features = PyUnicode_FromString(""); + Py_INCREF(state->internal->features); if (!state->internal->features) { Py_DECREF(self); return NULL; } + if (!remmina_plugin_registry) + remmina_plugin_registry = g_ptr_array_new(); + + g_ptr_array_add(remmina_plugin_registry, state); + return self; } static int -remmina_protocol_plugin_init(RemminaPluginPythonProtocolPlugin *self, PyObject *args, PyObject *kwds) +remmina_protocol_plugin_init(RemminaPluginPythonPlugin *self, PyObject *args, PyObject *kwds) { static char* kwlist[] = { "name", "description", "version", "appicon", NULL }; PyObject *name = NULL; @@ -254,7 +265,6 @@ remmina_protocol_plugin_init(RemminaPluginPythonProtocolPlugin *self, PyObject * if (PyArg_ParseTuple(args, "ssss", &name_str, &description_str, &version_str, &appicon_str)) printf("Initialied plugin: %s\nVersion: %s\nApp-Icon: %s\nDescription: %s\n", name_str, version_str, appicon_str, description_str); - /* Protocol plugin definition and features */ RemminaProtocolPlugin* remmina_plugin = (RemminaProtocolPlugin*)malloc(sizeof(RemminaProtocolPlugin)); @@ -279,36 +289,63 @@ remmina_protocol_plugin_init(RemminaPluginPythonProtocolPlugin *self, PyObject * remmina_plugin_manager_service.register_plugin((RemminaPlugin *)remmina_plugin); - return 0; } + +static PyObject* get_python_plugin_instance(RemminaProtocolWidget *gp) { + PyPlugin* state = NULL; + for (int i = 0; i < remmina_plugin_registry->len; i++) { + state = (PyPlugin*)g_ptr_array_index(remmina_plugin_registry, i); + if (!state->plugin) + continue; + if (g_strcmp0(state->plugin->name, gp->plugin->name)) { + return (PyObject*)state; + } + } + + return NULL; +} + static void remmina_protocol_plugin_wrapper_init(RemminaProtocolWidget *gp) { - + PyObject* self = get_python_plugin_instance(gp); + if (self) { + PyObject* result = PyObject_CallMethod(self, "init", NULL); + } } static gboolean remmina_protocol_plugin_wrapper_open_connection(RemminaProtocolWidget *gp) { - return TRUE; + PyObject* self = get_python_plugin_instance(gp); + if (self) { + PyObject* result = PyObject_CallMethod(self, "open_connection", NULL); + return PyObject_IsTrue(result); + } + return FALSE; } static gboolean remmina_protocol_plugin_wrapper_close_connection(RemminaProtocolWidget *gp) { - return TRUE; + PyObject* self = get_python_plugin_instance(gp); + if (self) { + PyObject* result = PyObject_CallMethod(self, "close_connection", NULL); + return PyObject_IsTrue(result); + } + return FALSE; } -static gboolean remmina_protocol_plugin_wrapper_query_feature(RemminaProtocolWidget *gp, const RemminaProtocolFeature *feature) { +static gboolean remmina_protocol_plugin_wrapper_query_feature(RemminaProtocolPlugin* plugin, RemminaProtocolWidget *gp, const RemminaProtocolFeature *feature) { return TRUE; } -static void remmina_protocol_plugin_wrapper_call_feature(RemminaProtocolWidget *gp, const RemminaProtocolFeature *feature) { +static void remmina_protocol_plugin_wrapper_call_feature(RemminaProtocolPlugin* plugin, RemminaProtocolWidget *gp, const RemminaProtocolFeature *feature) { } -static void remmina_protocol_plugin_wrapper_send_keystrokes(RemminaProtocolWidget *gp, const guint keystrokes[], const gint keylen) { +static void remmina_protocol_plugin_wrapper_send_keystrokes(RemminaProtocolPlugin* plugin, RemminaProtocolWidget *gp, const guint keystrokes[], const gint keylen) { } -static gboolean remmina_protocol_plugin_wrapper_get_plugin_screenshot(RemminaProtocolWidget *gp, RemminaPluginScreenshotData *rpsd) { +static gboolean remmina_protocol_plugin_wrapper_get_plugin_screenshot(RemminaProtocolPlugin* plugin, RemminaProtocolWidget *gp, RemminaPluginScreenshotData *rpsd) { return TRUE; } diff --git a/src/remmina_plugin_python_plugin.h b/src/remmina_plugin_python_plugin.h index dd202be66..c07817b3c 100644 --- a/src/remmina_plugin_python_plugin.h +++ b/src/remmina_plugin_python_plugin.h @@ -37,3 +37,4 @@ #pragma once PyTypeObject* remmina_plugin_python_plugin_create(void); +PyTypeObject* remmina_plugin_manager_service_create(void); diff --git a/src/remmina_protocol_widget.c b/src/remmina_protocol_widget.c index e8c41b544..93e663ed9 100644 --- a/src/remmina_protocol_widget.c +++ b/src/remmina_protocol_widget.c @@ -1808,6 +1808,7 @@ void remmina_protocol_widget_setup(RemminaProtocolWidget *gp, RemminaFile *remmi return; } gp->priv->plugin = plugin; + gp->plugin = plugin; gp->priv->scalemode = remmina_file_get_int(gp->priv->remmina_file, "scale", FALSE); gp->priv->scaler_expand = remmina_file_get_int(gp->priv->remmina_file, "scaler_expand", FALSE); diff --git a/src/remmina_protocol_widget.h b/src/remmina_protocol_widget.h index d8d401f7a..ff8d1874e 100644 --- a/src/remmina_protocol_widget.h +++ b/src/remmina_protocol_widget.h @@ -53,11 +53,13 @@ G_BEGIN_DECLS #define REMMINA_PROTOCOL_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), REMMINA_TYPE_PROTOCOL_WIDGET, RemminaProtocolWidgetClass)) typedef struct _RemminaProtocolWidgetPriv RemminaProtocolWidgetPriv; +typedef struct _RemminaProtocolPlugin RemminaProtocolPlugin; struct _RemminaProtocolWidget { GtkEventBox event_box; RemminaConnectionObject * cnnobj; RemminaProtocolWidgetPriv * priv; + RemminaProtocolPlugin * plugin; }; struct _RemminaProtocolWidgetClass { |