Skip to content

Commit cbbbe61

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

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

c/datasetjson.c

+111
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,116 @@ 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 + 1, "//'%s(%s)'", dsName, memName);
1770+
FILE* memberExists = fopen(fullPath,"r");
1771+
if (memberExists && overwrite != TRUE) {//Member already exists and overwrite wasn't specified
1772+
if (fclose(memberExists) != 0) {
1773+
zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING, "ERROR CLOSING FILE");
1774+
respondWithJsonError(response, "Could not close dataset", 500, "Internal Server Error");
1775+
}
1776+
else {
1777+
respondWithJsonError(response, "Member already exists and overwrite not specified", 400, "Bad Request");
1778+
}
1779+
}
1780+
else { // Member doesn't exist
1781+
if (memberExists) {
1782+
if (fclose(memberExists) != 0) {
1783+
zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING, "ERROR CLOSING FILE");
1784+
respondWithJsonError(response, "Could not close dataset", 500, "Internal Server Error");
1785+
return;
1786+
}
1787+
}
1788+
FILE* newMember = fopen(fullPath, "w");
1789+
if (!newMember){
1790+
respondWithJsonError(response, "Bad dataset name", 400, "Bad Request");
1791+
return;
1792+
}
1793+
if (fclose(newMember) == 0){
1794+
response200WithMessage(response, "Successfully created member");
1795+
}
1796+
else {
1797+
zowelog(NULL, LOG_COMP_DATASETJSON, ZOWE_LOG_WARNING, "ERROR CLOSING FILE");
1798+
respondWithJsonError(response, "Could not close dataset", 500, "Internal Server Error");
1799+
}
1800+
}
1801+
}
1802+
}
1803+
}
1804+
1805+
void removeDatasetMember(HttpResponse* response, char* datasetPath, char* memberName) {
1806+
char dscb[INDEXED_DSCB] = {0};
1807+
int bufferSize = sizeof(dscb);
1808+
if (getDSCB(datasetPath, dscb, bufferSize) != 0) {
1809+
respondWithJsonError(response, "Error decoding dataset", 400, "Bad Request");
1810+
}
1811+
else {
1812+
if (!isPartionedDataset(dscb)) {
1813+
respondWithJsonError(response, "Dataset must be PDS/E", 400, "Bad Request");
1814+
}
1815+
else {
1816+
char fullPath[DATASET_MEMBER_MAXLEN + 1] = {0};
1817+
//concatenates dataset name with member name
1818+
char *dsName = strtok(datasetPath, " ");
1819+
char *memName = strtok(memberName, " ");
1820+
snprintf(fullPath, DATASET_MEMBER_MAXLEN + 1, "//'%s(%s)'", dsName, memName);
1821+
if (remove(fullPath) == 0) {
1822+
response200WithMessage(response, "Successfully deleted");
1823+
return;
1824+
}
1825+
else {
1826+
respondWithJsonError(response, "Could not delete, member likely does not exist", 400, "Bad Request");
1827+
return;
1828+
}
1829+
}
1830+
}
1831+
}
1832+
17221833

17231834
#endif /* not METTLE - the whole module */
17241835

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)