2018-12-13 13:07:20 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2008 Red Hat, Inc.
|
|
|
|
|
* Copyright 2010 Ralf Habacker
|
|
|
|
|
* Copyright 2016-2018 Collabora Ltd.
|
|
|
|
|
* Copyright 2017 Endless Mobile, Inc.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-03-19 12:36:49 +01:00
|
|
|
#include <config.h>
|
2018-07-12 13:06:32 +01:00
|
|
|
#include <dbus/dbus-valgrind-internal.h>
|
2018-12-11 11:52:38 +00:00
|
|
|
#include "test-utils.h"
|
2008-05-30 17:11:15 -04:00
|
|
|
|
2016-10-07 19:45:48 +01:00
|
|
|
static void die (const char *message,
|
|
|
|
|
...) _DBUS_GNUC_NORETURN _DBUS_GNUC_PRINTF (1, 2);
|
|
|
|
|
|
2008-05-30 17:11:15 -04:00
|
|
|
static void
|
|
|
|
|
die (const char *message, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start (args, message);
|
|
|
|
|
vfprintf (stderr, message, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct TestServiceData TestServiceData;
|
|
|
|
|
|
|
|
|
|
struct TestServiceData
|
|
|
|
|
{
|
|
|
|
|
DBusLoop *loop;
|
|
|
|
|
char *private_addr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
new_connection_callback (DBusServer *server,
|
|
|
|
|
DBusConnection *new_connection,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
TestServiceData *testdata = data;
|
|
|
|
|
|
2017-11-27 19:26:03 +00:00
|
|
|
if (!test_connection_try_setup (testdata->loop, new_connection))
|
2008-05-30 17:11:15 -04:00
|
|
|
dbus_connection_close (new_connection);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-13 12:42:11 +00:00
|
|
|
static DBusHandlerResult
|
2008-05-30 17:11:15 -04:00
|
|
|
filter_session_message (DBusConnection *connection,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
TestServiceData *testdata = user_data;
|
|
|
|
|
|
|
|
|
|
if (dbus_message_is_method_call (message,
|
2008-07-24 16:19:14 -04:00
|
|
|
"org.freedesktop.DBus.TestSuite.PrivServer",
|
2008-05-30 17:11:15 -04:00
|
|
|
"GetPrivateAddress"))
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *reply;
|
2017-02-09 09:35:49 +00:00
|
|
|
|
2008-05-30 17:11:15 -04:00
|
|
|
reply = dbus_message_new_method_return (message);
|
2017-02-09 09:35:49 +00:00
|
|
|
if (reply == NULL)
|
|
|
|
|
die ("OOM");
|
|
|
|
|
if (!dbus_message_append_args (reply, DBUS_TYPE_STRING,
|
|
|
|
|
&(testdata->private_addr),
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
die ("OOM");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (connection, reply, NULL))
|
|
|
|
|
die ("Error sending message");
|
|
|
|
|
|
2008-05-30 17:11:15 -04:00
|
|
|
dbus_message_unref (reply);
|
2017-02-09 09:35:49 +00:00
|
|
|
|
2008-05-30 17:11:15 -04:00
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call (message,
|
2008-07-24 16:19:14 -04:00
|
|
|
"org.freedesktop.DBus.TestSuite.PrivServer",
|
2008-05-30 17:11:15 -04:00
|
|
|
"Quit"))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "server exiting loop\n");
|
|
|
|
|
_dbus_loop_quit (testdata->loop);
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
DBusServer *server;
|
|
|
|
|
DBusError error;
|
|
|
|
|
DBusLoop *loop;
|
|
|
|
|
DBusConnection *session;
|
|
|
|
|
TestServiceData *testdata;
|
|
|
|
|
|
2018-07-12 13:06:32 +01:00
|
|
|
if (RUNNING_ON_VALGRIND)
|
|
|
|
|
{
|
|
|
|
|
printf ("1..0 # SKIP Not ready to run under valgrind yet\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-30 17:11:15 -04:00
|
|
|
dbus_error_init (&error);
|
|
|
|
|
|
|
|
|
|
loop = _dbus_loop_new ();
|
|
|
|
|
|
|
|
|
|
testdata = dbus_new (TestServiceData, 1);
|
|
|
|
|
testdata->loop = loop;
|
|
|
|
|
|
|
|
|
|
session = dbus_bus_get (DBUS_BUS_SESSION, &error);
|
|
|
|
|
if (!session)
|
|
|
|
|
die ("couldn't access session bus");
|
|
|
|
|
|
|
|
|
|
test_connection_setup (loop, session);
|
|
|
|
|
|
2008-07-24 16:19:14 -04:00
|
|
|
dbus_bus_request_name (session, "org.freedesktop.DBus.TestSuite.PrivServer", 0, &error);
|
2008-05-30 17:11:15 -04:00
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
die ("couldn't request name: %s", error.message);
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_add_filter (session, filter_session_message, testdata, NULL))
|
|
|
|
|
die ("couldn't add filter");
|
|
|
|
|
|
2010-04-11 01:34:37 +02:00
|
|
|
server = dbus_server_listen (TEST_LISTEN, &error);
|
2008-05-30 17:11:15 -04:00
|
|
|
if (!server)
|
2016-10-07 19:44:47 +01:00
|
|
|
die ("%s", error.message);
|
2008-05-30 17:11:15 -04:00
|
|
|
testdata->private_addr = dbus_server_get_address (server);
|
2016-02-08 20:28:21 +00:00
|
|
|
fprintf (stderr, "test server listening on %s\n", testdata->private_addr);
|
2008-05-30 17:11:15 -04:00
|
|
|
|
|
|
|
|
dbus_server_set_new_connection_function (server, new_connection_callback,
|
|
|
|
|
testdata, NULL);
|
|
|
|
|
|
2017-11-27 19:26:03 +00:00
|
|
|
test_server_setup (loop, server);
|
2008-05-30 17:11:15 -04:00
|
|
|
|
|
|
|
|
fprintf (stderr, "server running mainloop\n");
|
|
|
|
|
_dbus_loop_run (loop);
|
|
|
|
|
fprintf (stderr, "server mainloop quit\n");
|
|
|
|
|
|
|
|
|
|
test_server_shutdown (loop, server);
|
|
|
|
|
|
|
|
|
|
test_connection_shutdown (loop, session);
|
|
|
|
|
|
|
|
|
|
dbus_connection_unref (session);
|
|
|
|
|
|
2018-12-11 10:04:18 +00:00
|
|
|
dbus_server_unref (server);
|
|
|
|
|
|
2008-05-30 17:11:15 -04:00
|
|
|
_dbus_loop_unref (loop);
|
|
|
|
|
|
|
|
|
|
dbus_free (testdata);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|