2007-07-14 02:44:01 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2003-04-14 03:25:19 +00:00
|
|
|
/* dbus-send.c Utility program to send messages from the command line
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 Philip Blundell <philb@gnu.org>
|
2022-05-18 14:55:48 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2003-04-14 03:25:19 +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
|
2009-07-10 19:32:38 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-04-14 03:25:19 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2006-12-31 11:31:12 +00:00
|
|
|
#include <config.h>
|
2003-04-14 03:25:19 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <dbus/dbus.h>
|
2015-02-23 22:00:46 +01:00
|
|
|
#include "dbus/dbus-internals.h"
|
2003-04-14 03:25:19 +00:00
|
|
|
|
2010-03-16 15:54:00 +01:00
|
|
|
#ifdef DBUS_WINCE
|
|
|
|
|
#ifndef strdup
|
|
|
|
|
#define strdup _strdup
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-05-16 20:09:25 +00:00
|
|
|
#include "dbus-print-message.h"
|
|
|
|
|
|
2005-05-11 18:48:24 +00:00
|
|
|
static const char *appname;
|
|
|
|
|
|
2016-10-07 19:45:48 +01:00
|
|
|
static void usage (int ecode) _DBUS_GNUC_NORETURN;
|
|
|
|
|
|
2003-04-14 03:25:19 +00:00
|
|
|
static void
|
2005-05-11 18:48:24 +00:00
|
|
|
usage (int ecode)
|
2003-04-14 03:25:19 +00:00
|
|
|
{
|
2019-07-15 12:36:50 +00:00
|
|
|
fprintf (stderr, "Usage: %s [--help] [--system | --session | --bus=ADDRESS | --peer=ADDRESS] [--sender=NAME] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] <destination object path> <message name> [contents ...]\n", appname);
|
2003-05-18 02:39:47 +00:00
|
|
|
exit (ecode);
|
2003-04-14 03:25:19 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-10 11:21:02 +00:00
|
|
|
/* Abort on any allocation failure; there is nothing else we can do. */
|
|
|
|
|
static void
|
|
|
|
|
handle_oom (dbus_bool_t success)
|
|
|
|
|
{
|
|
|
|
|
if (!success)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s: Ran out of memory\n", appname);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 00:02:45 +02:00
|
|
|
static int type_from_name (const char *arg, dbus_bool_t allow_container_types);
|
|
|
|
|
|
2005-05-11 18:48:24 +00:00
|
|
|
static void
|
|
|
|
|
append_arg (DBusMessageIter *iter, int type, const char *value)
|
|
|
|
|
{
|
2005-07-13 21:13:16 +00:00
|
|
|
dbus_uint16_t uint16;
|
|
|
|
|
dbus_int16_t int16;
|
2005-05-11 18:48:24 +00:00
|
|
|
dbus_uint32_t uint32;
|
|
|
|
|
dbus_int32_t int32;
|
2005-07-13 21:13:16 +00:00
|
|
|
dbus_uint64_t uint64;
|
|
|
|
|
dbus_int64_t int64;
|
2005-05-11 18:48:24 +00:00
|
|
|
double d;
|
|
|
|
|
unsigned char byte;
|
|
|
|
|
dbus_bool_t v_BOOLEAN;
|
2017-02-10 11:21:02 +00:00
|
|
|
dbus_bool_t ret;
|
|
|
|
|
|
2005-05-11 18:48:24 +00:00
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case DBUS_TYPE_BYTE:
|
|
|
|
|
byte = strtoul (value, NULL, 0);
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_BYTE, &byte);
|
2005-05-11 18:48:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_DOUBLE:
|
|
|
|
|
d = strtod (value, NULL);
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &d);
|
2005-05-11 18:48:24 +00:00
|
|
|
break;
|
|
|
|
|
|
2005-07-13 21:13:16 +00:00
|
|
|
case DBUS_TYPE_INT16:
|
|
|
|
|
int16 = strtol (value, NULL, 0);
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_INT16, &int16);
|
2005-07-13 21:13:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_UINT16:
|
|
|
|
|
uint16 = strtoul (value, NULL, 0);
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT16, &uint16);
|
2005-07-13 21:13:16 +00:00
|
|
|
break;
|
|
|
|
|
|
2005-05-11 18:48:24 +00:00
|
|
|
case DBUS_TYPE_INT32:
|
|
|
|
|
int32 = strtol (value, NULL, 0);
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_INT32, &int32);
|
2005-05-11 18:48:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_UINT32:
|
|
|
|
|
uint32 = strtoul (value, NULL, 0);
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT32, &uint32);
|
2005-05-11 18:48:24 +00:00
|
|
|
break;
|
|
|
|
|
|
2005-07-13 21:13:16 +00:00
|
|
|
case DBUS_TYPE_INT64:
|
|
|
|
|
int64 = strtoll (value, NULL, 0);
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_INT64, &int64);
|
2005-07-13 21:13:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_UINT64:
|
|
|
|
|
uint64 = strtoull (value, NULL, 0);
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT64, &uint64);
|
2005-07-13 21:13:16 +00:00
|
|
|
break;
|
|
|
|
|
|
2005-05-11 18:48:24 +00:00
|
|
|
case DBUS_TYPE_STRING:
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &value);
|
2005-05-11 18:48:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_OBJECT_PATH:
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_OBJECT_PATH, &value);
|
2005-05-11 18:48:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_BOOLEAN:
|
|
|
|
|
if (strcmp (value, "true") == 0)
|
|
|
|
|
{
|
|
|
|
|
v_BOOLEAN = TRUE;
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN);
|
2005-05-11 18:48:24 +00:00
|
|
|
}
|
|
|
|
|
else if (strcmp (value, "false") == 0)
|
|
|
|
|
{
|
|
|
|
|
v_BOOLEAN = FALSE;
|
2017-02-10 11:21:02 +00:00
|
|
|
ret = dbus_message_iter_append_basic (iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN);
|
2005-05-11 18:48:24 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s: Expected \"true\" or \"false\" instead of \"%s\"\n", appname, value);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2021-04-18 00:02:45 +02:00
|
|
|
case DBUS_TYPE_VARIANT:
|
|
|
|
|
{
|
|
|
|
|
DBusMessageIter subiter;
|
|
|
|
|
|
|
|
|
|
char sig[2] = "\0\0";
|
|
|
|
|
char *subtype = strdup (value);
|
|
|
|
|
char *c = NULL;
|
|
|
|
|
|
|
|
|
|
handle_oom (subtype != NULL);
|
|
|
|
|
c = strchr (subtype, ':');
|
|
|
|
|
if (!c)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s: missing variant subtype specifier\n",
|
|
|
|
|
appname);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
*c = '\0';
|
|
|
|
|
|
|
|
|
|
sig[0] = (char) type_from_name (subtype, TRUE);
|
|
|
|
|
|
|
|
|
|
handle_oom (dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT,
|
|
|
|
|
sig, &subiter));
|
|
|
|
|
append_arg (&subiter, sig[0], c + 1);
|
|
|
|
|
free (subtype);
|
|
|
|
|
ret = dbus_message_iter_close_container (iter, &subiter);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-05-11 18:48:24 +00:00
|
|
|
default:
|
|
|
|
|
fprintf (stderr, "%s: Unsupported data type %c\n", appname, (char) type);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
2017-02-10 11:21:02 +00:00
|
|
|
|
|
|
|
|
handle_oom (ret);
|
2005-05-11 18:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
append_array (DBusMessageIter *iter, int type, const char *value)
|
|
|
|
|
{
|
2005-06-16 04:48:10 +00:00
|
|
|
const char *val;
|
|
|
|
|
char *dupval = strdup (value);
|
2005-05-11 18:48:24 +00:00
|
|
|
|
2017-02-10 11:21:02 +00:00
|
|
|
handle_oom (dupval != NULL);
|
|
|
|
|
|
2005-06-16 04:48:10 +00:00
|
|
|
val = strtok (dupval, ",");
|
|
|
|
|
while (val != NULL)
|
2005-05-11 18:48:24 +00:00
|
|
|
{
|
2005-06-16 04:48:10 +00:00
|
|
|
append_arg (iter, type, val);
|
|
|
|
|
val = strtok (NULL, ",");
|
2005-05-11 18:48:24 +00:00
|
|
|
}
|
2005-06-16 04:48:10 +00:00
|
|
|
free (dupval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
append_dict (DBusMessageIter *iter, int keytype, int valtype, const char *value)
|
|
|
|
|
{
|
|
|
|
|
const char *val;
|
|
|
|
|
char *dupval = strdup (value);
|
|
|
|
|
|
2017-02-10 11:21:02 +00:00
|
|
|
handle_oom (dupval != NULL);
|
|
|
|
|
|
2005-06-16 04:48:10 +00:00
|
|
|
val = strtok (dupval, ",");
|
|
|
|
|
while (val != NULL)
|
|
|
|
|
{
|
|
|
|
|
DBusMessageIter subiter;
|
2008-04-04 14:58:07 -04:00
|
|
|
|
2017-02-10 11:21:02 +00:00
|
|
|
handle_oom (dbus_message_iter_open_container (iter,
|
|
|
|
|
DBUS_TYPE_DICT_ENTRY,
|
|
|
|
|
NULL,
|
|
|
|
|
&subiter));
|
2005-06-16 04:48:10 +00:00
|
|
|
|
|
|
|
|
append_arg (&subiter, keytype, val);
|
|
|
|
|
val = strtok (NULL, ",");
|
|
|
|
|
if (val == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s: Malformed dictionary\n", appname);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
append_arg (&subiter, valtype, val);
|
|
|
|
|
|
2017-02-10 11:21:02 +00:00
|
|
|
handle_oom (dbus_message_iter_close_container (iter, &subiter));
|
2005-06-16 04:48:10 +00:00
|
|
|
val = strtok (NULL, ",");
|
|
|
|
|
}
|
|
|
|
|
free (dupval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2021-04-18 00:02:45 +02:00
|
|
|
type_from_name (const char *arg, dbus_bool_t allow_container_types)
|
2005-06-16 04:48:10 +00:00
|
|
|
{
|
|
|
|
|
int type;
|
|
|
|
|
if (!strcmp (arg, "string"))
|
|
|
|
|
type = DBUS_TYPE_STRING;
|
2005-07-13 21:13:16 +00:00
|
|
|
else if (!strcmp (arg, "int16"))
|
|
|
|
|
type = DBUS_TYPE_INT16;
|
|
|
|
|
else if (!strcmp (arg, "uint16"))
|
|
|
|
|
type = DBUS_TYPE_UINT16;
|
2005-06-16 04:48:10 +00:00
|
|
|
else if (!strcmp (arg, "int32"))
|
|
|
|
|
type = DBUS_TYPE_INT32;
|
|
|
|
|
else if (!strcmp (arg, "uint32"))
|
|
|
|
|
type = DBUS_TYPE_UINT32;
|
2005-07-13 21:13:16 +00:00
|
|
|
else if (!strcmp (arg, "int64"))
|
|
|
|
|
type = DBUS_TYPE_INT64;
|
|
|
|
|
else if (!strcmp (arg, "uint64"))
|
|
|
|
|
type = DBUS_TYPE_UINT64;
|
2005-06-16 04:48:10 +00:00
|
|
|
else if (!strcmp (arg, "double"))
|
|
|
|
|
type = DBUS_TYPE_DOUBLE;
|
|
|
|
|
else if (!strcmp (arg, "byte"))
|
|
|
|
|
type = DBUS_TYPE_BYTE;
|
|
|
|
|
else if (!strcmp (arg, "boolean"))
|
|
|
|
|
type = DBUS_TYPE_BOOLEAN;
|
|
|
|
|
else if (!strcmp (arg, "objpath"))
|
|
|
|
|
type = DBUS_TYPE_OBJECT_PATH;
|
2021-04-18 00:02:45 +02:00
|
|
|
else if (!strcmp(arg, "variant"))
|
|
|
|
|
{
|
|
|
|
|
if (!allow_container_types)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s: A variant cannot be the key in a dictionary\n", appname);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type = DBUS_TYPE_VARIANT;
|
|
|
|
|
}
|
2005-06-16 04:48:10 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s: Unknown type \"%s\"\n", appname, arg);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
return type;
|
2005-05-11 18:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-14 03:25:19 +00:00
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
DBusError error;
|
|
|
|
|
DBusMessage *message;
|
2015-03-04 08:28:09 +01:00
|
|
|
dbus_bool_t print_reply;
|
|
|
|
|
dbus_bool_t print_reply_literal;
|
2004-08-11 14:59:34 +00:00
|
|
|
int reply_timeout;
|
2003-04-14 03:25:19 +00:00
|
|
|
DBusMessageIter iter;
|
|
|
|
|
int i;
|
2003-05-18 02:39:47 +00:00
|
|
|
DBusBusType type = DBUS_BUS_SESSION;
|
2003-09-21 19:53:56 +00:00
|
|
|
const char *dest = NULL;
|
2003-08-31 01:51:44 +00:00
|
|
|
const char *name = NULL;
|
|
|
|
|
const char *path = NULL;
|
2003-08-11 02:11:58 +00:00
|
|
|
int message_type = DBUS_MESSAGE_TYPE_SIGNAL;
|
|
|
|
|
const char *type_str = NULL;
|
2008-10-18 14:50:49 -04:00
|
|
|
const char *address = NULL;
|
2019-07-15 12:36:50 +00:00
|
|
|
const char *sender = NULL;
|
2013-10-08 15:54:11 +01:00
|
|
|
int is_bus = FALSE;
|
2008-10-18 14:50:49 -04:00
|
|
|
int session_or_system = FALSE;
|
2005-05-11 18:48:24 +00:00
|
|
|
|
|
|
|
|
appname = argv[0];
|
2003-08-11 02:11:58 +00:00
|
|
|
|
2003-08-31 01:51:44 +00:00
|
|
|
if (argc < 3)
|
2005-05-11 18:48:24 +00:00
|
|
|
usage (1);
|
2003-04-14 03:25:19 +00:00
|
|
|
|
2003-05-16 20:09:25 +00:00
|
|
|
print_reply = FALSE;
|
2005-07-06 Colin Walters <walters@verbum.org>
* dbus/dbus-glib.h (DBusGPendingCall, DBusGPendingCallNotify)
(DBUS_TYPE_G_PENDING_CALL, dbus_g_pending_call_get_g_type)
(dbus_g_pending_call_ref, dbus_g_pending_call_unref): Delete.
(dbus_g_pending_call_set_notify, dbus_g_pending_call_cancel):
Delete in favor of dbus_g_proxy_begin_call and
dbus_g_proxy_cancel_call.
(DBusGProxyCall, DBusGProxyCallNotify): New.
(dbus_g_proxy_begin_call): Change prototype to take callback, user
data, and destroy function. This replaces
dbus_g_pending_call_set_notify.
(dbus_g_proxy_cancel_call): Prototype.
(DBusGAsyncData): Delete, shouldn't be needed anymore.
* glib/dbus-gproxy.c (struct _DBusGProxy): Add call_id_counter and
pending_calls map.
(struct _DBusGProxyManager): Add bus_proxy member, which is an
internal proxy for calls to the bus. Remove
pending_nameowner_calls, now the internal proxy keeps track.
(dbus_g_proxy_manager_unref): Unref bus proxy, remove reference to
pending_nameowner_calls.
(got_name_owner_cb): Update prototype, and use
dbus_g_proxy_end_call.
(got_name_owner_cb): Remove reference to pending_nameowner_calls.
(dbus_g_proxy_manager_register): Delete directly libdbus code in
favor of using internal proxy.
(dbus_g_proxy_manager_unregister): Update to use
dbus_g_proxy_cancel_call for any pending GetNameOwner call.
(dbus_g_proxy_init): Initialize pending calls map.
(dbus_g_proxy_constructor): New.
(dbus_g_proxy_class_init): Add get/set property functions,
constructor, and add NAME, PATH, and INTERFACE properties.
(cancel_pending_call): New function.
(dbus_g_proxy_dispose): Iterate over any outstanding calls and
cancel them.
(dbus_g_proxy_set_property, dbus_g_proxy_get_property): New.
(GPendingNotifyClosure): New structure.
(d_pending_call_notify, d_pending_call_free): Moved here from
dbus-glib.c.
(DBUS_G_VALUE_ARRAY_COLLECT_ALL): Moved around to satisfy function
ordering.
(manager_begin_bus_call): New internal function for talking to
internal bus proxy.
(dbus_g_proxy_new): Construct object using GObjet properties.
(dbus_g_proxy_begin_call_internal): Update to take user data, etc.
Create closure of same, and insert call into map of pending calls.
(dbus_g_proxy_end_call_internal): Take call id instead of pending
call. Look up pending call in current set. Remove it when we've
completed.
(dbus_g_pending_call_end, dbus_g_proxy_end_call_internal): Delete.
(dbus_g_proxy_begin_call): Change API to take callback, user data,
and destroy function directly.
(dbus_g_proxy_end_call): Update to take DBusGProxyCall.
(dbus_g_proxy_call): Invoke with NULL callback.
(dbus_g_proxy_cancel_call): New function, replaces
dbus_g_pending_call_cancel.
* glib/dbus-gparser.c (validate_signature): Fix call to
dbus_set_g_error.
* glib/dbus-gobject.c (dbus_g_object_type_dbus_metadata_quark):
New quark for attaching metadata to GType.
(info_hash): Delete.
(lookup_object_info): Look up using quark.
(dbus_g_object_type_install_info): Check that a type is classed,
not that it's an object. Also just install type data using quark
instead of using global hash.
* glib/dbus-glib.c (dbus_g_pending_call_ref)
(dbus_g_pending_call_unref, dbus_pending_call_get_g_type)
(GPendingNotifyClosure): Delete.
(d_pending_call_notify, d_pending_call_free): Move to dbus-gproxy.c.
(dbus_g_pending_call_set_notify, dbus_g_pending_call_cancel): Delete.
* glib/dbus-binding-tool-glib.c (generate_client_glue): Disable async
client method generation until we can fix it...
* tools/dbus-viewer.c (load_child_nodes): Use dbus_g_proxy_call.
(load_from_service_thread_func): Ditto.
* tools/dbus-names-model.c (struct NamesModel): Hold
DBusGProxyCall.
(have_names_notify): Update prototype, use
dbus_g_proxy_cancel_call.
(names_model_reload): Update for new dbus_g_proxy_begin_call API.
* tools/dbus-monitor.c (filter_func): Update for print_message
API change.
* test/glib/test-dbus-glib.c: Add more tests for async
invocations. Update many begin_call/end_call pairs to just use
dbus_g_proxy_call.
* tools/dbus-send.c (main): Add --print-reply=literal mode. This
allows us to dump print-introspect.c.
* tools/dbus-print-message.h (print_message): Add literal argument
to print_message which is intended to allow printing arguments without
metadata like "string=".
* tools/dbus-print-message.c (print_iter): Add literal argument.
(print_message): Allow printing string messages literally.
2005-07-06 21:27:53 +00:00
|
|
|
print_reply_literal = FALSE;
|
2004-08-11 14:59:34 +00:00
|
|
|
reply_timeout = -1;
|
2003-05-16 20:09:25 +00:00
|
|
|
|
2003-04-14 03:25:19 +00:00
|
|
|
for (i = 1; i < argc && name == NULL; i++)
|
|
|
|
|
{
|
|
|
|
|
char *arg = argv[i];
|
|
|
|
|
|
2003-05-18 02:39:47 +00:00
|
|
|
if (strcmp (arg, "--system") == 0)
|
2008-10-18 14:50:49 -04:00
|
|
|
{
|
|
|
|
|
type = DBUS_BUS_SYSTEM;
|
|
|
|
|
session_or_system = TRUE;
|
|
|
|
|
}
|
2003-06-19 22:22:37 +00:00
|
|
|
else if (strcmp (arg, "--session") == 0)
|
2008-10-18 14:50:49 -04:00
|
|
|
{
|
|
|
|
|
type = DBUS_BUS_SESSION;
|
|
|
|
|
session_or_system = TRUE;
|
|
|
|
|
}
|
2013-10-08 15:54:11 +01:00
|
|
|
else if ((strstr (arg, "--bus=") == arg) || (strstr (arg, "--peer=") == arg) || (strstr (arg, "--address=") == arg))
|
2008-10-18 14:50:49 -04:00
|
|
|
{
|
2018-10-17 08:33:25 +01:00
|
|
|
/* Check for peer first, to avoid the GCC -Wduplicated-branches
|
|
|
|
|
* warning.
|
|
|
|
|
*/
|
|
|
|
|
if (arg[2] == 'p') /* peer */
|
2008-10-18 14:50:49 -04:00
|
|
|
{
|
2018-10-17 08:33:25 +01:00
|
|
|
is_bus = FALSE;
|
2013-10-08 15:54:11 +01:00
|
|
|
}
|
2018-10-17 08:33:25 +01:00
|
|
|
else if (arg[2] == 'b') /* bus */
|
2013-10-08 15:54:11 +01:00
|
|
|
{
|
2018-10-17 08:33:25 +01:00
|
|
|
is_bus = TRUE;
|
2013-10-08 15:54:11 +01:00
|
|
|
}
|
|
|
|
|
else /* address; keeping backwards compatibility */
|
|
|
|
|
{
|
|
|
|
|
is_bus = FALSE;
|
2013-10-08 15:54:11 +01:00
|
|
|
}
|
2013-10-08 15:54:11 +01:00
|
|
|
|
2013-10-09 11:17:20 +01:00
|
|
|
address = strchr (arg, '=') + 1;
|
2013-10-08 15:54:11 +01:00
|
|
|
|
|
|
|
|
if (address[0] == '\0')
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "\"--peer=\" and \"--bus=\" require an ADDRESS\n");
|
|
|
|
|
usage (1);
|
|
|
|
|
}
|
2008-10-18 14:50:49 -04:00
|
|
|
}
|
2019-07-15 12:36:50 +00:00
|
|
|
else if (strstr (arg, "--sender=") == arg)
|
|
|
|
|
{
|
|
|
|
|
sender = strchr (arg, '=') + 1;
|
|
|
|
|
|
|
|
|
|
if (sender[0] == '\0')
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "\"--sender=\" requires a NAME\n");
|
|
|
|
|
usage (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-06 Colin Walters <walters@verbum.org>
* dbus/dbus-glib.h (DBusGPendingCall, DBusGPendingCallNotify)
(DBUS_TYPE_G_PENDING_CALL, dbus_g_pending_call_get_g_type)
(dbus_g_pending_call_ref, dbus_g_pending_call_unref): Delete.
(dbus_g_pending_call_set_notify, dbus_g_pending_call_cancel):
Delete in favor of dbus_g_proxy_begin_call and
dbus_g_proxy_cancel_call.
(DBusGProxyCall, DBusGProxyCallNotify): New.
(dbus_g_proxy_begin_call): Change prototype to take callback, user
data, and destroy function. This replaces
dbus_g_pending_call_set_notify.
(dbus_g_proxy_cancel_call): Prototype.
(DBusGAsyncData): Delete, shouldn't be needed anymore.
* glib/dbus-gproxy.c (struct _DBusGProxy): Add call_id_counter and
pending_calls map.
(struct _DBusGProxyManager): Add bus_proxy member, which is an
internal proxy for calls to the bus. Remove
pending_nameowner_calls, now the internal proxy keeps track.
(dbus_g_proxy_manager_unref): Unref bus proxy, remove reference to
pending_nameowner_calls.
(got_name_owner_cb): Update prototype, and use
dbus_g_proxy_end_call.
(got_name_owner_cb): Remove reference to pending_nameowner_calls.
(dbus_g_proxy_manager_register): Delete directly libdbus code in
favor of using internal proxy.
(dbus_g_proxy_manager_unregister): Update to use
dbus_g_proxy_cancel_call for any pending GetNameOwner call.
(dbus_g_proxy_init): Initialize pending calls map.
(dbus_g_proxy_constructor): New.
(dbus_g_proxy_class_init): Add get/set property functions,
constructor, and add NAME, PATH, and INTERFACE properties.
(cancel_pending_call): New function.
(dbus_g_proxy_dispose): Iterate over any outstanding calls and
cancel them.
(dbus_g_proxy_set_property, dbus_g_proxy_get_property): New.
(GPendingNotifyClosure): New structure.
(d_pending_call_notify, d_pending_call_free): Moved here from
dbus-glib.c.
(DBUS_G_VALUE_ARRAY_COLLECT_ALL): Moved around to satisfy function
ordering.
(manager_begin_bus_call): New internal function for talking to
internal bus proxy.
(dbus_g_proxy_new): Construct object using GObjet properties.
(dbus_g_proxy_begin_call_internal): Update to take user data, etc.
Create closure of same, and insert call into map of pending calls.
(dbus_g_proxy_end_call_internal): Take call id instead of pending
call. Look up pending call in current set. Remove it when we've
completed.
(dbus_g_pending_call_end, dbus_g_proxy_end_call_internal): Delete.
(dbus_g_proxy_begin_call): Change API to take callback, user data,
and destroy function directly.
(dbus_g_proxy_end_call): Update to take DBusGProxyCall.
(dbus_g_proxy_call): Invoke with NULL callback.
(dbus_g_proxy_cancel_call): New function, replaces
dbus_g_pending_call_cancel.
* glib/dbus-gparser.c (validate_signature): Fix call to
dbus_set_g_error.
* glib/dbus-gobject.c (dbus_g_object_type_dbus_metadata_quark):
New quark for attaching metadata to GType.
(info_hash): Delete.
(lookup_object_info): Look up using quark.
(dbus_g_object_type_install_info): Check that a type is classed,
not that it's an object. Also just install type data using quark
instead of using global hash.
* glib/dbus-glib.c (dbus_g_pending_call_ref)
(dbus_g_pending_call_unref, dbus_pending_call_get_g_type)
(GPendingNotifyClosure): Delete.
(d_pending_call_notify, d_pending_call_free): Move to dbus-gproxy.c.
(dbus_g_pending_call_set_notify, dbus_g_pending_call_cancel): Delete.
* glib/dbus-binding-tool-glib.c (generate_client_glue): Disable async
client method generation until we can fix it...
* tools/dbus-viewer.c (load_child_nodes): Use dbus_g_proxy_call.
(load_from_service_thread_func): Ditto.
* tools/dbus-names-model.c (struct NamesModel): Hold
DBusGProxyCall.
(have_names_notify): Update prototype, use
dbus_g_proxy_cancel_call.
(names_model_reload): Update for new dbus_g_proxy_begin_call API.
* tools/dbus-monitor.c (filter_func): Update for print_message
API change.
* test/glib/test-dbus-glib.c: Add more tests for async
invocations. Update many begin_call/end_call pairs to just use
dbus_g_proxy_call.
* tools/dbus-send.c (main): Add --print-reply=literal mode. This
allows us to dump print-introspect.c.
* tools/dbus-print-message.h (print_message): Add literal argument
to print_message which is intended to allow printing arguments without
metadata like "string=".
* tools/dbus-print-message.c (print_iter): Add literal argument.
(print_message): Allow printing string messages literally.
2005-07-06 21:27:53 +00:00
|
|
|
else if (strncmp (arg, "--print-reply", 13) == 0)
|
2004-03-27 05:29:31 +00:00
|
|
|
{
|
|
|
|
|
print_reply = TRUE;
|
|
|
|
|
message_type = DBUS_MESSAGE_TYPE_METHOD_CALL;
|
2013-06-06 16:58:11 +08:00
|
|
|
if (strcmp (arg + 13, "=literal") == 0)
|
2005-07-06 Colin Walters <walters@verbum.org>
* dbus/dbus-glib.h (DBusGPendingCall, DBusGPendingCallNotify)
(DBUS_TYPE_G_PENDING_CALL, dbus_g_pending_call_get_g_type)
(dbus_g_pending_call_ref, dbus_g_pending_call_unref): Delete.
(dbus_g_pending_call_set_notify, dbus_g_pending_call_cancel):
Delete in favor of dbus_g_proxy_begin_call and
dbus_g_proxy_cancel_call.
(DBusGProxyCall, DBusGProxyCallNotify): New.
(dbus_g_proxy_begin_call): Change prototype to take callback, user
data, and destroy function. This replaces
dbus_g_pending_call_set_notify.
(dbus_g_proxy_cancel_call): Prototype.
(DBusGAsyncData): Delete, shouldn't be needed anymore.
* glib/dbus-gproxy.c (struct _DBusGProxy): Add call_id_counter and
pending_calls map.
(struct _DBusGProxyManager): Add bus_proxy member, which is an
internal proxy for calls to the bus. Remove
pending_nameowner_calls, now the internal proxy keeps track.
(dbus_g_proxy_manager_unref): Unref bus proxy, remove reference to
pending_nameowner_calls.
(got_name_owner_cb): Update prototype, and use
dbus_g_proxy_end_call.
(got_name_owner_cb): Remove reference to pending_nameowner_calls.
(dbus_g_proxy_manager_register): Delete directly libdbus code in
favor of using internal proxy.
(dbus_g_proxy_manager_unregister): Update to use
dbus_g_proxy_cancel_call for any pending GetNameOwner call.
(dbus_g_proxy_init): Initialize pending calls map.
(dbus_g_proxy_constructor): New.
(dbus_g_proxy_class_init): Add get/set property functions,
constructor, and add NAME, PATH, and INTERFACE properties.
(cancel_pending_call): New function.
(dbus_g_proxy_dispose): Iterate over any outstanding calls and
cancel them.
(dbus_g_proxy_set_property, dbus_g_proxy_get_property): New.
(GPendingNotifyClosure): New structure.
(d_pending_call_notify, d_pending_call_free): Moved here from
dbus-glib.c.
(DBUS_G_VALUE_ARRAY_COLLECT_ALL): Moved around to satisfy function
ordering.
(manager_begin_bus_call): New internal function for talking to
internal bus proxy.
(dbus_g_proxy_new): Construct object using GObjet properties.
(dbus_g_proxy_begin_call_internal): Update to take user data, etc.
Create closure of same, and insert call into map of pending calls.
(dbus_g_proxy_end_call_internal): Take call id instead of pending
call. Look up pending call in current set. Remove it when we've
completed.
(dbus_g_pending_call_end, dbus_g_proxy_end_call_internal): Delete.
(dbus_g_proxy_begin_call): Change API to take callback, user data,
and destroy function directly.
(dbus_g_proxy_end_call): Update to take DBusGProxyCall.
(dbus_g_proxy_call): Invoke with NULL callback.
(dbus_g_proxy_cancel_call): New function, replaces
dbus_g_pending_call_cancel.
* glib/dbus-gparser.c (validate_signature): Fix call to
dbus_set_g_error.
* glib/dbus-gobject.c (dbus_g_object_type_dbus_metadata_quark):
New quark for attaching metadata to GType.
(info_hash): Delete.
(lookup_object_info): Look up using quark.
(dbus_g_object_type_install_info): Check that a type is classed,
not that it's an object. Also just install type data using quark
instead of using global hash.
* glib/dbus-glib.c (dbus_g_pending_call_ref)
(dbus_g_pending_call_unref, dbus_pending_call_get_g_type)
(GPendingNotifyClosure): Delete.
(d_pending_call_notify, d_pending_call_free): Move to dbus-gproxy.c.
(dbus_g_pending_call_set_notify, dbus_g_pending_call_cancel): Delete.
* glib/dbus-binding-tool-glib.c (generate_client_glue): Disable async
client method generation until we can fix it...
* tools/dbus-viewer.c (load_child_nodes): Use dbus_g_proxy_call.
(load_from_service_thread_func): Ditto.
* tools/dbus-names-model.c (struct NamesModel): Hold
DBusGProxyCall.
(have_names_notify): Update prototype, use
dbus_g_proxy_cancel_call.
(names_model_reload): Update for new dbus_g_proxy_begin_call API.
* tools/dbus-monitor.c (filter_func): Update for print_message
API change.
* test/glib/test-dbus-glib.c: Add more tests for async
invocations. Update many begin_call/end_call pairs to just use
dbus_g_proxy_call.
* tools/dbus-send.c (main): Add --print-reply=literal mode. This
allows us to dump print-introspect.c.
* tools/dbus-print-message.h (print_message): Add literal argument
to print_message which is intended to allow printing arguments without
metadata like "string=".
* tools/dbus-print-message.c (print_iter): Add literal argument.
(print_message): Allow printing string messages literally.
2005-07-06 21:27:53 +00:00
|
|
|
print_reply_literal = TRUE;
|
2013-06-06 16:58:11 +08:00
|
|
|
else if (*(arg + 13) != '\0')
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "invalid value (%s) of \"--print-reply\"\n", arg + 13);
|
|
|
|
|
usage (1);
|
|
|
|
|
}
|
2004-03-27 05:29:31 +00:00
|
|
|
}
|
2004-08-11 14:59:34 +00:00
|
|
|
else if (strstr (arg, "--reply-timeout=") == arg)
|
|
|
|
|
{
|
2013-06-06 16:58:11 +08:00
|
|
|
if (*(strchr (arg, '=') + 1) == '\0')
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "\"--reply-timeout=\" requires an MSEC\n");
|
|
|
|
|
usage (1);
|
|
|
|
|
}
|
2004-08-11 14:59:34 +00:00
|
|
|
reply_timeout = strtol (strchr (arg, '=') + 1,
|
|
|
|
|
NULL, 10);
|
2013-06-06 16:58:11 +08:00
|
|
|
if (reply_timeout <= 0)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "invalid value (%s) of \"--reply-timeout\"\n",
|
|
|
|
|
strchr (arg, '=') + 1);
|
|
|
|
|
usage (1);
|
|
|
|
|
}
|
2004-08-11 14:59:34 +00:00
|
|
|
}
|
2003-04-14 03:25:19 +00:00
|
|
|
else if (strstr (arg, "--dest=") == arg)
|
2013-06-06 16:58:11 +08:00
|
|
|
{
|
|
|
|
|
if (*(strchr (arg, '=') + 1) == '\0')
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "\"--dest=\" requires an NAME\n");
|
|
|
|
|
usage (1);
|
|
|
|
|
}
|
|
|
|
|
dest = strchr (arg, '=') + 1;
|
|
|
|
|
}
|
2003-08-11 02:11:58 +00:00
|
|
|
else if (strstr (arg, "--type=") == arg)
|
|
|
|
|
type_str = strchr (arg, '=') + 1;
|
2003-05-18 02:39:47 +00:00
|
|
|
else if (!strcmp(arg, "--help"))
|
2005-05-11 18:48:24 +00:00
|
|
|
usage (0);
|
2003-04-14 03:25:19 +00:00
|
|
|
else if (arg[0] == '-')
|
2005-05-11 18:48:24 +00:00
|
|
|
usage (1);
|
2003-08-31 01:51:44 +00:00
|
|
|
else if (path == NULL)
|
|
|
|
|
path = arg;
|
2011-01-26 18:40:49 +00:00
|
|
|
else /* name == NULL guaranteed by the 'while' loop */
|
2003-08-31 01:51:44 +00:00
|
|
|
name = arg;
|
2003-04-14 03:25:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (name == NULL)
|
2005-05-11 18:48:24 +00:00
|
|
|
usage (1);
|
2003-04-14 03:25:19 +00:00
|
|
|
|
2008-10-18 14:50:49 -04:00
|
|
|
if (session_or_system &&
|
|
|
|
|
(address != NULL))
|
|
|
|
|
{
|
2013-10-08 15:54:11 +01:00
|
|
|
fprintf (stderr, "\"--peer\" and \"--bus\" may not be used with \"--system\" or \"--session\"\n");
|
2008-10-18 14:50:49 -04:00
|
|
|
usage (1);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-15 12:36:50 +00:00
|
|
|
if (sender != NULL && address != NULL && !is_bus)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "\"--peer\" may not be used with \"--sender\"\n");
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
if (type_str != NULL)
|
|
|
|
|
{
|
2003-10-10 02:42:21 +00:00
|
|
|
message_type = dbus_message_type_from_string (type_str);
|
|
|
|
|
if (!(message_type == DBUS_MESSAGE_TYPE_METHOD_CALL ||
|
|
|
|
|
message_type == DBUS_MESSAGE_TYPE_SIGNAL))
|
2003-08-11 02:11:58 +00:00
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Message type \"%s\" is not supported\n",
|
|
|
|
|
type_str);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-15 12:36:50 +00:00
|
|
|
|
2003-04-14 03:25:19 +00:00
|
|
|
dbus_error_init (&error);
|
2008-10-18 14:50:49 -04:00
|
|
|
|
2013-06-19 16:35:43 +08:00
|
|
|
if (dest && !dbus_validate_bus_name (dest, &error))
|
2013-06-06 16:58:11 +08:00
|
|
|
{
|
|
|
|
|
fprintf (stderr, "invalid value (%s) of \"--dest\"\n", dest);
|
2019-07-15 12:36:50 +00:00
|
|
|
dbus_error_free (&error);
|
|
|
|
|
usage (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sender && !dbus_validate_bus_name (sender, &error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "invalid value (%s) of \"--sender\"\n", sender);
|
|
|
|
|
dbus_error_free (&error);
|
2013-06-06 16:58:11 +08:00
|
|
|
usage (1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 12:02:27 +01:00
|
|
|
if (!dbus_validate_path (path, &error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s\n", error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-18 14:50:49 -04:00
|
|
|
if (address != NULL)
|
|
|
|
|
{
|
|
|
|
|
connection = dbus_connection_open (address, &error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
connection = dbus_bus_get (type, &error);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 03:25:19 +00:00
|
|
|
if (connection == NULL)
|
|
|
|
|
{
|
2008-10-18 14:50:49 -04:00
|
|
|
fprintf (stderr, "Failed to open connection to \"%s\" message bus: %s\n",
|
|
|
|
|
(address != NULL) ? address :
|
|
|
|
|
((type == DBUS_BUS_SYSTEM) ? "system" : "session"),
|
2003-04-14 03:25:19 +00:00
|
|
|
error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
2013-10-08 15:54:11 +01:00
|
|
|
else if ((address != NULL) && is_bus)
|
|
|
|
|
{
|
|
|
|
|
if (!dbus_bus_register (connection, &error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Failed to register on connection to \"%s\" message bus: %s\n",
|
|
|
|
|
address, error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-14 03:25:19 +00:00
|
|
|
|
2019-07-15 12:36:50 +00:00
|
|
|
if (sender != NULL)
|
|
|
|
|
{
|
|
|
|
|
int ret = dbus_bus_request_name (connection, sender, DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);
|
|
|
|
|
switch (ret)
|
|
|
|
|
{
|
|
|
|
|
case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
|
|
|
|
|
/* success */
|
|
|
|
|
break;
|
|
|
|
|
case DBUS_REQUEST_NAME_REPLY_EXISTS:
|
|
|
|
|
fprintf (stderr, "Requested name \"%s\" already has owner\n", sender);
|
|
|
|
|
exit (1);
|
|
|
|
|
case -1:
|
|
|
|
|
fprintf (stderr, "Failed to request sender name \"%s\": %s\n", sender, error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
exit (1);
|
|
|
|
|
default:
|
|
|
|
|
/* This should be unreachable if the bus is compliant */
|
|
|
|
|
fprintf (stderr, "Failed to request sender name \"%s\": unexpected result code %d\n",
|
|
|
|
|
sender, ret);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL)
|
|
|
|
|
{
|
2003-08-18 22:43:30 +00:00
|
|
|
char *last_dot;
|
|
|
|
|
|
|
|
|
|
last_dot = strrchr (name, '.');
|
|
|
|
|
if (last_dot == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Must use org.mydomain.Interface.Method notation, no dot in \"%s\"\n",
|
|
|
|
|
name);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
*last_dot = '\0';
|
2021-06-21 12:04:05 +01:00
|
|
|
|
|
|
|
|
if (!dbus_validate_interface (name, &error))
|
|
|
|
|
{
|
|
|
|
|
/* Typically this is "Interface name was not valid: \"xxx\""
|
|
|
|
|
* so we don't need to prefix anything special */
|
|
|
|
|
fprintf (stderr, "%s\n", error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_validate_member (last_dot + 1, &error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Invalid method name: %s\n", error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-31 01:51:44 +00:00
|
|
|
message = dbus_message_new_method_call (NULL,
|
|
|
|
|
path,
|
|
|
|
|
name,
|
|
|
|
|
last_dot + 1);
|
2017-02-10 11:21:02 +00:00
|
|
|
handle_oom (message != NULL);
|
2005-06-16 04:48:10 +00:00
|
|
|
dbus_message_set_auto_start (message, TRUE);
|
2003-08-11 02:11:58 +00:00
|
|
|
}
|
|
|
|
|
else if (message_type == DBUS_MESSAGE_TYPE_SIGNAL)
|
|
|
|
|
{
|
2003-08-18 22:43:30 +00:00
|
|
|
char *last_dot;
|
|
|
|
|
|
|
|
|
|
last_dot = strrchr (name, '.');
|
|
|
|
|
if (last_dot == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Must use org.mydomain.Interface.Signal notation, no dot in \"%s\"\n",
|
|
|
|
|
name);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
*last_dot = '\0';
|
2021-06-21 12:04:05 +01:00
|
|
|
|
|
|
|
|
if (!dbus_validate_interface (name, &error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s\n", error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dbus_validate_member (last_dot + 1, &error))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Invalid signal name: %s\n", error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-31 01:51:44 +00:00
|
|
|
message = dbus_message_new_signal (path, name, last_dot + 1);
|
2017-02-10 11:21:02 +00:00
|
|
|
handle_oom (message != NULL);
|
2003-08-11 02:11:58 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Internal error, unknown message type\n");
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 03:25:19 +00:00
|
|
|
if (message == NULL)
|
|
|
|
|
{
|
2006-08-03 20:34:36 +00:00
|
|
|
fprintf (stderr, "Couldn't allocate D-Bus message\n");
|
2003-04-14 03:25:19 +00:00
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
if (dest && !dbus_message_set_destination (message, dest))
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Not enough memory\n");
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-16 15:51:55 +00:00
|
|
|
dbus_message_iter_init_append (message, &iter);
|
2003-04-14 03:25:19 +00:00
|
|
|
|
|
|
|
|
while (i < argc)
|
|
|
|
|
{
|
|
|
|
|
char *arg;
|
|
|
|
|
char *c;
|
2016-08-21 21:30:49 +02:00
|
|
|
int type2;
|
2005-06-16 04:48:10 +00:00
|
|
|
int secondary_type;
|
2005-05-11 18:48:24 +00:00
|
|
|
int container_type;
|
|
|
|
|
DBusMessageIter *target_iter;
|
|
|
|
|
DBusMessageIter container_iter;
|
2003-04-14 03:25:19 +00:00
|
|
|
|
2016-08-21 21:30:49 +02:00
|
|
|
type2 = DBUS_TYPE_INVALID;
|
2017-09-25 16:19:39 +01:00
|
|
|
secondary_type = DBUS_TYPE_INVALID;
|
2003-04-14 03:25:19 +00:00
|
|
|
arg = argv[i++];
|
|
|
|
|
c = strchr (arg, ':');
|
|
|
|
|
|
|
|
|
|
if (c == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*(c++) = 0;
|
|
|
|
|
|
2005-05-11 18:48:24 +00:00
|
|
|
container_type = DBUS_TYPE_INVALID;
|
|
|
|
|
|
|
|
|
|
if (strcmp (arg, "variant") == 0)
|
|
|
|
|
container_type = DBUS_TYPE_VARIANT;
|
|
|
|
|
else if (strcmp (arg, "array") == 0)
|
|
|
|
|
container_type = DBUS_TYPE_ARRAY;
|
2005-06-16 04:48:10 +00:00
|
|
|
else if (strcmp (arg, "dict") == 0)
|
|
|
|
|
container_type = DBUS_TYPE_DICT_ENTRY;
|
2005-05-11 18:48:24 +00:00
|
|
|
|
|
|
|
|
if (container_type != DBUS_TYPE_INVALID)
|
|
|
|
|
{
|
|
|
|
|
arg = c;
|
|
|
|
|
c = strchr (arg, ':');
|
|
|
|
|
if (c == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
*(c++) = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-16 04:48:10 +00:00
|
|
|
if (arg[0] == 0)
|
2016-08-21 21:30:49 +02:00
|
|
|
type2 = DBUS_TYPE_STRING;
|
2003-04-14 03:25:19 +00:00
|
|
|
else
|
2021-04-18 00:02:45 +02:00
|
|
|
type2 = type_from_name (arg, FALSE);
|
2005-06-16 04:48:10 +00:00
|
|
|
|
|
|
|
|
if (container_type == DBUS_TYPE_DICT_ENTRY)
|
2003-04-14 03:25:19 +00:00
|
|
|
{
|
2005-08-01 16:10:34 +00:00
|
|
|
char sig[5];
|
2005-06-16 04:48:10 +00:00
|
|
|
arg = c;
|
|
|
|
|
c = strchr (c, ':');
|
|
|
|
|
if (c == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
*(c++) = 0;
|
2021-04-18 00:02:45 +02:00
|
|
|
secondary_type = type_from_name (arg, TRUE);
|
2005-06-16 04:48:10 +00:00
|
|
|
sig[0] = DBUS_DICT_ENTRY_BEGIN_CHAR;
|
2016-08-21 21:30:49 +02:00
|
|
|
sig[1] = type2;
|
2005-06-16 04:48:10 +00:00
|
|
|
sig[2] = secondary_type;
|
|
|
|
|
sig[3] = DBUS_DICT_ENTRY_END_CHAR;
|
|
|
|
|
sig[4] = '\0';
|
2017-02-10 11:21:02 +00:00
|
|
|
handle_oom (dbus_message_iter_open_container (&iter,
|
|
|
|
|
DBUS_TYPE_ARRAY,
|
|
|
|
|
sig,
|
|
|
|
|
&container_iter));
|
2005-06-16 04:48:10 +00:00
|
|
|
target_iter = &container_iter;
|
2003-04-14 03:25:19 +00:00
|
|
|
}
|
2005-06-16 04:48:10 +00:00
|
|
|
else if (container_type != DBUS_TYPE_INVALID)
|
2003-04-14 03:25:19 +00:00
|
|
|
{
|
2005-05-11 18:48:24 +00:00
|
|
|
char sig[2];
|
2016-08-21 21:30:49 +02:00
|
|
|
sig[0] = type2;
|
2005-05-11 18:48:24 +00:00
|
|
|
sig[1] = '\0';
|
2017-02-10 11:21:02 +00:00
|
|
|
handle_oom (dbus_message_iter_open_container (&iter,
|
|
|
|
|
container_type,
|
|
|
|
|
sig,
|
|
|
|
|
&container_iter));
|
2005-05-11 18:48:24 +00:00
|
|
|
target_iter = &container_iter;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
target_iter = &iter;
|
2004-03-27 05:29:31 +00:00
|
|
|
|
2005-05-11 18:48:24 +00:00
|
|
|
if (container_type == DBUS_TYPE_ARRAY)
|
|
|
|
|
{
|
2016-08-21 21:30:49 +02:00
|
|
|
append_array (target_iter, type2, c);
|
2005-05-11 18:48:24 +00:00
|
|
|
}
|
2005-06-16 04:48:10 +00:00
|
|
|
else if (container_type == DBUS_TYPE_DICT_ENTRY)
|
|
|
|
|
{
|
2017-09-25 16:19:39 +01:00
|
|
|
_dbus_assert (secondary_type != DBUS_TYPE_INVALID);
|
2016-08-21 21:30:49 +02:00
|
|
|
append_dict (target_iter, type2, secondary_type, c);
|
2005-06-16 04:48:10 +00:00
|
|
|
}
|
2005-05-11 18:48:24 +00:00
|
|
|
else
|
2016-08-21 21:30:49 +02:00
|
|
|
append_arg (target_iter, type2, c);
|
2005-05-11 18:48:24 +00:00
|
|
|
|
|
|
|
|
if (container_type != DBUS_TYPE_INVALID)
|
|
|
|
|
{
|
2017-02-10 11:21:02 +00:00
|
|
|
handle_oom (dbus_message_iter_close_container (&iter,
|
|
|
|
|
&container_iter));
|
2003-04-14 03:25:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-16 20:09:25 +00:00
|
|
|
if (print_reply)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *reply;
|
|
|
|
|
|
|
|
|
|
dbus_error_init (&error);
|
|
|
|
|
reply = dbus_connection_send_with_reply_and_block (connection,
|
2004-08-11 14:59:34 +00:00
|
|
|
message, reply_timeout,
|
2003-05-16 20:09:25 +00:00
|
|
|
&error);
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
2005-06-29 Colin Walters <walters@verbum.org>
* glib/dbus-gproxy.c (struct _DBusGProxy): Add new member
name_call for keeping track of any outgoing GetNameOwner call.
Also add for_owner and associated.
(struct _DBusGProxyManager): Add owner_names, which is hash table
that maps a base name to a list of names it owns (that we're
interested in). Add pending_nameowner_calls which is a list of
all outstanding GetNameOwner; avoids us having to iterate over
every proxy. Add unassociated_proxies which keeps track of name
proxies with no associated name owner.
(dbus_g_proxy_manager_unref): Destroy owner_names.
(struct DBusGProxyNameOwnerInfo): New struct for keeping track of
name refcounts.
(find_name_in_info, name_owner_foreach)
(dbus_g_proxy_manager_lookup_name_owner, insert_nameinfo)
(dbus_g_proxy_manager_monitor_name_owner)
(dbus_g_proxy_manager_unmonitor_name_owner)
(unassociate_proxies, dbus_g_proxy_manager_replace_name_owner):
New functions; they manipulate the owner_names mapping.
(got_name_owner_cb): New function.
(get_name_owner): New function, extracted from
dbus_g_proxy_new_for_name_owner.
(dbus_g_proxy_manager_register): For now we need to keep track of
all NameOwnerChanged. Also if the proxy is for a name, if we
don't already know the name owner, queue a new GetNameOwner
request and add it to our list of unassociated proxies. Otherwise
inc the refcount.
(dbus_g_proxy_manager_unregister): If this proxy is for a name,
cancel any pending GetNameOwner call, etc.
(dbus_g_proxy_manager_filter): Handle NameOwnerChanged. Also use
the owner_names mapping to look up the current names for the
signal source, and dispatch to any proxies for that name.
(dbus_g_proxy_new): Initialize new members.
(dbus_g_proxy_new_for_name): Delete unused proxy variable.
(dbus_g_proxy_new_for_name_owner): Use get_name_owner.
(dbus_g_pending_call_end_valist): New function, extracted from
dbus_g_proxy_end_call_internal. Useful when we don't have a proxy
but want to use the GLib infrastructure. Also note how many
arguments in reply were over.
(dbus_g_pending_call_end): New function, just call
dbus_g_pending_call_end_valist.
(dbus_g_proxy_end_call_internal): Just call
dbus_g_pending_call_end_valist.
* glib/dbus-gobject.c (_dbus_gobject_lookup_marshaller): Fix lookup
of builtin marshaller for STRING_STRING_STRING.
* test/glib/test-dbus-glib.c:
* test/glib/test-service-glib.c:
* test/glib/test-service-glib.xml:
Extend tests to cover name proxies, destruction of owner proxies,
etc.
* glib/examples/example-signal-recipient.c
(dbus_g_proxy_new_for_name_owner): Create a name proxy.
* tools/dbus-send.c (main): Print D-BUS error name in addition
to message.
2005-06-29 16:59:00 +00:00
|
|
|
fprintf (stderr, "Error %s: %s\n",
|
|
|
|
|
error.name,
|
2003-05-16 20:09:25 +00:00
|
|
|
error.message);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reply)
|
|
|
|
|
{
|
2023-08-22 14:02:16 +02:00
|
|
|
dbus_int64_t sec;
|
|
|
|
|
long usec;
|
2015-02-23 22:00:46 +01:00
|
|
|
|
|
|
|
|
_dbus_get_real_time (&sec, &usec);
|
|
|
|
|
print_message (reply, print_reply_literal, sec, usec);
|
2003-05-16 20:09:25 +00:00
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dbus_connection_send (connection, message, NULL);
|
|
|
|
|
dbus_connection_flush (connection);
|
|
|
|
|
}
|
2003-04-14 03:25:19 +00:00
|
|
|
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
|
2006-10-17 22:31:16 +00:00
|
|
|
dbus_connection_unref (connection);
|
2003-04-14 03:25:19 +00:00
|
|
|
|
|
|
|
|
exit (0);
|
|
|
|
|
}
|