Commit 7bf62e31 authored by Havoc Pennington's avatar Havoc Pennington

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

        This is about it on what can be disabled/deleted from libdbus
	easily, back below 150K anyhow. Deeper cuts are more work than
	just turning the code off as I've done here.

	* dbus/dbus-marshal-basic.c (_dbus_pack_int32): we don't need the
	signed int convenience funcs

	* dbus/dbus-internals.c (_dbus_verbose_real): omit when not in
	verbose mode

	* dbus/dbus-string-util.c, dbus/dbus-string.c: more breaking
	things out of libdbus

	* dbus/dbus-sysdeps.c, dbus/dbus-sysdeps-util.c: same

	* dbus/dbus-hash.c: purge the TWO_STRINGS crap (well, make it
	tests-enabled-only, though it should probably be deleted)

	* dbus/dbus-message-util.c: same stuff

	* dbus/dbus-auth-util.c: same stuff
parent 4c1a2a76
2005-01-16 Havoc Pennington <hp@redhat.com>
This is about it on what can be disabled/deleted from libdbus
easily, back below 150K anyhow. Deeper cuts are more work than
just turning the code off as I've done here.
* dbus/dbus-marshal-basic.c (_dbus_pack_int32): we don't need the
signed int convenience funcs
* dbus/dbus-internals.c (_dbus_verbose_real): omit when not in
verbose mode
* dbus/dbus-string-util.c, dbus/dbus-string.c: more breaking
things out of libdbus
* dbus/dbus-sysdeps.c, dbus/dbus-sysdeps-util.c: same
* dbus/dbus-hash.c: purge the TWO_STRINGS crap (well, make it
tests-enabled-only, though it should probably be deleted)
* dbus/dbus-message-util.c: same stuff
* dbus/dbus-auth-util.c: same stuff
2005-01-16 Havoc Pennington <hp@redhat.com>
* dbus/dbus-userdb-util.c: split out part of dbus-userdb.c
......
......@@ -62,15 +62,16 @@ DBUS_LIB_SOURCES= \
dbus-marshal-validate.h \
dbus-message.c \
dbus-message-internal.h \
dbus-message-private.h \
dbus-object-tree.c \
dbus-object-tree.h \
dbus-pending-call.c \
dbus-resources.c \
dbus-resources.h \
dbus-server.c \
dbus-server-protected.h \
dbus-server-debug-pipe.c \
dbus-server-debug-pipe.h \
dbus-server-protected.h \
dbus-server-unix.c \
dbus-server-unix.h \
dbus-sha.c \
......@@ -121,16 +122,18 @@ DBUS_SHARED_SOURCES= \
### should be underscore-prefixed but don't really need
### to be unless they move to DBUS_SHARED_SOURCES later)
DBUS_UTIL_SOURCES= \
dbus-auth-util.c \
dbus-mainloop.c \
dbus-mainloop.h \
dbus-marshal-recursive-util.c \
dbus-message-util.c \
dbus-spawn.c \
dbus-spawn.h \
dbus-string-util.c \
dbus-sysdeps-util.c \
dbus-sysdeps-util.h \
dbus-test.c \
dbus-test.h \
dbus-userdb-util.c \
dbus-userdb-util.h
dbus-userdb-util.c
libdbus_1_la_SOURCES= \
$(DBUS_LIB_SOURCES) \
......
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-auth-util.c Would be in dbus-auth.c, but only used for tests/bus
*
* Copyright (C) 2002, 2003, 2004 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-internals.h"
#include "dbus-test.h"
#include "dbus-auth.h"
/**
* @addtogroup DBusAuth
* @{
*/
/** @} */
#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include "dbus-auth-script.h"
#include <stdio.h>
static dbus_bool_t
process_test_subdir (const DBusString *test_base_dir,
const char *subdir)
{
DBusString test_directory;
DBusString filename;
DBusDirIter *dir;
dbus_bool_t retval;
DBusError error;
retval = FALSE;
dir = NULL;
if (!_dbus_string_init (&test_directory))
_dbus_assert_not_reached ("didn't allocate test_directory\n");
_dbus_string_init_const (&filename, subdir);
if (!_dbus_string_copy (test_base_dir, 0,
&test_directory, 0))
_dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
if (!_dbus_concat_dir_and_file (&test_directory, &filename))
_dbus_assert_not_reached ("couldn't allocate full path");
_dbus_string_free (&filename);
if (!_dbus_string_init (&filename))
_dbus_assert_not_reached ("didn't allocate filename string\n");
dbus_error_init (&error);
dir = _dbus_directory_open (&test_directory, &error);
if (dir == NULL)
{
_dbus_warn ("Could not open %s: %s\n",
_dbus_string_get_const_data (&test_directory),
error.message);
dbus_error_free (&error);
goto failed;
}
printf ("Testing %s:\n", subdir);
next:
while (_dbus_directory_get_next_file (dir, &filename, &error))
{
DBusString full_path;
if (!_dbus_string_init (&full_path))
_dbus_assert_not_reached ("couldn't init string");
if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
_dbus_assert_not_reached ("couldn't copy dir to full_path");
if (!_dbus_concat_dir_and_file (&full_path, &filename))
_dbus_assert_not_reached ("couldn't concat file to dir");
if (!_dbus_string_ends_with_c_str (&filename, ".auth-script"))
{
_dbus_verbose ("Skipping non-.auth-script file %s\n",
_dbus_string_get_const_data (&filename));
_dbus_string_free (&full_path);
goto next;
}
printf (" %s\n", _dbus_string_get_const_data (&filename));
if (!_dbus_auth_script_run (&full_path))
{
_dbus_string_free (&full_path);
goto failed;
}
else
_dbus_string_free (&full_path);
}
if (dbus_error_is_set (&error))
{
_dbus_warn ("Could not get next file in %s: %s\n",
_dbus_string_get_const_data (&test_directory), error.message);
dbus_error_free (&error);
goto failed;
}
retval = TRUE;
failed:
if (dir)
_dbus_directory_close (dir);
_dbus_string_free (&test_directory);
_dbus_string_free (&filename);
return retval;
}
static dbus_bool_t
process_test_dirs (const char *test_data_dir)
{
DBusString test_directory;
dbus_bool_t retval;
retval = FALSE;
_dbus_string_init_const (&test_directory, test_data_dir);
if (!process_test_subdir (&test_directory, "auth"))
goto failed;
retval = TRUE;
failed:
_dbus_string_free (&test_directory);
return retval;
}
dbus_bool_t
_dbus_auth_test (const char *test_data_dir)
{
if (test_data_dir == NULL)
return TRUE;
if (!process_test_dirs (test_data_dir))
return FALSE;
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
......@@ -2392,139 +2392,4 @@ _dbus_auth_set_context (DBusAuth *auth,
/** @} */
#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include "dbus-auth-script.h"
#include <stdio.h>
static dbus_bool_t
process_test_subdir (const DBusString *test_base_dir,
const char *subdir)
{
DBusString test_directory;
DBusString filename;
DBusDirIter *dir;
dbus_bool_t retval;
DBusError error;
retval = FALSE;
dir = NULL;
if (!_dbus_string_init (&test_directory))
_dbus_assert_not_reached ("didn't allocate test_directory\n");
_dbus_string_init_const (&filename, subdir);
if (!_dbus_string_copy (test_base_dir, 0,
&test_directory, 0))
_dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
if (!_dbus_concat_dir_and_file (&test_directory, &filename))
_dbus_assert_not_reached ("couldn't allocate full path");
_dbus_string_free (&filename);
if (!_dbus_string_init (&filename))
_dbus_assert_not_reached ("didn't allocate filename string\n");
dbus_error_init (&error);
dir = _dbus_directory_open (&test_directory, &error);
if (dir == NULL)
{
_dbus_warn ("Could not open %s: %s\n",
_dbus_string_get_const_data (&test_directory),
error.message);
dbus_error_free (&error);
goto failed;
}
printf ("Testing %s:\n", subdir);
next:
while (_dbus_directory_get_next_file (dir, &filename, &error))
{
DBusString full_path;
if (!_dbus_string_init (&full_path))
_dbus_assert_not_reached ("couldn't init string");
if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
_dbus_assert_not_reached ("couldn't copy dir to full_path");
if (!_dbus_concat_dir_and_file (&full_path, &filename))
_dbus_assert_not_reached ("couldn't concat file to dir");
if (!_dbus_string_ends_with_c_str (&filename, ".auth-script"))
{
_dbus_verbose ("Skipping non-.auth-script file %s\n",
_dbus_string_get_const_data (&filename));
_dbus_string_free (&full_path);
goto next;
}
printf (" %s\n", _dbus_string_get_const_data (&filename));
if (!_dbus_auth_script_run (&full_path))
{
_dbus_string_free (&full_path);
goto failed;
}
else
_dbus_string_free (&full_path);
}
if (dbus_error_is_set (&error))
{
_dbus_warn ("Could not get next file in %s: %s\n",
_dbus_string_get_const_data (&test_directory), error.message);
dbus_error_free (&error);
goto failed;
}
retval = TRUE;
failed:
if (dir)
_dbus_directory_close (dir);
_dbus_string_free (&test_directory);
_dbus_string_free (&filename);
return retval;
}
static dbus_bool_t
process_test_dirs (const char *test_data_dir)
{
DBusString test_directory;
dbus_bool_t retval;
retval = FALSE;
_dbus_string_init_const (&test_directory, test_data_dir);
if (!process_test_subdir (&test_directory, "auth"))
goto failed;
retval = TRUE;
failed:
_dbus_string_free (&test_directory);
return retval;
}
dbus_bool_t
_dbus_auth_test (const char *test_data_dir)
{
if (test_data_dir == NULL)
return TRUE;
if (!process_test_dirs (test_data_dir))
return FALSE;
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
/* tests in dbus-auth-util.c */
......@@ -231,13 +231,17 @@ static DBusHashEntry* find_string_function (DBusHashTable *table,
dbus_bool_t create_if_not_found,
DBusHashEntry ***bucket,
DBusPreallocatedHash *preallocated);
#ifdef DBUS_BUILD_TESTS
static DBusHashEntry* find_two_strings_function (DBusHashTable *table,
void *key,
dbus_bool_t create_if_not_found,
DBusHashEntry ***bucket,
DBusPreallocatedHash *preallocated);
#endif
static unsigned int string_hash (const char *str);
#ifdef DBUS_BUILD_TESTS
static unsigned int two_strings_hash (const char *str);
#endif
static void rebuild_table (DBusHashTable *table);
static DBusHashEntry* alloc_entry (DBusHashTable *table);
static void remove_entry (DBusHashTable *table,
......@@ -330,7 +334,9 @@ _dbus_hash_table_new (DBusHashType type,
table->find_function = find_string_function;
break;
case DBUS_HASH_TWO_STRINGS:
#ifdef DBUS_BUILD_TESTS
table->find_function = find_two_strings_function;
#endif
break;
default:
_dbus_assert_not_reached ("Unknown hash table type");
......@@ -696,6 +702,7 @@ _dbus_hash_iter_get_string_key (DBusHashIter *iter)
return real->entry->key;
}
#ifdef DBUS_BUILD_TESTS
/**
* Gets the key for the current entry.
* Only works for hash tables of type #DBUS_HASH_TWO_STRINGS
......@@ -713,6 +720,7 @@ _dbus_hash_iter_get_two_strings_key (DBusHashIter *iter)
return real->entry->key;
}
#endif /* DBUS_BUILD_TESTS */
/**
* A low-level but efficient interface for manipulating the hash
......@@ -849,6 +857,7 @@ string_hash (const char *str)
return h;
}
#ifdef DBUS_BUILD_TESTS
/* This hashes a memory block with two nul-terminated strings
* in it, used in dbus-object-registry.c at the moment.
*/
......@@ -867,6 +876,7 @@ two_strings_hash (const char *str)
return h;
}
#endif /* DBUS_BUILD_TESTS */
/** Key comparison function */
typedef int (* KeyCompareFunc) (const void *key_a, const void *key_b);
......@@ -928,6 +938,7 @@ find_string_function (DBusHashTable *table,
preallocated);
}
#ifdef DBUS_BUILD_TESTS
static int
two_strings_cmp (const char *a,
const char *b)
......@@ -945,7 +956,9 @@ two_strings_cmp (const char *a,
return strcmp (a + len_a + 1, b + len_b + 1);
}
#endif
#ifdef DBUS_BUILD_TESTS
static DBusHashEntry*
find_two_strings_function (DBusHashTable *table,
void *key,
......@@ -961,6 +974,7 @@ find_two_strings_function (DBusHashTable *table,
(KeyCompareFunc) two_strings_cmp, create_if_not_found, bucket,
preallocated);
}
#endif /* DBUS_BUILD_TESTS */
static DBusHashEntry*
find_direct_function (DBusHashTable *table,
......@@ -1077,7 +1091,12 @@ rebuild_table (DBusHashTable *table)
idx = string_hash (entry->key) & table->mask;
break;
case DBUS_HASH_TWO_STRINGS:
#ifdef DBUS_BUILD_TESTS
idx = two_strings_hash (entry->key) & table->mask;
#else
idx = 0;
_dbus_assert_not_reached ("two-strings is not enabled");
#endif
break;
case DBUS_HASH_INT:
case DBUS_HASH_ULONG:
......@@ -1127,6 +1146,7 @@ _dbus_hash_table_lookup_string (DBusHashTable *table,
return NULL;
}
#ifdef DBUS_BUILD_TESTS
/**
* Looks up the value for a given string in a hash table
* of type #DBUS_HASH_TWO_STRINGS. Returns %NULL if the value
......@@ -1151,6 +1171,7 @@ _dbus_hash_table_lookup_two_strings (DBusHashTable *table,
else
return NULL;
}
#endif /* DBUS_BUILD_TESTS */
/**
* Looks up the value for a given integer in a hash table
......@@ -1258,6 +1279,7 @@ _dbus_hash_table_remove_string (DBusHashTable *table,
return FALSE;
}
#ifdef DBUS_BUILD_TESTS
/**
* Removes the hash entry for the given key. If no hash entry
* for the key exists, does nothing.
......@@ -1285,6 +1307,7 @@ _dbus_hash_table_remove_two_strings (DBusHashTable *table,
else
return FALSE;
}
#endif /* DBUS_BUILD_TESTS */
/**
* Removes the hash entry for the given key. If no hash entry
......@@ -1407,6 +1430,7 @@ _dbus_hash_table_insert_string (DBusHashTable *table,
return TRUE;
}
#ifdef DBUS_BUILD_TESTS
/**
* Creates a hash entry with the given key and value.
* The key and value are not copied; they are stored
......@@ -1447,6 +1471,7 @@ _dbus_hash_table_insert_two_strings (DBusHashTable *table,
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
/**
* Creates a hash entry with the given key and value.
......
......@@ -174,6 +174,8 @@ _dbus_warn (const char *format,
va_end (args);
}
#ifdef DBUS_ENABLE_VERBOSE_MODE
static dbus_bool_t verbose_initted = FALSE;
/**
......@@ -238,6 +240,8 @@ _dbus_verbose_reset_real (void)
verbose_initted = FALSE;
}
#endif /* DBUS_ENABLE_VERBOSE_MODE */
/**
* Duplicates a string. Result must be freed with
* dbus_free(). Returns #NULL if memory allocation fails.
......@@ -354,6 +358,7 @@ _dbus_string_array_contains (const char **array,
return FALSE;
}
#ifdef DBUS_BUILD_TESTS
/**
* Returns a string describing the given name.
*
......@@ -387,6 +392,7 @@ _dbus_header_field_to_string (int header_field)
return "unknown";
}
}
#endif /* DBUS_BUILD_TESTS */
#ifndef DBUS_DISABLE_CHECKS
/** String used in _dbus_return_if_fail macro */
......
......@@ -39,9 +39,6 @@ DBUS_BEGIN_DECLS
void _dbus_warn (const char *format,
...) _DBUS_GNUC_PRINTF (1, 2);
void _dbus_verbose_real (const char *format,
...) _DBUS_GNUC_PRINTF (1, 2);
void _dbus_verbose_reset_real (void);
#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define _DBUS_FUNCTION_NAME __func__
......@@ -79,6 +76,11 @@ void _dbus_verbose_reset_real (void);
#endif
#ifdef DBUS_ENABLE_VERBOSE_MODE
void _dbus_verbose_real (const char *format,
...) _DBUS_GNUC_PRINTF (1, 2);
void _dbus_verbose_reset_real (void);
# define _dbus_verbose _dbus_verbose_real
# define _dbus_verbose_reset _dbus_verbose_reset_real
#else
......
......@@ -126,6 +126,7 @@ link_before (DBusList **list,
}
}
#ifdef DBUS_BUILD_TESTS
static void
link_after (DBusList **list,
DBusList *after_this_link,
......@@ -145,6 +146,7 @@ link_after (DBusList **list,
link->next->prev = link;
}
}
#endif /* DBUS_BUILD_TESTS */
/** @} */
......@@ -313,6 +315,7 @@ _dbus_list_prepend_link (DBusList **list,
link_before (list, *list, link);
}
#ifdef DBUS_BUILD_TESTS
/**
* Inserts data into the list before the given existing link.
*
......@@ -341,7 +344,9 @@ _dbus_list_insert_before (DBusList **list,
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
#ifdef DBUS_BUILD_TESTS
/**
* Inserts data into the list after the given existing link.
*
......@@ -370,6 +375,7 @@ _dbus_list_insert_after (DBusList **list,
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
/**
* Inserts a link into the list before the given existing link.
......@@ -389,6 +395,7 @@ _dbus_list_insert_before_link (DBusList **list,
link_before (list, before_this_link, link);
}
#ifdef DBUS_BUILD_TESTS
/**
* Inserts a link into the list after the given existing link.
*
......@@ -406,6 +413,7 @@ _dbus_list_insert_after_link (DBusList **list,
else
link_after (list, after_this_link, link);
}
#endif /* DBUS_BUILD_TESTS */
/**
* Removes a value from the list. Only removes the
......@@ -690,6 +698,7 @@ _dbus_list_pop_last (DBusList **list)
return data;
}
#ifdef DBUS_BUILD_TESTS
/**
* Removes the last link in the list and returns it. This is a
* constant-time operation.
......@@ -710,6 +719,7 @@ _dbus_list_pop_last_link (DBusList **list)
return link;
}
#endif /* DBUS_BUILD_TESTS */
/**
* Copies a list. This is a linear-time operation. If there isn't
......
......@@ -88,21 +88,6 @@ _dbus_pack_uint32 (dbus_uint32_t value,
pack_4_octets (value, byte_order, data);
}
/**
* Packs a 32 bit signed integer into a data pointer.
*
* @param value the value
* @param byte_order the byte order to use
* @param data the data pointer
*/
void
_dbus_pack_int32 (dbus_int32_t value,
int byte_order,
unsigned char *data)
{
pack_4_octets ((dbus_uint32_t) value, byte_order, data);
}
#ifndef DBUS_HAVE_INT64
/* from ORBit */
static void
......@@ -183,20 +168,6 @@ _dbus_unpack_uint32 (int byte_order,
}
#endif /* _dbus_unpack_uint32 */
/**
* Unpacks a 32 bit signed integer from a data pointer
*
* @param byte_order The byte order to use
* @param data the data pointer
* @returns the integer
*/
dbus_int32_t
_dbus_unpack_int32 (int byte_order,
const unsigned char *data)
{
return (dbus_int32_t) _dbus_unpack_uint32 (byte_order, data);
}
static void
set_4_octets (DBusString *str,
int offset,
......
......@@ -152,11 +152,6 @@ typedef union
DBUS_UINT32_FROM_BE (*(dbus_uint32_t*)(data)))
#endif
void _dbus_pack_int32 (dbus_int32_t value,
int byte_order,
unsigned char *data);
dbus_int32_t _dbus_unpack_int32 (int byte_order,
const unsigned char *data);
void _dbus_pack_uint32 (dbus_uint32_t value,
int byte_order,
unsigned char *data);
......
This diff is collapsed.
This diff is collapsed.
......@@ -335,6 +335,115 @@ append_string_field (DBusString *dest,
return TRUE;
}
#ifdef DBUS_BUILD_TESTS
/**
* Parses a basic type defined by type contained in a DBusString. The
* end_return parameter may be #NULL if you aren't interested in it. The
* type is parsed and stored in value_return. Return parameters are not
* initialized if the function returns #FALSE.
*
* @param str the string
* @param type the type of the basic type
* @param start the byte index of the start of the type
* @param value_return return location of the value or #NULL
* @param end_return return location of the end of the type, or #NULL
* @returns #TRUE on success
*/
static dbus_bool_t
_dbus_string_parse_basic_type (const DBusString *str,
char type,
int start,
void *value,
int *end_return)
{
int end = start;
switch (type)
{
case DBUS_TYPE_BOOLEAN:
{
int len = _dbus_string_get_length (str) - start;
if (len >= 5 && _dbus_string_find_to (str, start, start + 5, "false", NULL))
{
end += 5;
*(unsigned char *) value = TRUE;
}
else if (len >= 4 && _dbus_string_find_to (str, start, start + 4, "true", NULL))
{
end += 4;
*(unsigned char *) value = FALSE;
}
else
_dbus_warn ("could not parse BOOLEAN\n");
break;
}
case DBUS_TYPE_BYTE:
{
long val = 0;
if (_dbus_string_get_byte (str, start) == '\'' &&
_dbus_string_get_length (str) >= start + 4 &&
_dbus_string_get_byte (str, start + 1) == '\\' &&
_dbus_string_get_byte (str, start + 2) == '\'' &&
_dbus_string_get_byte (str, start + 3) == '\'')
{
val = '\'';
end += 4;