+static struct json_object *call_void__runnables(AFB_request *request, AFB_PostItem *item)
+{
+ return embed(request, _runnables_, call_void(request, item));
+}
+
+static struct json_object *call_start(AFB_request *request, AFB_PostItem *item)
+{
+ struct json_object *resp;
+ const char *id, *mode;
+ char *query;
+ int rc;
+
+ /* get the id */
+ id = getQueryValue(request, _id_);
+ if (id == NULL) {
+ request->errcode = MHD_HTTP_BAD_REQUEST;
+ return NULL;
+ }
+ /* get the mode */
+ mode = getQueryValue(request, _mode_);
+ if (mode == NULL || !strcmp(mode, _auto_)) {
+ mode = request->config->mode == AFB_MODE_REMOTE ? _remote_ : _local_;
+ }
+
+ /* create the query */
+ rc = asprintf(&query, "{\"id\":\"%s\",\"mode\":\"%s\"}", id, mode);
+ if (rc < 0) {
+ request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ return NULL;
+ }
+
+ /* calls the service */
+ resp = jbus_call_sj_sync(jbus, _start_, query);
+ if (verbose)
+ fprintf(stderr, "(afm-main-plugin) call_start: %s -> %s\n", query, resp ? json_object_to_json_string(resp) : "NULL");
+ free(query);
+
+ /* embed if needed */
+ if (json_object_get_type(resp) == json_type_int)
+ resp = embed(request, _runid_, resp);
+ request->errcode = resp ? MHD_HTTP_OK : MHD_HTTP_FAILED_DEPENDENCY;
+ return resp;
+}
+
+static struct json_object *call_void__runners(AFB_request *request, AFB_PostItem *item)
+{
+ return embed(request, _runners_, call_void(request, item));
+}
+
+static struct json_object *call_file__appid(AFB_request *request, AFB_PostItem *item)
+{
+ if (item == NULL) {
+ const char *filename = getPostPath(request);
+ if (filename != NULL) {
+ struct json_object *obj;
+ char *query;
+ request->jresp = NULL;
+ if (0 >= asprintf(&query, "\"%s\"", filename))
+ request->errcode = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ else {
+ obj = jbus_call_sj_sync(jbus, request->api, 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);
+ if (obj)
+ request->jresp = embed(request, _id_, obj);
+ else
+ request->errcode = MHD_HTTP_FAILED_DEPENDENCY;
+ }
+ unlink(filename);
+ }
+ }
+ return getPostFile (request, item, "/tmp/upload");
+}
+