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
35 * @include: gdbus/gdbus.h
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.
111 g_dbus_node_info_ref (GDBusNodeInfo *info)
113 if (info->ref_count == -1)
115 g_atomic_int_inc (&info->ref_count);
120 * g_dbus_interface_info_ref:
121 * @info: A #GDBusInterfaceInfo
123 * If @info is statically allocated does nothing. Otherwise increases
124 * the reference count.
126 * Returns: The same @info.
129 g_dbus_interface_info_ref (GDBusInterfaceInfo *info)
131 if (info->ref_count == -1)
133 g_atomic_int_inc (&info->ref_count);
138 * g_dbus_method_info_ref:
139 * @info: A #GDBusMethodInfo
141 * If @info is statically allocated does nothing. Otherwise increases
142 * the reference count.
144 * Returns: The same @info.
147 g_dbus_method_info_ref (GDBusMethodInfo *info)
149 if (info->ref_count == -1)
151 g_atomic_int_inc (&info->ref_count);
156 * g_dbus_signal_info_ref:
157 * @info: A #GDBusSignalInfo
159 * If @info is statically allocated does nothing. Otherwise increases
160 * the reference count.
162 * Returns: The same @info.
165 g_dbus_signal_info_ref (GDBusSignalInfo *info)
167 if (info->ref_count == -1)
169 g_atomic_int_inc (&info->ref_count);
174 * g_dbus_property_info_ref:
175 * @info: A #GDBusPropertyInfo
177 * If @info is statically allocated does nothing. Otherwise increases
178 * the reference count.
180 * Returns: The same @info.
183 g_dbus_property_info_ref (GDBusPropertyInfo *info)
185 if (info->ref_count == -1)
187 g_atomic_int_inc (&info->ref_count);
192 * g_dbus_arg_info_ref:
193 * @info: A #GDBusArgInfo
195 * If @info is statically allocated does nothing. Otherwise increases
196 * the reference count.
198 * Returns: The same @info.
201 g_dbus_arg_info_ref (GDBusArgInfo *info)
203 if (info->ref_count == -1)
205 g_atomic_int_inc (&info->ref_count);
210 * g_dbus_node_info_ref:
211 * @info: A #GDBusNodeInfo
213 * If @info is statically allocated does nothing. Otherwise increases
214 * the reference count.
216 * Returns: The same @info.
218 GDBusAnnotationInfo *
219 g_dbus_annotation_info_ref (GDBusAnnotationInfo *info)
221 if (info->ref_count == -1)
223 g_atomic_int_inc (&info->ref_count);
227 /* ---------------------------------------------------------------------------------------------------- */
230 free_null_terminated_array (gpointer array, GDestroyNotify unref_func)
236 for (n = 0; p[n] != NULL; n++)
242 * g_dbus_annotation_info_unref:
243 * @info: A #GDBusAnnotationInfo.
245 * If @info is statically allocated, does nothing. Otherwise decreases
246 * the reference count of @info. When its reference count drops to 0,
247 * the memory used is freed.
250 g_dbus_annotation_info_unref (GDBusAnnotationInfo *info)
252 if (info->ref_count == -1)
254 if (g_atomic_int_dec_and_test (&info->ref_count))
257 g_free (info->value);
258 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
264 * g_dbus_arg_info_unref:
265 * @info: A #GDBusArgInfo.
267 * If @info is statically allocated, does nothing. Otherwise decreases
268 * the reference count of @info. When its reference count drops to 0,
269 * the memory used is freed.
272 g_dbus_arg_info_unref (GDBusArgInfo *info)
274 if (info->ref_count == -1)
276 if (g_atomic_int_dec_and_test (&info->ref_count))
279 g_free (info->signature);
280 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
286 * g_dbus_method_info_unref:
287 * @info: A #GDBusMethodInfo.
289 * If @info is statically allocated, does nothing. Otherwise decreases
290 * the reference count of @info. When its reference count drops to 0,
291 * the memory used is freed.
294 g_dbus_method_info_unref (GDBusMethodInfo *info)
296 if (info->ref_count == -1)
298 if (g_atomic_int_dec_and_test (&info->ref_count))
301 free_null_terminated_array (info->in_args, (GDestroyNotify) g_dbus_arg_info_unref);
302 free_null_terminated_array (info->out_args, (GDestroyNotify) g_dbus_arg_info_unref);
303 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
309 * g_dbus_signal_info_unref:
310 * @info: A #GDBusSignalInfo.
312 * If @info is statically allocated, does nothing. Otherwise decreases
313 * the reference count of @info. When its reference count drops to 0,
314 * the memory used is freed.
317 g_dbus_signal_info_unref (GDBusSignalInfo *info)
319 if (info->ref_count == -1)
321 if (g_atomic_int_dec_and_test (&info->ref_count))
324 free_null_terminated_array (info->args, (GDestroyNotify) g_dbus_arg_info_unref);
325 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
331 * g_dbus_property_info_unref:
332 * @info: A #GDBusPropertyInfo.
334 * If @info is statically allocated, does nothing. Otherwise decreases
335 * the reference count of @info. When its reference count drops to 0,
336 * the memory used is freed.
339 g_dbus_property_info_unref (GDBusPropertyInfo *info)
341 if (info->ref_count == -1)
343 if (g_atomic_int_dec_and_test (&info->ref_count))
346 g_free (info->signature);
347 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
353 * g_dbus_interface_info_unref:
354 * @info: A #GDBusInterfaceInfo.
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.
361 g_dbus_interface_info_unref (GDBusInterfaceInfo *info)
363 if (info->ref_count == -1)
365 if (g_atomic_int_dec_and_test (&info->ref_count))
368 free_null_terminated_array (info->methods, (GDestroyNotify) g_dbus_method_info_unref);
369 free_null_terminated_array (info->signals, (GDestroyNotify) g_dbus_signal_info_unref);
370 free_null_terminated_array (info->properties, (GDestroyNotify) g_dbus_property_info_unref);
371 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
377 * g_dbus_node_info_unref:
378 * @info: A #GDBusNodeInfo.
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.
385 g_dbus_node_info_unref (GDBusNodeInfo *info)
387 if (info->ref_count == -1)
389 if (g_atomic_int_dec_and_test (&info->ref_count))
392 free_null_terminated_array (info->interfaces, (GDestroyNotify) g_dbus_interface_info_unref);
393 free_null_terminated_array (info->nodes, (GDestroyNotify) g_dbus_node_info_unref);
394 free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
399 /* ---------------------------------------------------------------------------------------------------- */
402 g_dbus_annotation_info_set (ParseData *data,
403 GDBusAnnotationInfo *info,
406 GDBusAnnotationInfo **embedded_annotations)
411 info->key = g_strdup (key);
414 info->value = g_strdup (value);
416 if (embedded_annotations != NULL)
417 info->annotations = embedded_annotations;
421 g_dbus_arg_info_set (ParseData *data,
424 const gchar *signature,
425 GDBusAnnotationInfo **annotations)
429 /* name may be NULL - TODO: compute name? */
431 info->name = g_strdup (name);
433 if (signature != NULL)
434 info->signature = g_strdup (signature);
436 if (annotations != NULL)
437 info->annotations = annotations;
441 g_dbus_method_info_set (ParseData *data,
442 GDBusMethodInfo *info,
445 GDBusArgInfo **in_args,
447 GDBusArgInfo **out_args,
448 GDBusAnnotationInfo **annotations)
453 info->name = g_strdup (name);
455 if (in_num_args != 0)
457 //info->in_num_args = in_num_args;
458 info->in_args = in_args;
461 if (out_num_args != 0)
463 //info->out_num_args = out_num_args;
464 info->out_args = out_args;
467 if (annotations != NULL)
468 info->annotations = annotations;
472 g_dbus_signal_info_set (ParseData *data,
473 GDBusSignalInfo *info,
477 GDBusAnnotationInfo **annotations)
482 info->name = g_strdup (name);
486 //info->num_args = num_args;
490 if (annotations != NULL)
492 info->annotations = annotations;
497 g_dbus_property_info_set (ParseData *data,
498 GDBusPropertyInfo *info,
500 const gchar *signature,
501 GDBusPropertyInfoFlags flags,
502 GDBusAnnotationInfo **annotations)
507 info->name = g_strdup (name);
509 if (flags != G_DBUS_PROPERTY_INFO_FLAGS_NONE)
512 if (signature != NULL)
514 info->signature = g_strdup (signature);
517 if (annotations != NULL)
519 info->annotations = annotations;
524 g_dbus_interface_info_set (ParseData *data,
525 GDBusInterfaceInfo *info,
528 GDBusMethodInfo **methods,
530 GDBusSignalInfo **signals,
531 guint num_properties,
532 GDBusPropertyInfo **properties,
533 GDBusAnnotationInfo **annotations)
539 info->name = g_strdup (name);
542 if (num_methods != 0)
544 //info->num_methods = num_methods;
545 info->methods = methods;
548 if (num_signals != 0)
550 //info->num_signals = num_signals;
551 info->signals = signals;
554 if (num_properties != 0)
556 //info->num_properties = num_properties;
557 info->properties = properties;
560 if (annotations != NULL)
562 info->annotations = annotations;
567 g_dbus_node_info_set (ParseData *data,
570 guint num_interfaces,
571 GDBusInterfaceInfo **interfaces,
573 GDBusNodeInfo **nodes,
574 GDBusAnnotationInfo **annotations)
580 info->path = g_strdup (path);
581 /* TODO: relative / absolute path snafu */
584 if (num_interfaces != 0)
586 //info->num_interfaces = num_interfaces;
587 info->interfaces = interfaces;
592 //info->num_nodes = num_nodes;
596 if (annotations != NULL)
598 info->annotations = annotations;
603 /* ---------------------------------------------------------------------------------------------------- */
606 g_dbus_annotation_info_generate_xml (const GDBusAnnotationInfo *info,
608 GString *string_builder)
612 g_string_append_printf (string_builder, "%*s<annotation name=\"%s\" value=\"%s\"",
617 if (info->annotations == NULL)
619 g_string_append (string_builder, "/>\n");
623 g_string_append (string_builder, ">\n");
625 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
626 g_dbus_annotation_info_generate_xml (info->annotations[n],
630 g_string_append_printf (string_builder, "%*s</annotation>\n",
637 g_dbus_arg_info_generate_xml (const GDBusArgInfo *info,
639 const gchar *extra_attributes,
640 GString *string_builder)
644 g_string_append_printf (string_builder, "%*s<arg type=\"%s\"",
648 if (info->name != NULL)
649 g_string_append_printf (string_builder, " name=\"%s\"", info->name);
651 if (extra_attributes != NULL)
652 g_string_append_printf (string_builder, " %s", extra_attributes);
654 if (info->annotations == NULL)
656 g_string_append (string_builder, "/>\n");
660 g_string_append (string_builder, ">\n");
662 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
663 g_dbus_annotation_info_generate_xml (info->annotations[n],
667 g_string_append_printf (string_builder, "%*s</arg>\n", indent, "");
673 g_dbus_method_info_generate_xml (const GDBusMethodInfo *info,
675 GString *string_builder)
679 g_string_append_printf (string_builder, "%*s<method name=\"%s\"",
683 if (info->annotations == NULL && info->in_args == NULL && info->out_args == NULL)
685 g_string_append (string_builder, "/>\n");
689 g_string_append (string_builder, ">\n");
691 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
692 g_dbus_annotation_info_generate_xml (info->annotations[n],
696 for (n = 0; info->in_args != NULL && info->in_args[n] != NULL; n++)
697 g_dbus_arg_info_generate_xml (info->in_args[n],
702 for (n = 0; info->out_args != NULL && info->out_args[n] != NULL; n++)
703 g_dbus_arg_info_generate_xml (info->out_args[n],
708 g_string_append_printf (string_builder, "%*s</method>\n", indent, "");
713 g_dbus_signal_info_generate_xml (const GDBusSignalInfo *info,
715 GString *string_builder)
719 g_string_append_printf (string_builder, "%*s<signal name=\"%s\"",
723 if (info->annotations == NULL && info->args == NULL)
725 g_string_append (string_builder, "/>\n");
729 g_string_append (string_builder, ">\n");
731 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
732 g_dbus_annotation_info_generate_xml (info->annotations[n],
736 for (n = 0; info->args != NULL && info->args[n] != NULL; n++)
737 g_dbus_arg_info_generate_xml (info->args[n],
742 g_string_append_printf (string_builder, "%*s</signal>\n", indent, "");
747 g_dbus_property_info_generate_xml (const GDBusPropertyInfo *info,
749 GString *string_builder)
752 const gchar *access_string;
754 if ((info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE) &&
755 (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE))
757 access_string = "readwrite";
759 else if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)
761 access_string = "read";
763 else if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE)
765 access_string = "write";
769 g_assert_not_reached ();
772 g_string_append_printf (string_builder, "%*s<property type=\"%s\" name=\"%s\" access=\"%s\"",
778 if (info->annotations == NULL)
780 g_string_append (string_builder, "/>\n");
784 g_string_append (string_builder, ">\n");
786 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
787 g_dbus_annotation_info_generate_xml (info->annotations[n],
791 g_string_append_printf (string_builder, "%*s</property>\n", indent, "");
797 * g_dbus_interface_info_generate_xml:
798 * @info: A #GDBusNodeInfo
799 * @indent: Indentation level.
800 * @string_builder: A #GString to to append XML data to.
802 * Appends an XML representation of @info (and its children) to @string_builder.
804 * This function is typically used for generating introspection XML
805 * documents at run-time for handling the
806 * <literal>org.freedesktop.DBus.Introspectable.Introspect</literal>
810 g_dbus_interface_info_generate_xml (const GDBusInterfaceInfo *info,
812 GString *string_builder)
816 g_string_append_printf (string_builder, "%*s<interface name=\"%s\">\n",
820 for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
821 g_dbus_annotation_info_generate_xml (info->annotations[n],
825 for (n = 0; info->methods != NULL && info->methods[n] != NULL; n++)
826 g_dbus_method_info_generate_xml (info->methods[n],
830 for (n = 0; info->signals != NULL && info->signals[n] != NULL; n++)
831 g_dbus_signal_info_generate_xml (info->signals[n],
835 for (n = 0; info->properties != NULL && info->properties[n] != NULL; n++)
836 g_dbus_property_info_generate_xml (info->properties[n],
840 g_string_append_printf (string_builder, "%*s</interface>\n", indent, "");
844 * g_dbus_node_info_generate_xml:
845 * @node_info: A #GDBusNodeInfo.
846 * @indent: Indentation level.
847 * @string_builder: A #GString to to append XML data to.
849 * Appends an XML representation of @node_info (and its children) to @string_builder.
851 * This function is typically used for generating introspection XML documents at run-time for
852 * handling the <literal>org.freedesktop.DBus.Introspectable.Introspect</literal> method.
855 g_dbus_node_info_generate_xml (const GDBusNodeInfo *node_info,
857 GString *string_builder)
861 g_string_append_printf (string_builder, "%*s<node", indent, "");
862 if (node_info->path != NULL)
863 g_string_append_printf (string_builder, " name=\"%s\"", node_info->path);
865 if (node_info->interfaces == NULL && node_info->nodes == NULL && node_info->annotations == NULL)
867 g_string_append (string_builder, "/>\n");
871 g_string_append (string_builder, ">\n");
873 for (n = 0; node_info->annotations != NULL && node_info->annotations[n] != NULL; n++)
874 g_dbus_annotation_info_generate_xml (node_info->annotations[n],
878 for (n = 0; node_info->interfaces != NULL && node_info->interfaces[n] != NULL; n++)
879 g_dbus_interface_info_generate_xml (node_info->interfaces[n],
883 for (n = 0; node_info->nodes != NULL && node_info->nodes[n] != NULL; n++)
884 g_dbus_node_info_generate_xml (node_info->nodes[n],
888 g_string_append_printf (string_builder, "%*s</node>\n", indent, "");
892 /* ---------------------------------------------------------------------------------------------------- */
894 static GDBusAnnotationInfo **
895 parse_data_steal_annotations (ParseData *data, guint *out_num_elements)
897 GDBusAnnotationInfo **ret;
898 if (out_num_elements != NULL)
899 *out_num_elements = data->annotations->len;
900 if (data->annotations == NULL)
904 g_ptr_array_add (data->annotations, NULL);
905 ret = (GDBusAnnotationInfo **) g_ptr_array_free (data->annotations, FALSE);
907 data->annotations = g_ptr_array_new ();
911 static GDBusArgInfo **
912 parse_data_steal_args (ParseData *data, guint *out_num_elements)
915 if (out_num_elements != NULL)
916 *out_num_elements = data->args->len;
917 if (data->args == NULL)
921 g_ptr_array_add (data->args, NULL);
922 ret = (GDBusArgInfo **) g_ptr_array_free (data->args, FALSE);
924 data->args = g_ptr_array_new ();
928 static GDBusArgInfo **
929 parse_data_steal_out_args (ParseData *data, guint *out_num_elements)
932 if (out_num_elements != NULL)
933 *out_num_elements = data->out_args->len;
934 if (data->out_args == NULL)
938 g_ptr_array_add (data->out_args, NULL);
939 ret = (GDBusArgInfo **) g_ptr_array_free (data->out_args, FALSE);
941 data->out_args = g_ptr_array_new ();
945 static GDBusMethodInfo **
946 parse_data_steal_methods (ParseData *data, guint *out_num_elements)
948 GDBusMethodInfo **ret;
949 if (out_num_elements != NULL)
950 *out_num_elements = data->methods->len;
951 if (data->methods == NULL)
955 g_ptr_array_add (data->methods, NULL);
956 ret = (GDBusMethodInfo **) g_ptr_array_free (data->methods, FALSE);
958 data->methods = g_ptr_array_new ();
962 static GDBusSignalInfo **
963 parse_data_steal_signals (ParseData *data, guint *out_num_elements)
965 GDBusSignalInfo **ret;
966 if (out_num_elements != NULL)
967 *out_num_elements = data->signals->len;
968 if (data->signals == NULL)
972 g_ptr_array_add (data->signals, NULL);
973 ret = (GDBusSignalInfo **) g_ptr_array_free (data->signals, FALSE);
975 data->signals = g_ptr_array_new ();
979 static GDBusPropertyInfo **
980 parse_data_steal_properties (ParseData *data, guint *out_num_elements)
982 GDBusPropertyInfo **ret;
983 if (out_num_elements != NULL)
984 *out_num_elements = data->properties->len;
985 if (data->properties == NULL)
989 g_ptr_array_add (data->properties, NULL);
990 ret = (GDBusPropertyInfo **) g_ptr_array_free (data->properties, FALSE);
992 data->properties = g_ptr_array_new ();
996 static GDBusInterfaceInfo **
997 parse_data_steal_interfaces (ParseData *data, guint *out_num_elements)
999 GDBusInterfaceInfo **ret;
1000 if (out_num_elements != NULL)
1001 *out_num_elements = data->interfaces->len;
1002 if (data->interfaces == NULL)
1006 g_ptr_array_add (data->interfaces, NULL);
1007 ret = (GDBusInterfaceInfo **) g_ptr_array_free (data->interfaces, FALSE);
1009 data->interfaces = g_ptr_array_new ();
1013 static GDBusNodeInfo **
1014 parse_data_steal_nodes (ParseData *data, guint *out_num_elements)
1016 GDBusNodeInfo **ret;
1017 if (out_num_elements != NULL)
1018 *out_num_elements = data->nodes->len;
1019 if (data->nodes == NULL)
1023 g_ptr_array_add (data->nodes, NULL);
1024 ret = (GDBusNodeInfo **) g_ptr_array_free (data->nodes, FALSE);
1026 data->nodes = g_ptr_array_new ();
1030 /* ---------------------------------------------------------------------------------------------------- */
1033 parse_data_free_annotations (ParseData *data)
1035 if (data->annotations == NULL)
1037 g_ptr_array_foreach (data->annotations, (GFunc) g_dbus_annotation_info_unref, NULL);
1038 g_ptr_array_free (data->annotations, TRUE);
1039 data->annotations = NULL;
1043 parse_data_free_args (ParseData *data)
1045 if (data->args == NULL)
1047 g_ptr_array_foreach (data->args, (GFunc) g_dbus_arg_info_unref, NULL);
1048 g_ptr_array_free (data->args, TRUE);
1053 parse_data_free_out_args (ParseData *data)
1055 if (data->out_args == NULL)
1057 g_ptr_array_foreach (data->out_args, (GFunc) g_dbus_arg_info_unref, NULL);
1058 g_ptr_array_free (data->out_args, TRUE);
1059 data->out_args = NULL;
1063 parse_data_free_methods (ParseData *data)
1065 if (data->methods == NULL)
1067 g_ptr_array_foreach (data->methods, (GFunc) g_dbus_method_info_unref, NULL);
1068 g_ptr_array_free (data->methods, TRUE);
1069 data->methods = NULL;
1073 parse_data_free_signals (ParseData *data)
1075 if (data->signals == NULL)
1077 g_ptr_array_foreach (data->signals, (GFunc) g_dbus_signal_info_unref, NULL);
1078 g_ptr_array_free (data->signals, TRUE);
1079 data->signals = NULL;
1083 parse_data_free_properties (ParseData *data)
1085 if (data->properties == NULL)
1087 g_ptr_array_foreach (data->properties, (GFunc) g_dbus_property_info_unref, NULL);
1088 g_ptr_array_free (data->properties, TRUE);
1089 data->properties = NULL;
1093 parse_data_free_interfaces (ParseData *data)
1095 if (data->interfaces == NULL)
1097 g_ptr_array_foreach (data->interfaces, (GFunc) g_dbus_interface_info_unref, NULL);
1098 g_ptr_array_free (data->interfaces, TRUE);
1099 data->interfaces = NULL;
1103 parse_data_free_nodes (ParseData *data)
1105 if (data->nodes == NULL)
1107 g_ptr_array_foreach (data->nodes, (GFunc) g_dbus_node_info_unref, NULL);
1108 g_ptr_array_free (data->nodes, TRUE);
1112 /* ---------------------------------------------------------------------------------------------------- */
1114 static GDBusAnnotationInfo *
1115 parse_data_get_annotation (ParseData *data, gboolean create_new)
1118 g_ptr_array_add (data->annotations, g_new0 (GDBusAnnotationInfo, 1));
1119 return data->annotations->pdata[data->annotations->len - 1];
1122 static GDBusArgInfo *
1123 parse_data_get_arg (ParseData *data, gboolean create_new)
1126 g_ptr_array_add (data->args, g_new0 (GDBusArgInfo, 1));
1127 return data->args->pdata[data->args->len - 1];
1130 static GDBusArgInfo *
1131 parse_data_get_out_arg (ParseData *data, gboolean create_new)
1134 g_ptr_array_add (data->out_args, g_new0 (GDBusArgInfo, 1));
1135 return data->out_args->pdata[data->out_args->len - 1];
1138 static GDBusMethodInfo *
1139 parse_data_get_method (ParseData *data, gboolean create_new)
1142 g_ptr_array_add (data->methods, g_new0 (GDBusMethodInfo, 1));
1143 return data->methods->pdata[data->methods->len - 1];
1146 static GDBusSignalInfo *
1147 parse_data_get_signal (ParseData *data, gboolean create_new)
1150 g_ptr_array_add (data->signals, g_new0 (GDBusSignalInfo, 1));
1151 return data->signals->pdata[data->signals->len - 1];
1154 static GDBusPropertyInfo *
1155 parse_data_get_property (ParseData *data, gboolean create_new)
1158 g_ptr_array_add (data->properties, g_new0 (GDBusPropertyInfo, 1));
1159 return data->properties->pdata[data->properties->len - 1];
1162 static GDBusInterfaceInfo *
1163 parse_data_get_interface (ParseData *data, gboolean create_new)
1166 g_ptr_array_add (data->interfaces, g_new0 (GDBusInterfaceInfo, 1));
1167 return data->interfaces->pdata[data->interfaces->len - 1];
1170 static GDBusNodeInfo *
1171 parse_data_get_node (ParseData *data, gboolean create_new)
1174 g_ptr_array_add (data->nodes, g_new0 (GDBusNodeInfo, 1));
1175 return data->nodes->pdata[data->nodes->len - 1];
1178 /* ---------------------------------------------------------------------------------------------------- */
1181 parse_data_new (void)
1185 data = g_new0 (ParseData, 1);
1187 /* initialize arrays */
1188 parse_data_steal_annotations (data, NULL);
1189 parse_data_steal_args (data, NULL);
1190 parse_data_steal_out_args (data, NULL);
1191 parse_data_steal_methods (data, NULL);
1192 parse_data_steal_signals (data, NULL);
1193 parse_data_steal_properties (data, NULL);
1194 parse_data_steal_interfaces (data, NULL);
1195 parse_data_steal_nodes (data, NULL);
1201 parse_data_free (ParseData *data)
1205 /* free stack of annotation arrays */
1206 for (l = data->annotations_stack; l != NULL; l = l->next)
1208 GPtrArray *annotations = l->data;
1209 g_ptr_array_foreach (annotations, (GFunc) g_dbus_annotation_info_unref, NULL);
1210 g_ptr_array_free (annotations, TRUE);
1212 g_slist_free (data->annotations_stack);
1214 /* free stack of interface arrays */
1215 for (l = data->interfaces_stack; l != NULL; l = l->next)
1217 GPtrArray *interfaces = l->data;
1218 g_ptr_array_foreach (interfaces, (GFunc) g_dbus_interface_info_unref, NULL);
1219 g_ptr_array_free (interfaces, TRUE);
1221 g_slist_free (data->interfaces_stack);
1223 /* free stack of node arrays */
1224 for (l = data->nodes_stack; l != NULL; l = l->next)
1226 GPtrArray *nodes = l->data;
1227 g_ptr_array_foreach (nodes, (GFunc) g_dbus_node_info_unref, NULL);
1228 g_ptr_array_free (nodes, TRUE);
1230 g_slist_free (data->nodes_stack);
1232 /* free arrays (data->annotations, data->interfaces and data->nodes have been freed above) */
1233 parse_data_free_args (data);
1234 parse_data_free_out_args (data);
1235 parse_data_free_methods (data);
1236 parse_data_free_signals (data);
1237 parse_data_free_properties (data);
1242 /* ---------------------------------------------------------------------------------------------------- */
1245 parser_start_element (GMarkupParseContext *context,
1246 const gchar *element_name,
1247 const gchar **attribute_names,
1248 const gchar **attribute_values,
1252 ParseData *data = user_data;
1256 const gchar *access;
1257 const gchar *direction;
1266 stack = (GSList *) g_markup_parse_context_get_element_stack (context);
1268 /* ---------------------------------------------------------------------------------------------------- */
1269 if (strcmp (element_name, "node") == 0)
1271 if (!(g_slist_length (stack) >= 1 || strcmp (stack->next->data, "node") != 0))
1273 g_set_error_literal (error,
1275 G_MARKUP_ERROR_INVALID_CONTENT,
1276 "<node> elements can only be top-level or embedded in other <node> elements");
1280 if (!g_markup_collect_attributes (element_name,
1284 G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "name", &name,
1285 /* some hand-written introspection XML documents use this */
1286 G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "xmlns:doc", NULL,
1287 G_MARKUP_COLLECT_INVALID))
1290 g_dbus_node_info_set (data,
1291 parse_data_get_node (data, TRUE),
1297 /* push the currently retrieved interfaces and nodes on the stack and prepare new arrays */
1298 data->interfaces_stack = g_slist_prepend (data->interfaces_stack, data->interfaces);
1299 data->interfaces = NULL;
1300 parse_data_steal_interfaces (data, NULL);
1302 data->nodes_stack = g_slist_prepend (data->nodes_stack, data->nodes);
1304 parse_data_steal_nodes (data, NULL);
1307 /* ---------------------------------------------------------------------------------------------------- */
1308 else if (strcmp (element_name, "interface") == 0)
1310 if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "node") != 0)
1312 g_set_error_literal (error,
1314 G_MARKUP_ERROR_INVALID_CONTENT,
1315 "<interface> elements can only be embedded in <node> elements");
1319 if (!g_markup_collect_attributes (element_name,
1323 G_MARKUP_COLLECT_STRING, "name", &name,
1324 G_MARKUP_COLLECT_INVALID))
1327 g_dbus_interface_info_set (data,
1328 parse_data_get_interface (data, TRUE),
1336 /* ---------------------------------------------------------------------------------------------------- */
1337 else if (strcmp (element_name, "method") == 0)
1339 if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "interface") != 0)
1341 g_set_error_literal (error,
1343 G_MARKUP_ERROR_INVALID_CONTENT,
1344 "<method> elements can only be embedded in <interface> elements");
1348 if (!g_markup_collect_attributes (element_name,
1352 G_MARKUP_COLLECT_STRING, "name", &name,
1353 G_MARKUP_COLLECT_INVALID))
1356 g_dbus_method_info_set (data,
1357 parse_data_get_method (data, TRUE),
1366 /* ---------------------------------------------------------------------------------------------------- */
1367 else if (strcmp (element_name, "signal") == 0)
1369 if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "interface") != 0)
1371 g_set_error_literal (error,
1373 G_MARKUP_ERROR_INVALID_CONTENT,
1374 "<signal> elements can only be embedded in <interface> elements");
1378 if (!g_markup_collect_attributes (element_name,
1382 G_MARKUP_COLLECT_STRING, "name", &name,
1383 G_MARKUP_COLLECT_INVALID))
1386 g_dbus_signal_info_set (data,
1387 parse_data_get_signal (data, TRUE),
1395 /* ---------------------------------------------------------------------------------------------------- */
1396 else if (strcmp (element_name, "property") == 0)
1398 GDBusPropertyInfoFlags flags;
1400 if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "interface") != 0)
1402 g_set_error_literal (error,
1404 G_MARKUP_ERROR_INVALID_CONTENT,
1405 "<property> elements can only be embedded in <interface> elements");
1409 if (!g_markup_collect_attributes (element_name,
1413 G_MARKUP_COLLECT_STRING, "name", &name,
1414 G_MARKUP_COLLECT_STRING, "type", &type,
1415 G_MARKUP_COLLECT_STRING, "access", &access,
1416 G_MARKUP_COLLECT_INVALID))
1419 if (strcmp (access, "read") == 0)
1420 flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE;
1421 else if (strcmp (access, "write") == 0)
1422 flags = G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE;
1423 else if (strcmp (access, "readwrite") == 0)
1424 flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE;
1429 G_MARKUP_ERROR_INVALID_CONTENT,
1430 "Unknown value '%s' of access attribute for element <property>",
1435 g_dbus_property_info_set (data,
1436 parse_data_get_property (data, TRUE),
1443 /* ---------------------------------------------------------------------------------------------------- */
1444 else if (strcmp (element_name, "arg") == 0)
1449 if (g_slist_length (stack) < 2 ||
1450 (strcmp (stack->next->data, "method") != 0 &&
1451 strcmp (stack->next->data, "signal") != 0))
1453 g_set_error_literal (error,
1455 G_MARKUP_ERROR_INVALID_CONTENT,
1456 "<arg> elements can only be embedded in <method> or <signal> elements");
1460 if (!g_markup_collect_attributes (element_name,
1464 G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "name", &name,
1465 G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "direction", &direction,
1466 G_MARKUP_COLLECT_STRING, "type", &type,
1467 G_MARKUP_COLLECT_INVALID))
1471 if (direction != NULL)
1473 if (strcmp (direction, "in") == 0)
1475 else if (strcmp (direction, "out") == 0)
1481 G_MARKUP_ERROR_INVALID_CONTENT,
1482 "Unknown value '%s' of direction attribute",
1488 if (is_in && strcmp (stack->next->data, "signal") == 0)
1490 g_set_error_literal (error,
1492 G_MARKUP_ERROR_INVALID_CONTENT,
1493 "Only direction 'out' is allowed for <arg> elements embedded in <signal>");
1498 name_to_use = g_strdup_printf ("arg_%d", data->num_args);
1500 name_to_use = g_strdup (name);
1505 g_dbus_arg_info_set (data,
1506 parse_data_get_arg (data, TRUE),
1510 data->last_arg_was_in = TRUE;
1514 g_dbus_arg_info_set (data,
1515 parse_data_get_out_arg (data, TRUE),
1519 data->last_arg_was_in = FALSE;
1523 g_free (name_to_use);
1525 /* ---------------------------------------------------------------------------------------------------- */
1526 else if (strcmp (element_name, "annotation") == 0)
1528 if (g_slist_length (stack) < 2 ||
1529 (strcmp (stack->next->data, "node") != 0 &&
1530 strcmp (stack->next->data, "interface") != 0 &&
1531 strcmp (stack->next->data, "signal") != 0 &&
1532 strcmp (stack->next->data, "method") != 0 &&
1533 strcmp (stack->next->data, "property") != 0 &&
1534 strcmp (stack->next->data, "arg") != 0 &&
1535 strcmp (stack->next->data, "annotation") != 0))
1537 g_set_error_literal (error,
1539 G_MARKUP_ERROR_INVALID_CONTENT,
1540 "<annotation> elements can only be embedded in <node>, <interface>, <signal>, <method>, <property>, <arg> or <annotation> elements");
1544 if (!g_markup_collect_attributes (element_name,
1548 G_MARKUP_COLLECT_STRING, "name", &name,
1549 G_MARKUP_COLLECT_STRING, "value", &value,
1550 G_MARKUP_COLLECT_INVALID))
1553 g_dbus_annotation_info_set (data,
1554 parse_data_get_annotation (data, TRUE),
1559 /* ---------------------------------------------------------------------------------------------------- */
1562 /* don't bail on unknown elements; just ignore them */
1564 /* ---------------------------------------------------------------------------------------------------- */
1566 /* push the currently retrieved annotations on the stack and prepare a new one */
1567 data->annotations_stack = g_slist_prepend (data->annotations_stack, data->annotations);
1568 data->annotations = NULL;
1569 parse_data_steal_annotations (data, NULL);
1575 /* ---------------------------------------------------------------------------------------------------- */
1577 static GDBusAnnotationInfo **
1578 steal_annotations (ParseData *data)
1580 return parse_data_steal_annotations (data, NULL);
1585 parser_end_element (GMarkupParseContext *context,
1586 const gchar *element_name,
1590 ParseData *data = user_data;
1591 gboolean have_popped_annotations;
1593 have_popped_annotations = FALSE;
1595 if (strcmp (element_name, "node") == 0)
1598 guint num_interfaces;
1599 GDBusNodeInfo **nodes;
1600 GDBusInterfaceInfo **interfaces;
1602 nodes = parse_data_steal_nodes (data, &num_nodes);
1603 interfaces = parse_data_steal_interfaces (data, &num_interfaces);
1605 /* destroy the nodes, interfaces for scope we're exiting and and pop the nodes, interfaces from the
1606 * scope we're reentering
1608 parse_data_free_interfaces (data);
1609 data->interfaces = (GPtrArray *) data->interfaces_stack->data;
1610 data->interfaces_stack = g_slist_remove (data->interfaces_stack, data->interfaces_stack->data);
1612 parse_data_free_nodes (data);
1613 data->nodes = (GPtrArray *) data->nodes_stack->data;
1614 data->nodes_stack = g_slist_remove (data->nodes_stack, data->nodes_stack->data);
1616 g_dbus_node_info_set (data,
1617 parse_data_get_node (data, FALSE),
1623 steal_annotations (data));
1626 else if (strcmp (element_name, "interface") == 0)
1630 guint num_properties;
1631 GDBusMethodInfo **methods;
1632 GDBusSignalInfo **signals;
1633 GDBusPropertyInfo **properties;
1635 methods = parse_data_steal_methods (data, &num_methods);
1636 signals = parse_data_steal_signals (data, &num_signals);
1637 properties = parse_data_steal_properties (data, &num_properties);
1639 g_dbus_interface_info_set (data,
1640 parse_data_get_interface (data, FALSE),
1648 steal_annotations (data));
1651 else if (strcmp (element_name, "method") == 0)
1655 GDBusArgInfo **in_args;
1656 GDBusArgInfo **out_args;
1658 in_args = parse_data_steal_args (data, &in_num_args);
1659 out_args = parse_data_steal_out_args (data, &out_num_args);
1661 g_dbus_method_info_set (data,
1662 parse_data_get_method (data, FALSE),
1668 steal_annotations (data));
1670 else if (strcmp (element_name, "signal") == 0)
1673 GDBusArgInfo **args;
1675 args = parse_data_steal_out_args (data, &num_args);
1677 g_dbus_signal_info_set (data,
1678 parse_data_get_signal (data, FALSE),
1682 steal_annotations (data));
1684 else if (strcmp (element_name, "property") == 0)
1686 g_dbus_property_info_set (data,
1687 parse_data_get_property (data, FALSE),
1690 G_DBUS_PROPERTY_INFO_FLAGS_NONE,
1691 steal_annotations (data));
1693 else if (strcmp (element_name, "arg") == 0)
1695 g_dbus_arg_info_set (data,
1696 data->last_arg_was_in ? parse_data_get_arg (data, FALSE) : parse_data_get_out_arg (data, FALSE),
1699 steal_annotations (data));
1701 else if (strcmp (element_name, "annotation") == 0)
1703 GDBusAnnotationInfo **embedded_annotations;
1705 embedded_annotations = steal_annotations (data);
1707 /* destroy the annotations for scope we're exiting and and pop the annotations from the scope we're reentering */
1708 parse_data_free_annotations (data);
1709 data->annotations = (GPtrArray *) data->annotations_stack->data;
1710 data->annotations_stack = g_slist_remove (data->annotations_stack, data->annotations_stack->data);
1712 have_popped_annotations = TRUE;
1714 g_dbus_annotation_info_set (data,
1715 parse_data_get_annotation (data, FALSE),
1718 embedded_annotations);
1722 /* don't bail on unknown elements; just ignore them */
1725 if (!have_popped_annotations)
1727 /* destroy the annotations for scope we're exiting and and pop the annotations from the scope we're reentering */
1728 parse_data_free_annotations (data);
1729 data->annotations = (GPtrArray *) data->annotations_stack->data;
1730 data->annotations_stack = g_slist_remove (data->annotations_stack, data->annotations_stack->data);
1734 /* ---------------------------------------------------------------------------------------------------- */
1737 parser_error (GMarkupParseContext *context,
1744 g_markup_parse_context_get_position (context, &line_number, &char_number);
1746 g_prefix_error (&error, "%d:%d: ",
1751 /* ---------------------------------------------------------------------------------------------------- */
1754 * g_dbus_node_info_new_for_xml:
1755 * @xml_data: Valid D-Bus introspection XML.
1756 * @error: Return location for error.
1758 * Parses @xml_data and returns a #GDBusNodeInfo representing the data.
1760 * Returns: A #GDBusNodeInfo structure or %NULL if @error is set. Free
1761 * with g_dbus_node_info_unref().
1764 g_dbus_node_info_new_for_xml (const gchar *xml_data,
1768 GMarkupParseContext *context;
1769 GMarkupParser *parser;
1777 parser = g_new0 (GMarkupParser, 1);
1778 parser->start_element = parser_start_element;
1779 parser->end_element = parser_end_element;
1780 parser->error = parser_error;
1782 data = parse_data_new ();
1783 context = g_markup_parse_context_new (parser,
1786 (GDestroyNotify) parse_data_free);
1788 if (!g_markup_parse_context_parse (context,
1794 GDBusNodeInfo **ughret;
1795 ughret = parse_data_steal_nodes (data, &num_nodes);
1803 G_MARKUP_ERROR_INVALID_CONTENT,
1804 "Expected a single node in introspection XML, found %d",
1808 for (n = 0; n < num_nodes; n++)
1810 for (n = 0; n < num_nodes; n++)
1811 g_dbus_node_info_unref (&(ret[n]));
1823 if (context != NULL)
1824 g_markup_parse_context_free (context);
1829 /* ---------------------------------------------------------------------------------------------------- */
1832 * g_dbus_annotation_info_lookup:
1833 * @annotations: A %NULL-terminated array of annotations or %NULL.
1834 * @name: The name of the annotation to look up.
1836 * Looks up the value of an annotation.
1838 * This cost of this function is O(n) in number of annotations.
1840 * Returns: The value or %NULL if not found. Do not free, it is owned by @annotations.
1843 g_dbus_annotation_info_lookup (const GDBusAnnotationInfo **annotations,
1850 for (n = 0; annotations != NULL && annotations[n]->key != NULL; n++)
1852 if (g_strcmp0 (annotations[n]->key, name) == 0)
1854 ret = annotations[n]->value;
1863 /* ---------------------------------------------------------------------------------------------------- */
1866 * g_dbus_interface_info_lookup_method:
1867 * @info: A #GDBusInterfaceInfo.
1868 * @name: A D-Bus method name (typically in CamelCase)
1870 * Looks up information about a method.
1872 * This cost of this function is O(n) in number of methods.
1874 * Returns: A #GDBusMethodInfo or %NULL if not found. Do not free, it is owned by @info.
1876 const GDBusMethodInfo *
1877 g_dbus_interface_info_lookup_method (const GDBusInterfaceInfo *info,
1881 const GDBusMethodInfo *result;
1883 for (n = 0; info->methods != NULL && info->methods[n] != NULL; n++)
1885 const GDBusMethodInfo *i = info->methods[n];
1887 if (g_strcmp0 (i->name, name) == 0)
1900 /* ---------------------------------------------------------------------------------------------------- */
1903 * g_dbus_interface_info_lookup_signal:
1904 * @info: A #GDBusInterfaceInfo.
1905 * @name: A D-Bus signal name (typically in CamelCase)
1907 * Looks up information about a signal.
1909 * This cost of this function is O(n) in number of signals.
1911 * Returns: A #GDBusSignalInfo or %NULL if not found. Do not free, it is owned by @info.
1913 const GDBusSignalInfo *
1914 g_dbus_interface_info_lookup_signal (const GDBusInterfaceInfo *info,
1918 const GDBusSignalInfo *result;
1920 for (n = 0; info->signals != NULL && info->signals[n] != NULL; n++)
1922 const GDBusSignalInfo *i = info->signals[n];
1924 if (g_strcmp0 (i->name, name) == 0)
1937 /* ---------------------------------------------------------------------------------------------------- */
1940 * g_dbus_interface_info_lookup_property:
1941 * @info: A #GDBusInterfaceInfo.
1942 * @name: A D-Bus property name (typically in CamelCase).
1944 * Looks up information about a property.
1946 * This cost of this function is O(n) in number of properties.
1948 * Returns: A #GDBusPropertyInfo or %NULL if not found. Do not free, it is owned by @info.
1950 const GDBusPropertyInfo *
1951 g_dbus_interface_info_lookup_property (const GDBusInterfaceInfo *info,
1955 const GDBusPropertyInfo *result;
1957 for (n = 0; info->properties != NULL && info->properties[n] != NULL; n++)
1959 const GDBusPropertyInfo *i = info->properties[n];
1961 if (g_strcmp0 (i->name, name) == 0)
1974 /* ---------------------------------------------------------------------------------------------------- */
1977 * g_dbus_node_info_lookup_interface:
1978 * @node_info: A #GDBusNodeInfo.
1979 * @name: A D-Bus interface name.
1981 * Looks up information about an interface.
1983 * This cost of this function is O(n) in number of interfaces.
1985 * Returns: A #GDBusInterfaceInfo or %NULL if not found. Do not free, it is owned by @node_info.
1987 const GDBusInterfaceInfo *
1988 g_dbus_node_info_lookup_interface (const GDBusNodeInfo *node_info,
1992 const GDBusInterfaceInfo *result;
1994 for (n = 0; node_info->interfaces != NULL && node_info->interfaces[n] != NULL; n++)
1996 const GDBusInterfaceInfo *i = node_info->interfaces[n];
1998 if (g_strcmp0 (i->name, name) == 0)