X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dbus%2Fdbus-transport.c;h=6b503721aaa8c1407c08645b3471fb45e32d99c5;hb=04c58b9e5fbdf3acc7565f989e5fcd11f0c23c57;hp=ba6bd4b4beeec43b0cdb7ab9437043b6f32983f7;hpb=bf3a7d865307627136bf30dfa2558d7d208c7460;p=platform%2Fupstream%2Fdbus.git diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index ba6bd4b..6b50372 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -2,6 +2,7 @@ /* dbus-transport.c DBusTransport object (internal to D-Bus implementation) * * Copyright (C) 2002, 2003 Red Hat Inc. + * Copyright (C) 2013 Samsung Electronics * * Licensed under the Academic Free License version 2.1 * @@ -21,7 +22,8 @@ * */ -#include + +#include <../config.h> #include "dbus-transport-protected.h" #include "dbus-transport-unix.h" #include "dbus-transport-socket.h" @@ -31,9 +33,11 @@ #include "dbus-address.h" #include "dbus-credentials.h" #include "dbus-mainloop.h" -#include "dbus-message-private.h" -#include "dbus-marshal-header.h" -#ifdef DBUS_BUILD_TESTS +#include "dbus-message.h" +#ifdef ENABLE_KDBUS_TRANSPORT +#include "dbus-transport-kdbus.h" +#endif +#ifdef DBUS_ENABLE_EMBEDDED_TESTS #include "dbus-server-debug-pipe.h" #endif @@ -72,12 +76,16 @@ live_messages_notify (DBusCounter *counter, _dbus_verbose ("Unix FD counter value is now %d\n", (int) _dbus_counter_get_unix_fd_value (counter)); #endif - + /* disable or re-enable the read watch for the transport if * required. */ if (transport->vtable->live_messages_changed) - (* transport->vtable->live_messages_changed) (transport); + { + _dbus_connection_lock (transport->connection); + (* transport->vtable->live_messages_changed) (transport); + _dbus_connection_unlock (transport->connection); + } _dbus_transport_unref (transport); } @@ -114,7 +122,21 @@ _dbus_transport_init_base (DBusTransport *transport, if (server_guid) auth = _dbus_auth_server_new (server_guid); else - auth = _dbus_auth_client_new (); + { + _dbus_assert (address != NULL); + if (!_dbus_string_copy_data (address, &address_copy)) + { + _dbus_message_loader_unref (loader); + return FALSE; + } +#ifdef ENABLE_KDBUS_TRANSPORT + if(address_copy == strstr(address_copy, "kdbus:path=")) + auth = _dbus_auth_client_new_kdbus(); + else +#endif + auth = _dbus_auth_client_new (); + } + if (auth == NULL) { _dbus_message_loader_unref (loader); @@ -143,19 +165,6 @@ _dbus_transport_init_base (DBusTransport *transport, _dbus_assert (address == NULL); address_copy = NULL; } - else - { - _dbus_assert (address != NULL); - - if (!_dbus_string_copy_data (address, &address_copy)) - { - _dbus_credentials_unref (creds); - _dbus_counter_unref (counter); - _dbus_auth_unref (auth); - _dbus_message_loader_unref (loader); - return FALSE; - } - } transport->refcount = 1; transport->vtable = vtable; @@ -239,6 +248,7 @@ _dbus_transport_finalize_base (DBusTransport *transport) * opened DBusTransport object. If it isn't, returns #NULL * and sets @p error. * + * @param address the address to be checked. * @param error address where an error can be returned. * @returns a new transport, or #NULL on failure. */ @@ -250,7 +260,6 @@ check_address (const char *address, DBusError *error) int len, i; _dbus_assert (address != NULL); - _dbus_assert (*address != '\0'); if (!dbus_parse_address (address, &entries, &len, error)) return NULL; /* not a valid address */ @@ -270,6 +279,7 @@ check_address (const char *address, DBusError *error) * Creates a new transport for the "autostart" method. * This creates a client-side of a transport. * + * @param scope scope of autolaunch (Windows only) * @param error address where an error can be returned. * @returns a new transport, or #NULL on failure. */ @@ -343,10 +353,13 @@ static const struct { DBusTransport **transport_p, DBusError *error); } open_funcs[] = { +#ifdef ENABLE_KDBUS_TRANSPORT + { _dbus_transport_open_kdbus }, +#endif { _dbus_transport_open_socket }, { _dbus_transport_open_platform_specific }, { _dbus_transport_open_autolaunch } -#ifdef DBUS_BUILD_TESTS +#ifdef DBUS_ENABLE_EMBEDDED_TESTS , { _dbus_transport_open_debug_pipe } #endif }; @@ -682,10 +695,33 @@ auth_via_default_rules (DBusTransport *transport) return allow; } +/** + * Returns #TRUE if we have been authenticated. It will return #TRUE even if + * the transport is now disconnected, but was ever authenticated before + * disconnecting. + * + * This replaces the older _dbus_transport_get_is_authenticated() which + * had side-effects. + * + * @param transport the transport + * @returns whether we're authenticated + */ +dbus_bool_t +_dbus_transport_peek_is_authenticated (DBusTransport *transport) +{ + return transport->authenticated; +} /** - * Returns #TRUE if we have been authenticated. Will return #TRUE - * even if the transport is disconnected. + * Returns #TRUE if we have been authenticated. It will return #TRUE even if + * the transport is now disconnected, but was ever authenticated before + * disconnecting. + * + * If we have not finished authenticating, but we have enough buffered input + * to finish the job, then this function will do so before it returns. + * + * This used to be called _dbus_transport_get_is_authenticated(), but that + * name seems inappropriate for a function with side-effects. * * @todo we drop connection->mutex when calling the unix_user_function, * and windows_user_function, which may not be safe really. @@ -694,7 +730,7 @@ auth_via_default_rules (DBusTransport *transport) * @returns whether we're authenticated */ dbus_bool_t -_dbus_transport_get_is_authenticated (DBusTransport *transport) +_dbus_transport_try_to_authenticate (DBusTransport *transport) { if (transport->authenticated) return TRUE; @@ -987,7 +1023,7 @@ recover_unused_bytes (DBusTransport *transport) const DBusString *encoded; DBusString *buffer; int orig_len; - + if (!_dbus_string_init (&plaintext)) goto nomem; @@ -1000,12 +1036,12 @@ recover_unused_bytes (DBusTransport *transport) _dbus_string_free (&plaintext); goto nomem; } - + _dbus_message_loader_get_buffer (transport->loader, &buffer); orig_len = _dbus_string_get_length (buffer); - + if (!_dbus_string_move (&plaintext, 0, buffer, orig_len)) { @@ -1037,7 +1073,7 @@ recover_unused_bytes (DBusTransport *transport) &buffer); orig_len = _dbus_string_get_length (buffer); - + _dbus_auth_get_unused_bytes (transport->auth, &bytes); @@ -1081,12 +1117,12 @@ _dbus_transport_get_dispatch_status (DBusTransport *transport) _dbus_counter_get_unix_fd_value (transport->live_messages) >= transport->max_live_messages_unix_fds) return DBUS_DISPATCH_COMPLETE; /* complete for now */ - if (!_dbus_transport_get_is_authenticated (transport)) + if (!_dbus_transport_try_to_authenticate (transport)) { if (_dbus_auth_do_work (transport->auth) == DBUS_AUTH_STATE_WAITING_FOR_MEMORY) return DBUS_DISPATCH_NEED_MEMORY; - else if (!_dbus_transport_get_is_authenticated (transport)) + else if (!_dbus_transport_try_to_authenticate (transport)) return DBUS_DISPATCH_COMPLETE; } @@ -1144,6 +1180,13 @@ _dbus_transport_queue_messages (DBusTransport *transport) } else { + /* We didn't call the notify function when we added the counter, so + * catch up now. Since we have the connection's lock, it's desirable + * that we bypass the notify function and call this virtual method + * directly. */ + if (transport->vtable->live_messages_changed) + (* transport->vtable->live_messages_changed) (transport); + /* pass ownership of link and message ref to connection */ _dbus_connection_queue_received_message_link (transport->connection, link); @@ -1328,7 +1371,7 @@ _dbus_transport_get_unix_process_id (DBusTransport *transport, if (_dbus_credentials_include (auth_identity, DBUS_CREDENTIAL_UNIX_PROCESS_ID)) { - *pid = _dbus_credentials_get_unix_pid (auth_identity); + *pid = _dbus_credentials_get_pid (auth_identity); return TRUE; } else @@ -1482,4 +1525,26 @@ _dbus_transport_set_allow_anonymous (DBusTransport *transport, transport->allow_anonymous = value != FALSE; } +#ifdef DBUS_ENABLE_STATS +void +_dbus_transport_get_stats (DBusTransport *transport, + dbus_uint32_t *queue_bytes, + dbus_uint32_t *queue_fds, + dbus_uint32_t *peak_queue_bytes, + dbus_uint32_t *peak_queue_fds) +{ + if (queue_bytes != NULL) + *queue_bytes = _dbus_counter_get_size_value (transport->live_messages); + + if (queue_fds != NULL) + *queue_fds = _dbus_counter_get_unix_fd_value (transport->live_messages); + + if (peak_queue_bytes != NULL) + *peak_queue_bytes = _dbus_counter_get_peak_size_value (transport->live_messages); + + if (peak_queue_fds != NULL) + *peak_queue_fds = _dbus_counter_get_peak_unix_fd_value (transport->live_messages); +} +#endif /* DBUS_ENABLE_STATS */ + /** @} */