summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--legacy/ecore/src/lib/ecore_dbus/Ecore_DBus.h224
-rw-r--r--legacy/ecore/src/lib/ecore_dbus/ecore_dbus.c1468
-rw-r--r--legacy/ecore/src/lib/ecore_dbus/ecore_dbus_private.h82
3 files changed, 888 insertions, 886 deletions
diff --git a/legacy/ecore/src/lib/ecore_dbus/Ecore_DBus.h b/legacy/ecore/src/lib/ecore_dbus/Ecore_DBus.h
index 5f0c1f4f1e..d77291f360 100644
--- a/legacy/ecore/src/lib/ecore_dbus/Ecore_DBus.h
+++ b/legacy/ecore/src/lib/ecore_dbus/Ecore_DBus.h
@@ -1,3 +1,6 @@
1/*
2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3 */
1#ifndef _ECORE_DBUS_H 4#ifndef _ECORE_DBUS_H
2#define _ECORE_DBUS_H 5#define _ECORE_DBUS_H
3#endif 6#endif
@@ -19,194 +22,89 @@
19# endif 22# endif
20#endif 23#endif
21 24
22#include <Ecore_Data.h> 25#define ECORE_DBUS_MAJOR_PROTOCOL_VERSION 1
23 26
24#ifdef __cplusplus 27#ifdef __cplusplus
25extern "C" { 28extern "C" {
26#endif 29#endif
27 30
28 typedef struct _Ecore_DBus_Server Ecore_DBus_Server; 31 typedef struct _Ecore_DBus_Server Ecore_DBus_Server;
29 typedef struct _Ecore_DBus_Client Ecore_DBus_Client; 32 typedef struct _Ecore_DBus_Event_Server_Add Ecore_DBus_Event_Server_Add;
30 typedef struct _Ecore_DBus_Event_Server_Add Ecore_DBus_Event_Server_Add; 33 typedef struct _Ecore_DBus_Event_Server_Del Ecore_DBus_Event_Server_Del;
31 typedef struct _Ecore_DBus_Event_Server_Del Ecore_DBus_Event_Server_Del;
32 typedef struct _Ecore_DBus_Event_Server_Data Ecore_DBus_Event_Server_Data; 34 typedef struct _Ecore_DBus_Event_Server_Data Ecore_DBus_Event_Server_Data;
33 typedef struct _Ecore_DBus_Message Ecore_DBus_Message; 35 typedef struct _Ecore_DBus_Message Ecore_DBus_Message;
34 typedef struct _Ecore_DBus_Message_Field Ecore_DBus_Message_Field; 36 typedef struct _Ecore_DBus_Message_Field Ecore_DBus_Message_Field;
35 typedef struct _Ecore_DBus_Auth Ecore_DBus_Auth; 37
36 typedef unsigned char* (*Ecore_DBus_Auth_Transaction)(void*);
37
38 typedef enum _Ecore_DBus_Type 38 typedef enum _Ecore_DBus_Type
39 { 39 {
40 ECORE_DBUS_BUS_SESSION, 40 ECORE_DBUS_BUS_SESSION,
41 ECORE_DBUS_BUS_SYSTEM, 41 ECORE_DBUS_BUS_SYSTEM,
42 ECORE_DBUS_BUS_ACTIVATION 42 ECORE_DBUS_BUS_ACTIVATION
43 } Ecore_DBus_Type; 43 } Ecore_DBus_Type;
44 44
45 typedef enum _Ecore_DBus_Message_Type
46 {
47 ECORE_DBUS_MESSAGE_TYPE_INVALID,
48 ECORE_DBUS_MESSAGE_TYPE_METHOD_CALL,
49 ECORE_DBUS_MESSAGE_TYPE_METHOD_RETURN,
50 ECORE_DBUS_MESSAGE_TYPE_ERROR,
51 ECORE_DBUS_MESSAGE_TYPE_SIGNAL
52 } Ecore_DBus_Message_Type;
53
54 /* message data types */
55 typedef enum _Ecore_DBus_Data_Type 45 typedef enum _Ecore_DBus_Data_Type
56 { 46 {
57 ECORE_DBUS_DATA_TYPE_INVALID = ((int) '\0'), 47 ECORE_DBUS_DATA_TYPE_INVALID = ((int) '\0'),
58 ECORE_DBUS_DATA_TYPE_NIL = ((int) '\0'), 48 ECORE_DBUS_DATA_TYPE_BYTE = ((int) 'y'),
59 ECORE_DBUS_DATA_TYPE_BYTE = ((int) 'y'), 49 ECORE_DBUS_DATA_TYPE_BOOLEAN = ((int) 'b'), /* 0,1 */
60 ECORE_DBUS_DATA_TYPE_BOOLEAN = ((int) 'b'), /* 0,1 */ 50 ECORE_DBUS_DATA_TYPE_INT16 = ((int) 'n'),
61 ECORE_DBUS_DATA_TYPE_INT32 = ((int) 'i'), 51 ECORE_DBUS_DATA_TYPE_UINT16 = ((int) 'q'),
62 ECORE_DBUS_DATA_TYPE_UINT32 =((int) 'u'), 52 ECORE_DBUS_DATA_TYPE_INT32 = ((int) 'i'),
63 ECORE_DBUS_DATA_TYPE_INT64 = ((int) 'x'), 53 ECORE_DBUS_DATA_TYPE_UINT32 = ((int) 'u'),
64 ECORE_DBUS_DATA_TYPE_UINT64 = ((int) 't'), 54 ECORE_DBUS_DATA_TYPE_INT64 = ((int) 'x'),
65 ECORE_DBUS_DATA_TYPE_DOUBLE = ((int) 'd'), 55 ECORE_DBUS_DATA_TYPE_UINT64 = ((int) 't'),
66 ECORE_DBUS_DATA_TYPE_STRING = ((int) 's'), 56 ECORE_DBUS_DATA_TYPE_DOUBLE = ((int) 'd'),
67 ECORE_DBUS_DATA_TYPE_CUSTOM = ((int) 'c'), 57 ECORE_DBUS_DATA_TYPE_STRING = ((int) 's'),
68 ECORE_DBUS_DATA_TYPE_ARRAY =((int) 'a'), 58 ECORE_DBUS_DATA_TYPE_OBJECT_PATH = ((int) 'o'),
69 ECORE_DBUS_DATA_TYPE_DICT = ((int) 'm'), 59 ECORE_DBUS_DATA_TYPE_SIGNATURE = ((int) 'g'),
70 ECORE_DBUS_DATA_TYPE_OBJECT_PATH = ((int) 'o') 60 ECORE_DBUS_DATA_TYPE_ARRAY = ((int) 'a'),
61 ECORE_DBUS_DATA_TYPE_VARIANT = ((int) 'v'),
62 ECORE_DBUS_DATA_TYPE_STRUCT = ((int) 'r'),
63 ECORE_DBUS_DATA_TYPE_DICT_ENTRY = ((int) 'e'),
71 } Ecore_DBus_Data_Type; 64 } Ecore_DBus_Data_Type;
72 65
73 typedef enum _Ecore_DBus_Message_Header_Field
74 {
75 ECORE_DBUS_HEADER_FIELD_INVALID,
76 ECORE_DBUS_HEADER_FIELD_PATH,
77 ECORE_DBUS_HEADER_FIELD_INTERFACE,
78 ECORE_DBUS_HEADER_FIELD_MEMBER,
79 ECORE_DBUS_HEADER_FIELD_ERROR_NAME,
80 ECORE_DBUS_HEADER_FIELD_REPLY_SERIAL,
81 ECORE_DBUS_HEADER_FIELD_DESTINATION,
82 ECORE_DBUS_HEADER_FIELD_SENDER,
83 ECORE_DBUS_HEADER_FIELD_SIGNATURE
84 } Ecore_DBus_Message_Header_Field;
85
86 typedef enum _Ecore_DBus_Auth_Type
87 {
88 ECORE_DBUS_AUTH_TYPE_EXTERNAL,
89 ECORE_DBUS_AUTH_MAGIC_COOKIE,
90 ECORE_DBUS_AUTH_TYPE_DBUS_COOKIE_SHA1,
91 ECORE_DBUS_AUTH_TYPE_KERBEROS_V4,
92 ECORE_DBUS_AUTH_TYPE_SKEY
93 } Ecore_DBus_Auth_Type;
94
95 struct _Ecore_DBus_Auth
96 {
97 char *name;
98 unsigned int num_transactions;
99 Ecore_DBus_Auth_Transaction transactions[5];
100 };
101
102 struct _Ecore_DBus_Event_Server_Add 66 struct _Ecore_DBus_Event_Server_Add
103 { 67 {
104 Ecore_DBus_Server *server; 68 Ecore_DBus_Server *server;
105 }; 69 };
106 70
107 struct _Ecore_DBus_Event_Server_Del 71 struct _Ecore_DBus_Event_Server_Del
108 { 72 {
109 Ecore_DBus_Server *server; 73 Ecore_DBus_Server *server;
110 }; 74 };
111 75
112 struct _Ecore_DBus_Message_Field 76 typedef enum _Ecore_DBus_Message_Header_Field
113 {
114 Ecore_List __list_data;
115 Ecore_DBus_Data_Type type;
116 unsigned int offset;
117 unsigned int count; /* number of elements, usefull for structs, arrays, dicts */
118 unsigned int hfield; /* if the field is a header field, we need the type of it */
119 };
120
121 struct _Ecore_DBus_Message
122 { 77 {
123 /* header fields */ 78 ECORE_DBUS_HEADER_FIELD_INVALID,
124 unsigned char byte_order; 79 ECORE_DBUS_HEADER_FIELD_PATH,
125 unsigned char type; 80 ECORE_DBUS_HEADER_FIELD_INTERFACE,
126 unsigned char flags; 81 ECORE_DBUS_HEADER_FIELD_MEMBER,
127 unsigned char protocol; 82 ECORE_DBUS_HEADER_FIELD_ERROR_NAME,
128 unsigned long hlength; 83 ECORE_DBUS_HEADER_FIELD_REPLY_SERIAL,
129 unsigned long blength; 84 ECORE_DBUS_HEADER_FIELD_DESTINATION,
130 unsigned long serial; 85 ECORE_DBUS_HEADER_FIELD_SENDER,
131 86 ECORE_DBUS_HEADER_FIELD_SIGNATURE
132 Ecore_DBus_Server *ref_server; 87 } Ecore_DBus_Message_Header_Field;
133 88
134 unsigned char *header;
135 unsigned int hpos;
136 Ecore_DBus_Message_Field *header_fields;
137 unsigned char *body;
138 unsigned int bpos;
139 Ecore_DBus_Message_Field *body_fields;
140 unsigned char *signature;
141 };
142
143 extern int ECORE_DBUS_EVENT_SERVER_ADD; 89 extern int ECORE_DBUS_EVENT_SERVER_ADD;
144 extern int ECORE_DBUS_EVENT_SERVER_DATA; 90 extern int ECORE_DBUS_EVENT_SERVER_DATA;
145 91 extern int ECORE_DBUS_EVENT_SERVER_DEL;
146 /* Message byte order */ 92
147#define DBUS_LITTLE_ENDIAN ('l') /* LSB first */ 93 /* init */
148#define DBUS_BIG_ENDIAN ('B') /* MSB first */
149
150 /* Protocol version */
151#define DBUS_MAJOR_PROTOCOL_VERSION 0
152
153
154 /* Max length in bytes of a service or interface or member name */
155#define DBUS_MAXIMUM_NAME_LENGTH 256
156
157 /* Max length of a match rule string */
158#define DBUS_MAXIMUM_MATCH_RULE_LENGTH 1024
159
160
161 /* Header flags */
162#define DBUS_HEADER_FLAG_NO_REPLY_EXPECTED 0x1
163#define DBUS_HEADER_FLAG_AUTO_ACTIVATION 0x2
164
165
166#define DBUS_HEADER_FIELD_LAST DBUS_HEADER_FIELD_SIGNATURE
167
168 /* Services */
169#define DBUS_SERVICE_ORG_FREEDESKTOP_DBUS "org.freedesktop.DBus"
170
171 /* Paths */
172#define DBUS_PATH_ORG_FREEDESKTOP_DBUS "/org/freedesktop/DBus"
173#define DBUS_PATH_ORG_FREEDESKTOP_LOCAL "/org/freedesktop/Local"
174
175 /* Interfaces, these #define don't do much other than
176 * * catch typos at compile time
177 * */
178#define DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS "org.freedesktop.DBus"
179#define DBUS_INTERFACE_ORG_FREEDESKTOP_INTROSPECTABLE "org.freedesktop.Introspectable"
180
181 /* This is a special interface whose methods can only be invoked
182 * by the local implementation (messages from remote apps aren't
183 * allowed to specify this interface).
184 */
185#define DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL "org.freedesktop.Local"
186 /* Service owner flags */
187#define DBUS_SERVICE_FLAG_PROHIBIT_REPLACEMENT 0x1
188#define DBUS_SERVICE_FLAG_REPLACE_EXISTING 0x2
189
190 /* Service replies */
191#define DBUS_SERVICE_REPLY_PRIMARY_OWNER 0x1
192#define DBUS_SERVICE_REPLY_IN_QUEUE 0x2
193#define DBUS_SERVICE_REPLY_SERVICE_EXISTS 0x4
194#define DBUS_SERVICE_REPLY_ALREADY_OWNER 0x8
195
196 /* Activation replies */
197#define DBUS_ACTIVATION_REPLY_ACTIVATED 0x0
198#define DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE 0x1
199
200 /* connection */
201 EAPI int ecore_dbus_init(void); 94 EAPI int ecore_dbus_init(void);
202 EAPI int ecore_dbus_shutdown(void); 95 EAPI int ecore_dbus_shutdown(void);
203 96
204 EAPI Ecore_DBus_Server* ecore_dbus_server_connect(Ecore_DBus_Type compl_type, char *name, int port, const void *data); 97 /* connection */
205 /* message */ 98 EAPI Ecore_DBus_Server *ecore_dbus_server_connect(Ecore_DBus_Type type, char *name, int port, const void *data);
206 EAPI unsigned int ecore_dbus_message_new_method_call(Ecore_DBus_Server *svr,char *service,char *path,char *interface,char *method,char *fmt, ...); 99 EAPI void ecore_dbus_server_del(Ecore_DBus_Server *svr);
207 EAPI void ecore_dbus_message_print(Ecore_DBus_Message *msg); 100
208 EAPI void * ecore_dbus_get_header_field(Ecore_DBus_Message *,Ecore_DBus_Message_Field *, Ecore_DBus_Message_Header_Field); 101
209 EAPI void * ecore_dbus_get_body_field(Ecore_DBus_Message *,Ecore_DBus_Message_Field *, unsigned int); 102 /* message */
103 EAPI int ecore_dbus_server_send(Ecore_DBus_Server *svr, char *command, int length);
104 EAPI unsigned int ecore_dbus_message_new_method_call(Ecore_DBus_Server *svr, char *service, char *path, char *interface, char *method, char *fmt, ...);
105 EAPI void ecore_dbus_message_print(Ecore_DBus_Message *msg);
106 EAPI void *ecore_dbus_get_header_field(Ecore_DBus_Message *msg, Ecore_DBus_Message_Field *field, Ecore_DBus_Message_Header_Field header);
107 EAPI void *ecore_dbus_get_body_field(Ecore_DBus_Message *msg, Ecore_DBus_Message_Field *field, unsigned int pos);
210 108
211#ifdef __cplusplus 109#ifdef __cplusplus
212} 110}
diff --git a/legacy/ecore/src/lib/ecore_dbus/ecore_dbus.c b/legacy/ecore/src/lib/ecore_dbus/ecore_dbus.c
index f7249a0492..11227291b7 100644
--- a/legacy/ecore/src/lib/ecore_dbus/ecore_dbus.c
+++ b/legacy/ecore/src/lib/ecore_dbus/ecore_dbus.c
@@ -1,14 +1,15 @@
1/*
2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3 */
1#include <stdlib.h> 4#include <stdlib.h>
2#include <string.h>
3#include <stdio.h> 5#include <stdio.h>
4#include <unistd.h> 6#include <string.h>
5#include <sys/types.h>
6#include <stdarg.h> 7#include <stdarg.h>
7 8
8#include "Ecore.h" 9#include "Ecore.h"
9#include "ecore_private.h" 10#include "ecore_private.h"
10#include "Ecore_Con.h"
11#include "Ecore_DBus.h" 11#include "Ecore_DBus.h"
12#include "Ecore_Con.h"
12#include "ecore_dbus_private.h" 13#include "ecore_dbus_private.h"
13 14
14/********************************************************************************/ 15/********************************************************************************/
@@ -42,32 +43,415 @@
42/* 29-03-05 */ 43/* 29-03-05 */
43/* 0.2.1 some segfault fixes, new tests */ 44/* 0.2.1 some segfault fixes, new tests */
44 45
45static int ecore_dbus_server_send(Ecore_DBus_Server * svr, 46/* global variables */
46 char *command, int length);
47Ecore_List2 *_ecore_dbus_message_print_field(Ecore_List2 * l,
48 unsigned char *buf);
49void _ecore_dbus_message_print_raw(unsigned char *msg,
50 unsigned int msg_len);
51 47
52/**********************/ 48int ECORE_DBUS_EVENT_SERVER_ADD = 0;
53/* ecore dbus message */ 49int ECORE_DBUS_EVENT_SERVER_DEL = 0;
54/**********************/ 50int ECORE_DBUS_EVENT_SERVER_DATA = 0;
55 51
56#define BODY_LEN 64 52/* private function declaration */
57#define HEADER_LEN 16
58 53
59/* length functions */ 54/* length functions */
60/********************/ 55static void _ecore_dbus_message_append_length(unsigned char **buf, unsigned int old_length, unsigned int size);
61/* all of these increase the length */ 56static void _ecore_dbus_message_increase_length(unsigned char **buf, unsigned int new_length);
57/* padding functions */
58static void _ecore_dbus_message_4byte_padding(unsigned char **buf, unsigned int *old_length);
59static void _ecore_dbus_message_8byte_padding(unsigned char **buf, unsigned int *old_length);
60static void _ecore_dbus_message_skip_4byte_padding(unsigned int *old_length);
61static void _ecore_dbus_message_skip_8byte_padding(unsigned int *old_length);
62/* appending/reading functions */
63static void _ecore_dbus_message_append_nbytes(unsigned char *buf, unsigned char *data, unsigned int data_length);
64static void _ecore_dbus_message_append_byte(unsigned char *buf, unsigned char c);
65static void _ecore_dbus_message_append_uint32(unsigned char *buf, unsigned long int i);
66static unsigned char _ecore_dbus_message_read_byte(unsigned char *buf);
67static unsigned long _ecore_dbus_message_read_uint32(unsigned char *buf);
68/* message functions */
69static Ecore_DBus_Message *_ecore_dbus_message_new(Ecore_DBus_Server *svr);
70static Ecore_DBus_Message_Field *_ecore_dbus_message_new_field(Ecore_DBus_Data_Type type, unsigned int offset);
71static void _ecore_dbus_message_free(void *data, void *ev);
72/* marshal functions */
73static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_byte(unsigned char **buf, unsigned int *old_length, unsigned char c);
74/*
75static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_boolean(unsigned char **buf, unsigned int *old_length, uint32_t i);
76static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_int16(unsigned char **buf, unsigned int *old_length, int16_t i);
77static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_uint16(unsigned char **buf, unsigned int *old_length, uint16_t i);
78static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_int32(unsigned char **buf, unsigned int *old_length, int32_t i);
79*/
80static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_uint32(unsigned char **buf, unsigned int *old_length, uint32_t i);
81/*
82static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_int64(unsigned char **buf, unsigned int *old_length, int64_t i);
83static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_uint64(unsigned char **buf, unsigned int *old_length, uint64_t i);
84static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_double(unsigned char **buf, unsigned int *old_length, double i);
85*/
86static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_string(unsigned char **buf, unsigned int *old_length, char *str);
87static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_object_path(unsigned char **buf, unsigned int *old_length, char *str);
88/*
89static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_signature(unsigned char **buf, unsigned int *old_length, char *str);
90*/
91/*
92 * FIXME: These aren't correct !
93static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_array(unsigned char **msg, unsigned int *old_length);
94static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_variant(unsigned char **msg, unsigned int *old_length);
95static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_struct(unsigned char **msg, unsigned int *old_length);
96static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_dict_entry(unsigned char **msg, unsigned int *old_length);
97*/
98static Ecore_DBus_Message_Field *_ecore_dbus_message_marshal_data(unsigned char **buf, unsigned int *old_length, Ecore_DBus_Data_Type type, void *data);
99static 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);
100/* unmarshal functions */
101/*
102static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_byte(unsigned char *buf, unsigned int *old_length);
103static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_boolean(unsigned char *buf, unsigned int *old_length);
104static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_int16(unsigned char *buf, unsigned int *old_length);
105static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_uint16(unsigned char *buf, unsigned int *old_length);
106*/
107static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_int32(unsigned char *buf, unsigned int *old_length);
108static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_uint32(unsigned char *buf, unsigned int *old_length);
109/*
110static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_int64(unsigned char *buf, unsigned int *old_length);
111static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_uint64(unsigned char *buf, unsigned int *old_length);
112static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_double(unsigned char *buf, unsigned int *old_length);
113*/
114static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_string(unsigned char *buf, unsigned int *old_length);
115static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_object_path(unsigned char *buf, unsigned int *old_length);
116/*
117static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_signature(unsigned char *buf, unsigned int *old_length);
118*/
119/*
120 * FIXME: These aren't correct!
121static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_array(unsigned char *buf, unsigned int *old_length);
122static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_variant(unsigned char *buf, unsigned int *old_length);
123static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_struct(unsigned char *buf, unsigned int *old_length);
124static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_dict_entry(unsigned char *buf, unsigned int *old_length);
125static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_data(unsigned char *buf, unsigned int *old_length);
126*/
127static Ecore_DBus_Message_Field *_ecore_dbus_message_unmarshal_custom_header(unsigned char *buf, unsigned int *old_length);
128static Ecore_DBus_Message *_ecore_dbus_message_unmarshal(Ecore_DBus_Server *svr, unsigned char *message);
129/* header functions */
130static void _ecore_dbus_message_common_header(Ecore_DBus_Message *msg, int type, int flags);
131static void *_ecore_dbus_get_field(unsigned char *buf, Ecore_DBus_Message_Field *f);
132/* helper functions */
133static char *_ecore_dbus_getuid(void);
134static char *_ecore_dbus_hex_encode(char *src_str);
135/* auth functions */
136unsigned char *_ecore_dbus_auth_external(void *data);
137/* con functions */
138static int _ecore_dbus_event_server_add(void *data, int ev_type, void *ev);
139static int _ecore_dbus_event_server_del(void *data, int ev_type, void *ev);
140static int _ecore_dbus_event_server_data(void *data, int ev_type, void *ev);
141/* printing functions */
142static Ecore_DBus_Message_Field *_ecore_dbus_message_print_field(Ecore_DBus_Message_Field *f, unsigned char *buf);
143static Ecore_DBus_Message_Field *_ecore_dbus_message_print_header_field(Ecore_DBus_Message_Field *f, unsigned char *buf);
144static void _ecore_dbus_message_print_fields(Ecore_DBus_Message_Field *f);
145static void _ecore_dbus_message_print_raw(unsigned char *msg, unsigned int msg_len);
146
147/* local variables */
148
149static const Ecore_DBus_Auth auths[] = {
150 {"EXTERNAL", 1, {_ecore_dbus_auth_external, NULL, NULL, NULL, NULL}},
151 {"MAGIC_COOKIE", 0, {NULL, NULL, NULL, NULL, NULL}},
152 {"DBUS_COOKIE_SHA1", 0, {NULL, NULL, NULL, NULL, NULL}},
153 {"KERBEROS_V4", 0, {NULL, NULL, NULL, NULL, NULL}},
154 {"SKEY", 0, {NULL, NULL, NULL, NULL, NULL}},
155};
156
157static int init_count = 0;
158static Ecore_List2 *servers = NULL;
159static Ecore_Event_Handler *handler[3];
160
161/* public functions */
162int
163ecore_dbus_init(void)
164{
165 int i = 0;
166
167 if (++init_count != 1) return init_count;
168
169 ecore_con_init();
170
171 ECORE_DBUS_EVENT_SERVER_ADD = ecore_event_type_new();
172 ECORE_DBUS_EVENT_SERVER_DEL = ecore_event_type_new();
173 ECORE_DBUS_EVENT_SERVER_DATA = ecore_event_type_new();
174
175 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD,
176 _ecore_dbus_event_server_add, NULL);
177 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL,
178 _ecore_dbus_event_server_del, NULL);
179 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
180 _ecore_dbus_event_server_data, NULL);
181
182 return init_count;
183}
184
185int
186ecore_dbus_shutdown(void)
187{
188 int i = 0;
189
190 if (--init_count != 0) return init_count;
191
192 for (i = 0; i < 3; i++)
193 ecore_event_handler_del(handler[i]);
194
195 ecore_con_shutdown();
196
197 return init_count;
198}
199
200Ecore_DBus_Server *
201ecore_dbus_server_connect(Ecore_DBus_Type compl_type, char *name, int port,
202 const void *data)
203{
204 Ecore_DBus_Server *svr;
205 Ecore_DBus_Type type;
206 Ecore_Con_Type extra = 0;
207
208 svr = calloc(1, sizeof(Ecore_DBus_Server));
209 if (!svr) return NULL;
210 type = compl_type;
211 switch (type)
212 {
213 case ECORE_DBUS_BUS_SESSION:
214 svr->server =
215 ecore_con_server_connect(ECORE_CON_LOCAL_USER | extra, name, port, svr);
216 break;
217 case ECORE_DBUS_BUS_SYSTEM:
218 svr->server =
219 ecore_con_server_connect(ECORE_CON_LOCAL_USER | extra, name, port, svr);
220 break;
221 default:
222 free(svr);
223 return NULL;
224 }
225 if (!svr->server)
226 {
227 printf("Couldn't connect to server\n");
228 free(svr);
229 return NULL;
230 }
231 svr->authenticated = 0;
232 svr->cnt_msg = 0;
233 svr->auth_type = -1;
234 svr->auth_type_transaction = 0;
235 servers = _ecore_list2_append(servers, svr);
236
237 return svr;
238}
239
240void
241ecore_dbus_server_del(Ecore_DBus_Server *svr)
242{
243 if (svr->server) ecore_con_server_del(svr->server);
244 servers = _ecore_list2_remove(servers, svr);
245 free(svr);
246}
247
248int
249ecore_dbus_server_send(Ecore_DBus_Server *svr, char *command, int length)
250{
251 int ret;
252
253 ret = ecore_con_server_send(svr->server, command, length);
254 printf("[ecore_dbus] ecore_dbus_server: %p ecore_con_server: %p sent %d of %d bytes\n",
255 svr, svr->server, ret, length);
256 return ret;
257}
258
259unsigned int
260ecore_dbus_message_new_method_call(Ecore_DBus_Server *svr, char *service,
261 char *path, char *interface, char *method,
262 char *fmt, ...)
263{
264 unsigned long serial;
265 va_list ap;
266
267 Ecore_DBus_Message_Field *f;
268
269 /* init message */
270 Ecore_DBus_Message *msg = _ecore_dbus_message_new(svr);
271
272 /* common header */
273 _ecore_dbus_message_common_header(msg, ECORE_DBUS_MESSAGE_TYPE_METHOD_CALL, 0);
274 /* custom header */
275 if (path)
276 {
277 f = _ecore_dbus_message_marshal_custom_header(&msg->header, &msg->hpos,
278 1,
279 ECORE_DBUS_DATA_TYPE_OBJECT_PATH,
280 path);
281 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
282 }
283
284 if (interface)
285 {
286 f = _ecore_dbus_message_marshal_custom_header(&msg->header, &msg->hpos,
287 2,
288 ECORE_DBUS_DATA_TYPE_STRING,
289 interface);
290 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
291 }
292 if (method)
293 {
294 f = _ecore_dbus_message_marshal_custom_header(&msg->header, &msg->hpos,
295 3,
296 ECORE_DBUS_DATA_TYPE_STRING,
297 method);
298 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
299 }
300 if (service)
301 {
302 f = _ecore_dbus_message_marshal_custom_header(&msg->header, &msg->hpos,
303 6,
304 ECORE_DBUS_DATA_TYPE_STRING,
305 service);
306 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
307 }
308 if (fmt)
309 {
310 f = _ecore_dbus_message_marshal_custom_header(&msg->header, &msg->hpos,
311 8,
312 ECORE_DBUS_DATA_TYPE_STRING,
313 fmt);
314 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
315 }
316 _ecore_dbus_message_8byte_padding(&msg->header, &msg->hpos);
317 /* header length */
318 *(msg->header + 4) = msg->hlength = msg->hpos;
319 /* message body */
320 va_start(ap, fmt);
321 while (*fmt)
322 {
323 switch (*fmt)
324 {
325 case ECORE_DBUS_DATA_TYPE_BYTE:
326 f = _ecore_dbus_message_marshal_byte(&msg->body, &msg->bpos,
327 va_arg(ap, int));
328 msg->body_fields = _ecore_list2_append(msg->body_fields, f);
329 break;
330 case ECORE_DBUS_DATA_TYPE_UINT32:
331 f = _ecore_dbus_message_marshal_uint32(&msg->body, &msg->bpos,
332 va_arg(ap, unsigned long));
333 msg->body_fields = _ecore_list2_append(msg->body_fields, f);
334 break;
335 case ECORE_DBUS_DATA_TYPE_STRING:
336 f = _ecore_dbus_message_marshal_string(&msg->body, &msg->bpos,
337 (char *)va_arg(ap, char *));
338 msg->body_fields = _ecore_list2_append(msg->body_fields, f);
339 break;
340 case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
341 f = _ecore_dbus_message_marshal_object_path(&msg->body, &msg->bpos,
342 (char *)va_arg(ap, char *));
343 msg->body_fields = _ecore_list2_append(msg->body_fields, f);
344 break;
345 case ECORE_DBUS_DATA_TYPE_INT32:
346 case ECORE_DBUS_DATA_TYPE_BOOLEAN:
347 case ECORE_DBUS_DATA_TYPE_INT64:
348 case ECORE_DBUS_DATA_TYPE_UINT64:
349 case ECORE_DBUS_DATA_TYPE_DOUBLE:
350 case ECORE_DBUS_DATA_TYPE_ARRAY:
351 case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
352 case ECORE_DBUS_DATA_TYPE_INVALID:
353#if 0
354 default:
355#endif
356 printf("[ecore_dbus] unknown/unhandled data type %c\n", *fmt);
357 break;
358 }
359 fmt++;
360 }
361 va_end(ap);
362 *(unsigned int *)(msg->header + 8) = msg->blength = msg->bpos;
363 /* show message */
364 /*ecore_dbus_message_print(msg);
365 * _ecore_dbus_message_print_raw(msg->header,msg->hlength);
366 * _ecore_dbus_message_print_raw(msg->body,msg->blength); */
367 /* send message */
368 ecore_dbus_server_send(svr, (char *)msg->header, msg->hlength);
369 if (msg->body)
370 ecore_dbus_server_send(svr, (char *)msg->body, msg->blength);
371
372 serial = msg->serial;
373 _ecore_dbus_message_free(NULL, msg);
374 return serial;
375}
376
62void 377void
63_ecore_dbus_message_increase_lengthz(unsigned char **buf, 378ecore_dbus_message_print(Ecore_DBus_Message *msg)
64 unsigned int old_length, unsigned int size) 379{
380 Ecore_DBus_Message_Field *f;
381 static const char *msg_type[] = {
382 "INVALID", "METHOD_CALL", "METHOD_RETURN", "ERROR", "SIGNAL"
383 };
384
385 printf("[ecore_dbus] per field message:\n");
386 printf("[ecore_dbus] header fields:\n");
387 /* header common fields */
388 printf("[ecore_dbus] header endianess : %c\n", msg->byte_order);
389 printf("[ecore_dbus] header type : %s\n", msg_type[msg->type]);
390 printf("[ecore_dbus] header flags : %c\n", msg->flags + 48);
391 printf("[ecore_dbus] header protocol : %c\n", msg->protocol + 48);
392 printf("[ecore_dbus] header hlength : %u\n",
393 *(unsigned int *)(msg->header + 4));
394 printf("[ecore_dbus] header blength : %lu\n", msg->blength);
395 printf("[ecore_dbus] header serial : %lu\n", msg->serial);
396
397 /* header custom fields */
398 f = msg->header_fields;
399 while (f)
400 {
401 f = _ecore_dbus_message_print_header_field(f, msg->header);
402 }
403 /* body fields */
404 printf("[ecore_dbus] body fields:\n");
405 f = msg->body_fields;
406 while (f)
407 {
408 f = _ecore_dbus_message_print_field(f, msg->body);
409 }
410 printf("[ecore_dbus] end per field message\n");
411}
412
413void *
414ecore_dbus_get_header_field(Ecore_DBus_Message *m,
415 Ecore_DBus_Message_Field *mf,
416 Ecore_DBus_Message_Header_Field hft)
417{
418 Ecore_List2 *l;
419
420 for (l = (Ecore_List2 *)mf; l; l = l->next)
421 if (((Ecore_DBus_Message_Field *)l)->hfield == hft)
422 return _ecore_dbus_get_field(m->header, (Ecore_DBus_Message_Field *)l);
423 return NULL;
424}
425
426void *
427ecore_dbus_get_body_field(Ecore_DBus_Message *m, Ecore_DBus_Message_Field *mf,
428 unsigned int pos)
429{
430 Ecore_List2 *l;
431 unsigned int i = 0;
432
433 for (l = (Ecore_List2 *) mf; l; l = l->next)
434 {
435 if (i == pos)
436 return _ecore_dbus_get_field(m->body, (Ecore_DBus_Message_Field *)l);
437 i++;
438 }
439 return NULL;
440}
441
442/* private functions */
443
444/* length functions */
445
446static void
447_ecore_dbus_message_append_length(unsigned char **buf,
448 unsigned int old_length, unsigned int size)
65{ 449{
66 *buf = realloc(*buf, old_length + size); 450 *buf = realloc(*buf, old_length + size);
67 memset(*buf + old_length, 0, size); 451 memset(*buf + old_length, 0, size);
68} 452}
69 453
70void 454static void
71_ecore_dbus_message_increase_length(unsigned char **buf, 455_ecore_dbus_message_increase_length(unsigned char **buf,
72 unsigned int new_length) 456 unsigned int new_length)
73{ 457{
@@ -75,9 +459,8 @@ _ecore_dbus_message_increase_length(unsigned char **buf,
75} 459}
76 460
77/* padding functions */ 461/* padding functions */
78/*********************/ 462
79/* all of these increase the length */ 463static void
80void
81_ecore_dbus_message_4byte_padding(unsigned char **buf, unsigned int *old_length) 464_ecore_dbus_message_4byte_padding(unsigned char **buf, unsigned int *old_length)
82{ 465{
83 unsigned int padding; 466 unsigned int padding;
@@ -86,11 +469,12 @@ _ecore_dbus_message_4byte_padding(unsigned char **buf, unsigned int *old_length)
86 if (padding != 0) 469 if (padding != 0)
87 { 470 {
88 padding = 4 - padding; 471 padding = 4 - padding;
89 _ecore_dbus_message_increase_lengthz(buf, *old_length, padding); 472 _ecore_dbus_message_append_length(buf, *old_length, padding);
90 } 473 }
91 *old_length += padding; 474 *old_length += padding;
92} 475}
93void 476
477static void
94_ecore_dbus_message_8byte_padding(unsigned char **buf, unsigned int *old_length) 478_ecore_dbus_message_8byte_padding(unsigned char **buf, unsigned int *old_length)
95{ 479{
96 unsigned int padding; 480 unsigned int padding;
@@ -99,50 +483,49 @@ _ecore_dbus_message_8byte_padding(unsigned char **buf, unsigned int *old_length)
99 if (padding != 0) 483 if (padding != 0)
100 { 484 {
101 padding = 8 - padding; 485 padding = 8 - padding;
102 _ecore_dbus_message_increase_lengthz(buf, *old_length, padding); 486 _ecore_dbus_message_append_length(buf, *old_length, padding);
103 } 487 }
104 *old_length += padding; 488 *old_length += padding;
105} 489}
106 490
107void 491static void
108_ecore_dbus_message_skip_8byte_padding(unsigned int *old_length) 492_ecore_dbus_message_skip_4byte_padding(unsigned int *old_length)
109{ 493{
110 unsigned int padding; 494 unsigned int padding;
111 495
112 padding = *old_length % 8; 496 padding = *old_length % 4;
113 if (padding != 0) 497 if (padding != 0)
114 *old_length += 8 - padding; 498 *old_length += 4 - padding;
115 return; 499 return;
116} 500}
117 501
118void 502static void
119_ecore_dbus_message_skip_4byte_padding(unsigned int *old_length) /* DONE */ 503_ecore_dbus_message_skip_8byte_padding(unsigned int *old_length)
120{ 504{
121 unsigned int padding; 505 unsigned int padding;
122 506
123 padding = *old_length % 4; 507 padding = *old_length % 8;
124 if (padding != 0) 508 if (padding != 0)
125 *old_length += 4 - padding; 509 *old_length += 8 - padding;
126 return; 510 return;
127} 511}
128 512
129/* appending/reading functions */ 513/* appending/reading functions */
130/*******************************/ 514
131/* non of these increase the length */ 515static void
132void
133_ecore_dbus_message_append_nbytes(unsigned char *buf, unsigned char *data, 516_ecore_dbus_message_append_nbytes(unsigned char *buf, unsigned char *data,
134 unsigned int data_length) 517 unsigned int data_length)
135{ 518{
136 memcpy(buf, data, data_length); 519 memcpy(buf, data, data_length);
137} 520}
138 521
139void 522static void
140_ecore_dbus_message_append_byte(unsigned char *buf, unsigned char c) 523_ecore_dbus_message_append_byte(unsigned char *buf, unsigned char c)
141{ 524{
142 *buf = c; 525 *buf = c;
143} 526}
144 527
145void 528static void
146_ecore_dbus_message_append_uint32(unsigned char *buf, unsigned long int i) 529_ecore_dbus_message_append_uint32(unsigned char *buf, unsigned long int i)
147{ 530{
148 unsigned char *c; 531 unsigned char *c;
@@ -154,27 +537,27 @@ _ecore_dbus_message_append_uint32(unsigned char *buf, unsigned long int i)
154 *(buf + 3) = *(c + 3); 537 *(buf + 3) = *(c + 3);
155} 538}
156 539
157unsigned long 540static unsigned char
158_ecore_dbus_message_read_uint32(unsigned char *buf) 541_ecore_dbus_message_read_byte(unsigned char *buf)
159{ 542{
160 return *(unsigned long *)buf; 543 return *(unsigned char *)buf;
161} 544}
162 545
163unsigned char 546static unsigned long
164_ecore_dbus_message_read_byte(unsigned char *buf) 547_ecore_dbus_message_read_uint32(unsigned char *buf)
165{ 548{
166 return *(unsigned char *)buf; 549 return *(unsigned long *)buf;
167} 550}
168 551
169/* field functions */ 552/* message functions */
170/*******************/
171 553
172/* memory allocation */ 554static Ecore_DBus_Message *
173/**********************/ 555_ecore_dbus_message_new(Ecore_DBus_Server *svr)
174Ecore_DBus_Message *
175_ecore_dbus_message_new(Ecore_DBus_Server * svr)
176{ 556{
177 Ecore_DBus_Message *msg = calloc(1, sizeof(Ecore_DBus_Message)); 557 Ecore_DBus_Message *msg;
558
559 msg = calloc(1, sizeof(Ecore_DBus_Message));
560 if (!msg) return NULL;
178 561
179 msg->ref_server = svr; 562 msg->ref_server = svr;
180 msg->body_fields = NULL; 563 msg->body_fields = NULL;
@@ -188,25 +571,29 @@ _ecore_dbus_message_new(Ecore_DBus_Server * svr)
188 return msg; 571 return msg;
189} 572}
190 573
191Ecore_DBus_Message_Field * 574static Ecore_DBus_Message_Field *
192_ecore_dbus_message_new_field(Ecore_DBus_Data_Type type, unsigned int offset) 575_ecore_dbus_message_new_field(Ecore_DBus_Data_Type type, unsigned int offset)
193{ 576{
194 Ecore_DBus_Message_Field *f; 577 Ecore_DBus_Message_Field *f;
195 578
196 f = malloc(sizeof(Ecore_DBus_Message_Field)); 579 f = malloc(sizeof(Ecore_DBus_Message_Field));
580 if (!f) return NULL;
197 f->offset = offset; 581 f->offset = offset;
198 f->type = type; 582 f->type = type;
199 f->count = 0; 583 f->count = 0;
200 return f; 584 return f;
201} 585}
202 586
203void 587static void
204_ecore_dbus_message_free(void *data, void *ev) 588_ecore_dbus_message_free(void *data, void *ev)
205{ 589{
206 Ecore_DBus_Message *msg = ev; 590 Ecore_DBus_Message *msg;
207 Ecore_List2 *l = (Ecore_List2 *) msg->body_fields; 591 Ecore_List2 *l;
208 Ecore_List2 *next; 592 Ecore_List2 *next;
209 593
594 msg = ev;
595
596 l = (Ecore_List2 *)msg->body_fields;
210 while (l) 597 while (l)
211 { 598 {
212 next = l->next; 599 next = l->next;
@@ -225,41 +612,40 @@ _ecore_dbus_message_free(void *data, void *ev)
225 free(msg); 612 free(msg);
226} 613}
227 614
228/* signature functions */
229/***********************/
230
231/* marshal functions */ 615/* marshal functions */
232/*********************/
233
234/* cambiar todos los *msg por char** asi se podra cambiar el puntero sin problemas */
235/* agregarle el parametro de signature por si se quiere q agregue una variable al signature */
236/* y pasarle la lista de campos por si pone el argumento en la lista del header o del body */
237 616
238Ecore_DBus_Message_Field * 617static Ecore_DBus_Message_Field *
239_ecore_dbus_message_marshal_byte(unsigned char **buf, unsigned int *old_length, 618_ecore_dbus_message_marshal_byte(unsigned char **buf, unsigned int *old_length,
240 unsigned char c) 619 unsigned char c)
241{ 620{
242 Ecore_DBus_Message_Field *f; 621 Ecore_DBus_Message_Field *f;
243 622
244 _ecore_dbus_message_increase_length(buf, *old_length + 1); // increase the length + 1, old_length changed 623 /* increase the length + 1, old_length changed */
245 _ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_BYTE); // append the data type 624 _ecore_dbus_message_increase_length(buf, *old_length + 1);
625 /* append the data type */
626 _ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_BYTE);
246 *old_length += 1; 627 *old_length += 1;
247 _ecore_dbus_message_increase_length(buf, *old_length + 1); // increase the length + 1, old_length changed 628 /* increase the length + 1, old_length changed */
248 _ecore_dbus_message_append_byte(*buf + *old_length, c); // append c at cur_length 629 _ecore_dbus_message_increase_length(buf, *old_length + 1);
249 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_BYTE, *old_length); // create field 630 /* append c at cur_length */
631 _ecore_dbus_message_append_byte(*buf + *old_length, c);
632 /* create field */
633 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_BYTE, *old_length);
250 *old_length += 1; 634 *old_length += 1;
251 return f; 635 return f;
252} 636}
253 637
254Ecore_DBus_Message_Field * 638static Ecore_DBus_Message_Field *
255_ecore_dbus_message_marshal_uint32(unsigned char **buf, 639_ecore_dbus_message_marshal_uint32(unsigned char **buf,
256 unsigned int *old_length, 640 unsigned int *old_length,
257 unsigned long int i) 641 unsigned int i)
258{ 642{
259 Ecore_DBus_Message_Field *f; 643 Ecore_DBus_Message_Field *f;
260 644
261 _ecore_dbus_message_increase_length(buf, *old_length + 1); // increase the length + 1, old_length changed 645 /* increase the length + 1, old_length changed */
262 _ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_UINT32); // append the data type 646 _ecore_dbus_message_increase_length(buf, *old_length + 1);
647 /* append the data type */
648 _ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_UINT32);
263 *old_length += 1; 649 *old_length += 1;
264 _ecore_dbus_message_4byte_padding(buf, old_length); 650 _ecore_dbus_message_4byte_padding(buf, old_length);
265 _ecore_dbus_message_increase_length(buf, *old_length + 4); 651 _ecore_dbus_message_increase_length(buf, *old_length + 4);
@@ -269,67 +655,76 @@ _ecore_dbus_message_marshal_uint32(unsigned char **buf,
269 return f; 655 return f;
270} 656}
271 657
272Ecore_DBus_Message_Field * 658static Ecore_DBus_Message_Field *
273_ecore_dbus_message_marshal_path(unsigned char **buf, unsigned int *old_length, 659_ecore_dbus_message_marshal_object_path(unsigned char **buf, unsigned int *old_length,
274 unsigned char *str) 660 char *str)
275{ 661{
276 int str_len; 662 int str_len;
277 Ecore_DBus_Message_Field *f; 663 Ecore_DBus_Message_Field *f;
278 664
279 _ecore_dbus_message_increase_length(buf, *old_length + 1); // increase the length + 1, old_length changed 665 /* increase the length + 1, old_length changed */
280 _ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_OBJECT_PATH); // append the data type 666 _ecore_dbus_message_increase_length(buf, *old_length + 1);
667 /* append the data type */
668 _ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_OBJECT_PATH);
281 *old_length += 1; 669 *old_length += 1;
282 670
283 str_len = strlen((char *)str); 671 str_len = strlen(str);
284 _ecore_dbus_message_4byte_padding(buf, old_length); 672 _ecore_dbus_message_4byte_padding(buf, old_length);
285 _ecore_dbus_message_increase_length(buf, *old_length + 4); 673 _ecore_dbus_message_increase_length(buf, *old_length + 4);
286 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_OBJECT_PATH, 674 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_OBJECT_PATH, *old_length);
287 *old_length);
288 _ecore_dbus_message_append_uint32(*buf + *old_length, str_len); 675 _ecore_dbus_message_append_uint32(*buf + *old_length, str_len);
289 *old_length += 4; 676 *old_length += 4;
290 _ecore_dbus_message_increase_length(buf, *old_length + str_len + 1); // for the \n 677 /* + 1 for \0 */
291 _ecore_dbus_message_append_nbytes(*buf + *old_length, str, str_len + 1); // append all the string including \n 678 _ecore_dbus_message_increase_length(buf, *old_length + str_len + 1);
679 _ecore_dbus_message_append_nbytes(*buf + *old_length, (unsigned char *)str, str_len + 1);
292 *old_length += str_len + 1; 680 *old_length += str_len + 1;
293 681
294 return f; 682 return f;
295} 683}
296 684
297Ecore_DBus_Message_Field * 685static Ecore_DBus_Message_Field *
298_ecore_dbus_message_marshal_string(unsigned char **buf, 686_ecore_dbus_message_marshal_string(unsigned char **buf,
299 unsigned int *old_length, unsigned char *str) 687 unsigned int *old_length, char *str)
300{ 688{
301 int str_len; 689 int str_len;
302 Ecore_DBus_Message_Field *f; 690 Ecore_DBus_Message_Field *f;
303 691
304 _ecore_dbus_message_increase_length(buf, *old_length + 1); // increase the length + 1, new_length changed 692 /* increase the length + 1, new_length changed */
305 _ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_STRING); // append the data type 693 _ecore_dbus_message_increase_length(buf, *old_length + 1);
306 *old_length += 1; // old_length = new_length 694 /* append the data type */
695 _ecore_dbus_message_append_byte(*buf + *old_length, ECORE_DBUS_DATA_TYPE_STRING);
696 *old_length += 1;
307 697
308 str_len = strlen((char *)str); 698 str_len = strlen(str);
309 _ecore_dbus_message_4byte_padding(buf, old_length); 699 _ecore_dbus_message_4byte_padding(buf, old_length);
310 _ecore_dbus_message_increase_length(buf, *old_length + 4); 700 _ecore_dbus_message_increase_length(buf, *old_length + 4);
311 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRING, *old_length); 701 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRING, *old_length);
312 _ecore_dbus_message_append_uint32(*buf + *old_length, str_len); 702 _ecore_dbus_message_append_uint32(*buf + *old_length, str_len);
313 *old_length += 4; 703 *old_length += 4;
314 _ecore_dbus_message_increase_length(buf, *old_length + str_len + 1); // for the \n 704 /* + 1 for \0 */
315 _ecore_dbus_message_append_nbytes(*buf + *old_length, str, str_len + 1); // append all the string including \n 705 _ecore_dbus_message_increase_length(buf, *old_length + str_len + 1);
706 _ecore_dbus_message_append_nbytes(*buf + *old_length, (unsigned char *)str, str_len + 1);
316 *old_length += str_len + 1; 707 *old_length += str_len + 1;
317 return f; 708 return f;
318} 709}
319 710
320Ecore_DBus_Message_Field * 711#if 0
712static Ecore_DBus_Message_Field *
321_ecore_dbus_message_marshal_array(unsigned char **msg, unsigned int *old_length) 713_ecore_dbus_message_marshal_array(unsigned char **msg, unsigned int *old_length)
322{ 714{
715 /* TODO: complete this */
323 Ecore_DBus_Message_Field *f; 716 Ecore_DBus_Message_Field *f;
324 717
325 _ecore_dbus_message_8byte_padding(msg, old_length); 718 _ecore_dbus_message_8byte_padding(msg, old_length);
326 _ecore_dbus_message_increase_length(msg, *old_length + 4); // for the array length value 719 /* for the array length value */
720 _ecore_dbus_message_increase_length(msg, *old_length + 4);
327 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_ARRAY, *old_length); 721 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_ARRAY, *old_length);
328 *old_length += 4; 722 *old_length += 4;
329 return f; 723 return f;
330} 724}
725#endif
331 726
332Ecore_DBus_Message_Field * 727static Ecore_DBus_Message_Field *
333_ecore_dbus_message_marshal_data(unsigned char **buf, unsigned int *old_length, 728_ecore_dbus_message_marshal_data(unsigned char **buf, unsigned int *old_length,
334 Ecore_DBus_Data_Type type, void *data) 729 Ecore_DBus_Data_Type type, void *data)
335{ 730{
@@ -343,30 +738,36 @@ _ecore_dbus_message_marshal_data(unsigned char **buf, unsigned int *old_length,
343 break; 738 break;
344 case ECORE_DBUS_DATA_TYPE_STRING: 739 case ECORE_DBUS_DATA_TYPE_STRING:
345 f = _ecore_dbus_message_marshal_string(buf, old_length, 740 f = _ecore_dbus_message_marshal_string(buf, old_length,
346 (unsigned char *)data); 741 (char *)data);
347 break; 742 break;
348 case ECORE_DBUS_DATA_TYPE_OBJECT_PATH: 743 case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
349 f = _ecore_dbus_message_marshal_path(buf, old_length, 744 f = _ecore_dbus_message_marshal_object_path(buf, old_length,
350 (unsigned char *)data); 745 (char *)data);
351 break; 746 break;
352 case ECORE_DBUS_DATA_TYPE_INVALID: 747 case ECORE_DBUS_DATA_TYPE_INVALID:
353 case ECORE_DBUS_DATA_TYPE_BYTE: 748 case ECORE_DBUS_DATA_TYPE_BYTE:
354 case ECORE_DBUS_DATA_TYPE_BOOLEAN: 749 case ECORE_DBUS_DATA_TYPE_BOOLEAN:
750 case ECORE_DBUS_DATA_TYPE_INT16:
751 case ECORE_DBUS_DATA_TYPE_UINT16:
355 case ECORE_DBUS_DATA_TYPE_INT32: 752 case ECORE_DBUS_DATA_TYPE_INT32:
356 case ECORE_DBUS_DATA_TYPE_INT64: 753 case ECORE_DBUS_DATA_TYPE_INT64:
357 case ECORE_DBUS_DATA_TYPE_UINT64: 754 case ECORE_DBUS_DATA_TYPE_UINT64:
358 case ECORE_DBUS_DATA_TYPE_DOUBLE: 755 case ECORE_DBUS_DATA_TYPE_DOUBLE:
359 case ECORE_DBUS_DATA_TYPE_CUSTOM: 756 case ECORE_DBUS_DATA_TYPE_SIGNATURE:
360 case ECORE_DBUS_DATA_TYPE_ARRAY: 757 case ECORE_DBUS_DATA_TYPE_ARRAY:
361 case ECORE_DBUS_DATA_TYPE_DICT: 758 case ECORE_DBUS_DATA_TYPE_VARIANT:
759 case ECORE_DBUS_DATA_TYPE_STRUCT:
760 case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
761#if 0
362 default: 762 default:
763#endif
363 printf("[ecore_dbus] unknown/unhandled data type %c\n", type); 764 printf("[ecore_dbus] unknown/unhandled data type %c\n", type);
364 break; 765 break;
365 } 766 }
366 return f; 767 return f;
367} 768}
368 769
369Ecore_DBus_Message_Field * 770static Ecore_DBus_Message_Field *
370_ecore_dbus_message_marshal_custom_header(unsigned char **buf, 771_ecore_dbus_message_marshal_custom_header(unsigned char **buf,
371 unsigned int *old_length, 772 unsigned int *old_length,
372 unsigned int code, 773 unsigned int code,
@@ -374,18 +775,20 @@ _ecore_dbus_message_marshal_custom_header(unsigned char **buf,
374{ 775{
375 Ecore_DBus_Message_Field *f; 776 Ecore_DBus_Message_Field *f;
376 777
377 _ecore_dbus_message_increase_length(buf, *old_length + 1); // increase the length + 1, old_length changed 778 /* increase the length + 1, old_length changed */
378 _ecore_dbus_message_append_byte(*buf + *old_length, code); // append header field name at cur_length 779 _ecore_dbus_message_increase_length(buf, *old_length + 1);
780 /* append header field name at cur_length */
781 _ecore_dbus_message_append_byte(*buf + *old_length, code);
379 *old_length += 1; 782 *old_length += 1;
380 f = _ecore_dbus_message_marshal_data(buf, old_length, type, data); // marshal header field data 783 /* marshal header field data */
784 f = _ecore_dbus_message_marshal_data(buf, old_length, type, data);
381 f->hfield = code; 785 f->hfield = code;
382 return f; 786 return f;
383} 787}
384 788
385/* unmarshal functions */ 789/* unmarshal functions */
386/***********************/
387 790
388Ecore_DBus_Message_Field * 791static Ecore_DBus_Message_Field *
389_ecore_dbus_message_unmarshal_int32(unsigned char *buf, 792_ecore_dbus_message_unmarshal_int32(unsigned char *buf,
390 unsigned int *old_length) 793 unsigned int *old_length)
391{ 794{
@@ -395,10 +798,9 @@ _ecore_dbus_message_unmarshal_int32(unsigned char *buf,
395 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_INT32, *old_length); 798 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_INT32, *old_length);
396 *old_length += 4; 799 *old_length += 4;
397 return f; 800 return f;
398
399} 801}
400 802
401Ecore_DBus_Message_Field * 803static Ecore_DBus_Message_Field *
402_ecore_dbus_message_unmarshal_uint32(unsigned char *buf, 804_ecore_dbus_message_unmarshal_uint32(unsigned char *buf,
403 unsigned int *old_length) 805 unsigned int *old_length)
404{ 806{
@@ -408,15 +810,14 @@ _ecore_dbus_message_unmarshal_uint32(unsigned char *buf,
408 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_UINT32, *old_length); 810 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_UINT32, *old_length);
409 *old_length += 4; 811 *old_length += 4;
410 return f; 812 return f;
411
412} 813}
413 814
414Ecore_DBus_Message_Field * 815static Ecore_DBus_Message_Field *
415_ecore_dbus_message_unmarshal_string(unsigned char *buf, 816_ecore_dbus_message_unmarshal_string(unsigned char *buf,
416 unsigned int *old_length) 817 unsigned int *old_length)
417{ 818{
418 Ecore_DBus_Message_Field *f; 819 Ecore_DBus_Message_Field *f;
419 unsigned long str_len; 820 unsigned long str_len;
420 821
421 _ecore_dbus_message_skip_4byte_padding(old_length); 822 _ecore_dbus_message_skip_4byte_padding(old_length);
422 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRING, *old_length); 823 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_STRING, *old_length);
@@ -426,11 +827,11 @@ _ecore_dbus_message_unmarshal_string(unsigned char *buf,
426 return f; 827 return f;
427} 828}
428 829
429Ecore_DBus_Message_Field * 830static Ecore_DBus_Message_Field *
430_ecore_dbus_message_unmarshal_path(unsigned char *buf, unsigned int *old_length) 831_ecore_dbus_message_unmarshal_object_path(unsigned char *buf, unsigned int *old_length)
431{ 832{
432 Ecore_DBus_Message_Field *f; 833 Ecore_DBus_Message_Field *f;
433 unsigned long str_len; 834 unsigned long str_len;
434 835
435 _ecore_dbus_message_skip_4byte_padding(old_length); 836 _ecore_dbus_message_skip_4byte_padding(old_length);
436 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_OBJECT_PATH, 837 f = _ecore_dbus_message_new_field(ECORE_DBUS_DATA_TYPE_OBJECT_PATH,
@@ -441,11 +842,13 @@ _ecore_dbus_message_unmarshal_path(unsigned char *buf, unsigned int *old_length)
441 return f; 842 return f;
442} 843}
443 844
444Ecore_DBus_Message_Field * 845static Ecore_DBus_Message_Field *
445_ecore_dbus_message_unmarshal_data(unsigned char *buf, unsigned int *old_length) 846_ecore_dbus_message_unmarshal_data(unsigned char *buf, unsigned int *old_length)
446{ 847{
447 Ecore_DBus_Message_Field *f = NULL; 848 Ecore_DBus_Message_Field *f = NULL;
448 unsigned char type = _ecore_dbus_message_read_byte(buf + *old_length); 849 unsigned char type;
850
851 type = _ecore_dbus_message_read_byte(buf + *old_length);
449 852
450 *old_length += 1; 853 *old_length += 1;
451 switch (type) 854 switch (type)
@@ -460,50 +863,53 @@ _ecore_dbus_message_unmarshal_data(unsigned char *buf, unsigned int *old_length)
460 f = _ecore_dbus_message_unmarshal_string(buf, old_length); 863 f = _ecore_dbus_message_unmarshal_string(buf, old_length);
461 break; 864 break;
462 case ECORE_DBUS_DATA_TYPE_OBJECT_PATH: 865 case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
463 f = _ecore_dbus_message_unmarshal_path(buf, old_length); 866 f = _ecore_dbus_message_unmarshal_object_path(buf, old_length);
464 break; 867 break;
465 case ECORE_DBUS_DATA_TYPE_BYTE: 868 case ECORE_DBUS_DATA_TYPE_BYTE:
466 case ECORE_DBUS_DATA_TYPE_BOOLEAN: 869 case ECORE_DBUS_DATA_TYPE_BOOLEAN:
467 case ECORE_DBUS_DATA_TYPE_INT64: 870 case ECORE_DBUS_DATA_TYPE_INT64:
468 case ECORE_DBUS_DATA_TYPE_UINT64: 871 case ECORE_DBUS_DATA_TYPE_UINT64:
469 case ECORE_DBUS_DATA_TYPE_DOUBLE: 872 case ECORE_DBUS_DATA_TYPE_DOUBLE:
470 case ECORE_DBUS_DATA_TYPE_CUSTOM:
471 case ECORE_DBUS_DATA_TYPE_ARRAY: 873 case ECORE_DBUS_DATA_TYPE_ARRAY:
472 case ECORE_DBUS_DATA_TYPE_DICT: 874 case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
473 case ECORE_DBUS_DATA_TYPE_INVALID: 875 case ECORE_DBUS_DATA_TYPE_INVALID:
876#if 0
474 default: 877 default:
878#endif
475 printf("[ecore_dbus] unknown/unhandled data type %c\n", type); 879 printf("[ecore_dbus] unknown/unhandled data type %c\n", type);
476 break; 880 break;
477 } 881 }
478 return f; 882 return f;
479} 883}
480 884
481Ecore_DBus_Message_Field * 885static Ecore_DBus_Message_Field *
482_ecore_dbus_message_unmarshal_custom_header(unsigned char *buf, 886_ecore_dbus_message_unmarshal_custom_header(unsigned char *buf,
483 unsigned int *old_length) 887 unsigned int *old_length)
484{ 888{
485 Ecore_DBus_Message_Field *f; 889 Ecore_DBus_Message_Field *f;
486 unsigned int code; 890 unsigned int code;
487 891
488 code = _ecore_dbus_message_read_byte(buf + *old_length); // get header field name at cur_length 892 /* get header field name at cur_length */
893 code = _ecore_dbus_message_read_byte(buf + *old_length);
489 *old_length += 1; 894 *old_length += 1;
490 f = _ecore_dbus_message_unmarshal_data(buf, old_length); // unmarshal header field data 895 /* unmarshal header field data */
896 f = _ecore_dbus_message_unmarshal_data(buf, old_length);
491 f->hfield = code; 897 f->hfield = code;
492 return f; 898 return f;
493} 899}
494 900
495Ecore_DBus_Message * 901static Ecore_DBus_Message *
496_ecore_dbus_message_unmarshal(Ecore_DBus_Server * svr, unsigned char *message) 902_ecore_dbus_message_unmarshal(Ecore_DBus_Server *svr, unsigned char *message)
497{ 903{
498 Ecore_DBus_Message_Field *f; 904 Ecore_DBus_Message_Field *f;
499 905
500 /* init */ 906 /* init */
501 /********/
502 Ecore_DBus_Message *msg = _ecore_dbus_message_new(svr); 907 Ecore_DBus_Message *msg = _ecore_dbus_message_new(svr);
503 908
504 printf("[ecore_dbus] unmarshaling\n"); 909 printf("[ecore_dbus] unmarshaling\n");
910
505 /* message header */ 911 /* message header */
506 /******************/ 912
507 /* common fields */ 913 /* common fields */
508 msg->byte_order = *(message + 0); 914 msg->byte_order = *(message + 0);
509 msg->type = *(message + 1); 915 msg->type = *(message + 1);
@@ -528,8 +934,8 @@ _ecore_dbus_message_unmarshal(Ecore_DBus_Server * svr, unsigned char *message)
528 msg->header_fields = _ecore_list2_append(msg->header_fields, f); 934 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
529 } 935 }
530 msg->hpos = msg->hlength; 936 msg->hpos = msg->hlength;
937
531 /* message body */ 938 /* message body */
532 /****************/
533 message += msg->hlength; 939 message += msg->hlength;
534 _ecore_dbus_message_increase_length(&msg->body, msg->blength); 940 _ecore_dbus_message_increase_length(&msg->body, msg->blength);
535 _ecore_dbus_message_append_nbytes(msg->body, message, msg->blength); 941 _ecore_dbus_message_append_nbytes(msg->body, message, msg->blength);
@@ -543,29 +949,38 @@ _ecore_dbus_message_unmarshal(Ecore_DBus_Server * svr, unsigned char *message)
543} 949}
544 950
545/* header functions */ 951/* header functions */
546/********************/ 952
547void 953static void
548_ecore_dbus_message_common_header(Ecore_DBus_Message * msg, int type, int flags) 954_ecore_dbus_message_common_header(Ecore_DBus_Message *msg, int type, int flags)
549{ 955{
550 _ecore_dbus_message_increase_lengthz(&msg->header, msg->hpos, 16); // the body,header length arent filled only alloc 956 /* the body,header length arent filled only alloc */
551 msg->header[0] = msg->byte_order = 'l'; // endiannes (1) 957 _ecore_dbus_message_append_length(&msg->header, msg->hpos, 16);
552 msg->header[1] = msg->type = (char)type; // type (1) 958 /* endiannes (1) */
553 msg->header[2] = msg->flags = 0x0; // flags (1) 0x1 = no reply expected, 0x2 auto activiation 959 msg->header[0] = msg->byte_order = 'l';
554 msg->header[3] = msg->protocol = 0x0; // protocol (1) 960 /* type (1) */
555 msg->ref_server->cnt_msg++; // autoincrement the client_serial (0 is invalid) 961 msg->header[1] = msg->type = (char)type;
962 /* flags (1) 0x1 = no reply expected, 0x2 auto activiation */
963 msg->header[2] = msg->flags = 0x0;
964 /* protocol (1) */
965 msg->header[3] = msg->protocol = 0x0;
966 /* autoincrement the client_serial (0 is invalid) */
967 msg->ref_server->cnt_msg++;
968
556 *(msg->header + 12) = msg->serial = msg->ref_server->cnt_msg; 969 *(msg->header + 12) = msg->serial = msg->ref_server->cnt_msg;
557 msg->hpos = 16; 970 msg->hpos = 16;
558} 971}
559 972
560void * 973static void *
561_ecore_dbus_get_field(unsigned char *buf, Ecore_DBus_Message_Field * f) 974_ecore_dbus_get_field(unsigned char *buf, Ecore_DBus_Message_Field *f)
562{ 975{
563 switch (f->type) 976 switch (f->type)
564 { 977 {
565 case ECORE_DBUS_DATA_TYPE_INT32:
566 case ECORE_DBUS_DATA_TYPE_UINT32:
567 case ECORE_DBUS_DATA_TYPE_BYTE: 978 case ECORE_DBUS_DATA_TYPE_BYTE:
568 case ECORE_DBUS_DATA_TYPE_BOOLEAN: 979 case ECORE_DBUS_DATA_TYPE_BOOLEAN:
980 case ECORE_DBUS_DATA_TYPE_INT16:
981 case ECORE_DBUS_DATA_TYPE_UINT16:
982 case ECORE_DBUS_DATA_TYPE_INT32:
983 case ECORE_DBUS_DATA_TYPE_UINT32:
569 case ECORE_DBUS_DATA_TYPE_INT64: 984 case ECORE_DBUS_DATA_TYPE_INT64:
570 case ECORE_DBUS_DATA_TYPE_UINT64: 985 case ECORE_DBUS_DATA_TYPE_UINT64:
571 case ECORE_DBUS_DATA_TYPE_DOUBLE: 986 case ECORE_DBUS_DATA_TYPE_DOUBLE:
@@ -575,11 +990,15 @@ _ecore_dbus_get_field(unsigned char *buf, Ecore_DBus_Message_Field * f)
575 case ECORE_DBUS_DATA_TYPE_OBJECT_PATH: 990 case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
576 return buf + f->offset + 4; 991 return buf + f->offset + 4;
577 break; 992 break;
578 case ECORE_DBUS_DATA_TYPE_CUSTOM:
579 case ECORE_DBUS_DATA_TYPE_ARRAY:
580 case ECORE_DBUS_DATA_TYPE_DICT:
581 case ECORE_DBUS_DATA_TYPE_INVALID: 993 case ECORE_DBUS_DATA_TYPE_INVALID:
994 case ECORE_DBUS_DATA_TYPE_SIGNATURE:
995 case ECORE_DBUS_DATA_TYPE_ARRAY:
996 case ECORE_DBUS_DATA_TYPE_VARIANT:
997 case ECORE_DBUS_DATA_TYPE_STRUCT:
998 case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
999#if 0
582 default: 1000 default:
1001#endif
583 printf("[ecore_dbus] unknown/unhandled data type %c\n", f->type); 1002 printf("[ecore_dbus] unknown/unhandled data type %c\n", f->type);
584 break; 1003 break;
585 1004
@@ -587,308 +1006,9 @@ _ecore_dbus_get_field(unsigned char *buf, Ecore_DBus_Message_Field * f)
587 return NULL; 1006 return NULL;
588} 1007}
589 1008
590void *
591ecore_dbus_get_body_field(Ecore_DBus_Message * m, Ecore_DBus_Message_Field * mf,
592 unsigned int pos)
593{
594 Ecore_List2 *l, *list;
595 unsigned int i = 0;
596
597 list = (Ecore_List2 *) mf;
598
599 for (l = list; l; l = l->next)
600 {
601 if (i == pos)
602 return _ecore_dbus_get_field(m->body,
603 (Ecore_DBus_Message_Field *) l);
604 i++;
605 }
606 return NULL;
607}
608
609void *
610ecore_dbus_get_header_field(Ecore_DBus_Message * m,
611 Ecore_DBus_Message_Field * mf,
612 Ecore_DBus_Message_Header_Field hft)
613{
614 Ecore_List2 *l, *list;
615
616 list = (Ecore_List2 *) mf;
617 for (l = list; l; l = l->next)
618 if (((Ecore_DBus_Message_Field *) l)->hfield == hft)
619 return _ecore_dbus_get_field(m->header,
620 (Ecore_DBus_Message_Field *) l);
621 return NULL;
622}
623
624/* printing functions */
625/**********************/
626Ecore_List2 *
627_ecore_dbus_message_print_field(Ecore_List2 * l, unsigned char *buf)
628{
629 int i;
630 Ecore_DBus_Message_Field *f;
631
632 f = (Ecore_DBus_Message_Field *) l;
633 switch (f->type)
634 {
635 case ECORE_DBUS_DATA_TYPE_BYTE:
636 printf
637 ("[ecore_dbus] field BYTE : value offset = %d value = %d\n",
638 f->offset, (char)*(buf + f->offset));
639 break;
640 case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
641 printf
642 ("[ecore_dbus] field PATH : value offset = %d length = %d value = %s\n",
643 f->offset, *(buf + f->offset), (buf + f->offset + 4));
644 break;
645 case ECORE_DBUS_DATA_TYPE_STRING:
646 printf
647 ("[ecore_dbus] field STRING : value offset = %d length = %d value = %s\n",
648 f->offset, *(buf + f->offset), (buf + f->offset + 4));
649 break;
650 case ECORE_DBUS_DATA_TYPE_INT32:
651 printf
652 ("[ecore_dbus] field INT32 : value offset = %d value = %ld\n",
653 f->offset, (long int)*(buf + f->offset));
654 break;
655 case ECORE_DBUS_DATA_TYPE_UINT32:
656 printf
657 ("[ecore_dbus] field UINT32 : value offset = %d value = %lu\n",
658 f->offset, (unsigned long int)*(buf + f->offset));
659 break;
660 case ECORE_DBUS_DATA_TYPE_ARRAY:
661 printf
662 ("[ecore_dbus] field ARRAY : value offset = %d length = %lu elements = %u\n",
663 f->offset, *(unsigned long int *)(buf + f->offset), f->count);
664 printf("[ecore_dbus] * ARRAY elements begin *\n");
665 l = l->next;
666 for (i = 0; i < f->count; i++)
667 l = _ecore_dbus_message_print_field(l, buf);
668 printf("[ecore_dbus] * ARRAY elements end *\n");
669 return l;
670 break;
671 default:
672 printf("[ecore_dbus] field !UNKNOWN! : %c\n", f->type);
673 break;
674 }
675 return l->next;
676}
677
678Ecore_List2 *
679_ecore_dbus_message_print_header_field(Ecore_List2 * l, unsigned char *buf)
680{
681 static const char *header_fields[] =
682 { "INVALID", "PATH", "INTERFACE", "MEMBER", "ERROR_NAME", "REPLY_SERIAL",
683"DESTINATION", "SERIAL", "SIGNATURE" };
684 Ecore_DBus_Message_Field *f;
685
686 f = (Ecore_DBus_Message_Field *) l;
687 printf("[ecore_dbus] header field %s ", header_fields[f->hfield]);
688 l = _ecore_dbus_message_print_field(l, buf);
689 return l;
690}
691
692void
693_ecore_dbus_message_print_fields(Ecore_DBus_Message_Field * f)
694{
695 int i = 0;
696 Ecore_List2 *l;
697
698 l = (Ecore_List2 *) f;
699 while (l)
700 {
701 printf("%d\n", i);
702 l = l->next;
703 i++;
704 }
705
706}
707
708void
709_ecore_dbus_message_print_raw(unsigned char *msg, unsigned int msg_len)
710{
711 int i;
712
713 printf("[ecore_dbus] raw message:\n");
714 for (i = 0; i < msg_len; i++)
715 {
716 if (msg[i] == 0)
717 printf(",");
718 else if (msg[i] < 21)
719 printf("*");
720 else
721 printf("%c", msg[i]);
722 }
723 printf("\n");
724 printf("[ecore_dbus] end raw message\n");
725}
726
727void
728ecore_dbus_message_print(Ecore_DBus_Message * msg)
729{
730 Ecore_List2 *list;
731 static const char *msg_type[] =
732 { "INVALID", "METHOD_CALL", "METHOD_RETURN", "ERROR", "SIGNAL" };
733 printf("[ecore_dbus] per field message:\n");
734 printf("[ecore_dbus] header fields:\n");
735 /* header common fields */
736 printf("[ecore_dbus] header endianess : %c\n", msg->byte_order);
737 printf("[ecore_dbus] header type : %s\n", msg_type[msg->type]);
738 printf("[ecore_dbus] header flags : %c\n", msg->flags + 48);
739 printf("[ecore_dbus] header protocol : %c\n", msg->protocol + 48);
740 printf("[ecore_dbus] header hlength : %u\n",
741 *(unsigned int *)(msg->header + 4));
742 printf("[ecore_dbus] header blength : %lu\n", msg->blength);
743 printf("[ecore_dbus] header serial : %lu\n", msg->serial);
744
745 /* header custom fields */
746 list = (Ecore_List2 *) msg->header_fields;
747 while (list)
748 {
749 list = _ecore_dbus_message_print_header_field(list, msg->header);
750 }
751 /* body fields */
752 printf("[ecore_dbus] body fields:\n");
753 list = (Ecore_List2 *) msg->body_fields;
754 while (list)
755 {
756 list = _ecore_dbus_message_print_field(list, msg->body);
757 }
758 printf("[ecore_dbus] end per field message\n");
759
760}
761
762/* message type functions */
763/**************************/
764/* podria retornar el id del mensaje, para asi saber las respuestas y poderlas referenciar en el cliente */
765/* la idea aca seria hacer una funcion q llame metodos remotos, or ej: ("org.freedesktop.DBus", "/org/freedesktop/DBus","org.freedesktop.DBus","AddMatch","%s",rule);*/
766/* el parsing de los argumentos a la funcion podrian ser similares al printf s = string, d = int, f = float etc */
767
768unsigned int
769ecore_dbus_message_new_method_call(Ecore_DBus_Server * svr, char *service,
770 char *path, char *interface, char *method,
771 char *fmt, ...)
772{
773 va_list ap;
774
775 Ecore_DBus_Message_Field *f;
776
777 /* init message */
778 Ecore_DBus_Message *msg = _ecore_dbus_message_new(svr);
779
780 /* common header */
781 _ecore_dbus_message_common_header(msg, ECORE_DBUS_MESSAGE_TYPE_METHOD_CALL,
782 0);
783 /* custom header */
784 if (path)
785 {
786 f = _ecore_dbus_message_marshal_custom_header(&msg->header, &msg->hpos,
787 1,
788 ECORE_DBUS_DATA_TYPE_OBJECT_PATH,
789 path);
790 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
791 }
792
793 if (interface)
794 {
795 f = _ecore_dbus_message_marshal_custom_header(&msg->header, &msg->hpos,
796 2,
797 ECORE_DBUS_DATA_TYPE_STRING,
798 interface);
799 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
800 }
801 if (method)
802 {
803 f = _ecore_dbus_message_marshal_custom_header(&msg->header, &msg->hpos,
804 3,
805 ECORE_DBUS_DATA_TYPE_STRING,
806 method);
807 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
808 }
809 if (service)
810 {
811 f = _ecore_dbus_message_marshal_custom_header(&msg->header, &msg->hpos,
812 6,
813 ECORE_DBUS_DATA_TYPE_STRING,
814 service);
815 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
816 }
817 if (fmt)
818 {
819 f = _ecore_dbus_message_marshal_custom_header(&msg->header, &msg->hpos,
820 8,
821 ECORE_DBUS_DATA_TYPE_STRING,
822 fmt);
823 msg->header_fields = _ecore_list2_append(msg->header_fields, f);
824 }
825 _ecore_dbus_message_8byte_padding(&msg->header, &msg->hpos);
826 /* header length */
827 *(msg->header + 4) = msg->hlength = msg->hpos;
828 /* message body */
829 va_start(ap, fmt);
830 while (*fmt)
831 {
832 switch (*fmt)
833 {
834 case ECORE_DBUS_DATA_TYPE_UINT32:
835 f = _ecore_dbus_message_marshal_uint32(&msg->body, &msg->bpos,
836 va_arg(ap, unsigned long));
837 msg->body_fields = _ecore_list2_append(msg->body_fields, f);
838 break;
839 case ECORE_DBUS_DATA_TYPE_STRING:
840 f = _ecore_dbus_message_marshal_string(&msg->body, &msg->bpos,
841 (unsigned char *)va_arg(ap, char *));
842 msg->body_fields = _ecore_list2_append(msg->body_fields, f);
843 break;
844 case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
845 f = _ecore_dbus_message_marshal_path(&msg->body, &msg->bpos,
846 (unsigned char *)va_arg(ap, char *));
847 msg->body_fields = _ecore_list2_append(msg->body_fields, f);
848 break;
849 case ECORE_DBUS_DATA_TYPE_INVALID:
850 case ECORE_DBUS_DATA_TYPE_BYTE:
851 case ECORE_DBUS_DATA_TYPE_BOOLEAN:
852 case ECORE_DBUS_DATA_TYPE_INT32:
853 case ECORE_DBUS_DATA_TYPE_INT64:
854 case ECORE_DBUS_DATA_TYPE_UINT64:
855 case ECORE_DBUS_DATA_TYPE_DOUBLE:
856 case ECORE_DBUS_DATA_TYPE_CUSTOM:
857 case ECORE_DBUS_DATA_TYPE_ARRAY:
858 case ECORE_DBUS_DATA_TYPE_DICT:
859 default:
860 printf("[ecore_dbus] unknown/unhandled data type %c\n", *fmt);
861 break;
862 }
863 fmt++;
864 }
865 va_end(ap);
866 *(unsigned int *)(msg->header + 8) = msg->blength = msg->bpos;
867 /* show message */
868 /*ecore_dbus_message_print(msg);
869 * _ecore_dbus_message_print_raw(msg->header,msg->hlength);
870 * _ecore_dbus_message_print_raw(msg->body,msg->blength); */
871 /* send message */
872 ecore_dbus_server_send(svr, (char *)msg->header, msg->hlength);
873 if (msg->body)
874 ecore_dbus_server_send(svr, (char *)msg->body, msg->blength);
875 /* free data TODO free the list of fields */
876 /*for(i=0; i<8; i++)
877 * free(msg->header_fields[i]);
878 * free(msg->buf);
879 * free(msg); */
880 return msg->serial;
881}
882
883/*******************/
884/* ecore_dbus_auth */
885/*******************/
886
887static char *_ecore_dbus_getuid(void);
888static char *_ecore_dbus_hex_encode(char *src_str);
889
890/* helper functions */ 1009/* helper functions */
891static char * 1010
1011static char *
892_ecore_dbus_getuid(void) 1012_ecore_dbus_getuid(void)
893{ 1013{
894 /* this calculation is from comp.lang.c faq */ 1014 /* this calculation is from comp.lang.c faq */
@@ -909,7 +1029,7 @@ _ecore_dbus_getuid(void)
909 1029
910/* encodes a string into a string of hex values */ 1030/* encodes a string into a string of hex values */
911/* each byte is two hex digits */ 1031/* each byte is two hex digits */
912static char * 1032static char *
913_ecore_dbus_hex_encode(char *src_str) 1033_ecore_dbus_hex_encode(char *src_str)
914{ 1034{
915 const char hexdigits[16] = { 1035 const char hexdigits[16] = {
@@ -939,6 +1059,8 @@ _ecore_dbus_hex_encode(char *src_str)
939 return enc_str; 1059 return enc_str;
940} 1060}
941 1061
1062/* auth functions */
1063
942unsigned char * 1064unsigned char *
943_ecore_dbus_auth_external(void *data) 1065_ecore_dbus_auth_external(void *data)
944{ 1066{
@@ -953,300 +1075,230 @@ _ecore_dbus_auth_external(void *data)
953 return (unsigned char *)msg; 1075 return (unsigned char *)msg;
954} 1076}
955 1077
956/*****************************/ 1078/* con functions */
957/* main ecore_dbus functions */
958/*****************************/
959
960int ECORE_DBUS_EVENT_CLIENT_ADD = 0;
961int ECORE_DBUS_EVENT_CLIENT_DEL = 0;
962int ECORE_DBUS_EVENT_SERVER_ADD = 0;
963int ECORE_DBUS_EVENT_SERVER_DEL = 0;
964int ECORE_DBUS_EVENT_CLIENT_DATA = 0;
965int ECORE_DBUS_EVENT_SERVER_DATA = 0;
966
967static const Ecore_DBus_Auth auths[] = {
968 {"EXTERNAL", 1, {_ecore_dbus_auth_external, NULL, NULL, NULL, NULL}},
969 {"MAGIC_COOKIE", 0, {NULL, NULL, NULL, NULL, NULL}},
970 {"DBUS_COOKIE_SHA1", 0, {NULL, NULL, NULL, NULL, NULL}},
971 {"KERBEROS_V4", 0, {NULL, NULL, NULL, NULL, NULL}},
972 {"SKEY", 0, {NULL, NULL, NULL, NULL, NULL}},
973};
974
975static int init_count = 0;
976static Ecore_List *servers = NULL;
977static Ecore_Event_Handler *handler[6];
978
979static int _ecore_dbus_event_client_add(void *data, int ev_type,
980 void *ev);
981static int _ecore_dbus_event_client_del(void *data, int ev_type,
982 void *ev);
983static int _ecore_dbus_event_server_add(void *data, int ev_type,
984 void *ev);
985static int _ecore_dbus_event_server_del(void *data, int ev_type,
986 void *ev);
987static int _ecore_dbus_event_client_data(void *data, int ev_type,
988 void *ev);
989static int _ecore_dbus_event_server_data(void *data, int ev_type,
990 void *ev);
991/* helpers */
992void _ecore_dbus_message_free(void *data, void *ev);
993 1079
994int 1080static int
995ecore_dbus_init(void) 1081_ecore_dbus_event_server_add(void *data, int ev_type, void *ev)
996{ 1082{
997 int i = 0; 1083 Ecore_DBus_Event_Server_Add *e;
998 1084 Ecore_DBus_Server *svr;
999 if (++init_count != 1) return init_count;
1000
1001 ecore_con_init();
1002
1003 ECORE_DBUS_EVENT_CLIENT_ADD = ecore_event_type_new();
1004 ECORE_DBUS_EVENT_CLIENT_DEL = ecore_event_type_new();
1005 ECORE_DBUS_EVENT_SERVER_ADD = ecore_event_type_new();
1006 ECORE_DBUS_EVENT_SERVER_DEL = ecore_event_type_new();
1007 ECORE_DBUS_EVENT_CLIENT_DATA = ecore_event_type_new();
1008 ECORE_DBUS_EVENT_SERVER_DATA = ecore_event_type_new();
1009 1085
1010 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, 1086 e = ev;
1011 _ecore_dbus_event_client_add, NULL); 1087 if (!_ecore_list2_find(servers, ecore_con_server_data_get(e->server))) return 1;
1012 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL,
1013 _ecore_dbus_event_client_del, NULL);
1014 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD,
1015 _ecore_dbus_event_server_add, NULL);
1016 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL,
1017 _ecore_dbus_event_server_del, NULL);
1018 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA,
1019 _ecore_dbus_event_client_data, NULL);
1020 handler[i++] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
1021 _ecore_dbus_event_server_data, NULL);
1022 1088
1023 return init_count; 1089 svr = ecore_con_server_data_get(e->server);
1090 ecore_dbus_server_send(svr, "\0", 1);
1091 ecore_dbus_server_send(svr, "AUTH\r\n", 6);
1092 printf("[ecore_dbus] begining auth process\n");
1093 return 0;
1024} 1094}
1025 1095
1026int 1096static int
1027ecore_dbus_shutdown(void) 1097_ecore_dbus_event_server_del(void *udata, int ev_type, void *ev)
1028{ 1098{
1029 int i = 0; 1099 Ecore_Con_Event_Server_Del *e;
1030 1100 Ecore_DBus_Server *svr;
1031 if (--init_count != 0) return init_count; 1101 Ecore_DBus_Event_Server_Del *e2;
1032
1033 for (i = 0; i < 6; i++)
1034 ecore_event_handler_del(handler[i]);
1035 1102
1036 ecore_con_shutdown(); 1103 e = ev;
1104 if (!_ecore_list2_find(servers, ecore_con_server_data_get(e->server))) return 1;
1037 1105
1038 return init_count; 1106 svr = ecore_con_server_data_get(e->server);
1107 e2 = calloc(1, sizeof(Ecore_DBus_Event_Server_Del));
1108 if (e2)
1109 {
1110 e2->server = svr;
1111 ecore_event_add(ECORE_DBUS_EVENT_SERVER_DEL, e2, NULL, NULL);
1112 }
1113 return 0;
1039} 1114}
1040 1115
1041Ecore_DBus_Server * 1116static int
1042ecore_dbus_server_connect(Ecore_DBus_Type compl_type, char *name, int port, 1117_ecore_dbus_event_server_data(void *udata, int ev_type, void *ev)
1043 const void *data)
1044{ 1118{
1045 /* TODO */ 1119 Ecore_Con_Event_Server_Data *e;
1046 /* se tiene q conectar por direccion (unix socket path) */ 1120 Ecore_DBus_Server *svr;
1047 /* o por BUS directo */ 1121 Ecore_DBus_Event_Server_Add *svr_add;
1048 1122
1049 Ecore_DBus_Server *svr; 1123 e = ev;
1050 Ecore_DBus_Type type; 1124 if (!_ecore_list2_find(servers, ecore_con_server_data_get(e->server))) return 1;
1051 Ecore_Con_Type extra = 0;
1052 1125
1053 svr = calloc(1, sizeof(Ecore_DBus_Server)); 1126 svr = ecore_con_server_data_get(e->server);
1054 if (!svr) 1127
1055 return NULL; 1128 if (!svr->authenticated)
1056 type = compl_type;
1057 switch (type)
1058 { 1129 {
1059 case ECORE_DBUS_BUS_SESSION: 1130 /* authentication protocol */
1060 svr->server = 1131 const Ecore_DBus_Auth *auth;
1061 ecore_con_server_connect(ECORE_CON_LOCAL_USER | extra, name, port, 1132 Ecore_DBus_Auth_Transaction trans;
1062 svr);
1063 break;
1064 case ECORE_DBUS_BUS_SYSTEM:
1065 svr->server =
1066 ecore_con_server_connect(ECORE_CON_LOCAL_USER | extra, name, port,
1067 svr);
1068 break;
1069 1133
1070 default: 1134 if (!strncmp(e->data, "OK", 2))
1071 free(svr); 1135 {
1072 return NULL; 1136 printf("[ecore_dbus] auth type %s successful\n", auths[svr->auth_type].name);
1137 ecore_dbus_server_send(svr, "BEGIN\r\n", 7);
1138 svr->authenticated = 1;
1139 svr_add = malloc(sizeof(Ecore_DBus_Event_Server_Add));
1140 svr_add->server = svr;
1141 ecore_event_add(ECORE_DBUS_EVENT_SERVER_ADD, svr_add, NULL, NULL);
1142 }
1143 else if (!strncmp(e->data, "DATA", 4))
1144 {
1145 printf("[ecore_dbus] requering data (unaivable)\n");
1146 }
1147 else if (!strncmp(e->data, "ERROR", 5))
1148 {
1149 printf("[ecore_dbus] auth process error\n");
1150 }
1151 else if (!strncmp(e->data, "REJECTED", 8))
1152 {
1153 unsigned char *msg;
1154
1155 if (svr->auth_type >= 0)
1156 printf("[ecore_dbus] auth type %s rejected\n", auths[svr->auth_type].name);
1157 svr->auth_type++;
1158 auth = &auths[svr->auth_type];
1159 trans = auth->transactions[0];
1160 printf("[ecore_dbus] auth type %s started\n", auth->name);
1161 msg = trans(NULL);
1162 ecore_dbus_server_send(svr, (char *)msg, strlen((char *)msg));
1163 free(msg);
1164 }
1073 } 1165 }
1074 if (!svr->server) 1166 else
1075 { 1167 {
1076 printf("no hay servidor\n"); 1168 /* message protocol */
1077 free(svr); 1169 Ecore_DBus_Message *msg;
1078 return NULL; 1170 unsigned int offset = 0;
1079 }
1080 svr->authenticated = 0;
1081 svr->cnt_msg = 0;
1082 svr->auth_type = -1;
1083 svr->auth_type_transaction = 0;
1084 servers = _ecore_list2_append(servers, svr);
1085 1171
1086 return svr; 1172 printf("[ecore_dbus] received server data, %d bytes\n", e->size);
1173 while (e->size)
1174 {
1175 msg = _ecore_dbus_message_unmarshal(svr, (unsigned char *)(e->data) + offset);
1176 if (msg == NULL) break;
1177 offset += msg->hlength + msg->blength;
1178 e->size -= msg->hlength + msg->blength;
1179 printf("[ecore_dbus] dbus message length %lu bytes, still %d\n",
1180 msg->hlength + msg->blength, e->size);
1181 /*ecore_dbus_message_print(msg); */
1182 ecore_event_add(ECORE_DBUS_EVENT_SERVER_DATA, msg, _ecore_dbus_message_free, NULL);
1183 }
1184 }
1185 return 0;
1087} 1186}
1088 1187
1089int 1188/* printing functions */
1090ecore_dbus_server_send(Ecore_DBus_Server * svr, char *command, int length)
1091{
1092 int ret;
1093
1094 ret = ecore_con_server_send(svr->server, command, length);
1095 printf
1096 ("[ecore_dbus] ecore_dbus_server: %p ecore_con_server: %p sent %d of %d bytes\n",
1097 svr, svr->server, ret, length);
1098 return ret;
1099}
1100 1189
1101/* private functions */ 1190static Ecore_DBus_Message_Field *
1102static int 1191_ecore_dbus_message_print_field(Ecore_DBus_Message_Field *f, unsigned char *buf)
1103_ecore_dbus_event_client_add(void *data, int ev_type, void *ev)
1104{ 1192{
1105 printf("CLIENT ADDED \n"); 1193 int i;
1106 printf("this line should appear\n");
1107 return 1;
1108}
1109 1194
1110static int 1195 switch (f->type)
1111_ecore_dbus_event_client_del(void *data, int ev_type, void *ev) 1196 {
1112{ 1197 case ECORE_DBUS_DATA_TYPE_BYTE:
1113 return 0; 1198 printf
1199 ("[ecore_dbus] field BYTE : value offset = %d value = %d\n",
1200 f->offset, (char)*(buf + f->offset));
1201 break;
1202 case ECORE_DBUS_DATA_TYPE_INT32:
1203 printf
1204 ("[ecore_dbus] field INT32 : value offset = %d value = %ld\n",
1205 f->offset, (long int)*(buf + f->offset));
1206 break;
1207 case ECORE_DBUS_DATA_TYPE_UINT32:
1208 printf
1209 ("[ecore_dbus] field UINT32 : value offset = %d value = %lu\n",
1210 f->offset, (unsigned long int)*(buf + f->offset));
1211 break;
1212 case ECORE_DBUS_DATA_TYPE_STRING:
1213 printf
1214 ("[ecore_dbus] field STRING : value offset = %d length = %d value = %s\n",
1215 f->offset, *(buf + f->offset), (buf + f->offset + 4));
1216 break;
1217 case ECORE_DBUS_DATA_TYPE_OBJECT_PATH:
1218 printf
1219 ("[ecore_dbus] field PATH : value offset = %d length = %d value = %s\n",
1220 f->offset, *(buf + f->offset), (buf + f->offset + 4));
1221 break;
1222 case ECORE_DBUS_DATA_TYPE_ARRAY:
1223 {
1224 printf
1225 ("[ecore_dbus] field ARRAY : value offset = %d length = %lu elements = %u\n",
1226 f->offset, *(unsigned long int *)(buf + f->offset), f->count);
1227 printf("[ecore_dbus] * ARRAY elements begin *\n");
1228 f = (Ecore_DBus_Message_Field *)((Ecore_List2 *)f)->next;
1229 for (i = 0; i < f->count; i++)
1230 f = _ecore_dbus_message_print_field(f, buf);
1231 printf("[ecore_dbus] * ARRAY elements end *\n");
1232 return f;
1233 }
1234 break;
1235 case ECORE_DBUS_DATA_TYPE_INVALID:
1236 case ECORE_DBUS_DATA_TYPE_BOOLEAN:
1237 case ECORE_DBUS_DATA_TYPE_INT16:
1238 case ECORE_DBUS_DATA_TYPE_UINT16:
1239 case ECORE_DBUS_DATA_TYPE_INT64:
1240 case ECORE_DBUS_DATA_TYPE_UINT64:
1241 case ECORE_DBUS_DATA_TYPE_DOUBLE:
1242 case ECORE_DBUS_DATA_TYPE_SIGNATURE:
1243 case ECORE_DBUS_DATA_TYPE_VARIANT:
1244 case ECORE_DBUS_DATA_TYPE_STRUCT:
1245 case ECORE_DBUS_DATA_TYPE_DICT_ENTRY:
1246 /* TODO */
1247 printf("[ecore_dbus] field not implemented: %c\n", f->type);
1248 break;
1249#if 0
1250 default:
1251 printf("[ecore_dbus] field !UNKNOWN!: %c\n", f->type);
1252 break;
1253#endif
1254 }
1255 return (Ecore_DBus_Message_Field *)((Ecore_List2 *)f)->next;
1114} 1256}
1115 1257
1116static int 1258static Ecore_DBus_Message_Field *
1117_ecore_dbus_event_server_add(void *data, int ev_type, void *ev) 1259_ecore_dbus_message_print_header_field(Ecore_DBus_Message_Field *f, unsigned char *buf)
1118{ 1260{
1261 static const char *header_fields[] = {
1262 "INVALID", "PATH", "INTERFACE", "MEMBER", "ERROR_NAME",
1263 "REPLY_SERIAL", "DESTINATION", "SERIAL", "SIGNATURE"
1264 };
1119 1265
1120 Ecore_DBus_Event_Server_Add *e; 1266 printf("[ecore_dbus] header field %s ", header_fields[f->hfield]);
1121 1267 return _ecore_dbus_message_print_field(f, buf);
1122 e = ev;
1123 if (!_ecore_list2_find(servers, ecore_con_server_data_get(e->server)))
1124 return 1;
1125 {
1126 Ecore_DBus_Server *svr;
1127
1128 svr = ecore_con_server_data_get(e->server);
1129 ecore_dbus_server_send(svr, "\0", 1);
1130 ecore_dbus_server_send(svr, "AUTH\r\n", 6);
1131 printf("[ecore_dbus] begining auth process\n");
1132 }
1133 return 0;
1134} 1268}
1135 1269
1136static int 1270static void
1137_ecore_dbus_event_server_del(void *udata, int ev_type, void *ev) 1271_ecore_dbus_message_print_fields(Ecore_DBus_Message_Field *f)
1138{ 1272{
1139 Ecore_Con_Event_Server_Del *e; 1273 int i;
1140 1274 Ecore_List2 *l;
1141 e = ev;
1142 if (!_ecore_list2_find(servers, ecore_con_server_data_get(e->server)))
1143 return 1;
1144 {
1145 Ecore_DBus_Server *svr;
1146
1147 svr = ecore_con_server_data_get(e->server);
1148 {
1149 Ecore_DBus_Event_Server_Del *e2;
1150
1151 e2 = calloc(1, sizeof(Ecore_DBus_Event_Server_Del));
1152 if (e2)
1153 {
1154 e2->server = svr;
1155 ecore_event_add(ECORE_DBUS_EVENT_SERVER_DEL, e2, NULL, NULL);
1156 }
1157 }
1158 }
1159 return 0;
1160}
1161 1275
1162static int 1276 i = 0;
1163_ecore_dbus_event_client_data(void *udata, int ev_type, void *ev) 1277 l = (Ecore_List2 *)f;
1164{ 1278 while (l)
1165 printf("CLIENT DATA"); 1279 {
1166 return 1; 1280 printf("%d\n", i);
1281 l = l->next;
1282 i++;
1283 }
1167} 1284}
1168 1285
1169static int 1286static void
1170_ecore_dbus_event_server_data(void *udata, int ev_type, void *ev) 1287_ecore_dbus_message_print_raw(unsigned char *msg, unsigned int msg_len)
1171{ 1288{
1172 Ecore_Con_Event_Server_Data *e; 1289 int i;
1173 1290
1174 e = ev; 1291 printf("[ecore_dbus] raw message:\n");
1175 if (!_ecore_list2_find(servers, ecore_con_server_data_get(e->server))) 1292 for (i = 0; i < msg_len; i++)
1176 return 1; 1293 {
1177 1294 if (msg[i] == 0)
1178 { 1295 printf(",");
1179 Ecore_DBus_Server *svr; 1296 else if (msg[i] < 21)
1180 Ecore_DBus_Event_Server_Add *svr_add; 1297 printf("*");
1181 1298 else
1182 svr = ecore_con_server_data_get(e->server); 1299 printf("%c", msg[i]);
1183 1300 }
1184 /* authentication protocol */ 1301 printf("\n");
1185 /***************************/ 1302 printf("[ecore_dbus] end raw message\n");
1186 if (!svr->authenticated)
1187 {
1188 const Ecore_DBus_Auth *auth;
1189 Ecore_DBus_Auth_Transaction trans;
1190
1191 if (!strncmp(e->data, "OK", 2))
1192 {
1193 printf("[ecore_dbus] auth type %s successful\n",
1194 auths[svr->auth_type].name);
1195 ecore_dbus_server_send(svr, "BEGIN\r\n", 7);
1196 svr->authenticated = 1;
1197 svr_add = malloc(sizeof(Ecore_DBus_Event_Server_Add));
1198 svr_add->server = svr;
1199 ecore_event_add(ECORE_DBUS_EVENT_SERVER_ADD, svr_add, NULL,
1200 NULL);
1201 }
1202 if (!strncmp(e->data, "DATA", 4))
1203 {
1204 printf("[ecore_dbus] requering data (unaivable)\n");
1205 }
1206 if (!strncmp(e->data, "ERROR", 5))
1207 {
1208 printf("[ecore_dbus] auth process error\n");
1209 }
1210 if (!strncmp(e->data, "REJECTED", 8))
1211 {
1212 unsigned char *msg;
1213
1214 if (svr->auth_type >= 0)
1215 printf("[ecore_dbus] auth type %s rejected\n",
1216 auths[svr->auth_type].name);
1217 svr->auth_type++;
1218 auth = &auths[svr->auth_type];
1219 trans = auth->transactions[0];
1220 printf("[ecore_dbus] auth type %s started\n", auth->name);
1221 msg = trans(NULL);
1222 ecore_dbus_server_send(svr, (char *)msg, strlen((char *)msg));
1223 free(msg);
1224
1225 }
1226 }
1227 /* message protocol */
1228 /********************/
1229 else
1230 {
1231 Ecore_DBus_Message *msg;
1232 unsigned int offset = 0;
1233
1234 printf("[ecore_dbus] received server data, %d bytes\n", e->size);
1235 while (e->size)
1236 {
1237 msg = _ecore_dbus_message_unmarshal(svr, e->data + offset);
1238 if (msg == NULL)
1239 break;
1240 offset += msg->hlength + msg->blength;
1241 e->size -= msg->hlength + msg->blength;
1242 printf("[ecore_dbus] dbus message length %lu bytes, still %d\n",
1243 msg->hlength + msg->blength, e->size);
1244 /*ecore_dbus_message_print(msg); */
1245 ecore_event_add(ECORE_DBUS_EVENT_SERVER_DATA, msg,
1246 _ecore_dbus_message_free, NULL);
1247
1248 }
1249 }
1250 }
1251 return 1;
1252} 1303}
1304
diff --git a/legacy/ecore/src/lib/ecore_dbus/ecore_dbus_private.h b/legacy/ecore/src/lib/ecore_dbus/ecore_dbus_private.h
index f9e1a8e54a..9626c485a0 100644
--- a/legacy/ecore/src/lib/ecore_dbus/ecore_dbus_private.h
+++ b/legacy/ecore/src/lib/ecore_dbus/ecore_dbus_private.h
@@ -1,28 +1,80 @@
1/*
2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3 */
1#ifndef _ECORE_DBUS_PRIVATE_H 4#ifndef _ECORE_DBUS_PRIVATE_H
2#define _ECORE_DBUS_PRIVATE_H 5#define _ECORE_DBUS_PRIVATE_H
3 6
4struct _Ecore_DBus_Client 7typedef struct _Ecore_DBus_Auth Ecore_DBus_Auth;
8typedef unsigned char *(*Ecore_DBus_Auth_Transaction)(void *);
9
10typedef enum _Ecore_DBus_Auth_Type
5{ 11{
6 Ecore_DBus_Client *client; 12 ECORE_DBUS_AUTH_TYPE_EXTERNAL,
7}; 13 ECORE_DBUS_AUTH_MAGIC_COOKIE,
14 ECORE_DBUS_AUTH_TYPE_ECORE_DBUS_COOKIE_SHA1,
15 ECORE_DBUS_AUTH_TYPE_KERBEROS_V4,
16 ECORE_DBUS_AUTH_TYPE_SKEY
17} Ecore_DBus_Auth_Type;
18
19typedef enum _Ecore_DBus_Message_Type
20{
21 ECORE_DBUS_MESSAGE_TYPE_INVALID,
22 ECORE_DBUS_MESSAGE_TYPE_METHOD_CALL,
23 ECORE_DBUS_MESSAGE_TYPE_METHOD_RETURN,
24 ECORE_DBUS_MESSAGE_TYPE_ERROR,
25 ECORE_DBUS_MESSAGE_TYPE_SIGNAL
26} Ecore_DBus_Message_Type;
8 27
9struct _Ecore_DBus_Server 28struct _Ecore_DBus_Server
10{ 29{
11 Ecore_List __list_data; 30 Ecore_List2 __list_data;
12 Ecore_Con_Server *server; 31 Ecore_Con_Server *server;
13 Ecore_DBus_Client *clients; 32 int authenticated;
14 /* unsigned char *buf; */ 33 int auth_type;
15 /* int buf_size; */ 34 int auth_type_transaction;
16 unsigned int cnt_msg; 35 int cnt_msg;
17 Ecore_List *msg_queue; 36};
18 /* void *data;*/ 37
19 unsigned int authenticated; 38struct _Ecore_DBus_Message
20 int auth_type; 39{
21 unsigned int auth_type_transaction; 40 /* header fields */
41 unsigned char byte_order;
42 unsigned char type;
43 unsigned char flags;
44 unsigned char protocol;
45 unsigned long hlength;
46 unsigned long blength;
47 unsigned long serial;
48
49 Ecore_DBus_Server *ref_server;
50
51 unsigned char *header;
52 unsigned int hpos;
53 Ecore_DBus_Message_Field *header_fields;
54 unsigned char *body;
55 unsigned int bpos;
56 Ecore_DBus_Message_Field *body_fields;
57 unsigned char *signature;
58};
59
60struct _Ecore_DBus_Message_Field
61{
62 Ecore_List2 __list_data;
63 Ecore_DBus_Data_Type type;
64 unsigned int offset;
65 unsigned int count; /* number of elements, usefull for structs, arrays, dicts */
66 unsigned int hfield; /* if the field is a header field, we need the type of it */
22}; 67};
23 68
69struct _Ecore_DBus_Auth
70{
71 char *name;
72 unsigned int num_transactions;
73 Ecore_DBus_Auth_Transaction transactions[5];
74};
75
76
24/* Errors */ 77/* Errors */
25/* WARNING dont change order or ABI breaks. */
26#define DBUS_ERROR_FAILED "org.freedesktop.DBus.Error.Failed" 78#define DBUS_ERROR_FAILED "org.freedesktop.DBus.Error.Failed"
27#define DBUS_ERROR_NO_MEMORY "org.freedesktop.DBus.Error.NoMemory" 79#define DBUS_ERROR_NO_MEMORY "org.freedesktop.DBus.Error.NoMemory"
28#define DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND "org.freedesktop.DBus.Error.ServiceNotFound" 80#define DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND "org.freedesktop.DBus.Error.ServiceNotFound"