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.

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