00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00043 #include <stdlib.h>
00044 #include <string.h>
00045 #include <stdarg.h>
00046
00047 #include "easydbus-core.h"
00048 #include "debug.h"
00049 #include "introspect_internal.h"
00050 #include "utils.h"
00051
00062 int
00063 easydbus_add_info_field_on_register_method (EasyDbus_obj_method * method,
00064 unsigned char offset,
00065 char *name_field,
00066 unsigned char type, ...)
00067 {
00068 struct easydbus_introspect_arg_info *el, *list;
00069 struct easydbus_signature_elem_stack *list_elem;
00070 enum el_type elem = EASYDBUS_ELTYPE_INVALID;
00071 int name_length = 0;
00072 va_list ap;
00073
00074 if (method == NULL || name_field == NULL || type > 1)
00075 return -1;
00076
00077 list = el = NULL;
00078 list_elem = NULL;
00079
00080 if (type)
00081 list = method->output_info;
00082 else
00083 list = method->input_info;
00084
00085 if (list != NULL) {
00086
00087
00088 el = list;
00089 while (el != NULL) {
00090 if (el->offset == offset)
00091 return -1;
00092 el = el->next;
00093 }
00094 }
00095
00096 el = (struct easydbus_introspect_arg_info *)
00097 malloc (sizeof (struct easydbus_introspect_arg_info));
00098 if (el == NULL)
00099 return -1;
00100
00101
00102 memset (el, 0,
00103 sizeof (struct easydbus_introspect_arg_info));
00104 el->name = el->signature = NULL;
00105 el->next = NULL;
00106
00107
00108 va_start (ap, type);
00109
00110
00111 elem = va_arg (ap, enum el_type);
00112
00113 while (elem != EASYDBUS_ELTYPE_INVALID) {
00114 list_elem =
00115 easydbus_add_elem_to_stack (elem, list_elem);
00116 elem = va_arg (ap, enum el_type);
00117 }
00118 va_end (ap);
00119
00120 el->signature =
00121 easydbus_create_arg_signature (list_elem);
00122 if (el->signature == NULL)
00123 goto error;
00124 list_elem = NULL;
00125
00126 name_length = strlen (name_field) + 1;
00127 el->name = (char *) malloc (name_length);
00128 if (el->name == NULL)
00129 goto error;
00130
00131 EASYDBUS_MEMCOPY (el->name, name_field, name_length);
00132 el->offset = offset;
00133
00134 if (easydbus_add_new_field_to_list (el, &list))
00135 goto error;
00136
00137 if (type)
00138 method->output_info = list;
00139 else
00140 method->input_info = list;
00141
00142
00143 return 0;
00144
00145 error:
00146 if (el != NULL)
00147 easydbus_free_introspect_info_arg (el);
00148
00149 easydbus_free_elem_from_stack_list (list_elem);
00150
00151 return -1;
00152 }
00153
00154
00164 int
00165 easydbus_add_info_field_on_register_signal (EasyDbus_obj_signal * signal,
00166 unsigned char offset,
00167 char *name_field, ...)
00168 {
00169 struct easydbus_introspect_arg_info *el = NULL;
00170 struct easydbus_signature_elem_stack *list_elem;
00171 enum el_type elem = EASYDBUS_ELTYPE_INVALID;
00172 int name_length = 0;
00173 va_list ap;
00174
00175 if (signal == NULL || name_field == NULL)
00176 return -1;
00177
00178 list_elem = NULL;
00179
00180 if (signal->output_info != NULL) {
00181
00182
00183 el = signal->output_info;
00184 while (el != NULL) {
00185 if (el->offset == offset)
00186 return -1;
00187 el = el->next;
00188 }
00189 }
00190
00191 el = (struct easydbus_introspect_arg_info *)
00192 malloc (sizeof (struct easydbus_introspect_arg_info));
00193 if (el == NULL)
00194 return -1;
00195
00196
00197 memset (el, 0,
00198 sizeof (struct easydbus_introspect_arg_info));
00199 el->name = NULL;
00200 el->next = NULL;
00201
00202
00203 va_start (ap, name_field);
00204
00205
00206 elem = va_arg (ap, enum el_type);
00207
00208 while (elem != EASYDBUS_ELTYPE_INVALID) {
00209 list_elem =
00210 easydbus_add_elem_to_stack (elem, list_elem);
00211 elem = va_arg (ap, enum el_type);
00212 }
00213 va_end (ap);
00214
00215 el->signature =
00216 easydbus_create_arg_signature (list_elem);
00217 if (el->signature == NULL)
00218 goto error;
00219 list_elem = NULL;
00220
00221 name_length = strlen (name_field) + 1;
00222 el->name = (char *) malloc (name_length);
00223 if (el->name == NULL)
00224 goto error;
00225
00226 EASYDBUS_MEMCOPY (el->name, name_field, name_length);
00227 el->offset = offset;
00228
00229 if (easydbus_add_new_field_to_list
00230 (el, &signal->output_info))
00231 goto error;
00232
00233 return 0;
00234
00235 error:
00236 if (el != NULL)
00237 easydbus_free_introspect_info_arg (el);
00238
00239 easydbus_free_elem_from_stack_list (list_elem);
00240
00241 return -1;
00242 }
00243
00244
00255 int
00256 easydbus_enable_introspect_check (EasyDbus_conn * data,
00257 EasyDbus_object * object,
00258 char *obj_path)
00259 {
00260 struct EasyDbus_core *core =
00261 (struct EasyDbus_core *) data;
00262 char *introspect_string = NULL;
00263 introspect_objs_tree *t = NULL;
00264
00265 if (!data || !object)
00266 return -1;
00267
00268
00269 t = easydbus_introspect_objs_tree_build ((struct EasyDbus_object_box *)
00270 object);
00271 if (!t) return -1;
00272
00273
00274 introspect_string =
00275 easydbus_introspect_create_reply_string (obj_path, t,
00276 (struct EasyDbus_object_box *)
00277 object);
00278
00279 easydbus_introspect_objs_tree_destroy (t);
00280
00281 if (!introspect_string)
00282 return -1;
00283 free (introspect_string);
00284
00285 core->handled_introspect = 1;
00286
00287 return 0;
00288 }
00289
00290