dbus/dbus dbus-test.h, 1.31, 1.32 dbus-test.c, 1.41, 1.42 dbus-signature.h, NONE, 1.1 dbus-signature.c, NONE, 1.1 dbus-protocol.h, 1.40, 1.41 dbus-message.c, 1.164, 1.165 dbus-marshal-validate.c, 1.18, 1.19 dbus-marshal-recursive.h, 1.28, 1.29 dbus-marshal-recursive.c, 1.47, 1.48 dbus-marshal-recursive-util.c, 1.7, 1.8 dbus-marshal-basic.h, 1.19, 1.20 dbus-marshal-basic.c, 1.24, 1.25 Makefile.am, 1.66, 1.67

Colin Walters walters at freedesktop.org
Thu Feb 24 08:03:58 PST 2005


Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv1546/dbus

Modified Files:
	dbus-test.h dbus-test.c dbus-protocol.h dbus-message.c 
	dbus-marshal-validate.c dbus-marshal-recursive.h 
	dbus-marshal-recursive.c dbus-marshal-recursive-util.c 
	dbus-marshal-basic.h dbus-marshal-basic.c Makefile.am 
Added Files:
	dbus-signature.h dbus-signature.c 
Log Message:
2005-02-24  Colin Walters  <walters at verbum.org>
	
	* dbus/dbus-signature.c: New file; implements various functions
	related to type signatures.  Includes an interator for parsing,
	validation functions.
	(dbus_type_is_basic): Moved here from
	dbus-marshal-basic.c:_dbus_type_is_basic.
	(dbus_type_is_container): Moved here from
	dbus-marshal-basic.c:_dbus_type_is_container.

	All callers of _dbus_type_is_container and _dbus_type_is_basic
	updated, and include dbus-signature.h.

	* dbus/dbus-signature.h: New file; prototypes for the above.

	* dbus/Makefile.am (DBUS_LIB_SOURCES): Add dbus-signature.c,
	dbus-signature.h.

	* dbus/dbus-marshal-basic.c (map_type_char_to_type): New utility
	function factored out of _dbus_first_type_in_signature.
	(_dbus_first_type_in_signature_c_str): New function; returns first
	type code for a type signature character.

	* dbus/dbus-marshal-basic.h: Prototype _dbus_first_type_in_signature_c_str,
	handle function moves.

	* dbus/dbus-marshal-recursive.h: Export _dbus_type_signature_next.

	* dbus/dbus-marshal-recursive.c (_dbus_type_signature_next): New
	function; skips to next complete type in type signature.
	Implemented using previous skip_one_complete_type.  Now
	skip_one_complete_type just delegates to
	_dbus_type_signature_next.

	* dbus/dbus-marshal-basic.c (_dbus_type_is_basic): Moved
	to dbus-signature.c
	(_dbus_type_is_container): Ditto.

	* doc/dbus-specification.xml: Update introspection sample to
	use real type signatures.

	* dbus/dbus-test.h: Prototype signature test.

	* dbus/dbus-test.c (dbus_internal_do_not_use_run_tests): Run
	signature tests.

	* dbus/dbus-protocol.h (DBUS_ERROR_INVALID_SIGNATURE): New error.


Index: dbus-test.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-test.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- dbus-test.h	21 Feb 2005 19:38:06 -0000	1.31
+++ dbus-test.h	24 Feb 2005 16:03:56 -0000	1.32
@@ -36,6 +36,7 @@
 dbus_bool_t _dbus_marshal_byteswap_test  (void);
 dbus_bool_t _dbus_marshal_header_test    (void);
 dbus_bool_t _dbus_marshal_validate_test  (void);
+dbus_bool_t _dbus_signature_test         (void);
 dbus_bool_t _dbus_mem_pool_test          (void);
 dbus_bool_t _dbus_string_test            (void);
 dbus_bool_t _dbus_address_test           (void);

Index: dbus-test.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-test.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- dbus-test.c	21 Feb 2005 19:38:06 -0000	1.41
+++ dbus-test.c	24 Feb 2005 16:03:56 -0000	1.42
@@ -121,6 +121,8 @@
   run_test ("server", specific_test, _dbus_server_test);
 
   run_test ("object-tree", specific_test, _dbus_object_tree_test);
+
+  run_test ("signature", specific_test, _dbus_signature_test);
   
   run_test ("marshalling", specific_test, _dbus_marshal_test);
 

--- NEW FILE: dbus-signature.h ---
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-signatures.h utility functions for D-BUS types
 *
 * Copyright (C) 2005 Red Hat Inc.
 *
 * Licensed under the Academic Free License version 2.1
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
#endif

#ifndef DBUS_SIGNATURES_H
#define DBUS_SIGNATURES_H

#include <dbus/dbus-macros.h>
#include <dbus/dbus-types.h>
#include <dbus/dbus-errors.h>

DBUS_BEGIN_DECLS

/**
 * DBusSignatureIter struct; contains no public fields 
 */
typedef struct
{ 
  void *dummy1;         /**< Don't use this */
  void *dummy2;         /**< Don't use this */
  dbus_uint32_t dummy8; /**< Don't use this */
  int dummy12;           /**< Don't use this */
  int dummy17;           /**< Don't use this */
} DBusSignatureIter;

void            dbus_signature_iter_init             (DBusSignatureIter       *iter,
						      const char              *signature);

int             dbus_signature_iter_get_current_type (const DBusSignatureIter *iter);

int             dbus_signature_iter_get_element_type (const DBusSignatureIter *iter);

dbus_bool_t     dbus_signature_iter_next             (DBusSignatureIter       *iter);

void            dbus_signature_iter_recurse          (const DBusSignatureIter *iter,
						      DBusSignatureIter       *subiter);

dbus_bool_t     dbus_signature_validate              (const char       *signature,
						      DBusError        *error);

dbus_bool_t     dbus_signature_validate_single       (const char       *signature,
						      DBusError        *error);

dbus_bool_t     dbus_type_is_basic                   (int            typecode);
dbus_bool_t     dbus_type_is_container               (int            typecode);

DBUS_END_DECLS

#endif /* DBUS_MESSAGE_H */

--- NEW FILE: dbus-signature.c ---
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-signature.c  Routines for reading recursive type signatures
 *
 * Copyright (C) 2005 Red Hat, Inc.
 *
 * Licensed under the Academic Free License version 2.1
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include "dbus-signature.h"
#include "dbus-marshal-recursive.h"
#include "dbus-marshal-basic.h"
#include "dbus-internals.h"
#include "dbus-test.h"

typedef struct
{ 
  const char *pos;
  unsigned int finished : 1;
  unsigned int in_array : 1;
} DBusSignatureRealIter;

/**
 * @addtogroup DBusSignature
 * @{
 */

/**
 * Initializes a #DBusSignatureIter for reading a type signature.  This
 * function is not safe to use on invalid signatures; be sure to
 * validate potentially invalid signatures with dbus_signature_validate
 * before using this function.
 *
 * @param iter pointer to an iterator to initialize
 * @param signature the type signature
 */
void
dbus_signature_iter_init (DBusSignatureIter *iter,
			  const char        *signature)
{
  DBusSignatureRealIter *real_iter = (DBusSignatureRealIter *) iter;

  real_iter->pos = signature;
  real_iter->finished = FALSE;
  real_iter->in_array = FALSE;
}

/**
 * Returns the current type pointed to by the iterator.
 * If the iterator is pointing at a type code such as 's', then
 * it will be returned directly.
 *
 * However, when the parser encounters a container type start
 * character such as '(' for a structure, the corresponding type for
 * the container will be returned, e.g.  DBUS_TYPE_STRUCT, not '('.
 * In this case, you should initialize a sub-iterator with
 * dbus_signature_iter_recurse to parse the container type.
 *
 * @param iter pointer to an iterator 
 * @returns current type (e.g. DBUS_TYPE_STRING, DBUS_TYPE_ARRAY)
 */
int
dbus_signature_iter_get_current_type (const DBusSignatureIter *iter)
{
  DBusSignatureRealIter *real_iter = (DBusSignatureRealIter *) iter;

  return _dbus_first_type_in_signature_c_str (real_iter->pos, 0);
}

/**
 * Convenience function for returning the element type of an array;
 * This function allows you to avoid initializing a sub-iterator and
 * getting its current type.
 *
 * It is an error to invoke this function if the current type of the
 * iterator is not DBUS_TYPE_ARRAY.
 *
 * @param iter pointer to an iterator 
 * @returns current array element type
 */
int
dbus_signature_iter_get_element_type (const DBusSignatureIter *iter)
{
  DBusSignatureRealIter *real_iter = (DBusSignatureRealIter *) iter;

  _dbus_retur(dbus_signature_iter_get_current_type (iter) == DBUS_TYPE_ARRAY);

  return _dbus_first_type_in_signature_c_str (real_iter->pos, 1);
}

/**
 * Skip to the next value on this "level". e.g. the next field in a
 * struct, the next value in an array. Returns FALSE at the end of the
 * current container.
 *
 * @param iter the iterator
 * @returns FALSE if nothing more to read at or below this level
 */
dbus_bool_t
dbus_signature_iter_next (DBusSignatureIter *iter)
{
  DBusSignatureRealIter *real_iter = (DBusSignatureRealIter *) iter;

  if (real_iter->finished)
    return FALSE;
  else
    {
      int pos;

      if (real_iter->in_array)
	{
	  real_iter->finished = TRUE;
	  return FALSE;
	}

      pos = 0;
      _dbus_type_signature_next (real_iter->pos, &pos);
      real_iter->pos += pos;

      if (*real_iter->pos == DBUS_STRUCT_END_CHAR
	  || *real_iter->pos == DBUS_DICT_ENTRY_END_CHAR)
	{
	  real_iter->finished = TRUE;
	  return FALSE;
	}

      return *real_iter->pos != DBUS_TYPE_INVALID;
    }
}

/**
 * Initialize a new iterator pointing to the first type current
 * container. It's an error to call this if the current type is a
 * non-container (i.e. if dbus_type_is_container returns FALSE).
 *
 * @param iter the current interator
 * @param subiter an iterator to initialize pointing to the first child
 */
void
dbus_signature_iter_recurse (const DBusSignatureIter *iter,
			     DBusSignatureIter       *subiter)
{
  DBusSignatureRealIter *real_iter = (DBusSignatureRealIter *) iter;
  DBusSignatureRealIter *real_sub_iter = (DBusSignatureRealIter *) subiter;

  _dbus_return_if_fail (dbus_type_is_container (dbus_signature_iter_get_current_type (iter)));

  *real_sub_iter = *real_iter;
  real_sub_iter->pos++;

  if (dbus_signature_iter_get_current_type (subiter) == DBUS_TYPE_ARRAY)
    real_sub_iter->in_array = TRUE;
}

/**
 * Check a type signature for validity.
 *
 * @param signature a potentially invalid type signature
 * @error error return
 * @returns TRUE iif signature is valid
 */
dbus_bool_t
dbus_signature_validate (const char       *signature,
			 DBusError        *error)
			 
{
  DBusString str;

  _dbus_string_init_const (&str, signature);
  if (_dbus_validate_signature (&str, 0, _dbus_string_get_length (&str)))
    return TRUE;
  dbus_set_error (error, DBUS_ERROR_INVALID_SIGNATURE, "Corrupt type signature");
  return FALSE;
}

/**
 * Check that a type signature is both valid and contains exactly
 * one complete type.
 *
 * @param signature a potentially invalid type signature
 * @error error return
 * @returns TRUE iif signature is valid and has exactly one complete type
 */
dbus_bool_t
dbus_signature_validate_single (const char       *signature,
				DBusError        *error)
{
  DBusSignatureIter iter;

  if (!dbus_signature_validate (signature, error))
    return FALSE;

  dbus_signature_iter_init (&iter, signature);
  if (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_INVALID)
    goto lose;
  if (!dbus_signature_iter_next (&iter))
    return TRUE;
 lose:
  dbus_set_error (error, DBUS_ERROR_INVALID_SIGNATURE, "Exactly one complete type required in signature");
  return FALSE;
}

/** macro that checks whether a typecode is a container type */
#define TYPE_IS_CONTAINER(typecode)             \
    ((typecode) == DBUS_TYPE_STRUCT ||          \
     (typecode) == DBUS_TYPE_DICT_ENTRY ||      \
     (typecode) == DBUS_TYPE_VARIANT ||         \
     (typecode) == DBUS_TYPE_ARRAY)

/**
 * A "container type" can contain basic types, or nested
 * container types. #DBUS_TYPE_INVALID is not a container type.
 * This function will crash if passed a typecode that isn't
 * in dbus-protocol.h
 *
 * @returns #TRUE if type is a container
 */
dbus_bool_t
dbus_type_is_container (int typecode)
{
  /* only reasonable (non-line-noise) typecodes are allowed */
  _dbus_return_val_if_fail (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID,
			    FALSE);
  return TYPE_IS_CONTAINER (typecode);
}

/**
 * A "basic type" is a somewhat arbitrary concept, but the intent
 * is to include those types that are fully-specified by a single
 * typecode, with no additional type information or nested
 * values. So all numbers and strings are basic types and
 * structs, arrays, and variants are not basic types.
 * #DBUS_TYPE_INVALID is not a basic type.
 *
 * This function will crash if passed a typecode that isn't
 * in dbus-protocol.h
 *
 * @returns #TRUE if type is basic
 */
dbus_bool_t
dbus_type_is_basic (int typecode)
{
  /* only reasonable (non-line-noise) typecodes are allowed */
  _dbus_return_val_if_fail (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID,
			    FALSE);

  /* everything that isn't invalid or a container */
  return !(typecode == DBUS_TYPE_INVALID || TYPE_IS_CONTAINER (typecode));
}


#ifdef DBUS_BUILD_TESTS

/**
 * @ingroup DBusSignatureInternals
 * Unit test for DBusSignature.
 *
 * @returns #TRUE on success.
 */
dbus_bool_t
_dbus_signature_test (void)
{
  DBusSignatureIter iter;
  DBusSignatureIter subiter;
  DBusSignatureIter subsubiter;
  DBusSignatureIter subsubsubiter;
  const char *sig;

  _dbus_assert (sizeof (DBusSignatureIter) >= sizeof (DBusSignatureRealIter));

  sig = "";
  _dbus_assert (dbus_signature_validate (sig, NULL));
  _dbus_assert (!dbus_signature_validate_single (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_INVALID);

  sig = DBUS_TYPE_STRING_AS_STRING;
  _dbus_assert (dbus_signature_validate (sig, NULL));
  _dbus_assert (dbus_signature_validate_single (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRING);

  sig = DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
  _dbus_assert (dbus_signature_validate (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRING);
  _dbus_assert (dbus_signature_iter_next (&iter));
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_BYTE);

  sig = DBUS_TYPE_UINT16_AS_STRING
    DBUS_STRUCT_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_STRING_AS_STRING
    DBUS_TYPE_UINT32_AS_STRING
    DBUS_TYPE_VARIANT_AS_STRING
    DBUS_TYPE_DOUBLE_AS_STRING
    DBUS_STRUCT_END_CHAR_AS_STRING;
  _dbus_assert (dbus_signature_validate (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_UINT16);
  _dbus_assert (dbus_signature_iter_next (&iter));
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRUCT);
  dbus_signature_iter_recurse (&iter, &subiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_STRING);
  _dbus_assert (dbus_signature_iter_next (&subiter));
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_UINT32);
  _dbus_assert (dbus_signature_iter_next (&subiter));
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_VARIANT);
  _dbus_assert (dbus_signature_iter_next (&subiter));
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_DOUBLE);

  sig = DBUS_TYPE_UINT16_AS_STRING
    DBUS_STRUCT_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_UINT32_AS_STRING
    DBUS_TYPE_BYTE_AS_STRING
    DBUS_TYPE_ARRAY_AS_STRING
    DBUS_TYPE_ARRAY_AS_STRING
    DBUS_TYPE_DOUBLE_AS_STRING
    DBUS_STRUCT_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_BYTE_AS_STRING
    DBUS_STRUCT_END_CHAR_AS_STRING
    DBUS_STRUCT_END_CHAR_AS_STRING;
  _dbus_assert (dbus_signature_validate (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_UINT16);
  _dbus_assert (dbus_signature_iter_next (&iter));
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRUCT);
  dbus_signature_iter_recurse (&iter, &subiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_UINT32);
  _dbus_assert (dbus_signature_iter_next (&subiter));
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_BYTE);
  _dbus_assert (dbus_signature_iter_next (&subiter));
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_ARRAY);
  _dbus_assert (dbus_signature_iter_get_element_type (&subiter) == DBUS_TYPE_ARRAY);

  dbus_signature_iter_recurse (&subiter, &subsubiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_ARRAY);
  _dbus_assert (dbus_signature_iter_get_element_type (&subsubiter) == DBUS_TYPE_DOUBLE);

  dbus_signature_iter_recurse (&subsubiter, &subsubsubiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subsubsubiter) == DBUS_TYPE_DOUBLE);
  _dbus_assert (dbus_signature_iter_next (&subiter));
  _dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_STRUCT);
  dbus_signature_iter_recurse (&subiter, &subsubiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_BYTE);

  sig = DBUS_TYPE_ARRAY_AS_STRING
    DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_INT16_AS_STRING
    DBUS_TYPE_STRING_AS_STRING
    DBUS_DICT_ENTRY_END_CHAR_AS_STRING
    DBUS_TYPE_VARIANT_AS_STRING;
  _dbus_assert (dbus_signature_validate (sig, NULL));
  _dbus_assert (!dbus_signature_validate_single (sig, NULL));
  dbus_signature_iter_init (&iter, sig);
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_ARRAY);
  _dbus_assert (dbus_signature_iter_get_element_type (&iter) == DBUS_TYPE_DICT_ENTRY);

  dbus_signature_iter_recurse (&iter, &subiter);
  dbus_signature_iter_recurse (&subiter, &subsubiter);
  _dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_INT16);
  _dbus_assert (dbus_signature_iter_next (&subsubiter));
  _dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_STRING);
  _dbus_assert (!dbus_signature_iter_next (&subsubiter));

  _dbus_assert (dbus_signature_iter_next (&iter));
  _dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_VARIANT);
  _dbus_assert (!dbus_signature_iter_next (&iter));

  sig = DBUS_TYPE_DICT_ENTRY_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_TYPE_ARRAY_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_TYPE_UINT32_AS_STRING
    DBUS_TYPE_ARRAY_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_TYPE_ARRAY_AS_STRING
    DBUS_TYPE_DICT_ENTRY_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_INT32_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_INT32_AS_STRING
    DBUS_TYPE_STRING_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_STRUCT_END_CHAR_AS_STRING
    DBUS_STRUCT_BEGIN_CHAR_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));

  sig = DBUS_STRUCT_BEGIN_CHAR_AS_STRING
    DBUS_TYPE_BOOLEAN_AS_STRING;
  _dbus_assert (!dbus_signature_validate (sig, NULL));
  return TRUE;
#if 0
 oom:
  _dbus_assert_not_reached ("out of memory");
  return FALSE;
#endif
}

#endif

/** @} */ /* end of DBusSignature group */


Index: dbus-protocol.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-protocol.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- dbus-protocol.h	17 Feb 2005 21:19:49 -0000	1.40
+++ dbus-protocol.h	24 Feb 2005 16:03:56 -0000	1.41
@@ -271,6 +271,7 @@
 #define DBUS_ERROR_SPAWN_CHILD_SIGNALED       "org.freedesktop.DBus.Error.Spawn.ChildSignaled"
 #define DBUS_ERROR_SPAWN_FAILED               "org.freedesktop.DBus.Error.Spawn.Failed"
 #define DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN    "org.freedesktop.DBus.Error.UnixProcessIdUnknown"
+#define DBUS_ERROR_INVALID_SIGNATURE          "org.freedesktop.DBus.Error.InvalidSignature"
 
 #define DBUS_INTROSPECT_1_0_XML_NAMESPACE         "http://www.freedesktop.org/standards/dbus"
 #define DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"

Index: dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -d -r1.164 -r1.165
--- dbus-message.c	17 Feb 2005 21:19:49 -0000	1.164
+++ dbus-message.c	24 Feb 2005 16:03:56 -0000	1.165
@@ -27,6 +27,7 @@
 #include "dbus-marshal-validate.h"
 #include "dbus-marshal-byteswap.h"
 #include "dbus-marshal-header.h"
+#include "dbus-signature.h"
 #include "dbus-message-private.h"
 #include "dbus-object-tree.h"
 #include "dbus-memory.h"
@@ -1242,7 +1243,7 @@
 
   while (type != DBUS_TYPE_INVALID)
     {
-      if (_dbus_type_is_basic (type))
+      if (dbus_type_is_basic (type))
         {
           const DBusBasicValue *value;
           value = va_arg (var_args, const DBusBasicValue*);
@@ -1742,7 +1743,7 @@
           goto out;
 	}
 
-      if (_dbus_type_is_basic (spec_type))
+      if (dbus_type_is_basic (spec_type))
         {
           DBusBasicValue *ptr;
 
@@ -2076,7 +2077,7 @@
 
   _dbus_return_val_if_fail (_dbus_message_iter_append_check (real), FALSE);
   _dbus_return_val_if_fail (real->iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER, FALSE);
-  _dbus_return_val_if_fail (_dbus_type_is_basic (type), FALSE);
+  _dbus_return_val_if_fail (dbus_type_is_basic (type), FALSE);
   _dbus_return_val_if_fail (value != NULL, FALSE);
 
   if (!_dbus_message_iter_open_signature (real))
@@ -2182,7 +2183,7 @@
 
   _dbus_return_val_if_fail (_dbus_message_iter_append_check (real), FALSE);
   _dbus_return_val_if_fail (real->iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER, FALSE);
-  _dbus_return_val_if_fail (_dbus_type_is_container (type), FALSE);
+  _dbus_return_val_if_fail (dbus_type_is_container (type), FALSE);
   _dbus_return_val_if_fail (sub != NULL, FALSE);
   _dbus_return_val_if_fail ((type == DBUS_TYPE_STRUCT &&
                              contained_signature == NULL) ||

Index: dbus-marshal-validate.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-validate.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- dbus-marshal-validate.c	11 Feb 2005 01:13:45 -0000	1.18
+++ dbus-marshal-validate.c	24 Feb 2005 16:03:56 -0000	1.19
@@ -25,6 +25,7 @@
 #include "dbus-marshal-validate.h"
 #include "dbus-marshal-recursive.h"
 #include "dbus-marshal-basic.h"
+#include "dbus-signature.h"
 #include "dbus-string.h"
 
 /**
@@ -156,7 +157,7 @@
         }
 
       if (last == DBUS_DICT_ENTRY_BEGIN_CHAR &&
-          !_dbus_type_is_basic (*p))
+          !dbus_type_is_basic (*p))
         return DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE;
       
       last = *p;

Index: dbus-marshal-recursive.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-recursive.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- dbus-marshal-recursive.h	27 Jan 2005 23:39:26 -0000	1.28
+++ dbus-marshal-recursive.h	24 Feb 2005 16:03:56 -0000	1.29
@@ -170,6 +170,9 @@
 dbus_bool_t _dbus_type_reader_equal_values              (const DBusTypeReader *lhs,
                                                          const DBusTypeReader *rhs);
 
+void        _dbus_type_signature_next                   (const char            *signature,
+							 int                   *type_pos);
+
 void        _dbus_type_writer_init                 (DBusTypeWriter        *writer,
                                                     int                    byte_order,
                                                     DBusString            *type_str,

Index: dbus-marshal-recursive.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-recursive.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- dbus-marshal-recursive.c	28 Jan 2005 05:30:53 -0000	1.47
+++ dbus-marshal-recursive.c	24 Feb 2005 16:03:56 -0000	1.48
@@ -23,6 +23,7 @@
 
 #include "dbus-marshal-recursive.h"
 #include "dbus-marshal-basic.h"
+#include "dbus-signature.h"
 #include "dbus-internals.h"
 
 /**
@@ -308,18 +309,33 @@
   return reader->value_pos == end_pos;
 }
 
-/* this is written a little oddly to try and overoptimize */
 static void
 skip_one_complete_type (const DBusString *type_str,
                         int              *type_pos)
 {
+  _dbus_type_signature_next (_dbus_string_get_const_data (type_str),
+			     type_pos);
+}
+
+/**
+ * Skips to the next "complete" type inside a type signature.
+ * The signature is read starting at type_pos, and the next
+ * type position is stored in the same variable.
+ *
+ * @param type_str a type signature (must be valid)
+ * @param type_pos an integer position in the type signtaure (in and out)
+ */
+void
+_dbus_type_signature_next (const char       *type_str,
+			   int              *type_pos)
+{
   const unsigned char *p;
   const unsigned char *start;
 
   _dbus_assert (type_str != NULL);
   _dbus_assert (type_pos != NULL);
   
-  start = _dbus_string_get_const_data (type_str);
+  start = type_str;
   p = start + *type_pos;
 
   _dbus_assert (*p != DBUS_STRUCT_END_CHAR);
@@ -1446,7 +1462,7 @@
                                  realign_root->value_pos);
 #endif
 
-  _dbus_assert (_dbus_type_is_basic (current_type));
+  _dbus_assert (dbus_type_is_basic (current_type));
 
   if (_dbus_type_is_fixed (current_type))
     {
@@ -2500,7 +2516,7 @@
 
   while ((current_type = _dbus_type_reader_get_current_type (reader)) != DBUS_TYPE_INVALID)
     {
-      if (_dbus_type_is_container (current_type))
+      if (dbus_type_is_container (current_type))
         {
           DBusTypeReader subreader;
           DBusTypeWriter subwriter;
@@ -2646,7 +2662,7 @@
         {
           DBusBasicValue val;
 
-          _dbus_assert (_dbus_type_is_basic (current_type));
+          _dbus_assert (dbus_type_is_basic (current_type));
 
 #if RECURSIVE_MARSHAL_WRITE_TRACE
           _dbus_verbose ("Reading basic value %s at %d\n",

Index: dbus-marshal-recursive-util.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-recursive-util.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- dbus-marshal-recursive-util.c	28 Jan 2005 05:30:53 -0000	1.7
+++ dbus-marshal-recursive-util.c	24 Feb 2005 16:03:56 -0000	1.8
@@ -27,6 +27,7 @@
 
 #include "dbus-marshal-recursive.h"
 #include "dbus-marshal-basic.h"
+#include "dbus-signature.h"
 #include "dbus-internals.h"
 #include <string.h>
 
@@ -80,7 +81,7 @@
   if (lhs_type == DBUS_TYPE_INVALID)
     return TRUE;
 
-  if (_dbus_type_is_basic (lhs_type))
+  if (dbus_type_is_basic (lhs_type))
     {
       DBusBasicValue lhs_value;
       DBusBasicValue rhs_value;

Index: dbus-marshal-basic.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-basic.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- dbus-marshal-basic.h	28 Jan 2005 03:06:55 -0000	1.19
+++ dbus-marshal-basic.h	24 Feb 2005 16:03:56 -0000	1.20
@@ -244,14 +244,16 @@
                                                int              *new_pos);
 dbus_bool_t   _dbus_type_is_valid             (int               typecode);
 int           _dbus_type_get_alignment        (int               typecode);
-dbus_bool_t   _dbus_type_is_basic             (int               typecode);
-dbus_bool_t   _dbus_type_is_container         (int               typecode);
 dbus_bool_t   _dbus_type_is_fixed             (int               typecode);
+int           _dbus_type_get_alignment        (int               typecode);
 const char*   _dbus_type_to_string            (int               typecode);
 
 int           _dbus_first_type_in_signature   (const DBusString *str,
                                                int               pos);
 
+int           _dbus_first_type_in_signature_c_str   (const char       *str,
+						     int               pos);
+
 void _dbus_swap_array (unsigned char *data,
                        int            n_elements,
                        int            alignment);

Index: dbus-marshal-basic.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-basic.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- dbus-marshal-basic.c	6 Feb 2005 05:19:50 -0000	1.24
+++ dbus-marshal-basic.c	24 Feb 2005 16:03:56 -0000	1.25
@@ -24,6 +24,7 @@
 
 #include "dbus-internals.h"
 #include "dbus-marshal-basic.h"
+#include "dbus-signature.h"
 
 #include <string.h>
 
@@ -509,7 +510,7 @@
   const char *str_data;
   DBusBasicValue *vp;
 
-  _dbus_assert (_dbus_type_is_basic (type));
+  _dbus_assert (dbus_type_is_basic (type));
 
   str_data = _dbus_string_get_const_data (str);
   vp = value;
@@ -620,7 +621,7 @@
   int alignment;
 
   _dbus_assert (_dbus_type_is_fixed (element_type));
-  _dbus_assert (_dbus_type_is_basic (element_type));
+  _dbus_assert (dbus_type_is_basic (element_type));
 
 #if 0
   _dbus_verbose ("reading %d elements of %s\n",
@@ -849,7 +850,7 @@
 {
   const DBusBasicValue *vp;
 
-  _dbus_assert (_dbus_type_is_basic (type));
+  _dbus_assert (dbus_type_is_basic (type));
 
   vp = value;
 
@@ -1297,56 +1298,6 @@
     }
 }
 
-/** macro that checks whether a typecode is a container type */
-#define TYPE_IS_CONTAINER(typecode)             \
-    ((typecode) == DBUS_TYPE_STRUCT ||          \
-     (typecode) == DBUS_TYPE_DICT_ENTRY ||      \
-     (typecode) == DBUS_TYPE_VARIANT ||         \
-     (typecode) == DBUS_TYPE_ARRAY)
-
-/**
- * A "container type" can contain basic types, or nested
- * container types. #DBUS_TYPE_INVALID is not a container type.
- * This function will crash if passed a typecode that isn't
- * in dbus-protocol.h
- *
- * @returns #TRUE if type is a container
- */
-dbus_bool_t
-_dbus_type_is_container (int typecode)
-{
-  /* only reasonable (non-line-noise) typecodes are allowed */
-  _dbus_assert (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID);
-  return TYPE_IS_CONTAINER (typecode);
-}
-
-/**
- * A "basic type" is a somewhat arbitrary concept, but the intent
- * is to include those types that are fully-specified by a single
- * typecode, with no additional type information or nested
- * values. So all numbers and strings are basic types and
- * structs, arrays, and variants are not basic types.
- * #DBUS_TYPE_INVALID is not a basic type.
- *
- * This function is defined to return #TRUE for exactly those
- * types that can be written with _dbus_marshal_basic_type()
- * and read with _dbus_marshal_read_basic().
- *
- * This function will crash if passed a typecode that isn't
- * in dbus-protocol.h
- *
- * @returns #TRUE if type is basic
- */
-dbus_bool_t
-_dbus_type_is_basic (int typecode)
-{
-  /* only reasonable (non-line-noise) typecodes are allowed */
-  _dbus_assert (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID);
-
-  /* everything that isn't invalid or a container */
-  return !(typecode == DBUS_TYPE_INVALID || TYPE_IS_CONTAINER (typecode));
-}
-
 /**
  * Tells you whether values of this type can change length if you set
  * them to some other value. For this purpose, you assume that the
@@ -1552,6 +1503,21 @@
   _dbus_verbose_bytes (d, len, start);
 }
 
+static int
+map_type_char_to_type (int t)
+{
+  if (t == DBUS_STRUCT_BEGIN_CHAR)
+    return DBUS_TYPE_STRUCT;
+  else if (t == DBUS_DICT_ENTRY_BEGIN_CHAR)
+    return DBUS_TYPE_DICT_ENTRY;
+  else
+    {
+      _dbus_assert (t != DBUS_STRUCT_END_CHAR);
+      _dbus_assert (t != DBUS_DICT_ENTRY_END_CHAR);
+      return t;
+    }
+}
+
 /**
  * Get the first type in the signature. The difference between this
  * and just getting the first byte of the signature is that you won't
@@ -1566,20 +1532,22 @@
 _dbus_first_type_in_signature (const DBusString *str,
                                int               pos)
 {
-  unsigned char t;
-
-  t = _dbus_string_get_byte (str, pos);
+  return map_type_char_to_type (_dbus_string_get_byte (str, pos));
+}
 
-  if (t == DBUS_STRUCT_BEGIN_CHAR)
-    return DBUS_TYPE_STRUCT;
-  else if (t == DBUS_DICT_ENTRY_BEGIN_CHAR)
-    return DBUS_TYPE_DICT_ENTRY;
-  else
-    {
-      _dbus_assert (t != DBUS_STRUCT_END_CHAR);
-      _dbus_assert (t != DBUS_DICT_ENTRY_END_CHAR);
-      return t;
-    }
+/**
+ * Similar to #_dbus_first_type_in_signature, but operates
+ * on a C string buffer.
+ *
+ * @param str a C string buffer
+ * @param pos where the signature starts
+ * @returns the first type in the signature
+ */
+int
+_dbus_first_type_in_signature_c_str (const char       *str,
+				     int               pos)
+{
+  return map_type_char_to_type (str[pos]);
 }
 
 /** @} */

Index: Makefile.am
===================================================================
RCS file: /cvs/dbus/dbus/dbus/Makefile.am,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- Makefile.am	27 Jan 2005 23:39:26 -0000	1.66
+++ Makefile.am	24 Feb 2005 16:03:56 -0000	1.67
@@ -78,6 +78,8 @@
 	dbus-server-unix.h			\
 	dbus-sha.c				\
 	dbus-sha.h				\
+	dbus-signature.c			\
+	dbus-signature.h			\
 	dbus-timeout.c				\
 	dbus-timeout.h				\
 	dbus-threads.c				\



More information about the dbus-commit mailing list