diff options
-rw-r--r-- | include/local-def.h | 2 | ||||
-rw-r--r-- | plugins/afm-main-plugin/afm-main-plugin.c | 8 | ||||
-rw-r--r-- | src/afb-rest-api.c | 19 |
3 files changed, 15 insertions, 14 deletions
diff --git a/include/local-def.h b/include/local-def.h index 4c27233b..91b61abc 100644 --- a/include/local-def.h +++ b/include/local-def.h @@ -234,7 +234,7 @@ typedef struct { const char *uuid; const char *url; char *prefix; // plugin convivial name - char *api; + char *method; AFB_PostRequest *post; json_object *jresp; void *context; // Hold Client Context when using session diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c index f07afdb1..0b6b8680 100644 --- a/plugins/afm-main-plugin/afm-main-plugin.c +++ b/plugins/afm-main-plugin/afm-main-plugin.c @@ -71,7 +71,7 @@ static struct json_object *embed(AFB_request *request, const char *tag, struct j static struct json_object *call_void(AFB_request *request, AFB_PostItem *item) { - struct json_object *obj = jbus_call_sj_sync(jbus, request->api, "true"); + struct json_object *obj = jbus_call_sj_sync(jbus, request->method, "true"); if (verbose) fprintf(stderr, "(afm-main-plugin) call_void: true -> %s\n", obj ? json_object_to_json_string(obj) : "NULL"); request->errcode = obj ? MHD_HTTP_OK : MHD_HTTP_FAILED_DEPENDENCY; @@ -91,7 +91,7 @@ static struct json_object *call_appid(AFB_request *request, AFB_PostItem *item) request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR; return NULL; } - obj = jbus_call_sj_sync(jbus, request->api, sid); + obj = jbus_call_sj_sync(jbus, request->method, sid); if (verbose) fprintf(stderr, "(afm-main-plugin) call_appid: %s -> %s\n", sid, obj ? json_object_to_json_string(obj) : "NULL"); free(sid); @@ -107,7 +107,7 @@ static struct json_object *call_runid(AFB_request *request, AFB_PostItem *item) request->errcode = MHD_HTTP_BAD_REQUEST; return NULL; } - obj = jbus_call_sj_sync(jbus, request->api, id); + obj = jbus_call_sj_sync(jbus, request->method, id); if (verbose) fprintf(stderr, "(afm-main-plugin) call_runid: %s -> %s\n", id, obj ? json_object_to_json_string(obj) : "NULL"); request->errcode = obj ? MHD_HTTP_OK : MHD_HTTP_FAILED_DEPENDENCY; @@ -174,7 +174,7 @@ static struct json_object *call_file__appid(AFB_request *request, AFB_PostItem * if (0 >= asprintf(&query, "\"%s\"", filename)) request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR; else { - obj = jbus_call_sj_sync(jbus, request->api, query); + obj = jbus_call_sj_sync(jbus, request->method, query); if (verbose) fprintf(stderr, "(afm-main-plugin) call_file_appid: %s -> %s\n", query, obj ? json_object_to_json_string(obj) : "NULL"); free(query); diff --git a/src/afb-rest-api.c b/src/afb-rest-api.c index 0de762b1..2b47794e 100644 --- a/src/afb-rest-api.c +++ b/src/afb-rest-api.c @@ -31,6 +31,7 @@ #include <signal.h> #include "afb-apis.h" +#include "session.h" #define AFB_MSG_JTYPE "AJB_reply" @@ -72,7 +73,7 @@ static AFB_error doCallPluginApi(AFB_request * request, int apiidx, int verbidx, // prepare an object to store calling values jcall = json_object_new_object(); json_object_object_add(jcall, "prefix", json_object_new_string(request->prefix)); - json_object_object_add(jcall, "api", json_object_new_string(request->api)); + json_object_object_add(jcall, "api", json_object_new_string(request->method)); // Out of SessionNone every call get a client context session session = afb_apis_get(apiidx, verbidx)->session; @@ -91,7 +92,7 @@ static AFB_error doCallPluginApi(AFB_request * request, int apiidx, int verbidx, request->uuid = clientCtx->uuid; if (verbose) - fprintf(stderr, "Plugin=[%s] Api=[%s] Middleware=[%d] Client=[%p] Uuid=[%s] Token=[%s]\n", request->prefix, request->api, session, clientCtx, clientCtx->uuid, clientCtx->token); + fprintf(stderr, "Plugin=[%s] Api=[%s] Middleware=[%d] Client=[%p] Uuid=[%s] Token=[%s]\n", request->prefix, request->method, session, clientCtx, clientCtx->uuid, clientCtx->token); switch (session) { @@ -209,7 +210,7 @@ static AFB_error callPluginApi(AFB_request * request, int apiidx, int verbidx, v // prepare an object to store calling values jcall = json_object_new_object(); json_object_object_add(jcall, "prefix", json_object_new_string(request->prefix)); - json_object_object_add(jcall, "api", json_object_new_string(request->api)); + json_object_object_add(jcall, "api", json_object_new_string(request->method)); // Plugin aborted somewhere during its execution json_object_object_add(jcall, "status", json_object_new_string("abort")); @@ -241,7 +242,7 @@ STATIC AFB_error findAndCallApi(AFB_request * request, void *context) int apiidx, verbidx; AFB_error status; - if (!request->api || !request->prefix) + if (!request->method || !request->prefix) return AFB_FAIL; /* get the plugin if any */ @@ -253,9 +254,9 @@ STATIC AFB_error findAndCallApi(AFB_request * request, void *context) } /* get the verb if any */ - verbidx = afb_apis_get_verbidx(apiidx, request->api); + verbidx = afb_apis_get_verbidx(apiidx, request->method); if (verbidx < 0) { - request->jresp = jsonNewMessage(AFB_FATAL, "No API=[%s] for Plugin=[%s] url=[%s]", request->api, request->prefix, request->url); + request->jresp = jsonNewMessage(AFB_FATAL, "No API=[%s] for Plugin=[%s] url=[%s]", request->method, request->prefix, request->url); request->errcode = MHD_HTTP_UNPROCESSABLE_ENTITY; return AFB_FAIL; } @@ -265,7 +266,7 @@ STATIC AFB_error findAndCallApi(AFB_request * request, void *context) /* plugin callback did not return a valid Json Object */ if (status == AFB_FAIL) { - request->jresp = jsonNewMessage(AFB_FATAL, "No API=[%s] for Plugin=[%s] url=[%s]", request->api, request->prefix, request->url); + request->jresp = jsonNewMessage(AFB_FATAL, "No API=[%s] for Plugin=[%s] url=[%s]", request->method, request->prefix, request->url); request->errcode = MHD_HTTP_UNPROCESSABLE_ENTITY; return AFB_FAIL; } @@ -319,7 +320,7 @@ STATIC void freeRequest(AFB_request * request) { free(request->prefix); - free(request->api); + free(request->method); free(request); } @@ -353,7 +354,7 @@ STATIC AFB_request *createRequest(struct MHD_Connection *connection, AFB_session request->config = session->config; request->url = url; request->prefix = strdup(baseurl); - request->api = strdup(baseapi); + request->method = strdup(baseapi); Done: free(urlcpy1); |