You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

581 lines
22 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
6 years ago
​
6 years ago
6 years ago
​
​
​
​
​
6 years ago
​
​
​
6 years ago
​
​
​
​
​
​
​
6 years ago
6 years ago
6 years ago
​
​
​
​
6 years ago
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
6 years ago
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "rgooseZLMediaModule.h"
  2. #include "rgooseKernel.h"
  3. #include "../alg/generic/md5.h"
  4. #include <dirent.h>
  5. #include <stdio.h>
  6. #include <fcntl.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <sys/sendfile.h>
  10. #include <unistd.h>
  11. #define LOG( X ) m_pLog->Log( "ZLMM", this, X )
  12. #define LOG_S( X ) basicLogCollection::getInstance()->Log( "ZLMM", NULL, X )
  13. #define LOG_ERROR( X ) m_pLog->Log( "ZLMM", this, _LOG_ERROR, X )
  14. ARGUS_ZLMedia::ARGUS_ZLMedia( uint32_t id ): argusKernelModule( id, ARGUS_MODULE_ZLMEDIA ){
  15. m_pLog = basicLogCollection::getInstance();
  16. m_pProtocol = NULL;
  17. //m_pDefinedStreams = NULL;
  18. m_bCStage = ZLMC_STAGE_INIT;
  19. m_tTimeSeconds = 0;
  20. char tCHAR[1024];
  21. if(getcwd( tCHAR, 1024 )) {
  22. sprintf( m_pBasePath, "%s/data/videos", tCHAR );
  23. } else {
  24. sprintf( m_pBasePath, "./data/videos" );
  25. };
  26. memset( &m_sSettings,0,sizeof( DBC_MEDIA_SERVER_DATA ));
  27. if( m_pDBC!= NULL ) {
  28. DBC_MEDIA_SERVER_DATA * tDATA = NULL;
  29. tDATA = m_pDBC->getMediaServerData( m_nDBID );
  30. if( tDATA != NULL ) {
  31. memcpy( &m_sSettings, tDATA,sizeof( DBC_MEDIA_SERVER_DATA ) );
  32. free( tDATA );
  33. LOG( m_sSettings.name );
  34. m_pProtocol = new protocolZLMEDIA( m_sSettings.key, m_sSettings.host, m_sSettings.ip, m_sSettings.port );
  35. if( m_pProtocol!=NULL) {
  36. //Add IP Video Socket to Server in DB
  37. char tBuff[256];
  38. sprintf( tBuff,"%s_pxd", m_sSettings.key );
  39. m_pDBC->addNodeSocket( m_pKernel->getServerNodeId(), m_nDBID, ARGUS_NODE_SOCK_TYPE_NETWORK_DVR, ARGUS_NODE_SOCK_MODE_IN, true, tBuff, "ZLMEDIA Digital" );
  40. sprintf( tBuff,"%s_pxa", m_sSettings.key );
  41. m_pDBC->addNodeSocket( m_pKernel->getServerNodeId(), m_nDBID, ARGUS_NODE_SOCK_TYPE_AD_CONVERTER, ARGUS_NODE_SOCK_MODE_IN, true, tBuff, "ZLMEDIA Analog" );
  42. };
  43. };
  44. updateMRLs();
  45. };
  46. };
  47. ARGUS_ZLMedia::~ARGUS_ZLMedia(){
  48. if(m_pProtocol!= NULL) delete(m_pProtocol);
  49. //if(m_pDefinedStreams!=NULL) {
  50. // m_pDefinedStreams->clear();
  51. // delete(m_pDefinedStreams);
  52. //};
  53. if( m_pVHostIP!= NULL ) free( m_pVHostIP );
  54. };
  55. void ARGUS_ZLMedia::updateMRLs( void ){
  56. if( strstr( m_sSettings.ip, "127.0.0.1" ) != NULL ){
  57. //Must Update MRL only for Local Media Server
  58. LOG("Updating Local MRLs");
  59. m_pVHostIP = m_pDBC->getNodeIP4( m_pKernel->getServerNodeId() );
  60. if( m_pVHostIP!= NULL ){
  61. };
  62. };
  63. };
  64. bool ARGUS_ZLMedia::validate(){
  65. time_t tTimeSeconds;
  66. if( m_pProtocol != NULL ) {
  67. if( m_pProtocol->isOnline() ) {
  68. //tTimeSeconds = time( NULL );
  69. //if( m_tTimeSeconds > tTimeSeconds ) return true;
  70. //m_tTimeSeconds = tTimeSeconds + ZLM_SECONDS_VALIDATE;
  71. #ifdef DEBUG
  72. //char tBuff[256];
  73. //sprintf( tBuff, "Stage: %d", m_bCStage );
  74. //LOG( tBuff );
  75. #endif
  76. switch(m_bCStage) {
  77. // Request Current Media
  78. case ZLMC_STAGE_INIT:
  79. if( !m_pProtocol->delAllStreamProxys() ) return false;
  80. break;
  81. // Validate Media List
  82. case ZLMC_STAGE_START: {
  83. // Stay on same stage till request is finished
  84. if( !m_pProtocol->requestIsFinished() ) return true;
  85. DBC_INT_LIST *tStreams;
  86. tStreams = m_pDBC->listMediaStreams( m_pKernel->getSiteId(), m_sSettings.id, LIST_VALID_RECORDS );
  87. if( tStreams != NULL ){
  88. for( int index = 0; index < tStreams->size(); index++ ) {
  89. DBC_MEDIA_SERVER_STREAM_DATA * tData;
  90. tData = m_pDBC->getMediaServerStreamData( tStreams->at(index) );
  91. if( tData!= NULL ) {
  92. if( ! tData->online ) {
  93. char *tKey = NULL;
  94. // Put Stream Offline at first
  95. //m_pDBC->updateMediaServerStream( tData->id );
  96. LOG("Try to add MRL -> Server");
  97. LOG( tData->mrl );
  98. tKey = m_pProtocol->addStreamProxy( tData->id, m_pKernel->getServerIdentity(), tData->mrl );
  99. LOG( tKey );
  100. if( tKey!= NULL ) {
  101. m_pDBC->updateMediaServerStream( tData->id, tData->mrl, tKey );
  102. };
  103. };
  104. free( tData );
  105. };
  106. };
  107. };
  108. break;
  109. };
  110. case ZLM_STAGE_COLLECT_DATA:{
  111. // Validate Invalid Streams
  112. DBC_INT_LIST *tStreams;
  113. tStreams = m_pDBC->listMediaStreams( m_pKernel->getSiteId(), m_sSettings.id, LIST_INVALID_RECORDS );
  114. if( tStreams!= NULL ) {
  115. DBC_MEDIA_SERVER_STREAM_DATA *tData;
  116. for( int index = 0; index < tStreams->size(); index++ ) {
  117. tData = m_pDBC->getMediaServerStreamData( tStreams->at(index) );
  118. if( tData!= NULL ){
  119. //update MRL
  120. DBC_MEDIA_STREAM_DATA *tStream;
  121. tStream = m_pDBC->getMediaStreamData( tData->media_stream_id );
  122. if( tStream != NULL ) {
  123. if( tStream->valid ){
  124. if( tStream->source_type[0] == 'D' ) {
  125. DBC_CAM_DATA *tCam;
  126. tCam = m_pDBC->getCamData( tStream->source_id );
  127. if( tCam!= NULL ) {
  128. if( tCam->online ) {
  129. sprintf( tData->mrl, "%s://%s:%s@%s:%d%s",
  130. tStream->mrl_proto,
  131. tCam->username,
  132. tCam->password,
  133. tCam->ip,
  134. tStream->mrl_port,
  135. tStream->mrl
  136. );
  137. LOG( tData->mrl );
  138. m_pDBC->updateMediaServerStream( tStreams->at(index), tData->mrl );
  139. };
  140. free( tCam );
  141. } else LOG("Error Fetching Cam Data From DB");
  142. } else {
  143. // Grabber Stream Handling
  144. };
  145. } else {
  146. //LOG("Stream Not Valid");
  147. };
  148. free( tStream );
  149. } else LOG("Error Fetching Media Stream Data From DB");
  150. free( tData );
  151. } else LOG("Error Fetching Media Server Stream Data From DB");
  152. };
  153. tStreams->clear();
  154. delete( tStreams );
  155. };
  156. break;
  157. };
  158. };
  159. m_bCStage ++;
  160. if( m_bCStage >= ZLMC_STAGE_END ) m_bCStage = ZLMC_STAGE_START;
  161. };
  162. };
  163. return false;
  164. };
  165. char *findLatestDir( char *base ){
  166. DIR * DFD;
  167. struct dirent * DREC;
  168. struct stat STAT;
  169. struct timespec CT = { 0, 0 };
  170. char * RetVal = NULL;
  171. CT.tv_sec = 0;
  172. DFD = opendir( base );
  173. if( DFD ){
  174. while (( DREC = readdir( DFD )) != NULL) {
  175. if( DREC->d_type == DT_DIR && ( DREC->d_name[0] != '.' )){
  176. char tPath[1024];
  177. sprintf( tPath,"%s/%s", base, DREC->d_name );
  178. if( stat( tPath, &STAT ) == 0 ){
  179. if( CT.tv_sec < STAT.st_mtim.tv_sec ) {
  180. CT.tv_sec = STAT.st_mtim.tv_sec;
  181. if( RetVal == NULL ) {
  182. RetVal = (char *) malloc( 1024 );
  183. };
  184. if( RetVal!= NULL ) {
  185. sprintf( RetVal, "%s", tPath );
  186. } else {
  187. break;
  188. };
  189. };
  190. };
  191. };
  192. };
  193. closedir( DFD );
  194. };
  195. return RetVal;
  196. };
  197. char *findLatestFile( char *base ){
  198. DIR * DFD;
  199. struct dirent * DREC;
  200. struct stat STAT;
  201. struct timespec CT = { 0, 0 };
  202. char * RetVal = NULL;
  203. CT.tv_sec = 0;
  204. DFD = opendir( base );
  205. if( DFD ){
  206. while (( DREC = readdir( DFD )) != NULL) {
  207. if( DREC->d_type == DT_REG ){
  208. char tPath[1024];
  209. sprintf( tPath,"%s/%s", base, DREC->d_name );
  210. if( stat( tPath, &STAT ) == 0 ){
  211. if( CT.tv_sec < STAT.st_mtim.tv_sec ) {
  212. CT = STAT.st_mtim;
  213. if( RetVal == NULL ) {
  214. RetVal = (char *) malloc( 128 );
  215. };
  216. if( RetVal!= NULL ) {
  217. sprintf( RetVal, "%s", DREC->d_name );
  218. } else {
  219. break;
  220. };
  221. };
  222. };
  223. };
  224. };
  225. closedir( DFD );
  226. };
  227. return RetVal;
  228. };
  229. int appendFile( const char* source, const char* destination ){
  230. char tCMD[4096];
  231. sprintf( tCMD, "cat \"%s\" > \"%s\"", source, destination );
  232. return system( tCMD );
  233. };
  234. void ARGUS_ZLMedia::dispatchEvent( EVENT_CONTAINER *E ){
  235. if( E == NULL ) return;
  236. switch( E->m_eClass ) {
  237. case EVT_CLASS_VIDEO:{
  238. switch( E->m_eType ) {
  239. case EVT_CAPTURE_START:{
  240. if( E->m_ref_id ) {
  241. DBC_MEDIA_SERVER_STREAM_DATA *tStream;
  242. tStream = m_pDBC->getMediaServerStreamDataBySource( E->m_nDestinationUID );
  243. if( tStream != NULL ) {
  244. if( tStream->online ){
  245. char tDirName[MAX_PATH_LEN];
  246. sprintf( tDirName, "%s%s", m_sSettings.docRoot, tStream->key+strlen( m_sSettings.host ) );
  247. #ifdef DEBUG
  248. LOG("Media Dir For Record");
  249. #endif
  250. if( !startRecord( E->m_ref_id, tStream->id, E->m_ref_UUID, tDirName ) ) LOG_ERROR("Error Starting Record!");
  251. };
  252. free( tStream );
  253. } else LOG_ERROR("Error Fitching Media Stream Data!!");
  254. } else {
  255. LOG_ERROR("No Reference ID is SET!");
  256. };
  257. break;
  258. };
  259. };
  260. break;
  261. };
  262. };
  263. };
  264. bool ARGUS_ZLMedia::startRecord( uint32_t evt_id, uint32_t chan, CSTR evtID, CSTR base ){
  265. ZL_RECORDER_SLOT *tRecord = NULL;
  266. if( m_vRecorderSlots.size() > 0 ) {
  267. // validate old and search
  268. for( VECTOR_ZL_RECORDER_SLOTS::iterator idx=m_vRecorderSlots.begin(); idx < m_vRecorderSlots.end(); idx++ ) {
  269. if( (*idx)->m_bFinished ) {
  270. delete( (*idx)->m_pMutex );
  271. free((*idx));
  272. m_vRecorderSlots.erase( idx );
  273. } else {
  274. if( (*idx)->m_uStreamID == chan ) {
  275. tRecord = (*idx);
  276. };
  277. };
  278. };
  279. };
  280. if( tRecord != NULL ) {
  281. tRecord->m_pMutex->lock();
  282. m_pDBC->addVideoRecord( evt_id, chan, tRecord->m_sDstName, ZLM_10TH_SEC_RECORD_LENGTH / 10, tRecord->m_uTimer / 10 );
  283. tRecord->m_uTimer += ZLM_10TH_SEC_RECORD_LENGTH;
  284. tRecord->m_pMutex->unlock();
  285. return true;
  286. } else {
  287. char tCHAR[128];
  288. CSTR tMD5;
  289. sprintf( tCHAR,"%s_%d", evtID, chan );
  290. tMD5 = MD5String( tCHAR );
  291. if( tMD5 ) {
  292. CSTR tPath = createNewRecordFolder( tMD5 );
  293. if( tPath != NULL ){
  294. tRecord = (ZL_RECORDER_SLOT *)malloc( sizeof(ZL_RECORDER_SLOT));
  295. if( tRecord != NULL ) {
  296. char tBuff[512];
  297. sprintf( tBuff, "[%s] >>> [%s]", base, tPath );
  298. LOG( tBuff );
  299. memset(tRecord, 0, sizeof(ZL_RECORDER_SLOT));
  300. strncpy( tRecord->m_sSrcBase, base, 1024 );
  301. strncpy( tRecord->m_sDstBase, tPath, 1024 );
  302. strncpy( tRecord->m_sDstName, tMD5, 33 );
  303. tRecord->m_uStreamID = chan;
  304. tRecord->m_bFinished = false;
  305. tRecord->m_uTimer = ZLM_10TH_SEC_RECORD_LENGTH;
  306. tRecord->m_uSkeep = ZLM_10TH_SEC_RECORD_SKEEP;
  307. tRecord->m_pMutex = new basicMutex();
  308. m_pDBC->addVideoRecord( evt_id, chan, tRecord->m_sDstName, ZLM_10TH_SEC_RECORD_LENGTH / 10 );
  309. if(tRecord->m_pMutex!=NULL) {
  310. int RetVal = pthread_create( &tRecord->m_hThreadHandle, NULL, m_fRecorder, ( void * ) tRecord );
  311. if( RetVal == -1 ) {
  312. delete( tRecord->m_pMutex );
  313. free( tRecord );
  314. LOG_ERROR("Thread Creation Failed.");
  315. } else {
  316. m_vRecorderSlots.push_back( tRecord );
  317. free( tPath );
  318. return true;
  319. };
  320. } else {
  321. LOG_ERROR("Mutex Creation Failed.");
  322. free( tRecord );
  323. };
  324. };
  325. free( tPath );
  326. };
  327. free( tMD5 );
  328. };
  329. };
  330. return false;
  331. };
  332. float getDurationOfTS( CSTR fname ){
  333. char tCMD[2048];
  334. char tBuff[256];
  335. float RetVal = .0f;
  336. FILE * FID = NULL;
  337. //sprintf( tCMD, "ffprobe %s 2>&1 | grep \"Duration\"", fname );
  338. sprintf( tCMD, "ffprobe -hide_banner -v quiet -show_streams \"%s\" | grep \"duration=\"", fname );
  339. FID = popen( tCMD, "r" );
  340. if( FID ) {
  341. char * tT;
  342. fread( tBuff,1,256,FID);
  343. tT = trim( tBuff );
  344. //RetVal = atof( tT+16 );
  345. RetVal = atof( tT+9 );
  346. pclose( FID );
  347. };
  348. return RetVal;
  349. };
  350. void *ARGUS_ZLMedia::m_fRecorder( void *ptr ){
  351. ZL_RECORDER_SLOT *MS = (ZL_RECORDER_SLOT *) ptr;
  352. if( MS != NULL ) {
  353. char SFN[1024];
  354. char DFN[1024];
  355. char tB[4096];
  356. char LAST[1024];
  357. char M3U[1024];
  358. char *cFN;
  359. FILE *FID;
  360. while( MS->m_uSkeep && !MS->m_bFinished ) {
  361. MS->m_uSkeep--;
  362. SLEEP( 100 );
  363. };
  364. if( !MS->m_bFinished ){
  365. sprintf( M3U, "%s/%s.m3u8", MS->m_sDstBase, MS->m_sDstName );
  366. FID = fopen( M3U, "w+" );
  367. if( FID== NULL ) {
  368. MS->m_bFinished = true;
  369. } else {
  370. fprintf( FID, "#EXTM3U\n#EXT-X-VERSION:3\n#EXT-X-ALLOW-CACHE:NO\n#EXT-X-TARGETDURATION:2\n#EXT-X-MEDIA-SEQUENCE:1\n" );
  371. fclose(FID);
  372. char *tDD = findLatestDir( MS->m_sSrcBase );
  373. if( tDD ) {
  374. sprintf( SFN,"%s", tDD );
  375. free( tDD );
  376. tDD = findLatestDir( SFN );
  377. if( tDD ) {
  378. sprintf( LAST,"%s", tDD );
  379. free( tDD );
  380. cFN = findLatestFile( LAST );
  381. };
  382. };
  383. if( cFN ) {
  384. while( MS->m_uTimer && !MS->m_bFinished ) {
  385. char *tFN;
  386. tDD = findLatestDir( MS->m_sSrcBase );
  387. if( tDD ) {
  388. sprintf( SFN,"%s", tDD );
  389. free( tDD );
  390. tDD = findLatestDir( SFN );
  391. if( tDD ) {
  392. sprintf( LAST,"%s", tDD );
  393. free( tDD );
  394. tFN = findLatestFile( LAST );
  395. if( tFN ) {
  396. if( strstr( cFN, tFN )== NULL ) {
  397. sprintf( SFN, "%s/%s", LAST, cFN );
  398. sprintf( DFN, "%s/%s", MS->m_sDstBase, cFN );
  399. //Save File changed
  400. FID = fopen( M3U, "a" );
  401. if( FID== NULL) {
  402. MS->m_bFinished = true;
  403. continue;
  404. };
  405. fprintf( FID, "#EXTINF:%0.3f,\n%s\n", getDurationOfTS(SFN), cFN );
  406. fclose( FID );
  407. appendFile( SFN, DFN );
  408. free( cFN );
  409. cFN = tFN;
  410. } else free( tFN );
  411. SLEEP( 100 );
  412. MS->m_pMutex->lock();
  413. MS->m_uTimer--;
  414. MS->m_pMutex->unlock();
  415. } else MS->m_bFinished = true;
  416. };
  417. };
  418. };
  419. sprintf( SFN, "%s/%s", LAST, cFN );
  420. sprintf( DFN, "%s/%s", MS->m_sDstBase, cFN );
  421. FID = fopen( M3U, "a" );
  422. if( FID!= NULL) {
  423. fprintf( FID, "#EXTINF:%0.3f,\n%s\n#EXT-X-ENDLIST\n", getDurationOfTS(SFN), cFN );
  424. fclose( FID );
  425. };
  426. appendFile( SFN, DFN );
  427. free( cFN );
  428. } else {
  429. LOG_S("No File Find1!");
  430. }
  431. };
  432. MS->m_bFinished = true;
  433. };
  434. };
  435. pthread_exit( NULL );
  436. return NULL;
  437. };
  438. CSTR ARGUS_ZLMedia::createNewRecordFolder( CSTR seed ){
  439. char Buffer[1024];
  440. char tCWD[1024];
  441. char tB[64];
  442. int RetVal;
  443. if( fileExist( m_pBasePath ) == 0 ) {
  444. sprintf( Buffer, "No BasePath[%s] Detected", m_pBasePath );
  445. LOG(Buffer);
  446. return NULL;
  447. };
  448. strncpy( tB, seed, 2 );
  449. tB[2] = (char)0;
  450. sprintf( tCWD, "%s/%s", m_pBasePath, tB );
  451. #ifdef DEBUG
  452. sprintf( Buffer,"Level[0]: %s", tCWD );
  453. LOG(Buffer);
  454. #endif
  455. if( fileExist( tCWD ) == 0 ){
  456. #ifdef __linux__
  457. RetVal = mkdir( tCWD, STORAGE_DIR_MODE );
  458. #else
  459. RetVal = _mkdir( tCWD );
  460. #endif
  461. if( RetVal!= 0 ) {
  462. return NULL;
  463. };
  464. };
  465. strncpy( tB, seed+2, 2 );
  466. tB[2] = (char)0;
  467. sprintf( Buffer, "%s/%s", tCWD, tB );
  468. strncpy( tCWD, Buffer, 1024 );
  469. #ifdef DEBUG
  470. sprintf( Buffer,"Level[1]: %s", tCWD );
  471. LOG(Buffer);
  472. #endif
  473. if( fileExist( tCWD ) == 0 ){
  474. #ifdef __linux__
  475. RetVal = mkdir( tCWD, STORAGE_DIR_MODE );
  476. #else
  477. RetVal = _mkdir( tCWD );
  478. #endif
  479. if( RetVal!= 0 ) {
  480. return NULL;
  481. };
  482. };
  483. /*
  484. strncpy( tB, seed+4, 28 );
  485. tB[28] = (char)0;
  486. sprintf( Buffer, "%s/%s", tCWD, tB );
  487. strncpy( tCWD, Buffer, 1024 );
  488. #ifdef DEBUG
  489. sprintf( Buffer,"Level[2]: %s", tCWD );
  490. LOG(Buffer);
  491. #endif
  492. if( fileExist( tCWD ) == 0 ){
  493. #ifdef __linux__
  494. RetVal = mkdir( tCWD, STORAGE_DIR_MODE );
  495. #else
  496. RetVal = _mkdir( tCWD );
  497. #endif
  498. if( RetVal!= 0 ) {
  499. return NULL;
  500. };
  501. };
  502. strncpy( tB, seed+19, 4 );
  503. tB[4] = (char)0;
  504. sprintf( Buffer, "%s/%s", tCWD, tB );
  505. strncpy( tCWD, Buffer, 1024 );
  506. #ifdef DEBUG
  507. sprintf( Buffer,"Level[3]: %s", tCWD );
  508. LOG(Buffer);
  509. #endif
  510. if( fileExist( tCWD ) == 0 ){
  511. #ifdef __linux__
  512. RetVal = mkdir( tCWD, STORAGE_DIR_MODE );
  513. #else
  514. RetVal = _mkdir( tCWD );
  515. #endif
  516. if( RetVal!= 0 ) {
  517. return NULL;
  518. };
  519. };
  520. strncpy( tB, seed+24, 12 );
  521. tB[12] = (char)0;
  522. sprintf( Buffer, "%s/%s", tCWD, tB );
  523. strncpy( tCWD, Buffer, 1024 );
  524. #ifdef DEBUG
  525. sprintf( Buffer,"Level[4]: %s", tCWD );
  526. LOG(Buffer);
  527. #endif
  528. if( fileExist( tCWD ) == 0 ){
  529. #ifdef __linux__
  530. RetVal = mkdir( tCWD, STORAGE_DIR_MODE );
  531. #else
  532. RetVal = _mkdir( tCWD );
  533. #endif
  534. if( RetVal!= 0 ) {
  535. return NULL;
  536. };
  537. };
  538. */
  539. return strdup( tCWD );
  540. };
  541. #undef LOG
  542. #undef LOG_S
  543. #undef LOG_ERROR