@@ -156,6 +156,98 @@ static PyObject* add_exception_mapping(PyObject* Py_UNUSED(self), PyObject* args
156156 Py_RETURN_NONE ;
157157}
158158
159+ #ifndef Py_LIMITED_API
160+ static PyObject * is_interface_name_valid (PyObject * Py_UNUSED (self ), PyObject * const * args , Py_ssize_t nargs ) {
161+ SD_BUS_PY_CHECK_ARGS_NUMBER (1 );
162+ SD_BUS_PY_CHECK_ARG_CHECK_FUNC (0 , PyUnicode_Check );
163+
164+ const char * string_to_check = SD_BUS_PY_UNICODE_AS_CHAR_PTR (args [0 ]);
165+ #else
166+ static PyObject * is_interface_name_valid (PyObject * Py_UNUSED (self ), PyObject * args ) {
167+ const char * string_to_check = NULL ;
168+ CALL_PYTHON_BOOL_CHECK (PyArg_ParseTuple (args , "s" , & string_to_check , NULL ));
169+ #endif
170+ #ifdef LIBSYSTEMD_NO_VALIDATION_FUNCS
171+ PyErr_SetString (PyExc_NotImplementedError , "libsystemd < 246 does not support validation functions" );
172+ return NULL ;
173+ #else
174+ if (sd_bus_interface_name_is_valid (string_to_check )) {
175+ Py_RETURN_TRUE ;
176+ } else {
177+ Py_RETURN_FALSE ;
178+ }
179+ #endif
180+ }
181+
182+ #ifndef Py_LIMITED_API
183+ static PyObject * is_service_name_valid (PyObject * Py_UNUSED (self ), PyObject * const * args , Py_ssize_t nargs ) {
184+ SD_BUS_PY_CHECK_ARGS_NUMBER (1 );
185+ SD_BUS_PY_CHECK_ARG_CHECK_FUNC (0 , PyUnicode_Check );
186+
187+ const char * string_to_check = SD_BUS_PY_UNICODE_AS_CHAR_PTR (args [0 ]);
188+ #else
189+ static PyObject * is_service_name_valid (PyObject * Py_UNUSED (self ), PyObject * args ) {
190+ const char * string_to_check = NULL ;
191+ CALL_PYTHON_BOOL_CHECK (PyArg_ParseTuple (args , "s" , & string_to_check , NULL ));
192+ #endif
193+ #ifdef LIBSYSTEMD_NO_VALIDATION_FUNCS
194+ PyErr_SetString (PyExc_NotImplementedError , "libsystemd < 246 does not support validation functions" );
195+ return NULL ;
196+ #else
197+ if (sd_bus_service_name_is_valid (string_to_check )) {
198+ Py_RETURN_TRUE ;
199+ } else {
200+ Py_RETURN_FALSE ;
201+ }
202+ #endif
203+ }
204+
205+ #ifndef Py_LIMITED_API
206+ static PyObject * is_member_name_valid (PyObject * Py_UNUSED (self ), PyObject * const * args , Py_ssize_t nargs ) {
207+ SD_BUS_PY_CHECK_ARGS_NUMBER (1 );
208+ SD_BUS_PY_CHECK_ARG_CHECK_FUNC (0 , PyUnicode_Check );
209+
210+ const char * string_to_check = SD_BUS_PY_UNICODE_AS_CHAR_PTR (args [0 ]);
211+ #else
212+ static PyObject * is_member_name_valid (PyObject * Py_UNUSED (self ), PyObject * args ) {
213+ const char * string_to_check = NULL ;
214+ CALL_PYTHON_BOOL_CHECK (PyArg_ParseTuple (args , "s" , & string_to_check , NULL ));
215+ #endif
216+ #ifdef LIBSYSTEMD_NO_VALIDATION_FUNCS
217+ PyErr_SetString (PyExc_NotImplementedError , "libsystemd < 246 does not support validation functions" );
218+ return NULL ;
219+ #else
220+ if (sd_bus_member_name_is_valid (string_to_check )) {
221+ Py_RETURN_TRUE ;
222+ } else {
223+ Py_RETURN_FALSE ;
224+ }
225+ #endif
226+ }
227+
228+ #ifndef Py_LIMITED_API
229+ static PyObject * is_object_path_valid (PyObject * Py_UNUSED (self ), PyObject * const * args , Py_ssize_t nargs ) {
230+ SD_BUS_PY_CHECK_ARGS_NUMBER (1 );
231+ SD_BUS_PY_CHECK_ARG_CHECK_FUNC (0 , PyUnicode_Check );
232+
233+ const char * string_to_check = SD_BUS_PY_UNICODE_AS_CHAR_PTR (args [0 ]);
234+ #else
235+ static PyObject * is_object_path_valid (PyObject * Py_UNUSED (self ), PyObject * args ) {
236+ const char * string_to_check = NULL ;
237+ CALL_PYTHON_BOOL_CHECK (PyArg_ParseTuple (args , "s" , & string_to_check , NULL ));
238+ #endif
239+ #ifdef LIBSYSTEMD_NO_VALIDATION_FUNCS
240+ PyErr_SetString (PyExc_NotImplementedError , "libsystemd < 246 does not support validation functions" );
241+ return NULL ;
242+ #else
243+ if (sd_bus_object_path_is_valid (string_to_check )) {
244+ Py_RETURN_TRUE ;
245+ } else {
246+ Py_RETURN_FALSE ;
247+ }
248+ #endif
249+ }
250+
159251PyMethodDef SdBusPyInternal_methods [] = {
160252 {"sd_bus_open" , (PyCFunction )sd_bus_py_open , METH_NOARGS ,
161253 "Open dbus connection. Session bus running as user or system bus as "
@@ -168,5 +260,9 @@ PyMethodDef SdBusPyInternal_methods[] = {
168260 {"encode_object_path" , (SD_BUS_PY_FUNC_TYPE )encode_object_path , SD_BUS_PY_METH , "Encode object path with object path prefix and arbitrary string" },
169261 {"decode_object_path" , (SD_BUS_PY_FUNC_TYPE )decode_object_path , SD_BUS_PY_METH , "Decode object path with object path prefix and arbitrary string" },
170262 {"add_exception_mapping" , (SD_BUS_PY_FUNC_TYPE )add_exception_mapping , SD_BUS_PY_METH , "Add exception to the mapping of dbus error names" },
263+ {"is_interface_name_valid" , (SD_BUS_PY_FUNC_TYPE )is_interface_name_valid , SD_BUS_PY_METH , "Is the string valid interface name?" },
264+ {"is_service_name_valid" , (SD_BUS_PY_FUNC_TYPE )is_service_name_valid , SD_BUS_PY_METH , "Is the string valid service name?" },
265+ {"is_member_name_valid" , (SD_BUS_PY_FUNC_TYPE )is_member_name_valid , SD_BUS_PY_METH , "Is the string valid member name?" },
266+ {"is_object_path_valid" , (SD_BUS_PY_FUNC_TYPE )is_object_path_valid , SD_BUS_PY_METH , "Is the string valid object path?" },
171267 {NULL , NULL , 0 , NULL },
172268};
0 commit comments