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_remmina_file.c
Go to the documentation of this file.
1 /*
2  * Remmina - The GTK+ Remote Desktop Client
3  * Copyright (C) 2016-2022 Antenore Gatta, Giovanni Panozzo
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 
35 // I N C L U D E S
37 
39 #include "remmina_file.h"
42 
44 // D E C L A R A T I O N S
46 
47 static PyObject* file_get_path(PyRemminaFile* self, PyObject* args);
48 static PyObject* file_set_setting(PyRemminaFile* self, PyObject* args, PyObject* kwds);
49 static PyObject* file_get_setting(PyRemminaFile* self, PyObject* args, PyObject* kwds);
50 static PyObject* file_get_secret(PyRemminaFile* self, PyObject* setting);
51 static PyObject* file_unsave_passwords(PyRemminaFile* self, PyObject* args);
52 
53 static void file_dealloc(PyObject* self)
54 {
55  PyObject_Del(self);
56 }
57 
58 static PyMethodDef python_remmina_file_type_methods[] = {
59  { "get_path", (PyCFunction)file_get_path, METH_NOARGS, "" },
60  { "set_setting", (PyCFunction)file_set_setting, METH_VARARGS | METH_KEYWORDS, "Set file setting" },
61  { "get_setting", (PyCFunction)file_get_setting, METH_VARARGS | METH_KEYWORDS, "Get file setting" },
62  { "get_secret", (PyCFunction)file_get_secret, METH_VARARGS, "Get secret file setting" },
63  { "unsave_passwords", (PyCFunction)file_unsave_passwords, METH_NOARGS, "" },
64  { NULL }
65 };
66 
70 static PyTypeObject python_remmina_file_type = {
71  PyVarObject_HEAD_INIT(NULL, 0)
72  .tp_name = "remmina.RemminaFile",
73  .tp_doc = "",
74  .tp_basicsize = sizeof(PyRemminaFile),
75  .tp_itemsize = 0,
76  .tp_flags = Py_TPFLAGS_DEFAULT,
78  .tp_dealloc = file_dealloc
79 };
80 
82 // A P I
84 
86 {
87  PyType_Ready(&python_remmina_file_type);
88 }
89 
91 {
92  TRACE_CALL(__func__);
93 
94  PyRemminaFile* result = PyObject_New(PyRemminaFile, &python_remmina_file_type);
95  result->file = file;
96  Py_INCREF(result);
97  return result;
98 }
99 
100 static PyObject* file_get_path(PyRemminaFile* self, PyObject* args)
101 {
102  TRACE_CALL(__func__);
103 
104  return Py_BuildValue("s", remmina_file_get_filename(self->file));
105 }
106 
107 static PyObject* file_set_setting(PyRemminaFile* self, PyObject* args, PyObject* kwds)
108 {
109  TRACE_CALL(__func__);
110 
111  static char* keyword_list[] = { "key", "value", NULL };
112  gchar* key;
113  PyObject* value;
114 
115  if (PyArg_ParseTupleAndKeywords(args, kwds, "s|O", keyword_list, &key, &value))
116  {
117  if (PyUnicode_Check(value))
118  {
119  remmina_file_set_string(self->file, key, PyUnicode_AsUTF8(value));
120  }
121  else if (PyLong_Check(value))
122  {
123  remmina_file_set_int(self->file, key, PyLong_AsLong(value));
124  }
125  else
126  {
127  g_printerr("%s: Not a string or int value\n", PyUnicode_AsUTF8(PyObject_Str(value)));
128  }
129  return Py_None;
130  }
131  else
132  {
133  g_printerr("file.set_setting(key, value): Error parsing arguments!\n");
134  PyErr_Print();
135  return NULL;
136  }
137 }
138 
139 static PyObject* file_get_setting(PyRemminaFile* self, PyObject* args, PyObject* kwds)
140 {
141  TRACE_CALL(__func__);
142 
143  static gchar* keyword_list[] = { "key", "default" };
144  gchar* key;
145  PyObject* def;
146 
147  if (PyArg_ParseTupleAndKeywords(args, kwds, "sO", keyword_list, &key, &def))
148  {
149  if (PyUnicode_Check(def))
150  {
151  return Py_BuildValue("s", remmina_file_get_string(self->file, key));
152  }
153  else if (PyBool_Check(def))
154  {
155  return remmina_file_get_int(self->file, key, (gint)PyLong_AsLong(def)) ? Py_True : Py_False;
156  }
157  else if (PyLong_Check(def))
158  {
159  return Py_BuildValue("i", remmina_file_get_int(self->file, key, (gint)PyLong_AsLong(def)));
160  }
161  else
162  {
163  g_printerr("%s: Not a string or int value\n", PyUnicode_AsUTF8(PyObject_Str(def)));
164  }
165  return def;
166  }
167  else
168  {
169  g_printerr("file.get_setting(key, default): Error parsing arguments!\n");
170  PyErr_Print();
171  return Py_None;
172  }
173 }
174 
175 static PyObject* file_get_secret(PyRemminaFile* self, PyObject* key)
176 {
177  TRACE_CALL(__func__);
178 
179  if (key && PyUnicode_Check(key))
180  {
181  return Py_BuildValue("s", remmina_file_get_secret(self->file, PyUnicode_AsUTF8(key)));
182  }
183  else
184  {
185  g_printerr("file.get_secret(key): Error parsing arguments!\n");
186  PyErr_Print();
187  return NULL;
188  }
189 }
190 
191 static PyObject* file_unsave_passwords(PyRemminaFile* self, PyObject* args)
192 {
193  TRACE_CALL(__func__);
194 
195  if (self)
196  {
197  remmina_file_unsave_passwords(self->file);
198  return Py_None;
199  }
200  else
201  {
202  g_printerr("unsave_passwords(): self is null!\n");
203  return NULL;
204  }
205 }
const gchar * remmina_file_get_string(RemminaFile *remminafile, const gchar *setting)
Definition: remmina_file.c:495
static PyObject * file_get_secret(PyRemminaFile *self, PyObject *setting)
PyRemminaFile * remmina_plugin_python_remmina_file_to_python(RemminaFile *file)
Converts the instance of RemminaFile to a Python object that can be passed to the Python engine...
const gchar * remmina_file_get_filename(RemminaFile *remminafile)
Definition: remmina_file.c:206
typedefG_BEGIN_DECLS struct _RemminaFile RemminaFile
Definition: types.h:44
gchar * remmina_file_get_secret(RemminaFile *remminafile, const gchar *setting)
Definition: remmina_file.c:530
void remmina_plugin_python_remmina_init_types(void)
PyObject_HEAD RemminaFile * file
static PyObject * file_set_setting(PyRemminaFile *self, PyObject *args, PyObject *kwds)
static PyMethodDef python_remmina_file_type_methods[]
static void file_dealloc(PyObject *self)
void remmina_file_set_int(RemminaFile *remminafile, const gchar *setting, gint value)
Definition: remmina_file.c:564
static PyObject * file_get_setting(PyRemminaFile *self, PyObject *args, PyObject *kwds)
static PyObject * file_get_path(PyRemminaFile *self, PyObject *args)
Wrapper for a Python object that contains a pointer to an instance of RemminaFile.
gint remmina_file_get_int(RemminaFile *remminafile, const gchar *setting, gint default_value)
Definition: remmina_file.c:582
static PyObject * file_unsave_passwords(PyRemminaFile *self, PyObject *args)
Contains functions and constants that are commonly used throughout the Python plugin implementation...
void remmina_file_set_string(RemminaFile *remminafile, const gchar *setting, const gchar *value)
Definition: remmina_file.c:459
void remmina_file_unsave_passwords(RemminaFile *remminafile)
Definition: remmina_file.c:955
static PyTypeObject python_remmina_file_type
The definition of the Python module 'remmina'.