43 #pragma GCC diagnostic push 44 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 46 #pragma GCC diagnostic pop 100 TRACE_CALL(__func__);
102 if (PyErr_Occurred())
113 TRACE_CALL(__func__);
117 g_print(
"Python@%ld: %s.%s(...) -> %s\n",
118 PyObject_Hash(instance),
119 instance->ob_type->tp_name,
126 TRACE_CALL(__func__);
130 PyObject* attr = PyObject_GetAttrString(instance, attr_name);
131 if (attr && PyLong_Check(attr))
133 return PyLong_AsLong(attr);
141 TRACE_CALL(__func__);
145 if (PyObject_HasAttrString(instance, attr_name))
150 g_printerr(
"Python plugin instance is missing member: %s\n", attr_name);
156 TRACE_CALL(__func__);
161 void* result = malloc(bytes);
165 g_printerr(
"Unable to allocate %d bytes in memory!\n", bytes);
174 TRACE_CALL(__func__);
177 if (len <= 0 ||
string == NULL)
182 const char* py_str = PyUnicode_AsUTF8(
string);
185 const int label_size =
sizeof(char) * (len + 1);
188 memcpy(result, py_str, len);
196 remmina_plugin_service = service;
206 TRACE_CALL(__func__);
216 g_printerr(
"A plugin named '%s' has already been registered! Skipping...", plugin->
generic_plugin->
name);
226 TRACE_CALL(__func__);
228 if (PyUnicode_Check(field))
230 Py_ssize_t len = PyUnicode_GetLength(field);
243 else if (PyBool_Check(field))
246 long* long_target = (
long*)target;
247 *long_target = PyLong_AsLong(field);
250 else if (PyLong_Check(field))
253 long* long_target = (
long*)target;
254 *long_target = PyLong_AsLong(field);
257 else if (PyTuple_Check(field))
259 Py_ssize_t len = PyTuple_Size(field);
263 memset(dest, 0,
sizeof(gpointer) * (len + 1));
265 for (Py_ssize_t i = 0; i < len; ++i)
267 PyObject*
item = PyTuple_GetItem(field, i);
282 TRACE_CALL(__func__);
306 return (GtkWidget*)pygobject_new(obj);
311 return (GtkWidget*)pygobject_get(obj);
const char * ATTR_INIT_ORDER
void init_pygobject()
Initializes the pygobject library.
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...
Maps an instance of a Python plugin to a Remmina one.
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.
const char * ATTR_EXPORT_HINTS
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.
long remmina_plugin_python_get_attribute_long(PyObject *instance, const char *attr_name, long def)
Gets the attribute as long value.
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.
const char * ATTR_PREF_LABEL
static const int REASONABLE_LIMIT_FOR_MALLOC
To prevent some memory related attacks or accidental allocation of an excessive amount of byes...
gboolean remmina_plugin_python_check_error(void)
Checks if an error has occurred and prints it.
static GPtrArray * plugin_map
const char * ATTR_ADVANCED_SETTINGS
const char * ATTR_DESCRIPTION
const char * ATTR_ICON_NAME_SSH
RemminaPlugin * generic_plugin
static PyObject * __last_result
A cache to store the last result that has been returned by the Python code using CallPythonMethod (...
void remmina_plugin_python_add_plugin(PyPlugin *plugin)
Registers the given plugin if no other plugin with the same name has been already registered...
void remmina_plugin_python_set_service(RemminaPluginService *service)
Sets the pointer to the plugin service of Remmina.
const char * ATTR_FEATURES
gboolean remmina_plugin_python_check_attribute(PyObject *instance, const char *attr_name)
Checks if a given attribute exists.
RemminaPluginService * remmina_plugin_python_get_service(void)
const char * ATTR_BASIC_SETTINGS
Contains functions and constants that are commonly used throughout the Python plugin implementation...
static RemminaPluginService * remmina_plugin_service
void * remmina_plugin_python_malloc(int bytes)
Allocates memory and checks for errors before returning.
static PyObject * pygobject_init(int req_major, int req_minor, int req_micro)
pygobject_init: : minimum version major number, or -1 : minimum version minor number, or -1 : minimum version micro number, or -1
const char * ATTR_ICON_NAME
GtkWidget * new_pywidget(GObject *obj)
Creates a new GtkWidget.
PyObject * remmina_plugin_python_last_result_set(PyObject *last_result)
Sets the result of the last python method call.
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.