2 * Copyright (C) 2016-2019 "IoT.bzh"
3 * Author: José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
26 #include <json-c/json.h>
27 #if !defined(JSON_C_TO_STRING_NOSLASHESCAPE)
28 #define JSON_C_TO_STRING_NOSLASHESCAPE 0
31 #define AFB_BINDING_VERSION 0
32 #include <afb/afb-binding.h>
35 #include "afb-apiset.h"
36 #if WITH_LEGACY_BINDING_V1
37 #include "afb-api-so-v1.h"
39 #if WITH_LEGACY_BINDING_V2
40 #include "afb-api-so-v2.h"
42 #include "afb-api-v3.h"
43 #include "afb-common.h"
46 #include "afb-export.h"
48 #include "afb-msg-json.h"
49 #include "afb-session.h"
51 #include "afb-calls.h"
57 #include "sig-monitor.h"
58 #include "wrap-json.h"
60 /*************************************************************************
62 ************************************************************************/
65 * Actually supported versions
70 #if WITH_LEGACY_BINDING_V1
73 #if WITH_LEGACY_BINDING_V2
80 * The states of exported APIs
90 * structure of the exported API
95 struct afb_api_x3 api;
100 /* version of the api */
107 unsigned declared: 1;
110 unsigned unsealed: 1;
118 /* session for service */
119 struct afb_session *session;
121 /* apiset the API is declared in */
122 struct afb_apiset *declare_set;
124 /* apiset for calls */
125 struct afb_apiset *call_set;
127 /* event listener for service or NULL */
128 struct afb_evt_listener *listener;
130 /* event handler list */
131 struct globset *event_handlers;
134 struct afb_export *creator;
136 /* path indication if any */
140 struct json_object *settings;
142 /* internal descriptors */
144 #if WITH_LEGACY_BINDING_V1
145 struct afb_binding_v1 *v1;
147 const struct afb_binding_v2 *v2;
148 struct afb_api_v3 *v3;
153 #if WITH_LEGACY_BINDING_V1
154 int (*v1)(struct afb_service_x1);
157 int (*v3)(struct afb_api_x3 *api);
161 void (*on_any_event_v12)(const char *event, struct json_object *object);
162 void (*on_any_event_v3)(struct afb_api_x3 *api, const char *event, struct json_object *object);
166 #if WITH_LEGACY_BINDING_V1
167 struct afb_binding_interface_v1 v1;
169 struct afb_binding_data_v2 *v2;
176 /*****************************************************************************/
178 static inline struct afb_api_x3 *to_api_x3(struct afb_export *export)
180 return (struct afb_api_x3*)export;
183 static inline struct afb_export *from_api_x3(struct afb_api_x3 *api)
185 return (struct afb_export*)api;
188 struct afb_export *afb_export_from_api_x3(struct afb_api_x3 *api)
190 return from_api_x3(api);
193 struct afb_api_x3 *afb_export_to_api_x3(struct afb_export *export)
195 return to_api_x3(export);
198 /******************************************************************************
199 ******************************************************************************
200 ******************************************************************************
201 ******************************************************************************
203 ******************************************************************************
204 ******************************************************************************
205 ******************************************************************************
206 ******************************************************************************/
208 static struct json_object *configuration;
210 void afb_export_set_config(struct json_object *config)
212 struct json_object *save = configuration;
213 configuration = json_object_get(config);
214 json_object_put(save);
217 static struct json_object *make_settings(struct afb_export *export)
219 struct json_object *result;
220 struct json_object *obj;
221 struct afb_export *iter;
224 /* clone the globals */
225 if (json_object_object_get_ex(configuration, "*", &obj))
226 result = wrap_json_clone(obj);
228 result = json_object_new_object();
231 if (json_object_object_get_ex(configuration, export->name, &obj))
232 wrap_json_object_add(result, obj);
234 /* add library path */
235 for (iter = export ; iter && !iter->path ; iter = iter->creator);
237 path = realpath(iter->path, NULL);
238 json_object_object_add(result, "binding-path", json_object_new_string(path));
242 export->settings = result;
246 /******************************************************************************
247 ******************************************************************************
248 ******************************************************************************
249 ******************************************************************************
251 ******************************************************************************
252 ******************************************************************************
253 ******************************************************************************
254 ******************************************************************************/
256 /**********************************************
258 **********************************************/
259 static void vverbose_cb(struct afb_api_x3 *closure, int level, const char *file, int line, const char *function, const char *fmt, va_list args)
262 struct afb_export *export = from_api_x3(closure);
264 if (!fmt || vasprintf(&p, fmt, args) < 0)
265 vverbose(level, file, line, function, fmt, args);
267 verbose(level, file, line, function, (verbose_is_colorized() == 0 ? "[API %s] %s" : COLOR_API "[API %s]" COLOR_DEFAULT " %s"), export->api.apiname, p);
272 static struct afb_event_x2 *event_x2_make_cb(struct afb_api_x3 *closure, const char *name)
274 struct afb_export *export = from_api_x3(closure);
276 /* check daemon state */
277 if (export->state == Api_State_Pre_Init) {
278 ERROR("[API %s] Bad call to 'afb_daemon_event_make(%s)', must not be in PreInit", export->api.apiname, name);
283 /* create the event */
284 return afb_evt_event_x2_create2(export->api.apiname, name);
287 static int event_broadcast_cb(struct afb_api_x3 *closure, const char *name, struct json_object *object)
291 struct afb_export *export = from_api_x3(closure);
293 /* check daemon state */
294 if (export->state == Api_State_Pre_Init) {
295 ERROR("[API %s] Bad call to 'afb_daemon_event_broadcast(%s, %s)', must not be in PreInit",
296 export->api.apiname, name, json_object_to_json_string_ext(object, JSON_C_TO_STRING_NOSLASHESCAPE));
301 /* makes the event name */
302 plen = strlen(export->api.apiname);
304 event = alloca(nlen + plen + 2);
305 memcpy(event, export->api.apiname, plen);
307 memcpy(event + plen + 1, name, nlen + 1);
309 /* broadcast the event */
310 return afb_evt_broadcast(event, object);
313 static struct sd_event *get_event_loop(struct afb_api_x3 *closure)
315 jobs_acquire_event_manager();
316 return systemd_get_event_loop();
319 static struct sd_bus *get_user_bus(struct afb_api_x3 *closure)
321 jobs_acquire_event_manager();
322 return systemd_get_user_bus();
325 static struct sd_bus *get_system_bus(struct afb_api_x3 *closure)
327 jobs_acquire_event_manager();
328 return systemd_get_system_bus();
331 static int rootdir_open_locale_cb(struct afb_api_x3 *closure, const char *filename, int flags, const char *locale)
333 return afb_common_rootdir_open_locale(filename, flags, locale);
336 static int queue_job_cb(struct afb_api_x3 *closure, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout)
338 return jobs_queue(group, timeout, callback, argument);
341 static int require_api_cb(struct afb_api_x3 *closure, const char *name, int initialized)
343 struct afb_export *export = from_api_x3(closure);
345 char *iter, *end, save;
347 /* emit a warning about unexpected require in preinit */
348 if (export->state == Api_State_Pre_Init)
349 WARNING("[API %s] requiring apis in pre-init may lead to unexpected result (requires%s: %s)",
350 export->api.apiname, initialized ? " initialized" : "", name);
352 /* scan the names in a local copy */
354 iter = strdupa(name);
360 if (!save) /* at end? */
363 /* search for the end */
365 while (save && !isspace(save))
369 /* check the required api */
370 if (export->state == Api_State_Pre_Init)
371 rc2 = afb_apiset_require(export->declare_set, export->api.apiname, name);
373 rc2 = -!((initialized ? afb_apiset_lookup_started : afb_apiset_lookup)(export->call_set, iter, 1));
382 static int add_alias_cb(struct afb_api_x3 *closure, const char *apiname, const char *aliasname)
384 struct afb_export *export = from_api_x3(closure);
385 if (!afb_api_is_valid_name(aliasname)) {
386 ERROR("[API %s] Can't add alias to %s: bad API name", export->api.apiname, aliasname);
390 NOTICE("[API %s] aliasing [API %s] to [API %s]", export->api.apiname, apiname?:"<null>", aliasname);
391 afb_export_add_alias(export, apiname, aliasname);
395 static struct afb_api_x3 *api_new_api_cb(
396 struct afb_api_x3 *closure,
400 int (*preinit)(void*, struct afb_api_x3 *),
401 void *preinit_closure)
403 struct afb_export *export = from_api_x3(closure);
404 struct afb_api_v3 *apiv3 = afb_api_v3_create(
405 export->declare_set, export->call_set,
406 api, info, noconcurrency,
407 preinit, preinit_closure, 1,
409 return apiv3 ? to_api_x3(afb_api_v3_export(apiv3)) : NULL;
412 #if WITH_LEGACY_BINDING_V1 || WITH_LEGACY_BINDING_V2
414 static void legacy_vverbose_v1_cb(struct afb_api_x3 *closure, int level, const char *file, int line, const char *fmt, va_list args)
416 vverbose_cb(closure, level, file, line, NULL, fmt, args);
419 static struct afb_event_x1 legacy_event_x1_make_cb(struct afb_api_x3 *closure, const char *name)
421 struct afb_event_x2 *event = event_x2_make_cb(closure, name);
422 return afb_evt_event_from_evtid(afb_evt_event_x2_to_evtid(event));
425 static struct afb_req_x1 legacy_unstore_req_cb(struct afb_api_x3 *closure, struct afb_stored_req *sreq)
427 return afb_xreq_unstore(sreq);
430 static const struct afb_daemon_itf_x1 daemon_itf = {
431 .vverbose_v1 = legacy_vverbose_v1_cb,
432 .vverbose_v2 = vverbose_cb,
433 .event_make = legacy_event_x1_make_cb,
434 .event_broadcast = event_broadcast_cb,
435 .get_event_loop = get_event_loop,
436 .get_user_bus = get_user_bus,
437 .get_system_bus = get_system_bus,
438 .rootdir_get_fd = afb_common_rootdir_get_fd,
439 .rootdir_open_locale = rootdir_open_locale_cb,
440 .queue_job = queue_job_cb,
441 .unstore_req = legacy_unstore_req_cb,
442 .require_api = require_api_cb,
443 .add_alias = add_alias_cb,
444 .new_api = api_new_api_cb,
449 static void hooked_vverbose_cb(struct afb_api_x3 *closure, int level, const char *file, int line, const char *function, const char *fmt, va_list args)
451 struct afb_export *export = from_api_x3(closure);
454 vverbose_cb(closure, level, file, line, function, fmt, args);
455 afb_hook_api_vverbose(export, level, file, line, function, fmt, ap);
459 static struct afb_event_x2 *hooked_event_x2_make_cb(struct afb_api_x3 *closure, const char *name)
461 struct afb_export *export = from_api_x3(closure);
462 struct afb_event_x2 *r = event_x2_make_cb(closure, name);
463 afb_hook_api_event_make(export, name, r);
467 static int hooked_event_broadcast_cb(struct afb_api_x3 *closure, const char *name, struct json_object *object)
470 struct afb_export *export = from_api_x3(closure);
471 json_object_get(object);
472 afb_hook_api_event_broadcast_before(export, name, json_object_get(object));
473 r = event_broadcast_cb(closure, name, object);
474 afb_hook_api_event_broadcast_after(export, name, object, r);
475 json_object_put(object);
479 static struct sd_event *hooked_get_event_loop(struct afb_api_x3 *closure)
481 struct afb_export *export = from_api_x3(closure);
484 jobs_acquire_event_manager();
485 r = get_event_loop(closure);
486 return afb_hook_api_get_event_loop(export, r);
489 static struct sd_bus *hooked_get_user_bus(struct afb_api_x3 *closure)
491 struct afb_export *export = from_api_x3(closure);
494 jobs_acquire_event_manager();
495 r = get_user_bus(closure);
496 return afb_hook_api_get_user_bus(export, r);
499 static struct sd_bus *hooked_get_system_bus(struct afb_api_x3 *closure)
501 struct afb_export *export = from_api_x3(closure);
504 jobs_acquire_event_manager();
505 r = get_system_bus(closure);
506 return afb_hook_api_get_system_bus(export, r);
509 static int hooked_rootdir_get_fd(struct afb_api_x3 *closure)
511 struct afb_export *export = from_api_x3(closure);
512 int r = afb_common_rootdir_get_fd();
513 return afb_hook_api_rootdir_get_fd(export, r);
516 static int hooked_rootdir_open_locale_cb(struct afb_api_x3 *closure, const char *filename, int flags, const char *locale)
518 struct afb_export *export = from_api_x3(closure);
519 int r = rootdir_open_locale_cb(closure, filename, flags, locale);
520 return afb_hook_api_rootdir_open_locale(export, filename, flags, locale, r);
523 static int hooked_queue_job_cb(struct afb_api_x3 *closure, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout)
525 struct afb_export *export = from_api_x3(closure);
526 int r = queue_job_cb(closure, callback, argument, group, timeout);
527 return afb_hook_api_queue_job(export, callback, argument, group, timeout, r);
530 static int hooked_require_api_cb(struct afb_api_x3 *closure, const char *name, int initialized)
533 struct afb_export *export = from_api_x3(closure);
534 afb_hook_api_require_api(export, name, initialized);
535 result = require_api_cb(closure, name, initialized);
536 return afb_hook_api_require_api_result(export, name, initialized, result);
539 static int hooked_add_alias_cb(struct afb_api_x3 *closure, const char *apiname, const char *aliasname)
541 struct afb_export *export = from_api_x3(closure);
542 int result = add_alias_cb(closure, apiname, aliasname);
543 return afb_hook_api_add_alias(export, apiname, aliasname, result);
546 static struct afb_api_x3 *hooked_api_new_api_cb(
547 struct afb_api_x3 *closure,
551 int (*preinit)(void*, struct afb_api_x3 *),
552 void *preinit_closure)
554 struct afb_api_x3 *result;
555 struct afb_export *export = from_api_x3(closure);
556 afb_hook_api_new_api_before(export, api, info, noconcurrency);
557 result = api_new_api_cb(closure, api, info, noconcurrency, preinit, preinit_closure);
558 afb_hook_api_new_api_after(export, -!result, api);
562 #if WITH_LEGACY_BINDING_V1 || WITH_LEGACY_BINDING_V2
564 static void legacy_hooked_vverbose_v1_cb(struct afb_api_x3 *closure, int level, const char *file, int line, const char *fmt, va_list args)
566 hooked_vverbose_cb(closure, level, file, line, NULL, fmt, args);
569 static struct afb_event_x1 legacy_hooked_event_x1_make_cb(struct afb_api_x3 *closure, const char *name)
571 struct afb_event_x2 *event = hooked_event_x2_make_cb(closure, name);
572 struct afb_event_x1 e;
574 e.itf = event ? event->itf : NULL;
578 static struct afb_req_x1 legacy_hooked_unstore_req_cb(struct afb_api_x3 *closure, struct afb_stored_req *sreq)
580 struct afb_export *export = from_api_x3(closure);
581 afb_hook_api_legacy_unstore_req(export, sreq);
582 return legacy_unstore_req_cb(closure, sreq);
585 static const struct afb_daemon_itf_x1 hooked_daemon_itf = {
586 .vverbose_v1 = legacy_hooked_vverbose_v1_cb,
587 .vverbose_v2 = hooked_vverbose_cb,
588 .event_make = legacy_hooked_event_x1_make_cb,
589 .event_broadcast = hooked_event_broadcast_cb,
590 .get_event_loop = hooked_get_event_loop,
591 .get_user_bus = hooked_get_user_bus,
592 .get_system_bus = hooked_get_system_bus,
593 .rootdir_get_fd = hooked_rootdir_get_fd,
594 .rootdir_open_locale = hooked_rootdir_open_locale_cb,
595 .queue_job = hooked_queue_job_cb,
596 .unstore_req = legacy_hooked_unstore_req_cb,
597 .require_api = hooked_require_api_cb,
598 .add_alias = hooked_add_alias_cb,
599 .new_api = hooked_api_new_api_cb,
605 /******************************************************************************
606 ******************************************************************************
607 ******************************************************************************
608 ******************************************************************************
610 ******************************************************************************
611 ******************************************************************************
612 ******************************************************************************
613 ******************************************************************************/
615 /* the common session for services sharing their session */
616 static struct afb_session *common_session;
618 /******************************************************************************
619 ******************************************************************************
620 ******************************************************************************
621 ******************************************************************************
623 ******************************************************************************
624 ******************************************************************************
625 ******************************************************************************
626 ******************************************************************************/
629 struct afb_api_x3 *apix3,
632 struct json_object *args,
633 void (*callback)(void*, struct json_object*, const char *error, const char *info, struct afb_api_x3*),
636 struct afb_export *export = from_api_x3(apix3);
637 return afb_calls_call(export, api, verb, args, callback, closure);
640 static int call_sync_x3(
641 struct afb_api_x3 *apix3,
644 struct json_object *args,
645 struct json_object **object,
649 struct afb_export *export = from_api_x3(apix3);
650 return afb_calls_call_sync(export, api, verb, args, object, error, info);
653 static void legacy_call_x3(
654 struct afb_api_x3 *apix3,
657 struct json_object *args,
658 void (*callback)(void*, int, struct json_object*, struct afb_api_x3*),
661 struct afb_export *export = from_api_x3(apix3);
662 afb_calls_legacy_call_v3(export, api, verb, args, callback, closure);
665 static int legacy_call_sync(
666 struct afb_api_x3 *apix3,
669 struct json_object *args,
670 struct json_object **result)
672 struct afb_export *export = from_api_x3(apix3);
673 return afb_calls_legacy_call_sync(export, api, verb, args, result);
676 #if WITH_LEGACY_BINDING_V1 || WITH_LEGACY_BINDING_V2
678 static void legacy_call_v12(
679 struct afb_api_x3 *apix3,
682 struct json_object *args,
683 void (*callback)(void*, int, struct json_object*),
686 struct afb_export *export = from_api_x3(apix3);
687 afb_calls_legacy_call_v12(export, api, verb, args, callback, closure);
690 /* the interface for services */
691 static const struct afb_service_itf_x1 service_itf = {
692 .call = legacy_call_v12,
693 .call_sync = legacy_call_sync
698 static void hooked_call_x3(
699 struct afb_api_x3 *apix3,
702 struct json_object *args,
703 void (*callback)(void*, struct json_object*, const char*, const char*, struct afb_api_x3*),
706 struct afb_export *export = from_api_x3(apix3);
707 afb_calls_hooked_call(export, api, verb, args, callback, closure);
710 static int hooked_call_sync_x3(
711 struct afb_api_x3 *apix3,
714 struct json_object *args,
715 struct json_object **object,
719 struct afb_export *export = from_api_x3(apix3);
720 return afb_calls_hooked_call_sync(export, api, verb, args, object, error, info);
723 static void legacy_hooked_call_x3(
724 struct afb_api_x3 *apix3,
727 struct json_object *args,
728 void (*callback)(void*, int, struct json_object*, struct afb_api_x3*),
731 struct afb_export *export = from_api_x3(apix3);
732 afb_calls_legacy_hooked_call_v3(export, api, verb, args, callback, closure);
735 static int legacy_hooked_call_sync(
736 struct afb_api_x3 *apix3,
739 struct json_object *args,
740 struct json_object **result)
742 struct afb_export *export = from_api_x3(apix3);
743 return afb_calls_legacy_hooked_call_sync(export, api, verb, args, result);
746 #if WITH_LEGACY_BINDING_V1 || WITH_LEGACY_BINDING_V2
748 static void legacy_hooked_call_v12(
749 struct afb_api_x3 *apix3,
752 struct json_object *args,
753 void (*callback)(void*, int, struct json_object*),
756 struct afb_export *export = from_api_x3(apix3);
757 afb_calls_legacy_hooked_call_v12(export, api, verb, args, callback, closure);
760 /* the interface for services */
761 static const struct afb_service_itf_x1 hooked_service_itf = {
762 .call = legacy_hooked_call_v12,
763 .call_sync = legacy_hooked_call_sync
769 /******************************************************************************
770 ******************************************************************************
771 ******************************************************************************
772 ******************************************************************************
774 ******************************************************************************
775 ******************************************************************************
776 ******************************************************************************
777 ******************************************************************************/
779 static int api_set_verbs_v2_cb(
780 struct afb_api_x3 *api,
781 const struct afb_verb_v2 *verbs)
783 #if WITH_LEGACY_BINDING_V2
784 struct afb_export *export = from_api_x3(api);
786 if (export->unsealed) {
787 afb_api_v3_set_verbs_v2(export->desc.v3, verbs);
798 static int api_set_verbs_v3_cb(
799 struct afb_api_x3 *api,
800 const struct afb_verb_v3 *verbs)
802 struct afb_export *export = from_api_x3(api);
804 if (!export->unsealed) {
809 afb_api_v3_set_verbs_v3(export->desc.v3, verbs);
813 static int api_add_verb_cb(
814 struct afb_api_x3 *api,
817 void (*callback)(struct afb_req_x2 *req),
819 const struct afb_auth *auth,
823 struct afb_export *export = from_api_x3(api);
825 if (!export->unsealed) {
830 return afb_api_v3_add_verb(export->desc.v3, verb, info, callback, vcbdata, auth, (uint16_t)session, glob);
833 static int api_del_verb_cb(
834 struct afb_api_x3 *api,
838 struct afb_export *export = from_api_x3(api);
840 if (!export->unsealed) {
845 return afb_api_v3_del_verb(export->desc.v3, verb, vcbdata);
848 static int api_set_on_event_cb(
849 struct afb_api_x3 *api,
850 void (*onevent)(struct afb_api_x3 *api, const char *event, struct json_object *object))
852 struct afb_export *export = from_api_x3(api);
853 return afb_export_handle_events_v3(export, onevent);
856 static int api_set_on_init_cb(
857 struct afb_api_x3 *api,
858 int (*oninit)(struct afb_api_x3 *api))
860 struct afb_export *export = from_api_x3(api);
862 return afb_export_handle_init_v3(export, oninit);
865 static void api_seal_cb(
866 struct afb_api_x3 *api)
868 struct afb_export *export = from_api_x3(api);
870 export->unsealed = 0;
873 static int event_handler_add_cb(
874 struct afb_api_x3 *api,
876 void (*callback)(void *, const char*, struct json_object*, struct afb_api_x3*),
879 struct afb_export *export = from_api_x3(api);
881 return afb_export_event_handler_add(export, pattern, callback, closure);
884 static int event_handler_del_cb(
885 struct afb_api_x3 *api,
889 struct afb_export *export = from_api_x3(api);
891 return afb_export_event_handler_del(export, pattern, closure);
894 static int class_provide_cb(struct afb_api_x3 *api, const char *name)
896 struct afb_export *export = from_api_x3(api);
899 char *iter, *end, save;
901 iter = strdupa(name);
907 if (!save) /* at end? */
910 /* search for the end */
912 while (save && !isspace(save))
916 rc2 = afb_apiset_provide_class(export->declare_set, api->apiname, iter);
925 static int class_require_cb(struct afb_api_x3 *api, const char *name)
927 struct afb_export *export = from_api_x3(api);
930 char *iter, *end, save;
932 iter = strdupa(name);
938 if (!save) /* at end? */
941 /* search for the end */
943 while (save && !isspace(save))
947 rc2 = afb_apiset_require_class(export->declare_set, api->apiname, iter);
956 static int delete_api_cb(struct afb_api_x3 *api)
958 struct afb_export *export = from_api_x3(api);
960 if (!export->unsealed) {
965 afb_export_undeclare(export);
966 afb_export_unref(export);
970 static struct json_object *settings_cb(struct afb_api_x3 *api)
972 struct afb_export *export = from_api_x3(api);
973 struct json_object *result = export->settings;
975 result = make_settings(export);
979 static const struct afb_api_x3_itf api_x3_itf = {
981 .vverbose = (void*)vverbose_cb,
983 .get_event_loop = get_event_loop,
984 .get_user_bus = get_user_bus,
985 .get_system_bus = get_system_bus,
986 .rootdir_get_fd = afb_common_rootdir_get_fd,
987 .rootdir_open_locale = rootdir_open_locale_cb,
988 .queue_job = queue_job_cb,
990 .require_api = require_api_cb,
991 .add_alias = add_alias_cb,
993 .event_broadcast = event_broadcast_cb,
994 .event_make = event_x2_make_cb,
996 .legacy_call = legacy_call_x3,
997 .legacy_call_sync = legacy_call_sync,
999 .api_new_api = api_new_api_cb,
1000 .api_set_verbs_v2 = api_set_verbs_v2_cb,
1001 .api_add_verb = api_add_verb_cb,
1002 .api_del_verb = api_del_verb_cb,
1003 .api_set_on_event = api_set_on_event_cb,
1004 .api_set_on_init = api_set_on_init_cb,
1005 .api_seal = api_seal_cb,
1006 .api_set_verbs_v3 = api_set_verbs_v3_cb,
1007 .event_handler_add = event_handler_add_cb,
1008 .event_handler_del = event_handler_del_cb,
1011 .call_sync = call_sync_x3,
1013 .class_provide = class_provide_cb,
1014 .class_require = class_require_cb,
1016 .delete_api = delete_api_cb,
1017 .settings = settings_cb,
1021 static int hooked_api_set_verbs_v2_cb(
1022 struct afb_api_x3 *api,
1023 const struct afb_verb_v2 *verbs)
1025 struct afb_export *export = from_api_x3(api);
1026 int result = api_set_verbs_v2_cb(api, verbs);
1027 return afb_hook_api_api_set_verbs_v2(export, result, verbs);
1030 static int hooked_api_set_verbs_v3_cb(
1031 struct afb_api_x3 *api,
1032 const struct afb_verb_v3 *verbs)
1034 struct afb_export *export = from_api_x3(api);
1035 int result = api_set_verbs_v3_cb(api, verbs);
1036 return afb_hook_api_api_set_verbs_v3(export, result, verbs);
1039 static int hooked_api_add_verb_cb(
1040 struct afb_api_x3 *api,
1043 void (*callback)(struct afb_req_x2 *req),
1045 const struct afb_auth *auth,
1049 struct afb_export *export = from_api_x3(api);
1050 int result = api_add_verb_cb(api, verb, info, callback, vcbdata, auth, session, glob);
1051 return afb_hook_api_api_add_verb(export, result, verb, info, glob);
1054 static int hooked_api_del_verb_cb(
1055 struct afb_api_x3 *api,
1059 struct afb_export *export = from_api_x3(api);
1060 int result = api_del_verb_cb(api, verb, vcbdata);
1061 return afb_hook_api_api_del_verb(export, result, verb);
1064 static int hooked_api_set_on_event_cb(
1065 struct afb_api_x3 *api,
1066 void (*onevent)(struct afb_api_x3 *api, const char *event, struct json_object *object))
1068 struct afb_export *export = from_api_x3(api);
1069 int result = api_set_on_event_cb(api, onevent);
1070 return afb_hook_api_api_set_on_event(export, result);
1073 static int hooked_api_set_on_init_cb(
1074 struct afb_api_x3 *api,
1075 int (*oninit)(struct afb_api_x3 *api))
1077 struct afb_export *export = from_api_x3(api);
1078 int result = api_set_on_init_cb(api, oninit);
1079 return afb_hook_api_api_set_on_init(export, result);
1082 static void hooked_api_seal_cb(
1083 struct afb_api_x3 *api)
1085 struct afb_export *export = from_api_x3(api);
1086 afb_hook_api_api_seal(export);
1090 static int hooked_event_handler_add_cb(
1091 struct afb_api_x3 *api,
1092 const char *pattern,
1093 void (*callback)(void *, const char*, struct json_object*, struct afb_api_x3*),
1096 struct afb_export *export = from_api_x3(api);
1097 int result = event_handler_add_cb(api, pattern, callback, closure);
1098 return afb_hook_api_event_handler_add(export, result, pattern);
1101 static int hooked_event_handler_del_cb(
1102 struct afb_api_x3 *api,
1103 const char *pattern,
1106 struct afb_export *export = from_api_x3(api);
1107 int result = event_handler_del_cb(api, pattern, closure);
1108 return afb_hook_api_event_handler_del(export, result, pattern);
1111 static int hooked_class_provide_cb(struct afb_api_x3 *api, const char *name)
1113 struct afb_export *export = from_api_x3(api);
1114 int result = class_provide_cb(api, name);
1115 return afb_hook_api_class_provide(export, result, name);
1118 static int hooked_class_require_cb(struct afb_api_x3 *api, const char *name)
1120 struct afb_export *export = from_api_x3(api);
1121 int result = class_require_cb(api, name);
1122 return afb_hook_api_class_require(export, result, name);
1125 static int hooked_delete_api_cb(struct afb_api_x3 *api)
1127 struct afb_export *export = afb_export_addref(from_api_x3(api));
1128 int result = delete_api_cb(api);
1129 result = afb_hook_api_delete_api(export, result);
1130 afb_export_unref(export);
1134 static struct json_object *hooked_settings_cb(struct afb_api_x3 *api)
1136 struct afb_export *export = from_api_x3(api);
1137 struct json_object *result = settings_cb(api);
1138 result = afb_hook_api_settings(export, result);
1142 static const struct afb_api_x3_itf hooked_api_x3_itf = {
1144 .vverbose = hooked_vverbose_cb,
1146 .get_event_loop = hooked_get_event_loop,
1147 .get_user_bus = hooked_get_user_bus,
1148 .get_system_bus = hooked_get_system_bus,
1149 .rootdir_get_fd = hooked_rootdir_get_fd,
1150 .rootdir_open_locale = hooked_rootdir_open_locale_cb,
1151 .queue_job = hooked_queue_job_cb,
1153 .require_api = hooked_require_api_cb,
1154 .add_alias = hooked_add_alias_cb,
1156 .event_broadcast = hooked_event_broadcast_cb,
1157 .event_make = hooked_event_x2_make_cb,
1159 .legacy_call = legacy_hooked_call_x3,
1160 .legacy_call_sync = legacy_hooked_call_sync,
1162 .api_new_api = hooked_api_new_api_cb,
1163 .api_set_verbs_v2 = hooked_api_set_verbs_v2_cb,
1164 .api_add_verb = hooked_api_add_verb_cb,
1165 .api_del_verb = hooked_api_del_verb_cb,
1166 .api_set_on_event = hooked_api_set_on_event_cb,
1167 .api_set_on_init = hooked_api_set_on_init_cb,
1168 .api_seal = hooked_api_seal_cb,
1169 .api_set_verbs_v3 = hooked_api_set_verbs_v3_cb,
1170 .event_handler_add = hooked_event_handler_add_cb,
1171 .event_handler_del = hooked_event_handler_del_cb,
1173 .call = hooked_call_x3,
1174 .call_sync = hooked_call_sync_x3,
1176 .class_provide = hooked_class_provide_cb,
1177 .class_require = hooked_class_require_cb,
1179 .delete_api = hooked_delete_api_cb,
1180 .settings = hooked_settings_cb,
1184 /******************************************************************************
1185 ******************************************************************************
1186 ******************************************************************************
1187 ******************************************************************************
1189 ******************************************************************************
1190 ******************************************************************************
1191 ******************************************************************************
1192 ******************************************************************************/
1195 * Propagates the event to the service
1197 static void listener_of_events(void *closure, const char *event, int eventid, struct json_object *object)
1199 const struct globset_handler *handler;
1200 void (*callback)(void *, const char*, struct json_object*, struct afb_api_x3*);
1201 struct afb_export *export = from_api_x3(closure);
1204 /* hook the event before */
1205 if (export->hooksvc & afb_hook_flag_api_on_event)
1206 afb_hook_api_on_event_before(export, event, eventid, object);
1209 /* transmit to specific handlers */
1210 /* search the handler */
1211 handler = export->event_handlers ? globset_match(export->event_handlers, event) : NULL;
1213 callback = handler->callback;
1215 if (!(export->hooksvc & afb_hook_flag_api_on_event_handler))
1217 callback(handler->closure, event, object, to_api_x3(export));
1220 afb_hook_api_on_event_handler_before(export, event, eventid, object, handler->pattern);
1221 callback(handler->closure, event, object, to_api_x3(export));
1222 afb_hook_api_on_event_handler_after(export, event, eventid, object, handler->pattern);
1226 /* transmit to default handler */
1227 if (export->on_any_event_v3)
1228 export->on_any_event_v3(to_api_x3(export), event, object);
1229 else if (export->on_any_event_v12)
1230 export->on_any_event_v12(event, object);
1234 /* hook the event after */
1235 if (export->hooksvc & afb_hook_flag_api_on_event)
1236 afb_hook_api_on_event_after(export, event, eventid, object);
1238 json_object_put(object);
1241 /* the interface for events */
1242 static const struct afb_evt_itf evt_itf = {
1243 .broadcast = listener_of_events,
1244 .push = listener_of_events
1247 /* ensure an existing listener */
1248 static int ensure_listener(struct afb_export *export)
1250 if (!export->listener) {
1251 export->listener = afb_evt_listener_create(&evt_itf, export);
1252 if (export->listener == NULL)
1258 int afb_export_event_handler_add(
1259 struct afb_export *export,
1260 const char *pattern,
1261 void (*callback)(void *, const char*, struct json_object*, struct afb_api_x3*),
1266 /* ensure the listener */
1267 rc = ensure_listener(export);
1271 /* ensure the globset for event handling */
1272 if (!export->event_handlers) {
1273 export->event_handlers = globset_create();
1274 if (!export->event_handlers)
1278 /* add the handler */
1279 rc = globset_add(export->event_handlers, pattern, callback, closure);
1283 if (errno == EEXIST) {
1284 ERROR("[API %s] event handler %s already exists", export->api.apiname, pattern);
1289 ERROR("[API %s] can't allocate event handler %s", export->api.apiname, pattern);
1293 int afb_export_event_handler_del(
1294 struct afb_export *export,
1295 const char *pattern,
1298 if (export->event_handlers
1299 && !globset_del(export->event_handlers, pattern, closure))
1302 ERROR("[API %s] event handler %s not found", export->api.apiname, pattern);
1307 /******************************************************************************
1308 ******************************************************************************
1309 ******************************************************************************
1310 ******************************************************************************
1312 ******************************************************************************
1313 ******************************************************************************
1314 ******************************************************************************
1315 ******************************************************************************/
1317 static void set_interfaces(struct afb_export *export)
1320 export->hookditf = afb_hook_flags_api(export->api.apiname);
1321 export->hooksvc = afb_hook_flags_api(export->api.apiname);
1322 export->api.itf = export->hookditf|export->hooksvc ? &hooked_api_x3_itf : &api_x3_itf;
1324 switch (export->version) {
1325 #if WITH_LEGACY_BINDING_V1
1327 export->export.v1.daemon.itf = export->hookditf ? &hooked_daemon_itf : &daemon_itf;
1330 #if WITH_LEGACY_BINDING_V2
1332 export->export.v2->daemon.itf = export->hookditf ? &hooked_daemon_itf : &daemon_itf;
1333 export->export.v2->service.itf = export->hooksvc ? &hooked_service_itf : &service_itf;
1339 export->api.itf = &api_x3_itf;
1341 switch (export->version) {
1342 #if WITH_LEGACY_BINDING_V1
1344 export->export.v1.daemon.itf = &daemon_itf;
1347 #if WITH_LEGACY_BINDING_V2
1349 export->export.v2->daemon.itf = &daemon_itf;
1350 export->export.v2->service.itf = &service_itf;
1358 static struct afb_export *create(
1359 struct afb_apiset *declare_set,
1360 struct afb_apiset *call_set,
1361 const char *apiname,
1363 enum afb_api_version version)
1365 struct afb_export *export;
1368 /* session shared with other exports */
1369 if (common_session == NULL) {
1370 common_session = afb_session_create (0);
1371 if (common_session == NULL)
1374 lenapi = strlen(apiname);
1375 export = calloc(1, sizeof *export + 1 + lenapi + (path == apiname || !path ? 0 : 1 + strlen(path)));
1379 export->refcount = 1;
1380 strcpy(export->name, apiname);
1381 export->api.apiname = export->name;
1382 if (path == apiname)
1383 export->path = export->name;
1385 export->path = strcpy(&export->name[lenapi + 1], path);
1386 export->version = version;
1387 export->state = Api_State_Pre_Init;
1388 export->session = afb_session_addref(common_session);
1389 export->declare_set = afb_apiset_addref(declare_set);
1390 export->call_set = afb_apiset_addref(call_set);
1395 struct afb_export *afb_export_addref(struct afb_export *export)
1398 __atomic_add_fetch(&export->refcount, 1, __ATOMIC_RELAXED);
1402 void afb_export_unref(struct afb_export *export)
1404 if (export && !__atomic_sub_fetch(&export->refcount, 1, __ATOMIC_RELAXED))
1405 afb_export_destroy(export);
1408 void afb_export_destroy(struct afb_export *export)
1411 if (export->event_handlers)
1412 globset_destroy(export->event_handlers);
1413 if (export->listener != NULL)
1414 afb_evt_listener_unref(export->listener);
1415 afb_session_unref(export->session);
1416 afb_apiset_unref(export->declare_set);
1417 afb_apiset_unref(export->call_set);
1418 json_object_put(export->settings);
1419 afb_export_unref(export->creator);
1420 if (export->api.apiname != export->name)
1421 free((void*)export->api.apiname);
1426 struct afb_export *afb_export_create_none_for_path(
1427 struct afb_apiset *declare_set,
1428 struct afb_apiset *call_set,
1430 int (*creator)(void*, struct afb_api_x3*),
1433 struct afb_export *export = create(declare_set, call_set, path, path, Api_Version_None);
1435 afb_export_logmask_set(export, logmask);
1436 set_interfaces(export);
1437 if (creator && creator(closure, to_api_x3(export)) < 0) {
1438 afb_export_unref(export);
1445 #if WITH_LEGACY_BINDING_V1
1446 struct afb_export *afb_export_create_v1(struct afb_apiset *declare_set,
1447 struct afb_apiset *call_set,
1448 const char *apiname,
1449 int (*init)(struct afb_service_x1),
1450 void (*onevent)(const char*, struct json_object*),
1453 struct afb_export *export = create(declare_set, call_set, apiname, path, Api_Version_1);
1455 export->init.v1 = init;
1456 export->on_any_event_v12 = onevent;
1457 export->export.v1.mode = AFB_MODE_LOCAL;
1458 export->export.v1.daemon.closure = to_api_x3(export);
1459 afb_export_logmask_set(export, logmask);
1460 set_interfaces(export);
1466 #if WITH_LEGACY_BINDING_V2
1467 struct afb_export *afb_export_create_v2(struct afb_apiset *declare_set,
1468 struct afb_apiset *call_set,
1469 const char *apiname,
1470 const struct afb_binding_v2 *binding,
1471 struct afb_binding_data_v2 *data,
1473 void (*onevent)(const char*, struct json_object*),
1476 struct afb_export *export = create(declare_set, call_set, apiname, path, Api_Version_2);
1478 export->init.v2 = init;
1479 export->on_any_event_v12 = onevent;
1480 export->desc.v2 = binding;
1481 export->export.v2 = data;
1482 data->daemon.closure = to_api_x3(export);
1483 data->service.closure = to_api_x3(export);
1484 afb_export_logmask_set(export, logmask);
1485 set_interfaces(export);
1491 struct afb_export *afb_export_create_v3(struct afb_apiset *declare_set,
1492 struct afb_apiset *call_set,
1493 const char *apiname,
1494 struct afb_api_v3 *apiv3,
1495 struct afb_export* creator,
1498 struct afb_export *export = create(declare_set, call_set, apiname, path, Api_Version_3);
1500 export->unsealed = 1;
1501 export->desc.v3 = apiv3;
1502 export->creator = afb_export_addref(creator);
1503 afb_export_logmask_set(export, logmask);
1504 set_interfaces(export);
1509 int afb_export_add_alias(struct afb_export *export, const char *apiname, const char *aliasname)
1511 return afb_apiset_add_alias(export->declare_set, apiname ?: export->api.apiname, aliasname);
1514 int afb_export_rename(struct afb_export *export, const char *apiname)
1518 if (export->declared) {
1523 /* copy the name locally */
1524 name = strdup(apiname);
1530 if (export->api.apiname != export->name)
1531 free((void*)export->api.apiname);
1532 export->api.apiname = name;
1534 set_interfaces(export);
1538 const char *afb_export_apiname(const struct afb_export *export)
1540 return export->api.apiname;
1543 int afb_export_unshare_session(struct afb_export *export)
1545 if (export->session == common_session) {
1546 export->session = afb_session_create (0);
1547 if (export->session)
1548 afb_session_unref(common_session);
1550 export->session = common_session;
1557 #if WITH_LEGACY_BINDING_V1 || WITH_LEGACY_BINDING_V2
1558 int afb_export_handle_events_v12(struct afb_export *export, void (*on_event)(const char *event, struct json_object *object))
1561 switch (export->version) {
1562 #if WITH_LEGACY_BINDING_V1
1565 #if WITH_LEGACY_BINDING_V2
1570 ERROR("invalid version 12 for API %s", export->api.apiname);
1575 export->on_any_event_v12 = on_event;
1576 return ensure_listener(export);
1580 int afb_export_handle_events_v3(struct afb_export *export, void (*on_event)(struct afb_api_x3 *api, const char *event, struct json_object *object))
1583 switch (export->version) {
1584 case Api_Version_3: break;
1586 ERROR("invalid version Dyn for API %s", export->api.apiname);
1591 export->on_any_event_v3 = on_event;
1592 return ensure_listener(export);
1595 int afb_export_handle_init_v3(struct afb_export *export, int (*oninit)(struct afb_api_x3 *api))
1597 if (export->state != Api_State_Pre_Init) {
1598 ERROR("[API %s] Bad call to 'afb_api_x3_on_init', must be in PreInit", export->api.apiname);
1603 export->init.v3 = oninit;
1607 #if WITH_LEGACY_BINDING_V1
1609 * Starts a new service (v1)
1611 struct afb_binding_v1 *afb_export_register_v1(struct afb_export *export, struct afb_binding_v1 *(*regfun)(const struct afb_binding_interface_v1*))
1613 return export->desc.v1 = regfun(&export->export.v1);
1617 int afb_export_preinit_x3(
1618 struct afb_export *export,
1619 int (*preinit)(void*, struct afb_api_x3*),
1622 return preinit(closure, to_api_x3(export));
1625 int afb_export_logmask_get(const struct afb_export *export)
1627 return export->api.logmask;
1630 void afb_export_logmask_set(struct afb_export *export, int mask)
1632 export->api.logmask = mask;
1633 switch (export->version) {
1634 #if WITH_LEGACY_BINDING_V1
1635 case Api_Version_1: export->export.v1.verbosity = verbosity_from_mask(mask); break;
1637 #if WITH_LEGACY_BINDING_V2
1638 case Api_Version_2: export->export.v2->verbosity = verbosity_from_mask(mask); break;
1643 void *afb_export_userdata_get(const struct afb_export *export)
1645 return export->api.userdata;
1648 void afb_export_userdata_set(struct afb_export *export, void *data)
1650 export->api.userdata = data;
1653 /******************************************************************************
1654 ******************************************************************************
1655 ******************************************************************************
1656 ******************************************************************************
1658 ******************************************************************************
1659 ******************************************************************************
1660 ******************************************************************************
1661 ******************************************************************************/
1666 struct afb_export *export;
1669 static void do_init(int sig, void *closure)
1672 struct init *init = closure;
1673 struct afb_export *export;
1678 export = init->export;
1679 switch (export->version) {
1680 #if WITH_LEGACY_BINDING_V1
1682 rc = export->init.v1 ? export->init.v1(
1683 (struct afb_service_x1){
1685 .itf = &hooked_service_itf,
1687 .itf = &service_itf,
1689 .closure = to_api_x3(export) }) : 0;
1692 #if WITH_LEGACY_BINDING_V2
1694 rc = export->init.v2 ? export->init.v2() : 0;
1698 rc = export->init.v3 ? export->init.v3(to_api_x3(export)) : 0;
1705 init->return_code = rc;
1709 int afb_export_start(struct afb_export *export)
1715 switch (export->state) {
1719 case Api_State_Init:
1720 /* starting in progress: it is an error */
1721 ERROR("Service of API %s required started while starting", export->api.apiname);
1728 /* set event handling */
1729 #if WITH_LEGACY_BINDING_V1 || WITH_LEGACY_BINDING_V2
1730 switch (export->version) {
1731 #if WITH_LEGACY_BINDING_V1
1734 #if WITH_LEGACY_BINDING_V2
1737 if (export->on_any_event_v12) {
1738 rc = afb_export_handle_events_v12(export, export->on_any_event_v12);
1747 ERROR("Can't set event handler for %s", export->api.apiname);
1753 /* Starts the service */
1754 if (export->hooksvc & afb_hook_flag_api_start)
1755 afb_hook_api_start_before(export);
1758 export->state = Api_State_Init;
1759 init.export = export;
1760 sig_monitor(0, do_init, &init);
1761 rc = init.return_code;
1762 export->state = Api_State_Run;
1765 if (export->hooksvc & afb_hook_flag_api_start)
1766 afb_hook_api_start_after(export, rc);
1770 /* initialisation error */
1771 ERROR("Initialisation of service API %s failed (%d): %m", export->api.apiname, rc);
1778 static void api_call_cb(void *closure, struct afb_xreq *xreq)
1780 struct afb_export *export = closure;
1782 xreq->request.api = to_api_x3(export);
1784 switch (export->version) {
1785 #if WITH_LEGACY_BINDING_V1
1787 afb_api_so_v1_process_call(export->desc.v1, xreq);
1790 #if WITH_LEGACY_BINDING_V2
1792 afb_api_so_v2_process_call(export->desc.v2, xreq);
1796 afb_api_v3_process_call(export->desc.v3, xreq);
1799 afb_xreq_reply(xreq, NULL, "bad-api-type", NULL);
1804 static struct json_object *api_describe_cb(void *closure)
1806 struct afb_export *export = closure;
1807 struct json_object *result;
1809 switch (export->version) {
1810 #if WITH_LEGACY_BINDING_V1
1812 result = afb_api_so_v1_make_description_openAPIv3(export->desc.v1, export->api.apiname);
1815 #if WITH_LEGACY_BINDING_V2
1817 result = afb_api_so_v2_make_description_openAPIv3(export->desc.v2, export->api.apiname);
1821 result = afb_api_v3_make_description_openAPIv3(export->desc.v3, export->api.apiname);
1830 static int api_service_start_cb(void *closure)
1832 struct afb_export *export = closure;
1834 return afb_export_start(export);
1838 static void api_update_hooks_cb(void *closure)
1839 __attribute__((alias("set_interfaces")));
1841 void afb_export_update_hooks(struct afb_export *export)
1842 __attribute__((alias("set_interfaces")));
1845 static int api_get_logmask_cb(void *closure)
1847 struct afb_export *export = closure;
1849 return afb_export_logmask_get(export);
1852 static void api_set_logmask_cb(void *closure, int level)
1854 struct afb_export *export = closure;
1856 afb_export_logmask_set(export, level);
1859 static void api_unref_cb(void *closure)
1861 struct afb_export *export = closure;
1863 afb_export_unref(export);
1866 static struct afb_api_itf export_api_itf =
1868 .call = api_call_cb,
1869 .service_start = api_service_start_cb,
1871 .update_hooks = api_update_hooks_cb,
1873 .get_logmask = api_get_logmask_cb,
1874 .set_logmask = api_set_logmask_cb,
1875 .describe = api_describe_cb,
1876 .unref = api_unref_cb
1879 int afb_export_declare(struct afb_export *export,
1883 struct afb_api_item afb_api;
1885 if (export->declared)
1888 /* init the record structure */
1889 afb_api.closure = afb_export_addref(export);
1890 afb_api.itf = &export_api_itf;
1891 afb_api.group = noconcurrency ? export : NULL;
1893 /* records the binding */
1894 rc = afb_apiset_add(export->declare_set, export->api.apiname, afb_api);
1896 export->declared = 1;
1898 ERROR("can't declare export %s to set %s, ABORTING it!",
1899 export->api.apiname,
1900 afb_apiset_name(export->declare_set));
1901 afb_export_unref(export);
1908 void afb_export_undeclare(struct afb_export *export)
1910 if (export->declared) {
1911 export->declared = 0;
1912 afb_apiset_del(export->declare_set, export->api.apiname);
1916 int afb_export_subscribe(struct afb_export *export, struct afb_event_x2 *event)
1918 return afb_evt_event_x2_add_watch(export->listener, event);
1921 int afb_export_unsubscribe(struct afb_export *export, struct afb_event_x2 *event)
1923 return afb_evt_event_x2_remove_watch(export->listener, event);
1926 void afb_export_process_xreq(struct afb_export *export, struct afb_xreq *xreq)
1928 afb_xreq_process(xreq, export->call_set);
1931 void afb_export_context_init(struct afb_export *export, struct afb_context *context)
1933 afb_context_init(context, export->session, NULL);
1934 context->validated = 1;