2010-05-06 20:13:59 +02:00
|
|
|
/* GDBus - GLib D-Bus Library
|
|
|
|
*
|
2010-05-09 19:14:55 +02:00
|
|
|
* Copyright (C) 2008-2010 Red Hat, Inc.
|
2010-05-06 20:13:59 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
2014-01-23 12:58:29 +01:00
|
|
|
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2010-05-06 20:13:59 +02:00
|
|
|
*
|
|
|
|
* Author: David Zeuthen <davidz@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2010-06-17 23:58:25 +02:00
|
|
|
/* Uncomment to debug serializer code */
|
|
|
|
/* #define DEBUG_SERIALIZER */
|
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-05-06 22:34:23 +02:00
|
|
|
#include <string.h>
|
2010-05-14 14:38:07 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2013-11-14 16:12:02 +01:00
|
|
|
#if MAJOR_IN_MKDEV
|
|
|
|
#include <sys/mkdev.h>
|
|
|
|
#elif MAJOR_IN_SYSMACROS
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
#endif
|
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
#include "gdbusutils.h"
|
|
|
|
#include "gdbusmessage.h"
|
|
|
|
#include "gdbuserror.h"
|
|
|
|
#include "gioenumtypes.h"
|
|
|
|
#include "ginputstream.h"
|
|
|
|
#include "gdatainputstream.h"
|
|
|
|
#include "gmemoryinputstream.h"
|
|
|
|
#include "goutputstream.h"
|
|
|
|
#include "gdataoutputstream.h"
|
|
|
|
#include "gmemoryoutputstream.h"
|
|
|
|
#include "gseekable.h"
|
|
|
|
#include "gioerror.h"
|
2010-06-17 23:58:25 +02:00
|
|
|
#include "gdbusprivate.h"
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
#ifdef G_OS_UNIX
|
2010-05-14 02:29:04 +02:00
|
|
|
#include "gunixfdlist.h"
|
2010-05-06 20:13:59 +02:00
|
|
|
#endif
|
|
|
|
|
2010-05-06 22:34:23 +02:00
|
|
|
#include "glibintl.h"
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
typedef struct _GMemoryBuffer GMemoryBuffer;
|
|
|
|
struct _GMemoryBuffer
|
|
|
|
{
|
|
|
|
gsize len;
|
|
|
|
gsize valid_len;
|
|
|
|
gsize pos;
|
|
|
|
gchar *data;
|
|
|
|
GDataStreamByteOrder byte_order;
|
|
|
|
};
|
|
|
|
|
2014-07-04 20:59:17 +02:00
|
|
|
static gboolean
|
|
|
|
g_memory_buffer_is_byteswapped (GMemoryBuffer *mbuf)
|
|
|
|
{
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
return mbuf->byte_order == G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN;
|
|
|
|
#else
|
|
|
|
return mbuf->byte_order == G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
static guchar
|
2014-05-09 15:06:52 +02:00
|
|
|
g_memory_buffer_read_byte (GMemoryBuffer *mbuf)
|
2012-11-01 01:44:03 +01:00
|
|
|
{
|
|
|
|
if (mbuf->pos >= mbuf->valid_len)
|
|
|
|
return 0;
|
|
|
|
return mbuf->data [mbuf->pos++];
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint16
|
2014-05-09 15:06:52 +02:00
|
|
|
g_memory_buffer_read_int16 (GMemoryBuffer *mbuf)
|
2012-11-01 01:44:03 +01:00
|
|
|
{
|
|
|
|
gint16 v;
|
|
|
|
|
|
|
|
if (mbuf->pos > mbuf->valid_len - 2)
|
|
|
|
{
|
|
|
|
mbuf->pos = mbuf->valid_len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (&v, mbuf->data + mbuf->pos, 2);
|
|
|
|
mbuf->pos += 2;
|
2014-07-04 20:59:17 +02:00
|
|
|
|
|
|
|
if (g_memory_buffer_is_byteswapped (mbuf))
|
|
|
|
v = GUINT16_SWAP_LE_BE (v);
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint16
|
2014-05-09 15:06:52 +02:00
|
|
|
g_memory_buffer_read_uint16 (GMemoryBuffer *mbuf)
|
2012-11-01 01:44:03 +01:00
|
|
|
{
|
|
|
|
guint16 v;
|
|
|
|
|
|
|
|
if (mbuf->pos > mbuf->valid_len - 2)
|
|
|
|
{
|
|
|
|
mbuf->pos = mbuf->valid_len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (&v, mbuf->data + mbuf->pos, 2);
|
|
|
|
mbuf->pos += 2;
|
2014-07-04 20:59:17 +02:00
|
|
|
|
|
|
|
if (g_memory_buffer_is_byteswapped (mbuf))
|
|
|
|
v = GUINT16_SWAP_LE_BE (v);
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint32
|
2014-05-09 15:06:52 +02:00
|
|
|
g_memory_buffer_read_int32 (GMemoryBuffer *mbuf)
|
2012-11-01 01:44:03 +01:00
|
|
|
{
|
|
|
|
gint32 v;
|
|
|
|
|
|
|
|
if (mbuf->pos > mbuf->valid_len - 4)
|
|
|
|
{
|
|
|
|
mbuf->pos = mbuf->valid_len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (&v, mbuf->data + mbuf->pos, 4);
|
|
|
|
mbuf->pos += 4;
|
2014-07-04 20:59:17 +02:00
|
|
|
|
|
|
|
if (g_memory_buffer_is_byteswapped (mbuf))
|
|
|
|
v = GUINT32_SWAP_LE_BE (v);
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint32
|
2014-05-09 15:06:52 +02:00
|
|
|
g_memory_buffer_read_uint32 (GMemoryBuffer *mbuf)
|
2012-11-01 01:44:03 +01:00
|
|
|
{
|
|
|
|
guint32 v;
|
|
|
|
|
|
|
|
if (mbuf->pos > mbuf->valid_len - 4)
|
|
|
|
{
|
|
|
|
mbuf->pos = mbuf->valid_len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (&v, mbuf->data + mbuf->pos, 4);
|
|
|
|
mbuf->pos += 4;
|
2014-07-04 20:59:17 +02:00
|
|
|
|
|
|
|
if (g_memory_buffer_is_byteswapped (mbuf))
|
|
|
|
v = GUINT32_SWAP_LE_BE (v);
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint64
|
2014-05-09 15:06:52 +02:00
|
|
|
g_memory_buffer_read_int64 (GMemoryBuffer *mbuf)
|
2012-11-01 01:44:03 +01:00
|
|
|
{
|
|
|
|
gint64 v;
|
|
|
|
|
|
|
|
if (mbuf->pos > mbuf->valid_len - 8)
|
|
|
|
{
|
|
|
|
mbuf->pos = mbuf->valid_len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (&v, mbuf->data + mbuf->pos, 8);
|
|
|
|
mbuf->pos += 8;
|
2014-07-04 20:59:17 +02:00
|
|
|
|
|
|
|
if (g_memory_buffer_is_byteswapped (mbuf))
|
|
|
|
v = GUINT64_SWAP_LE_BE (v);
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint64
|
2014-05-09 15:06:52 +02:00
|
|
|
g_memory_buffer_read_uint64 (GMemoryBuffer *mbuf)
|
2012-11-01 01:44:03 +01:00
|
|
|
{
|
|
|
|
guint64 v;
|
|
|
|
|
|
|
|
if (mbuf->pos > mbuf->valid_len - 8)
|
|
|
|
{
|
|
|
|
mbuf->pos = mbuf->valid_len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (&v, mbuf->data + mbuf->pos, 8);
|
|
|
|
mbuf->pos += 8;
|
2014-07-04 20:59:17 +02:00
|
|
|
|
|
|
|
if (g_memory_buffer_is_byteswapped (mbuf))
|
|
|
|
v = GUINT64_SWAP_LE_BE (v);
|
|
|
|
|
|
|
|
return v;
|
2012-11-01 01:44:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define MIN_ARRAY_SIZE 128
|
|
|
|
|
2014-10-29 23:12:39 +01:00
|
|
|
static gsize
|
|
|
|
g_nearest_pow (gsize num)
|
2012-11-01 01:44:03 +01:00
|
|
|
{
|
2014-10-29 23:12:39 +01:00
|
|
|
gsize n = 1;
|
2012-11-01 01:44:03 +01:00
|
|
|
|
2014-10-29 23:12:39 +01:00
|
|
|
while (n < num && n > 0)
|
2012-11-01 01:44:03 +01:00
|
|
|
n <<= 1;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-09 15:06:52 +02:00
|
|
|
array_resize (GMemoryBuffer *mbuf,
|
|
|
|
gsize size)
|
2012-11-01 01:44:03 +01:00
|
|
|
{
|
|
|
|
gpointer data;
|
|
|
|
gsize len;
|
|
|
|
|
|
|
|
if (mbuf->len == size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
len = mbuf->len;
|
|
|
|
data = g_realloc (mbuf->data, size);
|
|
|
|
|
|
|
|
if (size > len)
|
|
|
|
memset ((guint8 *)data + len, 0, size - len);
|
|
|
|
|
|
|
|
mbuf->data = data;
|
|
|
|
mbuf->len = size;
|
|
|
|
|
|
|
|
if (mbuf->len < mbuf->valid_len)
|
|
|
|
mbuf->valid_len = mbuf->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_memory_buffer_write (GMemoryBuffer *mbuf,
|
2014-05-09 15:06:52 +02:00
|
|
|
const void *buffer,
|
|
|
|
gsize count)
|
2012-11-01 01:44:03 +01:00
|
|
|
{
|
|
|
|
guint8 *dest;
|
|
|
|
gsize new_size;
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* Check for address space overflow, but only if the buffer is resizable.
|
|
|
|
Otherwise we just do a short write and don't worry. */
|
|
|
|
if (mbuf->pos + count < mbuf->pos)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (mbuf->pos + count > mbuf->len)
|
|
|
|
{
|
|
|
|
/* At least enought to fit the write, rounded up
|
|
|
|
for greater than linear growth.
|
|
|
|
TODO: This wastes a lot of memory at large buffer sizes.
|
|
|
|
Figure out a more rational allocation strategy. */
|
|
|
|
new_size = g_nearest_pow (mbuf->pos + count);
|
2014-10-29 23:12:39 +01:00
|
|
|
/* Check for overflow again. We have checked if
|
|
|
|
pos + count > G_MAXSIZE, but now check if g_nearest_pow () has
|
|
|
|
overflowed */
|
|
|
|
if (new_size == 0)
|
2012-11-01 01:44:03 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
new_size = MAX (new_size, MIN_ARRAY_SIZE);
|
|
|
|
array_resize (mbuf, new_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
dest = (guint8 *)mbuf->data + mbuf->pos;
|
|
|
|
memcpy (dest, buffer, count);
|
|
|
|
mbuf->pos += count;
|
|
|
|
|
|
|
|
if (mbuf->pos > mbuf->valid_len)
|
|
|
|
mbuf->valid_len = mbuf->pos;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_memory_buffer_put_byte (GMemoryBuffer *mbuf,
|
|
|
|
guchar data)
|
|
|
|
{
|
|
|
|
return g_memory_buffer_write (mbuf, &data, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_memory_buffer_put_int16 (GMemoryBuffer *mbuf,
|
|
|
|
gint16 data)
|
|
|
|
{
|
|
|
|
switch (mbuf->byte_order)
|
|
|
|
{
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN:
|
|
|
|
data = GINT16_TO_BE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN:
|
|
|
|
data = GINT16_TO_LE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_memory_buffer_write (mbuf, &data, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_memory_buffer_put_uint16 (GMemoryBuffer *mbuf,
|
|
|
|
guint16 data)
|
|
|
|
{
|
|
|
|
switch (mbuf->byte_order)
|
|
|
|
{
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN:
|
|
|
|
data = GUINT16_TO_BE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN:
|
|
|
|
data = GUINT16_TO_LE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_memory_buffer_write (mbuf, &data, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_memory_buffer_put_int32 (GMemoryBuffer *mbuf,
|
|
|
|
gint32 data)
|
|
|
|
{
|
|
|
|
switch (mbuf->byte_order)
|
|
|
|
{
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN:
|
|
|
|
data = GINT32_TO_BE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN:
|
|
|
|
data = GINT32_TO_LE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_memory_buffer_write (mbuf, &data, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_memory_buffer_put_uint32 (GMemoryBuffer *mbuf,
|
|
|
|
guint32 data)
|
|
|
|
{
|
|
|
|
switch (mbuf->byte_order)
|
|
|
|
{
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN:
|
|
|
|
data = GUINT32_TO_BE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN:
|
|
|
|
data = GUINT32_TO_LE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_memory_buffer_write (mbuf, &data, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_memory_buffer_put_int64 (GMemoryBuffer *mbuf,
|
|
|
|
gint64 data)
|
|
|
|
{
|
|
|
|
switch (mbuf->byte_order)
|
|
|
|
{
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN:
|
|
|
|
data = GINT64_TO_BE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN:
|
|
|
|
data = GINT64_TO_LE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_memory_buffer_write (mbuf, &data, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_memory_buffer_put_uint64 (GMemoryBuffer *mbuf,
|
|
|
|
guint64 data)
|
|
|
|
{
|
|
|
|
switch (mbuf->byte_order)
|
|
|
|
{
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN:
|
|
|
|
data = GUINT64_TO_BE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN:
|
|
|
|
data = GUINT64_TO_LE (data);
|
|
|
|
break;
|
|
|
|
case G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_memory_buffer_write (mbuf, &data, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_memory_buffer_put_string (GMemoryBuffer *mbuf,
|
|
|
|
const char *str)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (str != NULL, FALSE);
|
|
|
|
|
|
|
|
return g_memory_buffer_write (mbuf, str, strlen (str));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
/**
|
|
|
|
* SECTION:gdbusmessage
|
|
|
|
* @short_description: D-Bus Message
|
2010-05-06 21:31:45 +02:00
|
|
|
* @include: gio/gio.h
|
2010-05-06 20:13:59 +02:00
|
|
|
*
|
|
|
|
* A type for representing D-Bus messages that can be sent or received
|
|
|
|
* on a #GDBusConnection.
|
|
|
|
*/
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
typedef struct _GDBusMessageClass GDBusMessageClass;
|
2010-07-07 21:57:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GDBusMessageClass:
|
|
|
|
*
|
|
|
|
* Class structure for #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
struct _GDBusMessageClass
|
|
|
|
{
|
|
|
|
/*< private >*/
|
|
|
|
GObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
/**
|
|
|
|
* GDBusMessage:
|
|
|
|
*
|
|
|
|
* The #GDBusMessage structure contains only private data and should
|
|
|
|
* only be accessed using the provided API.
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
struct _GDBusMessage
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2010-07-07 22:35:17 +02:00
|
|
|
/*< private >*/
|
|
|
|
GObject parent_instance;
|
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
GDBusMessageType type;
|
|
|
|
GDBusMessageFlags flags;
|
2010-09-09 17:37:14 +02:00
|
|
|
gboolean locked;
|
|
|
|
GDBusMessageByteOrder byte_order;
|
2010-05-06 20:13:59 +02:00
|
|
|
guchar major_protocol_version;
|
|
|
|
guint32 serial;
|
|
|
|
GHashTable *headers;
|
|
|
|
GVariant *body;
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
GUnixFDList *fd_list;
|
|
|
|
#endif
|
2010-09-09 17:37:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_LOCKED
|
2010-05-06 20:13:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GDBusMessage, g_dbus_message, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_dbus_message_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GDBusMessage *message = G_DBUS_MESSAGE (object);
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->headers != NULL)
|
|
|
|
g_hash_table_unref (message->headers);
|
|
|
|
if (message->body != NULL)
|
|
|
|
g_variant_unref (message->body);
|
2010-05-06 20:13:59 +02:00
|
|
|
#ifdef G_OS_UNIX
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->fd_list != NULL)
|
|
|
|
g_object_unref (message->fd_list);
|
2010-05-06 20:13:59 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (G_OBJECT_CLASS (g_dbus_message_parent_class)->finalize != NULL)
|
|
|
|
G_OBJECT_CLASS (g_dbus_message_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2010-09-09 17:37:14 +02:00
|
|
|
static void
|
|
|
|
g_dbus_message_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GDBusMessage *message = G_DBUS_MESSAGE (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_LOCKED:
|
|
|
|
g_value_set_boolean (value, g_dbus_message_get_locked (message));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
static void
|
|
|
|
g_dbus_message_class_init (GDBusMessageClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
gobject_class->finalize = g_dbus_message_finalize;
|
2010-09-09 17:37:14 +02:00
|
|
|
gobject_class->get_property = g_dbus_message_get_property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GDBusConnection:locked:
|
|
|
|
*
|
|
|
|
* A boolean specifying whether the message is locked.
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_LOCKED,
|
|
|
|
g_param_spec_boolean ("locked",
|
|
|
|
P_("Locked"),
|
|
|
|
P_("Whether the message is locked"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
G_PARAM_STATIC_NAME |
|
|
|
|
G_PARAM_STATIC_BLURB |
|
|
|
|
G_PARAM_STATIC_NICK));
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_dbus_message_init (GDBusMessage *message)
|
|
|
|
{
|
2010-08-04 19:32:19 +02:00
|
|
|
/* Any D-Bus implementation is supposed to handle both Big and
|
|
|
|
* Little Endian encodings and the Endianness is part of the D-Bus
|
|
|
|
* message - we prefer to use Big Endian (since it's Network Byte
|
|
|
|
* Order and just easier to read for humans) but if the machine is
|
|
|
|
* Little Endian we use that for performance reasons.
|
|
|
|
*/
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
message->byte_order = G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN;
|
|
|
|
#else
|
|
|
|
/* this could also be G_PDP_ENDIAN */
|
|
|
|
message->byte_order = G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN;
|
|
|
|
#endif
|
2010-07-07 22:35:17 +02:00
|
|
|
message->headers = g_hash_table_new_full (g_direct_hash,
|
|
|
|
g_direct_equal,
|
|
|
|
NULL,
|
|
|
|
(GDestroyNotify) g_variant_unref);
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_new:
|
|
|
|
*
|
|
|
|
* Creates a new empty #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Returns: A #GDBusMessage. Free with g_object_unref().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GDBusMessage *
|
|
|
|
g_dbus_message_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (G_TYPE_DBUS_MESSAGE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_new_method_call:
|
2012-03-24 13:58:45 +01:00
|
|
|
* @name: (allow-none): A valid D-Bus name or %NULL.
|
2010-05-06 20:13:59 +02:00
|
|
|
* @path: A valid object path.
|
2012-03-24 13:58:45 +01:00
|
|
|
* @interface_: (allow-none): A valid D-Bus interface name or %NULL.
|
2010-05-06 20:13:59 +02:00
|
|
|
* @method: A valid method name.
|
|
|
|
*
|
|
|
|
* Creates a new #GDBusMessage for a method call.
|
|
|
|
*
|
|
|
|
* Returns: A #GDBusMessage. Free with g_object_unref().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GDBusMessage *
|
|
|
|
g_dbus_message_new_method_call (const gchar *name,
|
|
|
|
const gchar *path,
|
2010-05-20 16:51:00 +02:00
|
|
|
const gchar *interface_,
|
2010-05-06 20:13:59 +02:00
|
|
|
const gchar *method)
|
|
|
|
{
|
|
|
|
GDBusMessage *message;
|
|
|
|
|
|
|
|
g_return_val_if_fail (name == NULL || g_dbus_is_name (name), NULL);
|
|
|
|
g_return_val_if_fail (g_variant_is_object_path (path), NULL);
|
|
|
|
g_return_val_if_fail (g_dbus_is_member_name (method), NULL);
|
2010-05-20 16:51:00 +02:00
|
|
|
g_return_val_if_fail (interface_ == NULL || g_dbus_is_interface_name (interface_), NULL);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
message = g_dbus_message_new ();
|
2010-07-07 22:35:17 +02:00
|
|
|
message->type = G_DBUS_MESSAGE_TYPE_METHOD_CALL;
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
if (name != NULL)
|
|
|
|
g_dbus_message_set_destination (message, name);
|
|
|
|
g_dbus_message_set_path (message, path);
|
|
|
|
g_dbus_message_set_member (message, method);
|
2010-05-20 16:51:00 +02:00
|
|
|
if (interface_ != NULL)
|
|
|
|
g_dbus_message_set_interface (message, interface_);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_new_signal:
|
|
|
|
* @path: A valid object path.
|
2010-08-04 20:38:51 +02:00
|
|
|
* @interface_: A valid D-Bus interface name.
|
2010-05-06 20:13:59 +02:00
|
|
|
* @signal: A valid signal name.
|
|
|
|
*
|
|
|
|
* Creates a new #GDBusMessage for a signal emission.
|
|
|
|
*
|
|
|
|
* Returns: A #GDBusMessage. Free with g_object_unref().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GDBusMessage *
|
|
|
|
g_dbus_message_new_signal (const gchar *path,
|
2010-05-20 16:51:00 +02:00
|
|
|
const gchar *interface_,
|
2010-05-06 20:13:59 +02:00
|
|
|
const gchar *signal)
|
|
|
|
{
|
|
|
|
GDBusMessage *message;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_variant_is_object_path (path), NULL);
|
|
|
|
g_return_val_if_fail (g_dbus_is_member_name (signal), NULL);
|
2010-08-04 20:38:51 +02:00
|
|
|
g_return_val_if_fail (g_dbus_is_interface_name (interface_), NULL);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
message = g_dbus_message_new ();
|
2010-07-07 22:35:17 +02:00
|
|
|
message->type = G_DBUS_MESSAGE_TYPE_SIGNAL;
|
|
|
|
message->flags = G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED;
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
g_dbus_message_set_path (message, path);
|
|
|
|
g_dbus_message_set_member (message, signal);
|
2010-08-04 20:38:51 +02:00
|
|
|
g_dbus_message_set_interface (message, interface_);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_new_method_reply:
|
|
|
|
* @method_call_message: A message of type %G_DBUS_MESSAGE_TYPE_METHOD_CALL to
|
|
|
|
* create a reply message to.
|
|
|
|
*
|
|
|
|
* Creates a new #GDBusMessage that is a reply to @method_call_message.
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): #GDBusMessage. Free with g_object_unref().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GDBusMessage *
|
|
|
|
g_dbus_message_new_method_reply (GDBusMessage *method_call_message)
|
|
|
|
{
|
|
|
|
GDBusMessage *message;
|
|
|
|
const gchar *sender;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (method_call_message), NULL);
|
2010-05-06 23:31:51 +02:00
|
|
|
g_return_val_if_fail (g_dbus_message_get_message_type (method_call_message) == G_DBUS_MESSAGE_TYPE_METHOD_CALL, NULL);
|
2010-05-06 20:13:59 +02:00
|
|
|
g_return_val_if_fail (g_dbus_message_get_serial (method_call_message) != 0, NULL);
|
|
|
|
|
|
|
|
message = g_dbus_message_new ();
|
2010-07-07 22:35:17 +02:00
|
|
|
message->type = G_DBUS_MESSAGE_TYPE_METHOD_RETURN;
|
|
|
|
message->flags = G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED;
|
2010-08-04 19:32:19 +02:00
|
|
|
/* reply with same endianness */
|
|
|
|
message->byte_order = method_call_message->byte_order;
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
g_dbus_message_set_reply_serial (message, g_dbus_message_get_serial (method_call_message));
|
|
|
|
sender = g_dbus_message_get_sender (method_call_message);
|
|
|
|
if (sender != NULL)
|
|
|
|
g_dbus_message_set_destination (message, sender);
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_new_method_error:
|
|
|
|
* @method_call_message: A message of type %G_DBUS_MESSAGE_TYPE_METHOD_CALL to
|
|
|
|
* create a reply message to.
|
|
|
|
* @error_name: A valid D-Bus error name.
|
|
|
|
* @error_message_format: The D-Bus error message in a printf() format.
|
|
|
|
* @...: Arguments for @error_message_format.
|
|
|
|
*
|
|
|
|
* Creates a new #GDBusMessage that is an error reply to @method_call_message.
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): A #GDBusMessage. Free with g_object_unref().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GDBusMessage *
|
|
|
|
g_dbus_message_new_method_error (GDBusMessage *method_call_message,
|
|
|
|
const gchar *error_name,
|
|
|
|
const gchar *error_message_format,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GDBusMessage *ret;
|
|
|
|
va_list var_args;
|
|
|
|
|
|
|
|
va_start (var_args, error_message_format);
|
|
|
|
ret = g_dbus_message_new_method_error_valist (method_call_message,
|
|
|
|
error_name,
|
|
|
|
error_message_format,
|
|
|
|
var_args);
|
|
|
|
va_end (var_args);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_new_method_error_literal:
|
|
|
|
* @method_call_message: A message of type %G_DBUS_MESSAGE_TYPE_METHOD_CALL to
|
|
|
|
* create a reply message to.
|
|
|
|
* @error_name: A valid D-Bus error name.
|
|
|
|
* @error_message: The D-Bus error message.
|
|
|
|
*
|
|
|
|
* Creates a new #GDBusMessage that is an error reply to @method_call_message.
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): A #GDBusMessage. Free with g_object_unref().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GDBusMessage *
|
|
|
|
g_dbus_message_new_method_error_literal (GDBusMessage *method_call_message,
|
|
|
|
const gchar *error_name,
|
|
|
|
const gchar *error_message)
|
|
|
|
{
|
|
|
|
GDBusMessage *message;
|
|
|
|
const gchar *sender;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (method_call_message), NULL);
|
2010-05-06 23:31:51 +02:00
|
|
|
g_return_val_if_fail (g_dbus_message_get_message_type (method_call_message) == G_DBUS_MESSAGE_TYPE_METHOD_CALL, NULL);
|
2010-05-06 20:13:59 +02:00
|
|
|
g_return_val_if_fail (g_dbus_message_get_serial (method_call_message) != 0, NULL);
|
|
|
|
g_return_val_if_fail (g_dbus_is_name (error_name), NULL);
|
|
|
|
g_return_val_if_fail (error_message != NULL, NULL);
|
|
|
|
|
|
|
|
message = g_dbus_message_new ();
|
2010-07-07 22:35:17 +02:00
|
|
|
message->type = G_DBUS_MESSAGE_TYPE_ERROR;
|
|
|
|
message->flags = G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED;
|
2010-08-04 19:32:19 +02:00
|
|
|
/* reply with same endianness */
|
|
|
|
message->byte_order = method_call_message->byte_order;
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
g_dbus_message_set_reply_serial (message, g_dbus_message_get_serial (method_call_message));
|
|
|
|
g_dbus_message_set_error_name (message, error_name);
|
|
|
|
g_dbus_message_set_body (message, g_variant_new ("(s)", error_message));
|
|
|
|
|
|
|
|
sender = g_dbus_message_get_sender (method_call_message);
|
|
|
|
if (sender != NULL)
|
|
|
|
g_dbus_message_set_destination (message, sender);
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_new_method_error_valist:
|
|
|
|
* @method_call_message: A message of type %G_DBUS_MESSAGE_TYPE_METHOD_CALL to
|
|
|
|
* create a reply message to.
|
|
|
|
* @error_name: A valid D-Bus error name.
|
|
|
|
* @error_message_format: The D-Bus error message in a printf() format.
|
|
|
|
* @var_args: Arguments for @error_message_format.
|
|
|
|
*
|
|
|
|
* Like g_dbus_message_new_method_error() but intended for language bindings.
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): A #GDBusMessage. Free with g_object_unref().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
2013-01-13 17:05:14 +01:00
|
|
|
G_GNUC_PRINTF(3, 0)
|
2010-05-06 20:13:59 +02:00
|
|
|
GDBusMessage *
|
|
|
|
g_dbus_message_new_method_error_valist (GDBusMessage *method_call_message,
|
|
|
|
const gchar *error_name,
|
|
|
|
const gchar *error_message_format,
|
|
|
|
va_list var_args)
|
|
|
|
{
|
|
|
|
GDBusMessage *ret;
|
|
|
|
gchar *error_message;
|
|
|
|
error_message = g_strdup_vprintf (error_message_format, var_args);
|
|
|
|
ret = g_dbus_message_new_method_error_literal (method_call_message,
|
|
|
|
error_name,
|
|
|
|
error_message);
|
|
|
|
g_free (error_message);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
2010-08-04 19:32:19 +02:00
|
|
|
/**
|
|
|
|
* g_dbus_message_get_byte_order:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Gets the byte order of @message.
|
|
|
|
*
|
|
|
|
* Returns: The byte order.
|
|
|
|
*/
|
|
|
|
GDBusMessageByteOrder
|
|
|
|
g_dbus_message_get_byte_order (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), (GDBusMessageByteOrder) 0);
|
|
|
|
return message->byte_order;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_byte_order:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @byte_order: The byte order.
|
|
|
|
*
|
|
|
|
* Sets the byte order of @message.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_byte_order (GDBusMessage *message,
|
|
|
|
GDBusMessageByteOrder byte_order)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
2010-09-09 17:37:14 +02:00
|
|
|
|
|
|
|
if (message->locked)
|
|
|
|
{
|
|
|
|
g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-04 19:32:19 +02:00
|
|
|
message->byte_order = byte_order;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
/* TODO: need GI annotations to specify that any guchar value goes for the type */
|
|
|
|
|
|
|
|
/**
|
2010-05-06 23:31:51 +02:00
|
|
|
* g_dbus_message_get_message_type:
|
2010-05-06 20:13:59 +02:00
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Gets the type of @message.
|
|
|
|
*
|
|
|
|
* Returns: A 8-bit unsigned integer (typically a value from the #GDBusMessageType enumeration).
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GDBusMessageType
|
2010-05-06 23:31:51 +02:00
|
|
|
g_dbus_message_get_message_type (GDBusMessage *message)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), G_DBUS_MESSAGE_TYPE_INVALID);
|
2010-07-07 22:35:17 +02:00
|
|
|
return message->type;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-05-06 23:31:51 +02:00
|
|
|
* g_dbus_message_set_message_type:
|
2010-05-06 20:13:59 +02:00
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @type: A 8-bit unsigned integer (typically a value from the #GDBusMessageType enumeration).
|
|
|
|
*
|
|
|
|
* Sets @message to be of @type.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
2010-05-06 23:31:51 +02:00
|
|
|
g_dbus_message_set_message_type (GDBusMessage *message,
|
|
|
|
GDBusMessageType type)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (type >=0 && type < 256);
|
2010-09-09 17:37:14 +02:00
|
|
|
|
|
|
|
if (message->locked)
|
|
|
|
{
|
|
|
|
g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
message->type = type;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* TODO: need GI annotations to specify that any guchar value goes for flags */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_flags:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Gets the flags for @message.
|
|
|
|
*
|
|
|
|
* Returns: Flags that are set (typically values from the #GDBusMessageFlags enumeration bitwise ORed together).
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GDBusMessageFlags
|
|
|
|
g_dbus_message_get_flags (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), G_DBUS_MESSAGE_FLAGS_NONE);
|
2010-07-07 22:35:17 +02:00
|
|
|
return message->flags;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_flags:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @flags: Flags for @message that are set (typically values from the #GDBusMessageFlags
|
|
|
|
* enumeration bitwise ORed together).
|
|
|
|
*
|
|
|
|
* Sets the flags to set on @message.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_flags (GDBusMessage *message,
|
|
|
|
GDBusMessageFlags flags)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (flags >=0 && flags < 256);
|
2010-09-09 17:37:14 +02:00
|
|
|
|
|
|
|
if (message->locked)
|
|
|
|
{
|
|
|
|
g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
message->flags = flags;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_serial:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Gets the serial for @message.
|
|
|
|
*
|
|
|
|
* Returns: A #guint32.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
guint32
|
|
|
|
g_dbus_message_get_serial (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), 0);
|
2010-07-07 22:35:17 +02:00
|
|
|
return message->serial;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_serial:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @serial: A #guint32.
|
|
|
|
*
|
|
|
|
* Sets the serial for @message.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_serial (GDBusMessage *message,
|
|
|
|
guint32 serial)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
2010-09-09 17:37:14 +02:00
|
|
|
|
|
|
|
if (message->locked)
|
|
|
|
{
|
|
|
|
g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
message->serial = serial;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* TODO: need GI annotations to specify that any guchar value goes for header_field */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_header:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @header_field: A 8-bit unsigned integer (typically a value from the #GDBusMessageHeaderField enumeration)
|
|
|
|
*
|
|
|
|
* Gets a header field on @message.
|
|
|
|
*
|
|
|
|
* Returns: A #GVariant with the value if the header was found, %NULL
|
|
|
|
* otherwise. Do not free, it is owned by @message.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GVariant *
|
|
|
|
g_dbus_message_get_header (GDBusMessage *message,
|
|
|
|
GDBusMessageHeaderField header_field)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
g_return_val_if_fail (header_field >=0 && header_field < 256, NULL);
|
2010-07-07 22:35:17 +02:00
|
|
|
return g_hash_table_lookup (message->headers, GUINT_TO_POINTER (header_field));
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_header:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @header_field: A 8-bit unsigned integer (typically a value from the #GDBusMessageHeaderField enumeration)
|
2012-03-24 13:58:45 +01:00
|
|
|
* @value: (allow-none): A #GVariant to set the header field or %NULL to clear the header field.
|
2010-05-06 20:13:59 +02:00
|
|
|
*
|
|
|
|
* Sets a header field on @message.
|
|
|
|
*
|
|
|
|
* If @value is floating, @message assumes ownership of @value.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_header (GDBusMessage *message,
|
|
|
|
GDBusMessageHeaderField header_field,
|
|
|
|
GVariant *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (header_field >=0 && header_field < 256);
|
2010-09-09 17:37:14 +02:00
|
|
|
|
|
|
|
if (message->locked)
|
|
|
|
{
|
|
|
|
g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
if (value == NULL)
|
|
|
|
{
|
2010-07-07 22:35:17 +02:00
|
|
|
g_hash_table_remove (message->headers, GUINT_TO_POINTER (header_field));
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-07 22:35:17 +02:00
|
|
|
g_hash_table_insert (message->headers, GUINT_TO_POINTER (header_field), g_variant_ref_sink (value));
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_header_fields:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Gets an array of all header fields on @message that are set.
|
|
|
|
*
|
2012-01-07 18:54:53 +01:00
|
|
|
* Returns: (array zero-terminated=1): An array of header fields
|
|
|
|
* terminated by %G_DBUS_MESSAGE_HEADER_FIELD_INVALID. Each element
|
|
|
|
* is a #guchar. Free with g_free().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
guchar *
|
|
|
|
g_dbus_message_get_header_fields (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
GList *keys;
|
|
|
|
guchar *ret;
|
|
|
|
guint num_keys;
|
|
|
|
GList *l;
|
|
|
|
guint n;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
keys = g_hash_table_get_keys (message->headers);
|
2010-05-06 20:13:59 +02:00
|
|
|
num_keys = g_list_length (keys);
|
|
|
|
ret = g_new (guchar, num_keys + 1);
|
|
|
|
for (l = keys, n = 0; l != NULL; l = l->next, n++)
|
|
|
|
ret[n] = GPOINTER_TO_UINT (l->data);
|
|
|
|
g_assert (n == num_keys);
|
|
|
|
ret[n] = G_DBUS_MESSAGE_HEADER_FIELD_INVALID;
|
|
|
|
g_list_free (keys);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_body:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Gets the body of a message.
|
|
|
|
*
|
2014-05-21 09:27:36 +02:00
|
|
|
* Returns: (transfer none): A #GVariant or %NULL if the body is
|
|
|
|
* empty. Do not free, it is owned by @message.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GVariant *
|
|
|
|
g_dbus_message_get_body (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
2010-07-07 22:35:17 +02:00
|
|
|
return message->body;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_body:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @body: Either %NULL or a #GVariant that is a tuple.
|
|
|
|
*
|
|
|
|
* Sets the body @message. As a side-effect the
|
|
|
|
* %G_DBUS_MESSAGE_HEADER_FIELD_SIGNATURE header field is set to the
|
|
|
|
* type string of @body (or cleared if @body is %NULL).
|
|
|
|
*
|
|
|
|
* If @body is floating, @message assumes ownership of @body.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_body (GDBusMessage *message,
|
|
|
|
GVariant *body)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail ((body == NULL) || g_variant_is_of_type (body, G_VARIANT_TYPE_TUPLE));
|
|
|
|
|
2010-09-09 17:37:14 +02:00
|
|
|
if (message->locked)
|
|
|
|
{
|
|
|
|
g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->body != NULL)
|
|
|
|
g_variant_unref (message->body);
|
2010-05-06 20:13:59 +02:00
|
|
|
if (body == NULL)
|
|
|
|
{
|
2010-07-07 22:35:17 +02:00
|
|
|
message->body = NULL;
|
2010-05-06 20:13:59 +02:00
|
|
|
g_dbus_message_set_signature (message, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const gchar *type_string;
|
|
|
|
gsize type_string_len;
|
|
|
|
gchar *signature;
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
message->body = g_variant_ref_sink (body);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
type_string = g_variant_get_type_string (body);
|
|
|
|
type_string_len = strlen (type_string);
|
|
|
|
g_assert (type_string_len >= 2);
|
|
|
|
signature = g_strndup (type_string + 1, type_string_len - 2);
|
|
|
|
g_dbus_message_set_signature (message, signature);
|
|
|
|
g_free (signature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_unix_fd_list:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Gets the UNIX file descriptors associated with @message, if any.
|
|
|
|
*
|
|
|
|
* This method is only available on UNIX.
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer none):A #GUnixFDList or %NULL if no file descriptors are
|
2010-05-06 20:13:59 +02:00
|
|
|
* associated. Do not free, this object is owned by @message.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GUnixFDList *
|
|
|
|
g_dbus_message_get_unix_fd_list (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
2010-07-07 22:35:17 +02:00
|
|
|
return message->fd_list;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_unix_fd_list:
|
|
|
|
* @message: A #GDBusMessage.
|
2010-08-30 16:02:32 +02:00
|
|
|
* @fd_list: (allow-none): A #GUnixFDList or %NULL.
|
2010-05-06 20:13:59 +02:00
|
|
|
*
|
|
|
|
* Sets the UNIX file descriptors associated with @message. As a
|
|
|
|
* side-effect the %G_DBUS_MESSAGE_HEADER_FIELD_NUM_UNIX_FDS header
|
|
|
|
* field is set to the number of fds in @fd_list (or cleared if
|
|
|
|
* @fd_list is %NULL).
|
|
|
|
*
|
|
|
|
* This method is only available on UNIX.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_unix_fd_list (GDBusMessage *message,
|
|
|
|
GUnixFDList *fd_list)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (fd_list == NULL || G_IS_UNIX_FD_LIST (fd_list));
|
2010-09-09 17:37:14 +02:00
|
|
|
|
|
|
|
if (message->locked)
|
|
|
|
{
|
|
|
|
g_warning ("%s: Attempted to modify a locked message", G_STRFUNC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->fd_list != NULL)
|
|
|
|
g_object_unref (message->fd_list);
|
2010-05-06 20:13:59 +02:00
|
|
|
if (fd_list != NULL)
|
|
|
|
{
|
2010-07-07 22:35:17 +02:00
|
|
|
message->fd_list = g_object_ref (fd_list);
|
2010-05-06 20:13:59 +02:00
|
|
|
g_dbus_message_set_num_unix_fds (message, g_unix_fd_list_get_length (fd_list));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-07 22:35:17 +02:00
|
|
|
message->fd_list = NULL;
|
2010-05-06 20:13:59 +02:00
|
|
|
g_dbus_message_set_num_unix_fds (message, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
2014-07-04 21:00:49 +02:00
|
|
|
static guint
|
|
|
|
get_type_fixed_size (const GVariantType *type)
|
|
|
|
{
|
|
|
|
/* NB: we do not treat 'b' as fixed-size here because GVariant and
|
|
|
|
* D-Bus disagree about the size.
|
|
|
|
*/
|
|
|
|
switch (*g_variant_type_peek_string (type))
|
|
|
|
{
|
|
|
|
case 'y':
|
|
|
|
return 1;
|
|
|
|
case 'n': case 'q':
|
|
|
|
return 2;
|
|
|
|
case 'i': case 'u': case 'h':
|
|
|
|
return 4;
|
2014-07-24 11:36:57 +02:00
|
|
|
case 'x': case 't': case 'd':
|
2014-07-04 21:00:49 +02:00
|
|
|
return 8;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 20:38:51 +02:00
|
|
|
static gboolean
|
|
|
|
validate_headers (GDBusMessage *message,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
switch (message->type)
|
|
|
|
{
|
|
|
|
case G_DBUS_MESSAGE_TYPE_INVALID:
|
|
|
|
g_set_error_literal (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("type is INVALID"));
|
|
|
|
goto out;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_DBUS_MESSAGE_TYPE_METHOD_CALL:
|
|
|
|
if (g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_PATH) == NULL ||
|
|
|
|
g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_MEMBER) == NULL)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("METHOD_CALL message: PATH or MEMBER header field is missing"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_DBUS_MESSAGE_TYPE_METHOD_RETURN:
|
|
|
|
if (g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL) == NULL)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("METHOD_RETURN message: REPLY_SERIAL header field is missing"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_DBUS_MESSAGE_TYPE_ERROR:
|
|
|
|
if (g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_ERROR_NAME) == NULL ||
|
|
|
|
g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL) == NULL)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("ERROR message: REPLY_SERIAL or ERROR_NAME header field is missing"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_DBUS_MESSAGE_TYPE_SIGNAL:
|
|
|
|
if (g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_PATH) == NULL ||
|
|
|
|
g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_INTERFACE) == NULL ||
|
|
|
|
g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_MEMBER) == NULL)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("SIGNAL message: PATH, INTERFACE or MEMBER header field is missing"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (g_strcmp0 (g_dbus_message_get_path (message), "/org/freedesktop/DBus/Local") == 0)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("SIGNAL message: The PATH header field is using the reserved value /org/freedesktop/DBus/Local"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (g_strcmp0 (g_dbus_message_get_interface (message), "org.freedesktop.DBus.Local") == 0)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("SIGNAL message: The INTERFACE header field is using the reserved value org.freedesktop.DBus.Local"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* hitherto unknown type - nothing to check */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
out:
|
|
|
|
g_assert (ret || (error == NULL || *error != NULL));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
static gboolean
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (GMemoryBuffer *buf,
|
|
|
|
gsize padding_size)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
gsize offset;
|
|
|
|
gsize wanted_offset;
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
offset = buf->pos;
|
2010-05-06 20:13:59 +02:00
|
|
|
wanted_offset = ((offset + padding_size - 1) / padding_size) * padding_size;
|
2012-11-01 01:44:03 +01:00
|
|
|
buf->pos = wanted_offset;
|
|
|
|
return TRUE;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
2012-11-29 23:51:59 +01:00
|
|
|
static const gchar *
|
2014-05-09 15:06:52 +02:00
|
|
|
read_string (GMemoryBuffer *mbuf,
|
|
|
|
gsize len,
|
|
|
|
GError **error)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2012-11-01 01:44:03 +01:00
|
|
|
gchar *str;
|
2010-08-04 17:26:48 +02:00
|
|
|
const gchar *end_valid;
|
2012-11-29 23:51:59 +01:00
|
|
|
|
2014-07-09 17:19:58 +02:00
|
|
|
if G_UNLIKELY (mbuf->pos + len >= mbuf->valid_len || mbuf->pos + len < mbuf->pos)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2012-11-29 23:51:59 +01:00
|
|
|
mbuf->pos = mbuf->valid_len;
|
2012-11-01 01:44:03 +01:00
|
|
|
/* G_GSIZE_FORMAT doesn't work with gettext, so we use %lu */
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
g_dngettext (GETTEXT_PACKAGE,
|
|
|
|
"Wanted to read %lu byte but only got %lu",
|
2013-03-07 22:44:36 +01:00
|
|
|
"Wanted to read %lu bytes but only got %lu",
|
2012-11-01 01:44:03 +01:00
|
|
|
(gulong)len),
|
|
|
|
(gulong)len,
|
2013-03-31 16:40:34 +02:00
|
|
|
(gulong)(mbuf->valid_len - mbuf->pos));
|
2012-11-29 23:51:59 +01:00
|
|
|
return NULL;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
2014-07-09 17:19:58 +02:00
|
|
|
if G_UNLIKELY (mbuf->data[mbuf->pos + len] != '\0')
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2012-11-29 23:51:59 +01:00
|
|
|
str = g_strndup (mbuf->data + mbuf->pos, len);
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Expected NUL byte after the string '%s' but found byte %d"),
|
2012-11-29 23:51:59 +01:00
|
|
|
str, mbuf->data[mbuf->pos + len]);
|
|
|
|
g_free (str);
|
|
|
|
mbuf->pos += len + 1;
|
|
|
|
return NULL;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
2012-11-29 23:51:59 +01:00
|
|
|
|
|
|
|
str = mbuf->data + mbuf->pos;
|
|
|
|
mbuf->pos += len + 1;
|
|
|
|
|
2014-07-09 17:19:58 +02:00
|
|
|
if G_UNLIKELY (!g_utf8_validate (str, -1, &end_valid))
|
2010-08-04 17:26:48 +02:00
|
|
|
{
|
|
|
|
gint offset;
|
|
|
|
gchar *valid_str;
|
2012-11-01 01:44:03 +01:00
|
|
|
offset = (gint) (end_valid - str);
|
|
|
|
valid_str = g_strndup (str, offset);
|
2010-08-04 17:26:48 +02:00
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Expected valid UTF-8 string but found invalid bytes at byte offset %d (length of string is %d). "
|
2013-05-20 22:54:48 +02:00
|
|
|
"The valid UTF-8 string up until that point was '%s'"),
|
2010-08-04 17:26:48 +02:00
|
|
|
offset,
|
2012-11-29 23:51:59 +01:00
|
|
|
(gint) len,
|
2010-08-04 17:26:48 +02:00
|
|
|
valid_str);
|
|
|
|
g_free (valid_str);
|
2012-11-29 23:51:59 +01:00
|
|
|
return NULL;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
return str;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
2014-07-04 21:00:49 +02:00
|
|
|
static gconstpointer
|
|
|
|
read_bytes (GMemoryBuffer *mbuf,
|
|
|
|
gsize len,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
gconstpointer result;
|
|
|
|
|
2014-07-09 17:19:58 +02:00
|
|
|
if G_UNLIKELY (mbuf->pos + len > mbuf->valid_len || mbuf->pos + len < mbuf->pos)
|
2014-07-04 21:00:49 +02:00
|
|
|
{
|
|
|
|
mbuf->pos = mbuf->valid_len;
|
|
|
|
/* G_GSIZE_FORMAT doesn't work with gettext, so we use %lu */
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
g_dngettext (GETTEXT_PACKAGE,
|
|
|
|
"Wanted to read %lu byte but only got %lu",
|
|
|
|
"Wanted to read %lu bytes but only got %lu",
|
|
|
|
(gulong)len),
|
|
|
|
(gulong)len,
|
|
|
|
(gulong)(mbuf->valid_len - mbuf->pos));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = mbuf->data + mbuf->pos;
|
|
|
|
mbuf->pos += len;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-05-14 18:49:51 +02:00
|
|
|
/* if just_align==TRUE, don't read a value, just align the input stream wrt padding */
|
2010-06-30 22:36:47 +02:00
|
|
|
|
|
|
|
/* returns a non-floating GVariant! */
|
2010-05-06 20:13:59 +02:00
|
|
|
static GVariant *
|
2014-05-09 15:06:52 +02:00
|
|
|
parse_value_from_blob (GMemoryBuffer *buf,
|
|
|
|
const GVariantType *type,
|
|
|
|
gboolean just_align,
|
|
|
|
guint indent,
|
|
|
|
GError **error)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
GVariant *ret;
|
|
|
|
GError *local_error;
|
2010-06-17 23:58:25 +02:00
|
|
|
gboolean is_leaf;
|
2011-06-15 00:11:09 +02:00
|
|
|
const gchar *type_string;
|
|
|
|
|
|
|
|
type_string = g_variant_type_peek_string (type);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2010-06-17 23:58:25 +02:00
|
|
|
#ifdef DEBUG_SERIALIZER
|
|
|
|
{
|
|
|
|
gchar *s;
|
|
|
|
s = g_variant_type_dup_string (type);
|
2012-04-10 13:58:52 +02:00
|
|
|
g_print ("%*s%s type %s from offset 0x%04x",
|
2010-06-17 23:58:25 +02:00
|
|
|
indent, "",
|
2012-04-10 13:58:52 +02:00
|
|
|
just_align ? "Aligning" : "Reading",
|
2010-06-17 23:58:25 +02:00
|
|
|
s,
|
2012-11-01 01:44:03 +01:00
|
|
|
(gint) g_seekable_tell (G_SEEKABLE (buf)));
|
2010-06-17 23:58:25 +02:00
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
#endif /* DEBUG_SERIALIZER */
|
2010-05-14 18:49:51 +02:00
|
|
|
|
|
|
|
ret = NULL;
|
|
|
|
|
2010-06-17 23:58:25 +02:00
|
|
|
is_leaf = TRUE;
|
2010-05-06 20:13:59 +02:00
|
|
|
local_error = NULL;
|
2011-06-15 00:11:09 +02:00
|
|
|
switch (type_string[0])
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
case 'b': /* G_VARIANT_TYPE_BOOLEAN */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 4);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
gboolean v;
|
2014-05-09 15:06:52 +02:00
|
|
|
v = g_memory_buffer_read_uint32 (buf);
|
2010-05-14 18:49:51 +02:00
|
|
|
ret = g_variant_new_boolean (v);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'y': /* G_VARIANT_TYPE_BYTE */
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
guchar v;
|
2014-05-09 15:06:52 +02:00
|
|
|
v = g_memory_buffer_read_byte (buf);
|
2010-05-14 18:49:51 +02:00
|
|
|
ret = g_variant_new_byte (v);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n': /* G_VARIANT_TYPE_INT16 */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 2);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
gint16 v;
|
2014-05-09 15:06:52 +02:00
|
|
|
v = g_memory_buffer_read_int16 (buf);
|
2010-05-14 18:49:51 +02:00
|
|
|
ret = g_variant_new_int16 (v);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'q': /* G_VARIANT_TYPE_UINT16 */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 2);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
guint16 v;
|
2014-05-09 15:06:52 +02:00
|
|
|
v = g_memory_buffer_read_uint16 (buf);
|
2010-05-14 18:49:51 +02:00
|
|
|
ret = g_variant_new_uint16 (v);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i': /* G_VARIANT_TYPE_INT32 */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 4);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
gint32 v;
|
2014-05-09 15:06:52 +02:00
|
|
|
v = g_memory_buffer_read_int32 (buf);
|
2010-05-14 18:49:51 +02:00
|
|
|
ret = g_variant_new_int32 (v);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u': /* G_VARIANT_TYPE_UINT32 */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 4);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
guint32 v;
|
2014-05-09 15:06:52 +02:00
|
|
|
v = g_memory_buffer_read_uint32 (buf);
|
2010-05-14 18:49:51 +02:00
|
|
|
ret = g_variant_new_uint32 (v);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x': /* G_VARIANT_TYPE_INT64 */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 8);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
gint64 v;
|
2014-05-09 15:06:52 +02:00
|
|
|
v = g_memory_buffer_read_int64 (buf);
|
2010-05-14 18:49:51 +02:00
|
|
|
ret = g_variant_new_int64 (v);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': /* G_VARIANT_TYPE_UINT64 */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 8);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
guint64 v;
|
2014-05-09 15:06:52 +02:00
|
|
|
v = g_memory_buffer_read_uint64 (buf);
|
2010-05-14 18:49:51 +02:00
|
|
|
ret = g_variant_new_uint64 (v);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd': /* G_VARIANT_TYPE_DOUBLE */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 8);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
2011-06-09 18:02:30 +02:00
|
|
|
union {
|
|
|
|
guint64 v_uint64;
|
|
|
|
gdouble v_double;
|
|
|
|
} u;
|
2010-11-12 03:47:13 +01:00
|
|
|
G_STATIC_ASSERT (sizeof (gdouble) == sizeof (guint64));
|
2014-05-09 15:06:52 +02:00
|
|
|
u.v_uint64 = g_memory_buffer_read_uint64 (buf);
|
2011-06-09 18:02:30 +02:00
|
|
|
ret = g_variant_new_double (u.v_double);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's': /* G_VARIANT_TYPE_STRING */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 4);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
guint32 len;
|
2012-11-29 23:51:59 +01:00
|
|
|
const gchar *v;
|
2014-05-09 15:06:52 +02:00
|
|
|
len = g_memory_buffer_read_uint32 (buf);
|
2012-11-01 01:44:03 +01:00
|
|
|
v = read_string (buf, (gsize) len, &local_error);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (v == NULL)
|
|
|
|
goto fail;
|
|
|
|
ret = g_variant_new_string (v);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o': /* G_VARIANT_TYPE_OBJECT_PATH */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 4);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2010-05-14 18:49:51 +02:00
|
|
|
guint32 len;
|
2012-11-29 23:51:59 +01:00
|
|
|
const gchar *v;
|
2014-05-09 15:06:52 +02:00
|
|
|
len = g_memory_buffer_read_uint32 (buf);
|
2012-11-01 01:44:03 +01:00
|
|
|
v = read_string (buf, (gsize) len, &local_error);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (v == NULL)
|
|
|
|
goto fail;
|
|
|
|
if (!g_variant_is_object_path (v))
|
|
|
|
{
|
|
|
|
g_set_error (&local_error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Parsed value '%s' is not a valid D-Bus object path"),
|
2010-05-14 18:49:51 +02:00
|
|
|
v);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
ret = g_variant_new_object_path (v);
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'g': /* G_VARIANT_TYPE_SIGNATURE */
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!just_align)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2010-05-14 18:49:51 +02:00
|
|
|
guchar len;
|
2012-11-29 23:51:59 +01:00
|
|
|
const gchar *v;
|
2014-05-09 15:06:52 +02:00
|
|
|
len = g_memory_buffer_read_byte (buf);
|
2012-11-01 01:44:03 +01:00
|
|
|
v = read_string (buf, (gsize) len, &local_error);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (v == NULL)
|
|
|
|
goto fail;
|
|
|
|
if (!g_variant_is_signature (v))
|
|
|
|
{
|
|
|
|
g_set_error (&local_error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Parsed value '%s' is not a valid D-Bus signature"),
|
2010-05-06 20:13:59 +02:00
|
|
|
v);
|
2010-05-14 18:49:51 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
ret = g_variant_new_signature (v);
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h': /* G_VARIANT_TYPE_HANDLE */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 4);
|
2010-07-20 17:38:23 +02:00
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
gint32 v;
|
2014-05-09 15:06:52 +02:00
|
|
|
v = g_memory_buffer_read_int32 (buf);
|
2010-07-20 17:38:23 +02:00
|
|
|
ret = g_variant_new_handle (v);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2011-06-15 00:11:09 +02:00
|
|
|
case 'a': /* G_VARIANT_TYPE_ARRAY */
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 4);
|
2011-06-15 00:11:09 +02:00
|
|
|
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
/* If we are only aligning for this array type, it is the child type of
|
|
|
|
* another array, which is empty. So, we do not need to add padding for
|
|
|
|
* this nonexistent array's elements: we only need to align for this
|
|
|
|
* array itself (4 bytes). See
|
|
|
|
* <https://bugzilla.gnome.org/show_bug.cgi?id=673612>.
|
|
|
|
*/
|
|
|
|
if (!just_align)
|
|
|
|
{
|
|
|
|
guint32 array_len;
|
|
|
|
const GVariantType *element_type;
|
2014-07-04 21:00:49 +02:00
|
|
|
guint fixed_size;
|
2011-06-15 00:11:09 +02:00
|
|
|
|
2014-05-09 15:06:52 +02:00
|
|
|
array_len = g_memory_buffer_read_uint32 (buf);
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
|
|
|
|
is_leaf = FALSE;
|
2011-06-15 00:11:09 +02:00
|
|
|
#ifdef DEBUG_SERIALIZER
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
g_print (": array spans 0x%04x bytes\n", array_len);
|
2011-06-15 00:11:09 +02:00
|
|
|
#endif /* DEBUG_SERIALIZER */
|
|
|
|
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
if (array_len > (2<<26))
|
|
|
|
{
|
|
|
|
/* G_GUINT32_FORMAT doesn't work with gettext, so use u */
|
|
|
|
g_set_error (&local_error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
g_dngettext (GETTEXT_PACKAGE,
|
|
|
|
"Encountered array of length %u byte. Maximum length is 2<<26 bytes (64 MiB).",
|
|
|
|
"Encountered array of length %u bytes. Maximum length is 2<<26 bytes (64 MiB).",
|
|
|
|
array_len),
|
|
|
|
array_len);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
element_type = g_variant_type_element (type);
|
2014-07-04 21:00:49 +02:00
|
|
|
fixed_size = get_type_fixed_size (element_type);
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
|
2014-07-04 21:00:49 +02:00
|
|
|
/* Fast-path the cases like 'ay', etc. */
|
|
|
|
if (fixed_size != 0)
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
{
|
2014-07-04 21:00:49 +02:00
|
|
|
gconstpointer array_data;
|
|
|
|
|
|
|
|
if (array_len % fixed_size != 0)
|
|
|
|
{
|
|
|
|
g_set_error (&local_error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Encountered array of type 'a%c', expected to have a length a multiple "
|
|
|
|
"of %u bytes, but found to be %u bytes in length"),
|
|
|
|
g_variant_type_peek_string (element_type)[0], fixed_size, array_len);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ensure_input_padding (buf, fixed_size);
|
|
|
|
array_data = read_bytes (buf, array_len, &local_error);
|
|
|
|
if (array_data == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ret = g_variant_new_fixed_array (element_type, array_data, array_len / fixed_size, fixed_size);
|
|
|
|
|
|
|
|
if (g_memory_buffer_is_byteswapped (buf))
|
|
|
|
{
|
|
|
|
GVariant *tmp = g_variant_ref_sink (ret);
|
|
|
|
ret = g_variant_byteswap (tmp);
|
|
|
|
g_variant_unref (tmp);
|
|
|
|
}
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-04 21:00:49 +02:00
|
|
|
GVariantBuilder builder;
|
|
|
|
goffset offset;
|
|
|
|
goffset target;
|
|
|
|
|
|
|
|
g_variant_builder_init (&builder, type);
|
|
|
|
|
|
|
|
if (array_len == 0)
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
{
|
|
|
|
GVariant *item;
|
2012-11-01 01:44:03 +01:00
|
|
|
item = parse_value_from_blob (buf,
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
element_type,
|
2014-07-04 21:00:49 +02:00
|
|
|
TRUE,
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
indent + 2,
|
2014-07-04 21:00:49 +02:00
|
|
|
NULL);
|
|
|
|
g_assert (item == NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offset = buf->pos;
|
|
|
|
target = offset + array_len;
|
|
|
|
while (offset < target)
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
{
|
2014-07-04 21:00:49 +02:00
|
|
|
GVariant *item;
|
|
|
|
item = parse_value_from_blob (buf,
|
|
|
|
element_type,
|
|
|
|
FALSE,
|
|
|
|
indent + 2,
|
|
|
|
&local_error);
|
|
|
|
if (item == NULL)
|
|
|
|
{
|
|
|
|
g_variant_builder_clear (&builder);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
g_variant_builder_add_value (&builder, item);
|
|
|
|
g_variant_unref (item);
|
|
|
|
offset = buf->pos;
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 21:00:49 +02:00
|
|
|
ret = g_variant_builder_end (&builder);
|
|
|
|
}
|
GDBusMessage: do not align for grandchildren of empty arrays.
D-Bus arrays are serialized as follows:
1. align to a 4-byte boundary (for the length)
2. uint32: the length of the serialized body in bytes
3. padding for the alignment of the body type (not included in the length)
4. the body.
Note that 3. is a no-op unless the body type is an 8-byte aligned type
(uint64, int64, double, struct, dict_entry), since you are always on a
4-byte boundary from aligning and writing the length.
So, an empty aax (that is, an array containing zero arrays of int64)
is serialized as follows:
1. align to a 4-byte boundary
2. length of the contents of this (empty) array, in bytes (0)
3. align to a 4-byte boundary (the child array's alignment requirement)
4. there is no body.
But previously, GDBus would recurse in step three to align not just for
the type of the child array, but for the nonexistent child array's
contents. This only affects the algorithm when the grandchild type has
8-byte alignment and the reader happened to not already be on an 8-byte
boundary, in which case 4 bytes were spuriously skipped.
https://bugzilla.gnome.org/show_bug.cgi?id=673612
Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-04-10 14:20:09 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (g_variant_type_is_dict_entry (type))
|
2010-06-17 23:58:25 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
const GVariantType *key_type;
|
|
|
|
const GVariantType *value_type;
|
|
|
|
GVariant *key;
|
|
|
|
GVariant *value;
|
|
|
|
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 8);
|
2010-06-17 23:58:25 +02:00
|
|
|
|
|
|
|
is_leaf = FALSE;
|
|
|
|
#ifdef DEBUG_SERIALIZER
|
2011-06-15 00:11:09 +02:00
|
|
|
g_print ("\n");
|
2010-06-17 23:58:25 +02:00
|
|
|
#endif /* DEBUG_SERIALIZER */
|
|
|
|
|
2011-06-15 00:11:09 +02:00
|
|
|
if (!just_align)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
key_type = g_variant_type_key (type);
|
2012-11-01 01:44:03 +01:00
|
|
|
key = parse_value_from_blob (buf,
|
2011-06-15 00:11:09 +02:00
|
|
|
key_type,
|
|
|
|
FALSE,
|
|
|
|
indent + 2,
|
|
|
|
&local_error);
|
|
|
|
if (key == NULL)
|
|
|
|
goto fail;
|
|
|
|
value_type = g_variant_type_value (type);
|
2012-11-01 01:44:03 +01:00
|
|
|
value = parse_value_from_blob (buf,
|
2011-06-15 00:11:09 +02:00
|
|
|
value_type,
|
|
|
|
FALSE,
|
|
|
|
indent + 2,
|
|
|
|
&local_error);
|
|
|
|
if (value == NULL)
|
2010-05-14 18:49:51 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
g_variant_unref (key);
|
2010-05-14 18:49:51 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
ret = g_variant_new_dict_entry (key, value);
|
|
|
|
g_variant_unref (key);
|
|
|
|
g_variant_unref (value);
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
else if (g_variant_type_is_tuple (type))
|
2010-05-14 18:49:51 +02:00
|
|
|
{
|
2014-05-09 15:06:52 +02:00
|
|
|
ensure_input_padding (buf, 8);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2011-06-15 00:11:09 +02:00
|
|
|
is_leaf = FALSE;
|
2010-06-17 23:58:25 +02:00
|
|
|
#ifdef DEBUG_SERIALIZER
|
2011-06-15 00:11:09 +02:00
|
|
|
g_print ("\n");
|
2010-06-17 23:58:25 +02:00
|
|
|
#endif /* DEBUG_SERIALIZER */
|
|
|
|
|
2011-06-15 00:11:09 +02:00
|
|
|
if (!just_align)
|
2010-05-14 18:49:51 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
const GVariantType *element_type;
|
|
|
|
GVariantBuilder builder;
|
|
|
|
|
|
|
|
g_variant_builder_init (&builder, type);
|
|
|
|
element_type = g_variant_type_first (type);
|
|
|
|
while (element_type != NULL)
|
|
|
|
{
|
|
|
|
GVariant *item;
|
2012-11-01 01:44:03 +01:00
|
|
|
item = parse_value_from_blob (buf,
|
2011-06-15 00:11:09 +02:00
|
|
|
element_type,
|
|
|
|
FALSE,
|
|
|
|
indent + 2,
|
|
|
|
&local_error);
|
|
|
|
if (item == NULL)
|
|
|
|
{
|
|
|
|
g_variant_builder_clear (&builder);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
g_variant_builder_add_value (&builder, item);
|
|
|
|
g_variant_unref (item);
|
|
|
|
|
|
|
|
element_type = g_variant_type_next (element_type);
|
|
|
|
}
|
|
|
|
ret = g_variant_builder_end (&builder);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
else if (g_variant_type_is_variant (type))
|
|
|
|
{
|
|
|
|
is_leaf = FALSE;
|
2010-06-17 23:58:25 +02:00
|
|
|
#ifdef DEBUG_SERIALIZER
|
2011-06-15 00:11:09 +02:00
|
|
|
g_print ("\n");
|
2010-06-17 23:58:25 +02:00
|
|
|
#endif /* DEBUG_SERIALIZER */
|
|
|
|
|
2011-06-15 00:11:09 +02:00
|
|
|
if (!just_align)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
guchar siglen;
|
2012-11-29 23:51:59 +01:00
|
|
|
const gchar *sig;
|
2011-06-15 00:11:09 +02:00
|
|
|
GVariantType *variant_type;
|
|
|
|
GVariant *value;
|
|
|
|
|
2014-05-09 15:06:52 +02:00
|
|
|
siglen = g_memory_buffer_read_byte (buf);
|
2012-11-01 01:44:03 +01:00
|
|
|
sig = read_string (buf, (gsize) siglen, &local_error);
|
2011-06-15 00:11:09 +02:00
|
|
|
if (sig == NULL)
|
|
|
|
goto fail;
|
|
|
|
if (!g_variant_is_signature (sig))
|
2010-05-14 18:49:51 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
g_set_error (&local_error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Parsed value '%s' for variant is not a valid D-Bus signature"),
|
2011-06-15 00:11:09 +02:00
|
|
|
sig);
|
2010-05-14 18:49:51 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
variant_type = g_variant_type_new (sig);
|
2012-11-01 01:44:03 +01:00
|
|
|
value = parse_value_from_blob (buf,
|
2011-06-15 00:11:09 +02:00
|
|
|
variant_type,
|
|
|
|
FALSE,
|
|
|
|
indent + 2,
|
|
|
|
&local_error);
|
|
|
|
g_variant_type_free (variant_type);
|
|
|
|
if (value == NULL)
|
|
|
|
goto fail;
|
|
|
|
ret = g_variant_new_variant (value);
|
|
|
|
g_variant_unref (value);
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
else
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
gchar *s;
|
|
|
|
s = g_variant_type_dup_string (type);
|
|
|
|
g_set_error (&local_error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Error deserializing GVariant with type string '%s' from the D-Bus wire format"),
|
2011-06-15 00:11:09 +02:00
|
|
|
s);
|
|
|
|
g_free (s);
|
|
|
|
goto fail;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
2010-05-14 18:49:51 +02:00
|
|
|
g_assert ((just_align && ret == NULL) || (!just_align && ret != NULL));
|
2010-06-17 23:58:25 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_SERIALIZER
|
|
|
|
if (ret != NULL)
|
|
|
|
{
|
|
|
|
if (is_leaf)
|
|
|
|
{
|
|
|
|
gchar *s;
|
|
|
|
if (g_variant_type_equal (type, G_VARIANT_TYPE_BYTE))
|
|
|
|
{
|
|
|
|
s = g_strdup_printf ("0x%02x '%c'", g_variant_get_byte (ret), g_variant_get_byte (ret));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = g_variant_print (ret, FALSE);
|
|
|
|
}
|
|
|
|
g_print (": %s\n", s);
|
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
}
|
2011-04-08 21:44:25 +02:00
|
|
|
#else
|
|
|
|
is_leaf = is_leaf; /* To avoid -Wunused-but-set-variable */
|
2010-06-17 23:58:25 +02:00
|
|
|
#endif /* DEBUG_SERIALIZER */
|
|
|
|
|
2014-07-04 21:00:49 +02:00
|
|
|
/* sink the reference, if floating */
|
2010-06-30 22:36:47 +02:00
|
|
|
if (ret != NULL)
|
2014-07-04 21:00:49 +02:00
|
|
|
g_variant_take_ref (ret);
|
2010-05-06 20:13:59 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
fail:
|
2010-06-17 23:58:25 +02:00
|
|
|
#ifdef DEBUG_SERIALIZER
|
|
|
|
g_print ("\n"
|
|
|
|
"%*sFAILURE: %s (%s, %d)\n",
|
|
|
|
indent, "",
|
|
|
|
local_error->message,
|
|
|
|
g_quark_to_string (local_error->domain),
|
|
|
|
local_error->code);
|
|
|
|
#endif /* DEBUG_SERIALIZER */
|
2010-05-06 20:13:59 +02:00
|
|
|
g_propagate_error (error, local_error);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* message_header must be at least 16 bytes */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_bytes_needed:
|
2012-01-07 18:54:53 +01:00
|
|
|
* @blob: (array length=blob_len) (element-type guint8): A blob represent a binary D-Bus message.
|
2010-05-06 20:13:59 +02:00
|
|
|
* @blob_len: The length of @blob (must be at least 16).
|
|
|
|
* @error: Return location for error or %NULL.
|
|
|
|
*
|
|
|
|
* Utility function to calculate how many bytes are needed to
|
|
|
|
* completely deserialize the D-Bus message stored at @blob.
|
|
|
|
*
|
|
|
|
* Returns: Number of bytes needed or -1 if @error is set (e.g. if
|
|
|
|
* @blob contains invalid data or not enough data is available to
|
|
|
|
* determine the size).
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
gssize
|
2014-05-09 15:06:52 +02:00
|
|
|
g_dbus_message_bytes_needed (guchar *blob,
|
|
|
|
gsize blob_len,
|
|
|
|
GError **error)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
gssize ret;
|
|
|
|
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
g_return_val_if_fail (blob != NULL, -1);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, -1);
|
|
|
|
g_return_val_if_fail (blob_len >= 16, -1);
|
|
|
|
|
|
|
|
if (blob[0] == 'l')
|
|
|
|
{
|
|
|
|
/* core header (12 bytes) + ARRAY of STRUCT of (BYTE,VARIANT) */
|
|
|
|
ret = 12 + 4 + GUINT32_FROM_LE (((guint32 *) blob)[3]);
|
|
|
|
/* round up so it's a multiple of 8 */
|
|
|
|
ret = 8 * ((ret + 7)/8);
|
|
|
|
/* finally add the body size */
|
|
|
|
ret += GUINT32_FROM_LE (((guint32 *) blob)[1]);
|
|
|
|
}
|
|
|
|
else if (blob[0] == 'B')
|
|
|
|
{
|
2010-05-25 17:59:57 +02:00
|
|
|
/* core header (12 bytes) + ARRAY of STRUCT of (BYTE,VARIANT) */
|
|
|
|
ret = 12 + 4 + GUINT32_FROM_BE (((guint32 *) blob)[3]);
|
|
|
|
/* round up so it's a multiple of 8 */
|
|
|
|
ret = 8 * ((ret + 7)/8);
|
|
|
|
/* finally add the body size */
|
|
|
|
ret += GUINT32_FROM_BE (((guint32 *) blob)[1]);
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
"Unable to determine message blob length - given blob is malformed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret > (2<<27))
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
"Blob indicates that message exceeds maximum message length (128MiB)");
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_new_from_blob:
|
2012-01-07 18:54:53 +01:00
|
|
|
* @blob: (array length=blob_len) (element-type guint8): A blob represent a binary D-Bus message.
|
2010-05-06 20:13:59 +02:00
|
|
|
* @blob_len: The length of @blob.
|
2010-05-13 20:01:41 +02:00
|
|
|
* @capabilities: A #GDBusCapabilityFlags describing what protocol features are supported.
|
2010-05-06 20:13:59 +02:00
|
|
|
* @error: Return location for error or %NULL.
|
|
|
|
*
|
2010-08-04 19:32:19 +02:00
|
|
|
* Creates a new #GDBusMessage from the data stored at @blob. The byte
|
|
|
|
* order that the message was in can be retrieved using
|
|
|
|
* g_dbus_message_get_byte_order().
|
2010-05-06 20:13:59 +02:00
|
|
|
*
|
|
|
|
* Returns: A new #GDBusMessage or %NULL if @error is set. Free with
|
|
|
|
* g_object_unref().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
GDBusMessage *
|
2010-05-13 20:01:41 +02:00
|
|
|
g_dbus_message_new_from_blob (guchar *blob,
|
|
|
|
gsize blob_len,
|
|
|
|
GDBusCapabilityFlags capabilities,
|
|
|
|
GError **error)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
gboolean ret;
|
2012-11-01 01:44:03 +01:00
|
|
|
GMemoryBuffer mbuf;
|
2010-05-06 20:13:59 +02:00
|
|
|
GDBusMessage *message;
|
|
|
|
guchar endianness;
|
|
|
|
guchar major_protocol_version;
|
|
|
|
guint32 message_body_len;
|
|
|
|
GVariant *headers;
|
|
|
|
GVariant *item;
|
|
|
|
GVariantIter iter;
|
|
|
|
GVariant *signature;
|
|
|
|
|
2010-05-13 20:01:41 +02:00
|
|
|
/* TODO: check against @capabilities */
|
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (blob != NULL, NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
g_return_val_if_fail (blob_len >= 12, NULL);
|
|
|
|
|
|
|
|
message = g_dbus_message_new ();
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
memset (&mbuf, 0, sizeof (mbuf));
|
|
|
|
mbuf.data = (gchar *)blob;
|
|
|
|
mbuf.len = mbuf.valid_len = blob_len;
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2014-05-09 15:06:52 +02:00
|
|
|
endianness = g_memory_buffer_read_byte (&mbuf);
|
2010-05-06 20:13:59 +02:00
|
|
|
switch (endianness)
|
|
|
|
{
|
|
|
|
case 'l':
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf.byte_order = G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN;
|
2010-08-04 19:32:19 +02:00
|
|
|
message->byte_order = G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN;
|
2010-05-06 20:13:59 +02:00
|
|
|
break;
|
|
|
|
case 'B':
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf.byte_order = G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN;
|
2010-08-04 19:32:19 +02:00
|
|
|
message->byte_order = G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN;
|
2010-05-06 20:13:59 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2010-08-04 19:32:19 +02:00
|
|
|
_("Invalid endianness value. Expected 0x6c ('l') or 0x42 ('B') but found value 0x%02x"),
|
|
|
|
endianness);
|
2010-05-06 20:13:59 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-05-09 15:06:52 +02:00
|
|
|
message->type = g_memory_buffer_read_byte (&mbuf);
|
|
|
|
message->flags = g_memory_buffer_read_byte (&mbuf);
|
|
|
|
major_protocol_version = g_memory_buffer_read_byte (&mbuf);
|
2010-05-06 20:13:59 +02:00
|
|
|
if (major_protocol_version != 1)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
_("Invalid major protocol version. Expected 1 but found %d"),
|
|
|
|
major_protocol_version);
|
|
|
|
goto out;
|
|
|
|
}
|
2014-05-09 15:06:52 +02:00
|
|
|
message_body_len = g_memory_buffer_read_uint32 (&mbuf);
|
|
|
|
message->serial = g_memory_buffer_read_uint32 (&mbuf);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2010-06-17 23:58:25 +02:00
|
|
|
#ifdef DEBUG_SERIALIZER
|
|
|
|
g_print ("Parsing blob (blob_len = 0x%04x bytes)\n", (gint) blob_len);
|
|
|
|
{
|
|
|
|
gchar *s;
|
|
|
|
s = _g_dbus_hexdump ((const gchar *) blob, blob_len, 2);
|
|
|
|
g_print ("%s\n", s);
|
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
#endif /* DEBUG_SERIALIZER */
|
|
|
|
|
|
|
|
#ifdef DEBUG_SERIALIZER
|
|
|
|
g_print ("Parsing headers (blob_len = 0x%04x bytes)\n", (gint) blob_len);
|
|
|
|
#endif /* DEBUG_SERIALIZER */
|
2012-11-01 01:44:03 +01:00
|
|
|
headers = parse_value_from_blob (&mbuf,
|
2010-05-06 20:13:59 +02:00
|
|
|
G_VARIANT_TYPE ("a{yv}"),
|
2010-05-14 18:49:51 +02:00
|
|
|
FALSE,
|
2010-06-17 23:58:25 +02:00
|
|
|
2,
|
2010-05-06 20:13:59 +02:00
|
|
|
error);
|
|
|
|
if (headers == NULL)
|
|
|
|
goto out;
|
|
|
|
g_variant_iter_init (&iter, headers);
|
2010-06-30 22:36:47 +02:00
|
|
|
while ((item = g_variant_iter_next_value (&iter)) != NULL)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
guchar header_field;
|
|
|
|
GVariant *value;
|
|
|
|
g_variant_get (item,
|
|
|
|
"{yv}",
|
|
|
|
&header_field,
|
|
|
|
&value);
|
|
|
|
g_dbus_message_set_header (message, header_field, value);
|
2010-06-30 22:36:47 +02:00
|
|
|
g_variant_unref (value);
|
|
|
|
g_variant_unref (item);
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
g_variant_unref (headers);
|
|
|
|
|
|
|
|
signature = g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_SIGNATURE);
|
|
|
|
if (signature != NULL)
|
|
|
|
{
|
|
|
|
const gchar *signature_str;
|
|
|
|
gsize signature_str_len;
|
|
|
|
|
2010-06-06 22:32:04 +02:00
|
|
|
signature_str = g_variant_get_string (signature, &signature_str_len);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
/* signature but no body */
|
|
|
|
if (message_body_len == 0 && signature_str_len > 0)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Signature header with signature '%s' found but message body is empty"),
|
2010-05-06 20:13:59 +02:00
|
|
|
signature_str);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else if (signature_str_len > 0)
|
|
|
|
{
|
|
|
|
GVariantType *variant_type;
|
|
|
|
gchar *tupled_signature_str;
|
|
|
|
|
|
|
|
if (!g_variant_is_signature (signature_str))
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Parsed value '%s' is not a valid D-Bus signature (for body)"),
|
2010-05-06 20:13:59 +02:00
|
|
|
signature_str);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
tupled_signature_str = g_strdup_printf ("(%s)", signature_str);
|
|
|
|
variant_type = g_variant_type_new (tupled_signature_str);
|
|
|
|
g_free (tupled_signature_str);
|
2010-06-17 23:58:25 +02:00
|
|
|
#ifdef DEBUG_SERIALIZER
|
|
|
|
g_print ("Parsing body (blob_len = 0x%04x bytes)\n", (gint) blob_len);
|
|
|
|
#endif /* DEBUG_SERIALIZER */
|
2012-11-01 01:44:03 +01:00
|
|
|
message->body = parse_value_from_blob (&mbuf,
|
2010-07-07 22:35:17 +02:00
|
|
|
variant_type,
|
|
|
|
FALSE,
|
|
|
|
2,
|
|
|
|
error);
|
2010-05-06 20:13:59 +02:00
|
|
|
g_variant_type_free (variant_type);
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->body == NULL)
|
2010-06-30 22:36:47 +02:00
|
|
|
goto out;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* no signature, this is only OK if the body is empty */
|
|
|
|
if (message_body_len != 0)
|
|
|
|
{
|
2010-07-07 13:37:42 +02:00
|
|
|
/* G_GUINT32_FORMAT doesn't work with gettext, just use %u */
|
2010-05-06 20:13:59 +02:00
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2011-08-27 19:15:42 +02:00
|
|
|
g_dngettext (GETTEXT_PACKAGE,
|
|
|
|
"No signature header in message but the message body is %u byte",
|
|
|
|
"No signature header in message but the message body is %u bytes",
|
|
|
|
message_body_len),
|
2010-05-06 20:13:59 +02:00
|
|
|
message_body_len);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 20:38:51 +02:00
|
|
|
if (!validate_headers (message, error))
|
|
|
|
{
|
|
|
|
g_prefix_error (error, _("Cannot deserialize message: "));
|
|
|
|
goto out;
|
|
|
|
}
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (message != NULL)
|
|
|
|
g_object_unref (message);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static gsize
|
2012-11-01 01:44:03 +01:00
|
|
|
ensure_output_padding (GMemoryBuffer *mbuf,
|
2014-05-09 15:06:52 +02:00
|
|
|
gsize padding_size)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
gsize offset;
|
|
|
|
gsize wanted_offset;
|
|
|
|
gsize padding_needed;
|
|
|
|
guint n;
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
offset = mbuf->pos;
|
2010-05-06 20:13:59 +02:00
|
|
|
wanted_offset = ((offset + padding_size - 1) / padding_size) * padding_size;
|
|
|
|
padding_needed = wanted_offset - offset;
|
|
|
|
|
|
|
|
for (n = 0; n < padding_needed; n++)
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_byte (mbuf, '\0');
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
return padding_needed;
|
|
|
|
}
|
|
|
|
|
2010-05-14 18:49:51 +02:00
|
|
|
/* note that value can be NULL for e.g. empty arrays - type is never NULL */
|
2010-05-06 20:13:59 +02:00
|
|
|
static gboolean
|
2014-05-09 15:06:52 +02:00
|
|
|
append_value_to_blob (GVariant *value,
|
|
|
|
const GVariantType *type,
|
|
|
|
GMemoryBuffer *mbuf,
|
|
|
|
gsize *out_padding_added,
|
|
|
|
GError **error)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
gsize padding_added;
|
2011-06-15 00:11:09 +02:00
|
|
|
const gchar *type_string;
|
|
|
|
|
|
|
|
type_string = g_variant_type_peek_string (type);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
padding_added = 0;
|
|
|
|
|
2011-06-15 00:11:09 +02:00
|
|
|
switch (type_string[0])
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
case 'b': /* G_VARIANT_TYPE_BOOLEAN */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 4);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
gboolean v = g_variant_get_boolean (value);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_uint32 (mbuf, v);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'y': /* G_VARIANT_TYPE_BYTE */
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
guint8 v = g_variant_get_byte (value);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_byte (mbuf, v);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n': /* G_VARIANT_TYPE_INT16 */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 2);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
gint16 v = g_variant_get_int16 (value);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_int16 (mbuf, v);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'q': /* G_VARIANT_TYPE_UINT16 */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 2);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
guint16 v = g_variant_get_uint16 (value);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_uint16 (mbuf, v);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i': /* G_VARIANT_TYPE_INT32 */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 4);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
gint32 v = g_variant_get_int32 (value);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_int32 (mbuf, v);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u': /* G_VARIANT_TYPE_UINT32 */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 4);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
guint32 v = g_variant_get_uint32 (value);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_uint32 (mbuf, v);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x': /* G_VARIANT_TYPE_INT64 */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 8);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
gint64 v = g_variant_get_int64 (value);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_int64 (mbuf, v);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': /* G_VARIANT_TYPE_UINT64 */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 8);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
guint64 v = g_variant_get_uint64 (value);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_uint64 (mbuf, v);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd': /* G_VARIANT_TYPE_DOUBLE */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 8);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
2011-06-09 18:02:30 +02:00
|
|
|
union {
|
|
|
|
guint64 v_uint64;
|
|
|
|
gdouble v_double;
|
|
|
|
} u;
|
2010-08-04 18:24:22 +02:00
|
|
|
G_STATIC_ASSERT (sizeof (gdouble) == sizeof (guint64));
|
2011-06-09 18:02:30 +02:00
|
|
|
u.v_double = g_variant_get_double (value);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_uint64 (mbuf, u.v_uint64);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's': /* G_VARIANT_TYPE_STRING */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 4);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
gsize len;
|
2010-08-04 18:24:22 +02:00
|
|
|
const gchar *v;
|
|
|
|
const gchar *end;
|
|
|
|
v = g_variant_get_string (value, &len);
|
|
|
|
g_assert (g_utf8_validate (v, -1, &end) && (end == v + len));
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_uint32 (mbuf, len);
|
|
|
|
g_memory_buffer_put_string (mbuf, v);
|
|
|
|
g_memory_buffer_put_byte (mbuf, '\0');
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o': /* G_VARIANT_TYPE_OBJECT_PATH */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 4);
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
gsize len;
|
2010-06-06 22:32:04 +02:00
|
|
|
const gchar *v = g_variant_get_string (value, &len);
|
2010-08-04 18:24:22 +02:00
|
|
|
g_assert (g_variant_is_object_path (v));
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_uint32 (mbuf, len);
|
|
|
|
g_memory_buffer_put_string (mbuf, v);
|
|
|
|
g_memory_buffer_put_byte (mbuf, '\0');
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'g': /* G_VARIANT_TYPE_SIGNATURE */
|
2010-05-14 18:49:51 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
gsize len;
|
2010-06-06 22:32:04 +02:00
|
|
|
const gchar *v = g_variant_get_string (value, &len);
|
2010-08-04 18:24:22 +02:00
|
|
|
g_assert (g_variant_is_signature (v));
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_byte (mbuf, len);
|
|
|
|
g_memory_buffer_put_string (mbuf, v);
|
|
|
|
g_memory_buffer_put_byte (mbuf, '\0');
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h': /* G_VARIANT_TYPE_HANDLE */
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 4);
|
2010-07-20 17:38:23 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
gint32 v = g_variant_get_handle (value);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_int32 (mbuf, v);
|
2010-07-20 17:38:23 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2011-06-15 00:11:09 +02:00
|
|
|
case 'a': /* G_VARIANT_TYPE_ARRAY */
|
|
|
|
{
|
2014-07-05 00:42:14 +02:00
|
|
|
const GVariantType *element_type;
|
2011-06-15 00:11:09 +02:00
|
|
|
GVariant *item;
|
|
|
|
GVariantIter iter;
|
|
|
|
goffset array_len_offset;
|
|
|
|
goffset array_payload_begin_offset;
|
|
|
|
goffset cur_offset;
|
|
|
|
gsize array_len;
|
2014-07-05 00:42:14 +02:00
|
|
|
guint fixed_size;
|
2011-06-15 00:11:09 +02:00
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 4);
|
2011-06-15 00:11:09 +02:00
|
|
|
if (value != NULL)
|
|
|
|
{
|
|
|
|
/* array length - will be filled in later */
|
2012-11-01 01:44:03 +01:00
|
|
|
array_len_offset = mbuf->valid_len;
|
|
|
|
g_memory_buffer_put_uint32 (mbuf, 0xF00DFACE);
|
2011-06-15 00:11:09 +02:00
|
|
|
|
|
|
|
/* From the D-Bus spec:
|
|
|
|
*
|
|
|
|
* "A UINT32 giving the length of the array data in bytes,
|
|
|
|
* followed by alignment padding to the alignment boundary of
|
|
|
|
* the array element type, followed by each array element. The
|
|
|
|
* array length is from the end of the alignment padding to
|
|
|
|
* the end of the last element, i.e. it does not include the
|
|
|
|
* padding after the length, or any padding after the last
|
|
|
|
* element."
|
|
|
|
*
|
|
|
|
* Thus, we need to count how much padding the first element
|
|
|
|
* contributes and subtract that from the array length.
|
|
|
|
*/
|
2012-11-01 01:44:03 +01:00
|
|
|
array_payload_begin_offset = mbuf->valid_len;
|
2011-06-15 00:11:09 +02:00
|
|
|
|
2014-07-05 00:42:14 +02:00
|
|
|
element_type = g_variant_type_element (type);
|
|
|
|
fixed_size = get_type_fixed_size (element_type);
|
|
|
|
|
2011-06-15 00:11:09 +02:00
|
|
|
if (g_variant_n_children (value) == 0)
|
|
|
|
{
|
|
|
|
gsize padding_added_for_item;
|
|
|
|
if (!append_value_to_blob (NULL,
|
2014-07-05 00:42:14 +02:00
|
|
|
element_type,
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf,
|
2011-06-15 00:11:09 +02:00
|
|
|
&padding_added_for_item,
|
|
|
|
error))
|
|
|
|
goto fail;
|
|
|
|
array_payload_begin_offset += padding_added_for_item;
|
|
|
|
}
|
2014-07-05 00:42:14 +02:00
|
|
|
else if (fixed_size != 0)
|
|
|
|
{
|
|
|
|
GVariant *use_value;
|
|
|
|
|
|
|
|
if (g_memory_buffer_is_byteswapped (mbuf))
|
|
|
|
use_value = g_variant_byteswap (value);
|
|
|
|
else
|
|
|
|
use_value = g_variant_ref (value);
|
|
|
|
|
2014-07-24 11:36:57 +02:00
|
|
|
array_payload_begin_offset += ensure_output_padding (mbuf, fixed_size);
|
|
|
|
|
2014-07-05 00:42:14 +02:00
|
|
|
array_len = g_variant_get_size (use_value);
|
|
|
|
g_memory_buffer_write (mbuf, g_variant_get_data (use_value), array_len);
|
|
|
|
g_variant_unref (use_value);
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
guint n;
|
|
|
|
n = 0;
|
|
|
|
g_variant_iter_init (&iter, value);
|
|
|
|
while ((item = g_variant_iter_next_value (&iter)) != NULL)
|
|
|
|
{
|
|
|
|
gsize padding_added_for_item;
|
|
|
|
if (!append_value_to_blob (item,
|
|
|
|
g_variant_get_type (item),
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf,
|
2011-06-15 00:11:09 +02:00
|
|
|
&padding_added_for_item,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
g_variant_unref (item);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
g_variant_unref (item);
|
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
array_payload_begin_offset += padding_added_for_item;
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
cur_offset = mbuf->valid_len;
|
2011-06-15 00:11:09 +02:00
|
|
|
array_len = cur_offset - array_payload_begin_offset;
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf->pos = array_len_offset;
|
2011-06-15 00:11:09 +02:00
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_uint32 (mbuf, array_len);
|
|
|
|
mbuf->pos = cur_offset;
|
2011-06-15 00:11:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (g_variant_type_is_dict_entry (type) || g_variant_type_is_tuple (type))
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2012-11-01 01:44:03 +01:00
|
|
|
padding_added = ensure_output_padding (mbuf, 8);
|
2011-06-15 00:11:09 +02:00
|
|
|
if (value != NULL)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
GVariant *item;
|
|
|
|
GVariantIter iter;
|
2010-05-14 18:49:51 +02:00
|
|
|
g_variant_iter_init (&iter, value);
|
2010-06-30 22:36:47 +02:00
|
|
|
while ((item = g_variant_iter_next_value (&iter)) != NULL)
|
2010-05-14 18:49:51 +02:00
|
|
|
{
|
|
|
|
if (!append_value_to_blob (item,
|
|
|
|
g_variant_get_type (item),
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf,
|
2011-06-15 00:11:09 +02:00
|
|
|
NULL,
|
2010-05-14 18:49:51 +02:00
|
|
|
error))
|
2010-06-30 22:36:47 +02:00
|
|
|
{
|
|
|
|
g_variant_unref (item);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
g_variant_unref (item);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
else if (g_variant_type_is_variant (type))
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
if (value != NULL)
|
2010-05-14 18:49:51 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
GVariant *child;
|
|
|
|
const gchar *signature;
|
|
|
|
child = g_variant_get_child_value (value, 0);
|
|
|
|
signature = g_variant_get_type_string (child);
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_byte (mbuf, strlen (signature));
|
|
|
|
g_memory_buffer_put_string (mbuf, signature);
|
|
|
|
g_memory_buffer_put_byte (mbuf, '\0');
|
2011-06-15 00:11:09 +02:00
|
|
|
if (!append_value_to_blob (child,
|
|
|
|
g_variant_get_type (child),
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf,
|
2010-05-14 18:49:51 +02:00
|
|
|
NULL,
|
|
|
|
error))
|
2010-06-30 22:36:47 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
g_variant_unref (child);
|
2010-06-30 22:36:47 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
g_variant_unref (child);
|
2010-05-14 18:49:51 +02:00
|
|
|
}
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
else
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2011-06-15 00:11:09 +02:00
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Error serializing GVariant with type string '%s' to the D-Bus wire format"),
|
2011-06-15 00:11:09 +02:00
|
|
|
g_variant_get_type_string (value));
|
|
|
|
goto fail;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
2011-06-15 00:11:09 +02:00
|
|
|
break;
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (out_padding_added != NULL)
|
|
|
|
*out_padding_added = padding_added;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-05-09 15:06:52 +02:00
|
|
|
append_body_to_blob (GVariant *value,
|
2012-11-01 01:44:03 +01:00
|
|
|
GMemoryBuffer *mbuf,
|
2014-05-09 15:06:52 +02:00
|
|
|
GError **error)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
GVariant *item;
|
|
|
|
GVariantIter iter;
|
|
|
|
|
|
|
|
if (!g_variant_is_of_type (value, G_VARIANT_TYPE_TUPLE))
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
|
|
|
"Expected a tuple for the body of the GDBusMessage.");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, value);
|
2010-06-30 22:36:47 +02:00
|
|
|
while ((item = g_variant_iter_next_value (&iter)) != NULL)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!append_value_to_blob (item,
|
|
|
|
g_variant_get_type (item),
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf,
|
2010-05-14 18:49:51 +02:00
|
|
|
NULL,
|
|
|
|
error))
|
2010-06-30 22:36:47 +02:00
|
|
|
{
|
|
|
|
g_variant_unref (item);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
g_variant_unref (item);
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_to_blob:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @out_size: Return location for size of generated blob.
|
2010-05-13 20:01:41 +02:00
|
|
|
* @capabilities: A #GDBusCapabilityFlags describing what protocol features are supported.
|
2010-05-06 20:13:59 +02:00
|
|
|
* @error: Return location for error.
|
|
|
|
*
|
2010-08-04 19:32:19 +02:00
|
|
|
* Serializes @message to a blob. The byte order returned by
|
|
|
|
* g_dbus_message_get_byte_order() will be used.
|
2010-05-06 20:13:59 +02:00
|
|
|
*
|
2012-01-07 18:54:53 +01:00
|
|
|
* Returns: (array length=out_size) (transfer full): A pointer to a
|
|
|
|
* valid binary D-Bus message of @out_size bytes generated by @message
|
|
|
|
* or %NULL if @error is set. Free with g_free().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
guchar *
|
2010-05-13 20:01:41 +02:00
|
|
|
g_dbus_message_to_blob (GDBusMessage *message,
|
|
|
|
gsize *out_size,
|
|
|
|
GDBusCapabilityFlags capabilities,
|
|
|
|
GError **error)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2012-11-01 01:44:03 +01:00
|
|
|
GMemoryBuffer mbuf;
|
2010-05-06 20:13:59 +02:00
|
|
|
guchar *ret;
|
|
|
|
gsize size;
|
|
|
|
goffset body_len_offset;
|
|
|
|
goffset body_start_offset;
|
|
|
|
gsize body_size;
|
|
|
|
GVariant *header_fields;
|
2010-05-14 14:00:24 +02:00
|
|
|
GVariantBuilder builder;
|
2010-05-06 20:13:59 +02:00
|
|
|
GHashTableIter hash_iter;
|
|
|
|
gpointer key;
|
|
|
|
GVariant *header_value;
|
|
|
|
GVariant *signature;
|
|
|
|
const gchar *signature_str;
|
|
|
|
gint num_fds_in_message;
|
|
|
|
gint num_fds_according_to_header;
|
|
|
|
|
2010-05-13 20:01:41 +02:00
|
|
|
/* TODO: check against @capabilities */
|
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
ret = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
g_return_val_if_fail (out_size != NULL, NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
memset (&mbuf, 0, sizeof (mbuf));
|
|
|
|
mbuf.len = MIN_ARRAY_SIZE;
|
|
|
|
mbuf.data = g_malloc (mbuf.len);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf.byte_order = G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN;
|
2010-08-04 19:32:19 +02:00
|
|
|
switch (message->byte_order)
|
|
|
|
{
|
|
|
|
case G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN:
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf.byte_order = G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN;
|
2010-08-04 19:32:19 +02:00
|
|
|
break;
|
|
|
|
case G_DBUS_MESSAGE_BYTE_ORDER_LITTLE_ENDIAN:
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf.byte_order = G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN;
|
2010-08-04 19:32:19 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
/* Core header */
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_byte (&mbuf, (guchar) message->byte_order);
|
|
|
|
g_memory_buffer_put_byte (&mbuf, message->type);
|
|
|
|
g_memory_buffer_put_byte (&mbuf, message->flags);
|
|
|
|
g_memory_buffer_put_byte (&mbuf, 1); /* major protocol version */
|
|
|
|
body_len_offset = mbuf.valid_len;
|
2010-05-06 20:13:59 +02:00
|
|
|
/* body length - will be filled in later */
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_uint32 (&mbuf, 0xF00DFACE);
|
|
|
|
g_memory_buffer_put_uint32 (&mbuf, message->serial);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
num_fds_in_message = 0;
|
|
|
|
#ifdef G_OS_UNIX
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->fd_list != NULL)
|
|
|
|
num_fds_in_message = g_unix_fd_list_get_length (message->fd_list);
|
2010-05-06 20:13:59 +02:00
|
|
|
#endif
|
|
|
|
num_fds_according_to_header = g_dbus_message_get_num_unix_fds (message);
|
|
|
|
if (num_fds_in_message != num_fds_according_to_header)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2011-08-27 19:18:45 +02:00
|
|
|
_("Message has %d file descriptors but the header field indicates %d file descriptors"),
|
2010-05-06 20:13:59 +02:00
|
|
|
num_fds_in_message,
|
|
|
|
num_fds_according_to_header);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-08-04 20:38:51 +02:00
|
|
|
if (!validate_headers (message, error))
|
|
|
|
{
|
|
|
|
g_prefix_error (error, _("Cannot serialize message: "));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-05-14 14:00:24 +02:00
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{yv}"));
|
2010-07-07 22:35:17 +02:00
|
|
|
g_hash_table_iter_init (&hash_iter, message->headers);
|
2010-05-06 20:13:59 +02:00
|
|
|
while (g_hash_table_iter_next (&hash_iter, &key, (gpointer) &header_value))
|
|
|
|
{
|
2010-05-14 14:00:24 +02:00
|
|
|
g_variant_builder_add (&builder,
|
2010-05-06 20:13:59 +02:00
|
|
|
"{yv}",
|
|
|
|
(guchar) GPOINTER_TO_UINT (key),
|
|
|
|
header_value);
|
|
|
|
}
|
2010-05-14 14:00:24 +02:00
|
|
|
header_fields = g_variant_builder_end (&builder);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2010-05-14 18:49:51 +02:00
|
|
|
if (!append_value_to_blob (header_fields,
|
|
|
|
g_variant_get_type (header_fields),
|
2012-11-01 01:44:03 +01:00
|
|
|
&mbuf,
|
2010-05-14 18:49:51 +02:00
|
|
|
NULL,
|
|
|
|
error))
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
g_variant_unref (header_fields);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
g_variant_unref (header_fields);
|
|
|
|
|
|
|
|
/* header size must be a multiple of 8 */
|
2012-11-01 01:44:03 +01:00
|
|
|
ensure_output_padding (&mbuf, 8);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
body_start_offset = mbuf.valid_len;
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
signature = g_dbus_message_get_header (message, G_DBUS_MESSAGE_HEADER_FIELD_SIGNATURE);
|
|
|
|
signature_str = NULL;
|
|
|
|
if (signature != NULL)
|
|
|
|
signature_str = g_variant_get_string (signature, NULL);
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->body != NULL)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
gchar *tupled_signature_str;
|
|
|
|
tupled_signature_str = g_strdup_printf ("(%s)", signature_str);
|
|
|
|
if (signature == NULL)
|
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Message body has signature '%s' but there is no signature header"),
|
2010-05-06 20:13:59 +02:00
|
|
|
signature_str);
|
|
|
|
g_free (tupled_signature_str);
|
|
|
|
goto out;
|
|
|
|
}
|
2010-07-07 22:35:17 +02:00
|
|
|
else if (g_strcmp0 (tupled_signature_str, g_variant_get_type_string (message->body)) != 0)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Message body has type signature '%s' but signature in the header field is '%s'"),
|
2010-07-07 22:35:17 +02:00
|
|
|
tupled_signature_str, g_variant_get_type_string (message->body));
|
2010-05-06 20:13:59 +02:00
|
|
|
g_free (tupled_signature_str);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
g_free (tupled_signature_str);
|
2012-11-01 01:44:03 +01:00
|
|
|
if (!append_body_to_blob (message->body, &mbuf, error))
|
2010-05-06 20:13:59 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-15 18:19:24 +02:00
|
|
|
if (signature != NULL && strlen (signature_str) > 0)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_INVALID_ARGUMENT,
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Message body is empty but signature in the header field is '(%s)'"),
|
2010-05-06 20:13:59 +02:00
|
|
|
signature_str);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK, we're done writing the message - set the body length */
|
2012-11-01 01:44:03 +01:00
|
|
|
size = mbuf.valid_len;
|
2010-05-06 20:13:59 +02:00
|
|
|
body_size = size - body_start_offset;
|
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
mbuf.pos = body_len_offset;
|
2010-05-06 20:13:59 +02:00
|
|
|
|
2012-11-01 01:44:03 +01:00
|
|
|
g_memory_buffer_put_uint32 (&mbuf, body_size);
|
2010-06-20 14:33:27 +02:00
|
|
|
|
2010-05-06 20:13:59 +02:00
|
|
|
*out_size = size;
|
2012-11-01 01:44:03 +01:00
|
|
|
ret = (guchar *)mbuf.data;
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static guint32
|
|
|
|
get_uint32_header (GDBusMessage *message,
|
|
|
|
GDBusMessageHeaderField header_field)
|
|
|
|
{
|
|
|
|
GVariant *value;
|
|
|
|
guint32 ret;
|
|
|
|
|
|
|
|
ret = 0;
|
2010-07-07 22:35:17 +02:00
|
|
|
value = g_hash_table_lookup (message->headers, GUINT_TO_POINTER (header_field));
|
2010-05-06 20:13:59 +02:00
|
|
|
if (value != NULL && g_variant_is_of_type (value, G_VARIANT_TYPE_UINT32))
|
|
|
|
ret = g_variant_get_uint32 (value);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
get_string_header (GDBusMessage *message,
|
|
|
|
GDBusMessageHeaderField header_field)
|
|
|
|
{
|
|
|
|
GVariant *value;
|
|
|
|
const gchar *ret;
|
|
|
|
|
|
|
|
ret = NULL;
|
2010-07-07 22:35:17 +02:00
|
|
|
value = g_hash_table_lookup (message->headers, GUINT_TO_POINTER (header_field));
|
2010-05-06 20:13:59 +02:00
|
|
|
if (value != NULL && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
|
|
|
|
ret = g_variant_get_string (value, NULL);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
get_object_path_header (GDBusMessage *message,
|
|
|
|
GDBusMessageHeaderField header_field)
|
|
|
|
{
|
|
|
|
GVariant *value;
|
|
|
|
const gchar *ret;
|
|
|
|
|
|
|
|
ret = NULL;
|
2010-07-07 22:35:17 +02:00
|
|
|
value = g_hash_table_lookup (message->headers, GUINT_TO_POINTER (header_field));
|
2010-05-06 20:13:59 +02:00
|
|
|
if (value != NULL && g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH))
|
|
|
|
ret = g_variant_get_string (value, NULL);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
get_signature_header (GDBusMessage *message,
|
|
|
|
GDBusMessageHeaderField header_field)
|
|
|
|
{
|
|
|
|
GVariant *value;
|
|
|
|
const gchar *ret;
|
|
|
|
|
|
|
|
ret = NULL;
|
2010-07-07 22:35:17 +02:00
|
|
|
value = g_hash_table_lookup (message->headers, GUINT_TO_POINTER (header_field));
|
2010-05-06 20:13:59 +02:00
|
|
|
if (value != NULL && g_variant_is_of_type (value, G_VARIANT_TYPE_SIGNATURE))
|
|
|
|
ret = g_variant_get_string (value, NULL);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_uint32_header (GDBusMessage *message,
|
|
|
|
GDBusMessageHeaderField header_field,
|
|
|
|
guint32 value)
|
|
|
|
{
|
|
|
|
g_dbus_message_set_header (message,
|
|
|
|
header_field,
|
|
|
|
g_variant_new_uint32 (value));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_string_header (GDBusMessage *message,
|
|
|
|
GDBusMessageHeaderField header_field,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
g_dbus_message_set_header (message,
|
|
|
|
header_field,
|
|
|
|
value == NULL ? NULL : g_variant_new_string (value));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_object_path_header (GDBusMessage *message,
|
|
|
|
GDBusMessageHeaderField header_field,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
g_dbus_message_set_header (message,
|
|
|
|
header_field,
|
|
|
|
value == NULL ? NULL : g_variant_new_object_path (value));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_signature_header (GDBusMessage *message,
|
|
|
|
GDBusMessageHeaderField header_field,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
g_dbus_message_set_header (message,
|
|
|
|
header_field,
|
|
|
|
value == NULL ? NULL : g_variant_new_signature (value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_reply_serial:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Convenience getter for the %G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL header field.
|
|
|
|
*
|
|
|
|
* Returns: The value.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
guint32
|
|
|
|
g_dbus_message_get_reply_serial (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), 0);
|
|
|
|
return get_uint32_header (message, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_reply_serial:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @value: The value to set.
|
|
|
|
*
|
|
|
|
* Convenience setter for the %G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL header field.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_reply_serial (GDBusMessage *message,
|
|
|
|
guint32 value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
set_uint32_header (message, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_interface:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Convenience getter for the %G_DBUS_MESSAGE_HEADER_FIELD_INTERFACE header field.
|
|
|
|
*
|
|
|
|
* Returns: The value.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
g_dbus_message_get_interface (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
return get_string_header (message, G_DBUS_MESSAGE_HEADER_FIELD_INTERFACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_interface:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @value: The value to set.
|
|
|
|
*
|
|
|
|
* Convenience setter for the %G_DBUS_MESSAGE_HEADER_FIELD_INTERFACE header field.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_interface (GDBusMessage *message,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (value == NULL || g_dbus_is_interface_name (value));
|
|
|
|
set_string_header (message, G_DBUS_MESSAGE_HEADER_FIELD_INTERFACE, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_member:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Convenience getter for the %G_DBUS_MESSAGE_HEADER_FIELD_MEMBER header field.
|
|
|
|
*
|
|
|
|
* Returns: The value.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
g_dbus_message_get_member (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
return get_string_header (message, G_DBUS_MESSAGE_HEADER_FIELD_MEMBER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_member:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @value: The value to set.
|
|
|
|
*
|
|
|
|
* Convenience setter for the %G_DBUS_MESSAGE_HEADER_FIELD_MEMBER header field.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_member (GDBusMessage *message,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (value == NULL || g_dbus_is_member_name (value));
|
|
|
|
set_string_header (message, G_DBUS_MESSAGE_HEADER_FIELD_MEMBER, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_path:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Convenience getter for the %G_DBUS_MESSAGE_HEADER_FIELD_PATH header field.
|
|
|
|
*
|
|
|
|
* Returns: The value.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
g_dbus_message_get_path (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
return get_object_path_header (message, G_DBUS_MESSAGE_HEADER_FIELD_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_path:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @value: The value to set.
|
|
|
|
*
|
|
|
|
* Convenience setter for the %G_DBUS_MESSAGE_HEADER_FIELD_PATH header field.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_path (GDBusMessage *message,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (value == NULL || g_variant_is_object_path (value));
|
|
|
|
set_object_path_header (message, G_DBUS_MESSAGE_HEADER_FIELD_PATH, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_sender:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Convenience getter for the %G_DBUS_MESSAGE_HEADER_FIELD_SENDER header field.
|
|
|
|
*
|
|
|
|
* Returns: The value.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
g_dbus_message_get_sender (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
return get_string_header (message, G_DBUS_MESSAGE_HEADER_FIELD_SENDER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_sender:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @value: The value to set.
|
|
|
|
*
|
|
|
|
* Convenience setter for the %G_DBUS_MESSAGE_HEADER_FIELD_SENDER header field.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_sender (GDBusMessage *message,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (value == NULL || g_dbus_is_name (value));
|
|
|
|
set_string_header (message, G_DBUS_MESSAGE_HEADER_FIELD_SENDER, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_destination:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Convenience getter for the %G_DBUS_MESSAGE_HEADER_FIELD_DESTINATION header field.
|
|
|
|
*
|
|
|
|
* Returns: The value.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
g_dbus_message_get_destination (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
return get_string_header (message, G_DBUS_MESSAGE_HEADER_FIELD_DESTINATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_destination:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @value: The value to set.
|
|
|
|
*
|
|
|
|
* Convenience setter for the %G_DBUS_MESSAGE_HEADER_FIELD_DESTINATION header field.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_destination (GDBusMessage *message,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (value == NULL || g_dbus_is_name (value));
|
|
|
|
set_string_header (message, G_DBUS_MESSAGE_HEADER_FIELD_DESTINATION, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_error_name:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Convenience getter for the %G_DBUS_MESSAGE_HEADER_FIELD_ERROR_NAME header field.
|
|
|
|
*
|
|
|
|
* Returns: The value.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
g_dbus_message_get_error_name (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
return get_string_header (message, G_DBUS_MESSAGE_HEADER_FIELD_ERROR_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_error_name:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @value: The value to set.
|
|
|
|
*
|
|
|
|
* Convenience setter for the %G_DBUS_MESSAGE_HEADER_FIELD_ERROR_NAME header field.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_error_name (GDBusMessage *message,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (value == NULL || g_dbus_is_interface_name (value));
|
|
|
|
set_string_header (message, G_DBUS_MESSAGE_HEADER_FIELD_ERROR_NAME, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_signature:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Convenience getter for the %G_DBUS_MESSAGE_HEADER_FIELD_SIGNATURE header field.
|
|
|
|
*
|
|
|
|
* Returns: The value.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
g_dbus_message_get_signature (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
const gchar *ret;
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
ret = get_signature_header (message, G_DBUS_MESSAGE_HEADER_FIELD_SIGNATURE);
|
|
|
|
if (ret == NULL)
|
|
|
|
ret = "";
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_signature:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @value: The value to set.
|
|
|
|
*
|
|
|
|
* Convenience setter for the %G_DBUS_MESSAGE_HEADER_FIELD_SIGNATURE header field.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_signature (GDBusMessage *message,
|
|
|
|
const gchar *value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
g_return_if_fail (value == NULL || g_variant_is_signature (value));
|
|
|
|
set_signature_header (message, G_DBUS_MESSAGE_HEADER_FIELD_SIGNATURE, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_arg0:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Convenience to get the first item in the body of @message.
|
|
|
|
*
|
|
|
|
* Returns: The string item or %NULL if the first item in the body of
|
|
|
|
* @message is not a string.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
g_dbus_message_get_arg0 (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
const gchar *ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
|
|
|
|
ret = NULL;
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->body != NULL && g_variant_is_of_type (message->body, G_VARIANT_TYPE_TUPLE))
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
GVariant *item;
|
2010-07-07 22:35:17 +02:00
|
|
|
item = g_variant_get_child_value (message->body, 0);
|
2010-05-06 20:13:59 +02:00
|
|
|
if (g_variant_is_of_type (item, G_VARIANT_TYPE_STRING))
|
|
|
|
ret = g_variant_get_string (item, NULL);
|
2010-06-30 22:36:47 +02:00
|
|
|
g_variant_unref (item);
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_num_unix_fds:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Convenience getter for the %G_DBUS_MESSAGE_HEADER_FIELD_NUM_UNIX_FDS header field.
|
|
|
|
*
|
|
|
|
* Returns: The value.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
guint32
|
|
|
|
g_dbus_message_get_num_unix_fds (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), 0);
|
|
|
|
return get_uint32_header (message, G_DBUS_MESSAGE_HEADER_FIELD_NUM_UNIX_FDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_set_num_unix_fds:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @value: The value to set.
|
|
|
|
*
|
|
|
|
* Convenience setter for the %G_DBUS_MESSAGE_HEADER_FIELD_NUM_UNIX_FDS header field.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_set_num_unix_fds (GDBusMessage *message,
|
|
|
|
guint32 value)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
set_uint32_header (message, G_DBUS_MESSAGE_HEADER_FIELD_NUM_UNIX_FDS, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_to_gerror:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @error: The #GError to set.
|
|
|
|
*
|
|
|
|
* If @message is not of type %G_DBUS_MESSAGE_TYPE_ERROR does
|
|
|
|
* nothing and returns %FALSE.
|
|
|
|
*
|
|
|
|
* Otherwise this method encodes the error in @message as a #GError
|
|
|
|
* using g_dbus_error_set_dbus_error() using the information in the
|
|
|
|
* %G_DBUS_MESSAGE_HEADER_FIELD_ERROR_NAME header field of @message as
|
|
|
|
* well as the first string item in @message's body.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @error was set, %FALSE otherwise.
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_dbus_message_to_gerror (GDBusMessage *message,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
const gchar *error_name;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), FALSE);
|
|
|
|
|
|
|
|
ret = FALSE;
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->type != G_DBUS_MESSAGE_TYPE_ERROR)
|
2010-05-06 20:13:59 +02:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
error_name = g_dbus_message_get_error_name (message);
|
|
|
|
if (error_name != NULL)
|
|
|
|
{
|
|
|
|
GVariant *body;
|
|
|
|
|
|
|
|
body = g_dbus_message_get_body (message);
|
|
|
|
|
|
|
|
if (body != NULL && g_variant_is_of_type (body, G_VARIANT_TYPE ("(s)")))
|
|
|
|
{
|
|
|
|
const gchar *error_message;
|
2010-05-13 19:20:26 +02:00
|
|
|
g_variant_get (body, "(&s)", &error_message);
|
2010-05-06 20:13:59 +02:00
|
|
|
g_dbus_error_set_dbus_error (error,
|
|
|
|
error_name,
|
|
|
|
error_message,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* these two situations are valid, yet pretty rare */
|
|
|
|
if (body != NULL)
|
|
|
|
{
|
|
|
|
g_dbus_error_set_dbus_error (error,
|
|
|
|
error_name,
|
|
|
|
"",
|
2013-05-20 22:54:48 +02:00
|
|
|
_("Error return with body of type '%s'"),
|
2010-05-06 20:13:59 +02:00
|
|
|
g_variant_get_type_string (body));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_dbus_error_set_dbus_error (error,
|
|
|
|
error_name,
|
|
|
|
"",
|
|
|
|
_("Error return with empty body"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* TOOD: this shouldn't happen - should check this at message serialization
|
|
|
|
* time and disconnect the peer.
|
|
|
|
*/
|
|
|
|
g_set_error (error,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Error return without error-name header!");
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
flags_to_string (GType flags_type, guint value)
|
|
|
|
{
|
|
|
|
GString *s;
|
|
|
|
GFlagsClass *klass;
|
|
|
|
guint n;
|
|
|
|
|
|
|
|
klass = g_type_class_ref (flags_type);
|
|
|
|
s = g_string_new (NULL);
|
|
|
|
for (n = 0; n < 32; n++)
|
|
|
|
{
|
|
|
|
if ((value & (1<<n)) != 0)
|
|
|
|
{
|
|
|
|
GFlagsValue *flags_value;
|
|
|
|
flags_value = g_flags_get_first_value (klass, (1<<n));
|
|
|
|
if (s->len > 0)
|
|
|
|
g_string_append_c (s, ',');
|
|
|
|
if (flags_value != NULL)
|
|
|
|
g_string_append (s, flags_value->value_nick);
|
|
|
|
else
|
|
|
|
g_string_append_printf (s, "unknown (bit %d)", n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (s->len == 0)
|
|
|
|
g_string_append (s, "none");
|
|
|
|
g_type_class_unref (klass);
|
2010-07-06 01:45:55 +02:00
|
|
|
return g_string_free (s, FALSE);
|
2010-05-06 20:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
_sort_keys_func (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
gint ia;
|
|
|
|
gint ib;
|
|
|
|
|
|
|
|
ia = GPOINTER_TO_INT (a);
|
|
|
|
ib = GPOINTER_TO_INT (b);
|
|
|
|
|
|
|
|
return ia - ib;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_print:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @indent: Indentation level.
|
|
|
|
*
|
|
|
|
* Produces a human-readable multi-line description of @message.
|
|
|
|
*
|
|
|
|
* The contents of the description has no ABI guarantees, the contents
|
|
|
|
* and formatting is subject to change at any time. Typical output
|
|
|
|
* looks something like this:
|
2014-02-01 03:56:33 +01:00
|
|
|
* |[
|
2014-02-01 17:57:13 +01:00
|
|
|
* Type: method-call
|
|
|
|
* Flags: none
|
|
|
|
* Version: 0
|
|
|
|
* Serial: 4
|
|
|
|
* Headers:
|
2010-05-06 20:13:59 +02:00
|
|
|
* path -> objectpath '/org/gtk/GDBus/TestObject'
|
|
|
|
* interface -> 'org.gtk.GDBus.TestInterface'
|
|
|
|
* member -> 'GimmeStdout'
|
|
|
|
* destination -> ':1.146'
|
2014-02-01 17:57:13 +01:00
|
|
|
* Body: ()
|
2010-05-06 20:13:59 +02:00
|
|
|
* UNIX File Descriptors:
|
|
|
|
* (none)
|
2014-02-01 03:56:33 +01:00
|
|
|
* ]|
|
2010-05-06 20:13:59 +02:00
|
|
|
* or
|
2014-02-01 03:56:33 +01:00
|
|
|
* |[
|
2014-02-01 17:57:13 +01:00
|
|
|
* Type: method-return
|
|
|
|
* Flags: no-reply-expected
|
|
|
|
* Version: 0
|
|
|
|
* Serial: 477
|
|
|
|
* Headers:
|
2010-05-06 20:13:59 +02:00
|
|
|
* reply-serial -> uint32 4
|
|
|
|
* destination -> ':1.159'
|
|
|
|
* sender -> ':1.146'
|
|
|
|
* num-unix-fds -> uint32 1
|
2014-02-01 17:57:13 +01:00
|
|
|
* Body: ()
|
|
|
|
* UNIX File Descriptors:
|
2010-05-06 20:13:59 +02:00
|
|
|
* fd 12: dev=0:10,mode=020620,ino=5,uid=500,gid=5,rdev=136:2,size=0,atime=1273085037,mtime=1273085851,ctime=1272982635
|
2014-02-01 03:56:33 +01:00
|
|
|
* ]|
|
2010-05-06 20:13:59 +02:00
|
|
|
*
|
|
|
|
* Returns: A string that should be freed with g_free().
|
2010-05-06 22:02:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
2010-05-06 20:13:59 +02:00
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
g_dbus_message_print (GDBusMessage *message,
|
|
|
|
guint indent)
|
|
|
|
{
|
|
|
|
GString *str;
|
|
|
|
gchar *s;
|
|
|
|
GList *keys;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
|
|
|
|
|
|
|
str = g_string_new (NULL);
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
s = _g_dbus_enum_to_string (G_TYPE_DBUS_MESSAGE_TYPE, message->type);
|
2010-05-06 20:13:59 +02:00
|
|
|
g_string_append_printf (str, "%*sType: %s\n", indent, "", s);
|
|
|
|
g_free (s);
|
2010-07-07 22:35:17 +02:00
|
|
|
s = flags_to_string (G_TYPE_DBUS_MESSAGE_FLAGS, message->flags);
|
2010-05-06 20:13:59 +02:00
|
|
|
g_string_append_printf (str, "%*sFlags: %s\n", indent, "", s);
|
|
|
|
g_free (s);
|
2010-07-07 22:35:17 +02:00
|
|
|
g_string_append_printf (str, "%*sVersion: %d\n", indent, "", message->major_protocol_version);
|
|
|
|
g_string_append_printf (str, "%*sSerial: %d\n", indent, "", message->serial);
|
2010-05-06 20:13:59 +02:00
|
|
|
|
|
|
|
g_string_append_printf (str, "%*sHeaders:\n", indent, "");
|
2010-07-07 22:35:17 +02:00
|
|
|
keys = g_hash_table_get_keys (message->headers);
|
2010-05-06 20:13:59 +02:00
|
|
|
keys = g_list_sort (keys, _sort_keys_func);
|
|
|
|
if (keys != NULL)
|
|
|
|
{
|
|
|
|
for (l = keys; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
gint key = GPOINTER_TO_INT (l->data);
|
|
|
|
GVariant *value;
|
|
|
|
gchar *value_str;
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
value = g_hash_table_lookup (message->headers, l->data);
|
2010-05-06 20:13:59 +02:00
|
|
|
g_assert (value != NULL);
|
|
|
|
|
GDBus: Handle autolaunching on UNIX/Freedesktop OSes
Also add a 'address' G_DBUS_DEBUG option that will print out useful
debug information such as
GDBus-debug:Address: In g_dbus_address_get_for_bus_sync() for bus type `session'
GDBus-debug:Address: env var DBUS_SESSION_BUS_ADDRESS is not set
GDBus-debug:Address: env var DBUS_SYSTEM_BUS_ADDRESS is not set
GDBus-debug:Address: env var DBUS_STARTER_BUS_TYPE is not set
GDBus-debug:Address: Running `dbus-launch --autolaunch=05e508961149264c9b750a4c494aa6f7 --binary-syntax --close-stderr' to get bus address (possibly autolaunching)
GDBus-debug:Address: dbus-launch output:
0000: 75 6e 69 78 3a 61 62 73 74 72 61 63 74 3d 2f 74 unix:abstract=/t
0010: 6d 70 2f 64 62 75 73 2d 77 42 41 6f 4b 59 49 52 mp/dbus-wBAoKYIR
0020: 7a 75 2c 67 75 69 64 3d 30 34 30 64 31 33 66 33 zu,guid=040d13f3
0030: 30 61 30 62 35 32 63 32 30 66 36 32 63 34 31 63 0a0b52c20f62c41c
0040: 30 30 30 30 35 30 38 64 00 d2 38 00 00 01 00 40 0000508d..8....@
0050: 05 00 00 00 00 .....
GDBus-debug:Address: dbus-launch stderr output:
14542: Autolaunch enabled (using X11).
14542: --exit-with-session automatically enabled
14542: Connected to X11 display ':0.0'
14542: === Parent dbus-launch continues
14542: Waiting for babysitter's intermediate parent
14542: Reading address from bus
14542: Reading PID from daemon
14542: Saving x11 address
14542: Created window 88080385
14542: session file: /root/.dbus/session-bus/05e508961149264c9b750a4c494aa6f7-0
14542: dbus-launch exiting
GDBus-debug:Address: Returning address `unix:abstract=/tmp/dbus-wBAoKYIRzu,guid=040d13f30a0b52c20f62c41c0000508d' for bus type `session'
and
GDBus-debug:Address: In g_dbus_address_get_for_bus_sync() for bus type `session'
GDBus-debug:Address: env var DBUS_SESSION_BUS_ADDRESS is not set
GDBus-debug:Address: env var DBUS_SYSTEM_BUS_ADDRESS is not set
GDBus-debug:Address: env var DBUS_STARTER_BUS_TYPE is not set
GDBus-debug:Address: Running `dbus-launch --autolaunch=05e508961149264c9b750a4c494aa6f7 --binary-syntax --close-stderr' to get bus address (possibly autolaunching)
GDBus-debug:Address: dbus-launch output:
0000: 75 6e 69 78 3a 61 62 73 74 72 61 63 74 3d 2f 74 unix:abstract=/t
0010: 6d 70 2f 64 62 75 73 2d 77 42 41 6f 4b 59 49 52 mp/dbus-wBAoKYIR
0020: 7a 75 2c 67 75 69 64 3d 30 34 30 64 31 33 66 33 zu,guid=040d13f3
0030: 30 61 30 62 35 32 63 32 30 66 36 32 63 34 31 63 0a0b52c20f62c41c
0040: 30 30 30 30 35 30 38 64 00 d2 38 00 00 01 00 40 0000508d..8....@
0050: 05 00 00 00 00 .....
GDBus-debug:Address: dbus-launch stderr output:
14549: Autolaunch enabled (using X11).
14549: --exit-with-session automatically enabled
14549: Connected to X11 display ':0.0'
14549: dbus-daemon is already running. Returning existing parameters.
14549: dbus-launch exiting
GDBus-debug:Address: Returning address `unix:abstract=/tmp/dbus-wBAoKYIRzu,guid=040d13f30a0b52c20f62c41c0000508d' for bus type `session'
Note that things work exactly like libdbus, e.g. from the
dbus-launch(1) man page:
Whenever an autolaunch occurs, the application that had to start a
new bus will be in its own little world; it can effectively end up
starting a whole new session if it tries to use a lot of bus
services. This can be suboptimal or even totally broken, depending
on the app and what it tries to do.
[...]
You can always avoid autolaunch by manually setting
DBUS_SESSION_BUS_ADDRESS. Autolaunch happens because the default
address if none is set is "autolaunch:", so if any other address is
set there will be no autolaunch. You can however include autolaunch
in an explicit session bus address as a fallback, for example
DBUS_SESSION_BUS_ADDRESS="something:,autolaunch:" - in that case if
the first address doesn't work, processes will autolaunch. (The bus
address variable contains a comma-separated list of addresses to
try.)
Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-07-06 22:57:28 +02:00
|
|
|
s = _g_dbus_enum_to_string (G_TYPE_DBUS_MESSAGE_HEADER_FIELD, key);
|
2010-05-06 20:13:59 +02:00
|
|
|
value_str = g_variant_print (value, TRUE);
|
|
|
|
g_string_append_printf (str, "%*s %s -> %s\n", indent, "", s, value_str);
|
|
|
|
g_free (s);
|
|
|
|
g_free (value_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_string_append_printf (str, "%*s (none)\n", indent, "");
|
|
|
|
}
|
|
|
|
g_string_append_printf (str, "%*sBody: ", indent, "");
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->body != NULL)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
2010-07-07 22:35:17 +02:00
|
|
|
g_variant_print_string (message->body,
|
2010-05-06 20:13:59 +02:00
|
|
|
str,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_string_append (str, "()");
|
|
|
|
}
|
|
|
|
g_string_append (str, "\n");
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
g_string_append_printf (str, "%*sUNIX File Descriptors:\n", indent, "");
|
2010-07-07 22:35:17 +02:00
|
|
|
if (message->fd_list != NULL)
|
2010-05-06 20:13:59 +02:00
|
|
|
{
|
|
|
|
gint num_fds;
|
|
|
|
const gint *fds;
|
|
|
|
gint n;
|
|
|
|
|
2010-07-07 22:35:17 +02:00
|
|
|
fds = g_unix_fd_list_peek_fds (message->fd_list, &num_fds);
|
2010-05-06 20:13:59 +02:00
|
|
|
if (num_fds > 0)
|
|
|
|
{
|
|
|
|
for (n = 0; n < num_fds; n++)
|
|
|
|
{
|
|
|
|
GString *fs;
|
|
|
|
struct stat statbuf;
|
|
|
|
fs = g_string_new (NULL);
|
|
|
|
if (fstat (fds[n], &statbuf) == 0)
|
|
|
|
{
|
|
|
|
g_string_append_printf (fs, "%s" "dev=%d:%d", fs->len > 0 ? "," : "",
|
|
|
|
major (statbuf.st_dev), minor (statbuf.st_dev));
|
|
|
|
g_string_append_printf (fs, "%s" "mode=0%o", fs->len > 0 ? "," : "",
|
|
|
|
statbuf.st_mode);
|
|
|
|
g_string_append_printf (fs, "%s" "ino=%" G_GUINT64_FORMAT, fs->len > 0 ? "," : "",
|
|
|
|
(guint64) statbuf.st_ino);
|
2013-09-25 11:22:26 +02:00
|
|
|
g_string_append_printf (fs, "%s" "uid=%u", fs->len > 0 ? "," : "",
|
|
|
|
(guint) statbuf.st_uid);
|
|
|
|
g_string_append_printf (fs, "%s" "gid=%u", fs->len > 0 ? "," : "",
|
|
|
|
(guint) statbuf.st_gid);
|
2010-05-06 20:13:59 +02:00
|
|
|
g_string_append_printf (fs, "%s" "rdev=%d:%d", fs->len > 0 ? "," : "",
|
|
|
|
major (statbuf.st_rdev), minor (statbuf.st_rdev));
|
|
|
|
g_string_append_printf (fs, "%s" "size=%" G_GUINT64_FORMAT, fs->len > 0 ? "," : "",
|
|
|
|
(guint64) statbuf.st_size);
|
|
|
|
g_string_append_printf (fs, "%s" "atime=%" G_GUINT64_FORMAT, fs->len > 0 ? "," : "",
|
|
|
|
(guint64) statbuf.st_atime);
|
|
|
|
g_string_append_printf (fs, "%s" "mtime=%" G_GUINT64_FORMAT, fs->len > 0 ? "," : "",
|
|
|
|
(guint64) statbuf.st_mtime);
|
|
|
|
g_string_append_printf (fs, "%s" "ctime=%" G_GUINT64_FORMAT, fs->len > 0 ? "," : "",
|
|
|
|
(guint64) statbuf.st_ctime);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_string_append_printf (fs, "(fstat failed: %s)", strerror (errno));
|
|
|
|
}
|
|
|
|
g_string_append_printf (str, "%*s fd %d: %s\n", indent, "", fds[n], fs->str);
|
|
|
|
g_string_free (fs, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_string_append_printf (str, "%*s (empty)\n", indent, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_string_append_printf (str, "%*s (none)\n", indent, "");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return g_string_free (str, FALSE);
|
|
|
|
}
|
2010-09-09 17:37:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_get_locked:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* Checks whether @message is locked. To monitor changes to this
|
|
|
|
* value, conncet to the #GObject::notify signal to listen for changes
|
|
|
|
* on the #GDBusMessage:locked property.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @message is locked, %FALSE otherwise.
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_dbus_message_get_locked (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), FALSE);
|
|
|
|
return message->locked;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_lock:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
*
|
|
|
|
* If @message is locked, does nothing. Otherwise locks the message.
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_dbus_message_lock (GDBusMessage *message)
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
|
|
|
|
|
|
|
|
if (message->locked)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
message->locked = TRUE;
|
|
|
|
g_object_notify (G_OBJECT (message), "locked");
|
|
|
|
|
|
|
|
out:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_dbus_message_copy:
|
|
|
|
* @message: A #GDBusMessage.
|
|
|
|
* @error: Return location for error or %NULL.
|
|
|
|
*
|
|
|
|
* Copies @message. The copy is a deep copy and the returned
|
|
|
|
* #GDBusMessage is completely identical except that it is guaranteed
|
2010-09-09 21:15:13 +02:00
|
|
|
* to not be locked.
|
2010-09-09 17:37:14 +02:00
|
|
|
*
|
|
|
|
* This operation can fail if e.g. @message contains file descriptors
|
|
|
|
* and the per-process or system-wide open files limit is reached.
|
|
|
|
*
|
2011-04-27 04:51:54 +02:00
|
|
|
* Returns: (transfer full): A new #GDBusMessage or %NULL if @error is set.
|
|
|
|
* Free with g_object_unref().
|
2010-09-09 17:37:14 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
GDBusMessage *
|
|
|
|
g_dbus_message_copy (GDBusMessage *message,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GDBusMessage *ret;
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer header_key;
|
|
|
|
GVariant *header_value;
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
2011-04-27 04:51:54 +02:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2010-09-09 17:37:14 +02:00
|
|
|
|
|
|
|
ret = g_dbus_message_new ();
|
|
|
|
ret->type = message->type;
|
|
|
|
ret->flags = message->flags;
|
|
|
|
ret->byte_order = message->byte_order;
|
|
|
|
ret->major_protocol_version = message->major_protocol_version;
|
2010-09-09 21:15:13 +02:00
|
|
|
ret->serial = message->serial;
|
2010-09-09 17:37:14 +02:00
|
|
|
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
if (message->fd_list != NULL)
|
|
|
|
{
|
|
|
|
gint n;
|
|
|
|
gint num_fds;
|
|
|
|
const gint *fds;
|
|
|
|
|
|
|
|
ret->fd_list = g_unix_fd_list_new ();
|
|
|
|
fds = g_unix_fd_list_peek_fds (message->fd_list, &num_fds);
|
|
|
|
for (n = 0; n < num_fds; n++)
|
|
|
|
{
|
|
|
|
if (g_unix_fd_list_append (ret->fd_list,
|
|
|
|
fds[n],
|
|
|
|
error) == -1)
|
|
|
|
{
|
|
|
|
g_object_unref (ret);
|
|
|
|
ret = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* see https://bugzilla.gnome.org/show_bug.cgi?id=624546#c8 for why it's fine
|
|
|
|
* to just ref (as opposed to deep-copying) the GVariant instances
|
|
|
|
*/
|
|
|
|
ret->body = message->body != NULL ? g_variant_ref (message->body) : NULL;
|
|
|
|
g_hash_table_iter_init (&iter, message->headers);
|
|
|
|
while (g_hash_table_iter_next (&iter, &header_key, (gpointer) &header_value))
|
|
|
|
g_hash_table_insert (ret->headers, header_key, g_variant_ref (header_value));
|
|
|
|
|
2012-11-11 17:32:40 +01:00
|
|
|
#ifdef G_OS_UNIX
|
2010-09-09 17:37:14 +02:00
|
|
|
out:
|
2012-11-11 17:32:40 +01:00
|
|
|
#endif
|
2010-09-09 17:37:14 +02:00
|
|
|
return ret;
|
|
|
|
}
|