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.

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