aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2015-12-22 17:54:51 +0100
committerFulup Ar Foll <fulup@iot.bzh>2015-12-22 17:54:51 +0100
commit0d37437a44e872db93631270cee0472fe9716673 (patch)
tree8c0f8e6ca0c455deadd0ed9bd1182fc9c99a74e8
parent39a0ef5d1609e01f71039f9095c14cf6f3ca1a93 (diff)
Fix Post with invalid plugins
-rw-r--r--src/rest-api.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/rest-api.c b/src/rest-api.c
index 3d9ffeb7..5565f356 100644
--- a/src/rest-api.c
+++ b/src/rest-api.c
@@ -230,6 +230,7 @@ STATIC AFB_error findAndCallApi (AFB_request *request, void *context) {
int idx;
AFB_error status;
+ if (!request->api || !request->plugin) return (AFB_FAIL);
// Search for a plugin with this urlpath
for (idx = 0; request->plugins[idx] != NULL; idx++) {
@@ -240,13 +241,13 @@ STATIC AFB_error findAndCallApi (AFB_request *request, void *context) {
}
// No plugin was found
if (request->plugins[idx] == NULL) {
- request->jresp = jsonNewMessage(AFB_FATAL, "No Plugin=[%s]", request->plugin);
+ request->jresp = jsonNewMessage(AFB_FATAL, "No Plugin=[%s] Url=%s", request->plugin, request->url);
goto ExitOnError;
}
// plugin callback did not return a valid Json Object
if (status == AFB_FAIL) {
- request->jresp = jsonNewMessage(AFB_FATAL, "No API=[%s] for Plugin=[%s]", request->api, request->plugin);
+ request->jresp = jsonNewMessage(AFB_FATAL, "No API=[%s] for Plugin=[%s] url=[%s]", request->api, request->plugin, request->url);
goto ExitOnError;
}
@@ -321,12 +322,16 @@ STATIC AFB_request *createRequest (struct MHD_Connection *connection, AFB_sessio
baseurl = strsep(&urlcpy2, "/");
if (baseurl == NULL) {
request->jresp = jsonNewMessage(AFB_FATAL, "Invalid API call url=[%s]", url);
+ request->errcode = MHD_HTTP_BAD_REQUEST;
+ goto Done;
}
// let's compute URL and call API
baseapi = strsep(&urlcpy2, "/");
if (baseapi == NULL) {
- request->jresp = jsonNewMessage(AFB_FATAL, "Invalid API call url=[%s]", url);
+ request->jresp = jsonNewMessage(AFB_FATAL, "Invalid API call plugin=[%s] url=[%s]", baseurl, url);
+ request->errcode = MHD_HTTP_BAD_REQUEST;
+ goto Done;
}
// build request structure
@@ -336,7 +341,8 @@ STATIC AFB_request *createRequest (struct MHD_Connection *connection, AFB_sessio
request->plugin = strdup (baseurl);
request->api = strdup (baseapi);
request->plugins= session->plugins;
-
+
+Done:
free(urlcpy1);
return (request);
}
@@ -383,10 +389,8 @@ PUBLIC int doRestApi(struct MHD_Connection *connection, AFB_session *session, co
if (verbose) fprintf(stderr, "Create PostForm[uid=%d]\n", postHandle->uid);
request = createRequest (connection, session, url);
- if (request->jresp != NULL) {
- errMessage = request->jresp;
- goto ExitOnError;
- }
+ if (request->jresp != NULL) goto ProcessApiCall;
+
postHandle = malloc(sizeof (AFB_PostHandle)); // allocate application POST processor handle
postHandle->type = AFB_POST_FORM;
postHandle->pp = MHD_create_post_processor (connection, MAX_POST_SIZE, doPostIterate, postHandle);