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
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 CodeFactory AB
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Academic Free License version 1.2
|
|
|
|
|
*
|
|
|
|
|
* 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-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-03-13 00:56:43 +00:00
|
|
|
message = dbus_message_new (DBUS_SERVICE_BROADCAST,
|
|
|
|
|
DBUS_MESSAGE_SERVICE_DELETED);
|
|
|
|
|
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-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) ||
|
|
|
|
|
!dbus_message_append_args (message,
|
|
|
|
|
DBUS_TYPE_STRING, service_name,
|
|
|
|
|
0))
|
|
|
|
|
{
|
|
|
|
|
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-03-13 00:56:43 +00:00
|
|
|
retval = bus_dispatch_broadcast_message (transaction, message, error);
|
|
|
|
|
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
|
|
|
|
|
|
|
|
message = dbus_message_new (DBUS_SERVICE_BROADCAST,
|
|
|
|
|
DBUS_MESSAGE_SERVICE_CREATED);
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-24 23:51:59 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
|
|
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
|
0))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retval = bus_dispatch_broadcast_message (transaction, 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-03-13 00:56:43 +00:00
|
|
|
message = dbus_message_new (bus_connection_get_name (connection),
|
|
|
|
|
DBUS_MESSAGE_SERVICE_LOST);
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_append_args (message,
|
|
|
|
|
DBUS_TYPE_STRING, service_name,
|
|
|
|
|
0))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bus_transaction_send_message (transaction, connection, message))
|
|
|
|
|
{
|
|
|
|
|
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-03-13 00:56:43 +00:00
|
|
|
message = dbus_message_new (bus_connection_get_name (connection),
|
|
|
|
|
DBUS_MESSAGE_SERVICE_ACQUIRED);
|
|
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_append_args (message,
|
|
|
|
|
DBUS_TYPE_STRING, service_name,
|
|
|
|
|
0))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bus_transaction_send_message (transaction, connection, message))
|
|
|
|
|
{
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
static int next_major_number = 0;
|
|
|
|
|
static int next_minor_number = 0;
|
|
|
|
|
int len;
|
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;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_append (str, "-"))
|
|
|
|
|
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-03-26 03:58:11 +00:00
|
|
|
|
|
|
|
|
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
|
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-03-13 00:56:43 +00:00
|
|
|
if (!bus_connection_set_name (connection, &unique_name))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
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-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-03-13 00:56:43 +00:00
|
|
|
welcome = dbus_message_new_reply (hello_message);
|
|
|
|
|
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_set_sender (welcome, DBUS_SERVICE_DBUS))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (welcome);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2003-02-16 10:00:37 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_append_args (welcome,
|
|
|
|
|
DBUS_TYPE_STRING, name,
|
|
|
|
|
NULL))
|
|
|
|
|
{
|
|
|
|
|
dbus_message_unref (welcome);
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bus_transaction_send_message (transaction, connection, welcome))
|
|
|
|
|
{
|
|
|
|
|
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-03-13 00:56:43 +00:00
|
|
|
reply = dbus_message_new_reply (message);
|
|
|
|
|
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,
|
|
|
|
|
DBUS_TYPE_STRING_ARRAY, services, len,
|
|
|
|
|
0))
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (!bus_transaction_send_message (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
|
|
|
BusService *service;
|
|
|
|
|
char *name;
|
|
|
|
|
int service_reply;
|
|
|
|
|
int flags;
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_bool_t retval;
|
|
|
|
|
DBusConnection *old_owner;
|
|
|
|
|
DBusConnection *current_owner;
|
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-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_get_args (message,
|
|
|
|
|
error,
|
|
|
|
|
DBUS_TYPE_STRING, &name,
|
|
|
|
|
DBUS_TYPE_UINT32, &flags,
|
|
|
|
|
0))
|
|
|
|
|
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-01-21 12:42:33 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
retval = FALSE;
|
|
|
|
|
reply = NULL;
|
2003-01-21 12:42:33 +00:00
|
|
|
|
|
|
|
|
_dbus_string_init_const (&service_name, name);
|
2003-03-13 00:56:43 +00:00
|
|
|
|
2003-03-13 03:52:58 +00:00
|
|
|
service = bus_registry_lookup (registry, &service_name);
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (service != NULL)
|
|
|
|
|
old_owner = bus_service_get_primary_owner (service);
|
|
|
|
|
else
|
|
|
|
|
old_owner = NULL;
|
2003-01-21 12:42:33 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
reply = dbus_message_new_reply (message);
|
|
|
|
|
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
|
|
|
|
|
|
|
|
if (service == NULL)
|
2003-01-27 11:20:55 +00:00
|
|
|
{
|
2003-03-13 03:52:58 +00:00
|
|
|
service = bus_registry_ensure (registry,
|
|
|
|
|
&service_name, connection, transaction, error);
|
2003-03-13 00:56:43 +00:00
|
|
|
if (service == NULL)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_owner = bus_service_get_primary_owner (service);
|
|
|
|
|
|
|
|
|
|
if (old_owner == NULL)
|
|
|
|
|
{
|
|
|
|
|
_dbus_assert (current_owner == connection);
|
|
|
|
|
|
2003-01-27 11:20:55 +00:00
|
|
|
bus_service_set_prohibit_replacement (service,
|
2003-03-13 00:56:43 +00:00
|
|
|
(flags & DBUS_SERVICE_FLAG_PROHIBIT_REPLACEMENT));
|
|
|
|
|
|
|
|
|
|
service_reply = DBUS_SERVICE_REPLY_PRIMARY_OWNER;
|
|
|
|
|
}
|
|
|
|
|
else if (old_owner == connection)
|
|
|
|
|
service_reply = DBUS_SERVICE_REPLY_ALREADY_OWNER;
|
|
|
|
|
else if (!((flags & DBUS_SERVICE_FLAG_REPLACE_EXISTING)))
|
|
|
|
|
service_reply = DBUS_SERVICE_REPLY_SERVICE_EXISTS;
|
|
|
|
|
else if (bus_service_get_prohibit_replacement (service))
|
|
|
|
|
{
|
|
|
|
|
/* Queue the connection */
|
|
|
|
|
if (!bus_service_add_owner (service, connection,
|
|
|
|
|
transaction, error))
|
|
|
|
|
goto out;
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
service_reply = DBUS_SERVICE_REPLY_IN_QUEUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Replace the current owner */
|
|
|
|
|
|
|
|
|
|
/* We enqueue the new owner and remove the first one because
|
|
|
|
|
* that will cause ServiceAcquired and ServiceLost messages to
|
|
|
|
|
* be sent.
|
|
|
|
|
*/
|
2003-01-27 11:20:55 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
/* FIXME this is broken, if the remove_owner fails
|
|
|
|
|
* we don't undo the add_owner
|
|
|
|
|
* (easiest fix is probably to move all this to
|
|
|
|
|
* services.c and have a single routine for it)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!bus_service_add_owner (service, connection,
|
|
|
|
|
transaction, error))
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
if (!bus_service_remove_owner (service, old_owner,
|
|
|
|
|
transaction, error))
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
_dbus_assert (connection == bus_service_get_primary_owner (service));
|
2003-01-27 11:20:55 +00:00
|
|
|
service_reply = DBUS_SERVICE_REPLY_PRIMARY_OWNER;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, service_reply, 0))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2003-02-02 00:39:10 +00:00
|
|
|
|
2003-03-13 00:56:43 +00:00
|
|
|
if (!bus_transaction_send_message (transaction, connection, reply))
|
|
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
|
0))
|
|
|
|
|
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-03-13 00:56:43 +00:00
|
|
|
reply = dbus_message_new_reply (message);
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_set_sender (reply, DBUS_SERVICE_DBUS))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_append_args (reply,
|
|
|
|
|
DBUS_TYPE_UINT32, service != NULL,
|
|
|
|
|
0))
|
|
|
|
|
{
|
|
|
|
|
BUS_SET_OOM (error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bus_transaction_send_message (transaction, connection, reply))
|
|
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
|
0))
|
|
|
|
|
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
|
|
|
|
2003-03-16 22:25:18 +00:00
|
|
|
if (!bus_activation_activate_service (activation, connection, message, name, error))
|
2003-03-13 00:56:43 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
dbus_free (name);
|
|
|
|
|
return retval;
|
2003-02-16 10:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
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[] = {
|
|
|
|
|
{ DBUS_MESSAGE_ACQUIRE_SERVICE, bus_driver_handle_acquire_service },
|
|
|
|
|
{ DBUS_MESSAGE_ACTIVATE_SERVICE, bus_driver_handle_activate_service },
|
|
|
|
|
{ DBUS_MESSAGE_HELLO, bus_driver_handle_hello },
|
|
|
|
|
{ DBUS_MESSAGE_SERVICE_EXISTS, bus_driver_handle_service_exists },
|
|
|
|
|
{ DBUS_MESSAGE_LIST_SERVICES, bus_driver_handle_list_services }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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-03-13 00:56:43 +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
|
|
|
_dbus_verbose ("Driver got a message: %s\n",
|
|
|
|
|
dbus_message_get_name (message));
|
|
|
|
|
|
|
|
|
|
name = dbus_message_get_name (message);
|
|
|
|
|
sender = dbus_message_get_sender (message);
|
|
|
|
|
|
|
|
|
|
if (sender == NULL && (strcmp (name, DBUS_MESSAGE_HELLO) != 0))
|
|
|
|
|
{
|
2003-03-13 00:56:43 +00:00
|
|
|
dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
|
|
|
|
|
"Client tried to send a message other than %s without being registered",
|
|
|
|
|
DBUS_MESSAGE_HELLO);
|
|
|
|
|
|
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
|
|
|
dbus_connection_disconnect (connection);
|
2003-03-13 00:56:43 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < _DBUS_N_ELEMENTS (message_handlers))
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (message_handlers[i].name, name) == 0)
|
|
|
|
|
{
|
|
|
|
|
if ((* message_handlers[i].handler) (connection, transaction, message, error))
|
|
|
|
|
return TRUE;
|
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_set_error (error, DBUS_ERROR_UNKNOWN_MESSAGE,
|
|
|
|
|
"%s does not understand message %s",
|
|
|
|
|
DBUS_SERVICE_DBUS, name);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|