From: Havoc Pennington Date: Sat, 1 Feb 2003 00:08:32 +0000 (+0000) Subject: 2003-01-31 Havoc Pennington X-Git-Tag: dbus-0.3~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca84a292179f520df8e2c44a02d285ded95803ff;p=thirdparty%2Fdbus.git 2003-01-31 Havoc Pennington * doc/dbus-specification.sgml: work on the specification * dbus/dbus-message.c (_dbus_message_loader_return_buffer): check the protocol version of the message. * dbus/dbus-protocol.h: drop special _REPLY names, the spec no longer specifies that. (DBUS_SERVICE_REPLY_SERVICE_EXISTS): fix flags (1/2/4/8 not 1/2/3/4) * dbus/dbus-marshal.c (_dbus_marshal_get_arg_end_pos): add missing "break" for DBUS_TYPE_NIL, remove @todo --- diff --git a/ChangeLog b/ChangeLog index 8fd570e51..2857fedad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2003-01-31 Havoc Pennington + + * doc/dbus-specification.sgml: work on the specification + + * dbus/dbus-message.c (_dbus_message_loader_return_buffer): check + the protocol version of the message. + + * dbus/dbus-protocol.h: drop special _REPLY names, the spec + no longer specifies that. + (DBUS_SERVICE_REPLY_SERVICE_EXISTS): fix flags (1/2/4/8 not + 1/2/3/4) + + * dbus/dbus-marshal.c (_dbus_marshal_get_arg_end_pos): add missing + "break" for DBUS_TYPE_NIL, remove @todo + 2003-01-31 Havoc Pennington * dbus/dbus-message.c (dbus_message_set_is_error_reply): rename diff --git a/Makefile.am b/Makefile.am index c5b3c1af1..7ec5e7fc7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ if HAVE_QT QT_SUBDIR=qt endif -SUBDIRS=dbus $(GLIB_SUBDIR) $(QT_SUBDIR) bus test doc +SUBDIRS=dbus bus test doc $(GLIB_SUBDIR) $(QT_SUBDIR) pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = dbus-1.0.pc $(GLIB_PC) diff --git a/bus/driver.c b/bus/driver.c index c8631ffb2..ea13a9e6b 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -221,7 +221,7 @@ bus_driver_send_welcome_message (DBusConnection *connection, name = bus_connection_get_name (connection); _dbus_assert (name != NULL); - _DBUS_HANDLE_OOM (welcome = dbus_message_new_reply (DBUS_MESSAGE_HELLO_REPLY, + _DBUS_HANDLE_OOM (welcome = dbus_message_new_reply (DBUS_MESSAGE_HELLO, hello_message)); _DBUS_HANDLE_OOM (dbus_message_set_sender (welcome, DBUS_SERVICE_DBUS)); @@ -243,7 +243,7 @@ bus_driver_handle_list_services (DBusConnection *connection, int len, i; char **services; - _DBUS_HANDLE_OOM (reply = dbus_message_new_reply (DBUS_MESSAGE_LIST_SERVICES_REPLY, message)); + _DBUS_HANDLE_OOM (reply = dbus_message_new_reply (DBUS_MESSAGE_LIST_SERVICES, message)); _DBUS_HANDLE_OOM (services = bus_services_list (&len)); @@ -292,7 +292,7 @@ bus_driver_handle_own_service (DBusConnection *connection, _dbus_string_init_const (&service_name, name); service = bus_service_lookup (&service_name, TRUE); - _DBUS_HANDLE_OOM ((reply = dbus_message_new_reply (DBUS_MESSAGE_ACQUIRE_SERVICE_REPLY, message))); + _DBUS_HANDLE_OOM ((reply = dbus_message_new_reply (DBUS_MESSAGE_ACQUIRE_SERVICE, message))); /* * Check if the service already has an owner @@ -372,7 +372,7 @@ bus_driver_handle_service_exists (DBusConnection *connection, _dbus_string_init_const (&service_name, name); service = bus_service_lookup (&service_name, FALSE); - _DBUS_HANDLE_OOM ((reply = dbus_message_new_reply (DBUS_MESSAGE_ACQUIRE_SERVICE_REPLY, message))); + _DBUS_HANDLE_OOM ((reply = dbus_message_new_reply (DBUS_MESSAGE_ACQUIRE_SERVICE, message))); _DBUS_HANDLE_OOM (dbus_message_set_sender (message, DBUS_SERVICE_DBUS)); _DBUS_HANDLE_OOM (dbus_message_append_fields (message, diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c index a31e0f494..2a674987a 100644 --- a/dbus/dbus-marshal.c +++ b/dbus/dbus-marshal.c @@ -847,8 +847,6 @@ _dbus_demarshal_string_array (const DBusString *str, * NO VALIDATION WHATSOEVER. The message must have been previously * validated. * - * @todo handle DBUS_TYPE_NIL - * * @param str a string * @param byte_order the byte order to use * @param pos the pos where the arg starts @@ -877,6 +875,7 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str, case DBUS_TYPE_NIL: *end_pos = pos + 1; + break; case DBUS_TYPE_INT32: *end_pos = _DBUS_ALIGN_VALUE (pos + 1, sizeof (dbus_int32_t)) + sizeof (dbus_int32_t); @@ -1071,8 +1070,6 @@ validate_string (const DBusString *str, * returns #TRUE if a valid arg begins at "pos" * * @todo security: need to audit this function. - * - * @todo handle DBUS_TYPE_NIL * * @param str a string * @param byte_order the byte order to use diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 7875d90e3..66c6bd594 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -2037,6 +2037,14 @@ _dbus_message_loader_return_buffer (DBusMessageLoader *loader, _dbus_string_get_const_data_len (&loader->data, &header_data, 0, 16); _dbus_assert (_DBUS_ALIGN_ADDRESS (header_data, 4) == header_data); + + if (header_data[2] != DBUS_MAJOR_PROTOCOL_VERSION) + { + _dbus_verbose ("Message has protocol version %d ours is %d\n", + (int) header_data[2], DBUS_MAJOR_PROTOCOL_VERSION); + loader->corrupted = TRUE; + return; + } byte_order = header_data[0]; diff --git a/dbus/dbus-protocol.h b/dbus/dbus-protocol.h index 5ff6d5809..f1d66ac42 100644 --- a/dbus/dbus-protocol.h +++ b/dbus/dbus-protocol.h @@ -72,18 +72,14 @@ extern "C" { /* Service replies */ #define DBUS_SERVICE_REPLY_PRIMARY_OWNER 0x1 #define DBUS_SERVICE_REPLY_IN_QUEUE 0x2 -#define DBUS_SERVICE_REPLY_SERVICE_EXISTS 0x3 -#define DBUS_SERVICE_REPLY_ALREADY_OWNER 0x4 +#define DBUS_SERVICE_REPLY_SERVICE_EXISTS 0x4 +#define DBUS_SERVICE_REPLY_ALREADY_OWNER 0x8 /* Messages */ #define DBUS_MESSAGE_SERVICE_EXISTS "org.freedesktop.DBus.ServiceExists" -#define DBUS_MESSAGE_SERVICE_EXISTS_REPLY "org.freedesktop.DBus.ServiceExists:Reply" #define DBUS_MESSAGE_HELLO "org.freedesktop.DBus.Hello" -#define DBUS_MESSAGE_HELLO_REPLY "org.freedesktop.DBus.Hello:Reply" #define DBUS_MESSAGE_LIST_SERVICES "org.freedesktop.DBus.ListServices" -#define DBUS_MESSAGE_LIST_SERVICES_REPLY "org.freedesktop.DBus.ListServices:Reply" #define DBUS_MESSAGE_ACQUIRE_SERVICE "org.freedesktop.DBus.OwnService" -#define DBUS_MESSAGE_ACQUIRE_SERVICE_REPLY "org.freedesktop.DBus.OwnService:Reply" #define DBUS_MESSAGE_SERVICE_ACQUIRED "org.freedesktop.DBus.ServiceAcquired" #define DBUS_MESSAGE_SERVICE_CREATED "org.freedesktop.DBus.ServiceCreated" #define DBUS_MESSAGE_SERVICE_DELETED "org.freedesktop.DBus.ServiceDeleted" diff --git a/doc/dbus-specification.sgml b/doc/dbus-specification.sgml index b8d80bb89..8e862f1b8 100644 --- a/doc/dbus-specification.sgml +++ b/doc/dbus-specification.sgml @@ -156,7 +156,7 @@ Flags that can appear in the second byte of the header: - + @@ -188,6 +188,60 @@ invent their own header fields; only changes to this specification may introduce new header fields. + + + Header field names MUST consist of 4 non-nul bytes. The field name is + NOT nul terminated; it occupies exactly 4 bytes. Following the name, + the field MUST have a type code, and then a properly-aligned value + of that type. + See for a description + of how each type is encoded. If an implementation sees a header + field name that it does not understand, it MUST ignore + that field. + + + + Here are the currently-defined named header fields: + + + + + Name + Type + Description + + + + + name + STRING + The name of the message, such as org.freedesktop.Peer.Ping + + + rply + INT32 + The serial number of the message this message is a reply + to. (The serial number is one of the mandatory header fields, + see .) + + + srvc + STRING + The name of the service this message should be routed to. + Only used in combination with the message bus, see + . + + + sndr + STRING + The name of the service that sent this message. + The message bus fills in this field; the field is + only meaningful in combination with the message bus. + + + + + @@ -274,6 +328,68 @@ The types are encoded as follows: + + + + + Type name + Encoding + + + + + INVALID + Not applicable; cannot be encoded. + + NIL + No data is encoded; the type code is followed immediately + by the type code of the next argument. + + INT32 + 32-bit signed integer in the message's byte order, aligned to 4-byte boundary. + + UINT32 + 32-bit unsigned integer in the message's byte order, aligned to 4-byte boundary. + + DOUBLE + 64-bit IEEE 754 double in the message's byte order, aligned to 8-byte boundary. + + STRING + UINT32 aligned to 4-byte boundary indicating the string's + length in bytes excluding its terminating nul, followed by + string data of the given length, followed by a terminating nul + byte. + + + INT32_ARRAY + UINT32 giving the number of values in the array, + followed by the given number of INT32 values. + + + UINT32_ARRAY + UINT32 giving the number of values in the array, + followed by the given number of UINT32 values. + + + DOUBLE_ARRAY + UINT32 giving the number of values in the array, + followed by the given number of DOUBLE values aligned + to 8-byte boundary. + + + BYTE_ARRAY + UINT32 giving the number of values in the array, + followed by the given number of one-byte values. + + + STRING_ARRAY + UINT32 giving the number of values in the array, + followed by the given number of STRING values. + + + + + @@ -348,10 +464,11 @@ - A reply to a message is conventionally named by - appending the string :Reply. - So the reply to org.freedesktop.Peer.Ping - is org.freedesktop.Peer.Ping:Reply. + A reply to a message conventionally has the same name as the message + being replied to. When following method call conventions (see ), this convention is mandatory, + because a message with multiple possible replies can't be mapped + to method call semantics without special-case code. @@ -385,7 +502,8 @@ Arguments to a method may be considered "in" (processed by the recipient of the message), or "out" (returned to the sender of the message in the reply). "inout" arguments are both sent and received, - i.e. the caller passes in a value which is modified. + i.e. the caller passes in a value which is modified. An "inout" argument + is equivalent to an "in" argument, followed by an "out" argument. Given a method with zero or one return values, followed by zero or more @@ -398,6 +516,19 @@ if any, then each "out" or "inout" argument, in order. "in" arguments are not represented in the reply message. + + The standard reply message MUST have the same name as the message being + replied to, and MUST set the "rply" header field to the serial + number of the message being replied to. + + + If an error occurs, an error reply may be sent in place of the + standard reply. Error replies can be identified by a special + header flag, see . + Error replies have a name which reflects the type of + error that occurred. Error replies would generally + be mapped to exceptions in a programming language. + @@ -422,7 +553,7 @@ On receipt of the message org.freedesktop.Peer.Ping, an application should reply with - org.freedesktop.Peer.Ping:Reply. Neither the + org.freedesktop.Peer.Ping. Neither the message nor its reply have any arguments. [FIXME the messages here are just made up to illustrate the format for defining them]