Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created functionality for creating dataset members #68

Open
wants to merge 1 commit into
base: feature/staging-int
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions c/datasetjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A dataset name is not necessarily DATASET_NAME_LEN bytes. This may 0C4. And for DSCB it probably needs to be space padded.


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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not follow the same convention as the rest of the function, i.e. require a full path? Please also do all the validation and checks (whether the dataset is on an offline volume), that's done in https://github.com/zowe/zowe-common-c/blob/staging/c/datasetjson.c#L832

char dscb[INDEXED_DSCB] = {0};
int bufferSize = sizeof(dscb);
if (getDSCB(datasetPath, dscb, bufferSize) != 0) {
respondWithJsonError(response, "Error decoding dataset", 400, "Bad Request");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you return from here early and not have a huge else?

}
else {
if (!isPartionedDataset(dscb)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Just check and return in case of an error.

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 */

Expand Down
4 changes: 4 additions & 0 deletions h/datasetjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions h/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down