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.

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