@@ -53,6 +53,7 @@ static int defaultVSAMCSIFieldCount = 4;
53
53
54
54
static char getRecordLengthType (char * dscb );
55
55
static int getMaxRecordLength (char * dscb );
56
+ static int getDSCB (char * datasetName , char * dscb , int bufferSize );
56
57
static void respondWithNonVSAMDataset (HttpResponse * response , char * absolutePath , int jsonMode );
57
58
static void respondWithVSAMDataset (HttpResponse * response , char * absolutePath , hashtable * acbTable , int jsonMode );
58
59
static void updateNonVSAMDataset (HttpResponse * response , char * absolutePath , int jsonMode );
@@ -1719,6 +1720,116 @@ void respondWithHLQNames(HttpResponse *response, MetadataQueryCache *metadataQue
1719
1720
#endif /* __ZOWE_OS_ZOS */
1720
1721
}
1721
1722
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
+
1722
1833
1723
1834
#endif /* not METTLE - the whole module */
1724
1835
0 commit comments