Update copyright dates
[src/app-framework-binder.git] / src / afb-calls.c
index e30fe36..a859cd3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2019 "IoT.bzh"
+ * Copyright (C) 2015-2020 "IoT.bzh"
  * Author: José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
 #include <afb/afb-binding.h>
 
 #include "afb-calls.h"
-#include "afb-cred.h"
 #include "afb-evt.h"
 #include "afb-export.h"
 #include "afb-hook.h"
 #include "afb-msg-json.h"
 #include "afb-session.h"
 #include "afb-xreq.h"
+#include "afb-error-text.h"
 
 #include "jobs.h"
 #include "verbose.h"
@@ -110,10 +110,6 @@ struct callreq
 
 /******************************************************************************/
 
-static const char _internal_error_[] = "internal-error";
-
-/******************************************************************************/
-
 static int store_reply(
                struct json_object *iobject, const char *ierror, const char *iinfo,
                struct json_object **sobject, char **serror, char **sinfo)
@@ -160,7 +156,7 @@ static void sync_enter(int signum, void *closure, struct jobloop *jobloop)
                callreq->jobloop = jobloop;
                afb_export_process_xreq(callreq->export, &callreq->xreq);
        } else {
-               afb_xreq_reply(&callreq->xreq, NULL, _internal_error_, NULL);
+               afb_xreq_reply(&callreq->xreq, NULL, afb_error_text_internal_error, NULL);
        }
 }
 
@@ -172,7 +168,6 @@ static void callreq_destroy_cb(struct afb_xreq *xreq)
 
        afb_context_disconnect(&callreq->xreq.context);
        json_object_put(callreq->xreq.json);
-       afb_cred_unref(callreq->xreq.cred);
        free(callreq);
 }
 
@@ -285,24 +280,25 @@ static struct callreq *callreq_create(
                errno = ENOMEM;
        } else {
                afb_xreq_init(&callreq->xreq, &afb_calls_xreq_itf);
-               callreq->xreq.context.validated = 1;
                api2 = (char*)&callreq[1];
                callreq->xreq.request.called_api = memcpy(api2, api, lenapi);;
                verb2 = &api2[lenapi];
                callreq->xreq.request.called_verb = memcpy(verb2, verb, lenverb);
                callreq->xreq.json = args;
                callreq->mode = mode;
-               if (caller) {
-                       export = afb_export_from_api_x3(caller->request.api);
+               if (!caller)
+                       afb_export_context_init(export, &callreq->xreq.context);
+               else {
+                       if (flags & afb_req_x2_subcall_api_session)
+                               afb_export_context_init(export, &callreq->xreq.context);
+                       else
+                               afb_context_subinit(&callreq->xreq.context, &caller->context);
                        if (flags & afb_req_x2_subcall_on_behalf)
-                               callreq->xreq.cred = afb_cred_addref(caller->cred);
+                               afb_context_on_behalf_other_context(&callreq->xreq.context, &caller->context);
                        callreq->xreq.caller = caller;
                        afb_xreq_unhooked_addref(caller);
+                       export = afb_export_from_api_x3(caller->request.api);
                }
-               if (caller && (flags & afb_req_x2_subcall_api_session))
-                       afb_context_subinit(&callreq->xreq.context, &caller->context);
-               else
-                       afb_export_context_init(export, &callreq->xreq.context);
                callreq->export = export;
                callreq->flags = flags;
        }
@@ -350,7 +346,7 @@ static int do_sync(
 
        afb_xreq_unhooked_unref(&callreq->xreq);
 interr:
-       return store_reply(NULL, _internal_error_, NULL, object, info, error);
+       return store_reply(NULL, afb_error_text_internal_error, NULL, object, error, info);
 }
 
 /******************************************************************************/
@@ -372,7 +368,7 @@ static void do_async(
        callreq = callreq_create(export, caller, api, verb, args, flags, mode);
 
        if (!callreq)
-               final(closure, NULL, _internal_error_, NULL, (union callback){ .any = callback }, export, caller);
+               final(closure, NULL, afb_error_text_internal_error, NULL, (union callback){ .any = callback }, export, caller);
        else {
                callreq->callback.any = callback;
                callreq->closure = closure;
@@ -559,7 +555,7 @@ static int do_legacy_sync(
        afb_xreq_unhooked_unref(&callreq->xreq);
 interr:
        if (object)
-               *object = afb_msg_json_reply(NULL, _internal_error_, NULL, NULL);
+               *object = afb_msg_json_reply(NULL, afb_error_text_internal_error, NULL, NULL);
        return -1;
 }
 
@@ -583,7 +579,7 @@ static void do_legacy_async(
        callreq = callreq_create(export, caller, api, verb, args, flags, mode);
 
        if (!callreq) {
-               ie = afb_msg_json_reply(NULL, _internal_error_, NULL, NULL);
+               ie = afb_msg_json_reply(NULL, afb_error_text_internal_error, NULL, NULL);
                final(closure, -1, ie, (union callback){ .any = callback }, export, caller);
                json_object_put(ie);
        } else {