From c8cc1191fdccd2d815058ad6ca595cb37ec694c3 Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Mon, 24 Mar 2025 20:32:30 +0200 Subject: [PATCH] Fixed TransportSocket Exit --- Projects/la_mojo/build | 2 +- lib/App/common/serverDataBinder.h | 19 +++ lib/App/common/serverMySQL_dataBinder.cpp | 66 +++++++- lib/App/common/serverMySQL_dataBinder.h | 2 + lib/App/mojo/mojoKernel.cpp | 2 + lib/App/mojo/mojoRemoteClient.cpp | 4 +- lib/App/serva/servaKernel.cpp | 15 +- lib/App/serva/servaRemoteClientHandler.cpp | 2 +- lib/App/serva/servaSessionManager.cpp | 169 ++++++++++++++++++--- lib/App/serva/servaSessionManager.h | 16 +- lib/data/transport/transportSocket.cpp | 24 ++- 11 files changed, 278 insertions(+), 43 deletions(-) diff --git a/Projects/la_mojo/build b/Projects/la_mojo/build index 7efee7e2..8d62327c 100755 --- a/Projects/la_mojo/build +++ b/Projects/la_mojo/build @@ -4,7 +4,7 @@ #make clean -e "CFG=Debug" #make -e "CFG=Debug" -j$(nproc) -#make clean -e "CFG=Debug86" +make clean -e "CFG=Debug86" make -e "CFG=Debug86" -j$(nproc) #make clean -e "CFG=Release86" diff --git a/lib/App/common/serverDataBinder.h b/lib/App/common/serverDataBinder.h index 8798de5a..c865a8f5 100644 --- a/lib/App/common/serverDataBinder.h +++ b/lib/App/common/serverDataBinder.h @@ -34,6 +34,23 @@ typedef enum E_SERVER_STAT_ENUM{ SERVER_PEER_COUNT = 16 }SERVER_STAT_ENUM; +class SQLite_Connector; + +typedef struct S_SESSION_DATA{ + uint32_t track_id; + uint64_t db_id; + char uuid[65]; + uint32_t sts; + uint32_t sms; + uint32_t lts; + uint8_t src; + bool skeep_validation; + char reportVaultPath[MAX_PATH]; + SQLite_Connector * m_pDataReport; +}SESSION_DATA; +typedef std::unordered_map< uint32_t, SESSION_DATA* > M_SESSIONS; + + class serverDataBinder { public: serverDataBinder(); @@ -50,6 +67,7 @@ class serverDataBinder { virtual uint64_t getRecentMediaId(){ return 0;}; virtual DBC_RPC_MEDIA_INFO * getRemoteMediaInfo( uint64_t id ){ return NULL; }; virtual DBC_RPC_MEDIA_INFO_EX * getRemoteMediaInfoEx( uint64_t id ){ return NULL; }; + virtual SESSION_DATA * getSessionData( uint64_t id ){ return NULL; }; virtual uint64_t getTrackIdByMojo( uint64_t id ){ return 0;}; virtual uint64_t getUpperLRF( uint64_t id ){ return 0; }; virtual DBC_RPC_WEB_CMD * fetchWebCmd( uint64_t id ){ return NULL;}; @@ -58,6 +76,7 @@ class serverDataBinder { virtual bool registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ){ return false; }; virtual bool removeRemoteMediaInfo( uint64_t id ){ return false; }; virtual bool removeWebCmd( uint64_t id ){ return false; }; + virtual bool sessionClose( uint64_t session_id ){ return false; }; virtual uint64_t sessionCreate( uint64_t track_id, uint32_t ts, uint16_t tsms, CSTR uuid, char src ){ return false; }; virtual bool sessionStatAddEvt( uint64_t session_id ){ return false; }; virtual bool sessionStatAddVid( uint64_t session_id ){ return false; }; diff --git a/lib/App/common/serverMySQL_dataBinder.cpp b/lib/App/common/serverMySQL_dataBinder.cpp index 53ec41ee..f48da648 100644 --- a/lib/App/common/serverMySQL_dataBinder.cpp +++ b/lib/App/common/serverMySQL_dataBinder.cpp @@ -106,7 +106,7 @@ bool servaMySQLDBC::connect( void ){ bool servaMySQLDBC::closeAllOnGoingSessions(){ if( m_bIsConnected ){ char tQBuf[MAX_PATH_LEN]; - sprintf( tQBuf, "UPDATE `sessions` SET `status`=1 WHERE `status`=0" ); + sprintf( tQBuf, "UPDATE `sessions` SET `final`='Y' WHERE `final`='N'" ); #ifdef DEBUG_ALL LOG(tQBuf); #endif @@ -417,6 +417,55 @@ DBC_RPC_MEDIA_INFO_EX *servaMySQLDBC::getRemoteMediaInfoEx( uint64_t id ){ return RetVal; }; +SESSION_DATA *servaMySQLDBC::getSessionData( uint64_t id ){ + SESSION_DATA *RetVal = NULL; + if( m_bIsConnected ){ + char tQBuf[MAX_PATH_LEN]; + AAssoc *result; + sprintf( tQBuf, "SELECT * FROM `sessions` WHERE `id`=%" PRIu64, id ); +#ifdef DEBUG_ALL + LOG(tQBuf); +#endif + result = m_pDatabase->Query( tQBuf ); + if( result!= NULL ) { + if (result->size() > 0) { + Assoc *cArr; + Assoc::iterator it; + RetVal = ( SESSION_DATA *) malloc(sizeof(SESSION_DATA)); + if ( RetVal ) { + memset( RetVal, 0, sizeof(SESSION_DATA)); + RetVal->db_id = id; + cArr = result->at(0); + it = cArr->find("ts"); + if( it != cArr->end() ){ + RetVal->sts = atoi( it->second.c_str() ); + }; + it = cArr->find("ts_ms"); + if( it != cArr->end() ){ + RetVal->sms = atoi( it->second.c_str() ); + }; + it = cArr->find("track_id"); + if( it != cArr->end() ){ + RetVal->track_id = atoi( it->second.c_str() ); + }; + //it = cArr->find("lts"); + //if( it != cArr->end() ){ + // RetVal->lts = atoi( it->second.c_str() ); + //}; + RetVal->lts = time(NULL); + it = cArr->find("uuid"); + if( it != cArr->end() ){ + strncpy( RetVal->uuid, it->second.c_str(), 64 ); + RetVal->uuid[64] = (char)0; + }; + }; + }; + }; + deleteResult( result ); + }; + return RetVal; +}; + uint64_t servaMySQLDBC::getTrackIdByMojo( uint64_t id ){ uint64_t RetVal = 0; if( m_bIsConnected ){ @@ -658,6 +707,19 @@ bool servaMySQLDBC::setNodeOffline( uint32_t NodeID ){ return false; }; +bool servaMySQLDBC::sessionClose( uint64_t session_id ){ + if( m_bIsConnected ){ + char tQBuf[CTEXT]; + sprintf(tQBuf, "UPDATE `sessions` SET `lts`=UNIX_TIMESTAMP(now()), `final`='Y' WHERE `id`=%" PRIu64, session_id ); +#ifdef DEBUG_ALL + LOG(tQBuf); +#endif + m_pDatabase->SilentQuery(tQBuf); + return true; + }; + return false; +}; + uint64_t servaMySQLDBC::sessionCreate( uint64_t track_id, uint32_t ts, uint16_t tsms, CSTR uuid, char src ){ if( m_bIsConnected ){ char tQBuf[CTEXT]; @@ -748,7 +810,7 @@ bool servaMySQLDBC::updateModuleData( uint64_t DBID, uint32_t UPPER_ID, uint32_t if( m_bIsConnected ) { char tQBuf[MAX_PATH_LEN]; sprintf( tQBuf, "UPDATE `metro_modules` SET `cam_stream`=%d, `top_id`=%d, `bottom_id`=%d, `cam_id`=%d, `tls_version`='%s', `lls_version`='%s' WHERE `id`=%" PRIu64, CAM_STREAM_ID, UPPER_ID, BOTTOM_ID, CAM_ID, vstr, lstr, DBID ); -#ifdef DEBUG +#ifdef DEBUG_EXTRA LOG(tQBuf); #endif m_pDatabase->SilentQuery( tQBuf ); diff --git a/lib/App/common/serverMySQL_dataBinder.h b/lib/App/common/serverMySQL_dataBinder.h index a96b366d..70bb2f55 100644 --- a/lib/App/common/serverMySQL_dataBinder.h +++ b/lib/App/common/serverMySQL_dataBinder.h @@ -37,6 +37,7 @@ class servaMySQLDBC: public serverDataBinder { virtual DBC_RPC_MEDIA_INFO * getRemoteMediaInfo( uint64_t id ); virtual DBC_RPC_MEDIA_INFO_EX * getRemoteMediaInfoEx( uint64_t id ); virtual uint64_t getRecentMediaId(); + virtual SESSION_DATA * getSessionData( uint64_t id ); virtual uint64_t getTrackIdByMojo( uint64_t id ); virtual uint64_t getUpperLRF( uint64_t id ); virtual bool putIntoLog( CSTR type, CSTR TS, CSTR Msg ); @@ -45,6 +46,7 @@ class servaMySQLDBC: public serverDataBinder { virtual uint32_t registerVideoTransfer( uint32_t srcNode, CSTR uuid, uint32_t dataSize, CSTR fmt, uint32_t ts ); virtual bool removeRemoteMediaInfo( uint64_t id ); virtual bool removeWebCmd( uint64_t id ); + virtual bool sessionClose( uint64_t session_id ); virtual uint64_t sessionCreate( uint64_t track_id, uint32_t ts, uint16_t tsms, CSTR uuid, char src ); virtual bool sessionStatAddEvt( uint64_t session_id ); virtual bool sessionStatAddVid( uint64_t session_id ); diff --git a/lib/App/mojo/mojoKernel.cpp b/lib/App/mojo/mojoKernel.cpp index 5b4be609..0194dc02 100644 --- a/lib/App/mojo/mojoKernel.cpp +++ b/lib/App/mojo/mojoKernel.cpp @@ -514,7 +514,9 @@ bool mojoKernel::fillMojoInfo( ARGUS_DATA_MOJO_INFO* ptr ){ ptr->TOT_DISK = m_sSysInfo.T_DISK; ptr->TOT_MEMO = m_sSysInfo.T_MEM; strncpy( ptr->TLS_VERSION, _BUILD_STRING_, 64 ); + ptr->TLS_VERSION[63]=(char)0; strncpy( ptr->LLS_VERSION, m_pHardwareManager->getSysInfo()->OS_INFO, 64 ); + ptr->LLS_VERSION[63]=(char)0; LOG("FIMO Overall info"); return true; }; diff --git a/lib/App/mojo/mojoRemoteClient.cpp b/lib/App/mojo/mojoRemoteClient.cpp index 92b83eac..fce8cb1e 100644 --- a/lib/App/mojo/mojoRemoteClient.cpp +++ b/lib/App/mojo/mojoRemoteClient.cpp @@ -423,7 +423,7 @@ void mojoRemoteClient::m_fThreadProc( void ){ break; }; case ARGUS_RPC_STAGE_WAIT_RECONNECT:{ -#ifdef DEBUG +#ifdef DEBUG_EXTRA LOG("Wait Reconnect!"); #endif if ( !decTO() ) setAutomationStage( ARGUS_RPC_STAGE_CONNECT ); @@ -576,8 +576,10 @@ bool mojoRemoteClient::validate(){ }; */ }; +#ifdef DEBUG_EXTRA } else { LOG("Not Connected!"); +#endif /* if( m_pPort ) { // Cancel all ongoing Queries diff --git a/lib/App/serva/servaKernel.cpp b/lib/App/serva/servaKernel.cpp index da735d43..6eb9d653 100644 --- a/lib/App/serva/servaKernel.cpp +++ b/lib/App/serva/servaKernel.cpp @@ -398,8 +398,19 @@ bool servaKernel::processVideoFile( uint64_t dbid ){ void servaKernel::handleEncodedVideo( servaMediaEncoder *ptr ){ if ( ptr ) { m_pDBC->updateEncodeFormat( ptr->getDBID(), ptr->getDstFormat() ); - if ( m_pSM->addVideo( m_pDBC->getRemoteMediaInfoEx( ptr->getDBID() ) ) ) m_pDBC->removeRemoteMediaInfo( ptr->getDBID() ); - LOG("Delete Encoder!"); + DBC_RPC_MEDIA_INFO_EX *tP = m_pDBC->getRemoteMediaInfoEx( ptr->getDBID() ); + if ( tP ) { + if( m_pSM->addVideo( tP )){ + m_pDBC->removeRemoteMediaInfo( ptr->getDBID() ); + } else { + LOG_ERROR("Cannot Add to session Media Info!"); + }; + LOG("Delete Extended Info"); + free( tP ); + } else { + LOG_ERROR("Cannot get Extended Encoder Queue Media Info!"); + }; + LOG("Delete Encoder"); delete( ptr ); LOG("Done"); }; diff --git a/lib/App/serva/servaRemoteClientHandler.cpp b/lib/App/serva/servaRemoteClientHandler.cpp index 679305a0..1779cce1 100644 --- a/lib/App/serva/servaRemoteClientHandler.cpp +++ b/lib/App/serva/servaRemoteClientHandler.cpp @@ -280,7 +280,7 @@ void servaRPCHadnler::m_fThreadProc( void ){ }; DBC_RPC_WEB_CMD *tCMD = m_pDBC->fetchWebCmd( m_dMojoDBID ); if ( tCMD ) { - LOG( "Have Web CMD!"); + //LOG( "Have Web CMD!"); ARGUS_DATA_RPC RPC_PACK; RPC_PACK.CMD = tCMD->cmd; RPC_PACK.NODE_ID = tCMD->aux_id; diff --git a/lib/App/serva/servaSessionManager.cpp b/lib/App/serva/servaSessionManager.cpp index d51859f0..c77bb763 100644 --- a/lib/App/serva/servaSessionManager.cpp +++ b/lib/App/serva/servaSessionManager.cpp @@ -119,7 +119,9 @@ bool servaSessionManager::addEvent( SESSION_DATA *sp, ARGUS_DATA_EVENT *ptr ){ switch ( ptr->TYPE ) { case EVT_LRF_END_SESSION_TO: case EVT_LRF_END_SESSION_MA: - sprintf( tQBuf, "INSERT INTO `events`(`session_id`,`module_id`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,%d,%d,%d,%d)", + //No Technical events + return false; + sprintf( tQBuf, "INSERT INTO `events`(`session_id`,`module_id`,`ts`,`ts_ms`,`evt_type`) VALUES(%" PRIu64 ",%" PRIu64 ",%d,%d,%d)", sp->db_id, ptr->MODULE_ID, ptr->TS, @@ -128,7 +130,9 @@ bool servaSessionManager::addEvent( SESSION_DATA *sp, ARGUS_DATA_EVENT *ptr ){ ); break; case EVT_LRF_START_SESSION: - sprintf( tQBuf, "INSERT INTO `events`(`session_id`,`module_id`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,%d,%d,%d,%d)", + //No Technical events + return false; + sprintf( tQBuf, "INSERT INTO `events`(`session_id`,`module_id`,`ts`,`ts_ms`,`evt_type`) VALUES(%" PRIu64 ",%" PRIu64 ",%d,%d,%d)", sp->db_id, ptr->MODULE_ID, ptr->TS, @@ -172,7 +176,9 @@ bool servaSessionManager::addEvent( SESSION_DATA *sp, ARGUS_DATA_EVENT *ptr ){ case EVT_SST_OVERFLOW: case EVT_VIDEO_FPS_DEGRADED: case EVT_VIDEO_FPS_RAISED:{ - sprintf( tQBuf, "INSERT INTO `events`(`session_id`,`module_id`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,%d,%d,%d,%d)", + //No Technical events + return false; + sprintf( tQBuf, "INSERT INTO `events`(`session_id`,`module_id`,`ts`,`ts_ms`,`evt_type`) VALUES(%" PRIu64 ",%" PRIu64 ",%d,%d,%d)", sp->db_id, ptr->MODULE_ID, ptr->TS, @@ -186,7 +192,7 @@ bool servaSessionManager::addEvent( SESSION_DATA *sp, ARGUS_DATA_EVENT *ptr ){ case EVT_TARGET_3D_BLACK:{ updateSessionStat( sp->db_id ); sprintf( tQBuf, "INSERT INTO `events`(`session_id`,`module_id`,`ts`,`ts_ms`,`evt_type`,`azimuth`,`elevation`,`range`,`area`)" \ - " VALUES(%d,%d,%d,%d,%d,%0.2f,%0.2f,%0.2f,%0.2f)", + " VALUES(%" PRIu64 ",%" PRIu64 ",%d,%d,%d,%0.2f,%0.2f,%0.2f,%0.2f)", sp->db_id, ptr->MODULE_ID, ptr->TS, @@ -203,7 +209,7 @@ bool servaSessionManager::addEvent( SESSION_DATA *sp, ARGUS_DATA_EVENT *ptr ){ case EVT_TARGET_2D_BLACK:{ updateSessionStat( sp->db_id ); sprintf( tQBuf, "INSERT INTO `events`(`session_id`,`module_id`,`ts`,`ts_ms`,`evt_type`,`azimuth`,`range`,`area`)" \ - " VALUES(%d,%d,%d,%d,%d,%0.2f,%0.2f,%0.2f)", + " VALUES(%" PRIu64 ",%" PRIu64 ",%d,%d,%d,%0.2f,%0.2f,%0.2f)", sp->db_id, ptr->MODULE_ID, ptr->TS, @@ -226,13 +232,34 @@ bool servaSessionManager::addEvent( SESSION_DATA *sp, ARGUS_DATA_EVENT *ptr ){ }; bool servaSessionManager::addVideo( DBC_RPC_MEDIA_INFO_EX *ptr ){//uint32_t module_id, uint32_t ts, uint16_t tsms, CSTR uuid, CSTR fmt, uint8_t fps ){ - if ( ptr == NULL ) return false; - SESSION_DATA *sp = validateSession( ptr->session_id ); - if ( sp == NULL ) return false; + if ( ptr == NULL ){ + LOG_ERROR( "ExtInfo ptr is null!"); + return false; + }; + + char tB[64]; + sprintf( tB, "Session id: %" PRIu64, ptr->session_id ); + LOG( tB ); + + // At Time of Video Addition the Session May be expired already!! + // No neet to Validate session! + + SESSION_DATA *sp = validateSession( ptr->session_id ); + if ( sp == NULL ) { + sp = reopenSession( ptr->session_id ); + if ( sp == NULL ) { + LOG_ERROR( "Session Data ptr is null!"); + return false; + }; + }; if ( sp->m_pDataReport ) { + char tName[MAX_PATH]; + sprintf(tName, "%s/%s.%s", sp->reportVaultPath, ptr->uuid, ptr->fmt ); + chown( tName, getUserUid(web_access_user), getUserGid(web_access_group) ); + chmod( tName, DB_FILE_MODE ); updateSessionStat( ptr->session_id, false ); char tQBuf[1024]; - sprintf( tQBuf, "INSERT INTO `videos`(`session_id`,`module_id`,`uuid`,`ts`,`ts_ms`,`ext`,`fps`) VALUES(%d, %d,'%s',%d,%d,'%s',%d)", + sprintf( tQBuf, "INSERT INTO `videos`(`session_id`,`module_id`,`uuid`,`ts`,`ts_ms`,`ext`,`fps`) VALUES(%" PRIu64 ", %d,'%s',%d,%d,'%s',%d)", ptr->session_id, ptr->module_id, ptr->uuid, @@ -244,7 +271,11 @@ bool servaSessionManager::addVideo( DBC_RPC_MEDIA_INFO_EX *ptr ){//uint32_t modu #ifdef DEBUG_EXTRA LOG( tQBuf ); #endif - return sp->m_pDataReport->SilentQuery( tQBuf ); + bool rv = sp->m_pDataReport->SilentQuery( tQBuf ); + if (sp->skeep_validation ) dropSession( ptr->session_id ); + return rv; + } else { + LOG_ERROR( "Report DB is closed!"); }; return false; }; @@ -260,6 +291,87 @@ CSTR servaSessionManager::getSessionBase( uint64_t sid ){ return NULL; }; +SESSION_DATA *servaSessionManager::reopenSession( uint64_t session_id ){ + SESSION_DATA * tData = NULL; + // No Session -> Create one + tData = m_pDBC->getSessionData( session_id ); + if ( tData ) { + //Reopen just for fun :) + tData->skeep_validation = true; + // Create History Database if not exists + char tBase[MAX_PATH]; + sprintf( tBase, "%s/%d", m_pDbReportBase, tData->track_id ); + if( fileExist( tBase ) == 0 ){ + if (!createAccessibleDir( tBase, STORAGE_DIR_MODE, getUserUid(web_access_user), getUserGid(web_access_group))){ + LOG_ERROR("Cannot create Base Report Dir!"); +#ifdef DEBUG + char tB[1024]; + sprintf( tB, "Dir: %s, UID[%s]: %d GID[%s]: %d", tBase, web_access_user, getUserUid(web_access_user) ,web_access_group, getUserGid(web_access_group) ); + LOG( tB ); +#endif + free( tData ); + return NULL; + }; + }; + REPORT_DIRINFO tRDF; + fillRDF( tData->sts, tRDF ); + + if( checkRDFDir( tBase, tRDF, true, getUserUid(web_access_user), getUserGid(web_access_group), STORAGE_DIR_MODE ) ){ +#ifdef DEBUG + LOG("Connect to Report Database"); +#endif + sprintf( tData->reportVaultPath, "%s/%s/%s/%s", tBase, tRDF.YEAR, tRDF.MONTH, tRDF.DAY ); + //LOG( tData->reportVaultPath ); + char tName[MAX_PATH]; + sprintf( tName, "%s/report.db", tData->reportVaultPath ); + + if( fileExist( tName ) ){ + //Allready have report file + tData->m_pDataReport = new SQLite_Connector(); + if ( tData->m_pDataReport ) { + if( !tData->m_pDataReport->Connect( tName, 0, true) ) { + //Cleanup + delete( tData->m_pDataReport ); + free( tData ); + tData = NULL; + }; + } else { + free( tData ); + tData = NULL; + }; + } else { +#ifdef DEBUG + LOG("Create New Report Database"); +#endif + //Create new report file + tData->m_pDataReport = new SQLite_Connector(); + if ( tData->m_pDataReport ) { + if( tData->m_pDataReport->Connect( tName, 0, true) ) { + chown( tName, getUserUid(web_access_user), getUserGid(web_access_group) ); + chmod( tName, DB_FILE_MODE ); + tData->m_pDataReport->SilentQuery("CREATE TABLE IF NOT EXISTS \"events\" ( \"id\" INTEGER NOT NULL, \"session_id\" INTEGER NOT NULL, \"module_id\" INTEGER NOT NULL, \"ts\" INTEGER NOT NULL, \"ts_ms\" INTEGER NOT NULL, \"evt_type\" INTEGER NOT NULL, \"azimuth\" REAL, \"elevation\" REAL, \"range\" REAL, \"area\" REAL, PRIMARY KEY(\"id\" AUTOINCREMENT) )"); + tData->m_pDataReport->SilentQuery("CREATE TABLE IF NOT EXISTS \"videos\" ( \"id\" INTEGER NOT NULL, \"session_id\" INTEGER NOT NULL, \"module_id\" INTEGER NOT NULL, \"uuid\" TEXT NOT NULL UNIQUE, \"ts\" INTEGER NOT NULL, \"ts_ms\" INTEGER NOT NULL, \"ext\" TEXT NOT NULL, \"fps\" INTEGER NOT NULL, PRIMARY KEY(\"id\" AUTOINCREMENT) )"); + } else { + //Cleanup + delete( tData->m_pDataReport ); + free( tData ); + tData = NULL; + }; + } else { + free( tData ); + tData = NULL; + }; + }; + } else { + LOG_ERROR("The report Vault Dir can not be accessed!"); + free( tData ); + tData = NULL; + }; + } else return NULL; + if ( tData ) m_mSessions[tData->track_id] = tData; + return tData; +}; + SESSION_DATA *servaSessionManager::updateSession( uint32_t tack_id, uint32_t module_id ){ SESSION_DATA * tData = NULL; try { @@ -386,13 +498,16 @@ bool servaSessionManager::validate(){ sprintf( tB, "Validation %d %d %d", cts, (*idx).second->lts, m_nSessionTO ); LOG( tB ); #endif - if( cts - (*idx).second->lts > m_nSessionTO ){ - // Expire Session - m_pDBC->updateSessionStatus( (*idx).second->db_id, 1 ); - // Set Session to remove - dE = idx; - bMustDelete = true; - }; + if ( !(*idx).second->skeep_validation ) { + if (cts - (*idx).second->lts > m_nSessionTO) { + // Expire Session + //m_pDBC->updateSessionStatus( (*idx).second->db_id, 1 ); + m_pDBC->sessionClose( (*idx).second->db_id ); + // Set Session to remove + dE = idx; + bMustDelete = true; + }; + } }; }; if ( bMustDelete ) { @@ -408,4 +523,24 @@ bool servaSessionManager::validate(){ SESSION_DATA *servaSessionManager::validateSession( uint64_t sid ){ for( M_SESSIONS::iterator idx = m_mSessions.begin(); idx != m_mSessions.end(); idx++ ) if( (*idx).second->db_id == sid ) return (*idx).second; return NULL; +}; + +bool servaSessionManager::dropSession( uint64_t session_id ){ + M_SESSIONS::iterator dE; + bool bMustDelete = false; + for( M_SESSIONS::iterator idx = m_mSessions.begin(); idx != m_mSessions.end(); idx++ ){ + if ( (*idx).second ) { + if( (*idx).second->db_id == session_id ) { + bMustDelete = true; + break; + }; + }; + }; + if ( bMustDelete ) { + // Remove Session + delete( (*dE).second->m_pDataReport ); + free( (*dE).second ); + (*dE).second = NULL; + m_mSessions.erase( dE ); + }; }; \ No newline at end of file diff --git a/lib/App/serva/servaSessionManager.h b/lib/App/serva/servaSessionManager.h index 4c22bf02..33db4742 100644 --- a/lib/App/serva/servaSessionManager.h +++ b/lib/App/serva/servaSessionManager.h @@ -13,20 +13,6 @@ #define DEFAULT_SESSION_TIMEOUT 120 // 2 minutes -typedef struct S_SESSION_DATA{ - uint32_t track_id; - uint64_t db_id; - char uuid[65]; - uint32_t sts; - uint32_t sms; - uint32_t lts; - uint8_t src; - char reportVaultPath[MAX_PATH]; - SQLite_Connector * m_pDataReport; -}SESSION_DATA; - -typedef std::unordered_map< uint32_t, SESSION_DATA* > M_SESSIONS; - class servaSessionManager{ private: basicLogCollection * m_pLog; @@ -40,6 +26,8 @@ class servaSessionManager{ char web_access_group[64]; char m_pDbReportBase[MAX_PATH]; bool addEvent( SESSION_DATA *sp, ARGUS_DATA_EVENT *ptr ); //DBC_EVT_RECORD *ptr ); + SESSION_DATA * reopenSession( uint64_t session_id ); + bool dropSession( uint64_t session_id ); protected: explicit servaSessionManager( config_setting_t * Settings ); public: diff --git a/lib/data/transport/transportSocket.cpp b/lib/data/transport/transportSocket.cpp index 84d9fc85..8f02e6cb 100644 --- a/lib/data/transport/transportSocket.cpp +++ b/lib/data/transport/transportSocket.cpp @@ -57,11 +57,25 @@ bool transportSocket::create( void ){ bool transportSocket::_close( void ){ setConnectionStatus( CS_DISCONNECTED ); - if( m_iControlPipeFD[0] > -1 ) write( m_iControlPipeFD[0], "E", 1 ); - if( m_iControlPipeFD[1] > -1 ) write( m_iControlPipeFD[1], "E", 1 ); + LOG("Sending Close Req!"); + if( m_iControlPipeFD[0] > -1 ){ + LOG("Sending Close Req[1]!"); + write( m_iControlPipeFD[0], "E", 1 ); + }; + if( m_iControlPipeFD[1] > -1 ){ + LOG("Sending Close Req[2]!"); + write( m_iControlPipeFD[1], "E", 1 ); + }; if( m_bInitComplete ) m_bInitComplete = !uninit(); - if ( m_iControlPipeFD[0] > -1 ) close( m_iControlPipeFD[0] ); - if ( m_iControlPipeFD[1] > -1 ) close( m_iControlPipeFD[1] ); + LOG("Closeing FIDs!"); + if ( m_iControlPipeFD[0] > -1 ){ + LOG("Closeing FIDs[1]!"); + close( m_iControlPipeFD[0] ); + }; + if ( m_iControlPipeFD[1] > -1 ){ + LOG("Closeing FIDs[2]!"); + close( m_iControlPipeFD[1] ); + }; return true; }; @@ -163,7 +177,7 @@ void transportSocket::m_fThreadBProc(void){ setConnectionStatus(CS_DISCONNECTED); m_nInputBufferSize = 0; m_bThreadBStatus = TH_ENDED; - m_bThreadAStatus = TH_ENDED; + //m_bThreadAStatus = TH_ENDED; LOG_ERROR("Connection Droped on Reception Data"); } else if( m_nInputBufferSize > 0 ){ do{