Blame gio/gdbusintrospection.c

Packit ae235b
/* GDBus - GLib D-Bus Library
Packit ae235b
 *
Packit ae235b
 * Copyright (C) 2008-2010 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: David Zeuthen <davidz@redhat.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include <stdlib.h>
Packit ae235b
#include <string.h>
Packit ae235b
Packit ae235b
#include "gdbusintrospection.h"
Packit ae235b
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gdbusintrospection
Packit ae235b
 * @title: D-Bus Introspection Data
Packit ae235b
 * @short_description: Node and interface description data structures
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 *
Packit ae235b
 * Various data structures and convenience routines to parse and
Packit ae235b
 * generate D-Bus introspection XML. Introspection information is
Packit ae235b
 * used when registering objects with g_dbus_connection_register_object().
Packit ae235b
 *
Packit ae235b
 * The format of D-Bus introspection XML is specified in the
Packit ae235b
 * [D-Bus specification](http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format)
Packit ae235b
 */
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
#define _MY_DEFINE_BOXED_TYPE(TypeName, type_name) \
Packit ae235b
  G_DEFINE_BOXED_TYPE (TypeName, type_name, type_name##_ref, type_name##_unref)
Packit ae235b
Packit ae235b
_MY_DEFINE_BOXED_TYPE (GDBusNodeInfo,       g_dbus_node_info)
Packit ae235b
_MY_DEFINE_BOXED_TYPE (GDBusInterfaceInfo,  g_dbus_interface_info)
Packit ae235b
_MY_DEFINE_BOXED_TYPE (GDBusMethodInfo,     g_dbus_method_info)
Packit ae235b
_MY_DEFINE_BOXED_TYPE (GDBusSignalInfo,     g_dbus_signal_info)
Packit ae235b
_MY_DEFINE_BOXED_TYPE (GDBusPropertyInfo,   g_dbus_property_info)
Packit ae235b
_MY_DEFINE_BOXED_TYPE (GDBusArgInfo,        g_dbus_arg_info)
Packit ae235b
_MY_DEFINE_BOXED_TYPE (GDBusAnnotationInfo, g_dbus_annotation_info)
Packit ae235b
Packit ae235b
#undef _MY_DEFINE_BOXED_TYPE
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  /* stuff we are currently collecting */
Packit ae235b
  GPtrArray *args;
Packit ae235b
  GPtrArray *out_args;
Packit ae235b
  GPtrArray *methods;
Packit ae235b
  GPtrArray *signals;
Packit ae235b
  GPtrArray *properties;
Packit ae235b
  GPtrArray *interfaces;
Packit ae235b
  GPtrArray *nodes;
Packit ae235b
  GPtrArray *annotations;
Packit ae235b
Packit ae235b
  /* A list of GPtrArray's containing annotations */
Packit ae235b
  GSList *annotations_stack;
Packit ae235b
Packit ae235b
  /* A list of GPtrArray's containing interfaces */
Packit ae235b
  GSList *interfaces_stack;
Packit ae235b
Packit ae235b
  /* A list of GPtrArray's containing nodes */
Packit ae235b
  GSList *nodes_stack;
Packit ae235b
Packit ae235b
  /* Whether the direction was "in" for last parsed arg */
Packit ae235b
  gboolean last_arg_was_in;
Packit ae235b
Packit ae235b
  /* Number of args currently being collected; used for assigning
Packit ae235b
   * names to args without a "name" attribute
Packit ae235b
   */
Packit ae235b
  guint num_args;
Packit ae235b
Packit ae235b
} ParseData;
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_node_info_ref:
Packit ae235b
 * @info: A #GDBusNodeInfo
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated does nothing. Otherwise increases
Packit ae235b
 * the reference count.
Packit ae235b
 *
Packit ae235b
 * Returns: The same @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusNodeInfo *
Packit ae235b
g_dbus_node_info_ref (GDBusNodeInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return info;
Packit ae235b
  g_atomic_int_inc (&info->ref_count);
Packit ae235b
  return info;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_info_ref:
Packit ae235b
 * @info: A #GDBusInterfaceInfo
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated does nothing. Otherwise increases
Packit ae235b
 * the reference count.
Packit ae235b
 *
Packit ae235b
 * Returns: The same @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusInterfaceInfo *
Packit ae235b
g_dbus_interface_info_ref (GDBusInterfaceInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return info;
Packit ae235b
  g_atomic_int_inc (&info->ref_count);
Packit ae235b
  return info;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_method_info_ref:
Packit ae235b
 * @info: A #GDBusMethodInfo
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated does nothing. Otherwise increases
Packit ae235b
 * the reference count.
Packit ae235b
 *
Packit ae235b
 * Returns: The same @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusMethodInfo *
Packit ae235b
g_dbus_method_info_ref (GDBusMethodInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return info;
Packit ae235b
  g_atomic_int_inc (&info->ref_count);
Packit ae235b
  return info;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_signal_info_ref:
Packit ae235b
 * @info: A #GDBusSignalInfo
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated does nothing. Otherwise increases
Packit ae235b
 * the reference count.
Packit ae235b
 *
Packit ae235b
 * Returns: The same @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusSignalInfo *
Packit ae235b
g_dbus_signal_info_ref (GDBusSignalInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return info;
Packit ae235b
  g_atomic_int_inc (&info->ref_count);
Packit ae235b
  return info;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_property_info_ref:
Packit ae235b
 * @info: A #GDBusPropertyInfo
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated does nothing. Otherwise increases
Packit ae235b
 * the reference count.
Packit ae235b
 *
Packit ae235b
 * Returns: The same @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusPropertyInfo *
Packit ae235b
g_dbus_property_info_ref (GDBusPropertyInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return info;
Packit ae235b
  g_atomic_int_inc (&info->ref_count);
Packit ae235b
  return info;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_arg_info_ref:
Packit ae235b
 * @info: A #GDBusArgInfo
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated does nothing. Otherwise increases
Packit ae235b
 * the reference count.
Packit ae235b
 *
Packit ae235b
 * Returns: The same @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusArgInfo *
Packit ae235b
g_dbus_arg_info_ref (GDBusArgInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return info;
Packit ae235b
  g_atomic_int_inc (&info->ref_count);
Packit ae235b
  return info;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_annotation_info_ref:
Packit ae235b
 * @info: A #GDBusNodeInfo
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated does nothing. Otherwise increases
Packit ae235b
 * the reference count.
Packit ae235b
 *
Packit ae235b
 * Returns: The same @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusAnnotationInfo *
Packit ae235b
g_dbus_annotation_info_ref (GDBusAnnotationInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return info;
Packit ae235b
  g_atomic_int_inc (&info->ref_count);
Packit ae235b
  return info;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
free_null_terminated_array (gpointer array, GDestroyNotify unref_func)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
  gpointer *p = array;
Packit ae235b
  if (p == NULL)
Packit ae235b
    return;
Packit ae235b
  for (n = 0; p[n] != NULL; n++)
Packit ae235b
    unref_func (p[n]);
Packit ae235b
  g_free (p);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_annotation_info_unref:
Packit ae235b
 * @info: A #GDBusAnnotationInfo.
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated, does nothing. Otherwise decreases
Packit ae235b
 * the reference count of @info. When its reference count drops to 0,
Packit ae235b
 * the memory used is freed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_annotation_info_unref (GDBusAnnotationInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return;
Packit ae235b
  if (g_atomic_int_dec_and_test (&info->ref_count))
Packit ae235b
    {
Packit ae235b
      g_free (info->key);
Packit ae235b
      g_free (info->value);
Packit ae235b
      free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
Packit ae235b
      g_free (info);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_arg_info_unref:
Packit ae235b
 * @info: A #GDBusArgInfo.
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated, does nothing. Otherwise decreases
Packit ae235b
 * the reference count of @info. When its reference count drops to 0,
Packit ae235b
 * the memory used is freed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_arg_info_unref (GDBusArgInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return;
Packit ae235b
  if (g_atomic_int_dec_and_test (&info->ref_count))
Packit ae235b
    {
Packit ae235b
      g_free (info->name);
Packit ae235b
      g_free (info->signature);
Packit ae235b
      free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
Packit ae235b
      g_free (info);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_method_info_unref:
Packit ae235b
 * @info: A #GDBusMethodInfo.
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated, does nothing. Otherwise decreases
Packit ae235b
 * the reference count of @info. When its reference count drops to 0,
Packit ae235b
 * the memory used is freed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_method_info_unref (GDBusMethodInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return;
Packit ae235b
  if (g_atomic_int_dec_and_test (&info->ref_count))
Packit ae235b
    {
Packit ae235b
      g_free (info->name);
Packit ae235b
      free_null_terminated_array (info->in_args, (GDestroyNotify) g_dbus_arg_info_unref);
Packit ae235b
      free_null_terminated_array (info->out_args, (GDestroyNotify) g_dbus_arg_info_unref);
Packit ae235b
      free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
Packit ae235b
      g_free (info);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_signal_info_unref:
Packit ae235b
 * @info: A #GDBusSignalInfo.
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated, does nothing. Otherwise decreases
Packit ae235b
 * the reference count of @info. When its reference count drops to 0,
Packit ae235b
 * the memory used is freed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_signal_info_unref (GDBusSignalInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return;
Packit ae235b
  if (g_atomic_int_dec_and_test (&info->ref_count))
Packit ae235b
    {
Packit ae235b
      g_free (info->name);
Packit ae235b
      free_null_terminated_array (info->args, (GDestroyNotify) g_dbus_arg_info_unref);
Packit ae235b
      free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
Packit ae235b
      g_free (info);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_property_info_unref:
Packit ae235b
 * @info: A #GDBusPropertyInfo.
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated, does nothing. Otherwise decreases
Packit ae235b
 * the reference count of @info. When its reference count drops to 0,
Packit ae235b
 * the memory used is freed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_property_info_unref (GDBusPropertyInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return;
Packit ae235b
  if (g_atomic_int_dec_and_test (&info->ref_count))
Packit ae235b
    {
Packit ae235b
      g_free (info->name);
Packit ae235b
      g_free (info->signature);
Packit ae235b
      free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
Packit ae235b
      g_free (info);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_info_unref:
Packit ae235b
 * @info: A #GDBusInterfaceInfo.
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated, does nothing. Otherwise decreases
Packit ae235b
 * the reference count of @info. When its reference count drops to 0,
Packit ae235b
 * the memory used is freed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_interface_info_unref (GDBusInterfaceInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return;
Packit ae235b
  if (g_atomic_int_dec_and_test (&info->ref_count))
Packit ae235b
    {
Packit ae235b
      g_free (info->name);
Packit ae235b
      free_null_terminated_array (info->methods, (GDestroyNotify) g_dbus_method_info_unref);
Packit ae235b
      free_null_terminated_array (info->signals, (GDestroyNotify) g_dbus_signal_info_unref);
Packit ae235b
      free_null_terminated_array (info->properties, (GDestroyNotify) g_dbus_property_info_unref);
Packit ae235b
      free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
Packit ae235b
      g_free (info);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_node_info_unref:
Packit ae235b
 * @info: A #GDBusNodeInfo.
Packit ae235b
 *
Packit ae235b
 * If @info is statically allocated, does nothing. Otherwise decreases
Packit ae235b
 * the reference count of @info. When its reference count drops to 0,
Packit ae235b
 * the memory used is freed.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_node_info_unref (GDBusNodeInfo *info)
Packit ae235b
{
Packit ae235b
  if (info->ref_count == -1)
Packit ae235b
    return;
Packit ae235b
  if (g_atomic_int_dec_and_test (&info->ref_count))
Packit ae235b
    {
Packit ae235b
      g_free (info->path);
Packit ae235b
      free_null_terminated_array (info->interfaces, (GDestroyNotify) g_dbus_interface_info_unref);
Packit ae235b
      free_null_terminated_array (info->nodes, (GDestroyNotify) g_dbus_node_info_unref);
Packit ae235b
      free_null_terminated_array (info->annotations, (GDestroyNotify) g_dbus_annotation_info_unref);
Packit ae235b
      g_free (info);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_annotation_info_set (ParseData            *data,
Packit ae235b
                            GDBusAnnotationInfo  *info,
Packit ae235b
                            const gchar          *key,
Packit ae235b
                            const gchar          *value,
Packit ae235b
                            GDBusAnnotationInfo **embedded_annotations)
Packit ae235b
{
Packit ae235b
  info->ref_count = 1;
Packit ae235b
Packit ae235b
  if (key != NULL)
Packit ae235b
    info->key = g_strdup (key);
Packit ae235b
Packit ae235b
  if (value != NULL)
Packit ae235b
    info->value = g_strdup (value);
Packit ae235b
Packit ae235b
  if (embedded_annotations != NULL)
Packit ae235b
    info->annotations = embedded_annotations;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_arg_info_set (ParseData            *data,
Packit ae235b
                     GDBusArgInfo         *info,
Packit ae235b
                     const gchar          *name,
Packit ae235b
                     const gchar          *signature,
Packit ae235b
                     GDBusAnnotationInfo **annotations)
Packit ae235b
{
Packit ae235b
  info->ref_count = 1;
Packit ae235b
Packit ae235b
  /* name may be NULL - TODO: compute name? */
Packit ae235b
  if (name != NULL)
Packit ae235b
    info->name = g_strdup (name);
Packit ae235b
Packit ae235b
  if (signature != NULL)
Packit ae235b
    info->signature = g_strdup (signature);
Packit ae235b
Packit ae235b
  if (annotations != NULL)
Packit ae235b
    info->annotations = annotations;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_method_info_set (ParseData            *data,
Packit ae235b
                        GDBusMethodInfo      *info,
Packit ae235b
                        const gchar          *name,
Packit ae235b
                        GDBusArgInfo        **in_args,
Packit ae235b
                        GDBusArgInfo        **out_args,
Packit ae235b
                        GDBusAnnotationInfo **annotations)
Packit ae235b
{
Packit ae235b
  info->ref_count = 1;
Packit ae235b
Packit ae235b
  if (name != NULL)
Packit ae235b
    info->name = g_strdup (name);
Packit ae235b
Packit ae235b
  if (in_args != NULL)
Packit ae235b
    info->in_args = in_args;
Packit ae235b
Packit ae235b
  if (out_args != NULL)
Packit ae235b
    info->out_args = out_args;
Packit ae235b
Packit ae235b
  if (annotations != NULL)
Packit ae235b
    info->annotations = annotations;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_signal_info_set (ParseData            *data,
Packit ae235b
                        GDBusSignalInfo      *info,
Packit ae235b
                        const gchar          *name,
Packit ae235b
                        GDBusArgInfo        **args,
Packit ae235b
                        GDBusAnnotationInfo **annotations)
Packit ae235b
{
Packit ae235b
  info->ref_count = 1;
Packit ae235b
Packit ae235b
  if (name != NULL)
Packit ae235b
    info->name = g_strdup (name);
Packit ae235b
Packit ae235b
  if (args != NULL)
Packit ae235b
    info->args = args;
Packit ae235b
Packit ae235b
  if (annotations != NULL)
Packit ae235b
    info->annotations = annotations;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_property_info_set (ParseData               *data,
Packit ae235b
                          GDBusPropertyInfo       *info,
Packit ae235b
                          const gchar             *name,
Packit ae235b
                          const gchar             *signature,
Packit ae235b
                          GDBusPropertyInfoFlags   flags,
Packit ae235b
                          GDBusAnnotationInfo    **annotations)
Packit ae235b
{
Packit ae235b
  info->ref_count = 1;
Packit ae235b
Packit ae235b
  if (name != NULL)
Packit ae235b
    info->name = g_strdup (name);
Packit ae235b
Packit ae235b
  if (flags != G_DBUS_PROPERTY_INFO_FLAGS_NONE)
Packit ae235b
    info->flags = flags;
Packit ae235b
Packit ae235b
  if (signature != NULL)
Packit ae235b
    info->signature = g_strdup (signature);
Packit ae235b
Packit ae235b
  if (annotations != NULL)
Packit ae235b
    info->annotations = annotations;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_interface_info_set (ParseData            *data,
Packit ae235b
                           GDBusInterfaceInfo   *info,
Packit ae235b
                           const gchar          *name,
Packit ae235b
                           GDBusMethodInfo     **methods,
Packit ae235b
                           GDBusSignalInfo     **signals,
Packit ae235b
                           GDBusPropertyInfo   **properties,
Packit ae235b
                           GDBusAnnotationInfo **annotations)
Packit ae235b
{
Packit ae235b
  info->ref_count = 1;
Packit ae235b
Packit ae235b
  if (name != NULL)
Packit ae235b
    info->name = g_strdup (name);
Packit ae235b
Packit ae235b
  if (methods != NULL)
Packit ae235b
    info->methods = methods;
Packit ae235b
Packit ae235b
  if (signals != NULL)
Packit ae235b
    info->signals = signals;
Packit ae235b
Packit ae235b
  if (properties != NULL)
Packit ae235b
    info->properties = properties;
Packit ae235b
Packit ae235b
  if (annotations != NULL)
Packit ae235b
    info->annotations = annotations;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_node_info_set (ParseData            *data,
Packit ae235b
                      GDBusNodeInfo        *info,
Packit ae235b
                      const gchar          *path,
Packit ae235b
                      GDBusInterfaceInfo  **interfaces,
Packit ae235b
                      GDBusNodeInfo       **nodes,
Packit ae235b
                      GDBusAnnotationInfo **annotations)
Packit ae235b
{
Packit ae235b
  info->ref_count = 1;
Packit ae235b
Packit ae235b
  if (path != NULL)
Packit ae235b
    {
Packit ae235b
      info->path = g_strdup (path);
Packit ae235b
      /* TODO: relative / absolute path snafu */
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (interfaces != NULL)
Packit ae235b
    info->interfaces = interfaces;
Packit ae235b
Packit ae235b
  if (nodes != NULL)
Packit ae235b
    info->nodes = nodes;
Packit ae235b
Packit ae235b
  if (annotations != NULL)
Packit ae235b
    info->annotations = annotations;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_annotation_info_generate_xml (GDBusAnnotationInfo *info,
Packit ae235b
                                     guint                indent,
Packit ae235b
                                     GString             *string_builder)
Packit ae235b
{
Packit ae235b
  gchar *tmp;
Packit ae235b
  guint n;
Packit ae235b
Packit ae235b
  tmp = g_markup_printf_escaped ("%*s
Packit ae235b
                                 indent, "",
Packit ae235b
                                 info->key,
Packit ae235b
                                 info->value);
Packit ae235b
  g_string_append (string_builder, tmp);
Packit ae235b
  g_free (tmp);
Packit ae235b
Packit ae235b
  if (info->annotations == NULL)
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, "/>\n");
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, ">\n");
Packit ae235b
Packit ae235b
      for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
Packit ae235b
        g_dbus_annotation_info_generate_xml (info->annotations[n],
Packit ae235b
                                             indent + 2,
Packit ae235b
                                             string_builder);
Packit ae235b
Packit ae235b
      g_string_append_printf (string_builder, "%*s</annotation>\n",
Packit ae235b
                              indent, "");
Packit ae235b
    }
Packit ae235b
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_arg_info_generate_xml (GDBusArgInfo *info,
Packit ae235b
                              guint         indent,
Packit ae235b
                              const gchar  *extra_attributes,
Packit ae235b
                              GString      *string_builder)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
Packit ae235b
  g_string_append_printf (string_builder, "%*s
Packit ae235b
                          indent, "",
Packit ae235b
                          info->signature);
Packit ae235b
Packit ae235b
  if (info->name != NULL)
Packit ae235b
    g_string_append_printf (string_builder, " name=\"%s\"", info->name);
Packit ae235b
Packit ae235b
  if (extra_attributes != NULL)
Packit ae235b
    g_string_append_printf (string_builder, " %s", extra_attributes);
Packit ae235b
Packit ae235b
  if (info->annotations == NULL)
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, "/>\n");
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, ">\n");
Packit ae235b
Packit ae235b
      for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
Packit ae235b
        g_dbus_annotation_info_generate_xml (info->annotations[n],
Packit ae235b
                                             indent + 2,
Packit ae235b
                                             string_builder);
Packit ae235b
Packit ae235b
      g_string_append_printf (string_builder, "%*s</arg>\n", indent, "");
Packit ae235b
    }
Packit ae235b
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_method_info_generate_xml (GDBusMethodInfo *info,
Packit ae235b
                                 guint            indent,
Packit ae235b
                                 GString         *string_builder)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
Packit ae235b
  g_string_append_printf (string_builder, "%*s
Packit ae235b
                          indent, "",
Packit ae235b
                          info->name);
Packit ae235b
Packit ae235b
  if (info->annotations == NULL && info->in_args == NULL && info->out_args == NULL)
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, "/>\n");
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, ">\n");
Packit ae235b
Packit ae235b
      for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
Packit ae235b
        g_dbus_annotation_info_generate_xml (info->annotations[n],
Packit ae235b
                                             indent + 2,
Packit ae235b
                                             string_builder);
Packit ae235b
Packit ae235b
      for (n = 0; info->in_args != NULL && info->in_args[n] != NULL; n++)
Packit ae235b
        g_dbus_arg_info_generate_xml (info->in_args[n],
Packit ae235b
                                      indent + 2,
Packit ae235b
                                      "direction=\"in\"",
Packit ae235b
                                      string_builder);
Packit ae235b
Packit ae235b
      for (n = 0; info->out_args != NULL && info->out_args[n] != NULL; n++)
Packit ae235b
        g_dbus_arg_info_generate_xml (info->out_args[n],
Packit ae235b
                                      indent + 2,
Packit ae235b
                                      "direction=\"out\"",
Packit ae235b
                                      string_builder);
Packit ae235b
Packit ae235b
      g_string_append_printf (string_builder, "%*s</method>\n", indent, "");
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_signal_info_generate_xml (GDBusSignalInfo *info,
Packit ae235b
                                 guint            indent,
Packit ae235b
                                 GString         *string_builder)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
Packit ae235b
  g_string_append_printf (string_builder, "%*s
Packit ae235b
                          indent, "",
Packit ae235b
                          info->name);
Packit ae235b
Packit ae235b
  if (info->annotations == NULL && info->args == NULL)
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, "/>\n");
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, ">\n");
Packit ae235b
Packit ae235b
      for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
Packit ae235b
        g_dbus_annotation_info_generate_xml (info->annotations[n],
Packit ae235b
                                             indent + 2,
Packit ae235b
                                             string_builder);
Packit ae235b
Packit ae235b
      for (n = 0; info->args != NULL && info->args[n] != NULL; n++)
Packit ae235b
        g_dbus_arg_info_generate_xml (info->args[n],
Packit ae235b
                                      indent + 2,
Packit ae235b
                                      NULL,
Packit ae235b
                                      string_builder);
Packit ae235b
Packit ae235b
      g_string_append_printf (string_builder, "%*s</signal>\n", indent, "");
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dbus_property_info_generate_xml (GDBusPropertyInfo *info,
Packit ae235b
                                   guint              indent,
Packit ae235b
                                   GString           *string_builder)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
  const gchar *access_string;
Packit ae235b
Packit ae235b
  if ((info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE) &&
Packit ae235b
      (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE))
Packit ae235b
    {
Packit ae235b
      access_string = "readwrite";
Packit ae235b
    }
Packit ae235b
  else if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)
Packit ae235b
    {
Packit ae235b
      access_string = "read";
Packit ae235b
    }
Packit ae235b
  else if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE)
Packit ae235b
    {
Packit ae235b
      access_string = "write";
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_assert_not_reached ();
Packit ae235b
    }
Packit ae235b
Packit ae235b
  g_string_append_printf (string_builder, "%*s
Packit ae235b
                          indent, "",
Packit ae235b
                          info->signature,
Packit ae235b
                          info->name,
Packit ae235b
                          access_string);
Packit ae235b
Packit ae235b
  if (info->annotations == NULL)
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, "/>\n");
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, ">\n");
Packit ae235b
Packit ae235b
      for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
Packit ae235b
        g_dbus_annotation_info_generate_xml (info->annotations[n],
Packit ae235b
                                               indent + 2,
Packit ae235b
                                               string_builder);
Packit ae235b
Packit ae235b
      g_string_append_printf (string_builder, "%*s</property>\n", indent, "");
Packit ae235b
    }
Packit ae235b
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_info_generate_xml:
Packit ae235b
 * @info: A #GDBusNodeInfo
Packit ae235b
 * @indent: Indentation level.
Packit ae235b
 * @string_builder: A #GString to to append XML data to.
Packit ae235b
 *
Packit ae235b
 * Appends an XML representation of @info (and its children) to @string_builder.
Packit ae235b
 *
Packit ae235b
 * This function is typically used for generating introspection XML
Packit ae235b
 * documents at run-time for handling the
Packit ae235b
 * `org.freedesktop.DBus.Introspectable.Introspect`
Packit ae235b
 * method.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_interface_info_generate_xml (GDBusInterfaceInfo *info,
Packit ae235b
                                    guint               indent,
Packit ae235b
                                    GString            *string_builder)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
Packit ae235b
  g_string_append_printf (string_builder, "%*s<interface name=\"%s\">\n",
Packit ae235b
                          indent, "",
Packit ae235b
                          info->name);
Packit ae235b
Packit ae235b
  for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
Packit ae235b
    g_dbus_annotation_info_generate_xml (info->annotations[n],
Packit ae235b
                                         indent + 2,
Packit ae235b
                                         string_builder);
Packit ae235b
Packit ae235b
  for (n = 0; info->methods != NULL && info->methods[n] != NULL; n++)
Packit ae235b
    g_dbus_method_info_generate_xml (info->methods[n],
Packit ae235b
                                     indent + 2,
Packit ae235b
                                     string_builder);
Packit ae235b
Packit ae235b
  for (n = 0; info->signals != NULL && info->signals[n] != NULL; n++)
Packit ae235b
    g_dbus_signal_info_generate_xml (info->signals[n],
Packit ae235b
                                     indent + 2,
Packit ae235b
                                     string_builder);
Packit ae235b
Packit ae235b
  for (n = 0; info->properties != NULL && info->properties[n] != NULL; n++)
Packit ae235b
    g_dbus_property_info_generate_xml (info->properties[n],
Packit ae235b
                                       indent + 2,
Packit ae235b
                                       string_builder);
Packit ae235b
Packit ae235b
  g_string_append_printf (string_builder, "%*s</interface>\n", indent, "");
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_node_info_generate_xml:
Packit ae235b
 * @info: A #GDBusNodeInfo.
Packit ae235b
 * @indent: Indentation level.
Packit ae235b
 * @string_builder: A #GString to to append XML data to.
Packit ae235b
 *
Packit ae235b
 * Appends an XML representation of @info (and its children) to @string_builder.
Packit ae235b
 *
Packit ae235b
 * This function is typically used for generating introspection XML documents at run-time for
Packit ae235b
 * handling the `org.freedesktop.DBus.Introspectable.Introspect`  method.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_node_info_generate_xml (GDBusNodeInfo *info,
Packit ae235b
                               guint          indent,
Packit ae235b
                               GString       *string_builder)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
Packit ae235b
  g_string_append_printf (string_builder, "%*s
Packit ae235b
  if (info->path != NULL)
Packit ae235b
    g_string_append_printf (string_builder, " name=\"%s\"", info->path);
Packit ae235b
Packit ae235b
  if (info->interfaces == NULL && info->nodes == NULL && info->annotations == NULL)
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, "/>\n");
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_string_append (string_builder, ">\n");
Packit ae235b
Packit ae235b
      for (n = 0; info->annotations != NULL && info->annotations[n] != NULL; n++)
Packit ae235b
        g_dbus_annotation_info_generate_xml (info->annotations[n],
Packit ae235b
                                             indent + 2,
Packit ae235b
                                             string_builder);
Packit ae235b
Packit ae235b
      for (n = 0; info->interfaces != NULL && info->interfaces[n] != NULL; n++)
Packit ae235b
        g_dbus_interface_info_generate_xml (info->interfaces[n],
Packit ae235b
                                            indent + 2,
Packit ae235b
                                            string_builder);
Packit ae235b
Packit ae235b
      for (n = 0; info->nodes != NULL && info->nodes[n] != NULL; n++)
Packit ae235b
        g_dbus_node_info_generate_xml (info->nodes[n],
Packit ae235b
                                       indent + 2,
Packit ae235b
                                       string_builder);
Packit ae235b
Packit ae235b
      g_string_append_printf (string_builder, "%*s</node>\n", indent, "");
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static GDBusAnnotationInfo **
Packit ae235b
parse_data_steal_annotations (ParseData *data,
Packit ae235b
                              guint     *out_num_elements)
Packit ae235b
{
Packit ae235b
  GDBusAnnotationInfo **ret;
Packit ae235b
  if (out_num_elements != NULL)
Packit ae235b
    *out_num_elements = data->annotations->len;
Packit ae235b
  if (data->annotations == NULL)
Packit ae235b
    ret = NULL;
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_ptr_array_add (data->annotations, NULL);
Packit ae235b
      ret = (GDBusAnnotationInfo **) g_ptr_array_free (data->annotations, FALSE);
Packit ae235b
    }
Packit ae235b
  data->annotations = g_ptr_array_new ();
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusArgInfo **
Packit ae235b
parse_data_steal_args (ParseData *data,
Packit ae235b
                       guint     *out_num_elements)
Packit ae235b
{
Packit ae235b
  GDBusArgInfo **ret;
Packit ae235b
  if (out_num_elements != NULL)
Packit ae235b
    *out_num_elements = data->args->len;
Packit ae235b
  if (data->args == NULL)
Packit ae235b
    ret = NULL;
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_ptr_array_add (data->args, NULL);
Packit ae235b
      ret = (GDBusArgInfo **) g_ptr_array_free (data->args, FALSE);
Packit ae235b
    }
Packit ae235b
  data->args = g_ptr_array_new ();
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusArgInfo **
Packit ae235b
parse_data_steal_out_args (ParseData *data,
Packit ae235b
                           guint     *out_num_elements)
Packit ae235b
{
Packit ae235b
  GDBusArgInfo **ret;
Packit ae235b
  if (out_num_elements != NULL)
Packit ae235b
    *out_num_elements = data->out_args->len;
Packit ae235b
  if (data->out_args == NULL)
Packit ae235b
    ret = NULL;
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_ptr_array_add (data->out_args, NULL);
Packit ae235b
      ret = (GDBusArgInfo **) g_ptr_array_free (data->out_args, FALSE);
Packit ae235b
    }
Packit ae235b
  data->out_args = g_ptr_array_new ();
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusMethodInfo **
Packit ae235b
parse_data_steal_methods (ParseData *data,
Packit ae235b
                          guint     *out_num_elements)
Packit ae235b
{
Packit ae235b
  GDBusMethodInfo **ret;
Packit ae235b
  if (out_num_elements != NULL)
Packit ae235b
    *out_num_elements = data->methods->len;
Packit ae235b
  if (data->methods == NULL)
Packit ae235b
    ret = NULL;
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_ptr_array_add (data->methods, NULL);
Packit ae235b
      ret = (GDBusMethodInfo **) g_ptr_array_free (data->methods, FALSE);
Packit ae235b
    }
Packit ae235b
  data->methods = g_ptr_array_new ();
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusSignalInfo **
Packit ae235b
parse_data_steal_signals (ParseData *data,
Packit ae235b
                          guint     *out_num_elements)
Packit ae235b
{
Packit ae235b
  GDBusSignalInfo **ret;
Packit ae235b
  if (out_num_elements != NULL)
Packit ae235b
    *out_num_elements = data->signals->len;
Packit ae235b
  if (data->signals == NULL)
Packit ae235b
    ret = NULL;
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_ptr_array_add (data->signals, NULL);
Packit ae235b
      ret = (GDBusSignalInfo **) g_ptr_array_free (data->signals, FALSE);
Packit ae235b
    }
Packit ae235b
  data->signals = g_ptr_array_new ();
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusPropertyInfo **
Packit ae235b
parse_data_steal_properties (ParseData *data,
Packit ae235b
                             guint     *out_num_elements)
Packit ae235b
{
Packit ae235b
  GDBusPropertyInfo **ret;
Packit ae235b
  if (out_num_elements != NULL)
Packit ae235b
    *out_num_elements = data->properties->len;
Packit ae235b
  if (data->properties == NULL)
Packit ae235b
    ret = NULL;
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_ptr_array_add (data->properties, NULL);
Packit ae235b
      ret = (GDBusPropertyInfo **) g_ptr_array_free (data->properties, FALSE);
Packit ae235b
    }
Packit ae235b
  data->properties = g_ptr_array_new ();
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusInterfaceInfo **
Packit ae235b
parse_data_steal_interfaces (ParseData *data,
Packit ae235b
                             guint     *out_num_elements)
Packit ae235b
{
Packit ae235b
  GDBusInterfaceInfo **ret;
Packit ae235b
  if (out_num_elements != NULL)
Packit ae235b
    *out_num_elements = data->interfaces->len;
Packit ae235b
  if (data->interfaces == NULL)
Packit ae235b
    ret = NULL;
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_ptr_array_add (data->interfaces, NULL);
Packit ae235b
      ret = (GDBusInterfaceInfo **) g_ptr_array_free (data->interfaces, FALSE);
Packit ae235b
    }
Packit ae235b
  data->interfaces = g_ptr_array_new ();
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusNodeInfo **
Packit ae235b
parse_data_steal_nodes (ParseData *data,
Packit ae235b
                        guint     *out_num_elements)
Packit ae235b
{
Packit ae235b
  GDBusNodeInfo **ret;
Packit ae235b
  if (out_num_elements != NULL)
Packit ae235b
    *out_num_elements = data->nodes->len;
Packit ae235b
  if (data->nodes == NULL)
Packit ae235b
    ret = NULL;
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      g_ptr_array_add (data->nodes, NULL);
Packit ae235b
      ret = (GDBusNodeInfo **) g_ptr_array_free (data->nodes, FALSE);
Packit ae235b
    }
Packit ae235b
  data->nodes = g_ptr_array_new ();
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
parse_data_free_annotations (ParseData *data)
Packit ae235b
{
Packit ae235b
  if (data->annotations == NULL)
Packit ae235b
    return;
Packit ae235b
  g_ptr_array_foreach (data->annotations, (GFunc) g_dbus_annotation_info_unref, NULL);
Packit ae235b
  g_ptr_array_free (data->annotations, TRUE);
Packit ae235b
  data->annotations = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
parse_data_free_args (ParseData *data)
Packit ae235b
{
Packit ae235b
  if (data->args == NULL)
Packit ae235b
    return;
Packit ae235b
  g_ptr_array_foreach (data->args, (GFunc) g_dbus_arg_info_unref, NULL);
Packit ae235b
  g_ptr_array_free (data->args, TRUE);
Packit ae235b
  data->args = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
parse_data_free_out_args (ParseData *data)
Packit ae235b
{
Packit ae235b
  if (data->out_args == NULL)
Packit ae235b
    return;
Packit ae235b
  g_ptr_array_foreach (data->out_args, (GFunc) g_dbus_arg_info_unref, NULL);
Packit ae235b
  g_ptr_array_free (data->out_args, TRUE);
Packit ae235b
  data->out_args = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
parse_data_free_methods (ParseData *data)
Packit ae235b
{
Packit ae235b
  if (data->methods == NULL)
Packit ae235b
    return;
Packit ae235b
  g_ptr_array_foreach (data->methods, (GFunc) g_dbus_method_info_unref, NULL);
Packit ae235b
  g_ptr_array_free (data->methods, TRUE);
Packit ae235b
  data->methods = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
parse_data_free_signals (ParseData *data)
Packit ae235b
{
Packit ae235b
  if (data->signals == NULL)
Packit ae235b
    return;
Packit ae235b
  g_ptr_array_foreach (data->signals, (GFunc) g_dbus_signal_info_unref, NULL);
Packit ae235b
  g_ptr_array_free (data->signals, TRUE);
Packit ae235b
  data->signals = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
parse_data_free_properties (ParseData *data)
Packit ae235b
{
Packit ae235b
  if (data->properties == NULL)
Packit ae235b
    return;
Packit ae235b
  g_ptr_array_foreach (data->properties, (GFunc) g_dbus_property_info_unref, NULL);
Packit ae235b
  g_ptr_array_free (data->properties, TRUE);
Packit ae235b
  data->properties = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
parse_data_free_interfaces (ParseData *data)
Packit ae235b
{
Packit ae235b
  if (data->interfaces == NULL)
Packit ae235b
    return;
Packit ae235b
  g_ptr_array_foreach (data->interfaces, (GFunc) g_dbus_interface_info_unref, NULL);
Packit ae235b
  g_ptr_array_free (data->interfaces, TRUE);
Packit ae235b
  data->interfaces = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
parse_data_free_nodes (ParseData *data)
Packit ae235b
{
Packit ae235b
  if (data->nodes == NULL)
Packit ae235b
    return;
Packit ae235b
  g_ptr_array_foreach (data->nodes, (GFunc) g_dbus_node_info_unref, NULL);
Packit ae235b
  g_ptr_array_free (data->nodes, TRUE);
Packit ae235b
  data->nodes = NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static GDBusAnnotationInfo *
Packit ae235b
parse_data_get_annotation (ParseData *data,
Packit ae235b
                           gboolean   create_new)
Packit ae235b
{
Packit ae235b
  if (create_new)
Packit ae235b
    g_ptr_array_add (data->annotations, g_new0 (GDBusAnnotationInfo, 1));
Packit ae235b
  return data->annotations->pdata[data->annotations->len - 1];
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusArgInfo *
Packit ae235b
parse_data_get_arg (ParseData *data,
Packit ae235b
                    gboolean   create_new)
Packit ae235b
{
Packit ae235b
  if (create_new)
Packit ae235b
    g_ptr_array_add (data->args, g_new0 (GDBusArgInfo, 1));
Packit ae235b
  return data->args->pdata[data->args->len - 1];
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusArgInfo *
Packit ae235b
parse_data_get_out_arg (ParseData *data,
Packit ae235b
                        gboolean   create_new)
Packit ae235b
{
Packit ae235b
  if (create_new)
Packit ae235b
    g_ptr_array_add (data->out_args, g_new0 (GDBusArgInfo, 1));
Packit ae235b
  return data->out_args->pdata[data->out_args->len - 1];
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusMethodInfo *
Packit ae235b
parse_data_get_method (ParseData *data,
Packit ae235b
                       gboolean   create_new)
Packit ae235b
{
Packit ae235b
  if (create_new)
Packit ae235b
    g_ptr_array_add (data->methods, g_new0 (GDBusMethodInfo, 1));
Packit ae235b
  return data->methods->pdata[data->methods->len - 1];
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusSignalInfo *
Packit ae235b
parse_data_get_signal (ParseData *data,
Packit ae235b
                       gboolean   create_new)
Packit ae235b
{
Packit ae235b
  if (create_new)
Packit ae235b
    g_ptr_array_add (data->signals, g_new0 (GDBusSignalInfo, 1));
Packit ae235b
  return data->signals->pdata[data->signals->len - 1];
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusPropertyInfo *
Packit ae235b
parse_data_get_property (ParseData *data,
Packit ae235b
                         gboolean   create_new)
Packit ae235b
{
Packit ae235b
  if (create_new)
Packit ae235b
    g_ptr_array_add (data->properties, g_new0 (GDBusPropertyInfo, 1));
Packit ae235b
  return data->properties->pdata[data->properties->len - 1];
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusInterfaceInfo *
Packit ae235b
parse_data_get_interface (ParseData *data,
Packit ae235b
                          gboolean   create_new)
Packit ae235b
{
Packit ae235b
  if (create_new)
Packit ae235b
    g_ptr_array_add (data->interfaces, g_new0 (GDBusInterfaceInfo, 1));
Packit ae235b
  return data->interfaces->pdata[data->interfaces->len - 1];
Packit ae235b
}
Packit ae235b
Packit ae235b
static GDBusNodeInfo *
Packit ae235b
parse_data_get_node (ParseData *data,
Packit ae235b
                     gboolean   create_new)
Packit ae235b
{
Packit ae235b
  if (create_new)
Packit ae235b
    g_ptr_array_add (data->nodes, g_new0 (GDBusNodeInfo, 1));
Packit ae235b
  return data->nodes->pdata[data->nodes->len - 1];
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static ParseData *
Packit ae235b
parse_data_new (void)
Packit ae235b
{
Packit ae235b
  ParseData *data;
Packit ae235b
Packit ae235b
  data = g_new0 (ParseData, 1);
Packit ae235b
Packit ae235b
  /* initialize arrays */
Packit ae235b
  parse_data_steal_annotations (data, NULL);
Packit ae235b
  parse_data_steal_args (data, NULL);
Packit ae235b
  parse_data_steal_out_args (data, NULL);
Packit ae235b
  parse_data_steal_methods (data, NULL);
Packit ae235b
  parse_data_steal_signals (data, NULL);
Packit ae235b
  parse_data_steal_properties (data, NULL);
Packit ae235b
  parse_data_steal_interfaces (data, NULL);
Packit ae235b
  parse_data_steal_nodes (data, NULL);
Packit ae235b
Packit ae235b
  return data;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
parse_data_free (ParseData *data)
Packit ae235b
{
Packit ae235b
  GSList *l;
Packit ae235b
Packit ae235b
  /* free stack of annotation arrays */
Packit ae235b
  for (l = data->annotations_stack; l != NULL; l = l->next)
Packit ae235b
    {
Packit ae235b
      GPtrArray *annotations = l->data;
Packit ae235b
      g_ptr_array_foreach (annotations, (GFunc) g_dbus_annotation_info_unref, NULL);
Packit ae235b
      g_ptr_array_free (annotations, TRUE);
Packit ae235b
    }
Packit ae235b
  g_slist_free (data->annotations_stack);
Packit ae235b
Packit ae235b
  /* free stack of interface arrays */
Packit ae235b
  for (l = data->interfaces_stack; l != NULL; l = l->next)
Packit ae235b
    {
Packit ae235b
      GPtrArray *interfaces = l->data;
Packit ae235b
      g_ptr_array_foreach (interfaces, (GFunc) g_dbus_interface_info_unref, NULL);
Packit ae235b
      g_ptr_array_free (interfaces, TRUE);
Packit ae235b
    }
Packit ae235b
  g_slist_free (data->interfaces_stack);
Packit ae235b
Packit ae235b
  /* free stack of node arrays */
Packit ae235b
  for (l = data->nodes_stack; l != NULL; l = l->next)
Packit ae235b
    {
Packit ae235b
      GPtrArray *nodes = l->data;
Packit ae235b
      g_ptr_array_foreach (nodes, (GFunc) g_dbus_node_info_unref, NULL);
Packit ae235b
      g_ptr_array_free (nodes, TRUE);
Packit ae235b
    }
Packit ae235b
  g_slist_free (data->nodes_stack);
Packit ae235b
Packit ae235b
  /* free arrays (data->annotations, data->interfaces and data->nodes have been freed above) */
Packit ae235b
  parse_data_free_args (data);
Packit ae235b
  parse_data_free_out_args (data);
Packit ae235b
  parse_data_free_methods (data);
Packit ae235b
  parse_data_free_signals (data);
Packit ae235b
  parse_data_free_properties (data);
Packit ae235b
  parse_data_free_interfaces (data);
Packit ae235b
  parse_data_free_annotations (data);
Packit ae235b
  parse_data_free_nodes (data);
Packit ae235b
Packit ae235b
  g_free (data);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
parser_start_element (GMarkupParseContext  *context,
Packit ae235b
                      const gchar          *element_name,
Packit ae235b
                      const gchar         **attribute_names,
Packit ae235b
                      const gchar         **attribute_values,
Packit ae235b
                      gpointer              user_data,
Packit ae235b
                      GError              **error)
Packit ae235b
{
Packit ae235b
  ParseData *data = user_data;
Packit ae235b
  GSList *stack;
Packit ae235b
  const gchar *name;
Packit ae235b
  const gchar *type;
Packit ae235b
  const gchar *access;
Packit ae235b
  const gchar *direction;
Packit ae235b
  const gchar *value;
Packit ae235b
Packit ae235b
  name = NULL;
Packit ae235b
  type = NULL;
Packit ae235b
  access = NULL;
Packit ae235b
  direction = NULL;
Packit ae235b
  value = NULL;
Packit ae235b
Packit ae235b
  stack = (GSList *) g_markup_parse_context_get_element_stack (context);
Packit ae235b
Packit ae235b
  /* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
  if (strcmp (element_name, "node") == 0)
Packit ae235b
    {
Packit ae235b
      if (!(g_slist_length (stack) >= 1 || strcmp (stack->next->data, "node") != 0))
Packit ae235b
        {
Packit ae235b
          g_set_error_literal (error,
Packit ae235b
                               G_MARKUP_ERROR,
Packit ae235b
                               G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                               "<node> elements can only be top-level or embedded in other <node> elements");
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
Packit ae235b
      if (!g_markup_collect_attributes (element_name,
Packit ae235b
                                        attribute_names,
Packit ae235b
                                        attribute_values,
Packit ae235b
                                        error,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "name", &name,
Packit ae235b
                                        /* some hand-written introspection XML documents use this */
Packit ae235b
                                        G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "xmlns:doc", NULL,
Packit ae235b
                                        G_MARKUP_COLLECT_INVALID))
Packit ae235b
        goto out;
Packit ae235b
Packit ae235b
      g_dbus_node_info_set (data,
Packit ae235b
                            parse_data_get_node (data, TRUE),
Packit ae235b
                            name,
Packit ae235b
                            NULL,
Packit ae235b
                            NULL,
Packit ae235b
                            NULL);
Packit ae235b
Packit ae235b
      /* push the currently retrieved interfaces and nodes on the stack and prepare new arrays */
Packit ae235b
      data->interfaces_stack = g_slist_prepend (data->interfaces_stack, data->interfaces);
Packit ae235b
      data->interfaces = NULL;
Packit ae235b
      parse_data_steal_interfaces (data, NULL);
Packit ae235b
Packit ae235b
      data->nodes_stack = g_slist_prepend (data->nodes_stack, data->nodes);
Packit ae235b
      data->nodes = NULL;
Packit ae235b
      parse_data_steal_nodes (data, NULL);
Packit ae235b
Packit ae235b
    }
Packit ae235b
  /* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
  else if (strcmp (element_name, "interface") == 0)
Packit ae235b
    {
Packit ae235b
      if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "node") != 0)
Packit ae235b
        {
Packit ae235b
          g_set_error_literal (error,
Packit ae235b
                               G_MARKUP_ERROR,
Packit ae235b
                               G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                               "<interface> elements can only be embedded in <node> elements");
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
Packit ae235b
      if (!g_markup_collect_attributes (element_name,
Packit ae235b
                                        attribute_names,
Packit ae235b
                                        attribute_values,
Packit ae235b
                                        error,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING, "name", &name,
Packit ae235b
                                        /* seen in the wild */
Packit ae235b
                                        G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "version", NULL,
Packit ae235b
                                        G_MARKUP_COLLECT_INVALID))
Packit ae235b
        goto out;
Packit ae235b
Packit ae235b
      g_dbus_interface_info_set (data,
Packit ae235b
                                 parse_data_get_interface (data, TRUE),
Packit ae235b
                                 name,
Packit ae235b
                                 NULL,
Packit ae235b
                                 NULL,
Packit ae235b
                                 NULL,
Packit ae235b
                                 NULL);
Packit ae235b
Packit ae235b
    }
Packit ae235b
  /* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
  else if (strcmp (element_name, "method") == 0)
Packit ae235b
    {
Packit ae235b
      if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "interface") != 0)
Packit ae235b
        {
Packit ae235b
          g_set_error_literal (error,
Packit ae235b
                               G_MARKUP_ERROR,
Packit ae235b
                               G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                               "<method> elements can only be embedded in <interface> elements");
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
Packit ae235b
      if (!g_markup_collect_attributes (element_name,
Packit ae235b
                                        attribute_names,
Packit ae235b
                                        attribute_values,
Packit ae235b
                                        error,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING, "name", &name,
Packit ae235b
                                        /* seen in the wild */
Packit ae235b
                                        G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "version", NULL,
Packit ae235b
                                        G_MARKUP_COLLECT_INVALID))
Packit ae235b
        goto out;
Packit ae235b
Packit ae235b
      g_dbus_method_info_set (data,
Packit ae235b
                              parse_data_get_method (data, TRUE),
Packit ae235b
                              name,
Packit ae235b
                              NULL,
Packit ae235b
                              NULL,
Packit ae235b
                              NULL);
Packit ae235b
Packit ae235b
      data->num_args = 0;
Packit ae235b
Packit ae235b
    }
Packit ae235b
  /* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
  else if (strcmp (element_name, "signal") == 0)
Packit ae235b
    {
Packit ae235b
      if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "interface") != 0)
Packit ae235b
        {
Packit ae235b
          g_set_error_literal (error,
Packit ae235b
                               G_MARKUP_ERROR,
Packit ae235b
                               G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                               "<signal> elements can only be embedded in <interface> elements");
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
Packit ae235b
      if (!g_markup_collect_attributes (element_name,
Packit ae235b
                                        attribute_names,
Packit ae235b
                                        attribute_values,
Packit ae235b
                                        error,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING, "name", &name,
Packit ae235b
                                        G_MARKUP_COLLECT_INVALID))
Packit ae235b
        goto out;
Packit ae235b
Packit ae235b
      g_dbus_signal_info_set (data,
Packit ae235b
                              parse_data_get_signal (data, TRUE),
Packit ae235b
                              name,
Packit ae235b
                              NULL,
Packit ae235b
                              NULL);
Packit ae235b
Packit ae235b
      data->num_args = 0;
Packit ae235b
Packit ae235b
    }
Packit ae235b
  /* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
  else if (strcmp (element_name, "property") == 0)
Packit ae235b
    {
Packit ae235b
      GDBusPropertyInfoFlags flags;
Packit ae235b
Packit ae235b
      if (g_slist_length (stack) < 2 || strcmp (stack->next->data, "interface") != 0)
Packit ae235b
        {
Packit ae235b
          g_set_error_literal (error,
Packit ae235b
                               G_MARKUP_ERROR,
Packit ae235b
                               G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                               "<property> elements can only be embedded in <interface> elements");
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
Packit ae235b
      if (!g_markup_collect_attributes (element_name,
Packit ae235b
                                        attribute_names,
Packit ae235b
                                        attribute_values,
Packit ae235b
                                        error,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING, "name", &name,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING, "type", &type,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING, "access", &access,
Packit ae235b
                                        G_MARKUP_COLLECT_INVALID))
Packit ae235b
        goto out;
Packit ae235b
Packit ae235b
      if (strcmp (access, "read") == 0)
Packit ae235b
        flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE;
Packit ae235b
      else if (strcmp (access, "write") == 0)
Packit ae235b
        flags = G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE;
Packit ae235b
      else if (strcmp (access, "readwrite") == 0)
Packit ae235b
        flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE;
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          g_set_error (error,
Packit ae235b
                       G_MARKUP_ERROR,
Packit ae235b
                       G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                       "Unknown value '%s' of access attribute for element <property>",
Packit ae235b
                       access);
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
Packit ae235b
      g_dbus_property_info_set (data,
Packit ae235b
                                parse_data_get_property (data, TRUE),
Packit ae235b
                                name,
Packit ae235b
                                type,
Packit ae235b
                                flags,
Packit ae235b
                                NULL);
Packit ae235b
Packit ae235b
    }
Packit ae235b
  /* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
  else if (strcmp (element_name, "arg") == 0)
Packit ae235b
    {
Packit ae235b
      gboolean is_in;
Packit ae235b
      gchar *name_to_use;
Packit ae235b
Packit ae235b
      if (g_slist_length (stack) < 2 ||
Packit ae235b
          (strcmp (stack->next->data, "method") != 0 &&
Packit ae235b
           strcmp (stack->next->data, "signal") != 0))
Packit ae235b
        {
Packit ae235b
          g_set_error_literal (error,
Packit ae235b
                               G_MARKUP_ERROR,
Packit ae235b
                               G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                               "<arg> elements can only be embedded in <method> or <signal> elements");
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
Packit ae235b
      if (!g_markup_collect_attributes (element_name,
Packit ae235b
                                        attribute_names,
Packit ae235b
                                        attribute_values,
Packit ae235b
                                        error,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "name", &name,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "direction", &direction,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING, "type", &type,
Packit ae235b
                                        G_MARKUP_COLLECT_INVALID))
Packit ae235b
        goto out;
Packit ae235b
Packit ae235b
      if (strcmp (stack->next->data, "method") == 0)
Packit ae235b
        is_in = TRUE;
Packit ae235b
      else
Packit ae235b
        is_in = FALSE;
Packit ae235b
      if (direction != NULL)
Packit ae235b
        {
Packit ae235b
          if (strcmp (direction, "in") == 0)
Packit ae235b
            is_in = TRUE;
Packit ae235b
          else if (strcmp (direction, "out") == 0)
Packit ae235b
            is_in = FALSE;
Packit ae235b
          else
Packit ae235b
            {
Packit ae235b
              g_set_error (error,
Packit ae235b
                           G_MARKUP_ERROR,
Packit ae235b
                           G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                           "Unknown value '%s' of direction attribute",
Packit ae235b
                           direction);
Packit ae235b
              goto out;
Packit ae235b
            }
Packit ae235b
        }
Packit ae235b
Packit ae235b
      if (is_in && strcmp (stack->next->data, "signal") == 0)
Packit ae235b
        {
Packit ae235b
          g_set_error_literal (error,
Packit ae235b
                               G_MARKUP_ERROR,
Packit ae235b
                               G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                               "Only direction 'out' is allowed for <arg> elements embedded in <signal>");
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
Packit ae235b
      if (name == NULL)
Packit ae235b
        name_to_use = g_strdup_printf ("arg_%d", data->num_args);
Packit ae235b
      else
Packit ae235b
        name_to_use = g_strdup (name);
Packit ae235b
      data->num_args++;
Packit ae235b
Packit ae235b
      if (is_in)
Packit ae235b
        {
Packit ae235b
          g_dbus_arg_info_set (data,
Packit ae235b
                               parse_data_get_arg (data, TRUE),
Packit ae235b
                               name_to_use,
Packit ae235b
                               type,
Packit ae235b
                               NULL);
Packit ae235b
          data->last_arg_was_in = TRUE;
Packit ae235b
        }
Packit ae235b
      else
Packit ae235b
        {
Packit ae235b
          g_dbus_arg_info_set (data,
Packit ae235b
                               parse_data_get_out_arg (data, TRUE),
Packit ae235b
                               name_to_use,
Packit ae235b
                               type,
Packit ae235b
                               NULL);
Packit ae235b
          data->last_arg_was_in = FALSE;
Packit ae235b
Packit ae235b
        }
Packit ae235b
Packit ae235b
      g_free (name_to_use);
Packit ae235b
    }
Packit ae235b
  /* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
  else if (strcmp (element_name, "annotation") == 0)
Packit ae235b
    {
Packit ae235b
      if (g_slist_length (stack) < 2 ||
Packit ae235b
          (strcmp (stack->next->data, "node") != 0 &&
Packit ae235b
           strcmp (stack->next->data, "interface") != 0 &&
Packit ae235b
           strcmp (stack->next->data, "signal") != 0 &&
Packit ae235b
           strcmp (stack->next->data, "method") != 0 &&
Packit ae235b
           strcmp (stack->next->data, "property") != 0 &&
Packit ae235b
           strcmp (stack->next->data, "arg") != 0 &&
Packit ae235b
           strcmp (stack->next->data, "annotation") != 0))
Packit ae235b
        {
Packit ae235b
          g_set_error_literal (error,
Packit ae235b
                               G_MARKUP_ERROR,
Packit ae235b
                               G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                               "<annotation> elements can only be embedded in <node>, <interface>, <signal>, <method>, <property>, <arg> or <annotation> elements");
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
Packit ae235b
      if (!g_markup_collect_attributes (element_name,
Packit ae235b
                                        attribute_names,
Packit ae235b
                                        attribute_values,
Packit ae235b
                                        error,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING, "name", &name,
Packit ae235b
                                        G_MARKUP_COLLECT_STRING, "value", &value,
Packit ae235b
                                        G_MARKUP_COLLECT_INVALID))
Packit ae235b
        goto out;
Packit ae235b
Packit ae235b
      g_dbus_annotation_info_set (data,
Packit ae235b
                                  parse_data_get_annotation (data, TRUE),
Packit ae235b
                                  name,
Packit ae235b
                                  value,
Packit ae235b
                                  NULL);
Packit ae235b
    }
Packit ae235b
  /* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      /* don't bail on unknown elements; just ignore them */
Packit ae235b
    }
Packit ae235b
  /* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
  /* push the currently retrieved annotations on the stack and prepare a new one */
Packit ae235b
  data->annotations_stack = g_slist_prepend (data->annotations_stack, data->annotations);
Packit ae235b
  data->annotations = NULL;
Packit ae235b
  parse_data_steal_annotations (data, NULL);
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  ;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static GDBusAnnotationInfo **
Packit ae235b
steal_annotations (ParseData *data)
Packit ae235b
{
Packit ae235b
  return parse_data_steal_annotations (data, NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
static void
Packit ae235b
parser_end_element (GMarkupParseContext  *context,
Packit ae235b
                    const gchar          *element_name,
Packit ae235b
                    gpointer              user_data,
Packit ae235b
                    GError              **error)
Packit ae235b
{
Packit ae235b
  ParseData *data = user_data;
Packit ae235b
  gboolean have_popped_annotations;
Packit ae235b
Packit ae235b
  have_popped_annotations = FALSE;
Packit ae235b
Packit ae235b
  if (strcmp (element_name, "node") == 0)
Packit ae235b
    {
Packit ae235b
      guint num_nodes;
Packit ae235b
      guint num_interfaces;
Packit ae235b
      GDBusNodeInfo **nodes;
Packit ae235b
      GDBusInterfaceInfo **interfaces;
Packit ae235b
Packit ae235b
      nodes = parse_data_steal_nodes (data, &num_nodes);
Packit ae235b
      interfaces = parse_data_steal_interfaces (data, &num_interfaces);
Packit ae235b
Packit ae235b
      /* destroy the nodes, interfaces for scope we're exiting and and pop the nodes, interfaces from the
Packit ae235b
       * scope we're reentering
Packit ae235b
       */
Packit ae235b
      parse_data_free_interfaces (data);
Packit ae235b
      data->interfaces = (GPtrArray *) data->interfaces_stack->data;
Packit ae235b
      data->interfaces_stack = g_slist_remove (data->interfaces_stack, data->interfaces_stack->data);
Packit ae235b
Packit ae235b
      parse_data_free_nodes (data);
Packit ae235b
      data->nodes = (GPtrArray *) data->nodes_stack->data;
Packit ae235b
      data->nodes_stack = g_slist_remove (data->nodes_stack, data->nodes_stack->data);
Packit ae235b
Packit ae235b
      g_dbus_node_info_set (data,
Packit ae235b
                            parse_data_get_node (data, FALSE),
Packit ae235b
                            NULL,
Packit ae235b
                            interfaces,
Packit ae235b
                            nodes,
Packit ae235b
                            steal_annotations (data));
Packit ae235b
Packit ae235b
    }
Packit ae235b
  else if (strcmp (element_name, "interface") == 0)
Packit ae235b
    {
Packit ae235b
      guint num_methods;
Packit ae235b
      guint num_signals;
Packit ae235b
      guint num_properties;
Packit ae235b
      GDBusMethodInfo **methods;
Packit ae235b
      GDBusSignalInfo **signals;
Packit ae235b
      GDBusPropertyInfo **properties;
Packit ae235b
Packit ae235b
      methods    = parse_data_steal_methods    (data, &num_methods);
Packit ae235b
      signals    = parse_data_steal_signals    (data, &num_signals);
Packit ae235b
      properties = parse_data_steal_properties (data, &num_properties);
Packit ae235b
Packit ae235b
      g_dbus_interface_info_set (data,
Packit ae235b
                                 parse_data_get_interface (data, FALSE),
Packit ae235b
                                 NULL,
Packit ae235b
                                 methods,
Packit ae235b
                                 signals,
Packit ae235b
                                 properties,
Packit ae235b
                                 steal_annotations (data));
Packit ae235b
Packit ae235b
    }
Packit ae235b
  else if (strcmp (element_name, "method") == 0)
Packit ae235b
    {
Packit ae235b
      guint in_num_args;
Packit ae235b
      guint out_num_args;
Packit ae235b
      GDBusArgInfo **in_args;
Packit ae235b
      GDBusArgInfo **out_args;
Packit ae235b
Packit ae235b
      in_args  = parse_data_steal_args     (data, &in_num_args);
Packit ae235b
      out_args = parse_data_steal_out_args (data, &out_num_args);
Packit ae235b
Packit ae235b
      g_dbus_method_info_set (data,
Packit ae235b
                              parse_data_get_method (data, FALSE),
Packit ae235b
                              NULL,
Packit ae235b
                              in_args,
Packit ae235b
                              out_args,
Packit ae235b
                              steal_annotations (data));
Packit ae235b
    }
Packit ae235b
  else if (strcmp (element_name, "signal") == 0)
Packit ae235b
    {
Packit ae235b
      guint num_args;
Packit ae235b
      GDBusArgInfo **args;
Packit ae235b
Packit ae235b
      args = parse_data_steal_out_args (data, &num_args);
Packit ae235b
Packit ae235b
      g_dbus_signal_info_set (data,
Packit ae235b
                              parse_data_get_signal (data, FALSE),
Packit ae235b
                              NULL,
Packit ae235b
                              args,
Packit ae235b
                              steal_annotations (data));
Packit ae235b
    }
Packit ae235b
  else if (strcmp (element_name, "property") == 0)
Packit ae235b
    {
Packit ae235b
      g_dbus_property_info_set (data,
Packit ae235b
                                parse_data_get_property (data, FALSE),
Packit ae235b
                                NULL,
Packit ae235b
                                NULL,
Packit ae235b
                                G_DBUS_PROPERTY_INFO_FLAGS_NONE,
Packit ae235b
                                steal_annotations (data));
Packit ae235b
    }
Packit ae235b
  else if (strcmp (element_name, "arg") == 0)
Packit ae235b
    {
Packit ae235b
      g_dbus_arg_info_set (data,
Packit ae235b
                           data->last_arg_was_in ? parse_data_get_arg (data, FALSE) : parse_data_get_out_arg (data, FALSE),
Packit ae235b
                           NULL,
Packit ae235b
                           NULL,
Packit ae235b
                           steal_annotations (data));
Packit ae235b
    }
Packit ae235b
  else if (strcmp (element_name, "annotation") == 0)
Packit ae235b
    {
Packit ae235b
      GDBusAnnotationInfo **embedded_annotations;
Packit ae235b
Packit ae235b
      embedded_annotations = steal_annotations (data);
Packit ae235b
Packit ae235b
      /* destroy the annotations for scope we're exiting and and pop the annotations from the scope we're reentering */
Packit ae235b
      parse_data_free_annotations (data);
Packit ae235b
      data->annotations = (GPtrArray *) data->annotations_stack->data;
Packit ae235b
      data->annotations_stack = g_slist_remove (data->annotations_stack, data->annotations_stack->data);
Packit ae235b
Packit ae235b
      have_popped_annotations = TRUE;
Packit ae235b
Packit ae235b
      g_dbus_annotation_info_set (data,
Packit ae235b
                                  parse_data_get_annotation (data, FALSE),
Packit ae235b
                                  NULL,
Packit ae235b
                                  NULL,
Packit ae235b
                                  embedded_annotations);
Packit ae235b
    }
Packit ae235b
  else
Packit ae235b
    {
Packit ae235b
      /* don't bail on unknown elements; just ignore them */
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (!have_popped_annotations)
Packit ae235b
    {
Packit ae235b
      /* destroy the annotations for scope we're exiting and and pop the annotations from the scope we're reentering */
Packit ae235b
      parse_data_free_annotations (data);
Packit ae235b
      data->annotations = (GPtrArray *) data->annotations_stack->data;
Packit ae235b
      data->annotations_stack = g_slist_remove (data->annotations_stack, data->annotations_stack->data);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
static void
Packit ae235b
parser_error (GMarkupParseContext *context,
Packit ae235b
              GError              *error,
Packit ae235b
              gpointer             user_data)
Packit ae235b
{
Packit ae235b
  gint line_number;
Packit ae235b
  gint char_number;
Packit ae235b
Packit ae235b
  g_markup_parse_context_get_position (context, &line_number, &char_number);
Packit ae235b
Packit ae235b
  g_prefix_error (&error, "%d:%d: ",
Packit ae235b
                  line_number,
Packit ae235b
                  char_number);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_node_info_new_for_xml:
Packit ae235b
 * @xml_data: Valid D-Bus introspection XML.
Packit ae235b
 * @error: Return location for error.
Packit ae235b
 *
Packit ae235b
 * Parses @xml_data and returns a #GDBusNodeInfo representing the data.
Packit ae235b
 *
Packit ae235b
 * The introspection XML must contain exactly one top-level
Packit ae235b
 * <node> element.
Packit ae235b
 *
Packit ae235b
 * Note that this routine is using a
Packit ae235b
 * [GMarkup][glib-Simple-XML-Subset-Parser.description]-based
Packit ae235b
 * parser that only accepts a subset of valid XML documents.
Packit ae235b
 *
Packit ae235b
 * Returns: A #GDBusNodeInfo structure or %NULL if @error is set. Free
Packit ae235b
 * with g_dbus_node_info_unref().
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusNodeInfo *
Packit ae235b
g_dbus_node_info_new_for_xml (const gchar  *xml_data,
Packit ae235b
                              GError      **error)
Packit ae235b
{
Packit ae235b
  GDBusNodeInfo *ret;
Packit ae235b
  GMarkupParseContext *context;
Packit ae235b
  GMarkupParser *parser;
Packit ae235b
  guint num_nodes;
Packit ae235b
  ParseData *data;
Packit ae235b
  GDBusNodeInfo **ughret;
Packit ae235b
Packit ae235b
  ret = NULL;
Packit ae235b
  parser = NULL;
Packit ae235b
  context = NULL;
Packit ae235b
Packit ae235b
  parser = g_new0 (GMarkupParser, 1);
Packit ae235b
  parser->start_element = parser_start_element;
Packit ae235b
  parser->end_element   = parser_end_element;
Packit ae235b
  parser->error         = parser_error;
Packit ae235b
Packit ae235b
  data = parse_data_new ();
Packit ae235b
  context = g_markup_parse_context_new (parser,
Packit ae235b
                                        G_MARKUP_IGNORE_QUALIFIED,
Packit ae235b
                                        data,
Packit ae235b
                                        (GDestroyNotify) parse_data_free);
Packit ae235b
Packit ae235b
  if (!g_markup_parse_context_parse (context,
Packit ae235b
                                     xml_data,
Packit ae235b
                                     strlen (xml_data),
Packit ae235b
                                     error))
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  if (!g_markup_parse_context_end_parse (context, error))
Packit ae235b
    goto out;
Packit ae235b
Packit ae235b
  ughret = parse_data_steal_nodes (data, &num_nodes);
Packit ae235b
Packit ae235b
  if (num_nodes != 1)
Packit ae235b
    {
Packit ae235b
      guint n;
Packit ae235b
Packit ae235b
      g_set_error (error,
Packit ae235b
                   G_MARKUP_ERROR,
Packit ae235b
                   G_MARKUP_ERROR_INVALID_CONTENT,
Packit ae235b
                   "Expected a single node in introspection XML, found %d",
Packit ae235b
                   num_nodes);
Packit ae235b
Packit ae235b
      /* clean up */
Packit ae235b
      for (n = 0; n < num_nodes; n++)
Packit ae235b
        {
Packit ae235b
          g_dbus_node_info_unref (ughret[n]);
Packit ae235b
          ughret[n] = NULL;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  ret = ughret[0];
Packit ae235b
  g_free (ughret);
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  g_free (parser);
Packit ae235b
  if (context != NULL)
Packit ae235b
    g_markup_parse_context_free (context);
Packit ae235b
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_annotation_info_lookup:
Packit ae235b
 * @annotations: (array zero-terminated=1) (nullable): A %NULL-terminated array of annotations or %NULL.
Packit ae235b
 * @name: The name of the annotation to look up.
Packit ae235b
 *
Packit ae235b
 * Looks up the value of an annotation.
Packit ae235b
 *
Packit ae235b
 * The cost of this function is O(n) in number of annotations.
Packit ae235b
 *
Packit ae235b
 * Returns: The value or %NULL if not found. Do not free, it is owned by @annotations.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dbus_annotation_info_lookup (GDBusAnnotationInfo **annotations,
Packit ae235b
                               const gchar          *name)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
  const gchar *ret;
Packit ae235b
Packit ae235b
  ret = NULL;
Packit ae235b
  for (n = 0; annotations != NULL && annotations[n] != NULL; n++)
Packit ae235b
    {
Packit ae235b
      if (g_strcmp0 (annotations[n]->key, name) == 0)
Packit ae235b
        {
Packit ae235b
          ret = annotations[n]->value;
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  return ret;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
G_LOCK_DEFINE_STATIC (info_cache_lock);
Packit ae235b
Packit ae235b
typedef struct
Packit ae235b
{
Packit ae235b
  gint use_count;
Packit ae235b
Packit ae235b
  /* gchar* -> GDBusMethodInfo* */
Packit ae235b
  GHashTable *method_name_to_data;
Packit ae235b
Packit ae235b
  /* gchar* -> GDBusMethodInfo* */
Packit ae235b
  GHashTable *signal_name_to_data;
Packit ae235b
Packit ae235b
  /* gchar* -> GDBusMethodInfo* */
Packit ae235b
  GHashTable *property_name_to_data;
Packit ae235b
} InfoCacheEntry;
Packit ae235b
Packit ae235b
static void
Packit ae235b
info_cache_free (InfoCacheEntry *cache)
Packit ae235b
{
Packit ae235b
  g_assert (cache->use_count == 0);
Packit ae235b
  g_hash_table_unref (cache->method_name_to_data);
Packit ae235b
  g_hash_table_unref (cache->signal_name_to_data);
Packit ae235b
  g_hash_table_unref (cache->property_name_to_data);
Packit ae235b
  g_slice_free (InfoCacheEntry, cache);
Packit ae235b
}
Packit ae235b
Packit ae235b
/* maps from GDBusInterfaceInfo* to InfoCacheEntry* */
Packit ae235b
static GHashTable *info_cache = NULL;
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_info_lookup_method:
Packit ae235b
 * @info: A #GDBusInterfaceInfo.
Packit ae235b
 * @name: A D-Bus method name (typically in CamelCase)
Packit ae235b
 *
Packit ae235b
 * Looks up information about a method.
Packit ae235b
 *
Packit ae235b
 * The cost of this function is O(n) in number of methods unless
Packit ae235b
 * g_dbus_interface_info_cache_build() has been used on @info.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): A #GDBusMethodInfo or %NULL if not found. Do not free, it is owned by @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusMethodInfo *
Packit ae235b
g_dbus_interface_info_lookup_method (GDBusInterfaceInfo *info,
Packit ae235b
                                     const gchar        *name)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
  GDBusMethodInfo *result;
Packit ae235b
Packit ae235b
  G_LOCK (info_cache_lock);
Packit ae235b
  if (G_LIKELY (info_cache != NULL))
Packit ae235b
    {
Packit ae235b
      InfoCacheEntry *cache;
Packit ae235b
      cache = g_hash_table_lookup (info_cache, info);
Packit ae235b
      if (G_LIKELY (cache != NULL))
Packit ae235b
        {
Packit ae235b
          result = g_hash_table_lookup (cache->method_name_to_data, name);
Packit ae235b
          G_UNLOCK (info_cache_lock);
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
  G_UNLOCK (info_cache_lock);
Packit ae235b
Packit ae235b
  for (n = 0; info->methods != NULL && info->methods[n] != NULL; n++)
Packit ae235b
    {
Packit ae235b
      GDBusMethodInfo *i = info->methods[n];
Packit ae235b
Packit ae235b
      if (g_strcmp0 (i->name, name) == 0)
Packit ae235b
        {
Packit ae235b
          result = i;
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  result = NULL;
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  return result;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_info_lookup_signal:
Packit ae235b
 * @info: A #GDBusInterfaceInfo.
Packit ae235b
 * @name: A D-Bus signal name (typically in CamelCase)
Packit ae235b
 *
Packit ae235b
 * Looks up information about a signal.
Packit ae235b
 *
Packit ae235b
 * The cost of this function is O(n) in number of signals unless
Packit ae235b
 * g_dbus_interface_info_cache_build() has been used on @info.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): A #GDBusSignalInfo or %NULL if not found. Do not free, it is owned by @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusSignalInfo *
Packit ae235b
g_dbus_interface_info_lookup_signal (GDBusInterfaceInfo *info,
Packit ae235b
                                     const gchar        *name)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
  GDBusSignalInfo *result;
Packit ae235b
Packit ae235b
  G_LOCK (info_cache_lock);
Packit ae235b
  if (G_LIKELY (info_cache != NULL))
Packit ae235b
    {
Packit ae235b
      InfoCacheEntry *cache;
Packit ae235b
      cache = g_hash_table_lookup (info_cache, info);
Packit ae235b
      if (G_LIKELY (cache != NULL))
Packit ae235b
        {
Packit ae235b
          result = g_hash_table_lookup (cache->signal_name_to_data, name);
Packit ae235b
          G_UNLOCK (info_cache_lock);
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
  G_UNLOCK (info_cache_lock);
Packit ae235b
Packit ae235b
  for (n = 0; info->signals != NULL && info->signals[n] != NULL; n++)
Packit ae235b
    {
Packit ae235b
      GDBusSignalInfo *i = info->signals[n];
Packit ae235b
Packit ae235b
      if (g_strcmp0 (i->name, name) == 0)
Packit ae235b
        {
Packit ae235b
          result = i;
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  result = NULL;
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  return result;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_info_lookup_property:
Packit ae235b
 * @info: A #GDBusInterfaceInfo.
Packit ae235b
 * @name: A D-Bus property name (typically in CamelCase).
Packit ae235b
 *
Packit ae235b
 * Looks up information about a property.
Packit ae235b
 *
Packit ae235b
 * The cost of this function is O(n) in number of properties unless
Packit ae235b
 * g_dbus_interface_info_cache_build() has been used on @info.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): A #GDBusPropertyInfo or %NULL if not found. Do not free, it is owned by @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusPropertyInfo *
Packit ae235b
g_dbus_interface_info_lookup_property (GDBusInterfaceInfo *info,
Packit ae235b
                                       const gchar        *name)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
  GDBusPropertyInfo *result;
Packit ae235b
Packit ae235b
  G_LOCK (info_cache_lock);
Packit ae235b
  if (G_LIKELY (info_cache != NULL))
Packit ae235b
    {
Packit ae235b
      InfoCacheEntry *cache;
Packit ae235b
      cache = g_hash_table_lookup (info_cache, info);
Packit ae235b
      if (G_LIKELY (cache != NULL))
Packit ae235b
        {
Packit ae235b
          result = g_hash_table_lookup (cache->property_name_to_data, name);
Packit ae235b
          G_UNLOCK (info_cache_lock);
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
  G_UNLOCK (info_cache_lock);
Packit ae235b
Packit ae235b
  for (n = 0; info->properties != NULL && info->properties[n] != NULL; n++)
Packit ae235b
    {
Packit ae235b
      GDBusPropertyInfo *i = info->properties[n];
Packit ae235b
Packit ae235b
      if (g_strcmp0 (i->name, name) == 0)
Packit ae235b
        {
Packit ae235b
          result = i;
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  result = NULL;
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  return result;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_info_cache_build:
Packit ae235b
 * @info: A #GDBusInterfaceInfo.
Packit ae235b
 *
Packit ae235b
 * Builds a lookup-cache to speed up
Packit ae235b
 * g_dbus_interface_info_lookup_method(),
Packit ae235b
 * g_dbus_interface_info_lookup_signal() and
Packit ae235b
 * g_dbus_interface_info_lookup_property().
Packit ae235b
 *
Packit ae235b
 * If this has already been called with @info, the existing cache is
Packit ae235b
 * used and its use count is increased.
Packit ae235b
 *
Packit ae235b
 * Note that @info cannot be modified until
Packit ae235b
 * g_dbus_interface_info_cache_release() is called.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_interface_info_cache_build (GDBusInterfaceInfo *info)
Packit ae235b
{
Packit ae235b
  InfoCacheEntry *cache;
Packit ae235b
  guint n;
Packit ae235b
Packit ae235b
  G_LOCK (info_cache_lock);
Packit ae235b
  if (info_cache == NULL)
Packit ae235b
    info_cache = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) info_cache_free);
Packit ae235b
  cache = g_hash_table_lookup (info_cache, info);
Packit ae235b
  if (cache != NULL)
Packit ae235b
    {
Packit ae235b
      cache->use_count += 1;
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
  cache = g_slice_new0 (InfoCacheEntry);
Packit ae235b
  cache->use_count = 1;
Packit ae235b
  cache->method_name_to_data = g_hash_table_new (g_str_hash, g_str_equal);
Packit ae235b
  cache->signal_name_to_data = g_hash_table_new (g_str_hash, g_str_equal);
Packit ae235b
  cache->property_name_to_data = g_hash_table_new (g_str_hash, g_str_equal);
Packit ae235b
  for (n = 0; info->methods != NULL && info->methods[n] != NULL; n++)
Packit ae235b
    g_hash_table_insert (cache->method_name_to_data, info->methods[n]->name, info->methods[n]);
Packit ae235b
  for (n = 0; info->signals != NULL && info->signals[n] != NULL; n++)
Packit ae235b
    g_hash_table_insert (cache->signal_name_to_data, info->signals[n]->name, info->signals[n]);
Packit ae235b
  for (n = 0; info->properties != NULL && info->properties[n] != NULL; n++)
Packit ae235b
    g_hash_table_insert (cache->property_name_to_data, info->properties[n]->name, info->properties[n]);
Packit ae235b
  g_hash_table_insert (info_cache, info, cache);
Packit ae235b
 out:
Packit ae235b
  G_UNLOCK (info_cache_lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_interface_info_cache_release:
Packit ae235b
 * @info: A GDBusInterfaceInfo
Packit ae235b
 *
Packit ae235b
 * Decrements the usage count for the cache for @info built by
Packit ae235b
 * g_dbus_interface_info_cache_build() (if any) and frees the
Packit ae235b
 * resources used by the cache if the usage count drops to zero.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_dbus_interface_info_cache_release (GDBusInterfaceInfo *info)
Packit ae235b
{
Packit ae235b
  InfoCacheEntry *cache;
Packit ae235b
Packit ae235b
  G_LOCK (info_cache_lock);
Packit ae235b
  if (G_UNLIKELY (info_cache == NULL))
Packit ae235b
    {
Packit ae235b
      g_warning ("%s called for interface %s but there is no cache", info->name, G_STRFUNC);
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  cache = g_hash_table_lookup (info_cache, info);
Packit ae235b
  if (G_UNLIKELY (cache == NULL))
Packit ae235b
    {
Packit ae235b
      g_warning ("%s called for interface %s but there is no cache entry", info->name, G_STRFUNC);
Packit ae235b
      goto out;
Packit ae235b
    }
Packit ae235b
  cache->use_count -= 1;
Packit ae235b
  if (cache->use_count == 0)
Packit ae235b
    {
Packit ae235b
      g_hash_table_remove (info_cache, info);
Packit ae235b
      /* could nuke info_cache itself if empty */
Packit ae235b
    }
Packit ae235b
 out:
Packit ae235b
  G_UNLOCK (info_cache_lock);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/* ---------------------------------------------------------------------------------------------------- */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dbus_node_info_lookup_interface:
Packit ae235b
 * @info: A #GDBusNodeInfo.
Packit ae235b
 * @name: A D-Bus interface name.
Packit ae235b
 *
Packit ae235b
 * Looks up information about an interface.
Packit ae235b
 *
Packit ae235b
 * The cost of this function is O(n) in number of interfaces.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): A #GDBusInterfaceInfo or %NULL if not found. Do not free, it is owned by @info.
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
GDBusInterfaceInfo *
Packit ae235b
g_dbus_node_info_lookup_interface (GDBusNodeInfo *info,
Packit ae235b
                                   const gchar   *name)
Packit ae235b
{
Packit ae235b
  guint n;
Packit ae235b
  GDBusInterfaceInfo *result;
Packit ae235b
Packit ae235b
  for (n = 0; info->interfaces != NULL && info->interfaces[n] != NULL; n++)
Packit ae235b
    {
Packit ae235b
      GDBusInterfaceInfo *i = info->interfaces[n];
Packit ae235b
Packit ae235b
      if (g_strcmp0 (i->name, name) == 0)
Packit ae235b
        {
Packit ae235b
          result = i;
Packit ae235b
          goto out;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  result = NULL;
Packit ae235b
Packit ae235b
 out:
Packit ae235b
  return result;
Packit ae235b
}