From 46d09048e1650e8c402889399e25b648c6e7b02d Mon Sep 17 00:00:00 2001 From: Sakshi Bobade Date: Thu, 9 Feb 2023 20:25:36 +0530 Subject: [PATCH 1/3] Adding the Native Json Printer --- c/json.c | 13 +++++++++++++ h/json.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/c/json.c b/c/json.c index 8c23fe78e..de3aab1b9 100644 --- a/c/json.c +++ b/c/json.c @@ -148,10 +148,23 @@ jsonPrinter *makeCustomUtf8JsonPrinter(void (*writeMethod)(jsonPrinter *, char * return p; } +jsonPrinter *makeCustomNativeJsonPrinter(void (*writeMethod)(jsonPrinter *, char *, int), + void *object, int inputCCSID) { + jsonPrinter *p = makeCustomJsonPrinter(writeMethod, object); + + p->mode = JSON_MODE_NATIVE_CHARSET; + p->inputCCSID = inputCCSID; + return p; +} + jsonPrinter *makeBufferJsonPrinter(int inputCCSID, JsonBuffer *buf) { return makeCustomUtf8JsonPrinter(&writeToBuffer, buf, inputCCSID); } +jsonPrinter *makeBufferNativeJsonPrinter(int inputCCSID, JsonBuffer *buf) { + return makeCustomNativeJsonPrinter(&writeToBuffer, buf, inputCCSID); +} + void jsonEnablePrettyPrint(jsonPrinter *p) { p->prettyPrint = TRUE; } diff --git a/h/json.h b/h/json.h index 7b120fe60..38add15de 100644 --- a/h/json.h +++ b/h/json.h @@ -89,6 +89,9 @@ jsonPrinter *makeCustomJsonPrinter(void (*writeMethod)(jsonPrinter *,char *,int) jsonPrinter *makeCustomUtf8JsonPrinter( void (*writeMethod)(jsonPrinter *, char *, int), void *object, int inputCCSID); +jsonPrinter *makeCustomNativeJsonPrinter( + void (*writeMethod)(jsonPrinter *, char *, int), void *object, + int inputCCSID); /** * \brief Reset a printer to its starting state. @@ -97,6 +100,8 @@ void jsonPrinterReset(jsonPrinter *printer); jsonPrinter *makeBufferJsonPrinter(int inputCCSID, JsonBuffer *buf); +jsonPrinter *makeBufferNativeJsonPrinter(int inputCCSID, JsonBuffer *buf); + /** * \brief This will change the JSON printing to generate newlines and indentation to make the output human-friendly. * From c2deb71a5b190f07084b7c91dbf7cafa7df191d7 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Fri, 24 Feb 2023 07:29:43 -0500 Subject: [PATCH 2/3] Removed obsolete message Signed-off-by: Martin Zeithaml --- c/httpserver.c | 1 - 1 file changed, 1 deletion(-) diff --git a/c/httpserver.c b/c/httpserver.c index e658d066a..7ce574c19 100644 --- a/c/httpserver.c +++ b/c/httpserver.c @@ -4979,7 +4979,6 @@ void parseURLMask(HttpService *service, char *urlMask){ if (strcmp(urlMask,"/")){ while ((slashPos = indexOf(urlMask,len,'/',prevSlashPos+1)) != -1){ - zowelog(NULL, LOG_COMP_HTTPSERVER, ZOWE_LOG_DEBUG3, "wow\n"); int partLen = slashPos - prevSlashPos; char *part = (char*) safeMalloc(NORMALIZED_PART_LENGTH, "urlMask part"); zowelog(NULL, LOG_COMP_HTTPSERVER, ZOWE_LOG_DEBUG3, "parse URL mask loop top len=%d slashPos=%d prevSlashPos=%d partLen=%d\n", From 359d8f4a328de2d07abfe8289828823fee349b01 Mon Sep 17 00:00:00 2001 From: 1000TurquoisePogs Date: Fri, 10 Mar 2023 04:39:55 -0500 Subject: [PATCH 3/3] Fix that file copy was writing random bytes to destination due to uninitialized pointer Signed-off-by: 1000TurquoisePogs --- CHANGELOG.md | 4 ++++ c/httpfileservice.c | 14 ++++++++++---- c/zosfile.c | 19 ++++++++++--------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be845d1a..7f62a1b4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Zowe Common C Changelog +## `2.8.0` + +- Bugfix: `fileCopy` would not work when convert encoding was not requested. The destination file would be created, but without the requested content. + ## `2.5.0` - Added embeddedjs command "xplatform.appendFileUTF8" for appending to files rather than writing whole files. diff --git a/c/httpfileservice.c b/c/httpfileservice.c index cc19ab8f6..085d9be95 100644 --- a/c/httpfileservice.c +++ b/c/httpfileservice.c @@ -508,9 +508,12 @@ void copyUnixDirectoryAndRespond(HttpResponse *response, char *oldAbsolutePath, case RC_HTTP_FILE_SERVICE_NOT_FOUND: respondWithJsonError(response, "Directory not found", 404, "Not Found"); break; - default: - respondWithJsonError(response, "Failed to copy a directory", 500, "Internal Server Error"); + default: { + char error[64]; + snprintf(error, 64, "Error copying directory, rc=%d", returnCode); + respondWithJsonError(response, error, 500, "Internal Server Error"); break; + } } } } @@ -593,9 +596,12 @@ void copyUnixFileAndRespond(HttpResponse *response, char *oldAbsolutePath, char case RC_HTTP_FILE_SERVICE_NOT_FOUND: respondWithJsonError(response, "File not found", 404, "Not Found"); break; - default: - respondWithJsonError(response, "Failed to copy a file", 500, "Internal Server Error"); + default: { + char error[64]; + snprintf(error, 64, "Error copying file, rc=%d", returnCode); + respondWithJsonError(response, error, 500, "Internal Server Error"); break; + } } } } diff --git a/c/zosfile.c b/c/zosfile.c index 84bc12faf..497580bf7 100644 --- a/c/zosfile.c +++ b/c/zosfile.c @@ -655,7 +655,7 @@ int fileCopyConverted(const char *existingFileName, const char *newFileName, char *fileBuffer = safeMalloc(FILE_BUFFER_SIZE,"fileCopyBuffer"); int conversionBufferLength = FILE_BUFFER_SIZE * MAX_CONVERT_FACTOR; char *conversionBuffer = (shouldConvert ? safeMalloc(conversionBufferLength,"fileCopyConvertBuffer"): NULL); - char *writeBuffer = (shouldConvert ? conversionBuffer : writeBuffer); + char *writeBuffer = (shouldConvert ? conversionBuffer : fileBuffer); int writeLength; int returnValue = 0; @@ -680,14 +680,15 @@ int fileCopyConverted(const char *existingFileName, const char *newFileName, } else { writeLength = bytesRead; } - - status = fileWrite(newFile, writeBuffer, writeLength, &returnCode, &reasonCode); - if (status == -1) { - *retCode = returnCode; - *resCode = reasonCode; - returnValue = -1; - goto cleanup; - } + if (bytesRead > 0) { + status = fileWrite(newFile, writeBuffer, writeLength, &returnCode, &reasonCode); + if (status == -1) { + *retCode = returnCode; + *resCode = reasonCode; + returnValue = -1; + goto cleanup; + } + } } while (bytesRead != 0); status = fileClose(existingFile, &returnCode, &reasonCode);