X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dbus%2Fdbus-message.c;h=20c8be35aef3857176572560286a94940562a5a7;hb=383f596c4aee2561c90abca3ce9d1f52407a3eec;hp=73a53ccd518c7fe79f51d7fd1f7e9b38cd3e9e3b;hpb=926496567a238cee5364b8afe961274926706591;p=platform%2Fupstream%2Fdbus.git diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 73a53cc..20c8be3 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -40,6 +40,10 @@ #include +#define _DBUS_TYPE_IS_STRINGLIKE(type) \ + (type == DBUS_TYPE_STRING || type == DBUS_TYPE_SIGNATURE || \ + type == DBUS_TYPE_OBJECT_PATH) + static void dbus_message_finalize (DBusMessage *message); /** @@ -52,7 +56,7 @@ static void dbus_message_finalize (DBusMessage *message); * @{ */ -#ifdef DBUS_BUILD_TESTS +#ifdef DBUS_ENABLE_EMBEDDED_TESTS static dbus_bool_t _dbus_enable_message_cache (void) { @@ -502,7 +506,7 @@ _dbus_message_set_signature (DBusMessage *message, /** Avoid caching too many messages */ #define MAX_MESSAGE_CACHE_SIZE 5 -_DBUS_DEFINE_GLOBAL_LOCK (message_cache); +/* Protected by _DBUS_LOCK (message_cache) */ static DBusMessage *message_cache[MAX_MESSAGE_CACHE_SIZE]; static int message_cache_count = 0; static dbus_bool_t message_cache_shutdown_registered = FALSE; @@ -512,7 +516,9 @@ dbus_message_cache_shutdown (void *data) { int i; - _DBUS_LOCK (message_cache); + if (!_DBUS_LOCK (message_cache)) + _dbus_assert_not_reached ("we would have initialized global locks " + "before registering a shutdown function"); i = 0; while (i < MAX_MESSAGE_CACHE_SIZE) @@ -544,7 +550,12 @@ dbus_message_get_cached (void) message = NULL; - _DBUS_LOCK (message_cache); + if (!_DBUS_LOCK (message_cache)) + { + /* we'd have initialized global locks before caching anything, + * so there can't be anything in the cache */ + return NULL; + } _dbus_assert (message_cache_count >= 0); @@ -656,7 +667,13 @@ dbus_message_cache_or_finalize (DBusMessage *message) was_cached = FALSE; - _DBUS_LOCK (message_cache); + if (!_DBUS_LOCK (message_cache)) + { + /* The only way to get a non-null message goes through + * dbus_message_get_cached() which takes the lock. */ + _dbus_assert_not_reached ("we would have initialized global locks " + "the first time we constructed a message"); + } if (!message_cache_shutdown_registered) { @@ -712,7 +729,7 @@ dbus_message_cache_or_finalize (DBusMessage *message) dbus_message_finalize (message); } -#ifndef DBUS_DISABLE_CHECKS +#if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT) static dbus_bool_t _dbus_message_iter_check (DBusMessageRealIter *iter) { @@ -760,7 +777,7 @@ _dbus_message_iter_check (DBusMessageRealIter *iter) return TRUE; } -#endif /* DBUS_DISABLE_CHECKS */ +#endif /* DBUS_ENABLE_CHECKS || DBUS_ENABLE_ASSERT */ /** * Implementation of the varargs arg-getting functions. @@ -887,9 +904,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, _dbus_type_reader_read_fixed_multi (&array, (void *) ptr, n_elements_p); } - else if (spec_element_type == DBUS_TYPE_STRING || - spec_element_type == DBUS_TYPE_SIGNATURE || - spec_element_type == DBUS_TYPE_OBJECT_PATH) + else if (_DBUS_TYPE_IS_STRINGLIKE (spec_element_type)) { char ***str_array_p; int n_elements; @@ -1244,7 +1259,7 @@ dbus_message_new (int message_type) * * @param destination name that the message should be sent to or #NULL * @param path object path the message should be sent to - * @param interface interface to invoke method on, or #NULL + * @param iface interface to invoke method on, or #NULL * @param method method to invoke * * @returns a new DBusMessage, free with dbus_message_unref() @@ -1252,7 +1267,7 @@ dbus_message_new (int message_type) DBusMessage* dbus_message_new_method_call (const char *destination, const char *path, - const char *interface, + const char *iface, const char *method) { DBusMessage *message; @@ -1262,8 +1277,8 @@ dbus_message_new_method_call (const char *destination, _dbus_return_val_if_fail (destination == NULL || _dbus_check_is_valid_bus_name (destination), NULL); _dbus_return_val_if_fail (_dbus_check_is_valid_path (path), NULL); - _dbus_return_val_if_fail (interface == NULL || - _dbus_check_is_valid_interface (interface), NULL); + _dbus_return_val_if_fail (iface == NULL || + _dbus_check_is_valid_interface (iface), NULL); _dbus_return_val_if_fail (_dbus_check_is_valid_member (method), NULL); message = dbus_message_new_empty_header (); @@ -1273,7 +1288,7 @@ dbus_message_new_method_call (const char *destination, if (!_dbus_header_create (&message->header, DBUS_COMPILER_BYTE_ORDER, DBUS_MESSAGE_TYPE_METHOD_CALL, - destination, path, interface, method, NULL)) + destination, path, iface, method, NULL)) { dbus_message_unref (message); return NULL; @@ -1336,22 +1351,22 @@ dbus_message_new_method_return (DBusMessage *method_call) * specification defines the syntax of these fields). * * @param path the path to the object emitting the signal - * @param interface the interface the signal is emitted from + * @param iface the interface the signal is emitted from * @param name name of the signal * @returns a new DBusMessage, free with dbus_message_unref() */ DBusMessage* dbus_message_new_signal (const char *path, - const char *interface, + const char *iface, const char *name) { DBusMessage *message; _dbus_return_val_if_fail (path != NULL, NULL); - _dbus_return_val_if_fail (interface != NULL, NULL); + _dbus_return_val_if_fail (iface != NULL, NULL); _dbus_return_val_if_fail (name != NULL, NULL); _dbus_return_val_if_fail (_dbus_check_is_valid_path (path), NULL); - _dbus_return_val_if_fail (_dbus_check_is_valid_interface (interface), NULL); + _dbus_return_val_if_fail (_dbus_check_is_valid_interface (iface), NULL); _dbus_return_val_if_fail (_dbus_check_is_valid_member (name), NULL); message = dbus_message_new_empty_header (); @@ -1361,7 +1376,7 @@ dbus_message_new_signal (const char *path, if (!_dbus_header_create (&message->header, DBUS_COMPILER_BYTE_ORDER, DBUS_MESSAGE_TYPE_SIGNAL, - NULL, path, interface, name, NULL)) + NULL, path, iface, name, NULL)) { dbus_message_unref (message); return NULL; @@ -1799,9 +1814,7 @@ dbus_message_append_args_valist (DBusMessage *message, goto failed; } } - else if (element_type == DBUS_TYPE_STRING || - element_type == DBUS_TYPE_SIGNATURE || - element_type == DBUS_TYPE_OBJECT_PATH) + else if (_DBUS_TYPE_IS_STRINGLIKE (element_type)) { const char ***value_p; const char **value; @@ -2191,22 +2204,22 @@ dbus_message_iter_get_signature (DBusMessageIter *iter) * descriptors), you can get all the array elements at once with * dbus_message_iter_get_fixed_array(). Otherwise, you have to iterate * over the container's contents one value at a time. - * - * All basic-typed values are guaranteed to fit in 8 bytes. So you can - * write code like this: + * + * All basic-typed values are guaranteed to fit in a #DBusBasicValue, + * so in versions of libdbus that have that type, you can write code like this: * * @code - * dbus_uint64_t value; + * DBusBasicValue value; * int type; * dbus_message_iter_get_basic (&read_iter, &value); * type = dbus_message_iter_get_arg_type (&read_iter); * dbus_message_iter_append_basic (&write_iter, type, &value); * @endcode * - * On some really obscure platforms dbus_uint64_t might not exist, if - * you need to worry about this you will know. dbus_uint64_t is just - * one example of a type that's large enough to hold any possible - * value, you could use a struct or char[8] instead if you like. + * (All D-Bus basic types are either numeric and 8 bytes or smaller, or + * behave like a string; so in older versions of libdbus, DBusBasicValue + * can be replaced with union { char *string; unsigned char bytes[8]; }, + * for instance.) * * @param iter the iterator * @param value location to store the value @@ -3113,23 +3126,23 @@ dbus_message_get_path_decomposed (DBusMessage *message, * in the D-Bus specification. * * @param message the message - * @param interface the interface or #NULL to unset + * @param iface the interface or #NULL to unset * @returns #FALSE if not enough memory */ dbus_bool_t dbus_message_set_interface (DBusMessage *message, - const char *interface) + const char *iface) { _dbus_return_val_if_fail (message != NULL, FALSE); _dbus_return_val_if_fail (!message->locked, FALSE); - _dbus_return_val_if_fail (interface == NULL || - _dbus_check_is_valid_interface (interface), + _dbus_return_val_if_fail (iface == NULL || + _dbus_check_is_valid_interface (iface), FALSE); return set_or_delete_string_field (message, DBUS_HEADER_FIELD_INTERFACE, DBUS_TYPE_STRING, - interface); + iface); } /** @@ -3164,28 +3177,28 @@ dbus_message_get_interface (DBusMessage *message) * Checks if the message has an interface * * @param message the message - * @param interface the interface name + * @param iface the interface name * @returns #TRUE if the interface field in the header matches */ dbus_bool_t dbus_message_has_interface (DBusMessage *message, - const char *interface) + const char *iface) { const char *msg_interface; msg_interface = dbus_message_get_interface (message); if (msg_interface == NULL) { - if (interface == NULL) + if (iface == NULL) return TRUE; else return FALSE; } - if (interface == NULL) + if (iface == NULL) return FALSE; - if (strcmp (msg_interface, interface) == 0) + if (strcmp (msg_interface, iface) == 0) return TRUE; return FALSE; @@ -3477,13 +3490,13 @@ dbus_message_get_signature (DBusMessage *message) static dbus_bool_t _dbus_message_has_type_interface_member (DBusMessage *message, int type, - const char *interface, + const char *iface, const char *member) { const char *n; _dbus_assert (message != NULL); - _dbus_assert (interface != NULL); + _dbus_assert (iface != NULL); _dbus_assert (member != NULL); if (dbus_message_get_type (message) != type) @@ -3499,7 +3512,7 @@ _dbus_message_has_type_interface_member (DBusMessage *message, { n = dbus_message_get_interface (message); - if (n == NULL || strcmp (n, interface) == 0) + if (n == NULL || strcmp (n, iface) == 0) return TRUE; } @@ -3515,18 +3528,18 @@ _dbus_message_has_type_interface_member (DBusMessage *message, * protocol allows method callers to leave out the interface name. * * @param message the message - * @param interface the name to check (must not be #NULL) + * @param iface the name to check (must not be #NULL) * @param method the name to check (must not be #NULL) * * @returns #TRUE if the message is the specified method call */ dbus_bool_t dbus_message_is_method_call (DBusMessage *message, - const char *interface, + const char *iface, const char *method) { _dbus_return_val_if_fail (message != NULL, FALSE); - _dbus_return_val_if_fail (interface != NULL, FALSE); + _dbus_return_val_if_fail (iface != NULL, FALSE); _dbus_return_val_if_fail (method != NULL, FALSE); /* don't check that interface/method are valid since it would be * expensive, and not catch many common errors @@ -3534,7 +3547,7 @@ dbus_message_is_method_call (DBusMessage *message, return _dbus_message_has_type_interface_member (message, DBUS_MESSAGE_TYPE_METHOD_CALL, - interface, method); + iface, method); } /** @@ -3543,18 +3556,18 @@ dbus_message_is_method_call (DBusMessage *message, * has a different interface or member field, returns #FALSE. * * @param message the message - * @param interface the name to check (must not be #NULL) + * @param iface the name to check (must not be #NULL) * @param signal_name the name to check (must not be #NULL) * * @returns #TRUE if the message is the specified signal */ dbus_bool_t dbus_message_is_signal (DBusMessage *message, - const char *interface, + const char *iface, const char *signal_name) { _dbus_return_val_if_fail (message != NULL, FALSE); - _dbus_return_val_if_fail (interface != NULL, FALSE); + _dbus_return_val_if_fail (iface != NULL, FALSE); _dbus_return_val_if_fail (signal_name != NULL, FALSE); /* don't check that interface/name are valid since it would be * expensive, and not catch many common errors @@ -3562,7 +3575,7 @@ dbus_message_is_signal (DBusMessage *message, return _dbus_message_has_type_interface_member (message, DBUS_MESSAGE_TYPE_SIGNAL, - interface, signal_name); + iface, signal_name); } /** @@ -3802,7 +3815,7 @@ _dbus_message_loader_new (void) SCM_RIGHTS works we need to preallocate an fd array of the maximum number of unix fds we want to receive in advance. A try-and-reallocate loop is not possible. */ - loader->max_message_unix_fds = 1024; + loader->max_message_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS; if (!_dbus_string_init (&loader->data)) { @@ -3968,7 +3981,7 @@ _dbus_message_loader_get_unix_fds(DBusMessageLoader *loader, * * @param loader the message loader. * @param fds the array fds were read into - * @param max_n_fds how many fds were read + * @param n_fds how many fds were read */ void @@ -4396,7 +4409,7 @@ _dbus_message_loader_get_max_message_size (DBusMessageLoader *loader) * Sets the maximum unix fds per message we allow. * * @param loader the loader - * @param size the max number of unix fds in a message + * @param n the max number of unix fds in a message */ void _dbus_message_loader_set_max_message_unix_fds (DBusMessageLoader *loader, @@ -4423,8 +4436,8 @@ _dbus_message_loader_get_max_message_unix_fds (DBusMessageLoader *loader) return loader->max_message_unix_fds; } -static DBusDataSlotAllocator slot_allocator; -_DBUS_DEFINE_GLOBAL_LOCK (message_slots); +static DBusDataSlotAllocator slot_allocator = + _DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (message_slots)); /** * Allocates an integer ID to be used for storing application-specific @@ -4444,7 +4457,6 @@ dbus_bool_t dbus_message_allocate_data_slot (dbus_int32_t *slot_p) { return _dbus_data_slot_allocator_alloc (&slot_allocator, - &_DBUS_LOCK_NAME (message_slots), slot_p); } @@ -4717,9 +4729,8 @@ dbus_message_demarshal (const char *str, * Generally, this function is only useful for encapsulating D-Bus messages in * a different protocol. * - * @param str data to be marshalled - * @param len the length of str - * @param error the location to save errors to + * @param buf data to be marshalled + * @param len the length of @p buf * @returns -1 if there was no valid data to be demarshalled, 0 if there wasn't enough data to determine how much should be demarshalled. Otherwise returns the number of bytes to be demarshalled * */