Remmina - The GTK+ Remote Desktop Client  v1.4.25
Remmina is a remote desktop client written in GTK+, aiming to be useful for system administrators and travellers, who need to work with lots of remote computers in front of either large monitors or tiny netbooks. Remmina supports multiple network protocols in an integrated and consistent user interface. Currently RDP, VNC, NX, XDMCP and SSH are supported.
remmina_plugin_python_common.h
Go to the documentation of this file.
1 /*
2  * Remmina - The GTK+ Remote Desktop Client
3  * Copyright (C) 2014-2021 Antenore Gatta, Giovanni Panozzo, Mathias Winterhalter (ToolsDevler)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  * In addition, as a special exception, the copyright holders give
21  * permission to link the code of portions of this program with the
22  * OpenSSL library under certain conditions as described in each
23  * individual source file, and distribute linked combinations
24  * including the two.
25  * You must obey the GNU General Public License in all respects
26  * for all of the code used other than OpenSSL. * If you modify
27  * file(s) with this exception, you may extend this exception to your
28  * version of the file(s), but you are not obligated to do so. * If you
29  * do not wish to do so, delete this exception statement from your
30  * version. * If you delete this exception statement from all source
31  * files in the program, then also delete it here.
32  */
33 
43 #pragma once
44 
46 // I N C L U D E S
48 
49 #include <glib.h>
50 #include <gtk/gtk.h>
51 
52 #include <Python.h>
53 #include <glib.h>
54 #include <Python.h>
55 #include <structmember.h>
56 
57 #include "remmina/plugin.h"
58 #include "config.h"
59 
60 
62 // D E C L A R A T I O N S
64 
65 G_BEGIN_DECLS
66 
67 // - Attribute names
68 
69 extern const char* ATTR_NAME;
70 extern const char* ATTR_ICON_NAME;
71 extern const char* ATTR_DESCRIPTION;
72 extern const char* ATTR_VERSION;
73 extern const char* ATTR_ICON_NAME_SSH;
74 extern const char* ATTR_FEATURES;
75 extern const char* ATTR_BASIC_SETTINGS;
76 extern const char* ATTR_ADVANCED_SETTINGS;
77 extern const char* ATTR_SSH_SETTING;
78 extern const char* ATTR_EXPORT_HINTS;
79 extern const char* ATTR_PREF_LABEL;
80 extern const char* ATTR_INIT_ORDER;
81 
82 // You can enable this for debuggin purposes or specify it in the build.
83 // #define WITH_PYTHON_TRACE_CALLS
84 
88 #ifdef WITH_PYTHON_TRACE_CALLS
89 #define CallPythonMethod(instance, name, params, ...) \
90  remmina_plugin_python_last_result_set(PyObject_CallMethod(instance, name, params, ##__VA_ARGS__)); \
91  remmina_plugin_python_log_method_call(instance, name); \
92  remmina_plugin_python_check_error()
93 #else
94 
97 #define CallPythonMethod(instance, name, params, ...) \
98  PyObject_CallMethod(instance, name, params, ##__VA_ARGS__); \
99  remmina_plugin_python_check_error()
100 #endif // WITH_PYTHON_TRACE_CALLS
101 
102 
104 // T Y P E S
106 
113 typedef struct
114 {
115  PyObject_HEAD
118 
125 typedef struct
126 {
135  PyObject* instance;
136 } PyPlugin;
137 
141 typedef struct
142 {
145  gpointer raw;
146 } PyGeneric;
147 
151 #define SELF_CHECK() if (!self) { \
152  g_printerr("[%s:%d]: self is null!\n", __FILE__, __LINE__); \
153  PyErr_SetString(PyExc_RuntimeError, "Method is not called from an instance (self is null)!"); \
154  return NULL; \
155  }
156 
158 // A P I
160 
165 
170 
175 
179 RemminaTypeHint remmina_plugin_python_to_generic(PyObject* field, gpointer* target);
180 
184 PyObject* remmina_plugin_python_last_result(void);
185 
191 PyObject* remmina_plugin_python_last_result_set(PyObject* result);
192 
201 void remmina_plugin_python_log_method_call(PyObject* instance, const char* method);
202 
208 gboolean remmina_plugin_python_check_error(void);
209 
219 long remmina_plugin_python_get_attribute_long(PyObject* instance, const char* attr_name, long def);
220 
229 gboolean remmina_plugin_python_check_attribute(PyObject* instance, const char* attr_name);
230 
238 void* remmina_plugin_python_malloc(int bytes);
239 
248 char* remmina_plugin_python_copy_string_from_python(PyObject* string, Py_ssize_t len);
249 
258 PyPlugin* remmina_plugin_python_get_plugin(const char* name);
259 
265 GtkWidget* new_pywidget(GObject* obj);
266 
272 GtkWidget* get_pywidget(PyObject* obj);
273 
277 void init_pygobject(void);
278 
279 G_END_DECLS
RemminaTypeHint
Definition: types.h:60
gboolean remmina_plugin_python_check_error(void)
Checks if an error has occurred and prints it.
Maps an instance of a Python plugin to a Remmina one.
RemminaSecretPlugin * secret_plugin
const char * ATTR_FEATURES
const char * ATTR_SSH_SETTING
const char * ATTR_VERSION
PyObject * remmina_plugin_python_last_result(void)
Gets the result of the last python method call.
PyObject_HEAD RemminaProtocolWidget * gp
const char * ATTR_BASIC_SETTINGS
const char * ATTR_ICON_NAME_SSH
A struct used to communicate data between Python and C without strict data type.
RemminaFilePlugin * file_plugin
GtkWidget * new_pywidget(GObject *obj)
Creates a new GtkWidget.
RemminaProtocolPlugin * protocol_plugin
Definition: plugin.h:88
RemminaToolPlugin * tool_plugin
PyRemminaProtocolWidget * gp
char * remmina_plugin_python_copy_string_from_python(PyObject *string, Py_ssize_t len)
Copies a string from a Python object to a new point in memory.
const char * ATTR_INIT_ORDER
RemminaPlugin * generic_plugin
void init_pygobject(void)
Initializes the pygobject library.
const char * ATTR_EXPORT_HINTS
void * remmina_plugin_python_malloc(int bytes)
Allocates memory and checks for errors before returning.
const char * ATTR_ICON_NAME
G_BEGIN_DECLS const char * ATTR_NAME
const char * ATTR_ADVANCED_SETTINGS
PyObject * remmina_plugin_python_last_result_set(PyObject *result)
Sets the result of the last python method call.
RemminaTypeHint type_hint
RemminaTypeHint remmina_plugin_python_to_generic(PyObject *field, gpointer *target)
Extracts data from a PyObject instance to a generic pointer and returns a type hint if it could be de...
const char * ATTR_PREF_LABEL
The Python abstraction of the protocol widget struct.
void remmina_plugin_python_set_service(RemminaPluginService *service)
Sets the pointer to the plugin service of Remmina.
RemminaPrefPlugin * pref_plugin
long remmina_plugin_python_get_attribute_long(PyObject *instance, const char *attr_name, long def)
Gets the attribute as long value.
gboolean remmina_plugin_python_check_attribute(PyObject *instance, const char *attr_name)
Checks if a given attribute exists.
const char * ATTR_DESCRIPTION
PyPlugin * remmina_plugin_python_get_plugin(const char *name)
Tries to find the Python plugin matching to the given instance of RemminaPlugin.
GtkWidget * get_pywidget(PyObject *obj)
Extracts a GtkWidget from a PyObject instance.
void remmina_plugin_python_log_method_call(PyObject *instance, const char *method)
Prints a log message to inform the user a python message has been called.
PyGeneric * remmina_plugin_python_generic_new(void)
Creates a new instance of PyGeneric.
void remmina_plugin_python_add_plugin(PyPlugin *plugin)
Registers the given plugin if no other plugin with the same name has been already registered...
RemminaEntryPlugin * entry_plugin