Skip to content

Commit d9d5f84

Browse files
author
Charlie Caron
committed
Created functionality for creating dataset members
Signed-off-by: Charlie Caron <[email protected]>
1 parent e85b841 commit d9d5f84

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

c/datasetjson.c

+106
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static int defaultVSAMCSIFieldCount = 4;
5353

5454
static char getRecordLengthType(char *dscb);
5555
static int getMaxRecordLength(char *dscb);
56+
static int getDSCB(char* datasetName, char* dscb, int bufferSize);
5657
static void respondWithNonVSAMDataset(HttpResponse* response, char* absolutePath, int jsonMode);
5758
static void respondWithVSAMDataset(HttpResponse* response, char* absolutePath, hashtable *acbTable, int jsonMode);
5859
static void updateNonVSAMDataset(HttpResponse* response, char* absolutePath, int jsonMode);
@@ -1719,6 +1720,111 @@ void respondWithHLQNames(HttpResponse *response, MetadataQueryCache *metadataQue
17191720
#endif /* __ZOWE_OS_ZOS */
17201721
}
17211722

1723+
static int getDSCB(char* datasetName, char* dscb, int bufferSize){
1724+
if (bufferSize < INDEXED_DSCB){
1725+
zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING,
1726+
"DSCB of size %d is too small, must be at least %d", bufferSize, INDEXED_DSCB);
1727+
return 1;
1728+
}
1729+
Volser volser = {0};
1730+
1731+
DatasetName dsn = {0};
1732+
memcpy(dsn.value, datasetName, DATASET_NAME_LEN);
1733+
1734+
int volserSuccess = getVolserForDataset(&dsn, &volser);
1735+
if(!volserSuccess){
1736+
int rc = obtainDSCB1(dsn.value, sizeof(dsn.value),
1737+
volser.value, sizeof(volser.value),
1738+
dscb);
1739+
if (rc == 0){
1740+
if (DSCB_TRACE){
1741+
zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING, "DSCB for %.*s found\n", sizeof(dsn.value), dsn.value);
1742+
dumpbuffer(dscb,INDEXED_DSCB);
1743+
}
1744+
}
1745+
return 0;
1746+
}
1747+
else {
1748+
return 1;
1749+
}
1750+
}
1751+
1752+
void newDatasetMember(HttpResponse* response, char* datasetPath, char* memberName) {
1753+
char dscb[INDEXED_DSCB] = {0};
1754+
int bufferSize = sizeof(dscb);
1755+
if (getDSCB(datasetPath, dscb, bufferSize) != 0) {
1756+
respondWithJsonError(response, "Error decoding dataset", 400, "Bad Request");
1757+
}
1758+
else {
1759+
if (!isPartionedDataset(dscb)) {
1760+
respondWithJsonError(response, "Dataset must be PDS/E", 400, "Bad Request");
1761+
}
1762+
else {
1763+
char *overwriteParam = getQueryParam(response->request,"overwrite");
1764+
int overwrite = !strcmp(overwriteParam, "TRUE") ? TRUE : FALSE;
1765+
char fullPath[DATASET_MEMBER_MAXLEN + 1] = {0};
1766+
//concatenates dataset name with member name
1767+
char *dsName = strtok(datasetPath, " ");
1768+
char *memName = strtok(memberName, " ");
1769+
snprintf(fullPath, DATASET_MEMBER_MAXLEN, "//'%s(%s)'", dsName, memName);
1770+
bool memberExists = FALSE;
1771+
FILE* memberFP = fopen(fullPath,"r");
1772+
if (memberFP) {
1773+
memberExists = TRUE;
1774+
if (fclose(memberFP)) {
1775+
zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING, "ERROR CLOSING FILE");
1776+
respondWithJsonError(response, "Could not close dataset", 500, "Internal Server Error");
1777+
}
1778+
}
1779+
if (memberExists && overwrite != TRUE) {//Member already exists and overwrite wasn't specified
1780+
respondWithJsonError(response, "Member already exists and overwrite not specified", 400, "Bad Request");
1781+
}
1782+
else { // Member doesn't exist
1783+
FILE* newMember = fopen(fullPath, "w");
1784+
if (!newMember){
1785+
respondWithJsonError(response, "Bad dataset name", 400, "Bad Request");
1786+
return;
1787+
}
1788+
if (!fclose(newMember)){
1789+
response200WithMessage(response, "Successfully created member");
1790+
}
1791+
else {
1792+
zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING, "ERROR CLOSING FILE");
1793+
respondWithJsonError(response, "Could not close dataset", 500, "Internal Server Error");
1794+
}
1795+
}
1796+
}
1797+
}
1798+
}
1799+
1800+
void removeDatasetMember(HttpResponse* response, char* datasetPath, char* memberName) {
1801+
char dscb[INDEXED_DSCB] = {0};
1802+
int bufferSize = sizeof(dscb);
1803+
if (getDSCB(datasetPath, dscb, bufferSize) != 0) {
1804+
respondWithJsonError(response, "Error decoding dataset", 400, "Bad Request");
1805+
}
1806+
else {
1807+
if (!isPartionedDataset(dscb)) {
1808+
respondWithJsonError(response, "Dataset must be PDS/E", 400, "Bad Request");
1809+
}
1810+
else {
1811+
char fullPath[DATASET_MEMBER_MAXLEN + 1] = {0};
1812+
//concatenates dataset name with member name
1813+
char *dsName = strtok(datasetPath, " ");
1814+
char *memName = strtok(memberName, " ");
1815+
snprintf(fullPath, DATASET_MEMBER_MAXLEN, "//'%s(%s)'", dsName, memName);
1816+
if (remove(fullPath) == 0) {
1817+
response200WithMessage(response, "Successfully deleted");
1818+
return;
1819+
}
1820+
else {
1821+
respondWithJsonError(response, "Could not delete, member likely does not exist", 400, "Bad Request");
1822+
return;
1823+
}
1824+
}
1825+
}
1826+
}
1827+
17221828

17231829
#endif /* not METTLE - the whole module */
17241830

h/datasetjson.h

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#define SAF_AUTHORIZATION_READ 0x04
2525
#define SAF_AUTHORIZATION_UPDATE 0x08
26+
#define MEMBER_MAX 8
27+
#define DATASET_MEMBER_MAXLEN DATASET_NAME_LEN + MEMBER_MAX + 6
2628

2729
typedef struct MetadataQueryCache_tag{
2830
EntryDataSet *cachedHLQSet;
@@ -63,6 +65,8 @@ void respondWithDatasetMetadata(HttpResponse *response);
6365
void respondWithHLQNames(HttpResponse *response, MetadataQueryCache *metadataQueryCache);
6466
void respondWithDataset(HttpResponse* response, char* fullPath, int jsonMode, HttpService* service);
6567
void updateDataset(HttpResponse* response, char* fullPath, int jsonMode, HttpService* service);
68+
void removeDatasetMember(HttpResponse* response, char* datasetPath, char* memberName);
69+
void newDatasetMember(HttpResponse* response, char* datasetPath, char* memberName);
6670
#endif
6771

6872

h/logging.h

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ ZOWE_PRAGMA_PACK_RESET
8989
#define LOG_COMP_DATASERVICE 0x008F0001000B0000LLU
9090
#define LOG_COMP_CMS 0x008F0001000C0000LLU
9191
#define LOG_COMP_LPA 0x008F0001000D0000LLU
92+
#define LOG_COMP_DATASETJSON 0x008F0001000E0000LLU
9293

9394
#define LOG_DEST_DEV_NULL 0x008F0000
9495
#define LOG_DEST_PRINTF_STDOUT 0x008F0001

0 commit comments

Comments
 (0)