1 /* GDBus - GLib D-Bus Library
3 * Copyright (C) 2008-2009 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: David Zeuthen <davidz@redhat.com>
27 #include <glib/gi18n.h>
29 #include "gdbusintrospection.h"
32 * SECTION:gdbusintrospection
33 * @title: Introspection XML
34 * @short_description: Parse and Generate Introspection XML
37 * Various data structures and convenience routines to parse and
38 * generate D-Bus introspection XML.
41 /* ---------------------------------------------------------------------------------------------------- */
43 /* See also https://bugzilla.gnome.org/show_bug.cgi?id=449565 ... */
44 #define _MY_DEFINE_BOXED_TYPE(TypeName, type_name) \
46 type_name##_get_type (void) \
48 static volatile gsize type_volatile = 0; \
49 if (g_once_init_enter (&type_volatile)) \
51 GType type = g_boxed_type_register_static (g_intern_static_string (#TypeName), \
52 (GBoxedCopyFunc) type_name##_ref, \
53 (GBoxedFreeFunc) type_name##_unref); \
54 g_once_init_leave (&type_volatile, type); \
56 return (GType) type_volatile; \
59 _MY_DEFINE_BOXED_TYPE (GDBusNodeInfo, g_dbus_node_info);
60 _MY_DEFINE_BOXED_TYPE (GDBusInterfaceInfo, g_dbus_interface_info);
61 _MY_DEFINE_BOXED_TYPE (GDBusMethodInfo, g_dbus_method_info);
62 _MY_DEFINE_BOXED_TYPE (GDBusPropertyInfo, g_dbus_property_info);
63 _MY_DEFINE_BOXED_TYPE (GDBusArgInfo, g_dbus_arg_info);
64 _MY_DEFINE_BOXED_TYPE (GDBusAnnotationInfo, g_dbus_annotation_info);
66 /* ---------------------------------------------------------------------------------------------------- */
70 /* stuff we are currently collecting */
75 GPtrArray *properties;
76 GPtrArray *interfaces;
78 GPtrArray *annotations;
80 /* A list of GPtrArray's containing annotations */
81 GSList *annotations_stack;
83 /* A list of GPtrArray's containing interfaces */
84 GSList *interfaces_stack;
86 /* A list of GPtrArray's containing nodes */
89 /* Whether the direction was "in" for last parsed arg */
90 gboolean last_arg_was_in;
92 /* Number of args currently being collected; used for assigning
93 * names to args without a "name" attribute
99 /* ---------------------------------------------------------------------------------------------------- */
102 * g_dbus_node_info_ref:
103 * @info: A #GDBusNodeInfo
105 * If @info is statically allocated does nothing. Otherwise increases
106 * the reference count.
108 * Returns: The same @info.
113 g_dbus_node_info_ref (GDBusNodeInfo *info)
115 if (info->ref_count == -1)
117 g_atomic_int_inc (&info->ref_count);
122 * g_dbus_interface_info_ref:
123 * @info: A #GDBusInterfaceInfo
125 * If @info is statically allocated does nothing. Otherwise increases
126 * the reference count.
128 * Returns: The same @info.
133 g_dbus_interface_info_ref (GDBusInterfaceInfo *info)
135 if (info->ref_count == -1)
137 g_atomic_int_inc (&info->ref_count);
142 * g_dbus_method_info_ref:
143 * @info: A #GDBusMethodInfo
145 * If @info is statically allocated does nothing. Otherwise increases
146 * the reference count.
148 * Returns: The same @info.
153 g_dbus_method_info_ref (GDBusMethodInfo *info)
155 if (info->ref_count == -1)
157 g_atomic_int_inc (&info->ref_count);
162 * g_dbus_signal_info_ref:
163 * @info: A #GDBusSignalInfo
165 * If @info is statically allocated does nothing. Otherwise increases
166 * the reference count.
168 * Returns: The same @info.
173 g_dbus_signal_info_ref (GDBusSignalInfo *info)
175 if (info->ref_count == -1)
177 g_atomic_int_inc (&info->ref_count);
182 * g_dbus_property_info_ref:
183 * @info: A #GDBusPropertyInfo
185 * If @info is statically allocated does nothing. Otherwise increases
186 * the reference count.
188 * Returns: The same @info.
193 g_dbus_property_info_ref (GDBusPropertyInfo *info)
195 if (info->ref_count == -1)
197 g_atomic_int_inc (&info->ref_count);
202 * g_dbus_arg_info_ref:
203 * @info: A #GDBusArgInfo
205 * If @info is statically allocated does nothing. Otherwise increases
206 * the reference count.
208 * Returns: The same @info.
213 g_dbus_arg_info_ref (GDBusArgInfo *info)
215 if (info->ref_count == -1)
217 g_atomic_int_inc (&info->ref_count);
222 * g_dbus_node_info_ref:
223 * @info: A #GDBusNodeInfo
225 * If @info is statically allocated does nothing. Otherwise increases
226 * the reference count.
228 * Returns: The same @info.
232 GDBusAnnotationInfo *
233 g_dbus_annotation_info_ref (GDBusAnnotationInfo *info)
235 if (info->ref_count == -1)
237 g_atomic_int_inc (&info->ref_count);
241 /* ---------------------------------------------------------------------------------------------------- */
244 free_null_terminated_array (gpointer array, GDestroyNotify unref_func)
250 for (n = 0; p[n] != NULL; n++)
256 * g_dbus_annotation_info_unref:
257 * @info: A #GDBusAnnotationInfo.
259 * If @info is statically allocated, does nothing. Otherwise decreases
260 * the reference count of @info. When its reference count drops to 0,
261 * the memory used is freed.
266 g_dbus_annotation_info_unref (GDBusAnnotationInfo *info)
268 if (info->ref_count == -1)
270 if (g_atomic_int_dec_and_test (&info->ref_count))
273 g_free (info->value);
274 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
280 * g_dbus_arg_info_unref:
281 * @info: A #GDBusArgInfo.
283 * If @info is statically allocated, does nothing. Otherwise decreases
284 * the reference count of @info. When its reference count drops to 0,
285 * the memory used is freed.
290 g_dbus_arg_info_unref (GDBusArgInfo *info)
292 if (info->ref_count == -1)
294 if (g_atomic_int_dec_and_test (&info->ref_count))
297 g_free (info->signature);
298 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
304 * g_dbus_method_info_unref:
305 * @info: A #GDBusMethodInfo.
307 * If @info is statically allocated, does nothing. Otherwise decreases
308 * the reference count of @info. When its reference count drops to 0,
309 * the memory used is freed.
314 g_dbus_method_info_unref (GDBusMethodInfo *info)
316 if (info->ref_count == -1)
318 if (g_atomic_int_dec_and_test (&info->ref_count))
321 free_null_terminated_array (info->in_args, (GDestroyNotify) g_dbus_arg_info_unref);
322 free_null_terminated_array (info->out_args, (GDestroyNotify) g_dbus_arg_info_unref);
323 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
329 * g_dbus_signal_info_unref:
330 * @info: A #GDBusSignalInfo.
332 * If @info is statically allocated, does nothing. Otherwise decreases
333 * the reference count of @info. When its reference count drops to 0,
334 * the memory used is freed.
339 g_dbus_signal_info_unref (GDBusSignalInfo *info)
341 if (info->ref_count == -1)
343 if (g_atomic_int_dec_and_test (&info->ref_count))
346 free_null_terminated_array (info->args, (GDestroyNotify) g_dbus_arg_info_unref);
347 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
353 * g_dbus_property_info_unref:
354 * @info: A #GDBusPropertyInfo.
356 * If @info is statically allocated, does nothing. Otherwise decreases
357 * the reference count of @info. When its reference count drops to 0,
358 * the memory used is freed.
363 g_dbus_property_info_unref (GDBusPropertyInfo *info)
365 if (info->ref_count == -1)
367 if (g_atomic_int_dec_and_test (&info->ref_count))
370 g_free (info->signature);
371 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
377 * g_dbus_interface_info_unref:
378 * @info: A #GDBusInterfaceInfo.
380 * If @info is statically allocated, does nothing. Otherwise decreases
381 * the reference count of @info. When its reference count drops to 0,
382 * the memory used is freed.
387 g_dbus_interface_info_unref (GDBusInterfaceInfo *info)
389 if (info->ref_count == -1)
391 if (g_atomic_int_dec_and_test (&info->ref_count))
394 free_null_terminated_array (info->methods, (GDestroyNotify) g_dbus_method_info_unref);
395 free_null_terminated_array (info->signals, (GDestroyNotify) g_dbus_signal_info_unref);
396 free_null_terminated_array (info->properties, (GDestroyNotify) g_dbus_property_info_unref);
397 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
403 * g_dbus_node_info_unref:
404 * @info: A #GDBusNodeInfo.
406 * If @info is statically allocated, does nothing. Otherwise decreases
407 * the reference count of @info. When its reference count drops to 0,
408 * the memory used is freed.
413 g_dbus_node_info_unref (GDBusNodeInfo *info)
415 if (info->ref_count == -1)
417 if (g_atomic_int_dec_and_test (&info->ref_count))
420 free_null_terminated_array (info->interfaces, (GDestroyNotify) g_dbus_interface_info_unref);
421 free_null_terminated_array (info->nodes, (GDestroyNotify) g_dbus_node_info_unref);
422 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
427 /* ---------------------------------------------------------------------------------------------------- */
430 g_dbus_annotation_info_set (ParseData *data,
431 GDBusAnnotationInfo *info,
434 GDBusAnnotationInfo **embedded_annotations)
439 info->key = g_strdup (key);
442 info->value = g_strdup (value);
444 if (embedded_annotations != NULL)
445 info->annotations = embedded_annotations;
449 g_dbus_arg_info_set (ParseData *data,
452 const gchar *signature,
453 GDBusAnnotationInfo **annotations)
457 /* name may be NULL - TODO: compute name? */
459 info->name = g_strdup (name);
461 if (signature != NULL)
462 info->signature = g_strdup (signature);
464 if (annotations != NULL)
465 info->annotations = annotations;
469 g_dbus_method_info_set (ParseData *data,
470 GDBusMethodInfo *info,
473 GDBusArgInfo **in_args,
475 GDBusArgInfo **out_args,
476 GDBusAnnotationInfo **annotations)
481 info->name = g_strdup (name);
483 if (in_num_args != 0)
485 //info->in_num_args = in_num_args;
486 info->in_args = in_args;
489 if (out_num_args != 0)
491 //info->out_num_args = out_num_args;
492 info->out_args = out_args;
495 if (annotations != NULL)
496 info->annotations = annotations;
500 g_dbus_signal_info_set (ParseData *data,
501 GDBusSignalInfo *info,
505 GDBusAnnotationInfo **annotations)
510 info->name = g_strdup (name);
514 //info->num_args = num_args;
518 if (annotations != NULL)
520 info->annotations = annotations;
525 g_dbus_property_info_set (ParseData *data,
526 GDBusPropertyInfo *info,
528 const gchar *signature,
529 GDBusPropertyInfoFlags flags,
530 GDBusAnnotationInfo **annotations)
535 info->name = g_strdup (name);
537 if (flags != G_DBUS_PROPERTY_INFO_FLAGS_NONE)
540 if (signature != NULL)
542 info->signature = g_strdup (signature);
545 if (annotations != NULL)
547 info->annotations = annotations;
552 g_dbus_interface_info_set (ParseData *data,
553 GDBusInterfaceInfo *info,
556 GDBusMethodInfo **methods,
558 GDBusSignalInfo **signals,
559 guint num_properties,
560 GDBusPropertyInfo **properties,
561 GDBusAnnotationInfo **annotations)
567 info->name = g_strdup (name);
570 if (num_methods != 0)
572 //info->num_methods = num_methods;
573 info->methods = methods;
576 if (num_signals != 0)
578 //info->num_signals = num_signals;
579 info->signals = signals;
582 if (num_properties != 0)
584 //info->num_properties = num_properties;
585 info->properties = properties;
588 if (annotations != NULL)
590 info->annotations = annotations;
595 g_dbus_node_info_set (ParseData *data,
598 guint num_interfaces,
599 GDBusInterfaceInfo **interfaces,
601 GDBusNodeInfo **nodes,
602 GDBusAnnotationInfo **annotations)
608 info->path = g_strdup (path);
609 /* TODO: relative / absolute path snafu */
612 if (num_interfaces != 0)
614 //info->num_interfaces = num_interfaces;
615 info->interfaces = interfaces;
620 //info->num_nodes = num_nodes;
624 if (annotations != NULL)
626 info->annotations = annotations;
631 /* ---------------------------------------------------------------------------------------------------- */
634 g_dbus_annotation_info_generate_xml (const GDBusAnnotationInfo *info,
636 GString *string_builder)
640 g_string_append_printf (string_builder, "%*s<annotation name=\"%s\" value=\"%s\"",
645 if (info->annotations == NULL)
647 g_string_append (string_builder, "/>\n");
651 g_string_append (string_builder, ">\n");
653 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
654 g_dbus_annotation_info_generate_xml (info->annotations[n],
658 g_string_append_printf (string_builder, "%*s</annotation>\n",
665 g_dbus_arg_info_generate_xml (const GDBusArgInfo *info,
667 const gchar *extra_attributes,
668 GString *string_builder)
672 g_string_append_printf (string_builder, "%*s<arg type=\"%s\"",
676 if (info->name != NULL)
677 g_string_append_printf (string_builder, " name=\"%s\"", info->name);
679 if (extra_attributes != NULL)
680 g_string_append_printf (string_builder, " %s", extra_attributes);
682 if (info->annotations == NULL)
684 g_string_append (string_builder, "/>\n");
688 g_string_append (string_builder, ">\n");
690 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
691 g_dbus_annotation_info_generate_xml (info->annotations[n],
695 g_string_append_printf (string_builder, "%*s</arg>\n", indent, "");
701 g_dbus_method_info_generate_xml (const GDBusMethodInfo *info,
703 GString *string_builder)
707 g_string_append_printf (string_builder, "%*s<method name=\"%s\"",
711 if (info->annotations == NULL && info->in_args == NULL && info->out_args == NULL)
713 g_string_append (string_builder, "/>\n");
717 g_string_append (string_builder, ">\n");
719 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
720 g_dbus_annotation_info_generate_xml (info->annotations[n],
724 for (n = 0; info->in_args != NULL && info->in_args[n] != NULL; n++)
725 g_dbus_arg_info_generate_xml (info->in_args[n],
730 for (n = 0; info->out_args != NULL && info->out_args[n] != NULL; n++)
731 g_dbus_arg_info_generate_xml (info->out_args[n],
736 g_string_append_printf (string_builder, "%*s</method>\n", indent, "");
741 g_dbus_signal_info_generate_xml (const GDBusSignalInfo *info,
743 GString *string_builder)
747 g_string_append_printf (string_builder, "%*s<signal name=\"%s\"",
751 if (info->annotations == NULL && info->args == NULL)
753 g_string_append (string_builder, "/>\n");
757 g_string_append (string_builder, ">\n");
759 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
760 g_dbus_annotation_info_generate_xml (info->annotations[n],
764 for (n = 0; info->args != NULL && info->args[n] != NULL; n++)
765 g_dbus_arg_info_generate_xml (info->args[n],
770 g_string_append_printf (string_builder, "%*s</signal>\n", indent, "");
775 g_dbus_property_info_generate_xml (const GDBusPropertyInfo *info,
777 GString *string_builder)
780 const gchar *access_string;
782 if ((info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE) &&
783 (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE))
785 access_string = "readwrite";
787 else if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)
789 access_string = "read";
791 else if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE)
793 access_string = "write";
797 g_assert_not_reached ();
800 g_string_append_printf (string_builder, "%*s<property type=\"%s\" name=\"%s\" access=\"%s\"",
806 if (info->annotations == NULL)
808 g_string_append (string_builder, "/>\n");
812 g_string_append (string_builder, ">\n");
814 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
815 g_dbus_annotation_info_generate_xml (info->annotations[n],
819 g_string_append_printf (string_builder, "%*s</property>\n", indent, "");
825 * g_dbus_interface_info_generate_xml:
826 * @info: A #GDBusNodeInfo
827 * @indent: Indentation level.
828 * @string_builder: A #GString to to append XML data to.
830 * Appends an XML representation of @info (and its children) to @string_builder.
832 * This function is typically used for generating introspection XML
833 * documents at run-time for handling the
834 * <literal>org.freedesktop.DBus.Introspectable.Introspect</literal>
840 g_dbus_interface_info_generate_xml (const GDBusInterfaceInfo *info,
842 GString *string_builder)
846 g_string_append_printf (string_builder, "%*s<interface name=\"%s\">\n",
850 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
851 g_dbus_annotation_info_generate_xml (info->annotations[n],
855 for (n = 0; info->methods != NULL && info->methods[n] != NULL; n++)
856 g_dbus_method_info_generate_xml (info->methods[n],
860 for (n = 0; info->signals != NULL && info->signals[n] != NULL; n++)
861 g_dbus_signal_info_generate_xml (info->signals[n],
865 for (n = 0; info->properties != NULL && info->properties[n] != NULL; n++)
866 g_dbus_property_info_generate_xml (info->properties[n],
870 g_string_append_printf (string_builder, "%*s</interface>\n", indent, "");
874 * g_dbus_node_info_generate_xml:
875 * @node_info: A #GDBusNodeInfo.
876 * @indent: Indentation level.
877 * @string_builder: A #GString to to append XML data to.
879 * Appends an XML representation of @node_info (and its children) to @string_builder.
881 * This function is typically used for generating introspection XML documents at run-time for
882 * handling the <literal>org.freedesktop.DBus.Introspectable.Introspect</literal> method.
887 g_dbus_node_info_generate_xml (const GDBusNodeInfo *node_info,
889 GString *string_builder)
893 g_string_append_printf (string_builder, "%*s<node", indent, "");
894 if (node_info->path != NULL)
895 g_string_append_printf (string_builder, " name=\"%s\"", node_info->path);
897 if (node_info->interfaces == NULL && node_info->nodes == NULL && node_info->annotations == NULL)
899 g_string_append (string_builder, "/>\n");
903 g_string_append (string_builder, ">\n");
905 for (n = 0; node_info->annotations != NULL && node_info->annotations[n] != NULL; n++)
906 g_dbus_annotation_info_generate_xml (node_info->annotations[n],
910 for (n = 0; node_info->interfaces != NULL && node_info->interfaces[n] != NULL; n++)
911 g_dbus_interface_info_generate_xml (node_info->interfaces[n],
915 for (n = 0; node_info->nodes != NULL && node_info->nodes[n] != NULL; n++)
916 g_dbus_node_info_generate_xml (node_info->nodes[n],
920 g_string_append_printf (string_builder, "%*s</node>\n", indent, "");
924 /* ---------------------------------------------------------------------------------------------------- */
926 static GDBusAnnotationInfo **
927 parse_data_steal_annotations (ParseData *data, guint *out_num_elements)
929 GDBusAnnotationInfo **ret;
930 if (out_num_elements != NULL)
931 *out_num_elements = data->annotations->len;
932 if (data->annotations == NULL)
936 g_ptr_array_add (data->annotations, NULL);
937 ret = (GDBusAnnotationInfo **) g_ptr_array_free (data->annotations, FALSE);
939 data->annotations = g_ptr_array_new ();
943 static GDBusArgInfo **
944 parse_data_steal_args (ParseData *data, guint *out_num_elements)
947 if (out_num_elements != NULL)
948 *out_num_elements = data->args->len;
949 if (data->args == NULL)
953 g_ptr_array_add (data->args, NULL);
954 ret = (GDBusArgInfo **) g_ptr_array_free (data->args, FALSE);
956 data->args = g_ptr_array_new ();
960 static GDBusArgInfo **
961 parse_data_steal_out_args (ParseData *data, guint *out_num_elements)
964 if (out_num_elements != NULL)
965 *out_num_elements = data->out_args->len;
966 if (data->out_args == NULL)
970 g_ptr_array_add (data->out_args, NULL);
971 ret = (GDBusArgInfo **) g_ptr_array_free (data->out_args, FALSE);
973 data->out_args = g_ptr_array_new ();
977 static GDBusMethodInfo **
978 parse_data_steal_methods (ParseData *data, guint *out_num_elements)
980 GDBusMethodInfo **ret;
981 if (out_num_elements != NULL)
982 *out_num_elements = data->methods->len;
983 if (data->methods == NULL)
987 g_ptr_array_add (data->methods, NULL);
988 ret = (GDBusMethodInfo **) g_ptr_array_free (data->methods, FALSE);
990 data->methods = g_ptr_array_new ();
994 static GDBusSignalInfo **
995 parse_data_steal_signals (ParseData *data, guint *out_num_elements)
997 GDBusSignalInfo **ret;
998 if (out_num_elements != NULL)
999 *out_num_elements = data->signals->len;
1000 if (data->signals == NULL)
1004 g_ptr_array_add (data->signals, NULL);
1005 ret = (GDBusSignalInfo **) g_ptr_array_free (data->signals, FALSE);
1007 data->signals = g_ptr_array_new ();
1011 static GDBusPropertyInfo **
1012 parse_data_steal_properties (ParseData *data, guint *out_num_elements)
1014 GDBusPropertyInfo **ret;
1015 if (out_num_elements != NULL)
1016 *out_num_elements = data->properties->len;
1017 if (data->properties == NULL)
1021 g_ptr_array_add (data->properties, NULL);
1022 ret = (GDBusPropertyInfo **) g_ptr_array_free (data->properties, FALSE);
1024 data->properties = g_ptr_array_new ();
1028 static GDBusInterfaceInfo **
1029 parse_data_steal_interfaces (ParseData *data, guint *out_num_elements)
1031 GDBusInterfaceInfo **ret;
1032 if (out_num_elements != NULL)
1033 *out_num_elements = data->interfaces->len;
1034 if (data->interfaces == NULL)
1038 g_ptr_array_add (data->interfaces, NULL);
1039 ret = (GDBusInterfaceInfo **) g_ptr_array_free (data->interfaces, FALSE);
1041 data->interfaces = g_ptr_array_new ();
1045 static GDBusNodeInfo **
1046 parse_data_steal_nodes (ParseData *data, guint *out_num_elements)
1048 GDBusNodeInfo **ret;
1049 if (out_num_elements != NULL)
1050 *out_num_elements = data->nodes->len;
1051 if (data->nodes == NULL)
1055 g_ptr_array_add (data->nodes, NULL);
1056 ret = (GDBusNodeInfo **) g_ptr_array_free (data->nodes, FALSE);
1058 data->nodes = g_ptr_array_new ();
1062 /* ---------------------------------------------------------------------------------------------------- */
1065 parse_data_free_annotations (ParseData *data)
1067 if (data->annotations == NULL)
1069 g_ptr_array_foreach (data->annotations, (GFunc) g_dbus_annotation_info_unref, NULL);
1070 g_ptr_array_free (data->annotations, TRUE);
1071 data->annotations = NULL;
1075 parse_data_free_args (ParseData *data)
1077 if (data->args == NULL)
1079 g_ptr_array_foreach (data->args, (GFunc) g_dbus_arg_info_unref, NULL);
1080 g_ptr_array_free (data->args, TRUE);
1085 parse_data_free_out_args (ParseData *data)
1087 if (data->out_args == NULL)
1089 g_ptr_array_foreach (data->out_args, (GFunc) g_dbus_arg_info_unref, NULL);
1090 g_ptr_array_free (data->out_args, TRUE);
1091 data->out_args = NULL;
1095 parse_data_free_methods (ParseData *data)
1097 if (data->methods == NULL)
1099 g_ptr_array_foreach (data->methods, (GFunc) g_dbus_method_info_unref, NULL);
1100 g_ptr_array_free (data->methods, TRUE);
1101 data->methods = NULL;
1105 parse_data_free_signals (ParseData *data)
1107 if (data->signals == NULL)
1109 g_ptr_array_foreach (data->signals, (GFunc) g_dbus_signal_info_unref, NULL);
1110 g_ptr_array_free (data->signals, TRUE);
1111 data->signals = NULL;
1115 parse_data_free_properties (ParseData *data)
1117 if (data->properties == NULL)
1119 g_ptr_array_foreach (data->properties, (GFunc) g_dbus_property_info_unref, NULL);
1120 g_ptr_array_free (data->properties, TRUE);
1121 data->properties = NULL;
1125 parse_data_free_interfaces (ParseData *data)
1127 if (data->interfaces == NULL)
1129 g_ptr_array_foreach (data->interfaces, (GFunc) g_dbus_interface_info_unref, NULL);
1130 g_ptr_array_free (data->interfaces, TRUE);
1131 data->interfaces = NULL;
1135 parse_data_free_nodes (ParseData *data)
1137 if (data->nodes == NULL)
1139 g_ptr_array_foreach (data->nodes, (GFunc) g_dbus_node_info_unref, NULL);
1140 g_ptr_array_free (data->nodes, TRUE);
1144 /* ---------------------------------------------------------------------------------------------------- */
1146 static GDBusAnnotationInfo *
1147 parse_data_get_annotation (ParseData *data, gboolean create_new)
1150 g_ptr_array_add (data->annotations, g_new0 (GDBusAnnotationInfo, 1));
1151 return data->annotations->pdata[data->annotations->len - 1];
1154 static GDBusArgInfo *
1155 parse_data_get_arg (ParseData *data, gboolean create_new)
1158 g_ptr_array_add (data->args, g_new0 (GDBusArgInfo, 1));
1159 return data->args->pdata[data->args->len - 1];
1162 static GDBusArgInfo *
1163 parse_data_get_out_arg (ParseData *data, gboolean create_new)
1166 g_ptr_array_add (data->out_args, g_new0 (GDBusArgInfo, 1));
1167 return data->out_args->pdata[data->out_args->len - 1];
1170 static GDBusMethodInfo *
1171 parse_data_get_method (ParseData *data, gboolean create_new)
1174 g_ptr_array_add (data->methods, g_new0 (GDBusMethodInfo, 1));
1175 return data->methods->pdata[data->methods->len - 1];
1178 static GDBusSignalInfo *
1179 parse_data_get_signal (ParseData *data, gboolean create_new)
1182 g_ptr_array_add (data->signals, g_new0 (GDBusSignalInfo, 1));
1183 return data->signals->pdata[data->signals->len - 1];
1186 static GDBusPropertyInfo *
1187 parse_data_get_property (ParseData *data, gboolean create_new)
1190 g_ptr_array_add (data->properties, g_new0 (GDBusPropertyInfo, 1));
1191 return data->properties->pdata[data->properties->len - 1];
1194 static GDBusInterfaceInfo *
1195 parse_data_get_interface (ParseData *data, gboolean create_new)
1198 g_ptr_array_add (data->interfaces, g_new0 (GDBusInterfaceInfo, 1));
1199 return data->interfaces->pdata[data->interfaces->len - 1];
1202 static GDBusNodeInfo *
1203 parse_data_get_node (ParseData *data, gboolean create_new)
1206 g_ptr_array_add (data->nodes, g_new0 (GDBusNodeInfo, 1));
1207 return data->nodes->pdata[data->nodes->len - 1];
1210 /* ---------------------------------------------------------------------------------------------------- */
1213 parse_data_new (void)
1217 data = g_new0 (ParseData, 1);
1219 /* initialize arrays */
1220 parse_data_steal_annotations (data, NULL);
1221 parse_data_steal_args (data, NULL);
1222 parse_data_steal_out_args (data, NULL);
1223 parse_data_steal_methods (data, NULL);
1224 parse_data_steal_signals (data, NULL);
1225 parse_data_steal_properties (data, NULL);
1226 parse_data_steal_interfaces (data, NULL);
1227 parse_data_steal_nodes (data, NULL);
1233 parse_data_free (ParseData *data)
1237 /* free stack of annotation arrays */
1238 for (l = data->annotations_stack; l != NULL; l = l->next)
1240 GPtrArray *annotations = l->data;
1241 g_ptr_array_foreach (annotations, (GFunc) g_dbus_annotation_info_unref, NULL);
1242 g_ptr_array_free (annotations, TRUE);
1244 g_slist_free (data->annotations_stack);
1246 /* free stack of interface arrays */
1247 for (l = data->interfaces_stack; l != NULL; l = l->next)
1249 GPtrArray *interfaces = l->data;
1250 g_ptr_array_foreach (interfaces, (GFunc) g_dbus_interface_info_unref, NULL);
1251 g_ptr_array_free (interfaces, TRUE);
1253 g_slist_free (data->interfaces_stack);
1255 /* free stack of node arrays */
1256 for (l = data->nodes_stack; l != NULL; l = l->next)
1258 GPtrArray *nodes = l->data;
1259 g_ptr_array_foreach (nodes, (GFunc) g_dbus_node_info_unref, NULL);
1260 g_ptr_array_free (nodes, TRUE);
1262 g_slist_free (data->nodes_stack);
1264 /* free arrays (data->annotations, data->interfaces and data->nodes have been freed above) */
1265 parse_data_free_args (data);
1266 parse_data_free_out_args (data);
1267 parse_data_free_methods (data);
1268 parse_data_free_signals (data);
1269 parse_data_free_properties (data);
1274 /* ---------------------------------------------------------------------------------------------------- */
1277 parser_start_element (GMarkupParseContext *context,
1278 const gchar *element_name,
1279 const gchar **attribute_names,
1280 const gchar **attribute_values,
1284 ParseData *data = user_data;
1288 const gchar *access;
1289 const gchar *direction;
1298 stack = (GSList *) g_markup_parse_context_get_element_stack (context);
1300 /* ---------------------------------------------------------------------------------------------------- */
1301 if (strcmp (element_name, "node") == 0)
1303 if (!(g_slist_length (stack) >= 1 || strcmp (stack->next->data, "node") != 0))
1305 g_set_error_literal (error,
1307 G_MARKUP_ERROR_INVALID_CONTENT,
1308 "<node> elements can only be top-level or embedded in other <node> elements");
1312 if (!g_markup_collect_attributes (element_name,
1316 G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "name", &name,
1317 /* some hand-written introspection XML documents use this */
1318 G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "xmlns:doc", NULL,
1319 G_MARKUP_COLLECT_INVALID))
1322 g_dbus_node_info_set (data,
1323 parse_data_get_node (data, TRUE),
1329 /* push the currently retrieved interfaces and nodes on the stack and prepare new arrays */
1330 data->interfaces_stack = g_slist_prepend (data->interfaces_stack, data->interfaces);
1331 data->interfaces = NULL;
1332 parse_data_steal_interfaces (data, NULL);
1334 data->nodes_stack = g_slist_prepend (data->nodes_stack, data->nodes);
1336 parse_data_steal_nodes (data, NULL);
1339 /* ---------------------------------------------------------------------------------------------------- */
1340 else if (strcmp (element_name, "interface") == 0)
1342 if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "node") != 0)
1344 g_set_error_literal (error,
1346 G_MARKUP_ERROR_INVALID_CONTENT,
1347 "<interface> elements can only be embedded in <node> elements");
1351 if (!g_markup_collect_attributes (element_name,
1355 G_MARKUP_COLLECT_STRING, "name", &name,
1356 G_MARKUP_COLLECT_INVALID))
1359 g_dbus_interface_info_set (data,
1360 parse_data_get_interface (data, TRUE),
1368 /* ---------------------------------------------------------------------------------------------------- */
1369 else if (strcmp (element_name, "method") == 0)
1371 if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "interface") != 0)
1373 g_set_error_literal (error,
1375 G_MARKUP_ERROR_INVALID_CONTENT,
1376 "<method> elements can only be embedded in <interface> elements");
1380 if (!g_markup_collect_attributes (element_name,
1384 G_MARKUP_COLLECT_STRING, "name", &name,
1385 G_MARKUP_COLLECT_INVALID))
1388 g_dbus_method_info_set (data,
1389 parse_data_get_method (data, TRUE),
1398 /* ---------------------------------------------------------------------------------------------------- */
1399 else if (strcmp (element_name, "signal") == 0)
1401 if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "interface") != 0)
1403 g_set_error_literal (error,
1405 G_MARKUP_ERROR_INVALID_CONTENT,
1406 "<signal> elements can only be embedded in <interface> elements");
1410 if (!g_markup_collect_attributes (element_name,
1414 G_MARKUP_COLLECT_STRING, "name", &name,
1415 G_MARKUP_COLLECT_INVALID))
1418 g_dbus_signal_info_set (data,
1419 parse_data_get_signal (data, TRUE),
1427 /* ---------------------------------------------------------------------------------------------------- */
1428 else if (strcmp (element_name, "property") == 0)
1430 GDBusPropertyInfoFlags flags;
1432 if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "interface") != 0)
1434 g_set_error_literal (error,
1436 G_MARKUP_ERROR_INVALID_CONTENT,
1437 "<property> elements can only be embedded in <interface> elements");
1441 if (!g_markup_collect_attributes (element_name,
1445 G_MARKUP_COLLECT_STRING, "name", &name,
1446 G_MARKUP_COLLECT_STRING, "type", &type,
1447 G_MARKUP_COLLECT_STRING, "access", &access,
1448 G_MARKUP_COLLECT_INVALID))
1451 if (strcmp (access, "read") == 0)
1452 flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE;
1453 else if (strcmp (access, "write") == 0)
1454 flags = G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE;
1455 else if (strcmp (access, "readwrite") == 0)
1456 flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE;
1461 G_MARKUP_ERROR_INVALID_CONTENT,
1462 "Unknown value '%s' of access attribute for element <property>",
1467 g_dbus_property_info_set (data,
1468 parse_data_get_property (data, TRUE),
1475 /* ---------------------------------------------------------------------------------------------------- */
1476 else if (strcmp (element_name, "arg") == 0)
1481 if (g_slist_length (stack) < 2 ||
1482 (strcmp (stack->next->data, "method") != 0 &&
1483 strcmp (stack->next->data, "signal") != 0))
1485 g_set_error_literal (error,
1487 G_MARKUP_ERROR_INVALID_CONTENT,
1488 "<arg> elements can only be embedded in <method> or <signal> elements");
1492 if (!g_markup_collect_attributes (element_name,
1496 G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "name", &name,
1497 G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "direction", &direction,
1498 G_MARKUP_COLLECT_STRING, "type", &type,
1499 G_MARKUP_COLLECT_INVALID))
1503 if (direction != NULL)
1505 if (strcmp (direction, "in") == 0)
1507 else if (strcmp (direction, "out") == 0)
1513 G_MARKUP_ERROR_INVALID_CONTENT,
1514 "Unknown value '%s' of direction attribute",
1520 if (is_in && strcmp (stack->next->data, "signal") == 0)
1522 g_set_error_literal (error,
1524 G_MARKUP_ERROR_INVALID_CONTENT,
1525 "Only direction 'out' is allowed for <arg> elements embedded in <signal>");
1530 name_to_use = g_strdup_printf ("arg_%d", data->num_args);
1532 name_to_use = g_strdup (name);
1537 g_dbus_arg_info_set (data,
1538 parse_data_get_arg (data, TRUE),
1542 data->last_arg_was_in = TRUE;
1546 g_dbus_arg_info_set (data,
1547 parse_data_get_out_arg (data, TRUE),
1551 data->last_arg_was_in = FALSE;
1555 g_free (name_to_use);
1557 /* ---------------------------------------------------------------------------------------------------- */
1558 else if (strcmp (element_name, "annotation") == 0)
1560 if (g_slist_length (stack) < 2 ||
1561 (strcmp (stack->next->data, "node") != 0 &&
1562 strcmp (stack->next->data, "interface") != 0 &&
1563 strcmp (stack->next->data, "signal") != 0 &&
1564 strcmp (stack->next->data, "method") != 0 &&
1565 strcmp (stack->next->data, "property") != 0 &&
1566 strcmp (stack->next->data, "arg") != 0 &&
1567 strcmp (stack->next->data, "annotation") != 0))
1569 g_set_error_literal (error,
1571 G_MARKUP_ERROR_INVALID_CONTENT,
1572 "<annotation> elements can only be embedded in <node>, <interface>, <signal>, <method>, <property>, <arg> or <annotation> elements");
1576 if (!g_markup_collect_attributes (element_name,
1580 G_MARKUP_COLLECT_STRING, "name", &name,
1581 G_MARKUP_COLLECT_STRING, "value", &value,
1582 G_MARKUP_COLLECT_INVALID))
1585 g_dbus_annotation_info_set (data,
1586 parse_data_get_annotation (data, TRUE),
1591 /* ---------------------------------------------------------------------------------------------------- */
1594 /* don't bail on unknown elements; just ignore them */
1596 /* ---------------------------------------------------------------------------------------------------- */
1598 /* push the currently retrieved annotations on the stack and prepare a new one */
1599 data->annotations_stack = g_slist_prepend (data->annotations_stack, data->annotations);
1600 data->annotations = NULL;
1601 parse_data_steal_annotations (data, NULL);
1607 /* ---------------------------------------------------------------------------------------------------- */
1609 static GDBusAnnotationInfo **
1610 steal_annotations (ParseData *data)
1612 return parse_data_steal_annotations (data, NULL);
1617 parser_end_element (GMarkupParseContext *context,
1618 const gchar *element_name,
1622 ParseData *data = user_data;
1623 gboolean have_popped_annotations;
1625 have_popped_annotations = FALSE;
1627 if (strcmp (element_name, "node") == 0)
1630 guint num_interfaces;
1631 GDBusNodeInfo **nodes;
1632 GDBusInterfaceInfo **interfaces;
1634 nodes = parse_data_steal_nodes (data, &num_nodes);
1635 interfaces = parse_data_steal_interfaces (data, &num_interfaces);
1637 /* destroy the nodes, interfaces for scope we're exiting and and pop the nodes, interfaces from the
1638 * scope we're reentering
1640 parse_data_free_interfaces (data);
1641 data->interfaces = (GPtrArray *) data->interfaces_stack->data;
1642 data->interfaces_stack = g_slist_remove (data->interfaces_stack, data->interfaces_stack->data);
1644 parse_data_free_nodes (data);
1645 data->nodes = (GPtrArray *) data->nodes_stack->data;
1646 data->nodes_stack = g_slist_remove (data->nodes_stack, data->nodes_stack->data);
1648 g_dbus_node_info_set (data,
1649 parse_data_get_node (data, FALSE),
1655 steal_annotations (data));
1658 else if (strcmp (element_name, "interface") == 0)
1662 guint num_properties;
1663 GDBusMethodInfo **methods;
1664 GDBusSignalInfo **signals;
1665 GDBusPropertyInfo **properties;
1667 methods = parse_data_steal_methods (data, &num_methods);
1668 signals = parse_data_steal_signals (data, &num_signals);
1669 properties = parse_data_steal_properties (data, &num_properties);
1671 g_dbus_interface_info_set (data,
1672 parse_data_get_interface (data, FALSE),
1680 steal_annotations (data));
1683 else if (strcmp (element_name, "method") == 0)
1687 GDBusArgInfo **in_args;
1688 GDBusArgInfo **out_args;
1690 in_args = parse_data_steal_args (data, &in_num_args);
1691 out_args = parse_data_steal_out_args (data, &out_num_args);
1693 g_dbus_method_info_set (data,
1694 parse_data_get_method (data, FALSE),
1700 steal_annotations (data));
1702 else if (strcmp (element_name, "signal") == 0)
1705 GDBusArgInfo **args;
1707 args = parse_data_steal_out_args (data, &num_args);
1709 g_dbus_signal_info_set (data,
1710 parse_data_get_signal (data, FALSE),
1714 steal_annotations (data));
1716 else if (strcmp (element_name, "property") == 0)
1718 g_dbus_property_info_set (data,
1719 parse_data_get_property (data, FALSE),
1722 G_DBUS_PROPERTY_INFO_FLAGS_NONE,
1723 steal_annotations (data));
1725 else if (strcmp (element_name, "arg") == 0)
1727 g_dbus_arg_info_set (data,
1728 data->last_arg_was_in ? parse_data_get_arg (data, FALSE) : parse_data_get_out_arg (data, FALSE),
1731 steal_annotations (data));
1733 else if (strcmp (element_name, "annotation") == 0)
1735 GDBusAnnotationInfo **embedded_annotations;
1737 embedded_annotations = steal_annotations (data);
1739 /* destroy the annotations for scope we're exiting and and pop the annotations from the scope we're reentering */
1740 parse_data_free_annotations (data);
1741 data->annotations = (GPtrArray *) data->annotations_stack->data;
1742 data->annotations_stack = g_slist_remove (data->annotations_stack, data->annotations_stack->data);
1744 have_popped_annotations = TRUE;
1746 g_dbus_annotation_info_set (data,
1747 parse_data_get_annotation (data, FALSE),
1750 embedded_annotations);
1754 /* don't bail on unknown elements; just ignore them */
1757 if (!have_popped_annotations)
1759 /* destroy the annotations for scope we're exiting and and pop the annotations from the scope we're reentering */
1760 parse_data_free_annotations (data);
1761 data->annotations = (GPtrArray *) data->annotations_stack->data;
1762 data->annotations_stack = g_slist_remove (data->annotations_stack, data->annotations_stack->data);
1766 /* ---------------------------------------------------------------------------------------------------- */
1769 parser_error (GMarkupParseContext *context,
1776 g_markup_parse_context_get_position (context, &line_number, &char_number);
1778 g_prefix_error (&error, "%d:%d: ",
1783 /* ---------------------------------------------------------------------------------------------------- */
1786 * g_dbus_node_info_new_for_xml:
1787 * @xml_data: Valid D-Bus introspection XML.
1788 * @error: Return location for error.
1790 * Parses @xml_data and returns a #GDBusNodeInfo representing the data.
1792 * Returns: A #GDBusNodeInfo structure or %NULL if @error is set. Free
1793 * with g_dbus_node_info_unref().
1798 g_dbus_node_info_new_for_xml (const gchar *xml_data,
1802 GMarkupParseContext *context;
1803 GMarkupParser *parser;
1811 parser = g_new0 (GMarkupParser, 1);
1812 parser->start_element = parser_start_element;
1813 parser->end_element = parser_end_element;
1814 parser->error = parser_error;
1816 data = parse_data_new ();
1817 context = g_markup_parse_context_new (parser,
1820 (GDestroyNotify) parse_data_free);
1822 if (!g_markup_parse_context_parse (context,
1828 GDBusNodeInfo **ughret;
1829 ughret = parse_data_steal_nodes (data, &num_nodes);
1837 G_MARKUP_ERROR_INVALID_CONTENT,
1838 "Expected a single node in introspection XML, found %d",
1842 for (n = 0; n < num_nodes; n++)
1844 for (n = 0; n < num_nodes; n++)
1845 g_dbus_node_info_unref (&(ret[n]));
1857 if (context != NULL)
1858 g_markup_parse_context_free (context);
1863 /* ---------------------------------------------------------------------------------------------------- */
1866 * g_dbus_annotation_info_lookup:
1867 * @annotations: A %NULL-terminated array of annotations or %NULL.
1868 * @name: The name of the annotation to look up.
1870 * Looks up the value of an annotation.
1872 * This cost of this function is O(n) in number of annotations.
1874 * Returns: The value or %NULL if not found. Do not free, it is owned by @annotations.
1879 g_dbus_annotation_info_lookup (const GDBusAnnotationInfo **annotations,
1886 for (n = 0; annotations != NULL && annotations[n]->key != NULL; n++)
1888 if (g_strcmp0 (annotations[n]->key, name) == 0)
1890 ret = annotations[n]->value;
1899 /* ---------------------------------------------------------------------------------------------------- */
1902 * g_dbus_interface_info_lookup_method:
1903 * @info: A #GDBusInterfaceInfo.
1904 * @name: A D-Bus method name (typically in CamelCase)
1906 * Looks up information about a method.
1908 * This cost of this function is O(n) in number of methods.
1910 * Returns: A #GDBusMethodInfo or %NULL if not found. Do not free, it is owned by @info.
1914 const GDBusMethodInfo *
1915 g_dbus_interface_info_lookup_method (const GDBusInterfaceInfo *info,
1919 const GDBusMethodInfo *result;
1921 for (n = 0; info->methods != NULL && info->methods[n] != NULL; n++)
1923 const GDBusMethodInfo *i = info->methods[n];
1925 if (g_strcmp0 (i->name, name) == 0)
1938 /* ---------------------------------------------------------------------------------------------------- */
1941 * g_dbus_interface_info_lookup_signal:
1942 * @info: A #GDBusInterfaceInfo.
1943 * @name: A D-Bus signal name (typically in CamelCase)
1945 * Looks up information about a signal.
1947 * This cost of this function is O(n) in number of signals.
1949 * Returns: A #GDBusSignalInfo or %NULL if not found. Do not free, it is owned by @info.
1953 const GDBusSignalInfo *
1954 g_dbus_interface_info_lookup_signal (const GDBusInterfaceInfo *info,
1958 const GDBusSignalInfo *result;
1960 for (n = 0; info->signals != NULL && info->signals[n] != NULL; n++)
1962 const GDBusSignalInfo *i = info->signals[n];
1964 if (g_strcmp0 (i->name, name) == 0)
1977 /* ---------------------------------------------------------------------------------------------------- */
1980 * g_dbus_interface_info_lookup_property:
1981 * @info: A #GDBusInterfaceInfo.
1982 * @name: A D-Bus property name (typically in CamelCase).
1984 * Looks up information about a property.
1986 * This cost of this function is O(n) in number of properties.
1988 * Returns: A #GDBusPropertyInfo or %NULL if not found. Do not free, it is owned by @info.
1992 const GDBusPropertyInfo *
1993 g_dbus_interface_info_lookup_property (const GDBusInterfaceInfo *info,
1997 const GDBusPropertyInfo *result;
1999 for (n = 0; info->properties != NULL && info->properties[n] != NULL; n++)
2001 const GDBusPropertyInfo *i = info->properties[n];
2003 if (g_strcmp0 (i->name, name) == 0)
2016 /* ---------------------------------------------------------------------------------------------------- */
2019 * g_dbus_node_info_lookup_interface:
2020 * @node_info: A #GDBusNodeInfo.
2021 * @name: A D-Bus interface name.
2023 * Looks up information about an interface.
2025 * This cost of this function is O(n) in number of interfaces.
2027 * Returns: A #GDBusInterfaceInfo or %NULL if not found. Do not free, it is owned by @node_info.
2031 const GDBusInterfaceInfo *
2032 g_dbus_node_info_lookup_interface (const GDBusNodeInfo *node_info,
2036 const GDBusInterfaceInfo *result;
2038 for (n = 0; node_info->interfaces != NULL && node_info->interfaces[n] != NULL; n++)
2040 const GDBusInterfaceInfo *i = node_info->interfaces[n];
2042 if (g_strcmp0 (i->name, name) == 0)