From f16b5926877ae3aaff656bcbec4f884959102e9c Mon Sep 17 00:00:00 2001 From: Tim Gerstel Date: Tue, 21 Sep 2021 19:20:54 -0400 Subject: [PATCH 01/12] Merge staging with dataset creation pr#60 Signed-off-by: Tim Gerstel --- c/datasetjson.c | 376 ++++++++++++++++++++++++++++++++++++++++++++++++ c/dynalloc.c | 79 ++++++++++ h/datasetjson.h | 4 + h/dynalloc.h | 50 +++++++ 4 files changed, 509 insertions(+) diff --git a/c/datasetjson.c b/c/datasetjson.c index b324ad595..fc045daab 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -27,6 +27,7 @@ #include "bpxnet.h" #include "logging.h" #include "unixfile.h" +#include "errno.h" #ifdef __ZOWE_OS_ZOS #include "zos.h" #endif @@ -58,6 +59,10 @@ static char vsamCSITypes[5] = {'R', 'D', 'G', 'I', 'C'}; static char getRecordLengthType(char *dscb); static int getMaxRecordLength(char *dscb); +static int updateInputParmsProperty(JsonObject *object, int *configsCount, DynallocNewTextUnit *textUnit); +static void setTextUnitString(int size, char* data, int *configsCount, int key, DynallocNewTextUnit *textUnit); +static void setTextUnitCharOrInt(int size, int data, int *configsCount, int key, DynallocNewTextUnit *textUnit); +static void setTextUnitBool(int *configsCount, int key, DynallocNewTextUnit *textUnit); typedef struct DatasetName_tag { char value[44]; /* space-padded */ @@ -347,6 +352,27 @@ static int isPartionedDataset(char *dscb) { } #endif +static bool isVSAM(char* dsPath) { + char dscb[INDEXED_DSCB] = {0}; + Volser volser = {0}; + DatasetName dsn = {0}; + memcpy(dsn.value,dsPath+3,strlen(dsPath)-4); + padWithSpaces(dsn.value, sizeof(dsn.value), 0, 0); + + int volserSuccess = getVolserForDataset(&dsn, &volser); + if(!volserSuccess){ + obtainDSCB1(dsn.value, sizeof(dsn.value), + volser.value, sizeof(volser.value), + dscb); + int posOffset = 44; + int dsorgLow = dscb[83-posOffset]; + if (dsorgLow & 0x08){ + return TRUE; + } + } + return FALSE; +} + static int obtainDSCB1(const char *dsname, unsigned int dsnameLength, const char *volser, unsigned int volserLength, char *dscb1) { @@ -2244,6 +2270,356 @@ void respondWithHLQNames(HttpResponse *response, MetadataQueryCache *metadataQue } +static int updateInputParmsProperty(JsonObject *object, int *configsCount, DynallocNewTextUnit *textUnit) { + Json* value = jsonObjectGetPropertyValue(object, "dsorg"); + if (jsonIsString(value)){ + if (!strcmp(value->data.string, "PS")) { + setTextUnitCharOrInt(sizeof(short), DALDSORG_PS, configsCount, DALDSORG, textUnit); + } + else if (!strcmp(value->data.string, "PO")) { + setTextUnitCharOrInt(sizeof(short), DALDSORG_PO, configsCount, DALDSORG, textUnit); + } + } + + errno = 0; + value = jsonObjectGetPropertyValue(object, "blksz"); + if (jsonIsString(value)){ + long toi = strtol(value->data.string, NULL, 0); + if(errno != ERANGE){ + if (toi <= 0x7FF8 && toi >= 0) { //<-- If DASD, if tape, it can be 80000000 + setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALBLKSZ, textUnit); + } + else if (toi <= 0x80000000){ + setTextUnitCharOrInt(sizeof(long long), toi, configsCount, DALBLKSZ, textUnit); + } + } + } + + errno = 0; + value = jsonObjectGetPropertyValue(object, "lrecl"); + if (jsonIsString(value)){ + long toi = strtol(value->data.string, NULL, 0); + if (errno != ERANGE){ + if (toi == 0x8000) { + setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); + } + else if (toi <= 0x7FF8 && toi >= 0) { + setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); + } + } + } + value = jsonObjectGetPropertyValue(object, "volser"); + if (jsonIsString(value)){ + if (strlen(value->data.string) <= VOLSER_SIZE){ + setTextUnitString(VOLSER_SIZE, &(value->data.string)[0], configsCount, DALVLSER, textUnit); + } + } + + value = jsonObjectGetPropertyValue(object, "recfm"); + if (jsonIsString(value)){ + int setRECFM = 0; + if (indexOf(value->data.string, strlen(value->data.string), 'A', 0) != -1){ + setRECFM = setRECFM | DALRECFM_A; + } + if (indexOf(value->data.string, strlen(value->data.string), 'B', 0) != -1){ + setRECFM = setRECFM | DALRECFM_B; + } + if (indexOf(value->data.string, strlen(value->data.string), 'V', 0) != -1){ + setRECFM = setRECFM | DALRECFM_V; + } + if (indexOf(value->data.string, strlen(value->data.string), 'F', 0) != -1){ + setRECFM = setRECFM | DALRECFM_F; + } + if (indexOf(value->data.string, strlen(value->data.string), 'U', 0) != -1){ + setRECFM = setRECFM | DALRECFM_U; + } + setTextUnitCharOrInt(sizeof(char), setRECFM, configsCount, DALRECFM, textUnit); + } + + errno = 0; + value = jsonObjectGetPropertyValue(object, "prime"); + if (jsonIsString(value)){ + long toi = strtol(value->data.string, NULL, 0); + if (toi <= 0xFFFFFF || toi >= 0) { + if (errno != ERANGE){ + setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, DALPRIME, textUnit); + } + } + } + + errno = 0; + value = jsonObjectGetPropertyValue(object, "second"); + if (jsonIsString(value)){ + long toi = strtol(value->data.string, NULL, 0); + if (toi <= 0xFFFFFF || toi >= 0) { + if (errno != ERANGE){ + setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, DALSECND, textUnit); + } + } + } + + value = jsonObjectGetPropertyValue(object, "space"); + if (jsonIsString(value)){ + if (!strcmp(value->data.string, "cyl")){ + setTextUnitBool(configsCount, DALCYL, textUnit); + } + if (!strcmp(value->data.string, "trk")){ + setTextUnitBool(configsCount, DALCYL, textUnit); + } + } + + errno = 0; + value = jsonObjectGetPropertyValue(object, "blkln"); + if (jsonIsString(value)){ + long toi = strtol(value->data.string, NULL, 0); + if (toi <= 0xFFFF || toi >= 0) { + if (errno != ERANGE){ + setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, DALBLKLN, textUnit); + } + } + } + + value = jsonObjectGetPropertyValue(object, "status"); + if (jsonIsString(value)){ + if (!strcmp(value->data.string, "OLD")){ + setTextUnitCharOrInt(sizeof(char), DISP_OLD, configsCount, DALSTATS, textUnit); + } + else if (!strcmp(value->data.string, "MOD")){ + setTextUnitCharOrInt(sizeof(char), DISP_MOD, configsCount, DALSTATS, textUnit); + } + else if (!strcmp(value->data.string, "SHARE")){ + setTextUnitCharOrInt(sizeof(char), DISP_SHARE, configsCount, DALSTATS, textUnit); + } + else { + setTextUnitCharOrInt(sizeof(char), DISP_NEW, configsCount, DALSTATS, textUnit); + } + } + else { + setTextUnitCharOrInt(sizeof(char), DISP_NEW, configsCount, DALSTATS, textUnit); + } + + value = jsonObjectGetPropertyValue(object, "ndisp"); + if (jsonIsString(value)){ + if (!strcmp(value->data.string, "UNCATLG")){ + setTextUnitCharOrInt(sizeof(char), DISP_UNCATLG, configsCount, DALNDISP, textUnit); + } + else if (!strcmp(value->data.string, "DELETE")){ + setTextUnitCharOrInt(sizeof(char), DISP_DELETE, configsCount, DALNDISP, textUnit); + } + else if (!strcmp(value->data.string, "KEEP")){ + setTextUnitCharOrInt(sizeof(char), DISP_KEEP, configsCount, DALNDISP, textUnit); + } + else { + setTextUnitCharOrInt(sizeof(char), DISP_CATLG, configsCount, DALNDISP, textUnit); + } + } + else { + setTextUnitCharOrInt(sizeof(char), DISP_CATLG, configsCount, DALNDISP, textUnit); + } + + value = jsonObjectGetPropertyValue(object, "unit"); + if (jsonIsString(value)){ + setTextUnitString(strlen(value->data.string), &(value->data.string)[0], configsCount, DALUNIT, textUnit); + } + + value = jsonObjectGetPropertyValue(object, "sysout"); + if (jsonIsString(value)){ + if (!strcmp(value->data.string, "default")){ + for(int i = 0; i < *configsCount; i++) { + if (textUnit[i].key == DALSTATS || textUnit[i].key == DALNDISP) { + textUnit[i].type = TEXT_UNIT_NULL; + } + } + setTextUnitBool(configsCount, DALSYSOU, textUnit); + } + else if (isalnum(value->data.string[0])) { + for(int i = 0; i < *configsCount; i++) { + if (textUnit[i].key == DALSTATS || textUnit[i].key == DALNDISP) { + textUnit[i].type == TEXT_UNIT_NULL; + } + } + setTextUnitCharOrInt(1, value->data.string[0], configsCount, DALSYSOU, textUnit); + } + } + + value = jsonObjectGetPropertyValue(object, "spgnm"); + if (jsonIsString(value)){ + if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ + setTextUnitString(strlen(value->data.string), &(value->data.string)[0], configsCount, DALSPGNM, textUnit); + } + } + + value = jsonObjectGetPropertyValue(object, "close"); + if (jsonIsString(value)){ + if (!strcmp(value->data.string, "true")){ + setTextUnitBool(configsCount, DALCLOSE, textUnit); + } + } + + value = jsonObjectGetPropertyValue(object, "dummy"); + if (jsonIsString(value)){ + if (!strcmp(value->data.string, "true")){ + setTextUnitBool(configsCount, DALDUMMY, textUnit); + } + } + + value = jsonObjectGetPropertyValue(object, "dcbdd"); + if (jsonIsString(value)){ + if (strlen(value->data.string) <= DD_NAME_LEN){ + setTextUnitString(DD_NAME_LEN, &(value->data.string)[0], configsCount, DALDCBDD, textUnit); + } + } + + value = jsonObjectGetPropertyValue(object, "retdd"); + if (jsonIsString(value)){ + if (strlen(value->data.string) <= DD_NAME_LEN){ + setTextUnitString(DD_NAME_LEN, &(value->data.string)[0], configsCount, DALRTDDN, textUnit); + } + } + + value = jsonObjectGetPropertyValue(object, "spin"); + if (jsonIsString(value)){ + if (!strcmp(value->data.string, "UNALLOC")){ + setTextUnitCharOrInt(1, SPIN_UNALLOC, configsCount, DALSPIN, textUnit); + } + else if (!strcmp(value->data.string, "ENDJOB")){ + setTextUnitCharOrInt(1, SPIN_ENDJOB, configsCount, DALSPIN, textUnit); + } + } + + value = jsonObjectGetPropertyValue(object, "strcls"); + if (jsonIsString(value)){ + if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ + setTextUnitString(8, &(value->data.string)[0], configsCount, DALSTCL, textUnit); + } + } + + value = jsonObjectGetPropertyValue(object, "mngcls"); + if (jsonIsString(value)){ + if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ + setTextUnitString(CLASS_WRITER_SIZE, &(value->data.string)[0], configsCount, DALMGCL, textUnit); + } + } + + value = jsonObjectGetPropertyValue(object, "datacls"); + if (jsonIsString(value)){ + if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ + setTextUnitString(CLASS_WRITER_SIZE, &(value->data.string)[0], configsCount, DALDACL, textUnit); + } + } +} + +static void setTextUnitString(int size, char* data, int *configsCount, int key, DynallocNewTextUnit *textUnit) { + textUnit[*configsCount].size = size; + textUnit[*configsCount].type = TEXT_UNIT_STRING; + textUnit[*configsCount].key = key; + textUnit[*configsCount].data.string = data; + (*configsCount)++; +} + +static void setTextUnitCharOrInt(int size, int data, int *configsCount, int key, DynallocNewTextUnit *textUnit) { + textUnit[*configsCount].size = size; + textUnit[*configsCount].type = TEXT_UNIT_CHARINT; + textUnit[*configsCount].key = key; + textUnit[*configsCount].data.number = data; + (*configsCount)++; +} + +static void setTextUnitBool(int *configsCount, int key, DynallocNewTextUnit *textUnit) { + textUnit[*configsCount].type = TEXT_UNIT_BOOLEAN; + textUnit[*configsCount].key = key; + (*configsCount)++; +} + +void newDataset(HttpResponse* response, char* datasetName, int jsonMode){ + #ifdef __ZOWE_OS_ZOS + + DatasetName dsn = {0}; + memset(dsn.value, ' ', DATASET_NAME_LEN); + + int lParenIndex = indexOf(datasetName, strlen(datasetName),'(',0); + + //String parsing operation, gets rid of of 3 initial unnecessary characters-> //' + if (lParenIndex > 0){ + memcpy(dsn.value,datasetName+3,lParenIndex-3); + } + //String parsing operation, gets rid of of 3 initial unnecessary characters-> //' + else{ + memcpy(dsn.value,datasetName+3,strlen(datasetName)-4); + } + + int configsCount = 0; + DynallocNewTextUnit textUnits[TOTAL_TEXT_UNITS]; + setTextUnitString(DATASET_NAME_LEN, &dsn.value[0], &configsCount, DALDSNAM, &textUnits[0]); + setTextUnitString(DD_NAME_LEN, "MVD00000", &configsCount, DALDDNAM, &textUnits[0]); + + if (jsonMode != TRUE) { /*TODO add support for updating files with raw bytes instead of JSON*/ + respondWithError(response, HTTP_STATUS_BAD_REQUEST,"Cannot update file without JSON formatted record request"); + return; + } + + HttpRequest *request = response->request; + + FileInfo info; + + char *contentBody = request->contentBody; + int bodyLength = strlen(contentBody); + + char *convertedBody = safeMalloc(bodyLength*4,"writeDatasetConvert"); + int conversionBufferLength = bodyLength*4; + int translationLength; + int outCCSID = NATIVE_CODEPAGE; + int reasonCode; + + int returnCode = convertCharset(contentBody, + bodyLength, + CCSID_UTF_8, + CHARSET_OUTPUT_USE_BUFFER, + &convertedBody, + conversionBufferLength, + outCCSID, + NULL, + &translationLength, + &reasonCode); + + if(returnCode == 0) { + + ShortLivedHeap *slh = makeShortLivedHeap(0x10000,0x10); + char errorBuffer[2048]; + Json *json = jsonParseUnterminatedString(slh, + convertedBody, translationLength, + errorBuffer, sizeof(errorBuffer)); + if (json) { + if (jsonIsObject(json)){ + JsonObject * jsonObject = jsonAsObject(json); + updateInputParmsProperty(jsonObject, &configsCount, &textUnits[0]); + } + } + } + + returnCode = dynallocNewDataset(&reasonCode, &textUnits[0], configsCount); + int ddNumber = 1; + char buffer[DD_NAME_LEN + 1]; + while (reasonCode==0x4100000 && ddNumber < 100000) { + sprintf(buffer, "MVD%05d", ddNumber); + int ddconfig = 1; + setTextUnitString(DD_NAME_LEN, buffer, &ddconfig, DALDDNAM, &textUnits[0]); + returnCode = dynallocNewDataset(&reasonCode, &textUnits[0], configsCount); + ddNumber++; + } + if (returnCode) { + printf("Dynalloc RC = %d, reasonCode = %x\n", returnCode, reasonCode); + respondWithError(response, HTTP_STATUS_INTERNAL_SERVER_ERROR, "Unable to allocate a DD for ACB"); + return; + } + else { + printf("Dynalloc RC = %d, reasonCode = %x\n", returnCode, reasonCode); + response200WithMessage(response, "Successfully created dataset"); + } + #endif +} + + #endif /* not METTLE - the whole module */ diff --git a/c/dynalloc.c b/c/dynalloc.c index 1d68ff3e9..517884b5f 100644 --- a/c/dynalloc.c +++ b/c/dynalloc.c @@ -60,6 +60,10 @@ TextUnit *createIntTextUnit(int key, int value) { return createSimpleTextUnit2(key, (char*)&value, sizeof(value)); } +TextUnit *createIntTextUnitLength(int key, int value, int length) { + return createSimpleTextUnit2(key, (char*)&value, length); +} + TextUnit *createInt8TextUnit(int key, int8_t value) { return createSimpleTextUnit2(key, (char*)&value, sizeof(value)); } @@ -68,6 +72,14 @@ TextUnit *createInt16TextUnit(int key, int16_t value) { return createSimpleTextUnit2(key, (char*)&value, sizeof(value)); } +TextUnit *createInt24TextUnit(int key, int value) { + return createSimpleTextUnit2(key, (char*)&value + 1, INT24_SIZE); +} + +TextUnit *createLongIntTextUnit(int key, long long value) { + return createSimpleTextUnit2(key, (char*)&value, sizeof(value)); +} + TextUnit *createCharTextUnit(int key, char value) { char valueArray[2]; valueArray[0] = value; @@ -75,6 +87,14 @@ TextUnit *createCharTextUnit(int key, char value) { return createSimpleTextUnit2(key, valueArray, 1); } +TextUnit *createCharTextUnit2(int key, short value) { + char valueArray[3]; + valueArray[0] = value >> BYTE_LENGTH & BYTE_FULL_MASK; + valueArray[1] = value & BYTE_FULL_MASK; + valueArray[2] = 0; + return createSimpleTextUnit2(key, valueArray, 2); +} + TextUnit *createCompoundTextUnit(int key, char **values, int valueCount) { TextUnit *textUnit = NULL; @@ -834,6 +854,65 @@ int dynallocDataset(DynallocInputParms *inputParms, int *reasonCode) { } +int dynallocNewDataset(int *reasonCode, DynallocNewTextUnit *setTextUnits, int TextUnitsSize) { + ALLOC_STRUCT31( + STRUCT31_NAME(below2G), + STRUCT31_FIELDS( + DynallocParms parms; + TextUnit ** __ptr32 textUnits; + ) + ); + + below2G->textUnits = (TextUnit **)safeMalloc(sizeof(TextUnit*) * TextUnitsSize, "Text units array"); + + DynallocParms *parms = &below2G->parms; + dynallocParmsInit(parms); + + dynallocParmsSetTextUnits(parms, below2G->textUnits, TextUnitsSize); + + int rc; + + do { + rc = -1; + for (int i = 0; i < TextUnitsSize; i++) { + if (setTextUnits[i].type == TEXT_UNIT_STRING) { + below2G->textUnits[i] = createSimpleTextUnit2(setTextUnits[i].key, setTextUnits[i].data.string, setTextUnits[i].size); + } + else if (setTextUnits[i].type == TEXT_UNIT_CHARINT) { + if (setTextUnits[i].size == sizeof(char)) { + below2G->textUnits[i] = createCharTextUnit(setTextUnits[i].key, setTextUnits[i].data.number); + } + else if (setTextUnits[i].size == sizeof(short)) { + below2G->textUnits[i] = createInt16TextUnit(setTextUnits[i].key, setTextUnits[i].data.number); + } + else if (setTextUnits[i].size == INT24_SIZE) { + below2G->textUnits[i] = createInt24TextUnit(setTextUnits[i].key, setTextUnits[i].data.number); + } + else if (setTextUnits[i].size == sizeof(long long)) { + long number = setTextUnits[i].data.number; + below2G->textUnits[i] = createLongIntTextUnit(setTextUnits[i].key, (long long)setTextUnits[i].data.number); + } + } + else if (setTextUnits[i].type == TEXT_UNIT_BOOLEAN) { + below2G->textUnits[i] = createSimpleTextUnit2(setTextUnits[i].key, NULL, 0); + } + } + + turn_on_HOB(below2G->textUnits[TextUnitsSize - 1]); + rc = invokeDynalloc(parms); + *reasonCode = dynallocParmsGetInfoCode(parms) + + (dynallocParmsGetErrorCode(parms) << 16); + } while (0); + freeTextUnitArray(below2G->textUnits, TextUnitsSize); + safeFree((char*)below2G->textUnits, sizeof(TextUnit*) * TextUnitsSize); + dynallocParmsTerm(parms); + parms = NULL; + FREE_STRUCT31( + STRUCT31_NAME(below2G) + ); + return rc; +} + int dynallocDatasetMember(DynallocInputParms *inputParms, int *reasonCode, char *member) { diff --git a/h/datasetjson.h b/h/datasetjson.h index b5ab5a60c..7c44d3e81 100644 --- a/h/datasetjson.h +++ b/h/datasetjson.h @@ -23,6 +23,9 @@ #define SAF_AUTHORIZATION_READ 0x04 #define SAF_AUTHORIZATION_UPDATE 0x08 +#define MEMBER_MAX 8 +#define DATASET_PATH_MAX 44 +#define DATASET_MEMBER_MAXLEN DATASET_PATH_MAX + MEMBER_MAX + 6 /* 6 is for extra characters in filepath -- //, '', () */ typedef struct MetadataQueryCache_tag{ EntryDataSet *cachedHLQSet; @@ -62,6 +65,7 @@ void respondWithDataset(HttpResponse* response, char* absolutePath, int jsonMode void respondWithVSAMDataset(HttpResponse* response, char* absolutePath, hashtable *acbTable, int jsonMode); void respondWithDatasetMetadata(HttpResponse *response); void respondWithHLQNames(HttpResponse *response, MetadataQueryCache *metadataQueryCache); +void newDataset(HttpResponse* response, char* absolutePath, int jsonMode); void updateDataset(HttpResponse* response, char* absolutePath, int jsonMode); void updateVSAMDataset(HttpResponse* response, char* absolutePath, hashtable *acbTable, int jsonMode); void deleteVSAMDataset(HttpResponse* response, char* absolutePath); diff --git a/h/dynalloc.h b/h/dynalloc.h index b75987233..473c62d44 100644 --- a/h/dynalloc.h +++ b/h/dynalloc.h @@ -209,7 +209,17 @@ X'40' Data set available for printing at the end of the job. #define DALVSER 0x0010 #define DALVSEQ 0x0012 #define DALDSORG 0x003C +#define DALDSORG_VSAM 0x0008 +#define DALDSORG_GRAPHICS 0x0080 +#define DALDSORG_PO 0x0200 +#define DALDSORG_POU 0x0300 +#define DALDSORG_MQ 0x0400 +#define DALDSORG_CQ 0x0800 +#define DALDSORG_CX 0x1000 +#define DALDSORG_DA 0x2000 +#define DALDSORG_DAU 0x2100 #define DALDSORG_PS 0x4000 +#define DALDSORG_PSU 0x4100 #define DALBLKSZ 0x0030 #define DALLRECL 0x0042 #define DALBUFNO 0x0034 @@ -252,8 +262,11 @@ TextUnit *createSimpleTextUnit2(int key, char *value, int firstParameterLength); TextUnit *createCharTextUnit(int key, char value); TextUnit *createCompoundTextUnit(int key, char **values, int valueCount); TextUnit *createIntTextUnit(int key, int value); +TextUnit *createCharTextUnit2(int key, short value); TextUnit *createInt8TextUnit(int key, int8_t value); +TextUnit *createIntTextUnitLength(int key, int value, int length); TextUnit *createInt16TextUnit(int key, int16_t value); +TextUnit *createInt24TextUnit(int key, int value); void freeTextUnit(TextUnit * text_unit); /* open a stream to the internal reader */ @@ -681,9 +694,29 @@ int DeallocDDName(char *ddname); // Values for disposition field #define DISP_OLD 0x01 #define DISP_MOD 0x02 +#define DISP_NEW 0x04 #define DISP_SHARE 0x08 #define DISP_DELETE 0x04 +// Values for normal disposition field +#define DISP_UNCATLG 0x01 +#define DISP_CATLG 0x02 +#define DISP_DELETE 0x04 +#define DISP_KEEP 0x08 + +#define DALSYSOU_DEFAULT 0x08 + +#define SPIN_UNALLOC 0x80 +#define SPIN_ENDJOB 0x40 + +#define BYTE_LENGTH 8 +#define BYTE_FULL_MASK 0xff + +#define INT24_SIZE 3 +#define VOLSER_SIZE 6 +#define CLASS_WRITER_SIZE 8 +#define TOTAL_TEXT_UNITS 23 + /* Use this structure to pass parameters to DYNALLOC functions. * Dsname should be padded by spaces. */ typedef struct DynallocInputParms_tag { @@ -696,11 +729,28 @@ typedef struct DynallocInputParms_tag { char reserved[3]; } DynallocInputParms; +typedef struct DynallocNewTextUnit_tag { +#define TEXT_UNIT_STRING 1 +#define TEXT_UNIT_BOOLEAN 2 +#define TEXT_UNIT_CHARINT 3 +#define TEXT_UNIT_NULL 4 +#define JSON_TYPE_ERROR 666 + int type; + int size; + int key; + union { + int number; + char *string; + int boolean; + } data; +} DynallocNewTextUnit; + #pragma map(dynallocDataset, "DYNAUALC") #pragma map(dynallocDatasetMember, "DYNAUALM") #pragma map(unallocDataset, "DYNADALC") int dynallocDataset(DynallocInputParms *inputParms, int *reasonCode); +int dynallocNewDataset(int *reasonCode, DynallocNewTextUnit *setTextUnits, int TextUnitsSize); int dynallocDatasetMember(DynallocInputParms *inputParms, int *reasonCode, char *member); int unallocDataset(DynallocInputParms *inputParms, int *reasonCode); From bb132a917e9790d26f189f6f3c70ce3f6c15aff3 Mon Sep 17 00:00:00 2001 From: Tim Gerstel Date: Thu, 23 Sep 2021 19:15:51 -0400 Subject: [PATCH 02/12] Add method for dataset member creation, todo: remove printfs, commented out code, etc Signed-off-by: Tim Gerstel --- c/datasetjson.c | 136 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 122 insertions(+), 14 deletions(-) diff --git a/c/datasetjson.c b/c/datasetjson.c index fc045daab..6001176de 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -59,6 +59,7 @@ static char vsamCSITypes[5] = {'R', 'D', 'G', 'I', 'C'}; static char getRecordLengthType(char *dscb); static int getMaxRecordLength(char *dscb); +static int getDSCB(char* datasetName, char* dscb, int bufferSize); static int updateInputParmsProperty(JsonObject *object, int *configsCount, DynallocNewTextUnit *textUnit); static void setTextUnitString(int size, char* data, int *configsCount, int key, DynallocNewTextUnit *textUnit); static void setTextUnitCharOrInt(int size, int data, int *configsCount, int key, DynallocNewTextUnit *textUnit); @@ -2531,26 +2532,116 @@ static void setTextUnitBool(int *configsCount, int key, DynallocNewTextUnit *tex (*configsCount)++; } -void newDataset(HttpResponse* response, char* datasetName, int jsonMode){ - #ifdef __ZOWE_OS_ZOS +static int getDSCB(char* datasetName, char* dscb, int bufferSize){ + if (bufferSize < INDEXED_DSCB){ + zowelog(NULL, LOG_COMP_RESTDATASET, 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}; - memset(dsn.value, ' ', DATASET_NAME_LEN); + memcpy(dsn.value, datasetName, DATASET_PATH_MAX); - int lParenIndex = indexOf(datasetName, strlen(datasetName),'(',0); + 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_RESTDATASET, ZOWE_LOG_WARNING, "DSCB for %.*s found\n", sizeof(dsn.value), dsn.value); + dumpbuffer(dscb,INDEXED_DSCB); + } + } + return 0; + } + else { + return 1; + } +} - //String parsing operation, gets rid of of 3 initial unnecessary characters-> //' - if (lParenIndex > 0){ - memcpy(dsn.value,datasetName+3,lParenIndex-3); +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"); } - //String parsing operation, gets rid of of 3 initial unnecessary characters-> //' - else{ - memcpy(dsn.value,datasetName+3,strlen(datasetName)-4); + 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 + 1, "//'%s(%s)'", dsName, memName); + FILE* memberExists = fopen(fullPath,"r"); + if (memberExists && overwrite != TRUE) {//Member already exists and overwrite wasn't specified + if (fclose(memberExists) != 0) { + zowelog(NULL, LOG_COMP_RESTDATASET, ZOWE_LOG_WARNING, "ERROR CLOSING FILE"); + respondWithJsonError(response, "Could not close dataset", 500, "Internal Server Error"); + } + else { + respondWithJsonError(response, "Member already exists and overwrite not specified", 400, "Bad Request"); + } + } + else { // Member doesn't exist + if (memberExists) { + if (fclose(memberExists) != 0) { + zowelog(NULL, LOG_COMP_RESTDATASET, ZOWE_LOG_WARNING, "ERROR CLOSING FILE"); + respondWithJsonError(response, "Could not close dataset", 500, "Internal Server Error"); + return; + } + } + FILE* newMember = fopen(fullPath, "w"); + if (!newMember){ + respondWithJsonError(response, "Bad dataset name", 400, "Bad Request"); + return; + } + if (fclose(newMember) == 0){ + response200WithMessage(response, "Successfully created member"); + } + else { + zowelog(NULL, LOG_COMP_RESTDATASET, ZOWE_LOG_WARNING, "ERROR CLOSING FILE"); + respondWithJsonError(response, "Could not close dataset", 500, "Internal Server Error"); + } + } + } + } +} + +void newDataset(HttpResponse* response, char* absolutePath, int jsonMode){ + #ifdef __ZOWE_OS_ZOS + HttpRequest *request = response->request; + if (!isDatasetPathValid(absolutePath)) { + respondWithError(response, HTTP_STATUS_BAD_REQUEST, "Invalid dataset name"); + return; + } + + DatasetName datasetName; + DatasetMemberName memberName; + extractDatasetAndMemberName(absolutePath, &datasetName, &memberName); + DynallocDatasetName daDatasetName; + DynallocMemberName daMemberName; + memcpy(daDatasetName.name, datasetName.value, sizeof(daDatasetName.name)); + memcpy(daMemberName.name, memberName.value, sizeof(daMemberName.name)); + DynallocDDName daDDName = {.name = "????????"}; + + int daRC = RC_DYNALLOC_OK, daSysReturnCode = 0, daSysReasonCode = 0; + + bool isMemberEmpty = IS_DAMEMBER_EMPTY(daMemberName); + + if(!isMemberEmpty){ + return newDatasetMember(response, daDatasetName.name, daMemberName.name); } int configsCount = 0; DynallocNewTextUnit textUnits[TOTAL_TEXT_UNITS]; - setTextUnitString(DATASET_NAME_LEN, &dsn.value[0], &configsCount, DALDSNAM, &textUnits[0]); + setTextUnitString(DATASET_NAME_LEN, &datasetName.value[0], &configsCount, DALDSNAM, &textUnits[0]); setTextUnitString(DD_NAME_LEN, "MVD00000", &configsCount, DALDDNAM, &textUnits[0]); if (jsonMode != TRUE) { /*TODO add support for updating files with raw bytes instead of JSON*/ @@ -2558,8 +2649,6 @@ void newDataset(HttpResponse* response, char* datasetName, int jsonMode){ return; } - HttpRequest *request = response->request; - FileInfo info; char *contentBody = request->contentBody; @@ -2601,6 +2690,7 @@ void newDataset(HttpResponse* response, char* datasetName, int jsonMode){ int ddNumber = 1; char buffer[DD_NAME_LEN + 1]; while (reasonCode==0x4100000 && ddNumber < 100000) { + printf("dnumber: %d\n", ddNumber); sprintf(buffer, "MVD%05d", ddNumber); int ddconfig = 1; setTextUnitString(DD_NAME_LEN, buffer, &ddconfig, DALDDNAM, &textUnits[0]); @@ -2615,11 +2705,29 @@ void newDataset(HttpResponse* response, char* datasetName, int jsonMode){ else { printf("Dynalloc RC = %d, reasonCode = %x\n", returnCode, reasonCode); response200WithMessage(response, "Successfully created dataset"); + DynallocInputParms inputParms; + memcpy(inputParms.ddName, buffer, DD_NAME_LEN); + printf("buffer: %s\ninputParms.ddName: %s\n", buffer, inputParms.ddName); + unallocDataset(&inputParms, &reasonCode); + if(reasonCode != 0) { + printf("unallocDataset RC: %d\n", reasonCode); + } + // daRC = dynallocUnallocDatasetByDDName2(&daDDName, DYNALLOC_UNALLOC_FLAG_NONE, + // &daSysReturnCode, &daSysReasonCode, + // false /* Delete data set on deallocation */ + // ); + // if (daRC != RC_DYNALLOC_OK) { + // zowelog(NULL, LOG_COMP_DATASERVICE, ZOWE_LOG_DEBUG, + // "error: ds unalloc dsn=\'%44.44s\', member=\'%8.8s\', dd=\'%8.8s\'," + // " rc=%d sysRC=%d, sysRSN=0x%08X (read)\n", + // daDatasetName.name, daMemberName.name, daDDName.name, daRC, daSysReturnCode, daSysReasonCode, "read"); + // return; + // } + return; } #endif } - #endif /* not METTLE - the whole module */ From 9bfe59e8ff5e426bab02dea8263f5c8396b5454b Mon Sep 17 00:00:00 2001 From: Tim Gerstel Date: Thu, 23 Sep 2021 19:21:02 -0400 Subject: [PATCH 03/12] Remove commented code, remove printf, remove unnecessary unalloc Signed-off-by: Tim Gerstel --- c/datasetjson.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/c/datasetjson.c b/c/datasetjson.c index 6001176de..dcaf26704 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -2690,7 +2690,6 @@ void newDataset(HttpResponse* response, char* absolutePath, int jsonMode){ int ddNumber = 1; char buffer[DD_NAME_LEN + 1]; while (reasonCode==0x4100000 && ddNumber < 100000) { - printf("dnumber: %d\n", ddNumber); sprintf(buffer, "MVD%05d", ddNumber); int ddconfig = 1; setTextUnitString(DD_NAME_LEN, buffer, &ddconfig, DALDDNAM, &textUnits[0]); @@ -2698,31 +2697,11 @@ void newDataset(HttpResponse* response, char* absolutePath, int jsonMode){ ddNumber++; } if (returnCode) { - printf("Dynalloc RC = %d, reasonCode = %x\n", returnCode, reasonCode); respondWithError(response, HTTP_STATUS_INTERNAL_SERVER_ERROR, "Unable to allocate a DD for ACB"); return; } else { - printf("Dynalloc RC = %d, reasonCode = %x\n", returnCode, reasonCode); response200WithMessage(response, "Successfully created dataset"); - DynallocInputParms inputParms; - memcpy(inputParms.ddName, buffer, DD_NAME_LEN); - printf("buffer: %s\ninputParms.ddName: %s\n", buffer, inputParms.ddName); - unallocDataset(&inputParms, &reasonCode); - if(reasonCode != 0) { - printf("unallocDataset RC: %d\n", reasonCode); - } - // daRC = dynallocUnallocDatasetByDDName2(&daDDName, DYNALLOC_UNALLOC_FLAG_NONE, - // &daSysReturnCode, &daSysReasonCode, - // false /* Delete data set on deallocation */ - // ); - // if (daRC != RC_DYNALLOC_OK) { - // zowelog(NULL, LOG_COMP_DATASERVICE, ZOWE_LOG_DEBUG, - // "error: ds unalloc dsn=\'%44.44s\', member=\'%8.8s\', dd=\'%8.8s\'," - // " rc=%d sysRC=%d, sysRSN=0x%08X (read)\n", - // daDatasetName.name, daMemberName.name, daDDName.name, daRC, daSysReturnCode, daSysReasonCode, "read"); - // return; - // } return; } #endif From b7b9fb05522966b5fb34265f3d9754c535f0461f Mon Sep 17 00:00:00 2001 From: Tim Gerstel Date: Fri, 24 Sep 2021 11:19:37 -0400 Subject: [PATCH 04/12] Refactor Signed-off-by: Tim Gerstel --- c/datasetjson.c | 106 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 82 insertions(+), 24 deletions(-) diff --git a/c/datasetjson.c b/c/datasetjson.c index dcaf26704..b690563a0 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -2272,7 +2272,63 @@ void respondWithHLQNames(HttpResponse *response, MetadataQueryCache *metadataQue static int updateInputParmsProperty(JsonObject *object, int *configsCount, DynallocNewTextUnit *textUnit) { - Json* value = jsonObjectGetPropertyValue(object, "dsorg"); + JsonProperty *currentProp = jsonObjectGetFirstProperty(object); + Json *value; + while(currentProp != NULL){ + /* Json **/value = jsonPropertyGetValue(currentProp); + char *valueString = jsonAsString(value); + errno = 0; + if(valueString != NULL){ + int valueStrLen = valueStrLen; + char *propString = jsonPropertyGetKey(currentProp); + if (!strcmp(propString, "dsorg")) { + setTextUnitCharOrInt(sizeof(short), !strcmp(valueString, "PS") ? DALDSORG_PS : DALDSORG_PO, configsCount, DALDSORG, textUnit); + } else if(!strcmp(propString, "blksz") || !strcmp(propString, "lrecl")){ + long toi = strtol(valueString, NULL, 0); + if(errno != ERANGE){ + int keyArg = !strcmp(propString, "blksz") ? DALBLKSZ : DALLRECL + if (toi <= 0x7FF8 && toi >= 0) { //<-- If DASD, if tape, it can be 80000000 + setTextUnitCharOrInt(sizeof(short), toi, configsCount, keyArg, textUnit); + } else if (toi <= 0x8000){ + setTextUnitCharOrInt(sizeof(long long), toi, configsCount, keyArg, textUnit); + } + } + } else if(!strcmp(propString, "volser")) { + if (valueStrLen <= VOLSER_SIZE){ + setTextUnitString(VOLSER_SIZE, &(valueString)[0], configsCount, DALVLSER, textUnit); + } + } else if(!strcmp(propString, "recfm")) { + int setRECFM = 0; + if (indexOf(valueString, valueStrLen, 'A', 0) != -1){ + setRECFM = setRECFM | DALRECFM_A; + } + if (indexOf(valueString, valueStrLen, 'B', 0) != -1){ + setRECFM = setRECFM | DALRECFM_B; + } + if (indexOf(valueString, valueStrLen, 'V', 0) != -1){ + setRECFM = setRECFM | DALRECFM_V; + } + if (indexOf(valueString, valueStrLen, 'F', 0) != -1){ + setRECFM = setRECFM | DALRECFM_F; + } + if (indexOf(valueString, valueStrLen, 'U', 0) != -1){ + setRECFM = setRECFM | DALRECFM_U; + } + setTextUnitCharOrInt(sizeof(char), setRECFM, configsCount, DALRECFM, textUnit); + } else if(!strcmp(propString, "prime") || !strcmp(propString, "second")) { + long toi = strtol(value->data.string, NULL, 0); + if (toi <= 0xFFFFFF || toi >= 0) { + int keyArg = !strcmp(propString, "prime") ? DALPRIME : DALSECND; + if (errno != ERANGE){ + setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, keyArg, textUnit); + } + } + } else { + continue; + } + } + } +/* Json* value = jsonObjectGetPropertyValue(object, "dsorg"); if (jsonIsString(value)){ if (!strcmp(value->data.string, "PS")) { setTextUnitCharOrInt(sizeof(short), DALDSORG_PS, configsCount, DALDSORG, textUnit); @@ -2280,9 +2336,9 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal else if (!strcmp(value->data.string, "PO")) { setTextUnitCharOrInt(sizeof(short), DALDSORG_PO, configsCount, DALDSORG, textUnit); } - } + } */ - errno = 0; +/* errno = 0; value = jsonObjectGetPropertyValue(object, "blksz"); if (jsonIsString(value)){ long toi = strtol(value->data.string, NULL, 0); @@ -2294,29 +2350,29 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal setTextUnitCharOrInt(sizeof(long long), toi, configsCount, DALBLKSZ, textUnit); } } - } - - errno = 0; - value = jsonObjectGetPropertyValue(object, "lrecl"); - if (jsonIsString(value)){ - long toi = strtol(value->data.string, NULL, 0); - if (errno != ERANGE){ - if (toi == 0x8000) { - setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); - } - else if (toi <= 0x7FF8 && toi >= 0) { - setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); - } - } - } - value = jsonObjectGetPropertyValue(object, "volser"); + } */ + + // errno = 0; + // value = jsonObjectGetPropertyValue(object, "lrecl"); + // if (jsonIsString(value)){ + // long toi = strtol(value->data.string, NULL, 0); + // if (errno != ERANGE){ + // if (toi == 0x8000) { + // setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); + // } + // else if (toi <= 0x7FF8 && toi >= 0) { + // setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); + // } + // } + // } +/* value = jsonObjectGetPropertyValue(object, "volser"); if (jsonIsString(value)){ if (strlen(value->data.string) <= VOLSER_SIZE){ setTextUnitString(VOLSER_SIZE, &(value->data.string)[0], configsCount, DALVLSER, textUnit); } - } + } */ - value = jsonObjectGetPropertyValue(object, "recfm"); +/* value = jsonObjectGetPropertyValue(object, "recfm"); if (jsonIsString(value)){ int setRECFM = 0; if (indexOf(value->data.string, strlen(value->data.string), 'A', 0) != -1){ @@ -2335,9 +2391,9 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal setRECFM = setRECFM | DALRECFM_U; } setTextUnitCharOrInt(sizeof(char), setRECFM, configsCount, DALRECFM, textUnit); - } + } */ - errno = 0; +/* errno = 0; value = jsonObjectGetPropertyValue(object, "prime"); if (jsonIsString(value)){ long toi = strtol(value->data.string, NULL, 0); @@ -2357,7 +2413,7 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, DALSECND, textUnit); } } - } + } */ value = jsonObjectGetPropertyValue(object, "space"); if (jsonIsString(value)){ @@ -2683,6 +2739,8 @@ void newDataset(HttpResponse* response, char* absolutePath, int jsonMode){ JsonObject * jsonObject = jsonAsObject(json); updateInputParmsProperty(jsonObject, &configsCount, &textUnits[0]); } + } else { + respondWithError(response, HTTP_STATUS_BAD_REQUEST, "Invalid JSON request body"); } } From 3db36762f0612f4723ede150a5690016d7a0594c Mon Sep 17 00:00:00 2001 From: Tim Gerstel Date: Mon, 27 Sep 2021 00:39:50 -0400 Subject: [PATCH 05/12] Refactor into c equiv of switch statment Signed-off-by: Tim Gerstel --- c/datasetjson.c | 194 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 142 insertions(+), 52 deletions(-) diff --git a/c/datasetjson.c b/c/datasetjson.c index b690563a0..7378ccb9c 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -2273,24 +2273,38 @@ void respondWithHLQNames(HttpResponse *response, MetadataQueryCache *metadataQue static int updateInputParmsProperty(JsonObject *object, int *configsCount, DynallocNewTextUnit *textUnit) { JsonProperty *currentProp = jsonObjectGetFirstProperty(object); + //printf("Updating input parms"); Json *value; + printf("updateInptuParmsProperty called\n"); while(currentProp != NULL){ - /* Json **/value = jsonPropertyGetValue(currentProp); + printf("currentProperty: %s\n", jsonPropertyGetKey(currentProp)); + value = jsonPropertyGetValue(currentProp); char *valueString = jsonAsString(value); errno = 0; if(valueString != NULL){ + printf("value for prop is not null\n"); int valueStrLen = valueStrLen; char *propString = jsonPropertyGetKey(currentProp); + if (!strcmp(propString, "dsorg")) { setTextUnitCharOrInt(sizeof(short), !strcmp(valueString, "PS") ? DALDSORG_PS : DALDSORG_PO, configsCount, DALDSORG, textUnit); - } else if(!strcmp(propString, "blksz") || !strcmp(propString, "lrecl")){ + } else if(!strcmp(propString, "blksz")) { long toi = strtol(valueString, NULL, 0); if(errno != ERANGE){ - int keyArg = !strcmp(propString, "blksz") ? DALBLKSZ : DALLRECL if (toi <= 0x7FF8 && toi >= 0) { //<-- If DASD, if tape, it can be 80000000 - setTextUnitCharOrInt(sizeof(short), toi, configsCount, keyArg, textUnit); - } else if (toi <= 0x8000){ - setTextUnitCharOrInt(sizeof(long long), toi, configsCount, keyArg, textUnit); + setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALBLKSZ, textUnit); + } else if (toi <= 0x80000000){ + setTextUnitCharOrInt(sizeof(long long), toi, configsCount, DALBLKSZ, textUnit); + } + } + } else if(!strcmp(propString, "lrecl")) { + long toi = strtol(value->data.string, NULL, 0); + if (errno != ERANGE){ + if (toi == 0x8000) { + setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); + } + else if (toi <= 0x7FF8 && toi >= 0) { + setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); } } } else if(!strcmp(propString, "volser")) { @@ -2299,34 +2313,110 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal } } else if(!strcmp(propString, "recfm")) { int setRECFM = 0; - if (indexOf(valueString, valueStrLen, 'A', 0) != -1){ + if (indexOf(valueString, strlen(valueString), 'A', 0) != -1){ setRECFM = setRECFM | DALRECFM_A; } - if (indexOf(valueString, valueStrLen, 'B', 0) != -1){ + if (indexOf(valueString, strlen(valueString), 'B', 0) != -1){ setRECFM = setRECFM | DALRECFM_B; } - if (indexOf(valueString, valueStrLen, 'V', 0) != -1){ + if (indexOf(valueString, strlen(valueString), 'V', 0) != -1){ setRECFM = setRECFM | DALRECFM_V; } - if (indexOf(valueString, valueStrLen, 'F', 0) != -1){ + if (indexOf(valueString, strlen(valueString), 'F', 0) != -1){ setRECFM = setRECFM | DALRECFM_F; } - if (indexOf(valueString, valueStrLen, 'U', 0) != -1){ + if (indexOf(valueString, strlen(valueString), 'U', 0) != -1){ setRECFM = setRECFM | DALRECFM_U; } setTextUnitCharOrInt(sizeof(char), setRECFM, configsCount, DALRECFM, textUnit); - } else if(!strcmp(propString, "prime") || !strcmp(propString, "second")) { - long toi = strtol(value->data.string, NULL, 0); - if (toi <= 0xFFFFFF || toi >= 0) { - int keyArg = !strcmp(propString, "prime") ? DALPRIME : DALSECND; + } else if(!strcmp(propString, "space")) { + setTextUnitBool(configsCount, !strcmp(valueString, "cyl) ? DALCYL : DALTRK, textUnit); + } else if(!strcmp(propString, "blkln")) { + long toi = strtol(valueString, NULL, 0); + if (toi <= 0xFFFF || toi >= 0) { if (errno != ERANGE){ - setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, keyArg, textUnit); + setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, DALBLKLN, textUnit); } } - } else { - continue; + } else if(!strcmp(propString, "status")) { + if (!strcmp(valueString, "OLD")){ + setTextUnitCharOrInt(sizeof(char), DISP_OLD, configsCount, DALSTATS, textUnit); + } else if (!strcmp(valueString, "MOD")){ + setTextUnitCharOrInt(sizeof(char), DISP_MOD, configsCount, DALSTATS, textUnit); + } else if (!strcmp(valueString, "SHARE")){ + setTextUnitCharOrInt(sizeof(char), DISP_SHARE, configsCount, DALSTATS, textUnit); + } else { + setTextUnitCharOrInt(sizeof(char), DISP_NEW, configsCount, DALSTATS, textUnit); + } + } else if (!strcmp(propString, "ndisp")) { + if (!strcmp(valueString, "UNCATLG")){ + setTextUnitCharOrInt(sizeof(char), DISP_UNCATLG, configsCount, DALNDISP, textUnit); + } else if (!strcmp(valueString, "DELETE")){ + setTextUnitCharOrInt(sizeof(char), DISP_DELETE, configsCount, DALNDISP, textUnit); + } else if (!strcmp(valueString, "KEEP")){ + setTextUnitCharOrInt(sizeof(char), DISP_KEEP, configsCount, DALNDISP, textUnit); + } else { + setTextUnitCharOrInt(sizeof(char), DISP_CATLG, configsCount, DALNDISP, textUnit); + } + } else if(!strcmp(propString, "unit")) { + setTextUnitString(strlen(valueString), &(valueString)[0], configsCount, DALUNIT, textUnit); + } else if(!strcmp(propString, "sysout")) { + if (!strcmp(valueString, "default")){ + for(int i = 0; i < *configsCount; i++) { + if (textUnit[i].key == DALSTATS || textUnit[i].key == DALNDISP) { + textUnit[i].type = TEXT_UNIT_NULL; + } + } + setTextUnitBool(configsCount, DALSYSOU, textUnit); + } else if (isalnum(valueString[0])) { + for(int i = 0; i < *configsCount; i++) { + if (textUnit[i].key == DALSTATS || textUnit[i].key == DALNDISP) { + textUnit[i].type == TEXT_UNIT_NULL; + } + } + setTextUnitCharOrInt(1, valueString[0], configsCount, DALSYSOU, textUnit); + } + } else if(!strcmp(propString, "spgnm")) { + if (strlen(valueString) <= CLASS_WRITER_SIZE){ + setTextUnitString(strlen(valueString), &(valueString)[0], configsCount, DALSPGNM, textUnit); + } + } else if(!strcmp(propString, "close")) { + if (!strcmp(valueString, "true")){ + setTextUnitBool(configsCount, DALCLOSE, textUnit); + } + } else if(!strcmp(propString, "dummy")) { + if (!strcmp(value->data.string, "true")){ + setTextUnitBool(configsCount, DALDUMMY, textUnit); + } + } else if(!strcmp(propString, "dcbdd")) { + if (strlen(valueString) <= DD_NAME_LEN){ + setTextUnitString(DD_NAME_LEN, &(valueString)[0], configsCount, DALDCBDD, textUnit); + } + } else if(!strcmp(propString, "retdd")) { + if (strlen(value->data.string) <= DD_NAME_LEN){ + setTextUnitString(DD_NAME_LEN, &(value->data.string)[0], configsCount, DALRTDDN, textUnit); + } + } else if(!strcmp(propString, "spin")) { + if (!strcmp(value->data.string, "UNALLOC")){ + setTextUnitCharOrInt(1, SPIN_UNALLOC, configsCount, DALSPIN, textUnit); + } else if (!strcmp(value->data.string, "ENDJOB")){ + setTextUnitCharOrInt(1, SPIN_ENDJOB, configsCount, DALSPIN, textUnit); + } + } else if(!strcmp(propString, "strcls")) { + if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ + setTextUnitString(8, &(value->data.string)[0], configsCount, DALSTCL, textUnit); + } + } else if(!strcmp(propString, "mngcls")) { + if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ + setTextUnitString(CLASS_WRITER_SIZE, &(value->data.string)[0], configsCount, DALMGCL, textUnit); + } + } else if(!strcmp(propString, "datacls")) { + if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ + setTextUnitString(CLASS_WRITER_SIZE, &(value->data.string)[0], configsCount, DALDACL, textUnit); + } } } + currentProp = jsonObjectGetNextProperty(currentProp); } /* Json* value = jsonObjectGetPropertyValue(object, "dsorg"); if (jsonIsString(value)){ @@ -2415,7 +2505,7 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal } } */ - value = jsonObjectGetPropertyValue(object, "space"); +/* value = jsonObjectGetPropertyValue(object, "space"); if (jsonIsString(value)){ if (!strcmp(value->data.string, "cyl")){ setTextUnitBool(configsCount, DALCYL, textUnit); @@ -2423,9 +2513,9 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal if (!strcmp(value->data.string, "trk")){ setTextUnitBool(configsCount, DALCYL, textUnit); } - } + } */ - errno = 0; +/* errno = 0; value = jsonObjectGetPropertyValue(object, "blkln"); if (jsonIsString(value)){ long toi = strtol(value->data.string, NULL, 0); @@ -2434,9 +2524,9 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, DALBLKLN, textUnit); } } - } + } */ - value = jsonObjectGetPropertyValue(object, "status"); +/* value = jsonObjectGetPropertyValue(object, "status"); if (jsonIsString(value)){ if (!strcmp(value->data.string, "OLD")){ setTextUnitCharOrInt(sizeof(char), DISP_OLD, configsCount, DALSTATS, textUnit); @@ -2453,9 +2543,9 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal } else { setTextUnitCharOrInt(sizeof(char), DISP_NEW, configsCount, DALSTATS, textUnit); - } + } */ - value = jsonObjectGetPropertyValue(object, "ndisp"); + /* value = jsonObjectGetPropertyValue(object, "ndisp"); if (jsonIsString(value)){ if (!strcmp(value->data.string, "UNCATLG")){ setTextUnitCharOrInt(sizeof(char), DISP_UNCATLG, configsCount, DALNDISP, textUnit); @@ -2472,14 +2562,14 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal } else { setTextUnitCharOrInt(sizeof(char), DISP_CATLG, configsCount, DALNDISP, textUnit); - } + } */ - value = jsonObjectGetPropertyValue(object, "unit"); +/* value = jsonObjectGetPropertyValue(object, "unit"); if (jsonIsString(value)){ setTextUnitString(strlen(value->data.string), &(value->data.string)[0], configsCount, DALUNIT, textUnit); - } + } */ - value = jsonObjectGetPropertyValue(object, "sysout"); + /* value = jsonObjectGetPropertyValue(object, "sysout"); if (jsonIsString(value)){ if (!strcmp(value->data.string, "default")){ for(int i = 0; i < *configsCount; i++) { @@ -2497,44 +2587,44 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal } setTextUnitCharOrInt(1, value->data.string[0], configsCount, DALSYSOU, textUnit); } - } + } */ - value = jsonObjectGetPropertyValue(object, "spgnm"); +/* value = jsonObjectGetPropertyValue(object, "spgnm"); if (jsonIsString(value)){ if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ setTextUnitString(strlen(value->data.string), &(value->data.string)[0], configsCount, DALSPGNM, textUnit); } - } + } */ - value = jsonObjectGetPropertyValue(object, "close"); - if (jsonIsString(value)){ - if (!strcmp(value->data.string, "true")){ - setTextUnitBool(configsCount, DALCLOSE, textUnit); - } - } + // value = jsonObjectGetPropertyValue(object, "close"); + // if (jsonIsString(value)){ + // if (!strcmp(value->data.string, "true")){ + // setTextUnitBool(configsCount, DALCLOSE, textUnit); + // } + // } - value = jsonObjectGetPropertyValue(object, "dummy"); +/* value = jsonObjectGetPropertyValue(object, "dummy"); if (jsonIsString(value)){ if (!strcmp(value->data.string, "true")){ setTextUnitBool(configsCount, DALDUMMY, textUnit); } } - - value = jsonObjectGetPropertyValue(object, "dcbdd"); + */ + /* value = jsonObjectGetPropertyValue(object, "dcbdd"); if (jsonIsString(value)){ if (strlen(value->data.string) <= DD_NAME_LEN){ setTextUnitString(DD_NAME_LEN, &(value->data.string)[0], configsCount, DALDCBDD, textUnit); } - } + } */ - value = jsonObjectGetPropertyValue(object, "retdd"); +/* value = jsonObjectGetPropertyValue(object, "retdd"); if (jsonIsString(value)){ if (strlen(value->data.string) <= DD_NAME_LEN){ setTextUnitString(DD_NAME_LEN, &(value->data.string)[0], configsCount, DALRTDDN, textUnit); } - } + } */ - value = jsonObjectGetPropertyValue(object, "spin"); +/* value = jsonObjectGetPropertyValue(object, "spin"); if (jsonIsString(value)){ if (!strcmp(value->data.string, "UNALLOC")){ setTextUnitCharOrInt(1, SPIN_UNALLOC, configsCount, DALSPIN, textUnit); @@ -2542,28 +2632,28 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal else if (!strcmp(value->data.string, "ENDJOB")){ setTextUnitCharOrInt(1, SPIN_ENDJOB, configsCount, DALSPIN, textUnit); } - } + } */ - value = jsonObjectGetPropertyValue(object, "strcls"); +/* value = jsonObjectGetPropertyValue(object, "strcls"); if (jsonIsString(value)){ if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ setTextUnitString(8, &(value->data.string)[0], configsCount, DALSTCL, textUnit); } - } + } */ - value = jsonObjectGetPropertyValue(object, "mngcls"); +/* value = jsonObjectGetPropertyValue(object, "mngcls"); if (jsonIsString(value)){ if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ setTextUnitString(CLASS_WRITER_SIZE, &(value->data.string)[0], configsCount, DALMGCL, textUnit); } - } + } */ - value = jsonObjectGetPropertyValue(object, "datacls"); +/* value = jsonObjectGetPropertyValue(object, "datacls"); if (jsonIsString(value)){ if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ setTextUnitString(CLASS_WRITER_SIZE, &(value->data.string)[0], configsCount, DALDACL, textUnit); } - } + } */ } static void setTextUnitString(int size, char* data, int *configsCount, int key, DynallocNewTextUnit *textUnit) { From 30224dc56fe9b6d4aec366a696c4a135e4d52c88 Mon Sep 17 00:00:00 2001 From: Tim Gerstel Date: Mon, 27 Sep 2021 00:43:04 -0400 Subject: [PATCH 06/12] Fix syntax error Signed-off-by: Tim Gerstel --- c/datasetjson.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c/datasetjson.c b/c/datasetjson.c index 7378ccb9c..016a88197 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -2330,7 +2330,7 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal } setTextUnitCharOrInt(sizeof(char), setRECFM, configsCount, DALRECFM, textUnit); } else if(!strcmp(propString, "space")) { - setTextUnitBool(configsCount, !strcmp(valueString, "cyl) ? DALCYL : DALTRK, textUnit); + setTextUnitBool(configsCount, !strcmp(valueString, "cyl") ? DALCYL : DALTRK, textUnit); } else if(!strcmp(propString, "blkln")) { long toi = strtol(valueString, NULL, 0); if (toi <= 0xFFFF || toi >= 0) { From b6e426c9e8b1cf0bbedf95ffc2d82dd223cbde54 Mon Sep 17 00:00:00 2001 From: Tim Gerstel Date: Mon, 27 Sep 2021 10:18:21 -0400 Subject: [PATCH 07/12] Remove comments Signed-off-by: Tim Gerstel --- c/datasetjson.c | 263 +++--------------------------------------------- 1 file changed, 14 insertions(+), 249 deletions(-) diff --git a/c/datasetjson.c b/c/datasetjson.c index 016a88197..2d65212cd 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -2280,9 +2280,9 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal printf("currentProperty: %s\n", jsonPropertyGetKey(currentProp)); value = jsonPropertyGetValue(currentProp); char *valueString = jsonAsString(value); - errno = 0; + if(valueString != NULL){ - printf("value for prop is not null\n"); + errno = 0; int valueStrLen = valueStrLen; char *propString = jsonPropertyGetKey(currentProp); @@ -2382,10 +2382,11 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal } } else if(!strcmp(propString, "close")) { if (!strcmp(valueString, "true")){ + printf("SETTING CLOSE TRUE\n"); setTextUnitBool(configsCount, DALCLOSE, textUnit); } } else if(!strcmp(propString, "dummy")) { - if (!strcmp(value->data.string, "true")){ + if (!strcmp(valueString, "true")){ setTextUnitBool(configsCount, DALDUMMY, textUnit); } } else if(!strcmp(propString, "dcbdd")) { @@ -2393,267 +2394,31 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal setTextUnitString(DD_NAME_LEN, &(valueString)[0], configsCount, DALDCBDD, textUnit); } } else if(!strcmp(propString, "retdd")) { - if (strlen(value->data.string) <= DD_NAME_LEN){ - setTextUnitString(DD_NAME_LEN, &(value->data.string)[0], configsCount, DALRTDDN, textUnit); + if (strlen(valueString) <= DD_NAME_LEN){ + setTextUnitString(DD_NAME_LEN, &(valueString)[0], configsCount, DALRTDDN, textUnit); } } else if(!strcmp(propString, "spin")) { - if (!strcmp(value->data.string, "UNALLOC")){ + if (!strcmp(valueString, "UNALLOC")){ setTextUnitCharOrInt(1, SPIN_UNALLOC, configsCount, DALSPIN, textUnit); - } else if (!strcmp(value->data.string, "ENDJOB")){ + } else if (!strcmp(valueString, "ENDJOB")){ setTextUnitCharOrInt(1, SPIN_ENDJOB, configsCount, DALSPIN, textUnit); } } else if(!strcmp(propString, "strcls")) { - if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ - setTextUnitString(8, &(value->data.string)[0], configsCount, DALSTCL, textUnit); + if (strlen(valueString) <= CLASS_WRITER_SIZE){ + setTextUnitString(8, &(valueString)[0], configsCount, DALSTCL, textUnit); } } else if(!strcmp(propString, "mngcls")) { - if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ - setTextUnitString(CLASS_WRITER_SIZE, &(value->data.string)[0], configsCount, DALMGCL, textUnit); + if (strlen(valueString) <= CLASS_WRITER_SIZE){ + setTextUnitString(CLASS_WRITER_SIZE, &(valueString)[0], configsCount, DALMGCL, textUnit); } } else if(!strcmp(propString, "datacls")) { - if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ - setTextUnitString(CLASS_WRITER_SIZE, &(value->data.string)[0], configsCount, DALDACL, textUnit); + if (strlen(valueString) <= CLASS_WRITER_SIZE){ + setTextUnitString(CLASS_WRITER_SIZE, &(valueString)[0], configsCount, DALDACL, textUnit); } } } currentProp = jsonObjectGetNextProperty(currentProp); } -/* Json* value = jsonObjectGetPropertyValue(object, "dsorg"); - if (jsonIsString(value)){ - if (!strcmp(value->data.string, "PS")) { - setTextUnitCharOrInt(sizeof(short), DALDSORG_PS, configsCount, DALDSORG, textUnit); - } - else if (!strcmp(value->data.string, "PO")) { - setTextUnitCharOrInt(sizeof(short), DALDSORG_PO, configsCount, DALDSORG, textUnit); - } - } */ - -/* errno = 0; - value = jsonObjectGetPropertyValue(object, "blksz"); - if (jsonIsString(value)){ - long toi = strtol(value->data.string, NULL, 0); - if(errno != ERANGE){ - if (toi <= 0x7FF8 && toi >= 0) { //<-- If DASD, if tape, it can be 80000000 - setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALBLKSZ, textUnit); - } - else if (toi <= 0x80000000){ - setTextUnitCharOrInt(sizeof(long long), toi, configsCount, DALBLKSZ, textUnit); - } - } - } */ - - // errno = 0; - // value = jsonObjectGetPropertyValue(object, "lrecl"); - // if (jsonIsString(value)){ - // long toi = strtol(value->data.string, NULL, 0); - // if (errno != ERANGE){ - // if (toi == 0x8000) { - // setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); - // } - // else if (toi <= 0x7FF8 && toi >= 0) { - // setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); - // } - // } - // } -/* value = jsonObjectGetPropertyValue(object, "volser"); - if (jsonIsString(value)){ - if (strlen(value->data.string) <= VOLSER_SIZE){ - setTextUnitString(VOLSER_SIZE, &(value->data.string)[0], configsCount, DALVLSER, textUnit); - } - } */ - -/* value = jsonObjectGetPropertyValue(object, "recfm"); - if (jsonIsString(value)){ - int setRECFM = 0; - if (indexOf(value->data.string, strlen(value->data.string), 'A', 0) != -1){ - setRECFM = setRECFM | DALRECFM_A; - } - if (indexOf(value->data.string, strlen(value->data.string), 'B', 0) != -1){ - setRECFM = setRECFM | DALRECFM_B; - } - if (indexOf(value->data.string, strlen(value->data.string), 'V', 0) != -1){ - setRECFM = setRECFM | DALRECFM_V; - } - if (indexOf(value->data.string, strlen(value->data.string), 'F', 0) != -1){ - setRECFM = setRECFM | DALRECFM_F; - } - if (indexOf(value->data.string, strlen(value->data.string), 'U', 0) != -1){ - setRECFM = setRECFM | DALRECFM_U; - } - setTextUnitCharOrInt(sizeof(char), setRECFM, configsCount, DALRECFM, textUnit); - } */ - -/* errno = 0; - value = jsonObjectGetPropertyValue(object, "prime"); - if (jsonIsString(value)){ - long toi = strtol(value->data.string, NULL, 0); - if (toi <= 0xFFFFFF || toi >= 0) { - if (errno != ERANGE){ - setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, DALPRIME, textUnit); - } - } - } - - errno = 0; - value = jsonObjectGetPropertyValue(object, "second"); - if (jsonIsString(value)){ - long toi = strtol(value->data.string, NULL, 0); - if (toi <= 0xFFFFFF || toi >= 0) { - if (errno != ERANGE){ - setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, DALSECND, textUnit); - } - } - } */ - -/* value = jsonObjectGetPropertyValue(object, "space"); - if (jsonIsString(value)){ - if (!strcmp(value->data.string, "cyl")){ - setTextUnitBool(configsCount, DALCYL, textUnit); - } - if (!strcmp(value->data.string, "trk")){ - setTextUnitBool(configsCount, DALCYL, textUnit); - } - } */ - -/* errno = 0; - value = jsonObjectGetPropertyValue(object, "blkln"); - if (jsonIsString(value)){ - long toi = strtol(value->data.string, NULL, 0); - if (toi <= 0xFFFF || toi >= 0) { - if (errno != ERANGE){ - setTextUnitCharOrInt(INT24_SIZE, toi, configsCount, DALBLKLN, textUnit); - } - } - } */ - -/* value = jsonObjectGetPropertyValue(object, "status"); - if (jsonIsString(value)){ - if (!strcmp(value->data.string, "OLD")){ - setTextUnitCharOrInt(sizeof(char), DISP_OLD, configsCount, DALSTATS, textUnit); - } - else if (!strcmp(value->data.string, "MOD")){ - setTextUnitCharOrInt(sizeof(char), DISP_MOD, configsCount, DALSTATS, textUnit); - } - else if (!strcmp(value->data.string, "SHARE")){ - setTextUnitCharOrInt(sizeof(char), DISP_SHARE, configsCount, DALSTATS, textUnit); - } - else { - setTextUnitCharOrInt(sizeof(char), DISP_NEW, configsCount, DALSTATS, textUnit); - } - } - else { - setTextUnitCharOrInt(sizeof(char), DISP_NEW, configsCount, DALSTATS, textUnit); - } */ - - /* value = jsonObjectGetPropertyValue(object, "ndisp"); - if (jsonIsString(value)){ - if (!strcmp(value->data.string, "UNCATLG")){ - setTextUnitCharOrInt(sizeof(char), DISP_UNCATLG, configsCount, DALNDISP, textUnit); - } - else if (!strcmp(value->data.string, "DELETE")){ - setTextUnitCharOrInt(sizeof(char), DISP_DELETE, configsCount, DALNDISP, textUnit); - } - else if (!strcmp(value->data.string, "KEEP")){ - setTextUnitCharOrInt(sizeof(char), DISP_KEEP, configsCount, DALNDISP, textUnit); - } - else { - setTextUnitCharOrInt(sizeof(char), DISP_CATLG, configsCount, DALNDISP, textUnit); - } - } - else { - setTextUnitCharOrInt(sizeof(char), DISP_CATLG, configsCount, DALNDISP, textUnit); - } */ - -/* value = jsonObjectGetPropertyValue(object, "unit"); - if (jsonIsString(value)){ - setTextUnitString(strlen(value->data.string), &(value->data.string)[0], configsCount, DALUNIT, textUnit); - } */ - - /* value = jsonObjectGetPropertyValue(object, "sysout"); - if (jsonIsString(value)){ - if (!strcmp(value->data.string, "default")){ - for(int i = 0; i < *configsCount; i++) { - if (textUnit[i].key == DALSTATS || textUnit[i].key == DALNDISP) { - textUnit[i].type = TEXT_UNIT_NULL; - } - } - setTextUnitBool(configsCount, DALSYSOU, textUnit); - } - else if (isalnum(value->data.string[0])) { - for(int i = 0; i < *configsCount; i++) { - if (textUnit[i].key == DALSTATS || textUnit[i].key == DALNDISP) { - textUnit[i].type == TEXT_UNIT_NULL; - } - } - setTextUnitCharOrInt(1, value->data.string[0], configsCount, DALSYSOU, textUnit); - } - } */ - -/* value = jsonObjectGetPropertyValue(object, "spgnm"); - if (jsonIsString(value)){ - if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ - setTextUnitString(strlen(value->data.string), &(value->data.string)[0], configsCount, DALSPGNM, textUnit); - } - } */ - - // value = jsonObjectGetPropertyValue(object, "close"); - // if (jsonIsString(value)){ - // if (!strcmp(value->data.string, "true")){ - // setTextUnitBool(configsCount, DALCLOSE, textUnit); - // } - // } - -/* value = jsonObjectGetPropertyValue(object, "dummy"); - if (jsonIsString(value)){ - if (!strcmp(value->data.string, "true")){ - setTextUnitBool(configsCount, DALDUMMY, textUnit); - } - } - */ - /* value = jsonObjectGetPropertyValue(object, "dcbdd"); - if (jsonIsString(value)){ - if (strlen(value->data.string) <= DD_NAME_LEN){ - setTextUnitString(DD_NAME_LEN, &(value->data.string)[0], configsCount, DALDCBDD, textUnit); - } - } */ - -/* value = jsonObjectGetPropertyValue(object, "retdd"); - if (jsonIsString(value)){ - if (strlen(value->data.string) <= DD_NAME_LEN){ - setTextUnitString(DD_NAME_LEN, &(value->data.string)[0], configsCount, DALRTDDN, textUnit); - } - } */ - -/* value = jsonObjectGetPropertyValue(object, "spin"); - if (jsonIsString(value)){ - if (!strcmp(value->data.string, "UNALLOC")){ - setTextUnitCharOrInt(1, SPIN_UNALLOC, configsCount, DALSPIN, textUnit); - } - else if (!strcmp(value->data.string, "ENDJOB")){ - setTextUnitCharOrInt(1, SPIN_ENDJOB, configsCount, DALSPIN, textUnit); - } - } */ - -/* value = jsonObjectGetPropertyValue(object, "strcls"); - if (jsonIsString(value)){ - if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ - setTextUnitString(8, &(value->data.string)[0], configsCount, DALSTCL, textUnit); - } - } */ - -/* value = jsonObjectGetPropertyValue(object, "mngcls"); - if (jsonIsString(value)){ - if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ - setTextUnitString(CLASS_WRITER_SIZE, &(value->data.string)[0], configsCount, DALMGCL, textUnit); - } - } */ - -/* value = jsonObjectGetPropertyValue(object, "datacls"); - if (jsonIsString(value)){ - if (strlen(value->data.string) <= CLASS_WRITER_SIZE){ - setTextUnitString(CLASS_WRITER_SIZE, &(value->data.string)[0], configsCount, DALDACL, textUnit); - } - } */ } static void setTextUnitString(int size, char* data, int *configsCount, int key, DynallocNewTextUnit *textUnit) { From b56c4246fbb0cf4c6234c3d89884e2ad7774cea2 Mon Sep 17 00:00:00 2001 From: Tim Gerstel Date: Mon, 27 Sep 2021 10:19:10 -0400 Subject: [PATCH 08/12] Remove printf Signed-off-by: Tim Gerstel --- c/datasetjson.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/c/datasetjson.c b/c/datasetjson.c index 2d65212cd..6abe7c4b0 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -2275,9 +2275,7 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal JsonProperty *currentProp = jsonObjectGetFirstProperty(object); //printf("Updating input parms"); Json *value; - printf("updateInptuParmsProperty called\n"); while(currentProp != NULL){ - printf("currentProperty: %s\n", jsonPropertyGetKey(currentProp)); value = jsonPropertyGetValue(currentProp); char *valueString = jsonAsString(value); @@ -2382,7 +2380,6 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal } } else if(!strcmp(propString, "close")) { if (!strcmp(valueString, "true")){ - printf("SETTING CLOSE TRUE\n"); setTextUnitBool(configsCount, DALCLOSE, textUnit); } } else if(!strcmp(propString, "dummy")) { From c566cd5d2bdb001e8f6bc79fffe7e65d3df477e6 Mon Sep 17 00:00:00 2001 From: Tim Gerstel Date: Mon, 27 Sep 2021 11:18:08 -0400 Subject: [PATCH 09/12] More refactoring Signed-off-by: Tim Gerstel --- c/datasetjson.c | 71 +++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 52 deletions(-) diff --git a/c/datasetjson.c b/c/datasetjson.c index 6abe7c4b0..7f571cf7b 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -353,27 +353,6 @@ static int isPartionedDataset(char *dscb) { } #endif -static bool isVSAM(char* dsPath) { - char dscb[INDEXED_DSCB] = {0}; - Volser volser = {0}; - DatasetName dsn = {0}; - memcpy(dsn.value,dsPath+3,strlen(dsPath)-4); - padWithSpaces(dsn.value, sizeof(dsn.value), 0, 0); - - int volserSuccess = getVolserForDataset(&dsn, &volser); - if(!volserSuccess){ - obtainDSCB1(dsn.value, sizeof(dsn.value), - volser.value, sizeof(volser.value), - dscb); - int posOffset = 44; - int dsorgLow = dscb[83-posOffset]; - if (dsorgLow & 0x08){ - return TRUE; - } - } - return FALSE; -} - static int obtainDSCB1(const char *dsname, unsigned int dsnameLength, const char *volser, unsigned int volserLength, char *dscb1) { @@ -2281,7 +2260,7 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal if(valueString != NULL){ errno = 0; - int valueStrLen = valueStrLen; + int valueStrLen = strlen(valueString); char *propString = jsonPropertyGetKey(currentProp); if (!strcmp(propString, "dsorg")) { @@ -2296,7 +2275,7 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal } } } else if(!strcmp(propString, "lrecl")) { - long toi = strtol(value->data.string, NULL, 0); + long toi = strtol(valueString, NULL, 0); if (errno != ERANGE){ if (toi == 0x8000) { setTextUnitCharOrInt(sizeof(short), toi, configsCount, DALLRECL, textUnit); @@ -2311,19 +2290,19 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal } } else if(!strcmp(propString, "recfm")) { int setRECFM = 0; - if (indexOf(valueString, strlen(valueString), 'A', 0) != -1){ + if (indexOf(valueString, valueStrLen, 'A', 0) != -1){ setRECFM = setRECFM | DALRECFM_A; } - if (indexOf(valueString, strlen(valueString), 'B', 0) != -1){ + if (indexOf(valueString, valueStrLen, 'B', 0) != -1){ setRECFM = setRECFM | DALRECFM_B; } - if (indexOf(valueString, strlen(valueString), 'V', 0) != -1){ + if (indexOf(valueString, valueStrLen, 'V', 0) != -1){ setRECFM = setRECFM | DALRECFM_V; } - if (indexOf(valueString, strlen(valueString), 'F', 0) != -1){ + if (indexOf(valueString, valueStrLen, 'F', 0) != -1){ setRECFM = setRECFM | DALRECFM_F; } - if (indexOf(valueString, strlen(valueString), 'U', 0) != -1){ + if (indexOf(valueString, valueStrLen, 'U', 0) != -1){ setRECFM = setRECFM | DALRECFM_U; } setTextUnitCharOrInt(sizeof(char), setRECFM, configsCount, DALRECFM, textUnit); @@ -2357,7 +2336,7 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal setTextUnitCharOrInt(sizeof(char), DISP_CATLG, configsCount, DALNDISP, textUnit); } } else if(!strcmp(propString, "unit")) { - setTextUnitString(strlen(valueString), &(valueString)[0], configsCount, DALUNIT, textUnit); + setTextUnitString(valueStrLen, &(valueString)[0], configsCount, DALUNIT, textUnit); } else if(!strcmp(propString, "sysout")) { if (!strcmp(valueString, "default")){ for(int i = 0; i < *configsCount; i++) { @@ -2375,24 +2354,16 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal setTextUnitCharOrInt(1, valueString[0], configsCount, DALSYSOU, textUnit); } } else if(!strcmp(propString, "spgnm")) { - if (strlen(valueString) <= CLASS_WRITER_SIZE){ - setTextUnitString(strlen(valueString), &(valueString)[0], configsCount, DALSPGNM, textUnit); + if (valueStrLen <= CLASS_WRITER_SIZE){ + setTextUnitString(valueStrLen, &(valueString)[0], configsCount, DALSPGNM, textUnit); } - } else if(!strcmp(propString, "close")) { + } else if(!strcmp(propString, "close") || !strcmp(propString, "dummy")) { if (!strcmp(valueString, "true")){ - setTextUnitBool(configsCount, DALCLOSE, textUnit); + setTextUnitBool(configsCount, !strcmp(propString, "close") ? DALCLOSE : DALDUMMY, textUnit); } - } else if(!strcmp(propString, "dummy")) { - if (!strcmp(valueString, "true")){ - setTextUnitBool(configsCount, DALDUMMY, textUnit); - } - } else if(!strcmp(propString, "dcbdd")) { - if (strlen(valueString) <= DD_NAME_LEN){ - setTextUnitString(DD_NAME_LEN, &(valueString)[0], configsCount, DALDCBDD, textUnit); - } - } else if(!strcmp(propString, "retdd")) { - if (strlen(valueString) <= DD_NAME_LEN){ - setTextUnitString(DD_NAME_LEN, &(valueString)[0], configsCount, DALRTDDN, textUnit); + } else if(!strcmp(propString, "dcbdd") || !strcmp(propString, "retdd")) { + if (valueStrLen <= DD_NAME_LEN){ + setTextUnitString(DD_NAME_LEN, &(valueString)[0], configsCount, !strcmp(propString, "dcbdd") ? DALDCBDD : DALRTDDN, textUnit); } } else if(!strcmp(propString, "spin")) { if (!strcmp(valueString, "UNALLOC")){ @@ -2401,16 +2372,12 @@ static int updateInputParmsProperty(JsonObject *object, int *configsCount, Dynal setTextUnitCharOrInt(1, SPIN_ENDJOB, configsCount, DALSPIN, textUnit); } } else if(!strcmp(propString, "strcls")) { - if (strlen(valueString) <= CLASS_WRITER_SIZE){ + if (valueStrLen <= CLASS_WRITER_SIZE){ setTextUnitString(8, &(valueString)[0], configsCount, DALSTCL, textUnit); } - } else if(!strcmp(propString, "mngcls")) { - if (strlen(valueString) <= CLASS_WRITER_SIZE){ - setTextUnitString(CLASS_WRITER_SIZE, &(valueString)[0], configsCount, DALMGCL, textUnit); - } - } else if(!strcmp(propString, "datacls")) { - if (strlen(valueString) <= CLASS_WRITER_SIZE){ - setTextUnitString(CLASS_WRITER_SIZE, &(valueString)[0], configsCount, DALDACL, textUnit); + } else if(!strcmp(propString, "mngcls") || !strcmp(propString, "datacls")) { + if (valueStrLen <= CLASS_WRITER_SIZE){ + setTextUnitString(CLASS_WRITER_SIZE, &(valueString)[0], configsCount, !strcmp(propString, "mngcls") ? DALMGCL : DALDACL, textUnit); } } } From 807e2c131658af3f2dc920d4ddc1938372fdc2a1 Mon Sep 17 00:00:00 2001 From: Tim Gerstel Date: Mon, 11 Oct 2021 18:31:11 -0400 Subject: [PATCH 10/12] Change function parameters to reuse inputs. Remove strtok. change safeFree to safeFree31 Signed-off-by: Tim Gerstel --- c/datasetjson.c | 63 +++++++++++++++++++++---------------------------- c/dynalloc.c | 4 ++-- 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/c/datasetjson.c b/c/datasetjson.c index 4423abe5f..4828cc728 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -47,6 +47,22 @@ #define INDEXED_DSCB 96 +typedef struct DatasetName_tag { + char value[44]; /* space-padded */ +} DatasetName; + +typedef struct DatasetMemberName_tag { + char value[8]; /* space-padded */ +} DatasetMemberName; + +typedef struct DDName_tag { + char value[8]; /* space-padded */ +} DDName; + +typedef struct Volser_tag { + char value[6]; /* space-padded */ +} Volser; + static char defaultDatasetTypesAllowed[3] = {'A','D','X'}; static char clusterTypesAllowed[3] = {'C','D','I'}; /* TODO: support 'I' type DSNs */ static int clusterTypesCount = 3; @@ -59,28 +75,12 @@ static char vsamCSITypes[5] = {'R', 'D', 'G', 'I', 'C'}; static char getRecordLengthType(char *dscb); static int getMaxRecordLength(char *dscb); -static int getDSCB(char* datasetName, char* dscb, int bufferSize); +static int getDSCB(DatasetName *dsName, char* dscb, int bufferSize); static int updateInputParmsProperty(JsonObject *object, int *configsCount, DynallocNewTextUnit *textUnit); static void setTextUnitString(int size, char* data, int *configsCount, int key, DynallocNewTextUnit *textUnit); static void setTextUnitCharOrInt(int size, int data, int *configsCount, int key, DynallocNewTextUnit *textUnit); static void setTextUnitBool(int *configsCount, int key, DynallocNewTextUnit *textUnit); -typedef struct DatasetName_tag { - char value[44]; /* space-padded */ -} DatasetName; - -typedef struct DatasetMemberName_tag { - char value[8]; /* space-padded */ -} DatasetMemberName; - -typedef struct DDName_tag { - char value[8]; /* space-padded */ -} DDName; - -typedef struct Volser_tag { - char value[6]; /* space-padded */ -} Volser; - static int getVolserForDataset(const DatasetName *dataset, Volser *volser); static bool memberExists(char* dsName, DynallocMemberName daMemberName); @@ -2415,7 +2415,7 @@ static void setTextUnitBool(int *configsCount, int key, DynallocNewTextUnit *tex (*configsCount)++; } -static int getDSCB(char* datasetName, char* dscb, int bufferSize){ +static int getDSCB(const DatasetName* datasetName, char* dscb, int bufferSize){ if (bufferSize < INDEXED_DSCB){ zowelog(NULL, LOG_COMP_RESTDATASET, ZOWE_LOG_WARNING, "DSCB of size %d is too small, must be at least %d", bufferSize, INDEXED_DSCB); @@ -2423,17 +2423,14 @@ static int getDSCB(char* datasetName, char* dscb, int bufferSize){ } Volser volser = {0}; - DatasetName dsn = {0}; - memcpy(dsn.value, datasetName, DATASET_PATH_MAX); - - int volserSuccess = getVolserForDataset(&dsn, &volser); + int volserSuccess = getVolserForDataset(datasetName, &volser); if(!volserSuccess){ - int rc = obtainDSCB1(dsn.value, sizeof(dsn.value), + int rc = obtainDSCB1(datasetName->value, sizeof(datasetName->value), volser.value, sizeof(volser.value), dscb); if (rc == 0){ if (DSCB_TRACE){ - zowelog(NULL, LOG_COMP_RESTDATASET, ZOWE_LOG_WARNING, "DSCB for %.*s found\n", sizeof(dsn.value), dsn.value); + zowelog(NULL, LOG_COMP_RESTDATASET, ZOWE_LOG_WARNING, "DSCB for %.*s found\n", sizeof(&datasetName->value), datasetName->value); dumpbuffer(dscb,INDEXED_DSCB); } } @@ -2444,10 +2441,10 @@ static int getDSCB(char* datasetName, char* dscb, int bufferSize){ } } -void newDatasetMember(HttpResponse* response, char* datasetPath, char* memberName) { +void newDatasetMember(HttpResponse* response, DatasetName* datasetName, char* absolutePath) { char dscb[INDEXED_DSCB] = {0}; int bufferSize = sizeof(dscb); - if (getDSCB(datasetPath, dscb, bufferSize) != 0) { + if (getDSCB(datasetName, dscb, bufferSize) != 0) { respondWithJsonError(response, "Error decoding dataset", 400, "Bad Request"); } else { @@ -2457,12 +2454,7 @@ void newDatasetMember(HttpResponse* response, char* datasetPath, char* memberNam 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 + 1, "//'%s(%s)'", dsName, memName); - FILE* memberExists = fopen(fullPath,"r"); + FILE* memberExists = fopen(absolutePath,"r"); if (memberExists && overwrite != TRUE) {//Member already exists and overwrite wasn't specified if (fclose(memberExists) != 0) { zowelog(NULL, LOG_COMP_RESTDATASET, ZOWE_LOG_WARNING, "ERROR CLOSING FILE"); @@ -2480,8 +2472,9 @@ void newDatasetMember(HttpResponse* response, char* datasetPath, char* memberNam return; } } - FILE* newMember = fopen(fullPath, "w"); + FILE* newMember = fopen(absolutePath, "w"); if (!newMember){ + printf("full path: %s\n", absolutePath); respondWithJsonError(response, "Bad dataset name", 400, "Bad Request"); return; } @@ -2519,7 +2512,7 @@ void newDataset(HttpResponse* response, char* absolutePath, int jsonMode){ bool isMemberEmpty = IS_DAMEMBER_EMPTY(daMemberName); if(!isMemberEmpty){ - return newDatasetMember(response, daDatasetName.name, daMemberName.name); + return newDatasetMember(response, &datasetName, absolutePath); } int configsCount = 0; @@ -2532,8 +2525,6 @@ void newDataset(HttpResponse* response, char* absolutePath, int jsonMode){ return; } - FileInfo info; - char *contentBody = request->contentBody; int bodyLength = strlen(contentBody); diff --git a/c/dynalloc.c b/c/dynalloc.c index 517884b5f..6f152169a 100644 --- a/c/dynalloc.c +++ b/c/dynalloc.c @@ -863,7 +863,7 @@ int dynallocNewDataset(int *reasonCode, DynallocNewTextUnit *setTextUnits, int T ) ); - below2G->textUnits = (TextUnit **)safeMalloc(sizeof(TextUnit*) * TextUnitsSize, "Text units array"); + below2G->textUnits = (TextUnit **)safeMalloc31(sizeof(TextUnit*) * TextUnitsSize, "Text units array"); DynallocParms *parms = &below2G->parms; dynallocParmsInit(parms); @@ -904,7 +904,7 @@ int dynallocNewDataset(int *reasonCode, DynallocNewTextUnit *setTextUnits, int T (dynallocParmsGetErrorCode(parms) << 16); } while (0); freeTextUnitArray(below2G->textUnits, TextUnitsSize); - safeFree((char*)below2G->textUnits, sizeof(TextUnit*) * TextUnitsSize); + safeFree31((char*)below2G->textUnits, sizeof(TextUnit*) * TextUnitsSize); dynallocParmsTerm(parms); parms = NULL; FREE_STRUCT31( From 9b31fcd717f6a5cca25713b6ad5f6e2c354ae985 Mon Sep 17 00:00:00 2001 From: Leonty Chudinov Date: Tue, 26 Oct 2021 16:02:44 +0500 Subject: [PATCH 11/12] Replace unprintable chars Signed-off-by: Leonty Chudinov --- h/dynalloc.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/h/dynalloc.h b/h/dynalloc.h index 473c62d44..e622efb8d 100644 --- a/h/dynalloc.h +++ b/h/dynalloc.h @@ -315,7 +315,7 @@ int DeallocDDName(char *ddname); #define DOBURST 0x0001 /* BURST FieldCount: 1 FieldLength 1 - X02 for YES X04 for NO + XDc12dc2for YES Xdc104dc2 for NO Directs output to a stacker on a 3800 Printing Subsystem. */ #define DOCHARS 0x0002 @@ -360,7 +360,7 @@ int DeallocDDName(char *ddname); #define DOCONTRO 0x0008 /* CONTROL FieldCount: 1 FieldLength 1 - X80 for SINGLE X40 for DOUBLE X20 for TRIPLE X10 for PROGRAM + XDC180' for SINGLE X'40' for DOUBLE X'20' for TRIPLE X'10' for PROGRAM Specifies that all the data records begin with carriage control characters or specifies line spacing. */ #define DOCOPIE9 0x0009 @@ -375,12 +375,12 @@ int DeallocDDName(char *ddname); #define DODATACK 0x2022 /* DATACK FieldCount: 1 FieldLength 1 - X00 for BLOCK X80 for UNBLOCK X81 for BLKCHAR X82 for BLKPOS + X'00' for BLOCK X'80' for UNBLOCK X'81' for BLKCHAR X'82' for BLKPOS Specifies how errors in printers accessed through the functional subsystem Print Services Facility (PSF) are to be reported. */ #define DODEFAUL 0x000B /* DEFAULT FieldCount: 1 FieldLength 1 - X40 for YES X80 for NO + X'40' for YES X'80' for NO Specifies that this is a default output descriptor. */ #define DODEPT 0x0029 @@ -395,12 +395,12 @@ int DeallocDDName(char *ddname); #define DODPAGEL 0x0023 /* DPAGELBL FieldCount: 1 FieldLength 1 - X40 for YES X80 for NO + X'40' for YES X'80' for NO Indicates whether the system should place a security label on each output page. YES means the system should place a label on each page. NO means the system should not place a label on each page. */ #define DODUPLEX 0x003D /* DUPLEX FieldCount: 1 FieldLength 1 - X80 for NO X40 for NORMAL X20 for TUMBLE + X'80' for NO X'40' for NORMAL X'20' for TUMBLE Specifies whether the job is to be printed on one or both sides of the paper. Overrides comparable FORMDEF specification. */ #define DOFCB 0x000D @@ -565,7 +565,7 @@ int DeallocDDName(char *ddname); #define DOPIMSG 0x0021 /* PIMSG FieldCount: 2 FieldLength 1 - X80 for NO X40 for YES The second value field is a two-byte number from 0 through 999 decimal, having a length field of 2. + X'80' for NO X'40' for YES The second value field is a two-byte number from 0 through 999 decimal, having a length field of 2. Indicates that messages from a functional subsystem should or should not be printed in the listing following the SYSOUT data set. Printing terminates if the number of printing errors exceeds the second value field. */ #define DOPORTNO 0x0045 @@ -581,7 +581,7 @@ int DeallocDDName(char *ddname); #define DOPRTATT 0x0050 /* PRTATTRS FieldCount: 1 FieldLength 1-127 EBCDIC text characters - Specifies an Infoprint Server job attribute. The z/OS Infoprint Server Users Guide documents job attribute names and syntax for acceptable values. */ + Specifies an Infoprint Server job attribute. The z/OS Infoprint Server User's Guide documents job attribute names and syntax for acceptable values. */ #define DOPROPTN 0x0039 /* PRTOPTNS FieldCount: 1 FieldLength 1-16 @@ -640,7 +640,7 @@ int DeallocDDName(char *ddname); #define DOSYSARE 0x0024 /* SYSAREA FieldCount: 1 FieldLength 1 - X40 for YES X80 for NO + X'40' for YES X'80' for NO Indicates whether you want to use the system printable area of each output page. YES means you want to use the area. NO means you do not want to use the area. */ #define DOTHRESH 0x0022 @@ -655,8 +655,8 @@ int DeallocDDName(char *ddname); #define DOTRC 0x001A /* TRC FieldCount: 1 FieldLength 1 - X80 for NO X40 for YES - Specifies whether or not the SYSOUT data sets records contain table reference codes (TRC) as the second character. */ + X'80' for NO X'40' for YES + Specifies whether or not the SYSOUT data set's records contain table reference codes (TRC) as the second character. */ #define DOUCS 0x001B /* UCS FieldCount: 1 FieldLength 1-4 @@ -674,7 +674,7 @@ int DeallocDDName(char *ddname); Specifies the names of libraries containing AFP resources. */ #define DOUSERPAT 0x004F -/* USERPATH FieldCount: 8 FieldLength 1255 +/* USERPATH FieldCount: 8 FieldLength 1-255 SPECIAL text. See z/OS MVS JCL Reference. Specifies up to eight HFS or ZFS system paths containing resources to be used by PSF when processing SYSOUT data sets. */ From c1c74c3079e7f06049f2e2bfaae5d7f1974c4df4 Mon Sep 17 00:00:00 2001 From: Leonty Chudinov Date: Tue, 26 Oct 2021 16:04:10 +0500 Subject: [PATCH 12/12] Add a call to dynallocUnallocDatasetByDDName Signed-off-by: Leonty Chudinov --- c/datasetjson.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/c/datasetjson.c b/c/datasetjson.c index 217996fce..281840fbc 100644 --- a/c/datasetjson.c +++ b/c/datasetjson.c @@ -79,16 +79,6 @@ typedef struct Volser_tag { char value[6]; /* space-padded */ } Volser; -static char defaultDatasetTypesAllowed[3] = {'A','D','X'}; -static char clusterTypesAllowed[3] = {'C','D','I'}; /* TODO: support 'I' type DSNs */ -static int clusterTypesCount = 3; -static char *datasetStart = "//'"; -static char *defaultCSIFields[] ={ "NAME ", "TYPE ", "VOLSER "}; -static int defaultCSIFieldCount = 3; -static char *defaultVSAMCSIFields[] ={"AMDCIREC", "AMDKEY ", "ASSOC ", "VSAMTYPE"}; -static int defaultVSAMCSIFieldCount = 4; -static char vsamCSITypes[5] = {'R', 'D', 'G', 'I', 'C'}; - static char getRecordLengthType(char *dscb); static int getMaxRecordLength(char *dscb); static int getDSCB(DatasetName *dsName, char* dscb, int bufferSize); @@ -2793,9 +2783,10 @@ void newDataset(HttpResponse* response, char* absolutePath, int jsonMode){ } int configsCount = 0; + char ddNameBuffer[DD_NAME_LEN+1] = "MVD00000"; DynallocNewTextUnit textUnits[TOTAL_TEXT_UNITS]; setTextUnitString(DATASET_NAME_LEN, &datasetName.value[0], &configsCount, DALDSNAM, &textUnits[0]); - setTextUnitString(DD_NAME_LEN, "MVD00000", &configsCount, DALDDNAM, &textUnits[0]); + setTextUnitString(DD_NAME_LEN, ddNameBuffer, &configsCount, DALDDNAM, &textUnits[0]); if (jsonMode != TRUE) { /*TODO add support for updating files with raw bytes instead of JSON*/ respondWithError(response, HTTP_STATUS_BAD_REQUEST,"Cannot update file without JSON formatted record request"); @@ -2841,22 +2832,30 @@ void newDataset(HttpResponse* response, char* absolutePath, int jsonMode){ returnCode = dynallocNewDataset(&reasonCode, &textUnits[0], configsCount); int ddNumber = 1; - char buffer[DD_NAME_LEN + 1]; while (reasonCode==0x4100000 && ddNumber < 100000) { - sprintf(buffer, "MVD%05d", ddNumber); + sprintf(ddNameBuffer, "MVD%05d", ddNumber); int ddconfig = 1; - setTextUnitString(DD_NAME_LEN, buffer, &ddconfig, DALDDNAM, &textUnits[0]); + setTextUnitString(DD_NAME_LEN, ddNameBuffer, &ddconfig, DALDDNAM, &textUnits[0]); returnCode = dynallocNewDataset(&reasonCode, &textUnits[0], configsCount); ddNumber++; } if (returnCode) { + zowelog(NULL, LOG_COMP_DATASERVICE, ZOWE_LOG_DEBUG, + "error: ds alloc dsn=\'%44.44s\' dd=\'%8.8s\', sysRC=%d, sysRSN=0x%08X\n", + daDatasetName.name, ddNameBuffer, returnCode, reasonCode); respondWithError(response, HTTP_STATUS_INTERNAL_SERVER_ERROR, "Unable to allocate a DD for ACB"); return; } - else { - response200WithMessage(response, "Successfully created dataset"); + memcpy(daDDName.name, ddNameBuffer, DD_NAME_LEN); + daRC = dynallocUnallocDatasetByDDName(&daDDName, DYNALLOC_UNALLOC_FLAG_NONE, &returnCode, &reasonCode); + if (daRC != RC_DYNALLOC_OK) { + zowelog(NULL, LOG_COMP_DATASERVICE, ZOWE_LOG_DEBUG, + "error: ds unalloc dsn=\'%44.44s\' dd=\'%8.8s\', rc=%d sysRC=%d, sysRSN=0x%08X\n", + daDatasetName.name, daDDName.name, daRC, returnCode, reasonCode); + respondWithError(response, HTTP_STATUS_INTERNAL_SERVER_ERROR, "Unable to deallocate DDNAME"); return; } + response200WithMessage(response, "Successfully created dataset"); #endif }