2003-01-21 12:42:33 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
2003-01-22 04:48:47 +00:00
|
|
|
/* driver.c Bus client (driver)
|
2003-01-21 12:42:33 +00:00
|
|
|
*
|
2003-04-10 05:12:19 +00:00
|
|
|
* Copyright (C) 2003 CodeFactory AB
|
|
|
|
|
* Copyright (C) 2003 Red Hat, Inc.
|
2003-01-21 12:42:33 +00:00
|
|
|
*
|
2003-12-02 10:44:22 +00:00
|
|
|
* Licensed under the Academic Free License version 2.0
|
2003-01-21 12:42:33 +00:00
|
|
|
*
|
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2003-02-16 10:00:37 +00:00
|
|
|
#include "activation.h"
|
2003-01-21 12:42:33 +00:00
|
|
|
#include "connection.h"
|
|
|
|
|
#include "driver.h"
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
#include "dispatch.h"
|
2003-01-21 12:42:33 +00:00
|
|
|
#include "services.h"
|
2003-09-21 19:53:56 +00:00
|
|
|
#include "signals.h"
|
2003-02-13 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
Add utils.[ch]
* bus/connection.c: (bus_connection_foreach):
Fix a warning.
* bus/desktop-file.c: (grow_lines_in_section), (grow_sections),
(unescape_string), (new_section), (parse_section_start),
(parse_key_value), (report_error), (bus_desktop_file_load),
(bus_desktop_file_get_string):
* bus/desktop-file.h:
Use DBusError for error reporting.
* bus/dispatch.c: (send_one_message),
(bus_dispatch_message_handler):
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_send_service_lost),
(bus_driver_send_service_acquired), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services),
(bus_driver_handle_acquire_service),
(bus_driver_handle_service_exists):
* bus/loop.c: (bus_loop_run):
* bus/main.c:
Use BUS_HANDLE_OOM instead of _DBUS_HANDLE_OOM.
* bus/utils.c: (bus_wait_for_memory):
* bus/utils.h:
New files with general utility functions.
* dbus/dbus-internals.h:
Remove _DBUS_HANDLE_OOM.
2003-02-13 19:06:42 +00:00
|
|
|
#include "utils.h"
|
2003-01-21 12:42:33 +00:00
|
|
|
#include <dbus/dbus-string.h>
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
#include <dbus/dbus-internals.h>
|
2003-01-21 12:42:33 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
static dbus_bool_t bus_driver_send_welcome_message (DBusConnection *connection,
|
|
|
|
|
DBusMessage *hello_message,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusError *error);
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
bus_driver_send_service_deleted (const char *service_name,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusError *error)
|
2003-01-24 23:51:59 +00:00
|
|
|
{
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
DBusMessage *message;
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t retval;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-01-27 11:20:55 +00:00
|
|
|
_dbus_verbose ("sending service deleted: %s\n", service_name);
|
2003-03-16 22:25:18 +00:00
|
|
|
|
2003-08-31 01:51:44 +00:00
|
|
|
message = dbus_message_new_signal (DBUS_PATH_ORG_FREEDESKTOP_DBUS,
|
|
|
|
|
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
|
2003-08-18 22:43:30 +00:00
|
|
|
"ServiceDeleted");
|
2003-08-11 02:11:58 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
|
2003-08-18 22:43:30 +00:00
|
|
|
if (!dbus_message_set_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS) ||
|
2003-03-13 00:56:43 +00:00
|
|
|
!dbus_message_append_args (message,
|
|
|
|
|
DBUS_TYPE_STRING, service_name,
|
2003-05-14 02:40:41 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
|
2003-09-21 19:53:56 +00:00
|
|
|
retval = bus_dispatch_matches (transaction, NULL, NULL, message, error);
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_message_unref (message);
|
|
|
|
|
|
|
|
|
|
return retval;
|
2003-01-24 23:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t
|
|
|
|
|
bus_driver_send_service_created (const char *service_name,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusError *error)
|
2003-01-24 23:51:59 +00:00
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t retval;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-08-31 01:51:44 +00:00
|
|
|
message = dbus_message_new_signal (DBUS_PATH_ORG_FREEDESKTOP_DBUS,
|
|
|
|
|
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
|
2003-08-18 22:43:30 +00:00
|
|
|
"ServiceCreated");
|
2003-08-11 02:11:58 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-24 23:51:59 +00:00
|
|
|
|
2003-08-18 22:43:30 +00:00
|
|
|
if (!dbus_message_set_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-02-13 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
Add utils.[ch]
* bus/connection.c: (bus_connection_foreach):
Fix a warning.
* bus/desktop-file.c: (grow_lines_in_section), (grow_sections),
(unescape_string), (new_section), (parse_section_start),
(parse_key_value), (report_error), (bus_desktop_file_load),
(bus_desktop_file_get_string):
* bus/desktop-file.h:
Use DBusError for error reporting.
* bus/dispatch.c: (send_one_message),
(bus_dispatch_message_handler):
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_send_service_lost),
(bus_driver_send_service_acquired), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services),
(bus_driver_handle_acquire_service),
(bus_driver_handle_service_exists):
* bus/loop.c: (bus_loop_run):
* bus/main.c:
Use BUS_HANDLE_OOM instead of _DBUS_HANDLE_OOM.
* bus/utils.c: (bus_wait_for_memory):
* bus/utils.h:
New files with general utility functions.
* dbus/dbus-internals.h:
Remove _DBUS_HANDLE_OOM.
2003-02-13 19:06:42 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_append_args (message,
|
|
|
|
|
DBUS_TYPE_STRING, service_name,
|
2003-05-14 02:40:41 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-21 19:53:56 +00:00
|
|
|
retval = bus_dispatch_matches (transaction, NULL, NULL, message, error);
|
2003-01-24 23:51:59 +00:00
|
|
|
dbus_message_unref (message);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
return retval;
|
2003-01-24 23:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t
|
2003-01-27 11:20:55 +00:00
|
|
|
bus_driver_send_service_lost (DBusConnection *connection,
|
2003-03-13 00:56:43 +00:00
|
|
|
const char *service_name,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusError *error)
|
2003-01-27 11:20:55 +00:00
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
2003-08-31 01:51:44 +00:00
|
|
|
message = dbus_message_new_signal (DBUS_PATH_ORG_FREEDESKTOP_DBUS,
|
|
|
|
|
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
|
2003-08-18 22:43:30 +00:00
|
|
|
"ServiceLost");
|
2003-08-11 02:11:58 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) ||
|
|
|
|
|
!dbus_message_append_args (message,
|
2003-03-13 00:56:43 +00:00
|
|
|
DBUS_TYPE_STRING, service_name,
|
2003-05-14 02:40:41 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 02:29:21 +00:00
|
|
|
if (!bus_transaction_send_from_driver (transaction, connection, message))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2003-01-27 11:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t
|
2003-01-27 11:20:55 +00:00
|
|
|
bus_driver_send_service_acquired (DBusConnection *connection,
|
2003-03-13 00:56:43 +00:00
|
|
|
const char *service_name,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusError *error)
|
2003-01-27 11:20:55 +00:00
|
|
|
{
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
2003-08-31 01:51:44 +00:00
|
|
|
message = dbus_message_new_signal (DBUS_PATH_ORG_FREEDESKTOP_DBUS,
|
|
|
|
|
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
|
2003-08-18 22:43:30 +00:00
|
|
|
"ServiceAcquired");
|
2003-04-24 19:18:23 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
if (!dbus_message_set_destination (message, bus_connection_get_name (connection)) ||
|
|
|
|
|
!dbus_message_append_args (message,
|
2003-03-13 00:56:43 +00:00
|
|
|
DBUS_TYPE_STRING, service_name,
|
2003-05-14 02:40:41 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 02:29:21 +00:00
|
|
|
if (!bus_transaction_send_from_driver (transaction, connection, message))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2003-01-27 11:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-21 12:42:33 +00:00
|
|
|
static dbus_bool_t
|
2003-03-13 03:52:58 +00:00
|
|
|
create_unique_client_name (BusRegistry *registry,
|
|
|
|
|
DBusString *str)
|
2003-01-21 12:42:33 +00:00
|
|
|
{
|
2003-01-22 03:36:05 +00:00
|
|
|
/* We never want to use the same unique client name twice, because
|
|
|
|
|
* we want to guarantee that if you send a message to a given unique
|
|
|
|
|
* name, you always get the same application. So we use two numbers
|
|
|
|
|
* for INT_MAX * INT_MAX combinations, should be pretty safe against
|
|
|
|
|
* wraparound.
|
|
|
|
|
*/
|
2003-04-25 23:50:34 +00:00
|
|
|
/* FIXME these should be in BusRegistry rather than static vars */
|
2003-01-22 03:36:05 +00:00
|
|
|
static int next_major_number = 0;
|
|
|
|
|
static int next_minor_number = 0;
|
|
|
|
|
int len;
|
2003-04-25 23:50:34 +00:00
|
|
|
|
2003-01-21 12:42:33 +00:00
|
|
|
len = _dbus_string_get_length (str);
|
|
|
|
|
|
2003-01-22 03:36:05 +00:00
|
|
|
while (TRUE)
|
2003-01-21 12:42:33 +00:00
|
|
|
{
|
2003-01-22 03:36:05 +00:00
|
|
|
/* start out with 1-0, go to 1-1, 1-2, 1-3,
|
|
|
|
|
* up to 1-MAXINT, then 2-0, 2-1, etc.
|
|
|
|
|
*/
|
|
|
|
|
if (next_minor_number <= 0)
|
|
|
|
|
{
|
|
|
|
|
next_major_number += 1;
|
|
|
|
|
next_minor_number = 0;
|
|
|
|
|
if (next_major_number <= 0)
|
|
|
|
|
_dbus_assert_not_reached ("INT_MAX * INT_MAX clients were added");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_assert (next_major_number > 0);
|
|
|
|
|
_dbus_assert (next_minor_number >= 0);
|
|
|
|
|
|
|
|
|
|
/* appname:MAJOR-MINOR */
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append (str, ":"))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append_int (str, next_major_number))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2003-10-21 05:46:52 +00:00
|
|
|
if (!_dbus_string_append (str, "."))
|
2003-01-22 03:36:05 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append_int (str, next_minor_number))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
next_minor_number += 1;
|
2003-01-21 12:42:33 +00:00
|
|
|
|
|
|
|
|
/* Check if a client with the name exists */
|
2003-03-13 03:52:58 +00:00
|
|
|
if (bus_registry_lookup (registry, str) == NULL)
|
2003-01-21 12:42:33 +00:00
|
|
|
break;
|
|
|
|
|
|
2003-01-22 03:36:05 +00:00
|
|
|
/* drop the number again, try the next one. */
|
2003-01-21 12:42:33 +00:00
|
|
|
_dbus_string_set_length (str, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
static dbus_bool_t
|
2003-01-24 23:51:59 +00:00
|
|
|
bus_driver_handle_hello (DBusConnection *connection,
|
2003-03-13 00:56:43 +00:00
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
DBusError *error)
|
2003-01-21 12:42:33 +00:00
|
|
|
{
|
|
|
|
|
DBusString unique_name;
|
|
|
|
|
BusService *service;
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t retval;
|
2003-03-13 03:52:58 +00:00
|
|
|
BusRegistry *registry;
|
2003-04-19 16:16:24 +00:00
|
|
|
BusConnections *connections;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-04-19 16:16:24 +00:00
|
|
|
|
|
|
|
|
/* Note that when these limits are exceeded we don't disconnect the
|
|
|
|
|
* connection; we just sort of leave it hanging there until it times
|
|
|
|
|
* out or disconnects itself or is dropped due to the max number of
|
|
|
|
|
* incomplete connections. It's even OK if the connection wants to
|
|
|
|
|
* retry the hello message, we support that.
|
|
|
|
|
*/
|
|
|
|
|
connections = bus_connection_get_connections (connection);
|
|
|
|
|
if (!bus_connections_check_limits (connections, connection,
|
|
|
|
|
error))
|
|
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-03-31 20:56:29 +00:00
|
|
|
if (!_dbus_string_init (&unique_name))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
retval = FALSE;
|
2003-03-13 03:52:58 +00:00
|
|
|
|
|
|
|
|
registry = bus_connection_get_registry (connection);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
if (!create_unique_client_name (registry, &unique_name))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out_0;
|
|
|
|
|
}
|
2003-02-13 21:37:58 +00:00
|
|
|
|
2003-04-27 06:25:42 +00:00
|
|
|
if (!bus_connection_complete (connection, &unique_name, error))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
2003-04-27 06:25:42 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
2003-03-13 00:56:43 +00:00
|
|
|
goto out_0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_set_sender (message,
|
|
|
|
|
bus_connection_get_name (connection)))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out_0;
|
|
|
|
|
}
|
2003-01-26 01:34:22 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!bus_driver_send_welcome_message (connection, message, transaction, error))
|
|
|
|
|
goto out_0;
|
2003-02-13 21:37:58 +00:00
|
|
|
|
2003-01-21 12:42:33 +00:00
|
|
|
/* Create the service */
|
2003-03-13 03:52:58 +00:00
|
|
|
service = bus_registry_ensure (registry,
|
|
|
|
|
&unique_name, connection, transaction, error);
|
2003-03-13 00:56:43 +00:00
|
|
|
if (service == NULL)
|
|
|
|
|
goto out_0;
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
bus_service_set_prohibit_replacement (service, TRUE);
|
2003-01-21 12:42:33 +00:00
|
|
|
|
2003-09-21 19:53:56 +00:00
|
|
|
_dbus_assert (bus_connection_is_active (connection));
|
2003-03-13 00:56:43 +00:00
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
out_0:
|
2003-01-21 12:42:33 +00:00
|
|
|
_dbus_string_free (&unique_name);
|
2003-03-13 00:56:43 +00:00
|
|
|
return retval;
|
2003-01-21 12:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
static dbus_bool_t
|
2003-01-21 12:42:33 +00:00
|
|
|
bus_driver_send_welcome_message (DBusConnection *connection,
|
2003-03-13 00:56:43 +00:00
|
|
|
DBusMessage *hello_message,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusError *error)
|
2003-01-21 12:42:33 +00:00
|
|
|
{
|
|
|
|
|
DBusMessage *welcome;
|
|
|
|
|
const char *name;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-01-21 12:42:33 +00:00
|
|
|
|
|
|
|
|
name = bus_connection_get_name (connection);
|
|
|
|
|
_dbus_assert (name != NULL);
|
|
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
welcome = dbus_message_new_method_return (hello_message);
|
2003-03-13 00:56:43 +00:00
|
|
|
if (welcome == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_append_args (welcome,
|
|
|
|
|
DBUS_TYPE_STRING, name,
|
2003-05-14 02:40:41 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (welcome);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 02:29:21 +00:00
|
|
|
if (!bus_transaction_send_from_driver (transaction, connection, welcome))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (welcome);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (welcome);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2003-01-21 12:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
static dbus_bool_t
|
2003-01-24 23:51:59 +00:00
|
|
|
bus_driver_handle_list_services (DBusConnection *connection,
|
2003-03-13 00:56:43 +00:00
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
DBusError *error)
|
2003-01-24 23:51:59 +00:00
|
|
|
{
|
|
|
|
|
DBusMessage *reply;
|
2003-03-13 00:56:43 +00:00
|
|
|
int len;
|
2003-01-24 23:51:59 +00:00
|
|
|
char **services;
|
2003-03-13 03:52:58 +00:00
|
|
|
BusRegistry *registry;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-13 03:52:58 +00:00
|
|
|
|
|
|
|
|
registry = bus_connection_get_registry (connection);
|
|
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
reply = dbus_message_new_method_return (message);
|
2003-03-13 00:56:43 +00:00
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-24 23:51:59 +00:00
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
if (!bus_registry_list_services (registry, &services, &len))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_append_args (reply,
|
2003-04-08 15:52:51 +00:00
|
|
|
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, services, len,
|
2003-05-14 02:40:41 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
dbus_free_string_array (services);
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_free_string_array (services);
|
|
|
|
|
|
2003-04-14 02:29:21 +00:00
|
|
|
if (!bus_transaction_send_from_driver (transaction, connection, reply))
|
2003-01-25 01:26:49 +00:00
|
|
|
{
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
return TRUE;
|
2003-01-25 01:26:49 +00:00
|
|
|
}
|
2003-01-24 23:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
static dbus_bool_t
|
2003-02-13 15:29:18 +00:00
|
|
|
bus_driver_handle_acquire_service (DBusConnection *connection,
|
2003-03-13 00:56:43 +00:00
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
DBusError *error)
|
2003-01-21 12:42:33 +00:00
|
|
|
{
|
2003-01-27 11:20:55 +00:00
|
|
|
DBusMessage *reply;
|
2003-01-21 12:42:33 +00:00
|
|
|
DBusString service_name;
|
2003-01-27 11:20:55 +00:00
|
|
|
char *name;
|
|
|
|
|
int service_reply;
|
|
|
|
|
int flags;
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t retval;
|
2003-03-13 03:52:58 +00:00
|
|
|
BusRegistry *registry;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-13 03:52:58 +00:00
|
|
|
|
|
|
|
|
registry = bus_connection_get_registry (connection);
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-04-08 15:52:51 +00:00
|
|
|
if (!dbus_message_get_args (message, error,
|
2003-03-13 00:56:43 +00:00
|
|
|
DBUS_TYPE_STRING, &name,
|
|
|
|
|
DBUS_TYPE_UINT32, &flags,
|
2003-05-14 02:40:41 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2003-03-13 00:56:43 +00:00
|
|
|
return FALSE;
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
_dbus_verbose ("Trying to own service %s with flags 0x%x\n", name, flags);
|
2003-04-08 20:16:03 +00:00
|
|
|
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
reply = NULL;
|
2003-01-21 12:42:33 +00:00
|
|
|
|
|
|
|
|
_dbus_string_init_const (&service_name, name);
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
if (!bus_registry_acquire_service (registry, connection,
|
|
|
|
|
&service_name, flags,
|
|
|
|
|
&service_reply, transaction,
|
|
|
|
|
error))
|
|
|
|
|
goto out;
|
2003-01-21 12:42:33 +00:00
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
reply = dbus_message_new_method_return (message);
|
2003-03-13 00:56:43 +00:00
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
2003-01-27 11:20:55 +00:00
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-04-11 00:03:06 +00:00
|
|
|
if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, service_reply, DBUS_TYPE_INVALID))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2003-02-02 00:39:10 +00:00
|
|
|
|
2003-04-14 02:29:21 +00:00
|
|
|
if (!bus_transaction_send_from_driver (transaction, connection, reply))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
out:
|
2003-01-27 11:20:55 +00:00
|
|
|
dbus_free (name);
|
2003-03-13 00:56:43 +00:00
|
|
|
if (reply)
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
2003-01-21 12:42:33 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
static dbus_bool_t
|
2003-01-27 11:20:55 +00:00
|
|
|
bus_driver_handle_service_exists (DBusConnection *connection,
|
2003-03-13 00:56:43 +00:00
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
DBusError *error)
|
2003-01-27 11:20:55 +00:00
|
|
|
{
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
DBusString service_name;
|
|
|
|
|
BusService *service;
|
|
|
|
|
char *name;
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t retval;
|
2003-03-13 03:52:58 +00:00
|
|
|
BusRegistry *registry;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-03-13 03:52:58 +00:00
|
|
|
|
|
|
|
|
registry = bus_connection_get_registry (connection);
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_get_args (message, error,
|
|
|
|
|
DBUS_TYPE_STRING, &name,
|
2003-05-14 02:40:41 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2003-03-13 00:56:43 +00:00
|
|
|
return FALSE;
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
retval = FALSE;
|
|
|
|
|
|
2003-02-13 Anders Carlsson <andersca@codefactory.se>
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_send_service_lost),
(bus_driver_send_service_acquired), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services),
(bus_driver_handle_acquire_service),
(bus_driver_handle_service_exists):
* dbus/dbus-bus.c: (dbus_bus_register_client),
(dbus_bus_acquire_service), (dbus_bus_service_exists):
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
* dbus/dbus-message.c: (dbus_message_append_args),
(dbus_message_append_args_valist), (dbus_message_get_args),
(dbus_message_get_args_valist), (dbus_message_get_args_iter),
(dbus_message_iter_get_arg_type), (dbus_message_iter_get_string),
(dbus_message_iter_get_byte_array),
(dbus_message_iter_get_string_array), (message_iter_test),
(check_message_handling), (_dbus_message_test):
* dbus/dbus-message.h:
* test/bus-test.c: (main):
Change fields to arguments in messages, so that they won't be
confused with header fields.
* glib/test-dbus-glib.c: (main):
Remove append_fields from hello message.
2003-02-13 21:21:42 +00:00
|
|
|
_dbus_string_init_const (&service_name, name);
|
2003-03-13 03:52:58 +00:00
|
|
|
service = bus_registry_lookup (registry, &service_name);
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
reply = dbus_message_new_method_return (message);
|
2003-03-13 00:56:43 +00:00
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_append_args (reply,
|
|
|
|
|
DBUS_TYPE_UINT32, service != NULL,
|
|
|
|
|
0))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 02:29:21 +00:00
|
|
|
if (!bus_transaction_send_from_driver (transaction, connection, reply))
|
2003-03-13 00:56:43 +00:00
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (reply)
|
|
|
|
|
dbus_message_unref (reply);
|
2003-02-13 Anders Carlsson <andersca@codefactory.se>
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_send_service_lost),
(bus_driver_send_service_acquired), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services),
(bus_driver_handle_acquire_service),
(bus_driver_handle_service_exists):
* dbus/dbus-bus.c: (dbus_bus_register_client),
(dbus_bus_acquire_service), (dbus_bus_service_exists):
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
* dbus/dbus-message.c: (dbus_message_append_args),
(dbus_message_append_args_valist), (dbus_message_get_args),
(dbus_message_get_args_valist), (dbus_message_get_args_iter),
(dbus_message_iter_get_arg_type), (dbus_message_iter_get_string),
(dbus_message_iter_get_byte_array),
(dbus_message_iter_get_string_array), (message_iter_test),
(check_message_handling), (_dbus_message_test):
* dbus/dbus-message.h:
* test/bus-test.c: (main):
Change fields to arguments in messages, so that they won't be
confused with header fields.
* glib/test-dbus-glib.c: (main):
Remove append_fields from hello message.
2003-02-13 21:21:42 +00:00
|
|
|
dbus_free (name);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
return retval;
|
2003-01-21 12:42:33 +00:00
|
|
|
}
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
static dbus_bool_t
|
2003-02-16 10:00:37 +00:00
|
|
|
bus_driver_handle_activate_service (DBusConnection *connection,
|
2003-03-13 00:56:43 +00:00
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
DBusError *error)
|
2003-02-16 10:00:37 +00:00
|
|
|
{
|
|
|
|
|
dbus_uint32_t flags;
|
|
|
|
|
char *name;
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t retval;
|
2003-03-13 03:52:58 +00:00
|
|
|
BusActivation *activation;
|
|
|
|
|
|
2003-03-26 03:58:11 +00:00
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
activation = bus_connection_get_activation (connection);
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_get_args (message, error,
|
|
|
|
|
DBUS_TYPE_STRING, &name,
|
|
|
|
|
DBUS_TYPE_UINT32, &flags,
|
2003-05-14 02:40:41 +00:00
|
|
|
DBUS_TYPE_INVALID))
|
2003-04-11 03:05:58 +00:00
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
_dbus_verbose ("No memory to get arguments to ActivateService\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
retval = FALSE;
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2004-03-16 18:00:35 +00:00
|
|
|
if (!bus_activation_activate_service (activation, connection, transaction, FALSE,
|
2003-04-02 20:14:52 +00:00
|
|
|
message, name, error))
|
2003-04-11 03:05:58 +00:00
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
_dbus_verbose ("bus_activation_activate_service() failed\n");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
dbus_free (name);
|
|
|
|
|
return retval;
|
2003-02-16 10:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
2003-09-21 19:53:56 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
send_ack_reply (DBusConnection *connection,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
|
|
|
|
|
reply = dbus_message_new_method_return (message);
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bus_transaction_send_from_driver (transaction, connection, reply))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
bus_driver_handle_add_match (DBusConnection *connection,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
BusMatchRule *rule;
|
|
|
|
|
char *text;
|
|
|
|
|
DBusString str;
|
|
|
|
|
BusMatchmaker *matchmaker;
|
|
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
|
|
|
|
text = NULL;
|
|
|
|
|
rule = NULL;
|
|
|
|
|
|
|
|
|
|
if (bus_connection_get_n_match_rules (connection) >=
|
|
|
|
|
bus_context_get_max_match_rules_per_connection (bus_transaction_get_context (transaction)))
|
|
|
|
|
{
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,
|
|
|
|
|
"Connection \"%s\" is not allowed to add more match rules "
|
|
|
|
|
"(increase limits in configuration file if required)",
|
|
|
|
|
bus_connection_is_active (connection) ?
|
|
|
|
|
bus_connection_get_name (connection) :
|
|
|
|
|
"(inactive)");
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_get_args (message, error,
|
|
|
|
|
DBUS_TYPE_STRING, &text,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("No memory to get arguments to AddMatch\n");
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_string_init_const (&str, text);
|
|
|
|
|
|
|
|
|
|
rule = bus_match_rule_parse (connection, &str, error);
|
|
|
|
|
if (rule == NULL)
|
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
|
|
matchmaker = bus_connection_get_matchmaker (connection);
|
|
|
|
|
|
|
|
|
|
if (!bus_matchmaker_add_rule (matchmaker, rule))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!send_ack_reply (connection, transaction,
|
|
|
|
|
message, error))
|
|
|
|
|
{
|
|
|
|
|
bus_matchmaker_remove_rule (matchmaker, rule);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bus_match_rule_unref (rule);
|
|
|
|
|
dbus_free (text);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
failed:
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
if (rule)
|
|
|
|
|
bus_match_rule_unref (rule);
|
|
|
|
|
if (text)
|
|
|
|
|
dbus_free (text);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
bus_driver_handle_remove_match (DBusConnection *connection,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
DBusError *error)
|
|
|
|
|
{
|
|
|
|
|
BusMatchRule *rule;
|
|
|
|
|
char *text;
|
|
|
|
|
DBusString str;
|
|
|
|
|
BusMatchmaker *matchmaker;
|
|
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
|
|
|
|
|
text = NULL;
|
|
|
|
|
rule = NULL;
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_get_args (message, error,
|
|
|
|
|
DBUS_TYPE_STRING, &text,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("No memory to get arguments to RemoveMatch\n");
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_string_init_const (&str, text);
|
|
|
|
|
|
|
|
|
|
rule = bus_match_rule_parse (connection, &str, error);
|
|
|
|
|
if (rule == NULL)
|
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
|
|
/* Send the ack before we remove the rule, since the ack is undone
|
|
|
|
|
* on transaction cancel, but rule removal isn't.
|
|
|
|
|
*/
|
|
|
|
|
if (!send_ack_reply (connection, transaction,
|
|
|
|
|
message, error))
|
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
|
|
matchmaker = bus_connection_get_matchmaker (connection);
|
|
|
|
|
|
|
|
|
|
if (!bus_matchmaker_remove_rule_by_value (matchmaker, rule, error))
|
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
|
|
bus_match_rule_unref (rule);
|
|
|
|
|
dbus_free (text);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
failed:
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
if (rule)
|
|
|
|
|
bus_match_rule_unref (rule);
|
|
|
|
|
if (text)
|
|
|
|
|
dbus_free (text);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
/* For speed it might be useful to sort this in order of
|
|
|
|
|
* frequency of use (but doesn't matter with only a few items
|
|
|
|
|
* anyhow)
|
|
|
|
|
*/
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
const char *name;
|
|
|
|
|
dbus_bool_t (* handler) (DBusConnection *connection,
|
|
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
DBusError *error);
|
|
|
|
|
} message_handlers[] = {
|
2003-08-18 22:43:30 +00:00
|
|
|
{ "AcquireService", bus_driver_handle_acquire_service },
|
|
|
|
|
{ "ActivateService", bus_driver_handle_activate_service },
|
|
|
|
|
{ "Hello", bus_driver_handle_hello },
|
|
|
|
|
{ "ServiceExists", bus_driver_handle_service_exists },
|
2003-09-21 19:53:56 +00:00
|
|
|
{ "ListServices", bus_driver_handle_list_services },
|
|
|
|
|
{ "AddMatch", bus_driver_handle_add_match },
|
|
|
|
|
{ "RemoveMatch", bus_driver_handle_remove_match }
|
2003-03-13 00:56:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
bus_driver_handle_message (DBusConnection *connection,
|
2003-03-13 00:56:43 +00:00
|
|
|
BusTransaction *transaction,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
DBusError *error)
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
{
|
|
|
|
|
const char *name, *sender;
|
2003-03-13 00:56:43 +00:00
|
|
|
int i;
|
2003-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
2003-08-18 22:43:30 +00:00
|
|
|
|
|
|
|
|
if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Driver got a non-method-call message, ignoring\n");
|
|
|
|
|
return TRUE; /* we just ignore this */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_assert (dbus_message_get_interface (message) != NULL);
|
|
|
|
|
_dbus_assert (dbus_message_get_member (message) != NULL);
|
|
|
|
|
|
|
|
|
|
name = dbus_message_get_member (message);
|
|
|
|
|
sender = dbus_message_get_sender (message);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-08-18 22:43:30 +00:00
|
|
|
if (strcmp (dbus_message_get_interface (message),
|
|
|
|
|
DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS) != 0)
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Driver got message to unknown interface \"%s\"\n",
|
|
|
|
|
dbus_message_get_interface (message));
|
|
|
|
|
goto unknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_verbose ("Driver got a method call: %s\n",
|
|
|
|
|
dbus_message_get_member (message));
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
|
2003-04-27 06:25:42 +00:00
|
|
|
/* security checks should have kept this from getting here */
|
2003-08-18 22:43:30 +00:00
|
|
|
_dbus_assert (sender != NULL || strcmp (name, "Hello") == 0);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-10-14 22:16:03 +00:00
|
|
|
if (dbus_message_get_reply_serial (message) != 0)
|
2003-04-14 02:29:21 +00:00
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Client sent a reply to the bus driver, ignoring it\n");
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
i = 0;
|
|
|
|
|
while (i < _DBUS_N_ELEMENTS (message_handlers))
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (message_handlers[i].name, name) == 0)
|
|
|
|
|
{
|
2003-04-11 03:05:58 +00:00
|
|
|
_dbus_verbose ("Running driver handler for %s\n", name);
|
2003-03-13 00:56:43 +00:00
|
|
|
if ((* message_handlers[i].handler) (connection, transaction, message, error))
|
2003-04-11 03:05:58 +00:00
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
|
|
|
|
_dbus_verbose ("Driver handler succeeded\n");
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
else
|
2003-04-11 03:05:58 +00:00
|
|
|
{
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_SET (error);
|
|
|
|
|
_dbus_verbose ("Driver handler returned failure\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-03-13 00:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-18 22:43:30 +00:00
|
|
|
unknown:
|
|
|
|
|
_dbus_verbose ("No driver handler for message \"%s\"\n",
|
|
|
|
|
name);
|
2003-04-11 03:05:58 +00:00
|
|
|
|
2003-08-12 04:15:49 +00:00
|
|
|
dbus_set_error (error, DBUS_ERROR_UNKNOWN_METHOD,
|
2003-03-13 00:56:43 +00:00
|
|
|
"%s does not understand message %s",
|
2003-08-18 22:43:30 +00:00
|
|
|
DBUS_SERVICE_ORG_FREEDESKTOP_DBUS, name);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
|
|
|
|
return FALSE;
|
2003-01-27 11:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_driver_remove_connection (DBusConnection *connection)
|
|
|
|
|
{
|
2003-03-13 00:56:43 +00:00
|
|
|
/* FIXME Does nothing for now, should unregister the connection
|
|
|
|
|
* with the bus driver.
|
|
|
|
|
*/
|
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am:
* bus/connection.c: (connection_disconnect_handler),
(connection_watch_callback), (bus_connection_setup):
* bus/dispatch.c: (send_one_message),
(bus_dispatch_broadcast_message), (bus_dispatch_message_handler),
(bus_dispatch_add_connection), (bus_dispatch_remove_connection):
* bus/dispatch.h:
* bus/driver.c: (bus_driver_send_service_deleted),
(bus_driver_send_service_created), (bus_driver_handle_hello),
(bus_driver_send_welcome_message),
(bus_driver_handle_list_services), (bus_driver_remove_connection),
(bus_driver_handle_message):
* bus/driver.h:
Refactor code, put the message dispatching in its own file. Use
_DBUS_HANDLE_OOM. Also send ServiceDeleted messages when a client
is disconnected.
2003-01-25 20:53:53 +00:00
|
|
|
}
|