From 08dd53c14b53b88cf798b910952ab3832b83c24c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 23 Jan 2012 10:27:32 +0000 Subject: Revert addition of files which were only meant to exist on master, too This completes the reversion started in 5df8c3db12590edd68e968. --- bus/stats.c | 352 -------------- bus/stats.h | 38 -- cmake/modules/MacrosAutotools.cmake | 40 -- test/data/valid-config-files/incoming-limit.conf | 18 - test/dbus-daemon-eavesdrop.c | 555 ----------------------- 5 files changed, 1003 deletions(-) delete mode 100644 bus/stats.c delete mode 100644 bus/stats.h delete mode 100644 cmake/modules/MacrosAutotools.cmake delete mode 100644 test/data/valid-config-files/incoming-limit.conf delete mode 100644 test/dbus-daemon-eavesdrop.c diff --git a/bus/stats.c b/bus/stats.c deleted file mode 100644 index 28fd49ba..00000000 --- a/bus/stats.c +++ /dev/null @@ -1,352 +0,0 @@ -/* stats.c - statistics from the bus driver - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#include -#include "stats.h" - -#include -#include - -#include "connection.h" -#include "services.h" -#include "utils.h" - -#ifdef DBUS_ENABLE_STATS - -static DBusMessage * -new_asv_reply (DBusMessage *message, - DBusMessageIter *iter, - DBusMessageIter *arr_iter) -{ - DBusMessage *reply = dbus_message_new_method_return (message); - - if (reply == NULL) - return NULL; - - dbus_message_iter_init_append (reply, iter); - - if (!dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, "{sv}", - arr_iter)) - { - dbus_message_unref (reply); - return NULL; - } - - return reply; -} - -static dbus_bool_t -open_asv_entry (DBusMessageIter *arr_iter, - DBusMessageIter *entry_iter, - const char *key, - const char *type, - DBusMessageIter *var_iter) -{ - if (!dbus_message_iter_open_container (arr_iter, DBUS_TYPE_DICT_ENTRY, - NULL, entry_iter)) - return FALSE; - - if (!dbus_message_iter_append_basic (entry_iter, DBUS_TYPE_STRING, &key)) - { - dbus_message_iter_abandon_container (arr_iter, entry_iter); - return FALSE; - } - - if (!dbus_message_iter_open_container (entry_iter, DBUS_TYPE_VARIANT, - type, var_iter)) - { - dbus_message_iter_abandon_container (arr_iter, entry_iter); - return FALSE; - } - - return TRUE; -} - -static dbus_bool_t -close_asv_entry (DBusMessageIter *arr_iter, - DBusMessageIter *entry_iter, - DBusMessageIter *var_iter) -{ - if (!dbus_message_iter_close_container (entry_iter, var_iter)) - { - dbus_message_iter_abandon_container (arr_iter, entry_iter); - return FALSE; - } - - if (!dbus_message_iter_close_container (arr_iter, entry_iter)) - return FALSE; - - return TRUE; -} - -static dbus_bool_t -close_asv_reply (DBusMessageIter *iter, - DBusMessageIter *arr_iter) -{ - return dbus_message_iter_close_container (iter, arr_iter); -} - -static void -abandon_asv_entry (DBusMessageIter *arr_iter, - DBusMessageIter *entry_iter, - DBusMessageIter *var_iter) -{ - dbus_message_iter_abandon_container (entry_iter, var_iter); - dbus_message_iter_abandon_container (arr_iter, entry_iter); -} - -static void -abandon_asv_reply (DBusMessageIter *iter, - DBusMessageIter *arr_iter) -{ - dbus_message_iter_abandon_container (iter, arr_iter); -} - -static dbus_bool_t -asv_add_uint32 (DBusMessageIter *iter, - DBusMessageIter *arr_iter, - const char *key, - dbus_uint32_t value) -{ - DBusMessageIter entry_iter, var_iter; - - if (!open_asv_entry (arr_iter, &entry_iter, key, DBUS_TYPE_UINT32_AS_STRING, - &var_iter)) - goto oom; - - if (!dbus_message_iter_append_basic (&var_iter, DBUS_TYPE_UINT32, - &value)) - { - abandon_asv_entry (arr_iter, &entry_iter, &var_iter); - goto oom; - } - - if (!close_asv_entry (arr_iter, &entry_iter, &var_iter)) - goto oom; - - return TRUE; - -oom: - abandon_asv_reply (iter, arr_iter); - return FALSE; -} - -static dbus_bool_t -asv_add_string (DBusMessageIter *iter, - DBusMessageIter *arr_iter, - const char *key, - const char *value) -{ - DBusMessageIter entry_iter, var_iter; - - if (!open_asv_entry (arr_iter, &entry_iter, key, DBUS_TYPE_STRING_AS_STRING, - &var_iter)) - goto oom; - - if (!dbus_message_iter_append_basic (&var_iter, DBUS_TYPE_STRING, - &value)) - { - abandon_asv_entry (arr_iter, &entry_iter, &var_iter); - goto oom; - } - - if (!close_asv_entry (arr_iter, &entry_iter, &var_iter)) - goto oom; - - return TRUE; - -oom: - abandon_asv_reply (iter, arr_iter); - return FALSE; -} - -dbus_bool_t -bus_stats_handle_get_stats (DBusConnection *connection, - BusTransaction *transaction, - DBusMessage *message, - DBusError *error) -{ - BusConnections *connections; - DBusMessage *reply = NULL; - DBusMessageIter iter, arr_iter; - static dbus_uint32_t stats_serial = 0; - dbus_uint32_t in_use, in_free_list, allocated; - - _DBUS_ASSERT_ERROR_IS_CLEAR (error); - - connections = bus_transaction_get_connections (transaction); - - reply = new_asv_reply (message, &iter, &arr_iter); - - if (reply == NULL) - goto oom; - - /* Globals */ - - if (!asv_add_uint32 (&iter, &arr_iter, "Serial", stats_serial++)) - goto oom; - - _dbus_list_get_stats (&in_use, &in_free_list, &allocated); - if (!asv_add_uint32 (&iter, &arr_iter, "ListMemPoolUsedBytes", in_use) || - !asv_add_uint32 (&iter, &arr_iter, "ListMemPoolCachedBytes", - in_free_list) || - !asv_add_uint32 (&iter, &arr_iter, "ListMemPoolAllocatedBytes", - allocated)) - goto oom; - - /* Connections */ - - if (!asv_add_uint32 (&iter, &arr_iter, "ActiveConnections", - bus_connections_get_n_active (connections)) || - !asv_add_uint32 (&iter, &arr_iter, "IncompleteConnections", - bus_connections_get_n_incomplete (connections)) || - !asv_add_uint32 (&iter, &arr_iter, "MatchRules", - bus_connections_get_total_match_rules (connections)) || - !asv_add_uint32 (&iter, &arr_iter, "PeakMatchRules", - bus_connections_get_peak_match_rules (connections)) || - !asv_add_uint32 (&iter, &arr_iter, "PeakMatchRulesPerConnection", - bus_connections_get_peak_match_rules_per_conn (connections)) || - !asv_add_uint32 (&iter, &arr_iter, "BusNames", - bus_connections_get_total_bus_names (connections)) || - !asv_add_uint32 (&iter, &arr_iter, "PeakBusNames", - bus_connections_get_peak_bus_names (connections)) || - !asv_add_uint32 (&iter, &arr_iter, "PeakBusNamesPerConnection", - bus_connections_get_peak_bus_names_per_conn (connections))) - goto oom; - - /* end */ - - if (!close_asv_reply (&iter, &arr_iter)) - goto oom; - - if (!bus_transaction_send_from_driver (transaction, connection, reply)) - goto oom; - - dbus_message_unref (reply); - return TRUE; - -oom: - if (reply != NULL) - dbus_message_unref (reply); - - BUS_SET_OOM (error); - return FALSE; -} - -dbus_bool_t -bus_stats_handle_get_connection_stats (DBusConnection *caller_connection, - BusTransaction *transaction, - DBusMessage *message, - DBusError *error) -{ - const char *bus_name = NULL; - DBusString bus_name_str; - DBusMessage *reply = NULL; - DBusMessageIter iter, arr_iter; - static dbus_uint32_t stats_serial = 0; - dbus_uint32_t in_messages, in_bytes, in_fds, in_peak_bytes, in_peak_fds; - dbus_uint32_t out_messages, out_bytes, out_fds, out_peak_bytes, out_peak_fds; - BusRegistry *registry; - BusService *service; - DBusConnection *stats_connection; - - _DBUS_ASSERT_ERROR_IS_CLEAR (error); - - registry = bus_connection_get_registry (caller_connection); - - if (! dbus_message_get_args (message, error, - DBUS_TYPE_STRING, &bus_name, - DBUS_TYPE_INVALID)) - return FALSE; - - _dbus_string_init_const (&bus_name_str, bus_name); - service = bus_registry_lookup (registry, &bus_name_str); - - if (service == NULL) - { - dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, - "Bus name '%s' has no owner", bus_name); - return FALSE; - } - - stats_connection = bus_service_get_primary_owners_connection (service); - _dbus_assert (stats_connection != NULL); - - reply = new_asv_reply (message, &iter, &arr_iter); - - if (reply == NULL) - goto oom; - - /* Bus daemon per-connection stats */ - - if (!asv_add_uint32 (&iter, &arr_iter, "Serial", stats_serial++) || - !asv_add_uint32 (&iter, &arr_iter, "MatchRules", - bus_connection_get_n_match_rules (stats_connection)) || - !asv_add_uint32 (&iter, &arr_iter, "PeakMatchRules", - bus_connection_get_peak_match_rules (stats_connection)) || - !asv_add_uint32 (&iter, &arr_iter, "BusNames", - bus_connection_get_n_services_owned (stats_connection)) || - !asv_add_uint32 (&iter, &arr_iter, "PeakBusNames", - bus_connection_get_peak_bus_names (stats_connection)) || - !asv_add_string (&iter, &arr_iter, "UniqueName", - bus_connection_get_name (stats_connection))) - goto oom; - - /* DBusConnection per-connection stats */ - - _dbus_connection_get_stats (stats_connection, - &in_messages, &in_bytes, &in_fds, - &in_peak_bytes, &in_peak_fds, - &out_messages, &out_bytes, &out_fds, - &out_peak_bytes, &out_peak_fds); - - if (!asv_add_uint32 (&iter, &arr_iter, "IncomingMessages", in_messages) || - !asv_add_uint32 (&iter, &arr_iter, "IncomingBytes", in_bytes) || - !asv_add_uint32 (&iter, &arr_iter, "IncomingFDs", in_fds) || - !asv_add_uint32 (&iter, &arr_iter, "PeakIncomingBytes", in_peak_bytes) || - !asv_add_uint32 (&iter, &arr_iter, "PeakIncomingFDs", in_peak_fds) || - !asv_add_uint32 (&iter, &arr_iter, "OutgoingMessages", out_messages) || - !asv_add_uint32 (&iter, &arr_iter, "OutgoingBytes", out_bytes) || - !asv_add_uint32 (&iter, &arr_iter, "OutgoingFDs", out_fds) || - !asv_add_uint32 (&iter, &arr_iter, "PeakOutgoingBytes", out_peak_bytes) || - !asv_add_uint32 (&iter, &arr_iter, "PeakOutgoingFDs", out_peak_fds)) - goto oom; - - /* end */ - - if (!close_asv_reply (&iter, &arr_iter)) - goto oom; - - if (!bus_transaction_send_from_driver (transaction, caller_connection, - reply)) - goto oom; - - dbus_message_unref (reply); - return TRUE; - -oom: - if (reply != NULL) - dbus_message_unref (reply); - - BUS_SET_OOM (error); - return FALSE; -} - -#endif diff --git a/bus/stats.h b/bus/stats.h deleted file mode 100644 index 0f843db5..00000000 --- a/bus/stats.h +++ /dev/null @@ -1,38 +0,0 @@ -/* stats.h - statistics from the bus driver - * - * Licensed under the Academic Free License version 2.1 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#ifndef BUS_STATS_H -#define BUS_STATS_H - -#include "bus.h" - -#define BUS_INTERFACE_STATS "org.freedesktop.DBus.Debug.Stats" - -dbus_bool_t bus_stats_handle_get_stats (DBusConnection *connection, - BusTransaction *transaction, - DBusMessage *message, - DBusError *error); - -dbus_bool_t bus_stats_handle_get_connection_stats (DBusConnection *connection, - BusTransaction *transaction, - DBusMessage *message, - DBusError *error); - -#endif /* multiple-inclusion guard */ diff --git a/cmake/modules/MacrosAutotools.cmake b/cmake/modules/MacrosAutotools.cmake deleted file mode 100644 index ff30eaf9..00000000 --- a/cmake/modules/MacrosAutotools.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# -# @Author Ralf Habacker -# -# extracts version information from autoconf config file -# and set related cmake variables -# -# returns -# ${prefix}_VERSION -# ${prefix}_VERSION_STRING -# ${prefix}_MAJOR_VERSION -# ${prefix}_MINOR_VERSION -# ${prefix}_MICRO_VERSION -# -macro(autoversion config prefix) - file (READ ${config} _configure_ac) - string(TOUPPER ${prefix} prefix_upper) - string (REGEX REPLACE ".*${prefix}_major_version], .([0-9]+).*" "\\1" ${prefix_upper}_MAJOR_VERSION ${_configure_ac}) - string (REGEX REPLACE ".*${prefix}_minor_version], .([0-9]+).*" "\\1" ${prefix_upper}_MINOR_VERSION ${_configure_ac}) - string (REGEX REPLACE ".*${prefix}_micro_version], .([0-9]+).*" "\\1" ${prefix_upper}_MICRO_VERSION ${_configure_ac}) - set (${prefix_upper}_VERSION ${${prefix_upper}_MAJOR_VERSION}.${${prefix_upper}_MINOR_VERSION}.${${prefix_upper}_MICRO_VERSION}) - set (${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}") - -endmacro() - -# -# parses config.h template and create cmake equivalent -# not implemented yet -# -macro(autoconfig template output) - file(READ ${template} contents) - # Convert file contents into a CMake list (where each element in the list - # is one line of the file) - STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}") - STRING(REGEX REPLACE "\n" ";" contents "${contents}") - foreach(line contents) - message(STATUS ${line}) - # find #undef lines - # append to config.h #define - endforeach() -endmacro() diff --git a/test/data/valid-config-files/incoming-limit.conf b/test/data/valid-config-files/incoming-limit.conf deleted file mode 100644 index abfab3f7..00000000 --- a/test/data/valid-config-files/incoming-limit.conf +++ /dev/null @@ -1,18 +0,0 @@ - - - - session - unix:tmpdir=/tmp - - - - - - - - - - - 1 - diff --git a/test/dbus-daemon-eavesdrop.c b/test/dbus-daemon-eavesdrop.c deleted file mode 100644 index 0bd923d2..00000000 --- a/test/dbus-daemon-eavesdrop.c +++ /dev/null @@ -1,555 +0,0 @@ -/* Integration tests for the eavesdrop=true|false keyword in DBusMatchRule - * - * Author: Cosimo Alfarano - * Based on: tests/dbus-daemon.c by Simon McVittie - * Copyright © 2010-2011 Nokia Corporation - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation files - * (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include - -#include -#include - -#include - -#ifdef DBUS_WIN -# include -# include -#else -# include -# include -#endif - -#define SENDER_NAME "test.eavesdrop.sender" -#define SENDER_PATH "/test/eavesdrop/sender" -#define SENDER_IFACE SENDER_NAME -#define SENDER_SIGNAL_NAME "Signal" -#define SENDER_STOPPER_NAME "Stopper" - -/* This rule is equivalent to the one added to a proxy connecting to - * SENDER_NAME+SENDER_IFACE, plus restricting on signal name. - * Being more restrictive, if the connection receives what we need, for sure - * the original proxy rule will match it */ -#define RECEIVER_RULE "sender='" SENDER_NAME "'," \ - "interface='" SENDER_IFACE "'," \ - "type='signal'," \ - "member='" SENDER_SIGNAL_NAME "'" -#define POLITELISTENER_RULE RECEIVER_RULE -#define EAVESDROPPER_RULE RECEIVER_RULE ",eavesdrop=true" - -#define STOPPER_RULE "sender='" SENDER_NAME \ - "',interface='" SENDER_IFACE "',type='signal',member='" SENDER_STOPPER_NAME "'" - -/* a connection received a signal to whom? */ -typedef enum { - NONE_YET = 0, - TO_ME, - TO_OTHER, - BROADCAST, -} SignalDst; - -typedef struct { - DBusError e; - GError *ge; - - GPid daemon_pid; - - /* eavedrop keyword tests */ - DBusConnection *sender; - DBusConnection *receiver; - SignalDst receiver_dst; - dbus_bool_t receiver_got_stopper; - DBusConnection *eavesdropper; - SignalDst eavesdropper_dst; - dbus_bool_t eavesdropper_got_stopper; - DBusConnection *politelistener; - SignalDst politelistener_dst; - dbus_bool_t politelistener_got_stopper; -} Fixture; - -#define assert_no_error(e) _assert_no_error (e, __FILE__, __LINE__) -static void -_assert_no_error (const DBusError *e, - const char *file, - int line) -{ - if (G_UNLIKELY (dbus_error_is_set (e))) - g_error ("%s:%d: expected success but got error: %s: %s", - file, line, e->name, e->message); -} - -static gchar * -spawn_dbus_daemon (gchar *binary, - gchar *configuration, - GPid *daemon_pid) -{ - GError *error = NULL; - GString *address; - gint address_fd; - gchar *argv[] = { - binary, - configuration, - "--nofork", - "--print-address=1", /* stdout */ - NULL - }; - - g_spawn_async_with_pipes (NULL, /* working directory */ - argv, - NULL, /* envp */ - G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, - NULL, /* child_setup */ - NULL, /* user data */ - daemon_pid, - NULL, /* child's stdin = /dev/null */ - &address_fd, - NULL, /* child's stderr = our stderr */ - &error); - g_assert_no_error (error); - - address = g_string_new (NULL); - - /* polling until the dbus-daemon writes out its address is a bit stupid, - * but at least it's simple, unlike dbus-launch... in principle we could - * use select() here, but life's too short */ - while (1) - { - gssize bytes; - gchar buf[4096]; - gchar *newline; - - bytes = read (address_fd, buf, sizeof (buf)); - - if (bytes > 0) - g_string_append_len (address, buf, bytes); - - newline = strchr (address->str, '\n'); - - if (newline != NULL) - { - g_string_truncate (address, newline - address->str); - break; - } - - g_usleep (G_USEC_PER_SEC / 10); - } - - return g_string_free (address, FALSE); -} - -static DBusConnection * -connect_to_bus (const gchar *address) -{ - DBusConnection *conn; - DBusError error = DBUS_ERROR_INIT; - dbus_bool_t ok; - - conn = dbus_connection_open_private (address, &error); - assert_no_error (&error); - g_assert (conn != NULL); - - ok = dbus_bus_register (conn, &error); - assert_no_error (&error); - g_assert (ok); - g_assert (dbus_bus_get_unique_name (conn) != NULL); - - dbus_connection_setup_with_g_main (conn, NULL); - return conn; -} - -/* send a unicast signal to to ensure that no other connection - * listening is the actual recipient for the signal */ -static DBusHandlerResult -sender_send_unicast_to_sender (Fixture *f) -{ - DBusMessage *signal; - - signal = dbus_message_new_signal (SENDER_PATH, SENDER_IFACE, - SENDER_SIGNAL_NAME); - dbus_message_set_destination (signal, dbus_bus_get_unique_name (f->sender)); - - if (signal == NULL) - g_error ("OOM"); - - if (!dbus_connection_send (f->sender, signal, NULL)) - g_error ("OOM"); - - dbus_message_unref (signal); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -/* send a unicast signal to , making and - * not a actual recipient for it */ -static DBusHandlerResult -sender_send_unicast_to_receiver (Fixture *f) -{ - DBusMessage *signal; - - signal = dbus_message_new_signal (SENDER_PATH, SENDER_IFACE, SENDER_SIGNAL_NAME); - dbus_message_set_destination (signal, dbus_bus_get_unique_name (f->receiver)); - - if (signal == NULL) - g_error ("OOM"); - - if (!dbus_connection_send (f->sender, signal, NULL)) - g_error ("OOM"); - - dbus_message_unref (signal); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -static DBusHandlerResult -sender_send_broadcast (Fixture *f) -{ - DBusMessage *signal; - - signal = dbus_message_new_signal (SENDER_PATH, SENDER_IFACE, SENDER_SIGNAL_NAME); - dbus_message_set_destination (signal, NULL); - - if (signal == NULL) - g_error ("OOM"); - - if (!dbus_connection_send (f->sender, signal, NULL)) - g_error ("OOM"); - - dbus_message_unref (signal); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -/* Send special broadcast signal to indicate that the connections can "stop" - * listening and check their results. - * DBus does not re-order messages, so when the three connections have received - * this signal, we are sure that any message sent before it has also been - * dispatched. */ -static DBusHandlerResult -sender_send_stopper (Fixture *f) -{ - DBusMessage *signal; - - signal = dbus_message_new_signal (SENDER_PATH, SENDER_IFACE, SENDER_STOPPER_NAME); - dbus_message_set_destination (signal, NULL); - - if (signal == NULL) - g_error ("OOM"); - - if (!dbus_connection_send (f->sender, signal, NULL)) - g_error ("OOM"); - - dbus_message_unref (signal); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -/* Ignore NameAcquired, then depending on the signal received: - * - updates f->_dst based on the destination of the message - * - asserts that received the stop signal - */ -static DBusHandlerResult -signal_filter (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - Fixture *f = user_data; - SignalDst *dst = NULL; - DBusConnection **conn; - dbus_bool_t *got_stopper; - - if (0 == strcmp (dbus_message_get_member (message), "NameAcquired")) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - if (connection == f->receiver) - { - dst = &(f->receiver_dst); - conn = &(f->receiver); - got_stopper = &(f->receiver_got_stopper); - } - else if (connection == f->eavesdropper) - { - dst = &(f->eavesdropper_dst); - conn = &(f->eavesdropper); - got_stopper = &(f->eavesdropper_got_stopper); - } - else if (connection == f->politelistener) - { - dst = &(f->politelistener_dst); - conn = &(f->politelistener); - got_stopper = &(f->politelistener_got_stopper); - } - else - { - g_error ("connection not matching"); - } - - if (0 == strcmp (dbus_message_get_member (message), SENDER_SIGNAL_NAME)) - { - if (dbus_message_get_destination (message) == NULL) - *dst = BROADCAST; - else if (0 == strcmp (dbus_message_get_destination (message), dbus_bus_get_unique_name (*conn))) - *dst = TO_ME; - else /* if (dbus_message_get_destination (message) != NULL) */ - *dst = TO_OTHER; - } - else if (0 == strcmp (dbus_message_get_member (message), SENDER_STOPPER_NAME)) - { - *got_stopper = TRUE; - } - else - { - g_error ("got unknown member from message: %s", - dbus_message_get_member (message)); - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -static void -add_receiver_filter (Fixture *f) -{ - DBusError e = DBUS_ERROR_INIT; - - dbus_bus_add_match (f->receiver, RECEIVER_RULE, &e); - assert_no_error (&e); - dbus_bus_add_match (f->receiver, STOPPER_RULE, &e); - assert_no_error (&e); - - if (!dbus_connection_add_filter (f->receiver, - signal_filter, f, NULL)) - g_error ("OOM"); -} - -static void -add_eavesdropper_filter (Fixture *f) -{ - DBusError e = DBUS_ERROR_INIT; - - dbus_bus_add_match (f->eavesdropper, EAVESDROPPER_RULE, &e); - assert_no_error (&e); - dbus_bus_add_match (f->eavesdropper, STOPPER_RULE, &e); - assert_no_error (&e); - - if (!dbus_connection_add_filter (f->eavesdropper, - signal_filter, f, NULL)) - g_error ("OOM"); -} - -static void -add_politelistener_filter (Fixture *f) -{ - DBusError e = DBUS_ERROR_INIT; - - dbus_bus_add_match (f->politelistener, POLITELISTENER_RULE, &e); - assert_no_error (&e); - dbus_bus_add_match (f->politelistener, STOPPER_RULE, &e); - assert_no_error (&e); - - if (!dbus_connection_add_filter (f->politelistener, - signal_filter, f, NULL)) - g_error ("OOM"); -} - -static void -setup (Fixture *f, - gconstpointer context G_GNUC_UNUSED) -{ - gchar *dbus_daemon; - gchar *config; - gchar *address; - - f->ge = NULL; - dbus_error_init (&f->e); - - dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON")); - - if (dbus_daemon == NULL) - dbus_daemon = g_strdup ("dbus-daemon"); - - if (g_getenv ("DBUS_TEST_SYSCONFDIR") != NULL) - { - config = g_strdup_printf ("--config-file=%s/dbus-1/session.conf", - g_getenv ("DBUS_TEST_SYSCONFDIR")); - } - else if (g_getenv ("DBUS_TEST_DATA") != NULL) - { - config = g_strdup_printf ( - "--config-file=%s/valid-config-files/session.conf", - g_getenv ("DBUS_TEST_DATA")); - } - else - { - config = g_strdup ("--session"); - } - - address = spawn_dbus_daemon (dbus_daemon, config, &f->daemon_pid); - - g_free (dbus_daemon); - g_free (config); - - f->sender = connect_to_bus (address); - dbus_bus_request_name (f->sender, SENDER_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE, - &(f->e)); - f->receiver = connect_to_bus (address); - f->eavesdropper = connect_to_bus (address); - f->politelistener = connect_to_bus (address); - add_receiver_filter (f); - add_politelistener_filter (f); - add_eavesdropper_filter (f); - - g_free (address); -} - -static void -test_eavesdrop_broadcast (Fixture *f, - gconstpointer context G_GNUC_UNUSED) -{ - sender_send_broadcast (f); - sender_send_stopper (f); - - while (!f->receiver_got_stopper || - !f->politelistener_got_stopper || - !f->eavesdropper_got_stopper) - g_main_context_iteration (NULL, TRUE); - - /* all the three connection can receive a broadcast */ - g_assert_cmpint (f->receiver_dst, ==, BROADCAST); - g_assert_cmpint (f->politelistener_dst, ==, BROADCAST); - g_assert_cmpint (f->eavesdropper_dst, ==, BROADCAST); -} - -/* a way to say that none of the listening connection are destination of the - * signal */ -static void -test_eavesdrop_unicast_to_sender (Fixture *f, - gconstpointer context G_GNUC_UNUSED) -{ - sender_send_unicast_to_sender (f); - sender_send_stopper (f); - - while (!f->receiver_got_stopper || - !f->politelistener_got_stopper || - !f->eavesdropper_got_stopper) - g_main_context_iteration (NULL, TRUE); - - /* not directed to it and not broadcasted, they cannot receive it */ - g_assert_cmpint (f->receiver_dst, ==, NONE_YET); - g_assert_cmpint (f->politelistener_dst, ==, NONE_YET); - /* eavesdrop=true, it will receive the signal even though it's not directed - * to it */ - g_assert_cmpint (f->eavesdropper_dst, ==, TO_OTHER); -} - -static void -test_eavesdrop_unicast_to_receiver (Fixture *f, - gconstpointer context G_GNUC_UNUSED) -{ - sender_send_unicast_to_receiver (f); - sender_send_stopper (f); - - while (!f->receiver_got_stopper || - !f->politelistener_got_stopper || - !f->eavesdropper_got_stopper) - g_main_context_iteration (NULL, TRUE); - - /* direct to him */ - g_assert_cmpint (f->receiver_dst, ==, TO_ME); - /* not directed to it and not broadcasted, it cannot receive it */ - g_assert_cmpint (f->politelistener_dst, ==, NONE_YET); - /* eavesdrop=true, it will receive the signal even though it's not directed - * to it */ - g_assert_cmpint (f->eavesdropper_dst, ==, TO_OTHER); -} - -static void -teardown (Fixture *f, - gconstpointer context G_GNUC_UNUSED) -{ - dbus_error_free (&f->e); - g_clear_error (&f->ge); - - if (f->sender != NULL) - { - dbus_connection_close (f->sender); - dbus_connection_unref (f->sender); - f->sender = NULL; - } - - if (f->receiver != NULL) - { - dbus_connection_remove_filter (f->receiver, - signal_filter, f); - - dbus_connection_close (f->receiver); - dbus_connection_unref (f->receiver); - f->receiver = NULL; - } - - if (f->politelistener != NULL) - { - dbus_connection_remove_filter (f->politelistener, - signal_filter, f); - - dbus_connection_close (f->politelistener); - dbus_connection_unref (f->politelistener); - f->politelistener = NULL; - } - - if (f->eavesdropper != NULL) - { - dbus_connection_remove_filter (f->eavesdropper, - signal_filter, f); - - dbus_connection_close (f->eavesdropper); - dbus_connection_unref (f->eavesdropper); - f->eavesdropper = NULL; - } - -#ifdef DBUS_WIN - TerminateProcess (f->daemon_pid, 1); -#else - kill (f->daemon_pid, SIGTERM); -#endif - - g_spawn_close_pid (f->daemon_pid); -} - -int -main (int argc, - char **argv) -{ - g_test_init (&argc, &argv, NULL); - g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id="); - - g_test_add ("/eavedrop/match_keyword/broadcast", Fixture, NULL, - setup, test_eavesdrop_broadcast, teardown); - g_test_add ("/eavedrop/match_keyword/unicast_to_receiver", Fixture, NULL, - setup, test_eavesdrop_unicast_to_receiver, - teardown); - g_test_add ("/eavedrop/match_keyword/unicast_to_sender", Fixture, NULL, - setup, test_eavesdrop_unicast_to_sender, teardown); - - return g_test_run (); -} -- cgit v1.2.3