Commit 9d21554d authored by Havoc Pennington's avatar Havoc Pennington

2005-01-23 Havoc Pennington <hp@redhat.com>

	* dbus/dbus-message-factory.c, dbus/dbus-message-util.c:
	get this all working, not many tests in the framework yet though
parent 487f1345
2005-01-23 Havoc Pennington <hp@redhat.com>
* dbus/dbus-message-factory.c, dbus/dbus-message-util.c:
get this all working, not many tests in the framework yet though
2005-01-22 Havoc Pennington <hp@redhat.com>
* doc/dbus-faq.xml, doc/dbus-tutorial: add a FAQ and update
......
......@@ -49,6 +49,9 @@ typedef enum
*/
typedef enum
{
DBUS_INVALID_FOR_UNKNOWN_REASON = -3,
DBUS_VALID_BUT_INCOMPLETE = -2,
DBUS_VALIDITY_UNKNOWN = -1,
DBUS_VALID = 0,
DBUS_INVALID_UNKNOWN_TYPECODE = 1,
DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE = 2,
......@@ -98,7 +101,7 @@ typedef enum
DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES = 46,
DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL = 47,
DBUS_INVALID_STRING_MISSING_NUL = 48,
DBUS_INVALID_SIGNATURE_MISSING_NUL = 49,
DBUS_INVALID_SIGNATURE_MISSING_NUL = 49
} DBusValidity;
DBusValidity _dbus_validate_signature_with_reason (const DBusString *type_str,
......
This diff is collapsed.
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-message-builder.h Build messages from text files for testing (internal to D-BUS implementation)
*
* Copyright (C) 2003 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
*
*/
#ifndef DBUS_MESSAGE_BUILDER_H
#define DBUS_MESSAGE_BUILDER_H
#include <config.h>
#include <dbus/dbus-memory.h>
#include <dbus/dbus-types.h>
#include <dbus/dbus-string.h>
DBUS_BEGIN_DECLS
dbus_bool_t _dbus_message_data_load (DBusString *dest,
const DBusString *filename);
DBUS_END_DECLS
#endif /* DBUS_MESSAGE_BUILDER_H */
......@@ -20,14 +20,17 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <config.h>
#ifdef DBUS_BUILD_TESTS
#include "dbus-message-factory.h"
#include "dbus-message-private.h"
typedef dbus_bool_t (* DBusMessageGeneratorFunc) (int sequence,
typedef dbus_bool_t (* DBusInnerGeneratorFunc) (int sequence,
DBusMessage **message_p);
typedef dbus_bool_t (* DBusMessageGeneratorFunc) (int sequence,
DBusString *data,
DBusValidity *expected_validity);
static void
set_reply_serial (DBusMessage *message)
......@@ -39,8 +42,8 @@ set_reply_serial (DBusMessage *message)
}
static dbus_bool_t
generate_trivial (int sequence,
DBusMessage **message_p)
generate_trivial_inner (int sequence,
DBusMessage **message_p)
{
DBusMessage *message;
......@@ -63,6 +66,22 @@ generate_trivial (int sequence,
break;
case 3:
message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
if (!dbus_message_set_error_name (message,
"org.freedesktop.TestErrorName"))
_dbus_assert_not_reached ("oom");
{
DBusMessageIter iter;
const char *v_STRING = "This is an error";
dbus_message_iter_init_append (message, &iter);
if (!dbus_message_iter_append_basic (&iter,
DBUS_TYPE_STRING,
&v_STRING))
_dbus_assert_not_reached ("oom");
}
set_reply_serial (message);
break;
default:
......@@ -77,6 +96,48 @@ generate_trivial (int sequence,
return TRUE;
}
static dbus_bool_t
generate_outer (int sequence,
DBusString *data,
DBusValidity *expected_validity,
DBusInnerGeneratorFunc func)
{
DBusMessage *message;
message = NULL;
if (!(*func)(sequence, &message))
return FALSE;
_dbus_assert (message != NULL);
_dbus_message_set_serial (message, 1);
_dbus_message_lock (message);
*expected_validity = DBUS_VALID;
/* move for efficiency, since we'll nuke the message anyway */
if (!_dbus_string_move (&message->header.data, 0,
data, 0))
_dbus_assert_not_reached ("oom");
if (!_dbus_string_copy (&message->body, 0,
data, _dbus_string_get_length (data)))
_dbus_assert_not_reached ("oom");
dbus_message_unref (message);
return TRUE;
}
static dbus_bool_t
generate_trivial (int sequence,
DBusString *data,
DBusValidity *expected_validity)
{
return generate_outer (sequence, data, expected_validity,
generate_trivial_inner);
}
static const DBusMessageGeneratorFunc generators[] = {
generate_trivial
};
......@@ -99,36 +160,25 @@ _dbus_message_data_iter_get_and_next (DBusMessageDataIter *iter,
DBusMessageData *data)
{
DBusMessageGeneratorFunc func;
DBusMessage *message;
restart:
if (iter->generator == _DBUS_N_ELEMENTS (generators))
return FALSE;
func = generators[iter->generator];
if ((*func)(iter->sequence, &message))
if (!_dbus_string_init (&data->data))
_dbus_assert_not_reached ("oom");
if ((*func)(iter->sequence, &data->data, &data->expected_validity))
iter->sequence += 1;
else
{
iter->generator += 1;
iter->sequence = 0;
_dbus_string_free (&data->data);
goto restart;
}
_dbus_assert (message != NULL);
if (!_dbus_string_init (&data->data))
_dbus_assert_not_reached ("oom");
/* move for efficiency, since we'll nuke the message anyway */
if (!_dbus_string_move (&message->header.data, 0,
&data->data, 0))
_dbus_assert_not_reached ("oom");
if (!_dbus_string_copy (&message->body, 0,
&data->data, _dbus_string_get_length (&data->data)))
_dbus_assert_not_reached ("oom");
dbus_message_unref (message);
return TRUE;
}
......
......@@ -34,7 +34,6 @@ DBUS_BEGIN_DECLS
typedef struct
{
dbus_bool_t validity_known;
DBusValidity expected_validity;
DBusString data;
......
......@@ -70,6 +70,8 @@ struct DBusMessageLoader
unsigned int buffer_outstanding : 1; /**< Someone is using the buffer to read */
unsigned int corrupted : 1; /**< We got broken data, and are no longer working */
DBusValidity corruption_reason; /**< why we were corrupted */
};
......
This diff is collapsed.
......@@ -570,7 +570,7 @@ dbus_message_cache_or_finalize (DBusMessage *message)
{
dbus_bool_t was_cached;
int i;
_dbus_assert (message->refcount.value == 0);
/* This calls application code and has to be done first thing
......@@ -654,7 +654,7 @@ dbus_message_new_empty_header (void)
message->generation = _dbus_current_generation;
#endif
}
message->refcount.value = 1;
message->byte_order = DBUS_COMPILER_BYTE_ORDER;
message->locked = FALSE;
......@@ -2881,9 +2881,12 @@ _dbus_message_loader_new (void)
loader = dbus_new0 (DBusMessageLoader, 1);
if (loader == NULL)
return NULL;
loader->refcount = 1;
loader->corrupted = FALSE;
loader->corruption_reason = DBUS_VALID;
/* Try to cap message size at something that won't *totally* hose
* the system if we have a couple of them.
*/
......@@ -3018,7 +3021,7 @@ _dbus_message_loader_return_buffer (DBusMessageLoader *loader,
* loader->data and only delete it occasionally, instead of after
* each message is loaded.
*
* load_message() returns FALSE if not enough memory
* load_message() returns FALSE if not enough memory OR the loader was corrupted
*/
static dbus_bool_t
load_message (DBusMessageLoader *loader,
......@@ -3059,6 +3062,11 @@ load_message (DBusMessageLoader *loader,
_dbus_verbose ("Failed to load header for new message code %d\n", validity);
if (validity == DBUS_VALID)
oom = TRUE;
else
{
loader->corrupted = TRUE;
loader->corruption_reason = validity;
}
goto failed;
}
......@@ -3084,6 +3092,10 @@ load_message (DBusMessageLoader *loader,
if (validity != DBUS_VALID)
{
_dbus_verbose ("Failed to validate message body code %d\n", validity);
loader->corrupted = TRUE;
loader->corruption_reason = validity;
goto failed;
}
}
......@@ -3117,6 +3129,8 @@ load_message (DBusMessageLoader *loader,
_dbus_assert (!oom);
_dbus_assert (!loader->corrupted);
_dbus_assert (loader->messages != NULL);
_dbus_assert (_dbus_list_find_last (&loader->messages, message) != NULL);
return TRUE;
......@@ -3126,13 +3140,15 @@ load_message (DBusMessageLoader *loader,
/* does nothing if the message isn't in the list */
_dbus_list_remove_last (&loader->messages, message);
if (!oom)
loader->corrupted = TRUE;
if (oom)
_dbus_assert (!loader->corrupted);
else
_dbus_assert (loader->corrupted);
_dbus_verbose_bytes_of_string (&loader->data, 0, _dbus_string_get_length (&loader->data));
return !oom;
return FALSE;
}
/**
......@@ -3180,15 +3196,24 @@ _dbus_message_loader_queue_messages (DBusMessageLoader *loader)
header_len, body_len))
{
dbus_message_unref (message);
return FALSE;
/* load_message() returns false if corrupted or OOM; if
* corrupted then return TRUE for not OOM
*/
return loader->corrupted;
}
_dbus_assert (loader->messages != NULL);
_dbus_assert (_dbus_list_find_last (&loader->messages, message) != NULL);
}
else
{
_dbus_verbose ("Initial peek at header says we don't have a whole message yet, or data broken with invalid code %d\n",
validity);
if (validity != DBUS_VALID)
loader->corrupted = TRUE;
{
loader->corrupted = TRUE;
loader->corruption_reason = validity;
}
return TRUE;
}
}
......@@ -3265,6 +3290,8 @@ _dbus_message_loader_putback_message_link (DBusMessageLoader *loader,
dbus_bool_t
_dbus_message_loader_get_is_corrupted (DBusMessageLoader *loader)
{
_dbus_assert ((loader->corrupted && loader->corruption_reason != DBUS_VALID) ||
(!loader->corrupted && loader->corruption_reason == DBUS_VALID));
return loader->corrupted;
}
......
......@@ -118,7 +118,7 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
check_memleaks ();
#if 1
#if 0
printf ("%s: running recursive marshalling tests\n", "dbus-test");
if (!_dbus_marshal_recursive_test ())
die ("recursive marshal");
......@@ -134,11 +134,13 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
check_memleaks ();
#if 0
printf ("%s: running memory pool tests\n", "dbus-test");
if (!_dbus_mem_pool_test ())
die ("memory pools");
check_memleaks ();
#endif
printf ("%s: running linked list tests\n", "dbus-test");
if (!_dbus_list_test ())
......
......@@ -26,14 +26,7 @@
#include <dbus/dbus-types.h>
#include <dbus/dbus-string.h>
typedef enum
{
_DBUS_MESSAGE_VALID,
_DBUS_MESSAGE_INVALID,
_DBUS_MESSAGE_INCOMPLETE,
_DBUS_MESSAGE_UNKNOWN
} DBusMessageValidity;
#include <dbus/dbus-marshal-validate.h>
dbus_bool_t _dbus_hash_test (void);
dbus_bool_t _dbus_dict_test (void);
......@@ -61,19 +54,16 @@ dbus_bool_t _dbus_pending_call_test (const char *test_data_dir);
void dbus_internal_do_not_use_run_tests (const char *test_data_dir);
dbus_bool_t dbus_internal_do_not_use_try_message_file (const DBusString *filename,
dbus_bool_t is_raw,
DBusMessageValidity expected_validity);
DBusValidity expected_validity);
dbus_bool_t dbus_internal_do_not_use_try_message_data (const DBusString *data,
DBusMessageValidity expected_validity);
DBusValidity expected_validity);
dbus_bool_t dbus_internal_do_not_use_load_message_file (const DBusString *filename,
dbus_bool_t is_raw,
DBusString *data);
/* returns FALSE on fatal failure */
typedef dbus_bool_t (* DBusForeachMessageFileFunc) (const DBusString *filename,
dbus_bool_t is_raw,
DBusMessageValidity expected_validity,
DBusValidity expected_validity,
void *data);
dbus_bool_t dbus_internal_do_not_use_foreach_message_file (const char *test_data_dir,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment