1 /* gs_rl_type_driver.c */
3 #include "gs/gs_private.h"
5 GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(NDR_tdriver_rl,NDR);
9 struct s_gs_rl_type_driver {
14 struct s_gs_rl_type_bag {
15 gras_dict_t *incoming_dict;
17 gras_dynar_t *type_dynar;
18 gras_dict_t *type_dict;
20 gras_dynar_t *message_dynar;
21 gras_dict_t *message_dict;
23 gras_dict_t *outgoing_dict;
26 struct s_gs_rl_incoming_connection {
27 struct s_gs_connection *p_connection;
29 gras_dynar_t *type_dynar;
30 gras_dict_t *type_dict;
32 gras_dynar_t *message_dynar;
33 gras_dict_t *message_dict;
36 struct s_gs_rl_outgoing_connection {
37 struct s_gs_connection *p_connection;
38 gras_dict_t *type_marker_dict;
39 gras_dict_t *message_marker_dict;
47 struct s_gs_type_driver_ops *type_driver_ops = NULL;
50 struct s_gs_type_bag_ops *type_bag_ops = NULL;
53 * exported functions, driver part
55 struct s_gs_type_driver_ops *
56 gs_rl_type_driver(void) {
59 type_bag_ops = calloc(1, sizeof(struct s_gs_type_bag_ops));
62 type_bag_ops->_init = gs_rl_bag__init;
63 type_bag_ops->_exit = gs_rl_bag__exit;
66 type_bag_ops->register_incoming_connection = gs_rl_bag_register_incoming_connection;
67 type_bag_ops->register_outgoing_connection = gs_rl_bag_register_outgoing_connection;
70 type_bag_ops->store_type = gs_rl_bag_store_type;
71 type_bag_ops->store_incoming_type = gs_rl_bag_store_incoming_type;
72 type_bag_ops->get_type_by_name = gs_rl_bag_get_type_by_name;
73 type_bag_ops->get_type_by_code = gs_rl_bag_get_type_by_code;
74 type_bag_ops->mark_type = gs_rl_bag_mark_type;
75 type_bag_ops->check_type_mark = gs_rl_bag_check_type_mark;
78 type_bag_ops->store_message = gs_rl_bag_store_message;
79 type_bag_ops->store_incoming_message = gs_rl_bag_store_incoming_message;
80 type_bag_ops->get_message_by_name = gs_rl_bag_get_message_by_name;
81 type_bag_ops->get_message_by_code = gs_rl_bag_get_message_by_code;
82 type_bag_ops->mark_message = gs_rl_bag_mark_message;
83 type_bag_ops->check_message_mark = gs_rl_bag_check_message_mark;
86 if (!type_driver_ops) {
87 type_driver_ops = calloc(1, sizeof(struct s_gs_type_driver_ops));
89 type_driver_ops->_init = gs_rl__init;
90 type_driver_ops->_exit = gs_rl__exit;
93 return type_driver_ops;
97 gs_rl__init(struct s_gs_type_driver *p_driver) {
99 struct s_gs_rl_type_driver *p_rl = NULL;
101 p_rl = calloc(1, sizeof(struct s_gs_rl_type_driver));
102 p_driver->specific = p_rl;
103 p_driver->bag_ops = type_bag_ops;
107 gs_rl__exit(struct s_gs_type_driver *p_driver) {
109 struct s_gs_rl_type_driver *p_rl = p_driver->specific;
112 p_driver->specific = NULL;
116 * exported functions, bag part
121 gs_rl_bag__init(struct s_gs_type_bag *p_bag) {
123 struct s_gs_rl_type_bag *p_rl = NULL;
125 p_rl = calloc(1, sizeof(struct s_gs_rl_type_bag));
127 p_rl->incoming_dict = NULL;
129 gras_dynar_new(&p_rl->type_dynar, sizeof(struct s_gs_type *), NULL);
130 p_rl->type_dict = NULL;
132 gras_dynar_new(&p_rl->message_dynar, sizeof(struct s_gs_type *), NULL);
133 p_rl->message_dict = NULL;
135 p_rl->outgoing_dict = NULL;
137 p_bag->specific = p_rl;
138 p_bag->bag_ops = type_bag_ops;
140 gs_bootstrap_type_bag(p_bag);
144 gs_rl_bag__exit(struct s_gs_type_bag *p_bag) {
146 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
148 gras_dict_free(&p_rl->type_dict);
149 gras_dynar_free(p_rl->type_dynar);
152 p_bag->specific = NULL;
157 gs_rl_bag_register_incoming_connection(struct s_gs_type_bag *p_bag,
158 struct s_gs_connection *p_cnx) {
160 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
161 struct s_gs_rl_incoming_connection *p_in = NULL;
163 if (p_cnx->direction != e_gs_connection_direction_incoming)
164 GS_FAILURE("invalid operation");
166 p_in = malloc(sizeof (struct s_gs_rl_incoming_connection));
168 p_in->p_connection = p_cnx;
170 gras_dynar_new(&p_in->type_dynar, sizeof(struct s_gs_type *), NULL);
171 p_in->type_dict = NULL;
173 gras_dynar_new(&p_in->message_dynar, sizeof(struct s_gs_type *), NULL);
174 p_in->message_dict = NULL;
176 gras_dict_insert_ext(p_rl->incoming_dict,
182 gs_bootstrap_incoming_connection(p_bag, p_cnx);
187 gs_rl_bag_register_outgoing_connection(struct s_gs_type_bag *p_bag,
188 struct s_gs_connection *p_cnx) {
190 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
191 struct s_gs_rl_outgoing_connection *p_out = NULL;
193 if (p_cnx->direction != e_gs_connection_direction_outgoing)
194 GS_FAILURE("invalid operation");
196 p_out = malloc(sizeof (struct s_gs_rl_outgoing_connection));
198 p_out->p_connection = p_cnx;
199 p_out->type_marker_dict = NULL;
200 p_out->message_marker_dict = NULL;
202 gras_dict_insert_ext(p_rl->outgoing_dict, (char *)&p_cnx, sizeof(p_cnx), p_out, NULL);
204 gs_bootstrap_outgoing_connection(p_bag, p_cnx);
210 gs_rl_bag_store_type(struct s_gs_type_bag *p_bag,
211 struct s_gs_connection *p_cnx,
212 struct s_gs_type *p_type) {
214 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
215 struct s_gs_type **pp_type = NULL;
217 pp_type = malloc(sizeof(struct s_gs_type *));
221 struct s_gs_rl_incoming_connection *p_in = NULL;
223 if (p_cnx->direction != e_gs_connection_direction_incoming)
224 GS_FAILURE("invalid operation");
226 gras_dict_retrieve_ext(p_rl->incoming_dict,
232 p_type->code = gras_dynar_length(p_in->type_dynar);
233 gras_dynar_insert_at(p_in->type_dynar, p_type->code, pp_type);
234 gras_dict_insert(p_in->type_dict, p_type->name, pp_type, NULL);
236 p_type->code = gras_dynar_length(p_rl->type_dynar);
237 gras_dynar_insert_at(p_rl->type_dynar, p_type->code, pp_type);
238 gras_dict_insert(p_rl->type_dict, p_type->name, pp_type, NULL);
243 gs_rl_bag_store_incoming_type(struct s_gs_type_bag *p_bag,
244 struct s_gs_connection *p_cnx,
245 struct s_gs_type *p_type) {
247 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
248 struct s_gs_rl_incoming_connection *p_in = NULL;
249 struct s_gs_type **pp_type = NULL;
251 if (p_cnx->direction != e_gs_connection_direction_incoming)
252 GS_FAILURE("invalid operation");
254 gras_dict_retrieve_ext(p_rl->incoming_dict,
259 pp_type = malloc(sizeof(struct s_gs_type *));
262 gras_dynar_set(p_in->type_dynar, p_type->code, pp_type);
263 gras_dict_insert(p_in->type_dict, p_type->name, pp_type, NULL);
267 gs_rl_bag_get_type_by_name(struct s_gs_type_bag *p_bag,
268 struct s_gs_connection *p_cnx,
271 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
272 struct s_gs_type **pp_type = NULL;
275 struct s_gs_rl_incoming_connection *p_in = NULL;
277 if (p_cnx->direction != e_gs_connection_direction_incoming)
278 GS_FAILURE("invalid operation");
280 gras_dict_retrieve_ext(p_rl->incoming_dict,
285 gras_dict_retrieve(p_in->type_dict, name, (void **)&pp_type);
287 gras_dict_retrieve(p_rl->type_dict, name, (void **)&pp_type);
291 DEBUG1("Get type by name '%s': not found",name);
295 DEBUG1("Get type by name '%s': found",name);
300 gs_rl_bag_get_type_by_code(struct s_gs_type_bag *p_bag,
301 struct s_gs_connection *p_cnx,
304 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
305 struct s_gs_type *p_type = NULL;
308 struct s_gs_rl_incoming_connection *p_in = NULL;
310 if (p_cnx->direction != e_gs_connection_direction_incoming)
311 GS_FAILURE("invalid operation");
313 gras_dict_retrieve_ext(p_rl->incoming_dict,
318 if ((unsigned int)code < gras_dynar_length(p_in->type_dynar)) {
319 gras_dynar_get(p_in->type_dynar, code, (void **)&p_type);
322 if ((unsigned int)code < gras_dynar_length(p_rl->type_dynar)) {
323 gras_dynar_get(p_rl->type_dynar, code, (void **)&p_type);
331 gs_rl_bag_mark_type(struct s_gs_type_bag *p_bag,
332 struct s_gs_connection *p_cnx,
335 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
336 struct s_gs_rl_outgoing_connection *p_out = NULL;
338 if (p_cnx->direction != e_gs_connection_direction_outgoing)
339 GS_FAILURE("invalid operation");
341 gras_dict_retrieve_ext(p_rl->outgoing_dict, (char *)&p_cnx, sizeof(p_cnx), (void **)&p_out);
344 GS_FAILURE("unregistered connection");
346 gras_dict_insert(p_out->type_marker_dict, name, strdup(name), NULL);
350 gs_rl_bag_check_type_mark(struct s_gs_type_bag *p_bag,
351 struct s_gs_connection *p_cnx,
354 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
355 struct s_gs_rl_outgoing_connection *p_out = NULL;
358 if (p_cnx->direction != e_gs_connection_direction_outgoing)
359 GS_FAILURE("invalid operation");
361 gras_dict_retrieve_ext(p_rl->outgoing_dict, (char *)&p_cnx, sizeof(p_cnx), (void **)&p_out);
364 GS_FAILURE("unregistered connection");
366 gras_dict_retrieve(p_out->type_marker_dict, name, (void **)&result);
373 gs_rl_bag_store_message(struct s_gs_type_bag *p_bag,
374 struct s_gs_connection *p_cnx,
375 struct s_gs_message *p_message) {
377 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
378 struct s_gs_message **pp_message = NULL;
380 pp_message = malloc(sizeof(struct s_gs_message *));
381 *pp_message = p_message;
384 struct s_gs_rl_incoming_connection *p_in = NULL;
386 if (p_cnx->direction != e_gs_connection_direction_incoming)
387 GS_FAILURE("invalid operation");
389 gras_dict_retrieve_ext(p_rl->incoming_dict,
395 p_message->code = gras_dynar_length(p_in->message_dynar);
396 gras_dynar_insert_at(p_in->message_dynar, p_message->code, pp_message);
397 gras_dict_insert(p_in->message_dict, p_message->name, pp_message, NULL);
399 p_message->code = gras_dynar_length(p_rl->message_dynar);
400 gras_dynar_insert_at(p_rl->message_dynar, p_message->code, pp_message);
401 gras_dict_insert(p_rl->message_dict, p_message->name, pp_message, NULL);
406 gs_rl_bag_store_incoming_message(struct s_gs_type_bag *p_bag,
407 struct s_gs_connection *p_cnx,
408 struct s_gs_message *p_message) {
410 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
411 struct s_gs_rl_incoming_connection *p_in = NULL;
412 struct s_gs_message **pp_message = NULL;
414 if (p_cnx->direction != e_gs_connection_direction_incoming)
415 GS_FAILURE("invalid operation");
417 gras_dict_retrieve_ext(p_rl->incoming_dict,
422 pp_message = malloc(sizeof(struct s_gs_message *));
423 *pp_message = p_message;
425 gras_dynar_set(p_in->message_dynar, p_message->code, pp_message);
426 gras_dict_insert(p_in->message_dict, p_message->name, pp_message, NULL);
429 struct s_gs_message *
430 gs_rl_bag_get_message_by_name(struct s_gs_type_bag *p_bag,
431 struct s_gs_connection *p_cnx,
434 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
435 struct s_gs_message **pp_message = NULL;
438 struct s_gs_rl_incoming_connection *p_in = NULL;
440 if (p_cnx->direction != e_gs_connection_direction_incoming)
441 GS_FAILURE("invalid operation");
443 gras_dict_retrieve_ext(p_rl->incoming_dict,
448 gras_dict_retrieve(p_in->message_dict, name, (void **)&pp_message);
450 gras_dict_retrieve(p_rl->message_dict, name, (void **)&pp_message);
460 struct s_gs_message *
461 gs_rl_bag_get_message_by_code(struct s_gs_type_bag *p_bag,
462 struct s_gs_connection *p_cnx,
465 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
466 struct s_gs_message *p_message = NULL;
469 struct s_gs_rl_incoming_connection *p_in = NULL;
471 if (p_cnx->direction != e_gs_connection_direction_incoming)
472 GS_FAILURE("invalid operation");
474 gras_dict_retrieve_ext(p_rl->incoming_dict,
479 if ((unsigned int)code < gras_dynar_length(p_in->message_dynar)) {
480 gras_dynar_get(p_in->message_dynar, code, (void **)&p_message);
483 if ((unsigned int)code < gras_dynar_length(p_rl->message_dynar)) {
484 gras_dynar_get(p_rl->message_dynar, code, (void **)&p_message);
492 gs_rl_bag_mark_message(struct s_gs_type_bag *p_bag,
493 struct s_gs_connection *p_cnx,
496 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
497 struct s_gs_rl_outgoing_connection *p_out = NULL;
499 if (p_cnx->direction != e_gs_connection_direction_outgoing)
500 GS_FAILURE("invalid operation");
502 gras_dict_retrieve_ext(p_rl->outgoing_dict, (char *)&p_cnx, sizeof(p_cnx), (void **)&p_out);
505 GS_FAILURE("unregistered connection");
507 gras_dict_insert(p_out->message_marker_dict, name, strdup(name), NULL);
511 gs_rl_bag_check_message_mark(struct s_gs_type_bag *p_bag,
512 struct s_gs_connection *p_cnx,
515 struct s_gs_rl_type_bag *p_rl = p_bag->specific;
516 struct s_gs_rl_outgoing_connection *p_out = NULL;
519 if (p_cnx->direction != e_gs_connection_direction_outgoing)
520 GS_FAILURE("invalid operation");
522 gras_dict_retrieve_ext(p_rl->outgoing_dict, (char *)&p_cnx, sizeof(p_cnx), (void **)&p_out);
525 GS_FAILURE("unregistered connection");
527 gras_dict_retrieve(p_out->message_marker_dict, name, (void **)&result);