aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/media/media-api.c
diff options
context:
space:
mode:
authorManuel Bachmann <manuel.bachmann@iot.bzh>2016-01-22 12:25:51 +0100
committerManuel Bachmann <manuel.bachmann@iot.bzh>2016-01-22 12:25:51 +0100
commitc9a33351febfbafb58f477b1bbc9bf14a4e35d05 (patch)
treea98e6c630359d4b48bc0a6002735be164d7cd620 /plugins/media/media-api.c
parent4c833aad4d3dcef303b34b70f86bb1e98153dc97 (diff)
Implement Media Plugin upload API, update README.md
Media Plugin now supports a "upload?value=<file>" API. Add Media Plugin requirements to README.md. Signed-off-by: Manuel Bachmann <manuel.bachmann@iot.bzh>
Diffstat (limited to 'plugins/media/media-api.c')
-rw-r--r--plugins/media/media-api.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/plugins/media/media-api.c b/plugins/media/media-api.c
index dc73136f..05237d39 100644
--- a/plugins/media/media-api.c
+++ b/plugins/media/media-api.c
@@ -136,6 +136,27 @@ STATIC json_object* paused (AFB_request *request) { /* AFB_SESSION_CHECK */
return jsonNewMessage(AFB_SUCCESS, "Paused media");
}
+STATIC json_object* upload (AFB_request *request) { /* AFB_SESSION_CHECK */
+
+ mediaCtxHandleT *ctx = (mediaCtxHandleT*)request->context;
+ const char *value = getQueryValue (request, "value");
+ json_object *jresp;
+ char path[256];
+
+ /* no "?value=" parameter : return error */
+ if (!value)
+ return jsonNewMessage(AFB_FAIL, "You must provide a file name");
+
+ snprintf (path, sizeof(path), "/tmp/%s", value);
+ if (access (path, R_OK) == -1)
+ return jsonNewMessage(AFB_FAIL, "File not found");
+
+ if (!_rygel_upload (ctx, path))
+ return jsonNewMessage(AFB_FAIL, "Error when uploading file... could not complete");
+
+ return jsonNewMessage(AFB_SUCCESS, "File successfully uploaded");
+}
+
STATIC json_object* ping (AFB_request *request) { /* AFB_SESSION_NONE */
return jsonNewMessage(AFB_SUCCESS, "Ping Binder Daemon - Media API");
}
@@ -147,7 +168,8 @@ STATIC AFB_restapi pluginApis[]= {
{"choose" , AFB_SESSION_CHECK, (AFB_apiCB)choose , "Media API - choose" },
{"play" , AFB_SESSION_CHECK, (AFB_apiCB)play , "Media API - play" },
{"stop" , AFB_SESSION_CHECK, (AFB_apiCB)stop , "Media API - stop" },
- {"paused" , AFB_SESSION_CHECK, (AFB_apiCB)paused , "Media API - paused" },
+ {"pause" , AFB_SESSION_CHECK, (AFB_apiCB)paused , "Media API - pause" },
+ {"upload" , AFB_SESSION_CHECK, (AFB_apiCB)upload , "Media API - upload" },
{"ping" , AFB_SESSION_NONE, (AFB_apiCB)ping , "Media API - ping" },
{NULL}
};