Remmina - The GTK+ Remote Desktop Client  v1.4.33
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.
python_wrapper_common.h
Go to the documentation of this file.
1 /*
2  * Remmina - The GTK+ Remote Desktop Client
3  * Copyright (C) 2014-2023 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 "common/remmina_plugin.h"
50 
51 #include <gtk/gtk.h>
52 
53 #include <Python.h>
54 #include <glib.h>
55 #include <Python.h>
56 #include <structmember.h>
57 
58 #include "remmina/plugin.h"
59 #include "config.h"
60 
61 
63 // D E C L A R A T I O N S
65 
66 G_BEGIN_DECLS
67 
68 // - Attribute names
69 
70 extern const char* ATTR_NAME;
71 extern const char* ATTR_ICON_NAME;
72 extern const char* ATTR_DESCRIPTION;
73 extern const char* ATTR_VERSION;
74 extern const char* ATTR_ICON_NAME_SSH;
75 extern const char* ATTR_FEATURES;
76 extern const char* ATTR_BASIC_SETTINGS;
77 extern const char* ATTR_ADVANCED_SETTINGS;
78 extern const char* ATTR_SSH_SETTING;
79 extern const char* ATTR_EXPORT_HINTS;
80 extern const char* ATTR_PREF_LABEL;
81 extern const char* ATTR_INIT_ORDER;
82 
83 // You can enable this for debuggin purposes or specify it in the build.
84 // #define WITH_PYTHON_TRACE_CALLS
85 
89 #ifdef WITH_PYTHON_TRACE_CALLS
90 #define CallPythonMethod(instance, name, params, ...) \
91  python_wrapper_last_result_set(PyObject_CallMethod(instance, name, params, ##__VA_ARGS__)); \
92  python_wrapper_log_method_call(instance, name); \
93  python_wrapper_check_error()
94 #else
95 
98 #define CallPythonMethod(instance, name, params, ...) \
99  PyObject_CallMethod(instance, name, params, ##__VA_ARGS__); \
100  python_wrapper_check_error()
101 #endif // WITH_PYTHON_TRACE_CALLS
102 
103 
105 // T Y P E S
107 
114 typedef struct
115 {
116  PyObject_HEAD
119 
126 typedef struct
127 {
136  PyObject* instance;
137 } PyPlugin;
138 
142 typedef struct
143 {
146  gpointer raw;
147 } PyGeneric;
148 
152 #define SELF_CHECK() if (!self) { \
153  g_printerr("[%s:%d]: self is null!\n", __FILE__, __LINE__); \
154  PyErr_SetString(PyExc_RuntimeError, "Method is not called from an instance (self is null)!"); \
155  return NULL; \
156  }
157 
159 // A P I
161 
166 
170 void python_wrapper_add_plugin(PyPlugin* plugin);
171 
176 
181 
185 RemminaTypeHint python_wrapper_to_generic(PyObject* field, gpointer* target);
186 
190 PyObject* python_wrapper_last_result(void);
191 
197 PyObject* python_wrapper_last_result_set(PyObject* result);
198 
207 void python_wrapper_log_method_call(PyObject* instance, const char* method);
208 
214 gboolean python_wrapper_check_error(void);
215 
225 long python_wrapper_get_attribute_long(PyObject* instance, const char* attr_name, long def);
226 
235 gboolean python_wrapper_check_attribute(PyObject* instance, const char* attr_name);
236 
244 void* python_wrapper_malloc(int bytes);
245 
254 char* python_wrapper_copy_string_from_python(PyObject* string, Py_ssize_t len);
255 
264 PyPlugin* python_wrapper_get_plugin(const gchar* name);
265 
275 
281 GtkWidget* new_pywidget(GObject* obj);
282 
288 GtkWidget* get_pywidget(PyObject* obj);
289 
293 void init_pygobject(void);
294 
295 G_END_DECLS
GtkWidget * new_pywidget(GObject *obj)
Creates a new GtkWidget.
void * python_wrapper_malloc(int bytes)
Allocates memory and checks for errors before returning.
RemminaTypeHint
Definition: types.h:60
Maps an instance of a Python plugin to a Remmina one.
RemminaSecretPlugin * secret_plugin
PyObject * python_wrapper_last_result_set(PyObject *result)
Sets the result of the last python method call.
PyObject_HEAD RemminaProtocolWidget * gp
RemminaTypeHint python_wrapper_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...
A struct used to communicate data between Python and C without strict data type.
RemminaFilePlugin * file_plugin
const char * ATTR_ICON_NAME_SSH
const char * ATTR_ADVANCED_SETTINGS
const char * ATTR_FEATURES
RemminaProtocolPlugin * protocol_plugin
PyPlugin * python_wrapper_get_plugin(const gchar *name)
Tries to find the Python plugin matching to the given instance of RemminaPlugin.
const char * ATTR_EXPORT_HINTS
const char * ATTR_DESCRIPTION
gboolean python_wrapper_check_error(void)
Checks if an error has occurred and prints it.
Definition: plugin.h:90
RemminaToolPlugin * tool_plugin
const char * ATTR_BASIC_SETTINGS
void python_wrapper_log_method_call(PyObject *instance, const char *method)
Prints a log message to inform the user a python message has been called.
PyRemminaProtocolWidget * gp
void init_pygobject(void)
Initializes the pygobject library.
PyObject * python_wrapper_last_result(void)
Gets the result of the last python method call.
const char * ATTR_INIT_ORDER
G_BEGIN_DECLS const char * ATTR_NAME
RemminaPlugin * generic_plugin
PyPlugin * python_wrapper_get_plugin_by_protocol_widget(RemminaProtocolWidget *gp)
Tries to find the Python plugin matching to the given instance of RemminaPlugin.
void python_wrapper_set_service(RemminaPluginService *service)
Sets the pointer to the plugin service of Remmina.
RemminaPluginService * python_wrapper_get_service(void)
Gets the pointer to the plugin service of Remmina.
GtkWidget * get_pywidget(PyObject *obj)
Extracts a GtkWidget from a PyObject instance.
char * python_wrapper_copy_string_from_python(PyObject *string, Py_ssize_t len)
Copies a string from a Python object to a new point in memory.
gboolean python_wrapper_check_attribute(PyObject *instance, const char *attr_name)
Checks if a given attribute exists.
const char * ATTR_PREF_LABEL
RemminaTypeHint type_hint
const char * ATTR_VERSION
const char * ATTR_ICON_NAME
long python_wrapper_get_attribute_long(PyObject *instance, const char *attr_name, long def)
Gets the attribute as long value.
The Python abstraction of the protocol widget struct.
void python_wrapper_add_plugin(PyPlugin *plugin)
Registers the given plugin if no other plugin with the same name has been already registered...
const char * ATTR_SSH_SETTING
PyGeneric * python_wrapper_generic_new(void)
Creates a new instance of PyGeneric.
RemminaPrefPlugin * pref_plugin
RemminaEntryPlugin * entry_plugin
PyObject * instance