From c6e9a7a7838d0a943b5207c7c21f2eef7c2496dd Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Wed, 5 Aug 2020 11:28:04 +0200 Subject: [PATCH] Add the functionality to download folder content. Signed-off-by: Akayeshmantha --- c/unixFileService.c | 35 +++++++++++++++++++++++++++++++++++ c/zss.c | 1 + h/unixFileService.h | 1 + 3 files changed, 37 insertions(+) diff --git a/c/unixFileService.c b/c/unixFileService.c index eb834ad29..441c00b7d 100644 --- a/c/unixFileService.c +++ b/c/unixFileService.c @@ -981,6 +981,26 @@ static int serveUnixFileChangeOwner (HttpService *service, HttpResponse *respons return 0; } +static int serveUnixFolderDownloadMode(HttpService *service, HttpResponse *response) { + HttpRequest *request = response->request; + char *routeFileFrag = stringListPrint(request->parsedFile, 2, 1000, "/", 0); + + if (routeFileFrag == NULL || strlen(routeFileFrag) == 0) { + respondWithJsonError(response, "Required absolute path of the resource is not provided", HTTP_STATUS_BAD_REQUEST, "Bad Request"); + return 0; + } + char *encodedRouteFolder = stringConcatenate(response->slh, "/", routeFileFrag); + char *routeFolderName = cleanURLParamValue(response->slh, encodedRouteFolder); + + if (!strcmp(request->method, methodGET)) { + createFileFromUnixDirectoryAndRespond (response, routeFolderName); + } + else { + respondWithJsonError(response, "Method Not Allowed", HTTP_STATUS_METHOD_NOT_FOUND, "Bad Request"); + return 0; + } + return 0; +} static int serveTableOfContents(HttpService *service, HttpResponse *response) { HttpRequest *request = response->request; @@ -1023,6 +1043,10 @@ static int serveTableOfContents(HttpService *service, HttpResponse *response) { jsonAddString(out, "chmod", "/unixfile/chmod/{absPath}"); jsonEndObject(out); + jsonStartObject(out, NULL); + jsonAddString(out, "folderdownload", "/unixfile/folderdownload/{absPath}"); + jsonEndObject(out); + jsonEndArray(out); jsonEnd(out); @@ -1144,6 +1168,17 @@ void installUnixFileTableOfContentsService(HttpServer *server) { registerHttpService(server, httpService); } +void installUnixFolderToFileConvertAndDownloadService(HttpServer *server) { + HttpService *httpService = makeGeneratedService("UnixFolderDownload", + "/unixfile/folderdownload/**"); + httpService->authType = SERVICE_AUTH_NATIVE_WITH_SESSION_TOKEN; + httpService->serviceFunction = serveUnixFolderDownloadMode; + httpService->runInSubtask = TRUE; + httpService->doImpersonation = TRUE; + registerHttpService(server, httpService); +} + + /* This program and the accompanying materials are diff --git a/c/zss.c b/c/zss.c index 54abb3806..eeeb138f4 100644 --- a/c/zss.c +++ b/c/zss.c @@ -1216,6 +1216,7 @@ int main(int argc, char **argv){ installUnixFileMetadataService(server); installUnixFileChangeOwnerService(server); installUnixFileChangeModeService(server); + installUnixFolderToFileConvertAndDownloadService(server); installUnixFileTableOfContentsService(server); /* This needs to be registered last */ #ifdef __ZOWE_OS_ZOS installVSAMDatasetContentsService(server); diff --git a/h/unixFileService.h b/h/unixFileService.h index c0a9b0fb4..64e82d33b 100644 --- a/h/unixFileService.h +++ b/h/unixFileService.h @@ -22,6 +22,7 @@ void installUnixFileMetadataService(HttpServer *server); void installUnixFileChangeOwnerService(HttpServer *server); void installUnixFileTableOfContentsService(HttpServer *server); void installUnixFileChangeModeService(HttpServer *server); +void installUnixFolderToFileConvertAndDownloadService(HttpServer *server); #endif