X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=plugins%2Fmedia%2Fmedia-api.c;h=4e064bc221ec18a1e83011051efbb5004ca1e23e;hb=ca208671cc79bbc05c574df788035878e5d39382;hp=257b1cf1ca1ced4d374216048087e3f28ad6619d;hpb=e3320f303c4eb8f7fe0fac69bfa9ce36d9916930;p=src%2Fapp-framework-binder.git diff --git a/plugins/media/media-api.c b/plugins/media/media-api.c index 257b1cf1..4e064bc2 100644 --- a/plugins/media/media-api.c +++ b/plugins/media/media-api.c @@ -33,7 +33,7 @@ STATIC mediaCtxHandleT* initMediaCtx () { } /* called when client session dies [e.g. client quits for more than 15mns] */ -STATIC void freeMedia (void *context, void *handle) { +STATIC void freeMedia (void *context) { free (context); } @@ -64,15 +64,12 @@ STATIC json_object* list (AFB_request *request) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = (mediaCtxHandleT*)request->context; json_object *jresp; - char *result; - result = _rygel_list (ctx); + jresp = _rygel_list (ctx); - if (!result) + if (!jresp) return jsonNewMessage(AFB_FAIL, "No content found in media server"); - jresp = json_object_new_object(); - json_object_object_add(jresp, "list", json_object_new_string (result)); return jresp; } @@ -106,6 +103,8 @@ STATIC json_object* selecting (AFB_request *request) { /* AFB_SESSION_CHECK */ jresp = json_object_new_object(); json_object_object_add (jresp, "index", json_object_new_string (value)); } + else + jresp = NULL; return jresp; } @@ -155,25 +154,35 @@ STATIC json_object* seek (AFB_request *request) { /* AFB_SESSION_CHECK */ return jsonNewMessage(AFB_SUCCESS, "Seeked media"); } -STATIC json_object* upload (AFB_request *request) { /* AFB_SESSION_CHECK */ +STATIC json_object* upload (AFB_request *request, AFB_PostItem *item) { /* AFB_SESSION_CHECK */ mediaCtxHandleT *ctx = (mediaCtxHandleT*)request->context; - const char *value = getQueryValue (request, "value"); + AFB_PostCtx *postFileCtx; json_object *jresp; - char path[256]; + char *path; - /* no "?value=" parameter : return error */ - if (!value) - return jsonNewMessage(AFB_FAIL, "You must provide a file name"); + /* item is !NULL until transfer is complete */ + if (item != NULL) + return getPostFile (request, item, "media"); - snprintf (path, sizeof(path), "/tmp/%s", value); - if (access (path, R_OK) == -1) - return jsonNewMessage(AFB_FAIL, "File not found"); + /* target intermediary file path */ + path = getPostPath (request); - if (!_rygel_upload (ctx, path)) - return jsonNewMessage(AFB_FAIL, "Error when uploading file... could not complete"); + if (!path) + fprintf (stderr, "Error encoutered during intermediary file transfer\n"); + + else if (!_rygel_upload (ctx, path)) { + request->errcode = MHD_HTTP_EXPECTATION_FAILED; + request->jresp = jsonNewMessage (AFB_FAIL, "Error when uploading file to media server... could not complete"); + } + + else { + request->errcode = MHD_HTTP_OK; + request->jresp = jsonNewMessage (AFB_SUCCESS, "upload=%s done", path); + } - return jsonNewMessage(AFB_SUCCESS, "File successfully uploaded"); + /* finalizes file transfer */ + return getPostFile (request, item, NULL); } STATIC json_object* ping (AFB_request *request) { /* AFB_SESSION_NONE */