From d9d5f848f028569f103215c5e6ab3ae96fd3cdfd Mon Sep 17 00:00:00 2001 From: Charlie Caron Date: Tue, 30 Jul 2019 14:34:45 -0400 Subject: [PATCH] Created functionality for creating dataset members Signed-off-by: Charlie Caron --- c/datasetjson.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ h/datasetjson.h | 4 ++ h/logging.h | 1 + 3 files changed, 111 insertions(+) diff --git a/c/datasetjson.c b/c/datasetjson.c index 97fb7f093..e8ea7ecc3 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -53,6 +53,7 @@ static int defaultVSAMCSIFieldCount = 4; static char getRecordLengthType(char *dscb); static int getMaxRecordLength(char *dscb); +static int getDSCB(char* datasetName, char* dscb, int bufferSize); static void respondWithNonVSAMDataset(HttpResponse* response, char* absolutePath, int jsonMode); static void respondWithVSAMDataset(HttpResponse* response, char* absolutePath, hashtable *acbTable, int jsonMode); static void updateNonVSAMDataset(HttpResponse* response, char* absolutePath, int jsonMode); @@ -1719,6 +1720,111 @@ void respondWithHLQNames(HttpResponse *response, MetadataQueryCache *metadataQue #endif /* __ZOWE_OS_ZOS */ } +static int getDSCB(char* datasetName, char* dscb, int bufferSize){ + if (bufferSize < INDEXED_DSCB){ + zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING, + "DSCB of size %d is too small, must be at least %d", bufferSize, INDEXED_DSCB); + return 1; + } + Volser volser = {0}; + + DatasetName dsn = {0}; + memcpy(dsn.value, datasetName, DATASET_NAME_LEN); + + int volserSuccess = getVolserForDataset(&dsn, &volser); + if(!volserSuccess){ + int rc = obtainDSCB1(dsn.value, sizeof(dsn.value), + volser.value, sizeof(volser.value), + dscb); + if (rc == 0){ + if (DSCB_TRACE){ + zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING, "DSCB for %.*s found\n", sizeof(dsn.value), dsn.value); + dumpbuffer(dscb,INDEXED_DSCB); + } + } + return 0; + } + else { + return 1; + } +} + +void newDatasetMember(HttpResponse* response, char* datasetPath, char* memberName) { + char dscb[INDEXED_DSCB] = {0}; + int bufferSize = sizeof(dscb); + if (getDSCB(datasetPath, dscb, bufferSize) != 0) { + respondWithJsonError(response, "Error decoding dataset", 400, "Bad Request"); + } + else { + if (!isPartionedDataset(dscb)) { + respondWithJsonError(response, "Dataset must be PDS/E", 400, "Bad Request"); + } + else { + char *overwriteParam = getQueryParam(response->request,"overwrite"); + int overwrite = !strcmp(overwriteParam, "TRUE") ? TRUE : FALSE; + char fullPath[DATASET_MEMBER_MAXLEN + 1] = {0}; + //concatenates dataset name with member name + char *dsName = strtok(datasetPath, " "); + char *memName = strtok(memberName, " "); + snprintf(fullPath, DATASET_MEMBER_MAXLEN, "//'%s(%s)'", dsName, memName); + bool memberExists = FALSE; + FILE* memberFP = fopen(fullPath,"r"); + if (memberFP) { + memberExists = TRUE; + if (fclose(memberFP)) { + zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING, "ERROR CLOSING FILE"); + respondWithJsonError(response, "Could not close dataset", 500, "Internal Server Error"); + } + } + if (memberExists && overwrite != TRUE) {//Member already exists and overwrite wasn't specified + respondWithJsonError(response, "Member already exists and overwrite not specified", 400, "Bad Request"); + } + else { // Member doesn't exist + FILE* newMember = fopen(fullPath, "w"); + if (!newMember){ + respondWithJsonError(response, "Bad dataset name", 400, "Bad Request"); + return; + } + if (!fclose(newMember)){ + response200WithMessage(response, "Successfully created member"); + } + else { + zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING, "ERROR CLOSING FILE"); + respondWithJsonError(response, "Could not close dataset", 500, "Internal Server Error"); + } + } + } + } +} + +void removeDatasetMember(HttpResponse* response, char* datasetPath, char* memberName) { + char dscb[INDEXED_DSCB] = {0}; + int bufferSize = sizeof(dscb); + if (getDSCB(datasetPath, dscb, bufferSize) != 0) { + respondWithJsonError(response, "Error decoding dataset", 400, "Bad Request"); + } + else { + if (!isPartionedDataset(dscb)) { + respondWithJsonError(response, "Dataset must be PDS/E", 400, "Bad Request"); + } + else { + char fullPath[DATASET_MEMBER_MAXLEN + 1] = {0}; + //concatenates dataset name with member name + char *dsName = strtok(datasetPath, " "); + char *memName = strtok(memberName, " "); + snprintf(fullPath, DATASET_MEMBER_MAXLEN, "//'%s(%s)'", dsName, memName); + if (remove(fullPath) == 0) { + response200WithMessage(response, "Successfully deleted"); + return; + } + else { + respondWithJsonError(response, "Could not delete, member likely does not exist", 400, "Bad Request"); + return; + } + } + } +} + #endif /* not METTLE - the whole module */ diff --git a/h/datasetjson.h b/h/datasetjson.h index bcf5de66d..b0265e018 100644 --- a/h/datasetjson.h +++ b/h/datasetjson.h @@ -23,6 +23,8 @@ #define SAF_AUTHORIZATION_READ 0x04 #define SAF_AUTHORIZATION_UPDATE 0x08 +#define MEMBER_MAX 8 +#define DATASET_MEMBER_MAXLEN DATASET_NAME_LEN + MEMBER_MAX + 6 typedef struct MetadataQueryCache_tag{ EntryDataSet *cachedHLQSet; @@ -63,6 +65,8 @@ void respondWithDatasetMetadata(HttpResponse *response); void respondWithHLQNames(HttpResponse *response, MetadataQueryCache *metadataQueryCache); void respondWithDataset(HttpResponse* response, char* fullPath, int jsonMode, HttpService* service); void updateDataset(HttpResponse* response, char* fullPath, int jsonMode, HttpService* service); +void removeDatasetMember(HttpResponse* response, char* datasetPath, char* memberName); +void newDatasetMember(HttpResponse* response, char* datasetPath, char* memberName); #endif diff --git a/h/logging.h b/h/logging.h index c4d498062..04cddcd9c 100644 --- a/h/logging.h +++ b/h/logging.h @@ -89,6 +89,7 @@ ZOWE_PRAGMA_PACK_RESET #define LOG_COMP_DATASERVICE 0x008F0001000B0000LLU #define LOG_COMP_CMS 0x008F0001000C0000LLU #define LOG_COMP_LPA 0x008F0001000D0000LLU +#define LOG_COMP_DATASETJSON 0x008F0001000E0000LLU #define LOG_DEST_DEV_NULL 0x008F0000 #define LOG_DEST_PRINTF_STDOUT 0x008F0001