summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'dbus')
-rw-r--r--dbus/dbus-address.c4
-rw-r--r--dbus/dbus-auth-script.c12
-rw-r--r--dbus/dbus-auth.c25
-rw-r--r--dbus/dbus-bus.c124
-rw-r--r--dbus/dbus-bus.h8
-rw-r--r--dbus/dbus-connection.c220
-rw-r--r--dbus/dbus-connection.h34
-rw-r--r--dbus/dbus-errors.c44
-rw-r--r--dbus/dbus-errors.h16
-rw-r--r--dbus/dbus-internals.c107
-rw-r--r--dbus/dbus-internals.h5
-rw-r--r--dbus/dbus-keyring.c12
-rw-r--r--dbus/dbus-list.c18
-rw-r--r--dbus/dbus-list.h2
-rw-r--r--dbus/dbus-message-builder.c11
-rw-r--r--dbus/dbus-message-internal.h17
-rw-r--r--dbus/dbus-message.c217
-rw-r--r--dbus/dbus-message.h39
-rw-r--r--dbus/dbus-sha.c16
-rw-r--r--dbus/dbus-sysdeps.c321
-rw-r--r--dbus/dbus-sysdeps.h30
21 files changed, 828 insertions, 454 deletions
diff --git a/dbus/dbus-address.c b/dbus/dbus-address.c
index fb8952b5..25179cea 100644
--- a/dbus/dbus-address.c
+++ b/dbus/dbus-address.c
@@ -27,9 +27,9 @@
#include "dbus-list.h"
/**
- * @defgroup DBusAddress address parsing
+ * @defgroup DBusAddress Address parsing
* @ingroup DBus
- * @brief Parsing addresses to DBus servers.
+ * @brief Parsing addresses of D-BUS servers.
*
* @{
*/
diff --git a/dbus/dbus-auth-script.c b/dbus/dbus-auth-script.c
index 732b4515..336d63e1 100644
--- a/dbus/dbus-auth-script.c
+++ b/dbus/dbus-auth-script.c
@@ -184,7 +184,7 @@ dbus_bool_t
_dbus_auth_script_run (const DBusString *filename)
{
DBusString file;
- DBusResultCode result;
+ DBusError error;
DBusString line;
dbus_bool_t retval;
int line_no;
@@ -213,14 +213,14 @@ _dbus_auth_script_run (const DBusString *filename)
_dbus_string_free (&line);
return FALSE;
}
-
- if ((result = _dbus_file_get_contents (&file, filename)) != DBUS_RESULT_SUCCESS)
- {
+
+ dbus_error_init (&error);
+ if (!_dbus_file_get_contents (&file, filename, &error)) {
const char *s;
_dbus_string_get_const_data (filename, &s);
_dbus_warn ("Getting contents of %s failed: %s\n",
- s, dbus_result_to_string (result));
-
+ s, error.message);
+ dbus_error_free (&error);
goto out;
}
diff --git a/dbus/dbus-auth.c b/dbus/dbus-auth.c
index 516a51ae..8dfdc766 100644
--- a/dbus/dbus-auth.c
+++ b/dbus/dbus-auth.c
@@ -514,7 +514,7 @@ sha1_handle_first_client_response (DBusAuth *auth,
}
else
{
- _dbus_assert (dbus_error_is_set (&error));
+ _DBUS_ASSERT_ERROR_IS_SET (&error);
_dbus_verbose ("Error loading keyring: %s\n",
error.message);
if (send_rejected (auth))
@@ -535,7 +535,7 @@ sha1_handle_first_client_response (DBusAuth *auth,
auth->cookie_id = _dbus_keyring_get_best_key (auth->keyring, &error);
if (auth->cookie_id < 0)
{
- _dbus_assert (dbus_error_is_set (&error));
+ _DBUS_ASSERT_ERROR_IS_SET (&error);
_dbus_verbose ("Could not get a cookie ID to send to client: %s\n",
error.message);
if (send_rejected (auth))
@@ -844,7 +844,8 @@ handle_client_data_cookie_sha1_mech (DBusAuth *auth,
}
else
{
- _dbus_assert (dbus_error_is_set (&error));
+ _DBUS_ASSERT_ERROR_IS_SET (&error);
+
_dbus_verbose ("Error loading keyring: %s\n",
error.message);
@@ -2238,7 +2239,7 @@ process_test_subdir (const DBusString *test_base_dir,
DBusString filename;
DBusDirIter *dir;
dbus_bool_t retval;
- DBusResultCode result;
+ DBusError error;
retval = FALSE;
dir = NULL;
@@ -2258,22 +2259,23 @@ process_test_subdir (const DBusString *test_base_dir,
_dbus_string_free (&filename);
if (!_dbus_string_init (&filename, _DBUS_INT_MAX))
_dbus_assert_not_reached ("didn't allocate filename string\n");
-
- dir = _dbus_directory_open (&test_directory, &result);
+
+ dbus_error_init (&error);
+ dir = _dbus_directory_open (&test_directory, &error);
if (dir == NULL)
{
const char *s;
_dbus_string_get_const_data (&test_directory, &s);
_dbus_warn ("Could not open %s: %s\n", s,
- dbus_result_to_string (result));
+ error.message);
+ dbus_error_free (&error);
goto failed;
}
printf ("Testing:\n");
- result = DBUS_RESULT_SUCCESS;
next:
- while (_dbus_directory_get_next_file (dir, &filename, &result))
+ while (_dbus_directory_get_next_file (dir, &filename, &error))
{
DBusString full_path;
@@ -2311,12 +2313,13 @@ process_test_subdir (const DBusString *test_base_dir,
_dbus_string_free (&full_path);
}
- if (result != DBUS_RESULT_SUCCESS)
+ if (dbus_error_is_set (&error))
{
const char *s;
_dbus_string_get_const_data (&test_directory, &s);
_dbus_warn ("Could not get next file in %s: %s\n",
- s, dbus_result_to_string (result));
+ s, error.message);
+ dbus_error_free (&error);
goto failed;
}
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c
index 99ef5ade..cc612a78 100644
--- a/dbus/dbus-bus.c
+++ b/dbus/dbus-bus.c
@@ -2,6 +2,7 @@
/* dbus-bus.c Convenience functions for communicating with the bus.
*
* Copyright (C) 2003 CodeFactory AB
+ * Copyright (C) 2003 Red Hat, Inc.
*
* Licensed under the Academic Free License version 1.2
*
@@ -23,29 +24,32 @@
#include "dbus-bus.h"
#include "dbus-protocol.h"
+#include "dbus-internals.h"
/**
- * @defgroup DBusBus Convenience functinos for communicating with the bus.
+ * @defgroup DBusBus Message bus APIs
* @ingroup DBus
- * @brief Convenience functinos for communicating with the bus.
+ * @brief Functions for communicating with the message bus
*
* @{
*/
/**
- * Registers a connection with the bus. This is needed to send messages
- * to other clients.
+ * Registers a connection with the bus. This must be the first
+ * thing an application does when connecting to the message bus.
*
- * @param connection The connection
- * @param result address where a result code can be returned.
- * @returns the service name of which the client is known as.
+ * @todo if we get an error reply, it has to be converted into
+ * DBusError and returned
+ *
+ * @param connection the connection
+ * @param error place to store errors
+ * @returns the client's unique service name, #NULL on error
*/
-char *
+char*
dbus_bus_register_client (DBusConnection *connection,
- DBusResultCode *result)
+ DBusError *error)
{
DBusMessage *message, *reply;
- DBusResultCode code;
char *name;
message = dbus_message_new (DBUS_SERVICE_DBUS,
@@ -53,56 +57,61 @@ dbus_bus_register_client (DBusConnection *connection,
if (!message)
{
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ _DBUS_SET_OOM (error);
return NULL;
}
- reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
+ reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
dbus_message_unref (message);
- if (!reply)
- return NULL;
-
- code = dbus_message_get_args (reply,
- DBUS_TYPE_STRING, &name,
- 0);
- if (code != DBUS_RESULT_SUCCESS)
+ if (reply == NULL)
{
- dbus_set_result (result, code);
+ _DBUS_ASSERT_ERROR_IS_SET (error);
return NULL;
}
- dbus_set_result (result, DBUS_RESULT_SUCCESS);
-
+ if (!dbus_message_get_args (reply, error,
+ DBUS_TYPE_STRING, &name,
+ 0))
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return NULL;
+ }
+
return name;
}
/**
* Asks the bus to try to acquire a certain service.
*
+ * @todo these docs are not complete, need to document the
+ * return value and flags
+ *
+ * @todo if we get an error reply, it has to be converted into
+ * DBusError and returned
+ *
* @param connection the connection
* @param service_name the service name
* @param flags flags
- * @param result address where a result code can be returned.
- * @returns a result code.
+ * @param error location to store the error
+ * @returns a result code, -1 if error is set
*/
int
dbus_bus_acquire_service (DBusConnection *connection,
const char *service_name,
unsigned int flags,
- DBusResultCode *result)
+ DBusError *error)
{
DBusMessage *message, *reply;
int service_result;
- DBusResultCode code;
message = dbus_message_new (DBUS_SERVICE_DBUS,
DBUS_MESSAGE_ACQUIRE_SERVICE);
- if (!message)
+ if (message == NULL)
{
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ _DBUS_SET_OOM (error);
return -1;
}
@@ -112,26 +121,28 @@ dbus_bus_acquire_service (DBusConnection *connection,
0))
{
dbus_message_unref (message);
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ _DBUS_SET_OOM (error);
return -1;
}
- reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
+ reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
+ error);
+
dbus_message_unref (message);
- if (!reply)
- return -1;
-
- code = dbus_message_get_args (reply,
- DBUS_TYPE_UINT32, &service_result,
- 0);
- if (code != DBUS_RESULT_SUCCESS)
+ if (reply == NULL)
{
- dbus_set_result (result, code);
+ _DBUS_ASSERT_ERROR_IS_SET (error);
return -1;
}
- dbus_set_result (result, DBUS_RESULT_SUCCESS);
+ if (!dbus_message_get_args (reply, error,
+ DBUS_TYPE_UINT32, &service_result,
+ 0))
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return -1;
+ }
return service_result;
}
@@ -139,25 +150,26 @@ dbus_bus_acquire_service (DBusConnection *connection,
/**
* Checks whether a certain service exists.
*
+ * @todo the SERVICE_EXISTS message should use BOOLEAN not UINT32
+ *
* @param connection the connection
* @param service_name the service name
- * @param result address where a result code can be returned.
- * @returns #TRUE if the service exists, #FALSE otherwise.
+ * @param error location to store any errors
+ * @returns #TRUE if the service exists, #FALSE if not or on error
*/
dbus_bool_t
dbus_bus_service_exists (DBusConnection *connection,
const char *service_name,
- DBusResultCode *result)
+ DBusError *error)
{
DBusMessage *message, *reply;
unsigned int exists;
- DBusResultCode code;
message = dbus_message_new (DBUS_SERVICE_DBUS,
DBUS_MESSAGE_SERVICE_EXISTS);
- if (!message)
+ if (message == NULL)
{
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ _DBUS_SET_OOM (error);
return FALSE;
}
@@ -166,27 +178,27 @@ dbus_bus_service_exists (DBusConnection *connection,
0))
{
dbus_message_unref (message);
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ _DBUS_SET_OOM (error);
return FALSE;
}
- reply = dbus_connection_send_message_with_reply_and_block (connection, message, -1, result);
+ reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
dbus_message_unref (message);
- if (!reply)
- return FALSE;
+ if (reply == NULL)
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return FALSE;
+ }
- code = dbus_message_get_args (reply,
- DBUS_TYPE_UINT32, &exists,
- 0);
- if (code != DBUS_RESULT_SUCCESS)
+ if (!dbus_message_get_args (reply, error,
+ DBUS_TYPE_UINT32, &exists,
+ 0))
{
- dbus_set_result (result, code);
+ _DBUS_ASSERT_ERROR_IS_SET (error);
return FALSE;
}
- dbus_set_result (result, DBUS_RESULT_SUCCESS);
-
return (exists != FALSE);
}
diff --git a/dbus/dbus-bus.h b/dbus/dbus-bus.h
index 0bd8dec8..d1c2bfd7 100644
--- a/dbus/dbus-bus.h
+++ b/dbus/dbus-bus.h
@@ -29,15 +29,15 @@
#include <dbus/dbus-connection.h>
-char * dbus_bus_register_client (DBusConnection *connection,
- DBusResultCode *result);
+char* dbus_bus_register_client (DBusConnection *connection,
+ DBusError *error);
int dbus_bus_acquire_service (DBusConnection *connection,
const char *service_name,
unsigned int flags,
- DBusResultCode *result);
+ DBusError *error);
dbus_bool_t dbus_bus_service_exists (DBusConnection *connection,
const char *service_name,
- DBusResultCode *result);
+ DBusError *error);
#endif /* DBUS_BUS_H */
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index 3611b871..bfc27e2a 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -187,7 +187,7 @@ _dbus_connection_queue_received_message (DBusConnection *connection,
return FALSE;
/* If this is a reply we're waiting on, remove timeout for it */
- reply_serial = _dbus_message_get_reply_serial (message);
+ reply_serial = dbus_message_get_reply_serial (message);
if (reply_serial != -1)
{
reply_handler_data = _dbus_hash_table_lookup_int (connection->pending_replies,
@@ -205,9 +205,11 @@ _dbus_connection_queue_received_message (DBusConnection *connection,
connection->n_incoming += 1;
_dbus_connection_wakeup_mainloop (connection);
-
- _dbus_verbose ("Incoming message %p added to queue, %d incoming\n",
- message, connection->n_incoming);
+
+ _dbus_assert (dbus_message_get_name (message) != NULL);
+ _dbus_verbose ("Incoming message %p (%s) added to queue, %d incoming\n",
+ message, dbus_message_get_name (message),
+ connection->n_incoming);
return TRUE;
}
@@ -963,54 +965,88 @@ dbus_connection_get_is_authenticated (DBusConnection *connection)
}
/**
- * Adds a message to the outgoing message queue. Does not block to
- * write the message to the network; that happens asynchronously. to
- * force the message to be written, call dbus_connection_flush().
+ * Preallocates resources needed to send a message, allowing the message
+ * to be sent without the possibility of memory allocation failure.
+ * Allows apps to create a future guarantee that they can send
+ * a message regardless of memory shortages.
*
- * If the function fails, it returns #FALSE and returns the
- * reason for failure via the result parameter.
- * The result parameter can be #NULL if you aren't interested
- * in the reason for the failure.
- *
- * @param connection the connection.
- * @param message the message to write.
- * @param client_serial return location for client serial.
- * @param result address where result code can be placed.
- * @returns #TRUE on success.
+ * @param connection the connection we're preallocating for.
+ * @returns the preallocated resources, or #NULL
*/
-dbus_bool_t
-dbus_connection_send_message (DBusConnection *connection,
- DBusMessage *message,
- dbus_int32_t *client_serial,
- DBusResultCode *result)
+DBusPreallocatedSend*
+dbus_connection_preallocate_send (DBusConnection *connection)
+{
+ /* we store "connection" in the link just to enforce via
+ * assertion that preallocated links are only used
+ * with the connection they were created for.
+ */
+ return (DBusPreallocatedSend*) _dbus_list_alloc_link (connection);
+}
+/**
+ * Frees preallocated message-sending resources from
+ * dbus_connection_preallocate_send(). Should only
+ * be called if the preallocated resources are not used
+ * to send a message.
+ *
+ * @param connection the connection
+ * @param preallocated the resources
+ */
+void
+dbus_connection_free_preallocated_send (DBusConnection *connection,
+ DBusPreallocatedSend *preallocated)
{
- dbus_int32_t serial;
+ DBusList *link = (DBusList*) preallocated;
+ _dbus_assert (link->data == connection);
+ _dbus_list_free_link (link);
+}
+/**
+ * Sends a message using preallocated resources. This function cannot fail.
+ * It works identically to dbus_connection_send() in other respects.
+ * Preallocated resources comes from dbus_connection_preallocate_send().
+ * This function "consumes" the preallocated resources, they need not
+ * be freed separately.
+ *
+ * @param connection the connection
+ * @param preallocated the preallocated resources
+ * @param message the message to send
+ * @param client_serial return location for client serial assigned to the message
+ */
+void
+dbus_connection_send_preallocated (DBusConnection *connection,
+ DBusPreallocatedSend *preallocated,
+ DBusMessage *message,
+ dbus_int32_t *client_serial)
+{
+ DBusList *link = (DBusList*) preallocated;
+ dbus_int32_t serial;
+
+ _dbus_assert (link->data == connection);
+ _dbus_assert (dbus_message_get_name (message) != NULL);
+
dbus_mutex_lock (connection->mutex);
- if (!_dbus_list_prepend (&connection->outgoing_messages,
- message))
- {
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
- dbus_mutex_unlock (connection->mutex);
- return FALSE;
- }
+ link->data = message;
+ _dbus_list_prepend_link (&connection->outgoing_messages,
+ link);
dbus_message_ref (message);
connection->n_outgoing += 1;
- _dbus_verbose ("Message %p added to outgoing queue, %d pending to send\n",
- message, connection->n_outgoing);
+ _dbus_verbose ("Message %p (%s) added to outgoing queue, %d pending to send\n",
+ message,
+ dbus_message_get_name (message),
+ connection->n_outgoing);
- if (_dbus_message_get_client_serial (message) == -1)
+ if (dbus_message_get_serial (message) == -1)
{
serial = _dbus_connection_get_next_client_serial (connection);
- _dbus_message_set_client_serial (message, serial);
+ _dbus_message_set_serial (message, serial);
}
if (client_serial)
- *client_serial = _dbus_message_get_client_serial (message);
+ *client_serial = dbus_message_get_serial (message);
_dbus_message_lock (message);
@@ -1021,8 +1057,43 @@ dbus_connection_send_message (DBusConnection *connection,
_dbus_connection_wakeup_mainloop (connection);
dbus_mutex_unlock (connection->mutex);
-
- return TRUE;
+}
+
+/**
+ * Adds a message to the outgoing message queue. Does not block to
+ * write the message to the network; that happens asynchronously. To
+ * force the message to be written, call dbus_connection_flush().
+ * Because this only queues the message, the only reason it can
+ * fail is lack of memory. Even if the connection is disconnected,
+ * no error will be returned.
+ *
+ * If the function fails, it returns #FALSE and returns the
+ * reason for failure via the result parameter.
+ * The result parameter can be #NULL if you aren't interested
+ * in the reason for the failure.
+ *
+ * @param connection the connection.
+ * @param message the message to write.
+ * @param client_serial return location for client serial.
+ * @returns #TRUE on success.
+ */
+dbus_bool_t
+dbus_connection_send (DBusConnection *connection,
+ DBusMessage *message,
+ dbus_int32_t *client_serial)
+{
+ DBusPreallocatedSend *preallocated;
+
+ preallocated = dbus_connection_preallocate_send (connection);
+ if (preallocated == NULL)
+ {
+ return FALSE;
+ }
+ else
+ {
+ dbus_connection_send_preallocated (connection, preallocated, message, client_serial);
+ return TRUE;
+ }
}
static void
@@ -1100,25 +1171,19 @@ reply_handler_data_free (ReplyHandlerData *data)
* you want a very short or very long timeout. There is no way to
* avoid a timeout entirely, other than passing INT_MAX for the
* timeout to postpone it indefinitely.
- *
- * @todo I think we should rename this function family
- * dbus_connection_send(), send_with_reply(), etc. (i.e.
- * drop the "message" part), the names are too long.
*
* @param connection the connection
* @param message the message to send
* @param reply_handler message handler expecting the reply, or #NULL
* @param timeout_milliseconds timeout in milliseconds or -1 for default
- * @param result return location for result code
* @returns #TRUE if the message is successfully queued, #FALSE if no memory.
*
*/
dbus_bool_t
-dbus_connection_send_message_with_reply (DBusConnection *connection,
- DBusMessage *message,
- DBusMessageHandler *reply_handler,
- int timeout_milliseconds,
- DBusResultCode *result)
+dbus_connection_send_with_reply (DBusConnection *connection,
+ DBusMessage *message,
+ DBusMessageHandler *reply_handler,
+ int timeout_milliseconds)
{
DBusTimeout *timeout;
ReplyHandlerData *data;
@@ -1132,10 +1197,7 @@ dbus_connection_send_message_with_reply (DBusConnection *connection,
data = dbus_new0 (ReplyHandlerData, 1);
if (!data)
- {
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
- return FALSE;
- }
+ return FALSE;
timeout = _dbus_timeout_new (timeout_milliseconds, reply_handler_timeout,
data, NULL);
@@ -1143,7 +1205,6 @@ dbus_connection_send_message_with_reply (DBusConnection *connection,
if (!timeout)
{
reply_handler_data_free (data);
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
return FALSE;
}
@@ -1155,8 +1216,6 @@ dbus_connection_send_message_with_reply (DBusConnection *connection,
reply_handler_data_free (data);
_dbus_timeout_unref (timeout);
dbus_mutex_unlock (connection->mutex);
-
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
return FALSE;
}
@@ -1171,17 +1230,15 @@ dbus_connection_send_message_with_reply (DBusConnection *connection,
{
dbus_mutex_unlock (connection->mutex);
reply_handler_data_free (data);
-
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
return FALSE;
}
data->connection_added = TRUE;
/* Assign a serial to the message */
- if (_dbus_message_get_client_serial (message) == -1)
+ if (dbus_message_get_serial (message) == -1)
{
serial = _dbus_connection_get_next_client_serial (connection);
- _dbus_message_set_client_serial (message, serial);
+ _dbus_message_set_serial (message, serial);
}
data->handler = reply_handler;
@@ -1195,8 +1252,6 @@ dbus_connection_send_message_with_reply (DBusConnection *connection,
{
dbus_mutex_unlock (connection->mutex);
reply_handler_data_free (data);
-
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
return FALSE;
}
@@ -1206,8 +1261,6 @@ dbus_connection_send_message_with_reply (DBusConnection *connection,
dbus_mutex_unlock (connection->mutex);
dbus_message_unref (reply);
reply_handler_data_free (data);
-
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
return FALSE;
}
@@ -1216,23 +1269,20 @@ dbus_connection_send_message_with_reply (DBusConnection *connection,
/* Insert the serial in the pending replies hash. */
if (!_dbus_hash_table_insert_int (connection->pending_replies, serial, data))
{
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
dbus_mutex_unlock (connection->mutex);
- reply_handler_data_free (data);
-
+ reply_handler_data_free (data);
return FALSE;
}
dbus_mutex_unlock (connection->mutex);
- if (!dbus_connection_send_message (connection, message, NULL, result))
+ if (!dbus_connection_send (connection, message, NULL))
{
/* This will free the handler data too */
_dbus_hash_table_remove_int (connection->pending_replies, serial);
return FALSE;
}
- dbus_set_result (result, DBUS_RESULT_SUCCESS);
return TRUE;
}
@@ -1242,9 +1292,9 @@ dbus_connection_send_message_with_reply (DBusConnection *connection,
* has been reached. This function is used to do non-reentrant "method calls."
* If a reply is received, it is returned, and removed from the incoming
* message queue. If it is not received, #NULL is returned and the
- * result is set to #DBUS_RESULT_NO_REPLY. If something else goes
+ * error is set to #DBUS_ERROR_NO_REPLY. If something else goes
* wrong, result is set to whatever is appropriate, such as
- * #DBUS_RESULT_NO_MEMORY.
+ * #DBUS_ERROR_NO_MEMORY or #DBUS_ERROR_DISCONNECTED.
*
* @todo could use performance improvements (it keeps scanning
* the whole message queue for example) and has thread issues,
@@ -1253,15 +1303,15 @@ dbus_connection_send_message_with_reply (DBusConnection *connection,
* @param connection the connection
* @param message the message to send
* @param timeout_milliseconds timeout in milliseconds or -1 for default
- * @param result return location for result code
+ * @param error return location for error message
* @returns the message that is the reply or #NULL with an error code if the
* function fails.
*/
DBusMessage *
-dbus_connection_send_message_with_reply_and_block (DBusConnection *connection,
- DBusMessage *message,
- int timeout_milliseconds,
- DBusResultCode *result)
+dbus_connection_send_with_reply_and_block (DBusConnection *connection,
+ DBusMessage *message,
+ int timeout_milliseconds,
+ DBusError *error)
{
dbus_int32_t client_serial;
DBusList *link;
@@ -1279,8 +1329,11 @@ dbus_connection_send_message_with_reply_and_block (DBusConnection *connectio
if (timeout_milliseconds > _DBUS_ONE_HOUR_IN_MILLISECONDS * 6)
timeout_milliseconds = _DBUS_ONE_HOUR_IN_MILLISECONDS * 6;
- if (!dbus_connection_send_message (connection, message, &client_serial, result))
- return NULL;
+ if (!dbus_connection_send (connection, message, &client_serial))
+ {
+ _DBUS_SET_OOM (error);
+ return NULL;
+ }
message = NULL;
@@ -1318,13 +1371,10 @@ dbus_connection_send_message_with_reply_and_block (DBusConnection *connectio
{
DBusMessage *reply = link->data;
- if (_dbus_message_get_reply_serial (reply) == client_serial)
+ if (dbus_message_get_reply_serial (reply) == client_serial)
{
_dbus_list_remove_link (&connection->incoming_messages, link);
dbus_message_ref (reply);
-
- if (result)
- *result = DBUS_RESULT_SUCCESS;
dbus_mutex_unlock (connection->mutex);
return reply;
@@ -1345,14 +1395,14 @@ dbus_connection_send_message_with_reply_and_block (DBusConnection *connectio
(end_tv_usec - tv_usec) / 1000;
_dbus_verbose ("%d milliseconds remain\n", timeout_milliseconds);
_dbus_assert (timeout_milliseconds > 0);
-
+
goto block_again; /* not expired yet */
}
-
+
if (dbus_connection_get_is_connected (connection))
- dbus_set_result (result, DBUS_RESULT_NO_REPLY);
+ dbus_set_error (error, DBUS_ERROR_NO_REPLY, "Message did not receive a reply");
else
- dbus_set_result (result, DBUS_RESULT_DISCONNECTED);
+ dbus_set_error (error, DBUS_ERROR_DISCONNECTED, "Disconnected prior to receiving a reply");
dbus_mutex_unlock (connection->mutex);
@@ -1631,7 +1681,7 @@ dbus_connection_dispatch_message (DBusConnection *connection)
result = DBUS_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
- reply_serial = _dbus_message_get_reply_serial (message);
+ reply_serial = dbus_message_get_reply_serial (message);
reply_handler_data = _dbus_hash_table_lookup_int (connection->pending_replies,
reply_serial);
diff --git a/dbus/dbus-connection.h b/dbus/dbus-connection.h
index fd631c6d..6b480136 100644
--- a/dbus/dbus-connection.h
+++ b/dbus/dbus-connection.h
@@ -37,6 +37,7 @@ typedef struct DBusConnection DBusConnection;
typedef struct DBusWatch DBusWatch;
typedef struct DBusTimeout DBusTimeout;
typedef struct DBusMessageHandler DBusMessageHandler;
+typedef struct DBusPreallocatedSend DBusPreallocatedSend;
typedef enum
{
@@ -85,19 +86,18 @@ DBusMessage* dbus_connection_pop_message (DBusConnection *connecti
dbus_bool_t dbus_connection_dispatch_message (DBusConnection *connection);
-dbus_bool_t dbus_connection_send_message (DBusConnection *connection,
- DBusMessage *message,
- dbus_int32_t *client_serial,
- DBusResultCode *result);
-dbus_bool_t dbus_connection_send_message_with_reply (DBusConnection *connection,
- DBusMessage *message,
- DBusMessageHandler *reply_handler,
- int timeout_milliseconds,
- DBusResultCode *result);
-DBusMessage *dbus_connection_send_message_with_reply_and_block (DBusConnection *connection,
- DBusMessage *message,
- int timeout_milliseconds,
- DBusResultCode *result);
+dbus_bool_t dbus_connection_send (DBusConnection *connection,
+ DBusMessage *message,
+ dbus_int32_t *client_serial);
+dbus_bool_t dbus_connection_send_with_reply (DBusConnection *connection,
+ DBusMessage *message,
+ DBusMessageHandler *reply_handler,
+ int timeout_milliseconds);
+DBusMessage *dbus_connection_send_with_reply_and_block (DBusConnection *connection,
+ DBusMessage *message,
+ int timeout_milliseconds,
+ DBusError *error);
+
void dbus_connection_set_watch_functions (DBusConnection *connection,
@@ -169,6 +169,14 @@ void dbus_connection_set_max_live_messages_size (DBusConnection *connection,
long size);
long dbus_connection_get_max_live_messages_size (DBusConnection *connection);
+DBusPreallocatedSend* dbus_connection_preallocate_send (DBusConnection *connection);
+void dbus_connection_free_preallocated_send (DBusConnection *connection,
+ DBusPreallocatedSend *preallocated);
+void dbus_connection_send_preallocated (DBusConnection *connection,
+ DBusPreallocatedSend *preallocated,
+ DBusMessage *message,
+ dbus_int32_t *client_serial);
+
DBUS_END_DECLS;
diff --git a/dbus/dbus-errors.c b/dbus/dbus-errors.c
index e57d3538..da49e2ea 100644
--- a/dbus/dbus-errors.c
+++ b/dbus/dbus-errors.c
@@ -44,9 +44,6 @@
* @endcode
*
* @todo add docs with DBusError
- *
- * @todo add dbus_error_is_set() to check
- * whether an error is set.
*
* @{
*/
@@ -138,11 +135,9 @@ dbus_result_to_string (DBusResultCode code)
}
/**
- * Initializes a DBusError structure.
- *
- * @todo calling dbus_error_init() in here is no good,
- * for the same reason a GError* has to be set to NULL
- * before you pass it in.
+ * Initializes a DBusError structure. Does not allocate
+ * any memory; the error only needs to be freed
+ * if it is set at some point.
*
* @param error the DBusError.
*/
@@ -164,7 +159,8 @@ dbus_error_init (DBusError *error)
}
/**
- * Frees an error created by dbus_error_init().
+ * Frees an error that's been set (or just initialized),
+ * then reinitializes the error as in dbus_error_init().
*
* @param error memory where the error is stored.
*/
@@ -177,6 +173,8 @@ dbus_error_free (DBusError *error)
if (!real->const_message)
dbus_free (real->message);
+
+ dbus_error_init (error);
}
/**
@@ -211,6 +209,32 @@ dbus_set_error_const (DBusError *error,
}
/**
+ * Moves an error src into dest, freeing src and
+ * overwriting dest. Both src and dest must be initialized.
+ * src is reinitialized to an empty error. dest may not
+ * contain an existing error. If the destination is
+ * #NULL, just frees and reinits the source error.
+ *
+ * @param src the source error
+ * @param dest the destination error or #NULL
+ */
+void
+dbus_move_error (DBusError *src,
+ DBusError *dest)
+{
+ _dbus_assert (!dbus_error_is_set (dest));
+
+ if (dest)
+ {
+ dbus_error_free (dest);
+ *dest = *src;
+ dbus_error_init (src);
+ }
+ else
+ dbus_error_free (src);
+}
+
+/**
* Checks whether the error is set and has the given
* name.
* @param error the error
@@ -246,7 +270,7 @@ dbus_error_has_name (const DBusError *error,
dbus_bool_t
dbus_error_is_set (const DBusError *error)
{
- _dbus_assert (error != NULL);
+ _dbus_assert (error != NULL);
_dbus_assert ((error->name != NULL && error->message != NULL) ||
(error->name == NULL && error->message == NULL));
return error->name != NULL;
diff --git a/dbus/dbus-errors.h b/dbus/dbus-errors.h
index e6b88465..63edbdbf 100644
--- a/dbus/dbus-errors.h
+++ b/dbus/dbus-errors.h
@@ -56,6 +56,20 @@ struct DBusError
#define DBUS_ERROR_NO_MEMORY "org.freedesktop.DBus.Error.NoMemory"
#define DBUS_ERROR_SERVICE_DOES_NOT_EXIST "org.freedesktop.DBus.Error.ServiceDoesNotExist"
#define DBUS_ERROR_NO_REPLY "org.freedesktop.DBus.Error.NoReply"
+#define DBUS_ERROR_IO_ERROR "org.freedesktop.DBus.Error.IOError"
+#define DBUS_ERROR_BAD_ADDRESS "org.freedesktop.DBus.Error.BadAddress"
+#define DBUS_ERROR_NOT_SUPPORTED "org.freedesktop.DBus.Error.NotSupported"
+#define DBUS_ERROR_LIMITS_EXCEEDED "org.freedesktop.DBus.Error.LimitsExceeded"
+#define DBUS_ERROR_ACCESS_DENIED "org.freedesktop.DBus.Error.AccessDenied"
+#define DBUS_ERROR_AUTH_FAILED "org.freedesktop.DBus.Error.AuthFailed"
+#define DBUS_ERROR_NO_SERVER "org.freedesktop.DBus.Error.NoServer"
+#define DBUS_ERROR_TIMEOUT "org.freedesktop.DBus.Error.Timeout"
+#define DBUS_ERROR_NO_NETWORK "org.freedesktop.DBus.Error.NoNetwork"
+#define DBUS_ERROR_ADDRESS_IN_USE "org.freedesktop.DBus.Error.AddressInUse"
+#define DBUS_ERROR_DISCONNECTED "org.freedesktop.DBus.Error.Disconnected"
+#define DBUS_ERROR_INVALID_ARGS "org.freedesktop.DBus.Error.InvalidArgs"
+#define DBUS_ERROR_FILE_NOT_FOUND "org.freedesktop.DBus.Error.FileNotFound"
+#define DBUS_ERROR_UNKNOWN_MESSAGE "org.freedesktop.DBus.Error.UnknownMessage"
typedef enum
{
@@ -90,6 +104,8 @@ void dbus_set_error (DBusError *error,
void dbus_set_error_const (DBusError *error,
const char *name,
const char *message);
+void dbus_move_error (DBusError *src,
+ DBusError *dest);
dbus_bool_t dbus_error_has_name (const DBusError *error,
const char *name);
dbus_bool_t dbus_error_is_set (const DBusError *error);
diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c
index 8dedb56a..acd6d72f 100644
--- a/dbus/dbus-internals.c
+++ b/dbus/dbus-internals.c
@@ -1,7 +1,7 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-internals.c random utility stuff (internal to D-BUS implementation)
*
- * Copyright (C) 2002 Red Hat, Inc.
+ * Copyright (C) 2002, 2003 Red Hat, Inc.
*
* Licensed under the Academic Free License version 1.2
*
@@ -128,6 +128,13 @@
*/
/**
+ * Fixed "out of memory" error message, just to avoid
+ * making up a different string every time and wasting
+ * space.
+ */
+const char _dbus_no_memory_message[] = "Not enough memory";
+
+/**
* Prints a warning message to stderr.
*
* @param format printf-style format string.
@@ -181,104 +188,6 @@ _dbus_verbose_real (const char *format,
}
/**
- * Converts a UNIX errno into a DBusResultCode.
- *
- * @todo should cover more errnos, specifically those
- * from open().
- *
- * @param error_number the errno.
- * @returns the result code.
- */
-DBusResultCode
-_dbus_result_from_errno (int error_number)
-{
- switch (error_number)
- {
- case 0:
- return DBUS_RESULT_SUCCESS;
-
-#ifdef EPROTONOSUPPORT
- case EPROTONOSUPPORT:
- return DBUS_RESULT_NOT_SUPPORTED;
-#endif
-#ifdef EAFNOSUPPORT
- case EAFNOSUPPORT:
- return DBUS_RESULT_NOT_SUPPORTED;
-#endif
-#ifdef ENFILE
- case ENFILE:
- return DBUS_RESULT_LIMITS_EXCEEDED; /* kernel out of memory */
-#endif
-#ifdef EMFILE
- case EMFILE:
- return DBUS_RESULT_LIMITS_EXCEEDED;
-#endif
-#ifdef EACCES
- case EACCES:
- return DBUS_RESULT_ACCESS_DENIED;
-#endif
-#ifdef EPERM
- case EPERM:
- return DBUS_RESULT_ACCESS_DENIED;
-#endif
-#ifdef ENOBUFS
- case ENOBUFS:
- return DBUS_RESULT_NO_MEMORY;
-#endif
-#ifdef ENOMEM
- case ENOMEM:
- return DBUS_RESULT_NO_MEMORY;
-#endif
-#ifdef EINVAL
- case EINVAL:
- return DBUS_RESULT_FAILED;
-#endif
-#ifdef EBADF
- case EBADF:
- return DBUS_RESULT_FAILED;
-#endif
-#ifdef EFAULT
- case EFAULT:
- return DBUS_RESULT_FAILED;
-#endif
-#ifdef ENOTSOCK
- case ENOTSOCK:
- return DBUS_RESULT_FAILED;
-#endif
-#ifdef EISCONN
- case EISCONN:
- return DBUS_RESULT_FAILED;
-#endif
-#ifdef ECONNREFUSED
- case ECONNREFUSED:
- return DBUS_RESULT_NO_SERVER;
-#endif
-#ifdef ETIMEDOUT
- case ETIMEDOUT:
- return DBUS_RESULT_TIMEOUT;
-#endif
-#ifdef ENETUNREACH
- case ENETUNREACH:
- return DBUS_RESULT_NO_NETWORK;
-#endif
-#ifdef EADDRINUSE
- case EADDRINUSE:
- return DBUS_RESULT_ADDRESS_IN_USE;
-#endif
-#ifdef EEXIST
- case EEXIST:
- return DBUS_RESULT_FILE_NOT_FOUND;
-#endif
-#ifdef ENOENT
- case ENOENT:
- return DBUS_RESULT_FILE_NOT_FOUND;
-#endif
- }
-
- return DBUS_RESULT_FAILED;
-}
-
-/**
* Duplicates a string. Result must be freed with
* dbus_free(). Returns #NULL if memory allocation fails.
* If the string to be duplicated is #NULL, returns #NULL.
diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h
index 19a5cdc3..2576982d 100644
--- a/dbus/dbus-internals.h
+++ b/dbus/dbus-internals.h
@@ -94,6 +94,8 @@ do {
#define _DBUS_STRUCT_OFFSET(struct_type, member) \
((long) ((unsigned char*) &((struct_type*) 0)->member))
+#define _DBUS_ASSERT_ERROR_IS_SET(error) _dbus_assert ((error) == NULL || dbus_error_is_set ((error)))
+
/* This alignment thing is from ORBit2 */
/* Align a value upward to a boundary, expressed as a number of bytes.
* E.g. align to an 8-byte boundary with argument of 8.
@@ -146,6 +148,9 @@ void _dbus_verbose_bytes_of_string (const DBusString *str,
const char* _dbus_type_to_string (int type);
+extern const char _dbus_no_memory_message[];
+#define _DBUS_SET_OOM(error) dbus_set_error ((error), DBUS_ERROR_NO_MEMORY, _dbus_no_memory_message)
+
#ifdef DBUS_BUILD_TESTS
/* Memory debugging */
void _dbus_set_fail_alloc_counter (int until_next_fail);
diff --git a/dbus/dbus-keyring.c b/dbus/dbus-keyring.c
index c5c6a0b5..db432be8 100644
--- a/dbus/dbus-keyring.c
+++ b/dbus/dbus-keyring.c
@@ -399,6 +399,7 @@ _dbus_keyring_reload (DBusKeyring *keyring,
int n_keys;
int i;
long now;
+ DBusError tmp_error;
if (!_dbus_string_init (&contents, _DBUS_INT_MAX))
{
@@ -434,14 +435,15 @@ _dbus_keyring_reload (DBusKeyring *keyring,
have_lock = TRUE;
}
- result = _dbus_file_get_contents (&contents,
- &keyring->filename);
-
- if (result != DBUS_RESULT_SUCCESS)
+ dbus_error_init (&tmp_error);
+ if (!_dbus_file_get_contents (&contents,
+ &keyring->filename,
+ &tmp_error))
{
_dbus_verbose ("Failed to load keyring file: %s\n",
- dbus_result_to_string (result));
+ tmp_error.message);
/* continue with empty keyring file, so we recreate it */
+ dbus_error_free (&tmp_error);
}
if (!_dbus_string_validate_ascii (&contents, 0,
diff --git a/dbus/dbus-list.c b/dbus/dbus-list.c
index 7b306924..d0ca8dfa 100644
--- a/dbus/dbus-list.c
+++ b/dbus/dbus-list.c
@@ -678,6 +678,19 @@ _dbus_list_foreach (DBusList **list,
}
}
+/**
+ * Check whether length is exactly one.
+ *
+ * @param list the list
+ * @returns #TRUE if length is exactly one
+ */
+dbus_bool_t
+_dbus_list_length_is_one (DBusList **list)
+{
+ return (*list != NULL &&
+ (*list)->next == *list);
+}
+
/** @} */
#ifdef DBUS_BUILD_TESTS
@@ -713,6 +726,11 @@ verify_list (DBusList **list)
while (link != *list);
_dbus_assert (length == _dbus_list_get_length (list));
+
+ if (length == 1)
+ _dbus_assert (_dbus_list_length_is_one (list));
+ else
+ _dbus_assert (!_dbus_list_length_is_one (list));
}
static dbus_bool_t
diff --git a/dbus/dbus-list.h b/dbus/dbus-list.h
index 2c55c6bc..3f23f2ec 100644
--- a/dbus/dbus-list.h
+++ b/dbus/dbus-list.h
@@ -73,6 +73,8 @@ void _dbus_list_append_link (DBusList **list,
void _dbus_list_prepend_link (DBusList **list,
DBusList *link);
+dbus_bool_t _dbus_list_length_is_one (DBusList **list);
+
void _dbus_list_foreach (DBusList **list,
DBusForeachFunction function,
void *data);
diff --git a/dbus/dbus-message-builder.c b/dbus/dbus-message-builder.c
index 54b5de70..e34e1b55 100644
--- a/dbus/dbus-message-builder.c
+++ b/dbus/dbus-message-builder.c
@@ -314,7 +314,7 @@ _dbus_message_data_load (DBusString *dest,
const DBusString *filename)
{
DBusString file;
- DBusResultCode result;
+ DBusError error;
DBusString line;
dbus_bool_t retval;
int line_no;
@@ -340,14 +340,15 @@ _dbus_message_data_load (DBusString *dest,
_dbus_string_get_const_data (filename, &s);
_dbus_verbose ("Loading %s\n", s);
}
-
- if ((result = _dbus_file_get_contents (&file, filename)) != DBUS_RESULT_SUCCESS)
+
+ dbus_error_init (&error);
+ if (!_dbus_file_get_contents (&file, filename, &error))
{
const char *s;
_dbus_string_get_const_data (filename, &s);
_dbus_warn ("Getting contents of %s failed: %s\n",
- s, dbus_result_to_string (result));
-
+ s, error.message);
+ dbus_error_free (&error);
goto out;
}
diff --git a/dbus/dbus-message-internal.h b/dbus/dbus-message-internal.h
index 44ce62a3..86796da9 100644
--- a/dbus/dbus-message-internal.h
+++ b/dbus/dbus-message-internal.h
@@ -34,17 +34,12 @@ void _dbus_message_get_network_data (DBusMessage *message,
const DBusString **header,
const DBusString **body);
-void _dbus_message_lock (DBusMessage *message);
-void _dbus_message_unlock (DBusMessage *message);
-void _dbus_message_set_client_serial (DBusMessage *message,
- dbus_int32_t client_serial);
-dbus_int32_t _dbus_message_get_client_serial (DBusMessage *message);
-dbus_bool_t _dbus_message_set_reply_serial (DBusMessage *message,
- dbus_int32_t reply_serial);
-dbus_int32_t _dbus_message_get_reply_serial (DBusMessage *message);
-void _dbus_message_add_size_counter (DBusMessage *message,
- DBusCounter *counter);
-
+void _dbus_message_lock (DBusMessage *message);
+void _dbus_message_unlock (DBusMessage *message);
+void _dbus_message_set_serial (DBusMessage *message,
+ dbus_int32_t serial);
+void _dbus_message_add_size_counter (DBusMessage *message,
+ DBusCounter *counter);
DBusMessageLoader* _dbus_message_loader_new (void);
void _dbus_message_loader_ref (DBusMessageLoader *loader);
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index a25480cb..6a3c6618 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -532,28 +532,22 @@ set_string_field (DBusMessage *message,
}
/**
- * Sets the client serial of a message.
+ * Sets the serial number of a message.
* This can only be done once on a message.
- *
- * @todo client_serial should be called simply
- * "serial"; it's in outgoing messages for both
- * the client and the server, it's only client-specific
- * in the message bus case. It's more like origin_serial
- * or something.
*
* @param message the message
- * @param client_serial the client serial
+ * @param serial the serial
*/
void
-_dbus_message_set_client_serial (DBusMessage *message,
- dbus_int32_t client_serial)
+_dbus_message_set_serial (DBusMessage *message,
+ dbus_int32_t serial)
{
_dbus_assert (!message->locked);
- _dbus_assert (_dbus_message_get_client_serial (message) < 0);
+ _dbus_assert (dbus_message_get_serial (message) < 0);
set_int_field (message, FIELD_CLIENT_SERIAL,
- client_serial);
- message->client_serial = client_serial;
+ serial);
+ message->client_serial = serial;
}
/**
@@ -565,7 +559,7 @@ _dbus_message_set_client_serial (DBusMessage *message,
* @returns #FALSE if not enough memory
*/
dbus_bool_t
-_dbus_message_set_reply_serial (DBusMessage *message,
+dbus_message_set_reply_serial (DBusMessage *message,
dbus_int32_t reply_serial)
{
_dbus_assert (!message->locked);
@@ -581,19 +575,15 @@ _dbus_message_set_reply_serial (DBusMessage *message,
}
/**
- * Returns the client serial of a message or
- * -1 if none has been specified.
- *
- * @todo see note in _dbus_message_set_client_serial()
- * about how client_serial is a misnomer
- *
- * @todo this function should be public, after renaming it.
+ * Returns the serial of a message or -1 if none has been specified.
+ * The message's serial number is provided by the application sending
+ * the message and is used to identify replies to this message.
*
* @param message the message
* @returns the client serial
*/
dbus_int32_t
-_dbus_message_get_client_serial (DBusMessage *message)
+dbus_message_get_serial (DBusMessage *message)
{
return message->client_serial;
}
@@ -606,7 +596,7 @@ _dbus_message_get_client_serial (DBusMessage *message)
* @returns the reply serial
*/
dbus_int32_t
-_dbus_message_get_reply_serial (DBusMessage *message)
+dbus_message_get_reply_serial (DBusMessage *message)
{
return message->reply_serial;
}
@@ -845,8 +835,8 @@ dbus_message_new_reply (DBusMessage *original_message)
if (message == NULL)
return NULL;
- if (!_dbus_message_set_reply_serial (message,
- _dbus_message_get_client_serial (original_message)))
+ if (!dbus_message_set_reply_serial (message,
+ dbus_message_get_serial (original_message)))
{
dbus_message_unref (message);
return NULL;
@@ -881,8 +871,8 @@ dbus_message_new_error_reply (DBusMessage *original_message,
if (message == NULL)
return NULL;
- if (!_dbus_message_set_reply_serial (message,
- _dbus_message_get_client_serial (original_message)))
+ if (!dbus_message_set_reply_serial (message,
+ dbus_message_get_serial (original_message)))
{
dbus_message_unref (message);
return NULL;
@@ -1542,12 +1532,14 @@ dbus_message_append_dict (DBusMessage *message,
* stored. The list is terminated with 0.
*
* @param message the message
+ * @param error error to be filled in on failure
* @param first_arg_type the first argument type
* @param ... location for first argument value, then list of type-location pairs
- * @returns result code
+ * @returns #FALSE if the error was set
*/
-DBusResultCode
+dbus_bool_t
dbus_message_get_args (DBusMessage *message,
+ DBusError *error,
int first_arg_type,
...)
{
@@ -1555,7 +1547,7 @@ dbus_message_get_args (DBusMessage *message,
va_list var_args;
va_start (var_args, first_arg_type);
- retval = dbus_message_get_args_valist (message, first_arg_type, var_args);
+ retval = dbus_message_get_args_valist (message, error, first_arg_type, var_args);
va_end (var_args);
return retval;
@@ -1575,22 +1567,31 @@ dbus_message_get_args (DBusMessage *message,
*
* @see dbus_message_get_args
* @param message the message
+ * @param error error to be filled in
* @param first_arg_type type of the first argument
* @param var_args return location for first argument, followed by list of type/location pairs
- * @returns result code
+ * @returns #FALSE if error was set
*/
-DBusResultCode
+dbus_bool_t
dbus_message_get_args_valist (DBusMessage *message,
+ DBusError *error,
int first_arg_type,
va_list var_args)
{
int spec_type, msg_type, i;
DBusMessageIter *iter;
-
+ dbus_bool_t retval;
+
iter = dbus_message_get_args_iter (message);
if (iter == NULL)
- return DBUS_RESULT_NO_MEMORY;
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory to get message arguments");
+ return FALSE;
+ }
+
+ retval = FALSE;
spec_type = first_arg_type;
i = 0;
@@ -1601,13 +1602,13 @@ dbus_message_get_args_valist (DBusMessage *message,
if (msg_type != spec_type)
{
- _dbus_verbose ("Argument %d is specified to be of type \"%s\", but "
- "is actually of type \"%s\"\n", i,
- _dbus_type_to_string (spec_type),
- _dbus_type_to_string (msg_type));
- dbus_message_iter_unref (iter);
+ dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
+ "Argument %d is specified to be of type \"%s\", but "
+ "is actually of type \"%s\"\n", i,
+ _dbus_type_to_string (spec_type),
+ _dbus_type_to_string (msg_type));
- return DBUS_RESULT_INVALID_ARGS;
+ goto out;
}
switch (spec_type)
@@ -1661,7 +1662,11 @@ dbus_message_get_args_valist (DBusMessage *message,
*ptr = dbus_message_iter_get_string (iter);
if (!*ptr)
- return DBUS_RESULT_NO_MEMORY;
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory for argument %d", i);
+ goto out;
+ }
break;
}
@@ -1675,8 +1680,11 @@ dbus_message_get_args_valist (DBusMessage *message,
len = va_arg (var_args, int *);
if (!dbus_message_iter_get_boolean_array (iter, ptr, len))
- return DBUS_RESULT_NO_MEMORY;
-
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory for argument %d", i);
+ goto out;
+ }
break;
}
@@ -1689,7 +1697,11 @@ dbus_message_get_args_valist (DBusMessage *message,
len = va_arg (var_args, int *);
if (!dbus_message_iter_get_int32_array (iter, ptr, len))
- return DBUS_RESULT_NO_MEMORY;
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory for argument %d", i);
+ goto out;
+ }
break;
}
@@ -1703,7 +1715,11 @@ dbus_message_get_args_valist (DBusMessage *message,
len = va_arg (var_args, int *);
if (!dbus_message_iter_get_uint32_array (iter, ptr, len))
- return DBUS_RESULT_NO_MEMORY;
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory for argument %d", i);
+ goto out;
+ }
break;
}
@@ -1717,8 +1733,11 @@ dbus_message_get_args_valist (DBusMessage *message,
len = va_arg (var_args, int *);
if (!dbus_message_iter_get_double_array (iter, ptr, len))
- return DBUS_RESULT_NO_MEMORY;
-
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory for argument %d", i);
+ goto out;
+ }
break;
}
@@ -1731,8 +1750,11 @@ dbus_message_get_args_valist (DBusMessage *message,
len = va_arg (var_args, int *);
if (!dbus_message_iter_get_byte_array (iter, ptr, len))
- return DBUS_RESULT_NO_MEMORY;
-
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory for argument %d", i);
+ goto out;
+ }
break;
}
case DBUS_TYPE_STRING_ARRAY:
@@ -1744,7 +1766,11 @@ dbus_message_get_args_valist (DBusMessage *message,
len = va_arg (var_args, int *);
if (!dbus_message_iter_get_string_array (iter, ptr, len))
- return DBUS_RESULT_NO_MEMORY;
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory for argument %d", i);
+ goto out;
+ }
break;
}
case DBUS_TYPE_DICT:
@@ -1754,7 +1780,11 @@ dbus_message_get_args_valist (DBusMessage *message,
dict = va_arg (var_args, DBusDict **);
if (!dbus_message_iter_get_dict (iter, dict))
- return DBUS_RESULT_NO_MEMORY;
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory for argument %d", i);
+ goto out;
+ }
break;
}
default:
@@ -1763,17 +1793,20 @@ dbus_message_get_args_valist (DBusMessage *message,
spec_type = va_arg (var_args, int);
if (spec_type != 0 && !dbus_message_iter_next (iter))
- {
- _dbus_verbose ("More fields than exist in the message were specified or field is corrupt\n");
+ {
+ dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
+ "Message has only %d arguments, but more were expected", i);
+ goto out;
+ }
- dbus_message_iter_unref (iter);
- return DBUS_RESULT_INVALID_ARGS;
- }
i++;
}
-
+
+ retval = TRUE;
+
+ out:
dbus_message_iter_unref (iter);
- return DBUS_RESULT_SUCCESS;
+ return retval;
}
/**
@@ -2318,6 +2351,10 @@ dbus_message_name_is (DBusMessage *message,
* DBusTransport implementation. The DBusTransport then hands off
* the loaded messages to a DBusConnection, making the messages
* visible to the application.
+ *
+ * @todo write tests for break-loader that a) randomly delete header
+ * fields and b) set string fields to zero-length and other funky
+ * values.
*
*/
@@ -2624,6 +2661,13 @@ decode_header_data (const DBusString *data,
}
}
+ if (fields[FIELD_NAME].offset < 0)
+ {
+ _dbus_verbose ("No %s field provided\n",
+ DBUS_HEADER_FIELD_NAME);
+ return FALSE;
+ }
+
if (message_padding)
*message_padding = header_len - pos;
@@ -2970,13 +3014,13 @@ check_message_handling (DBusMessage *message)
retval = FALSE;
iter = NULL;
- client_serial = _dbus_message_get_client_serial (message);
+ client_serial = dbus_message_get_serial (message);
- /* can't use set_client_serial due to the assertions at the start of it */
+ /* can't use set_serial due to the assertions at the start of it */
set_int_field (message, FIELD_CLIENT_SERIAL,
client_serial);
-
- if (client_serial != _dbus_message_get_client_serial (message))
+
+ if (client_serial != dbus_message_get_serial (message))
{
_dbus_warn ("get/set cycle for client_serial did not succeed\n");
goto failed;
@@ -3215,14 +3259,15 @@ dbus_internal_do_not_use_load_message_file (const DBusString *filename,
if (is_raw)
{
- DBusResultCode result;
+ DBusError error;
- result = _dbus_file_get_contents (data, filename);
- if (result != DBUS_RESULT_SUCCESS)
+ dbus_error_init (&error);
+ if (!_dbus_file_get_contents (data, filename, &error))
{
const char *s;
_dbus_string_get_const_data (filename, &s);
- _dbus_warn ("Could not load message file %s\n", s);
+ _dbus_warn ("Could not load message file %s: %s\n", s, error.message);
+ dbus_error_free (&error);
goto failed;
}
}
@@ -3397,7 +3442,7 @@ process_test_subdir (const DBusString *test_base_dir,
DBusString filename;
DBusDirIter *dir;
dbus_bool_t retval;
- DBusResultCode result;
+ DBusError error;
retval = FALSE;
dir = NULL;
@@ -3417,22 +3462,23 @@ process_test_subdir (const DBusString *test_base_dir,
_dbus_string_free (&filename);
if (!_dbus_string_init (&filename, _DBUS_INT_MAX))
_dbus_assert_not_reached ("didn't allocate filename string\n");
-
- dir = _dbus_directory_open (&test_directory, &result);
+
+ dbus_error_init (&error);
+ dir = _dbus_directory_open (&test_directory, &error);
if (dir == NULL)
{
const char *s;
_dbus_string_get_const_data (&test_directory, &s);
_dbus_warn ("Could not open %s: %s\n", s,
- dbus_result_to_string (result));
+ error.message);
+ dbus_error_free (&error);
goto failed;
}
printf ("Testing:\n");
- result = DBUS_RESULT_SUCCESS;
next:
- while (_dbus_directory_get_next_file (dir, &filename, &result))
+ while (_dbus_directory_get_next_file (dir, &filename, &error))
{
DBusString full_path;
dbus_bool_t is_raw;
@@ -3480,12 +3526,13 @@ process_test_subdir (const DBusString *test_base_dir,
_dbus_string_free (&full_path);
}
- if (result != DBUS_RESULT_SUCCESS)
+ if (dbus_error_is_set (&error))
{
const char *s;
_dbus_string_get_const_data (&test_directory, &s);
_dbus_warn ("Could not get next file in %s: %s\n",
- s, dbus_result_to_string (result));
+ s, error.message);
+ dbus_error_free (&error);
goto failed;
}
@@ -3563,7 +3610,7 @@ _dbus_message_test (const char *test_data_dir)
/* Test the vararg functions */
message = dbus_message_new ("org.freedesktop.DBus.Test", "testMessage");
- _dbus_message_set_client_serial (message, 1);
+ _dbus_message_set_serial (message, 1);
dbus_message_append_args (message,
DBUS_TYPE_INT32, -0x12345678,
DBUS_TYPE_STRING, "Test string",
@@ -3574,13 +3621,13 @@ _dbus_message_test (const char *test_data_dir)
_dbus_string_get_length (&message->header));
_dbus_verbose_bytes_of_string (&message->body, 0,
_dbus_string_get_length (&message->body));
-
- if (dbus_message_get_args (message,
- DBUS_TYPE_INT32, &our_int,
- DBUS_TYPE_STRING, &our_str,
- DBUS_TYPE_DOUBLE, &our_double,
- DBUS_TYPE_BOOLEAN, &our_bool,
- 0) != DBUS_RESULT_SUCCESS)
+
+ if (!dbus_message_get_args (message, NULL,
+ DBUS_TYPE_INT32, &our_int,
+ DBUS_TYPE_STRING, &our_str,
+ DBUS_TYPE_DOUBLE, &our_double,
+ DBUS_TYPE_BOOLEAN, &our_bool,
+ 0))
_dbus_assert_not_reached ("Could not get arguments");
if (our_int != -0x12345678)
@@ -3599,8 +3646,8 @@ _dbus_message_test (const char *test_data_dir)
dbus_message_unref (message);
message = dbus_message_new ("org.freedesktop.DBus.Test", "testMessage");
- _dbus_message_set_client_serial (message, 1);
- _dbus_message_set_reply_serial (message, 0x12345678);
+ _dbus_message_set_serial (message, 1);
+ dbus_message_set_reply_serial (message, 0x12345678);
dbus_message_append_string (message, "Test string");
dbus_message_append_int32 (message, -0x12345678);
@@ -3645,7 +3692,7 @@ _dbus_message_test (const char *test_data_dir)
if (!message)
_dbus_assert_not_reached ("received a NULL message");
- if (_dbus_message_get_reply_serial (message) != 0x12345678)
+ if (dbus_message_get_reply_serial (message) != 0x12345678)
_dbus_assert_not_reached ("reply serial fields differ");
message_iter_test (message);
diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
index 4ea63060..d30a0a3d 100644
--- a/dbus/dbus-message.h
+++ b/dbus/dbus-message.h
@@ -48,17 +48,21 @@ DBusMessage *dbus_message_new_from_message (const DBusMessage *message);
void dbus_message_ref (DBusMessage *message);
void dbus_message_unref (DBusMessage *message);
-const char* dbus_message_get_name (DBusMessage *message);
-const char* dbus_message_get_service (DBusMessage *message);
-dbus_bool_t dbus_message_set_sender (DBusMessage *message,
- const char *sender);
-const char* dbus_message_get_sender (DBusMessage *message);
-void dbus_message_set_is_error (DBusMessage *message,
- dbus_bool_t is_error_reply);
-dbus_bool_t dbus_message_get_is_error (DBusMessage *message);
+const char* dbus_message_get_name (DBusMessage *message);
+const char* dbus_message_get_service (DBusMessage *message);
+dbus_bool_t dbus_message_set_sender (DBusMessage *message,
+ const char *sender);
+const char* dbus_message_get_sender (DBusMessage *message);
+void dbus_message_set_is_error (DBusMessage *message,
+ dbus_bool_t is_error_reply);
+dbus_bool_t dbus_message_get_is_error (DBusMessage *message);
+dbus_bool_t dbus_message_name_is (DBusMessage *message,
+ const char *name);
+dbus_int32_t dbus_message_get_serial (DBusMessage *message);
+dbus_bool_t dbus_message_set_reply_serial (DBusMessage *message,
+ dbus_int32_t reply_serial);
+dbus_int32_t dbus_message_get_reply_serial (DBusMessage *message);
-dbus_bool_t dbus_message_name_is (DBusMessage *message,
- const char *name);
dbus_bool_t dbus_message_append_args (DBusMessage *message,
int first_arg_type,
@@ -99,13 +103,14 @@ dbus_bool_t dbus_message_append_dict (DBusMessage *message,
DBusDict *dict);
DBusMessageIter *dbus_message_get_args_iter (DBusMessage *message);
-DBusResultCode dbus_message_get_args (DBusMessage *message,
- int first_arg_type,
- ...);
-DBusResultCode dbus_message_get_args_valist (DBusMessage *message,
- int first_arg_type,
- va_list var_args);
-
+dbus_bool_t dbus_message_get_args (DBusMessage *message,
+ DBusError *error,
+ int first_arg_type,
+ ...);
+dbus_bool_t dbus_message_get_args_valist (DBusMessage *message,
+ DBusError *error,
+ int first_arg_type,
+ va_list var_args);
void dbus_message_iter_ref (DBusMessageIter *iter);
diff --git a/dbus/dbus-sha.c b/dbus/dbus-sha.c
index 2f73e363..8f047122 100644
--- a/dbus/dbus-sha.c
+++ b/dbus/dbus-sha.c
@@ -752,6 +752,7 @@ process_test_data (const char *test_data_dir)
int line_no;
dbus_bool_t retval;
int success_count;
+ DBusError error;
retval = FALSE;
@@ -784,21 +785,24 @@ process_test_data (const char *test_data_dir)
if (!_dbus_concat_dir_and_file (&results_file, &tmp))
_dbus_assert_not_reached ("no memory");
- if (_dbus_file_get_contents (&tests, &tests_file) != DBUS_RESULT_SUCCESS)
+ dbus_error_init (&error);
+ if (!_dbus_file_get_contents (&tests, &tests_file, &error))
{
const char *s;
_dbus_string_get_const_data (&tests_file, &s);
- fprintf (stderr, "could not load test data file %s\n",
- s);
+ fprintf (stderr, "could not load test data file %s: %s\n",
+ s, error.message);
+ dbus_error_free (&error);
goto out;
}
- if (_dbus_file_get_contents (&results, &results_file) != DBUS_RESULT_SUCCESS)
+ if (!_dbus_file_get_contents (&results, &results_file, &error))
{
const char *s;
_dbus_string_get_const_data (&results_file, &s);
- fprintf (stderr, "could not load results data file %s\n",
- s);
+ fprintf (stderr, "could not load results data file %s: %s\n",
+ s, error.message);
+ dbus_error_free (&error);
goto out;
}
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c
index d096ce3e..5d0be321 100644
--- a/dbus/dbus-sysdeps.c
+++ b/dbus/dbus-sysdeps.c
@@ -1,7 +1,7 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-sysdeps.c Wrappers around system/libc features (internal to D-BUS implementation)
*
- * Copyright (C) 2002 Red Hat, Inc.
+ * Copyright (C) 2002, 2003 Red Hat, Inc.
*
* Licensed under the Academic Free License version 1.2
*
@@ -1604,11 +1604,13 @@ _dbus_get_current_time (long *tv_sec,
*
* @param str the string to append to
* @param filename filename to load
- * @returns result
+ * @param error place to set an error
+ * @returns #FALSE if error was set
*/
-DBusResultCode
+dbus_bool_t
_dbus_file_get_contents (DBusString *str,
- const DBusString *filename)
+ const DBusString *filename,
+ DBusError *error)
{
int fd;
struct stat sb;
@@ -1621,28 +1623,32 @@ _dbus_file_get_contents (DBusString *str,
/* O_BINARY useful on Cygwin */
fd = open (filename_c, O_RDONLY | O_BINARY);
if (fd < 0)
- return _dbus_result_from_errno (errno);
+ {
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "%s", _dbus_strerror (errno));
+ return FALSE;
+ }
if (fstat (fd, &sb) < 0)
{
- DBusResultCode result;
-
- result = _dbus_result_from_errno (errno); /* prior to close() */
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "%s", _dbus_strerror (errno));
_dbus_verbose ("fstat() failed: %s",
_dbus_strerror (errno));
close (fd);
- return result;
+ return FALSE;
}
if (sb.st_size > _DBUS_ONE_MEGABYTE)
{
- _dbus_verbose ("File size %lu is too large.\n",
+ dbus_set_error (error, DBUS_ERROR_FAILED,
+ "File size %lu is too large.\n",
(unsigned long) sb.st_size);
close (fd);
- return DBUS_RESULT_FAILED;
+ return FALSE;
}
total = 0;
@@ -1657,34 +1663,35 @@ _dbus_file_get_contents (DBusString *str,
sb.st_size - total);
if (bytes_read <= 0)
{
- DBusResultCode result;
-
- result = _dbus_result_from_errno (errno); /* prior to close() */
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "%s", _dbus_strerror (errno));
_dbus_verbose ("read() failed: %s",
_dbus_strerror (errno));
close (fd);
_dbus_string_set_length (str, orig_len);
- return result;
+ return FALSE;
}
else
total += bytes_read;
}
close (fd);
- return DBUS_RESULT_SUCCESS;
+ return TRUE;
}
else if (sb.st_size != 0)
{
_dbus_verbose ("Can only open regular files at the moment.\n");
+ dbus_set_error (error, DBUS_ERROR_FAILED,
+ "Not a regular file");
close (fd);
- return DBUS_RESULT_FAILED;
+ return FALSE;
}
else
{
close (fd);
- return DBUS_RESULT_SUCCESS;
+ return TRUE;
}
}
@@ -1972,12 +1979,12 @@ struct DBusDirIter
* Open a directory to iterate over.
*
* @param filename the directory name
- * @param result return location for error code if #NULL returned
+ * @param error exception return object or #NULL
* @returns new iterator, or #NULL on error
*/
DBusDirIter*
_dbus_directory_open (const DBusString *filename,
- DBusResultCode *result)
+ DBusError *error)
{
DIR *d;
DBusDirIter *iter;
@@ -1988,15 +1995,16 @@ _dbus_directory_open (const DBusString *filename,
d = opendir (filename_c);
if (d == NULL)
{
- dbus_set_result (result, _dbus_result_from_errno (errno));
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "%s", _dbus_strerror (errno));
return NULL;
}
-
iter = dbus_new0 (DBusDirIter, 1);
if (iter == NULL)
{
closedir (d);
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "Could not allocate memory for directory iterator");
return NULL;
}
@@ -2006,39 +2014,38 @@ _dbus_directory_open (const DBusString *filename,
}
/**
- * Get next file in the directory. Will not return "." or ".."
- * on UNIX. If an error occurs, the contents of "filename"
- * are undefined. #DBUS_RESULT_SUCCESS is always returned
- * in result if no error occurs.
+ * Get next file in the directory. Will not return "." or ".." on
+ * UNIX. If an error occurs, the contents of "filename" are
+ * undefined. The error is never set if the function succeeds.
*
* @todo for thread safety, I think we have to use
* readdir_r(). (GLib has the same issue, should file a bug.)
*
* @param iter the iterator
* @param filename string to be set to the next file in the dir
- * @param result return location for error, or #DBUS_RESULT_SUCCESS
+ * @param error return location for error
* @returns #TRUE if filename was filled in with a new filename
*/
dbus_bool_t
_dbus_directory_get_next_file (DBusDirIter *iter,
DBusString *filename,
- DBusResultCode *result)
+ DBusError *error)
{
/* we always have to put something in result, since return
* value means whether there's a filename and doesn't
* reliably indicate whether an error was set.
*/
struct dirent *ent;
-
- dbus_set_result (result, DBUS_RESULT_SUCCESS);
again:
errno = 0;
ent = readdir (iter->d);
if (ent == NULL)
{
- dbus_set_result (result,
- _dbus_result_from_errno (errno));
+ if (errno != 0)
+ dbus_set_error (error,
+ _dbus_error_from_errno (errno),
+ "%s", _dbus_strerror (errno));
return FALSE;
}
else if (ent->d_name[0] == '.' &&
@@ -2050,7 +2057,8 @@ _dbus_directory_get_next_file (DBusDirIter *iter,
_dbus_string_set_length (filename, 0);
if (!_dbus_string_append (filename, ent->d_name))
{
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory to read directory entry");
return FALSE;
}
else
@@ -2501,4 +2509,249 @@ _dbus_fd_set_close_on_exec (int fd)
fcntl (fd, F_SETFD, val);
}
+
+/**
+ * Converts a UNIX errno into a DBusResultCode.
+ *
+ * @todo should cover more errnos, specifically those
+ * from open().
+ *
+ * @param error_number the errno.
+ * @returns the result code.
+ */
+DBusResultCode
+_dbus_result_from_errno (int error_number)
+{
+ switch (error_number)
+ {
+ case 0:
+ return DBUS_RESULT_SUCCESS;
+
+#ifdef EPROTONOSUPPORT
+ case EPROTONOSUPPORT:
+ return DBUS_RESULT_NOT_SUPPORTED;
+#endif
+#ifdef EAFNOSUPPORT
+ case EAFNOSUPPORT:
+ return DBUS_RESULT_NOT_SUPPORTED;
+#endif
+#ifdef ENFILE
+ case ENFILE:
+ return DBUS_RESULT_LIMITS_EXCEEDED; /* kernel out of memory */
+#endif
+#ifdef EMFILE
+ case EMFILE:
+ return DBUS_RESULT_LIMITS_EXCEEDED;
+#endif
+#ifdef EACCES
+ case EACCES:
+ return DBUS_RESULT_ACCESS_DENIED;
+#endif
+#ifdef EPERM
+ case EPERM:
+ return DBUS_RESULT_ACCESS_DENIED;
+#endif
+#ifdef ENOBUFS
+ case ENOBUFS:
+ return DBUS_RESULT_NO_MEMORY;
+#endif
+#ifdef ENOMEM
+ case ENOMEM:
+ return DBUS_RESULT_NO_MEMORY;
+#endif
+#ifdef EINVAL
+ case EINVAL:
+ return DBUS_RESULT_FAILED;
+#endif
+#ifdef EBADF
+ case EBADF:
+ return DBUS_RESULT_FAILED;
+#endif
+#ifdef EFAULT
+ case EFAULT:
+ return DBUS_RESULT_FAILED;
+#endif
+#ifdef ENOTSOCK
+ case ENOTSOCK:
+ return DBUS_RESULT_FAILED;
+#endif
+#ifdef EISCONN
+ case EISCONN:
+ return DBUS_RESULT_FAILED;
+#endif
+#ifdef ECONNREFUSED
+ case ECONNREFUSED:
+ return DBUS_RESULT_NO_SERVER;
+#endif
+#ifdef ETIMEDOUT
+ case ETIMEDOUT:
+ return DBUS_RESULT_TIMEOUT;
+#endif
+#ifdef ENETUNREACH
+ case ENETUNREACH:
+ return DBUS_RESULT_NO_NETWORK;
+#endif
+#ifdef EADDRINUSE
+ case EADDRINUSE:
+ return DBUS_RESULT_ADDRESS_IN_USE;
+#endif
+#ifdef EEXIST
+ case EEXIST:
+ return DBUS_RESULT_FILE_NOT_FOUND;
+#endif
+#ifdef ENOENT
+ case ENOENT:
+ return DBUS_RESULT_FILE_NOT_FOUND;
+#endif
+ }
+
+ return DBUS_RESULT_FAILED;
+}
+
+/**
+ * Converts a UNIX errno into a #DBusError name.
+ *
+ * @todo should cover more errnos, specifically those
+ * from open().
+ *
+ * @param error_number the errno.
+ * @returns an error name
+ */
+const char*
+_dbus_error_from_errno (int error_number)
+{
+ switch (error_number)
+ {
+ case 0:
+ return DBUS_ERROR_FAILED;
+
+#ifdef EPROTONOSUPPORT
+ case EPROTONOSUPPORT:
+ return DBUS_ERROR_NOT_SUPPORTED;
+#endif
+#ifdef EAFNOSUPPORT
+ case EAFNOSUPPORT:
+ return DBUS_ERROR_NOT_SUPPORTED;
+#endif
+#ifdef ENFILE
+ case ENFILE:
+ return DBUS_ERROR_LIMITS_EXCEEDED; /* kernel out of memory */
+#endif
+#ifdef EMFILE
+ case EMFILE:
+ return DBUS_ERROR_LIMITS_EXCEEDED;
+#endif
+#ifdef EACCES
+ case EACCES:
+ return DBUS_ERROR_ACCESS_DENIED;
+#endif
+#ifdef EPERM
+ case EPERM:
+ return DBUS_ERROR_ACCESS_DENIED;
+#endif
+#ifdef ENOBUFS
+ case ENOBUFS:
+ return DBUS_ERROR_NO_MEMORY;
+#endif
+#ifdef ENOMEM
+ case ENOMEM:
+ return DBUS_ERROR_NO_MEMORY;
+#endif
+#ifdef EINVAL
+ case EINVAL:
+ return DBUS_ERROR_FAILED;
+#endif
+#ifdef EBADF
+ case EBADF:
+ return DBUS_ERROR_FAILED;
+#endif
+#ifdef EFAULT
+ case EFAULT:
+ return DBUS_ERROR_FAILED;
+#endif
+#ifdef ENOTSOCK
+ case ENOTSOCK:
+ return DBUS_ERROR_FAILED;
+#endif
+#ifdef EISCONN
+ case EISCONN:
+ return DBUS_ERROR_FAILED;
+#endif
+#ifdef ECONNREFUSED
+ case ECONNREFUSED:
+ return DBUS_ERROR_NO_SERVER;
+#endif
+#ifdef ETIMEDOUT
+ case ETIMEDOUT:
+ return DBUS_ERROR_TIMEOUT;
+#endif
+#ifdef ENETUNREACH
+ case ENETUNREACH:
+ return DBUS_ERROR_NO_NETWORK;
+#endif
+#ifdef EADDRINUSE
+ case EADDRINUSE:
+ return DBUS_ERROR_ADDRESS_IN_USE;
+#endif
+#ifdef EEXIST
+ case EEXIST:
+ return DBUS_ERROR_FILE_NOT_FOUND;
+#endif
+#ifdef ENOENT
+ case ENOENT:
+ return DBUS_ERROR_FILE_NOT_FOUND;
+#endif
+ }
+
+ return DBUS_ERROR_FAILED;
+}
+
+/**
+ * Exit the process, returning the given value.
+ *
+ * @param code the exit code
+ */
+void
+_dbus_exit (int code)
+{
+ _exit (code);
+}
+
+/**
+ * stat() wrapper.
+ *
+ * @param filename the filename to stat
+ * @param statbuf the stat info to fill in
+ * @param error return location for error
+ * @returns #FALSE if error was set
+ */
+dbus_bool_t
+_dbus_stat (const DBusString *filename,
+ DBusStat *statbuf,
+ DBusError *error)
+{
+ const char *filename_c;
+ struct stat sb;
+
+ _dbus_string_get_const_data (filename, &filename_c);
+
+ if (stat (filename_c, &sb) < 0)
+ {
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "%s", _dbus_strerror (errno));
+ return FALSE;
+ }
+
+ statbuf->mode = sb.st_mode;
+ statbuf->nlink = sb.st_nlink;
+ statbuf->uid = sb.st_uid;
+ statbuf->gid = sb.st_gid;
+ statbuf->size = sb.st_size;
+ statbuf->atime = sb.st_atime;
+ statbuf->mtime = sb.st_mtime;
+ statbuf->ctime = sb.st_ctime;
+
+ return TRUE;
+}
+
/** @} end of sysdeps */
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index fb8362e2..f1ac47c8 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -138,8 +138,9 @@ void _dbus_sleep_milliseconds (int milliseconds);
void _dbus_get_current_time (long *tv_sec,
long *tv_usec);
-DBusResultCode _dbus_file_get_contents (DBusString *str,
- const DBusString *filename);
+dbus_bool_t _dbus_file_get_contents (DBusString *str,
+ const DBusString *filename,
+ DBusError *error);
DBusResultCode _dbus_string_save_to_file (const DBusString *str,
const DBusString *filename);
@@ -156,17 +157,18 @@ dbus_bool_t _dbus_concat_dir_and_file (DBusString *dir,
typedef struct DBusDirIter DBusDirIter;
DBusDirIter* _dbus_directory_open (const DBusString *filename,
- DBusResultCode *result);
+ DBusError *error);
dbus_bool_t _dbus_directory_get_next_file (DBusDirIter *iter,
DBusString *filename,
- DBusResultCode *result);
+ DBusError *error);
void _dbus_directory_close (DBusDirIter *iter);
dbus_bool_t _dbus_generate_random_bytes (DBusString *str,
int n_bytes);
-const char *_dbus_errno_to_string (int errnum);
+const char *_dbus_errno_to_string (int errnum);
+const char* _dbus_error_from_errno (int error_number);
typedef void (* DBusSpawnChildSetupFunc) (void *user_data);
@@ -180,6 +182,24 @@ void _dbus_disable_sigpipe (void);
void _dbus_fd_set_close_on_exec (int fd);
+void _dbus_exit (int code);
+
+typedef struct
+{
+ unsigned long mode;
+ unsigned long nlink;
+ unsigned long uid;
+ unsigned long gid;
+ unsigned long size;
+ unsigned long atime;
+ unsigned long mtime;
+ unsigned long ctime;
+} DBusStat;
+
+dbus_bool_t _dbus_stat (const DBusString *filename,
+ DBusStat *statbuf,
+ DBusError *error);
+
DBUS_END_DECLS;
#endif /* DBUS_SYSDEPS_H */