forked from enlightenment/efl
parent
f01726ab87
commit
5607a495c5
|
@ -26,7 +26,7 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#define ECORE_DBUS_MAJOR_PROTOCOL_VERSION 1
|
||||
#define ECORE_DBUS_MAJOR_PROTOCOL_VERSION 0x1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -21,6 +21,9 @@ Ecore_DBus.h
|
|||
|
||||
libecore_dbus_la_SOURCES = \
|
||||
ecore_dbus.c \
|
||||
ecore_dbus_marshal.c \
|
||||
ecore_dbus_unmarshal.c \
|
||||
ecore_dbus_utils.c \
|
||||
ecore_dbus_private.h
|
||||
|
||||
libecore_dbus_la_LIBADD = \
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
/*
|
||||
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "Ecore.h"
|
||||
#include "ecore_private.h"
|
||||
#include "Ecore_DBus.h"
|
||||
#include "Ecore_Con.h"
|
||||
#include "Ecore_DBus.h"
|
||||
#include "ecore_dbus_private.h"
|
||||
|
||||
/********************************************************************************/
|
||||
|
@ -51,78 +48,8 @@ EAPI int ECORE_DBUS_EVENT_SERVER_DATA = 0;
|
|||
|
||||
/* private function declaration */
|
||||
|
||||
/* length functions */
|
||||
static void _ecore_dbus_message_append_length(unsigned char **buf, unsigned int old_length, unsigned int size);
|
||||
static void _ecore_dbus_message_increase_length(unsigned char **buf, unsigned int new_length);
|
||||
/* padding functions */
|
||||
static void _ecore_dbus_message_padding(unsigned char **buf, unsigned int *old_length, int size);
|
||||
static void _ecore_dbus_message_padding_skip(unsigned int *old_length, int size);
|
||||
/* appending/reading functions */
|
||||
static void _ecore_dbus_message_append_nbytes(unsigned char *buf, unsigned char *data, unsigned int data_length);
|
||||
static void _ecore_dbus_message_append_byte(unsigned char *buf, unsigned char c);
|
||||
static void _ecore_dbus_message_append_uint32(unsigned char *buf, unsigned int i);
|
||||
static unsigned char _ecore_dbus_message_read_byte(unsigned char *buf);
|
||||
static unsigned int _ecore_dbus_message_read_uint32(unsigned char *buf);
|
||||
/* message functions */
|
||||
static Ecore_DBus_Message *_ecore_dbus_message_new(Ecore_DBus_Server *svr);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_new_field(Ecore_DBus_Data_Type type, unsigned int offset);
|
||||
static void _ecore_dbus_message_free(void *data, void *ev);
|
||||
/* marshal functions */
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_byte(unsigned char **buf, unsigned int *old_length, unsigned char c);
|
||||
/*
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_boolean(unsigned char **buf, unsigned int *old_length, uint32_t i);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_int16(unsigned char **buf, unsigned int *old_length, int16_t i);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_uint16(unsigned char **buf, unsigned int *old_length, uint16_t i);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_int32(unsigned char **buf, unsigned int *old_length, int32_t i);
|
||||
*/
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_uint32(unsigned char **buf, unsigned int *old_length, uint32_t i);
|
||||
/*
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_int64(unsigned char **buf, unsigned int *old_length, int64_t i);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_uint64(unsigned char **buf, unsigned int *old_length, uint64_t i);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_double(unsigned char **buf, unsigned int *old_length, double i);
|
||||
*/
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_string(unsigned char **buf, unsigned int *old_length, char *str);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_object_path(unsigned char **buf, unsigned int *old_length, char *str);
|
||||
/*
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_signature(unsigned char **buf, unsigned int *old_length, char *str);
|
||||
*/
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_array(unsigned char **msg, unsigned int *old_length, Ecore_DBus_Data_Type contained_type);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_struct_begin(unsigned char **msg, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_struct_end(unsigned char **msg, unsigned int *old_length);
|
||||
/*
|
||||
* FIXME: These aren't correct !
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_variant(unsigned char **msg, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_dict_entry(unsigned char **msg, unsigned int *old_length);
|
||||
*/
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_data(unsigned char **buf, unsigned int *old_length, Ecore_DBus_Data_Type type, void *data);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_custom_header(unsigned char **buf, unsigned int *old_length, unsigned int code, Ecore_DBus_Data_Type type, void *data);
|
||||
/* unmarshal functions */
|
||||
/*
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_byte(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_boolean(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_int16(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_uint16(unsigned char *buf, unsigned int *old_length);
|
||||
*/
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_int32(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_uint32(unsigned char *buf, unsigned int *old_length);
|
||||
/*
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_int64(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_uint64(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_double(unsigned char *buf, unsigned int *old_length);
|
||||
*/
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_string(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_object_path(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_signature(unsigned char *buf, unsigned int *old_length);
|
||||
/*
|
||||
* FIXME: These aren't correct!
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_array(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_variant(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_struct(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_dict_entry(unsigned char *buf, unsigned int *old_length);
|
||||
*/
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_data(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_custom_header(unsigned char *buf, unsigned int *old_length);
|
||||
static Ecore_DBus_Message *_ecore_dbus_message_unmarshal(Ecore_DBus_Server *svr, unsigned char *message);
|
||||
/* header functions */
|
||||
static void _ecore_dbus_message_common_header(Ecore_DBus_Message *msg, int type, int flags);
|
||||
static void *_ecore_dbus_field_get(unsigned char *buf, Ecore_DBus_Message_Field *f);
|
||||
|
@ -140,7 +67,6 @@ static Ecore_DBus_Message_Field *_ecore_dbus_message_print_field(Ecore_DBus_Mess
|
|||
static Ecore_DBus_Message_Field *_ecore_dbus_message_print_header_field(Ecore_DBus_Message_Field *f, unsigned char *buf);
|
||||
/*static void _ecore_dbus_message_print_fields(Ecore_DBus_Message_Field *f);*/
|
||||
/*static void _ecore_dbus_message_print_raw(unsigned char *msg, unsigned int msg_len);*/
|
||||
static int _ecore_dbus_alignment_get(Ecore_DBus_Data_Type type);
|
||||
|
||||
/* local variables */
|
||||
|
||||
|
@ -455,92 +381,9 @@ ecore_dbus_body_field_get(Ecore_DBus_Message *m, Ecore_DBus_Message_Field *mf,
|
|||
|
||||
/* private functions */
|
||||
|
||||
/* length functions */
|
||||
|
||||
static void
|
||||
_ecore_dbus_message_append_length(unsigned char **buf,
|
||||
unsigned int old_length, unsigned int size)
|
||||
{
|
||||
*buf = realloc(*buf, old_length + size);
|
||||
memset(*buf + old_length, 0, size);
|
||||
}
|
||||
|
||||
static void
|
||||
_ecore_dbus_message_increase_length(unsigned char **buf,
|
||||
unsigned int new_length)
|
||||
{
|
||||
*buf = realloc(*buf, new_length);
|
||||
}
|
||||
|
||||
/* padding functions */
|
||||
|
||||
static void
|
||||
_ecore_dbus_message_padding(unsigned char **buf, unsigned int *old_length, int size)
|
||||
{
|
||||
unsigned int padding;
|
||||
|
||||
padding = *old_length % size;
|
||||
if (padding != 0)
|
||||
{
|
||||
padding = size - padding;
|
||||
_ecore_dbus_message_append_length(buf, *old_length, padding);
|
||||
}
|
||||
*old_length += padding;
|
||||
}
|
||||
|
||||
static void
|
||||
_ecore_dbus_message_padding_skip(unsigned int *old_length, int size)
|
||||
{
|
||||
unsigned int padding;
|
||||
|
||||
padding = *old_length % size;
|
||||
if (padding != 0)
|
||||
*old_length += size - padding;
|
||||
return;
|
||||
}
|
||||
|
||||
/* appending/reading functions */
|
||||
|
||||
static void
|
||||
_ecore_dbus_message_append_nbytes(unsigned char *buf, unsigned char *data,
|
||||
unsigned int data_length)
|
||||
{
|
||||
memcpy(buf, data, data_length);
|
||||
}
|
||||
|
||||
static void
|
||||
_ecore_dbus_message_append_byte(unsigned char *buf, unsigned char c)
|
||||
{
|
||||
*buf = c;
|
||||
}
|
||||
|
||||
static void
|
||||
_ecore_dbus_message_append_uint32(unsigned char *buf, unsigned int i)
|
||||
{
|
||||
unsigned char *c;
|
||||
|
||||
c = (unsigned char *)&i;
|
||||
*(buf + 0) = *(c + 0);
|
||||
*(buf + 1) = *(c + 1);
|
||||
*(buf + 2) = *(c + 2);
|
||||
*(buf + 3) = *(c + 3);
|
||||
}
|
||||
|
||||
static unsigned char
|
||||
_ecore_dbus_message_read_byte(unsigned char *buf)
|
||||
{
|
||||
return *(unsigned char *)buf;
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
_ecore_dbus_message_read_uint32(unsigned char *buf)
|
||||
{
|
||||
return *(unsigned int *)buf;
|
||||
}
|
||||
|
||||
/* message functions */
|
||||
|
||||
static Ecore_DBus_Message *
|
||||
Ecore_DBus_Message *
|
||||
_ecore_dbus_message_new(Ecore_DBus_Server *svr)
|
||||
{
|
||||
Ecore_DBus_Message *msg;
|
||||
|
@ -560,7 +403,7 @@ _ecore_dbus_message_new(Ecore_DBus_Server *svr)
|
|||
return msg;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_new_field(Ecore_DBus_Data_Type type, unsigned int offset)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
@ -601,484 +444,6 @@ _ecore_dbus_message_free(void *data, void *ev)
|
|||
free(msg);
|
||||
}
|
||||
|
||||
/* marshal functions */
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_byte(unsigned char **buf, unsigned int *old_length,
|
||||
unsigned char c)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length + 1, old_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_BYTE);
|
||||
*old_length += 1;
|
||||
/* increase the length + 1, old_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append c at cur_length */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, c);
|
||||
/* create field */
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_BYTE, *old_length);
|
||||
*old_length += 1;
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_uint32(unsigned char **buf,
|
||||
unsigned int *old_length,
|
||||
unsigned int i)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length + 1, old_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_UINT32);
|
||||
*old_length += 1;
|
||||
_ecore_dbus_message_padding(buf, old_length, 4);
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 4);
|
||||
_ecore_dbus_message_append_uint32(*buf + *old_length, i);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_UINT32, *old_length);
|
||||
*old_length += 4;
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_object_path(unsigned char **buf, unsigned int *old_length,
|
||||
char *str)
|
||||
{
|
||||
int str_len;
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length + 1, old_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_OBJECT_PATH);
|
||||
*old_length += 1;
|
||||
|
||||
str_len = strlen(str);
|
||||
_ecore_dbus_message_padding(buf, old_length, 4);
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_OBJECT_PATH, *old_length);
|
||||
_ecore_dbus_message_append_uint32(*buf + *old_length, str_len);
|
||||
*old_length += 4;
|
||||
/* + 1 for \0 */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + str_len + 1);
|
||||
_ecore_dbus_message_append_nbytes(*buf + *old_length, (unsigned char *)str, str_len + 1);
|
||||
*old_length += str_len + 1;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_string(unsigned char **buf,
|
||||
unsigned int *old_length, char *str)
|
||||
{
|
||||
int str_len;
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length + 1, new_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_STRING);
|
||||
*old_length += 1;
|
||||
|
||||
str_len = strlen(str);
|
||||
_ecore_dbus_message_padding(buf, old_length, 4);
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRING, *old_length);
|
||||
_ecore_dbus_message_append_uint32(*buf + *old_length, str_len);
|
||||
*old_length += 4;
|
||||
/* + 1 for \0 */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + str_len + 1);
|
||||
_ecore_dbus_message_append_nbytes(*buf + *old_length, (unsigned char *)str, str_len + 1);
|
||||
*old_length += str_len + 1;
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_array(unsigned char **buf, unsigned int *old_length,
|
||||
Ecore_DBus_Data_Type contained_type)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length with 1 + contained length */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_ARRAY);
|
||||
*old_length += 1;
|
||||
|
||||
/* for the array length value */
|
||||
_ecore_dbus_message_padding(buf, old_length, 4);
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_ARRAY, *old_length);
|
||||
*old_length += 4;
|
||||
|
||||
/* pad for contained type */
|
||||
_ecore_dbus_message_padding(buf, old_length, _ecore_dbus_alignment_get(contained_type));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_struct_begin(unsigned char **buf, unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length with 1 */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_STRUCT_BEGIN);
|
||||
*old_length += 1;
|
||||
|
||||
/* padding */
|
||||
_ecore_dbus_message_padding(buf, old_length, 8);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRUCT, *old_length);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_struct_end(unsigned char **buf, unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length with 1 */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_STRUCT_END);
|
||||
*old_length += 1;
|
||||
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRUCT, *old_length);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_data(unsigned char **buf, unsigned int *old_length,
|
||||
Ecore_DBus_Data_Type type, void *data)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f = NULL;
|
||||
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the signature length */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, 1);
|
||||
*old_length += 1;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ECORE_DBUS_DATA_TYPE_UINT32:
|
||||
f = _ecore_dbus_message_marshal_uint32(buf, old_length,
|
||||
*(unsigned int *)data);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_STRING:
|
||||
f = _ecore_dbus_message_marshal_string(buf, old_length,
|
||||
(char *)data);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
|
||||
f = _ecore_dbus_message_marshal_object_path(buf, old_length,
|
||||
(char *)data);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_INVALID:
|
||||
case ECORE_DBUS_DATA_TYPE_BYTE:
|
||||
case ECORE_DBUS_DATA_TYPE_BOOLEAN:
|
||||
case ECORE_DBUS_DATA_TYPE_INT16:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT16:
|
||||
case ECORE_DBUS_DATA_TYPE_INT32:
|
||||
case ECORE_DBUS_DATA_TYPE_INT64:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT64:
|
||||
case ECORE_DBUS_DATA_TYPE_DOUBLE:
|
||||
case ECORE_DBUS_DATA_TYPE_SIGNATURE:
|
||||
case ECORE_DBUS_DATA_TYPE_ARRAY:
|
||||
case ECORE_DBUS_DATA_TYPE_VARIANT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_END:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_END:
|
||||
#if 0
|
||||
default:
|
||||
#endif
|
||||
printf("[ecore_dbus] unknown/unhandled data type %c\n", type);
|
||||
break;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_custom_header(unsigned char **buf,
|
||||
unsigned int *old_length,
|
||||
unsigned int code,
|
||||
Ecore_DBus_Data_Type type, void *data)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
_ecore_dbus_message_padding(buf, old_length, 8);
|
||||
/* increase the length + 1, old_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append header field name at cur_length */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, code);
|
||||
*old_length += 1;
|
||||
|
||||
/* marshal header field data */
|
||||
f = _ecore_dbus_message_marshal_data(buf, old_length, type, data);
|
||||
f->hfield = code;
|
||||
return f;
|
||||
}
|
||||
|
||||
/* unmarshal functions */
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_int32(unsigned char *buf,
|
||||
unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
_ecore_dbus_message_padding_skip(old_length, 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_INT32, *old_length);
|
||||
*old_length += 4;
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_uint32(unsigned char *buf,
|
||||
unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
_ecore_dbus_message_padding_skip(old_length, 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_UINT32, *old_length);
|
||||
*old_length += 4;
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_string(unsigned char *buf,
|
||||
unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
unsigned int str_len;
|
||||
|
||||
_ecore_dbus_message_padding_skip(old_length, 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRING, *old_length);
|
||||
str_len = _ecore_dbus_message_read_uint32(buf + *old_length);
|
||||
*old_length += 4;
|
||||
*old_length += str_len + 1;
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_object_path(unsigned char *buf, unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
unsigned int str_len;
|
||||
|
||||
_ecore_dbus_message_padding_skip(old_length, 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_OBJECT_PATH,
|
||||
*old_length);
|
||||
str_len = _ecore_dbus_message_read_uint32(buf + *old_length);
|
||||
*old_length += 4;
|
||||
*old_length += str_len + 1;
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_signature(unsigned char *buf,
|
||||
unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
unsigned int str_len;
|
||||
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_SIGNATURE, *old_length);
|
||||
str_len = _ecore_dbus_message_read_byte(buf + *old_length);
|
||||
*old_length += 1;
|
||||
*old_length += str_len + 1;
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_data(unsigned char *buf, unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f = NULL;
|
||||
Ecore_DBus_Data_Type type;
|
||||
|
||||
type = _ecore_dbus_message_read_byte(buf + *old_length);
|
||||
*old_length += 1;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ECORE_DBUS_DATA_TYPE_INT32:
|
||||
f = _ecore_dbus_message_unmarshal_int32(buf, old_length);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_UINT32:
|
||||
f = _ecore_dbus_message_unmarshal_uint32(buf, old_length);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_STRING:
|
||||
f = _ecore_dbus_message_unmarshal_string(buf, old_length);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
|
||||
f = _ecore_dbus_message_unmarshal_object_path(buf, old_length);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_SIGNATURE:
|
||||
f = _ecore_dbus_message_unmarshal_signature(buf, old_length);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_INVALID:
|
||||
case ECORE_DBUS_DATA_TYPE_BYTE:
|
||||
case ECORE_DBUS_DATA_TYPE_BOOLEAN:
|
||||
case ECORE_DBUS_DATA_TYPE_INT16:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT16:
|
||||
case ECORE_DBUS_DATA_TYPE_INT64:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT64:
|
||||
case ECORE_DBUS_DATA_TYPE_DOUBLE:
|
||||
case ECORE_DBUS_DATA_TYPE_ARRAY:
|
||||
case ECORE_DBUS_DATA_TYPE_VARIANT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_END:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_END:
|
||||
#if 0
|
||||
default:
|
||||
#endif
|
||||
printf("[ecore_dbus] unknown/unhandled data type %c\n", type);
|
||||
break;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_custom_header(unsigned char *buf,
|
||||
unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
unsigned int code, length;
|
||||
|
||||
_ecore_dbus_message_padding_skip(old_length, 8);
|
||||
/* get header field name at cur_length */
|
||||
code = _ecore_dbus_message_read_byte(buf + *old_length);
|
||||
*old_length += 1;
|
||||
/* Read signature length */
|
||||
length = _ecore_dbus_message_read_byte(buf + *old_length);
|
||||
if (length != 1)
|
||||
fprintf(stderr, "[ecore_dbus]: Wrong signature length in header\n");
|
||||
*old_length += 1;
|
||||
|
||||
/* unmarshal header field data */
|
||||
f = _ecore_dbus_message_unmarshal_data(buf, old_length);
|
||||
if (f) f->hfield = code;
|
||||
return f;
|
||||
}
|
||||
|
||||
static Ecore_DBus_Message *
|
||||
_ecore_dbus_message_unmarshal(Ecore_DBus_Server *svr, unsigned char *message)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f, *sig;
|
||||
|
||||
/* init */
|
||||
Ecore_DBus_Message *msg = _ecore_dbus_message_new(svr);
|
||||
|
||||
printf("[ecore_dbus] unmarshaling\n");
|
||||
|
||||
/* message header */
|
||||
|
||||
/* common fields */
|
||||
msg->byte_order = *(message + 0);
|
||||
msg->type = *(message + 1);
|
||||
msg->flags = *(message + 2);
|
||||
msg->protocol = *(message + 3);
|
||||
msg->blength = *(unsigned int *)(message + 4);
|
||||
msg->serial = *(unsigned int *)(message + 8);
|
||||
msg->hlength = *(unsigned int *)(message + 12) + 16;
|
||||
_ecore_dbus_message_padding_skip(&(msg->hlength), 8);
|
||||
if (msg->type == ECORE_DBUS_MESSAGE_TYPE_INVALID)
|
||||
{
|
||||
printf("[ecore_dbus] message type invalid\n");
|
||||
return NULL;
|
||||
}
|
||||
msg->hpos += 16;
|
||||
/* memcpy the header part */
|
||||
_ecore_dbus_message_increase_length(&msg->header, msg->hlength);
|
||||
_ecore_dbus_message_append_nbytes(msg->header, message, msg->hlength);
|
||||
/* custom fields */
|
||||
sig = NULL;
|
||||
while ((msg->hpos + 8 - (msg->hpos % 8)) < msg->hlength)
|
||||
{
|
||||
f = _ecore_dbus_message_unmarshal_custom_header(message, &msg->hpos);
|
||||
if (f)
|
||||
{
|
||||
msg->header_fields = _ecore_list2_append(msg->header_fields, f);
|
||||
if (f->type == ECORE_DBUS_DATA_TYPE_SIGNATURE)
|
||||
sig = f;
|
||||
}
|
||||
}
|
||||
msg->hpos = msg->hlength;
|
||||
message += msg->hlength;
|
||||
|
||||
/* message body */
|
||||
if (sig)
|
||||
{
|
||||
unsigned char *s;
|
||||
Ecore_DBus_Data_Type type;
|
||||
|
||||
_ecore_dbus_message_increase_length(&msg->body, msg->blength);
|
||||
_ecore_dbus_message_append_nbytes(msg->body, message, msg->blength);
|
||||
|
||||
s = msg->header + sig->offset + 2;
|
||||
while (*s)
|
||||
{
|
||||
f = NULL;
|
||||
printf("body: %c\n", *s);
|
||||
type = *s;
|
||||
switch (type)
|
||||
{
|
||||
case ECORE_DBUS_DATA_TYPE_INT32:
|
||||
f = _ecore_dbus_message_unmarshal_int32(msg->body, &(msg->bpos));
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_UINT32:
|
||||
f = _ecore_dbus_message_unmarshal_uint32(msg->body, &(msg->bpos));
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_STRING:
|
||||
f = _ecore_dbus_message_unmarshal_string(msg->body, &(msg->bpos));
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
|
||||
f = _ecore_dbus_message_unmarshal_object_path(msg->body, &(msg->bpos));
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_SIGNATURE:
|
||||
f = _ecore_dbus_message_unmarshal_signature(msg->body, &(msg->bpos));
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_INVALID:
|
||||
case ECORE_DBUS_DATA_TYPE_BYTE:
|
||||
case ECORE_DBUS_DATA_TYPE_BOOLEAN:
|
||||
case ECORE_DBUS_DATA_TYPE_INT16:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT16:
|
||||
case ECORE_DBUS_DATA_TYPE_INT64:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT64:
|
||||
case ECORE_DBUS_DATA_TYPE_DOUBLE:
|
||||
case ECORE_DBUS_DATA_TYPE_ARRAY:
|
||||
case ECORE_DBUS_DATA_TYPE_VARIANT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_END:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_END:
|
||||
#if 0
|
||||
default:
|
||||
#endif
|
||||
printf("[ecore_dbus] unknown/unhandled data type %c\n", type);
|
||||
break;
|
||||
}
|
||||
if (f)
|
||||
msg->body_fields = _ecore_list2_append(msg->body_fields, f);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
/* header functions */
|
||||
|
||||
static void
|
||||
|
@ -1093,7 +458,7 @@ _ecore_dbus_message_common_header(Ecore_DBus_Message *msg, int type, int flags)
|
|||
/* flags (1) 0x1 = no reply expected, 0x2 auto activiation */
|
||||
msg->header[2] = msg->flags = 0x0;
|
||||
/* protocol (1) */
|
||||
msg->header[3] = msg->protocol = 0x1;
|
||||
msg->header[3] = msg->protocol = ECORE_DBUS_MAJOR_PROTOCOL_VERSION;
|
||||
/* autoincrement the client_serial (0 is invalid) */
|
||||
msg->ref_server->cnt_msg++;
|
||||
|
||||
|
@ -1449,35 +814,3 @@ _ecore_dbus_message_print_raw(unsigned char *msg, unsigned int msg_len)
|
|||
printf("[ecore_dbus] end raw message\n");
|
||||
}
|
||||
*/
|
||||
|
||||
static int
|
||||
_ecore_dbus_alignment_get(Ecore_DBus_Data_Type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ECORE_DBUS_DATA_TYPE_BYTE:
|
||||
case ECORE_DBUS_DATA_TYPE_SIGNATURE:
|
||||
case ECORE_DBUS_DATA_TYPE_VARIANT:
|
||||
return 1;
|
||||
case ECORE_DBUS_DATA_TYPE_INT16:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT16:
|
||||
return 2;
|
||||
case ECORE_DBUS_DATA_TYPE_BOOLEAN:
|
||||
case ECORE_DBUS_DATA_TYPE_INT32:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT32:
|
||||
case ECORE_DBUS_DATA_TYPE_STRING:
|
||||
case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
|
||||
case ECORE_DBUS_DATA_TYPE_ARRAY:
|
||||
return 4;
|
||||
case ECORE_DBUS_DATA_TYPE_INT64:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT64:
|
||||
case ECORE_DBUS_DATA_TYPE_DOUBLE:
|
||||
return 8;
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
|
||||
return 8;
|
||||
default:
|
||||
fprintf(stderr, "Ecore_DBus: Alignment requested for invalid data type!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,267 @@
|
|||
/*
|
||||
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
||||
*/
|
||||
|
||||
#include "ecore_private.h"
|
||||
#include "Ecore_Con.h"
|
||||
#include "Ecore_DBus.h"
|
||||
#include "ecore_dbus_private.h"
|
||||
|
||||
static int _ecore_dbus_alignment_get(Ecore_DBus_Data_Type type);
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_byte(unsigned char **buf, unsigned int *old_length,
|
||||
unsigned char c)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length + 1, old_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_BYTE);
|
||||
*old_length += 1;
|
||||
/* increase the length + 1, old_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append c at cur_length */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, c);
|
||||
/* create field */
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_BYTE, *old_length);
|
||||
*old_length += 1;
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_uint32(unsigned char **buf,
|
||||
unsigned int *old_length,
|
||||
unsigned int i)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length + 1, old_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_UINT32);
|
||||
*old_length += 1;
|
||||
_ecore_dbus_message_padding(buf, old_length, 4);
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 4);
|
||||
_ecore_dbus_message_append_uint32(*buf + *old_length, i);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_UINT32, *old_length);
|
||||
*old_length += 4;
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_object_path(unsigned char **buf, unsigned int *old_length,
|
||||
char *str)
|
||||
{
|
||||
int str_len;
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length + 1, old_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_OBJECT_PATH);
|
||||
*old_length += 1;
|
||||
|
||||
str_len = strlen(str);
|
||||
_ecore_dbus_message_padding(buf, old_length, 4);
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_OBJECT_PATH, *old_length);
|
||||
_ecore_dbus_message_append_uint32(*buf + *old_length, str_len);
|
||||
*old_length += 4;
|
||||
/* + 1 for \0 */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + str_len + 1);
|
||||
_ecore_dbus_message_append_nbytes(*buf + *old_length, (unsigned char *)str, str_len + 1);
|
||||
*old_length += str_len + 1;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_string(unsigned char **buf,
|
||||
unsigned int *old_length, char *str)
|
||||
{
|
||||
int str_len;
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length + 1, new_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_STRING);
|
||||
*old_length += 1;
|
||||
|
||||
str_len = strlen(str);
|
||||
_ecore_dbus_message_padding(buf, old_length, 4);
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRING, *old_length);
|
||||
_ecore_dbus_message_append_uint32(*buf + *old_length, str_len);
|
||||
*old_length += 4;
|
||||
/* + 1 for \0 */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + str_len + 1);
|
||||
_ecore_dbus_message_append_nbytes(*buf + *old_length, (unsigned char *)str, str_len + 1);
|
||||
*old_length += str_len + 1;
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_array(unsigned char **buf, unsigned int *old_length,
|
||||
Ecore_DBus_Data_Type contained_type)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length with 1 + contained length */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_ARRAY);
|
||||
*old_length += 1;
|
||||
|
||||
/* for the array length value */
|
||||
_ecore_dbus_message_padding(buf, old_length, 4);
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_ARRAY, *old_length);
|
||||
*old_length += 4;
|
||||
|
||||
/* pad for contained type */
|
||||
_ecore_dbus_message_padding(buf, old_length, _ecore_dbus_alignment_get(contained_type));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_struct_begin(unsigned char **buf, unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length with 1 */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_STRUCT_BEGIN);
|
||||
*old_length += 1;
|
||||
|
||||
/* padding */
|
||||
_ecore_dbus_message_padding(buf, old_length, 8);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRUCT, *old_length);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_struct_end(unsigned char **buf, unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
/* increase the length with 1 */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the data type */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_STRUCT_END);
|
||||
*old_length += 1;
|
||||
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRUCT, *old_length);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_data(unsigned char **buf, unsigned int *old_length,
|
||||
Ecore_DBus_Data_Type type, void *data)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f = NULL;
|
||||
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append the signature length */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, 1);
|
||||
*old_length += 1;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ECORE_DBUS_DATA_TYPE_UINT32:
|
||||
f = _ecore_dbus_message_marshal_uint32(buf, old_length,
|
||||
*(unsigned int *)data);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_STRING:
|
||||
f = _ecore_dbus_message_marshal_string(buf, old_length,
|
||||
(char *)data);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
|
||||
f = _ecore_dbus_message_marshal_object_path(buf, old_length,
|
||||
(char *)data);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_INVALID:
|
||||
case ECORE_DBUS_DATA_TYPE_BYTE:
|
||||
case ECORE_DBUS_DATA_TYPE_BOOLEAN:
|
||||
case ECORE_DBUS_DATA_TYPE_INT16:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT16:
|
||||
case ECORE_DBUS_DATA_TYPE_INT32:
|
||||
case ECORE_DBUS_DATA_TYPE_INT64:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT64:
|
||||
case ECORE_DBUS_DATA_TYPE_DOUBLE:
|
||||
case ECORE_DBUS_DATA_TYPE_SIGNATURE:
|
||||
case ECORE_DBUS_DATA_TYPE_ARRAY:
|
||||
case ECORE_DBUS_DATA_TYPE_VARIANT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_END:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_END:
|
||||
#if 0
|
||||
default:
|
||||
#endif
|
||||
printf("[ecore_dbus] unknown/unhandled data type %c\n", type);
|
||||
break;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_marshal_custom_header(unsigned char **buf,
|
||||
unsigned int *old_length,
|
||||
unsigned int code,
|
||||
Ecore_DBus_Data_Type type, void *data)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
_ecore_dbus_message_padding(buf, old_length, 8);
|
||||
/* increase the length + 1, old_length changed */
|
||||
_ecore_dbus_message_increase_length(buf, *old_length + 1);
|
||||
/* append header field name at cur_length */
|
||||
_ecore_dbus_message_append_byte(*buf + *old_length, code);
|
||||
*old_length += 1;
|
||||
|
||||
/* marshal header field data */
|
||||
f = _ecore_dbus_message_marshal_data(buf, old_length, type, data);
|
||||
f->hfield = code;
|
||||
return f;
|
||||
}
|
||||
|
||||
static int
|
||||
_ecore_dbus_alignment_get(Ecore_DBus_Data_Type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ECORE_DBUS_DATA_TYPE_BYTE:
|
||||
case ECORE_DBUS_DATA_TYPE_SIGNATURE:
|
||||
case ECORE_DBUS_DATA_TYPE_VARIANT:
|
||||
return 1;
|
||||
case ECORE_DBUS_DATA_TYPE_INT16:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT16:
|
||||
return 2;
|
||||
case ECORE_DBUS_DATA_TYPE_BOOLEAN:
|
||||
case ECORE_DBUS_DATA_TYPE_INT32:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT32:
|
||||
case ECORE_DBUS_DATA_TYPE_STRING:
|
||||
case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
|
||||
case ECORE_DBUS_DATA_TYPE_ARRAY:
|
||||
return 4;
|
||||
case ECORE_DBUS_DATA_TYPE_INT64:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT64:
|
||||
case ECORE_DBUS_DATA_TYPE_DOUBLE:
|
||||
return 8;
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
|
||||
return 8;
|
||||
default:
|
||||
fprintf(stderr, "Ecore_DBus: Alignment requested for invalid data type!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -73,6 +73,76 @@ struct _Ecore_DBus_Auth
|
|||
Ecore_DBus_Auth_Transaction transactions[5];
|
||||
};
|
||||
|
||||
/* ecore_dbus_utils.c */
|
||||
void _ecore_dbus_message_append_length(unsigned char **buf, unsigned int old_length, unsigned int size);
|
||||
void _ecore_dbus_message_increase_length(unsigned char **buf, unsigned int new_length);
|
||||
void _ecore_dbus_message_padding(unsigned char **buf, unsigned int *old_length, int size);
|
||||
void _ecore_dbus_message_padding_skip(unsigned int *old_length, int size);
|
||||
void _ecore_dbus_message_append_nbytes(unsigned char *buf, unsigned char *data, unsigned int data_length);
|
||||
void _ecore_dbus_message_append_byte(unsigned char *buf, unsigned char c);
|
||||
void _ecore_dbus_message_append_uint32(unsigned char *buf, unsigned int i);
|
||||
unsigned char _ecore_dbus_message_read_byte(unsigned char *buf);
|
||||
unsigned int _ecore_dbus_message_read_uint32(unsigned char *buf);
|
||||
|
||||
/* ecore_dbus.c */
|
||||
Ecore_DBus_Message *_ecore_dbus_message_new(Ecore_DBus_Server *svr);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_new_field(Ecore_DBus_Data_Type type, unsigned int offset);
|
||||
/* ecore_dbus_marshal.c */
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_byte(unsigned char **buf, unsigned int *old_length, unsigned char c);
|
||||
/*
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_boolean(unsigned char **buf, unsigned int *old_length, uint32_t i);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_int16(unsigned char **buf, unsigned int *old_length, int16_t i);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_uint16(unsigned char **buf, unsigned int *old_length, uint16_t i);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_int32(unsigned char **buf, unsigned int *old_length, int32_t i);
|
||||
*/
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_uint32(unsigned char **buf, unsigned int *old_length, uint32_t i);
|
||||
/*
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_int64(unsigned char **buf, unsigned int *old_length, int64_t i);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_uint64(unsigned char **buf, unsigned int *old_length, uint64_t i);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_double(unsigned char **buf, unsigned int *old_length, double i);
|
||||
*/
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_string(unsigned char **buf, unsigned int *old_length, char *str);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_object_path(unsigned char **buf, unsigned int *old_length, char *str);
|
||||
/*
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_signature(unsigned char **buf, unsigned int *old_length, char *str);
|
||||
*/
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_array(unsigned char **msg, unsigned int *old_length, Ecore_DBus_Data_Type contained_type);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_struct_begin(unsigned char **msg, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_struct_end(unsigned char **msg, unsigned int *old_length);
|
||||
/*
|
||||
* FIXME: These aren't correct !
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_variant(unsigned char **msg, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_dict_entry(unsigned char **msg, unsigned int *old_length);
|
||||
*/
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_data(unsigned char **buf, unsigned int *old_length, Ecore_DBus_Data_Type type, void *data);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_custom_header(unsigned char **buf, unsigned int *old_length, unsigned int code, Ecore_DBus_Data_Type type, void *data);
|
||||
/* ecore_dbus_unmarshal.c */
|
||||
/*
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_byte(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_boolean(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_int16(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_uint16(unsigned char *buf, unsigned int *old_length);
|
||||
*/
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_int32(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_uint32(unsigned char *buf, unsigned int *old_length);
|
||||
/*
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_int64(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_uint64(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_double(unsigned char *buf, unsigned int *old_length);
|
||||
*/
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_string(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_object_path(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_signature(unsigned char *buf, unsigned int *old_length);
|
||||
/*
|
||||
* FIXME: These aren't correct!
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_array(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_variant(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_struct(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_dict_entry(unsigned char *buf, unsigned int *old_length);
|
||||
*/
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_data(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_custom_header(unsigned char *buf, unsigned int *old_length);
|
||||
Ecore_DBus_Message *_ecore_dbus_message_unmarshal(Ecore_DBus_Server *svr, unsigned char *message);
|
||||
|
||||
/* Errors */
|
||||
#define DBUS_ERROR_FAILED "org.freedesktop.DBus.Error.Failed"
|
||||
|
|
|
@ -0,0 +1,257 @@
|
|||
/*
|
||||
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
||||
*/
|
||||
|
||||
#include "ecore_private.h"
|
||||
#include "Ecore_Con.h"
|
||||
#include "Ecore_DBus.h"
|
||||
#include "ecore_dbus_private.h"
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_int32(unsigned char *buf,
|
||||
unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
_ecore_dbus_message_padding_skip(old_length, 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_INT32, *old_length);
|
||||
*old_length += 4;
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_uint32(unsigned char *buf,
|
||||
unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
|
||||
_ecore_dbus_message_padding_skip(old_length, 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_UINT32, *old_length);
|
||||
*old_length += 4;
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_string(unsigned char *buf,
|
||||
unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
unsigned int str_len;
|
||||
|
||||
_ecore_dbus_message_padding_skip(old_length, 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRING, *old_length);
|
||||
str_len = _ecore_dbus_message_read_uint32(buf + *old_length);
|
||||
*old_length += 4;
|
||||
*old_length += str_len + 1;
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_object_path(unsigned char *buf, unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
unsigned int str_len;
|
||||
|
||||
_ecore_dbus_message_padding_skip(old_length, 4);
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_OBJECT_PATH,
|
||||
*old_length);
|
||||
str_len = _ecore_dbus_message_read_uint32(buf + *old_length);
|
||||
*old_length += 4;
|
||||
*old_length += str_len + 1;
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_signature(unsigned char *buf,
|
||||
unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
unsigned int str_len;
|
||||
|
||||
f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_SIGNATURE, *old_length);
|
||||
str_len = _ecore_dbus_message_read_byte(buf + *old_length);
|
||||
*old_length += 1;
|
||||
*old_length += str_len + 1;
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_data(unsigned char *buf, unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f = NULL;
|
||||
Ecore_DBus_Data_Type type;
|
||||
|
||||
type = _ecore_dbus_message_read_byte(buf + *old_length);
|
||||
*old_length += 1;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ECORE_DBUS_DATA_TYPE_INT32:
|
||||
f = _ecore_dbus_message_unmarshal_int32(buf, old_length);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_UINT32:
|
||||
f = _ecore_dbus_message_unmarshal_uint32(buf, old_length);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_STRING:
|
||||
f = _ecore_dbus_message_unmarshal_string(buf, old_length);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
|
||||
f = _ecore_dbus_message_unmarshal_object_path(buf, old_length);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_SIGNATURE:
|
||||
f = _ecore_dbus_message_unmarshal_signature(buf, old_length);
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_INVALID:
|
||||
case ECORE_DBUS_DATA_TYPE_BYTE:
|
||||
case ECORE_DBUS_DATA_TYPE_BOOLEAN:
|
||||
case ECORE_DBUS_DATA_TYPE_INT16:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT16:
|
||||
case ECORE_DBUS_DATA_TYPE_INT64:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT64:
|
||||
case ECORE_DBUS_DATA_TYPE_DOUBLE:
|
||||
case ECORE_DBUS_DATA_TYPE_ARRAY:
|
||||
case ECORE_DBUS_DATA_TYPE_VARIANT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_END:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_END:
|
||||
#if 0
|
||||
default:
|
||||
#endif
|
||||
printf("[ecore_dbus] unknown/unhandled data type %c\n", type);
|
||||
break;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message_Field *
|
||||
_ecore_dbus_message_unmarshal_custom_header(unsigned char *buf,
|
||||
unsigned int *old_length)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f;
|
||||
unsigned int code, length;
|
||||
|
||||
_ecore_dbus_message_padding_skip(old_length, 8);
|
||||
/* get header field name at cur_length */
|
||||
code = _ecore_dbus_message_read_byte(buf + *old_length);
|
||||
*old_length += 1;
|
||||
/* Read signature length */
|
||||
length = _ecore_dbus_message_read_byte(buf + *old_length);
|
||||
if (length != 1)
|
||||
fprintf(stderr, "[ecore_dbus]: Wrong signature length in header\n");
|
||||
*old_length += 1;
|
||||
|
||||
/* unmarshal header field data */
|
||||
f = _ecore_dbus_message_unmarshal_data(buf, old_length);
|
||||
if (f) f->hfield = code;
|
||||
return f;
|
||||
}
|
||||
|
||||
Ecore_DBus_Message *
|
||||
_ecore_dbus_message_unmarshal(Ecore_DBus_Server *svr, unsigned char *message)
|
||||
{
|
||||
Ecore_DBus_Message_Field *f, *sig;
|
||||
|
||||
/* init */
|
||||
Ecore_DBus_Message *msg = _ecore_dbus_message_new(svr);
|
||||
|
||||
printf("[ecore_dbus] unmarshaling\n");
|
||||
|
||||
/* message header */
|
||||
|
||||
/* common fields */
|
||||
msg->byte_order = *(message + 0);
|
||||
msg->type = *(message + 1);
|
||||
msg->flags = *(message + 2);
|
||||
msg->protocol = *(message + 3);
|
||||
msg->blength = *(unsigned int *)(message + 4);
|
||||
msg->serial = *(unsigned int *)(message + 8);
|
||||
msg->hlength = *(unsigned int *)(message + 12) + 16;
|
||||
_ecore_dbus_message_padding_skip(&(msg->hlength), 8);
|
||||
if (msg->type == ECORE_DBUS_MESSAGE_TYPE_INVALID)
|
||||
{
|
||||
printf("[ecore_dbus] message type invalid\n");
|
||||
return NULL;
|
||||
}
|
||||
msg->hpos += 16;
|
||||
/* memcpy the header part */
|
||||
_ecore_dbus_message_increase_length(&msg->header, msg->hlength);
|
||||
_ecore_dbus_message_append_nbytes(msg->header, message, msg->hlength);
|
||||
/* custom fields */
|
||||
sig = NULL;
|
||||
while ((msg->hpos + 8 - (msg->hpos % 8)) < msg->hlength)
|
||||
{
|
||||
f = _ecore_dbus_message_unmarshal_custom_header(message, &msg->hpos);
|
||||
if (f)
|
||||
{
|
||||
msg->header_fields = _ecore_list2_append(msg->header_fields, f);
|
||||
if (f->type == ECORE_DBUS_DATA_TYPE_SIGNATURE)
|
||||
sig = f;
|
||||
}
|
||||
}
|
||||
msg->hpos = msg->hlength;
|
||||
message += msg->hlength;
|
||||
|
||||
/* message body */
|
||||
if (sig)
|
||||
{
|
||||
unsigned char *s;
|
||||
Ecore_DBus_Data_Type type;
|
||||
|
||||
_ecore_dbus_message_increase_length(&msg->body, msg->blength);
|
||||
_ecore_dbus_message_append_nbytes(msg->body, message, msg->blength);
|
||||
|
||||
s = msg->header + sig->offset + 2;
|
||||
while (*s)
|
||||
{
|
||||
f = NULL;
|
||||
printf("body: %c\n", *s);
|
||||
type = *s;
|
||||
switch (type)
|
||||
{
|
||||
case ECORE_DBUS_DATA_TYPE_INT32:
|
||||
f = _ecore_dbus_message_unmarshal_int32(msg->body, &(msg->bpos));
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_UINT32:
|
||||
f = _ecore_dbus_message_unmarshal_uint32(msg->body, &(msg->bpos));
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_STRING:
|
||||
f = _ecore_dbus_message_unmarshal_string(msg->body, &(msg->bpos));
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
|
||||
f = _ecore_dbus_message_unmarshal_object_path(msg->body, &(msg->bpos));
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_SIGNATURE:
|
||||
f = _ecore_dbus_message_unmarshal_signature(msg->body, &(msg->bpos));
|
||||
break;
|
||||
case ECORE_DBUS_DATA_TYPE_INVALID:
|
||||
case ECORE_DBUS_DATA_TYPE_BYTE:
|
||||
case ECORE_DBUS_DATA_TYPE_BOOLEAN:
|
||||
case ECORE_DBUS_DATA_TYPE_INT16:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT16:
|
||||
case ECORE_DBUS_DATA_TYPE_INT64:
|
||||
case ECORE_DBUS_DATA_TYPE_UINT64:
|
||||
case ECORE_DBUS_DATA_TYPE_DOUBLE:
|
||||
case ECORE_DBUS_DATA_TYPE_ARRAY:
|
||||
case ECORE_DBUS_DATA_TYPE_VARIANT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_STRUCT_END:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_BEGIN:
|
||||
case ECORE_DBUS_DATA_TYPE_DICT_ENTRY_END:
|
||||
#if 0
|
||||
default:
|
||||
#endif
|
||||
printf("[ecore_dbus] unknown/unhandled data type %c\n", type);
|
||||
break;
|
||||
}
|
||||
if (f)
|
||||
msg->body_fields = _ecore_list2_append(msg->body_fields, f);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/* length functions */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
_ecore_dbus_message_append_length(unsigned char **buf,
|
||||
unsigned int old_length, unsigned int size)
|
||||
{
|
||||
*buf = realloc(*buf, old_length + size);
|
||||
memset(*buf + old_length, 0, size);
|
||||
}
|
||||
|
||||
void
|
||||
_ecore_dbus_message_increase_length(unsigned char **buf,
|
||||
unsigned int new_length)
|
||||
{
|
||||
*buf = realloc(*buf, new_length);
|
||||
}
|
||||
|
||||
/* padding functions */
|
||||
|
||||
void
|
||||
_ecore_dbus_message_padding(unsigned char **buf, unsigned int *old_length, int size)
|
||||
{
|
||||
unsigned int padding;
|
||||
|
||||
padding = *old_length % size;
|
||||
if (padding != 0)
|
||||
{
|
||||
padding = size - padding;
|
||||
_ecore_dbus_message_append_length(buf, *old_length, padding);
|
||||
}
|
||||
*old_length += padding;
|
||||
}
|
||||
|
||||
void
|
||||
_ecore_dbus_message_padding_skip(unsigned int *old_length, int size)
|
||||
{
|
||||
unsigned int padding;
|
||||
|
||||
padding = *old_length % size;
|
||||
if (padding != 0)
|
||||
*old_length += size - padding;
|
||||
return;
|
||||
}
|
||||
|
||||
/* appending/reading functions */
|
||||
|
||||
void
|
||||
_ecore_dbus_message_append_nbytes(unsigned char *buf, unsigned char *data,
|
||||
unsigned int data_length)
|
||||
{
|
||||
memcpy(buf, data, data_length);
|
||||
}
|
||||
|
||||
void
|
||||
_ecore_dbus_message_append_byte(unsigned char *buf, unsigned char c)
|
||||
{
|
||||
*buf = c;
|
||||
}
|
||||
|
||||
void
|
||||
_ecore_dbus_message_append_uint32(unsigned char *buf, unsigned int i)
|
||||
{
|
||||
unsigned char *c;
|
||||
|
||||
c = (unsigned char *)&i;
|
||||
*(buf + 0) = *(c + 0);
|
||||
*(buf + 1) = *(c + 1);
|
||||
*(buf + 2) = *(c + 2);
|
||||
*(buf + 3) = *(c + 3);
|
||||
}
|
||||
|
||||
unsigned char
|
||||
_ecore_dbus_message_read_byte(unsigned char *buf)
|
||||
{
|
||||
return *(unsigned char *)buf;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
_ecore_dbus_message_read_uint32(unsigned char *buf)
|
||||
{
|
||||
return *(unsigned int *)buf;
|
||||
}
|
||||
|
Loading…
Reference in New Issue