diff --git a/Projects/la_serva/build b/Projects/la_serva/build index 8d62327c..7efee7e2 100755 --- a/Projects/la_serva/build +++ b/Projects/la_serva/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/serverMySQL_dataBinder.cpp b/lib/App/common/serverMySQL_dataBinder.cpp index e3570dea..75281071 100644 --- a/lib/App/common/serverMySQL_dataBinder.cpp +++ b/lib/App/common/serverMySQL_dataBinder.cpp @@ -692,13 +692,17 @@ DBC_UINT64_LIST *servaMySQLDBC::listMediaQueueItems( uint8_t status ){ bool servaMySQLDBC::putIntoLog( CSTR A, CSTR B, CSTR C ){ if( m_bIsConnected ){ - char tQBuf[MAX_PATH_LEN]; - sprintf( tQBuf, "INSERT INTO `server_log_messages` SET lvl = '%s', `ts`='%s', `msg`='%s'", A, B, C ); + char tQBuf[MAX_PATH_LEN]; + CSTR LL = m_pDatabase->escapeString( C ); + if ( LL ) { + sprintf(tQBuf, "INSERT INTO `server_log_messages` SET lvl = '%s', `ts`='%s', `msg`='%s'", A, B, LL ); + free( LL ); #ifdef DEBUG_ALL - LOG(tQBuf); + LOG(tQBuf); #endif - m_pDatabase->SilentQuery( tQBuf ); - return true; + m_pDatabase->SilentQuery( tQBuf ); + return true; + }; }; return false; }; @@ -898,9 +902,8 @@ bool servaMySQLDBC::sessionClose( uint64_t session_id ){ uint64_t servaMySQLDBC::sessionCreate( uint64_t track_id, uint32_t ts, uint16_t tsms, CSTR uuid, char src ){ if( m_bIsConnected ){ char tQBuf[CTEXT]; - sprintf(tQBuf, "INSERT INTO `sessions` SET `ts`=%d, `ts_ms`=%d, `lts`=UNIX_TIMESTAMP(now()), `track_id`=%" PRIu64 ", `src`='%c', `uuid`='%s'", - ts, tsms, - track_id, src, uuid ); + sprintf( tQBuf, "INSERT INTO `sessions` SET `ts`=%d, `ts_ms`=%d, `lts`=UNIX_TIMESTAMP(now()), `track_id`=%" PRIu64 ", `uuid`='%s', `src`='%c'", + ts, tsms, track_id, uuid, src ); #ifdef DEBUG LOG(tQBuf); #endif diff --git a/lib/App/serva/servaKernelToolKit.cpp b/lib/App/serva/servaKernelToolKit.cpp index 5167a310..ed6e34b5 100644 --- a/lib/App/serva/servaKernelToolKit.cpp +++ b/lib/App/serva/servaKernelToolKit.cpp @@ -198,8 +198,13 @@ bool servaKernel::updateStatus(){ tid = m_pDBC->getSessionOldest( m_sServaConfig.historyAutoDeleteLimit ); }; if ( tid ) { +#ifdef DEBUG_EXTRA LOG("Need to Delete some Sessions!"); +#endif m_pSM->eraseSession( tid ); +#ifdef DEBUG_EXTRA + LOG("Delete Session Done!"); +#endif }; #ifdef DEBUG_EXTRA } else { @@ -213,8 +218,13 @@ bool servaKernel::updateStatus(){ uint32_t cts = time( NULL ) - (m_sServaConfig.historyDaysLimit * 86400); uint64_t tid = m_pDBC->getSessionOlderThan( cts, m_sServaConfig.historyAutoDeleteLimit ); if ( tid ) { +#ifdef DEBUG_EXTRA LOG("Need to Delete some Sessions!"); +#endif m_pSM->eraseSession( tid ); +#ifdef DEBUG_EXTRA + LOG("Delete Session Done!"); +#endif }; #ifdef DEBUG_EXTRA } else { diff --git a/lib/App/serva/servaRemoteClient.cpp b/lib/App/serva/servaRemoteClient.cpp index 614d012f..90a9bf73 100644 --- a/lib/App/serva/servaRemoteClient.cpp +++ b/lib/App/serva/servaRemoteClient.cpp @@ -27,7 +27,9 @@ servaRemoteClient::servaRemoteClient( servaKernel *ptr ):networkServiceEngine(), }; servaRemoteClient::~servaRemoteClient(){ + LOG("Destructor Start"); waitThreadEnd( true ); + LOG("Destructor End"); }; networkClientHandler *servaRemoteClient::attachNewClient( int SocketID, void *ptr ){ diff --git a/lib/App/serva/servaSessionManager.cpp b/lib/App/serva/servaSessionManager.cpp index ea1310f9..ba5dacba 100644 --- a/lib/App/serva/servaSessionManager.cpp +++ b/lib/App/serva/servaSessionManager.cpp @@ -327,7 +327,7 @@ SESSION_DATA *servaSessionManager::reopenSession( uint64_t session_id ){ if( checkRDFDir( tBase, tRDF, true, getUserUid(web_access_user), getUserGid(web_access_group), STORAGE_DIR_MODE ) ){ #ifdef DEBUG - LOG("Connect to Report Database"); + LOG("Connect to Report Database RS"); #endif sprintf( tData->reportVaultPath, "%s/%s/%s/%s", tBase, tRDF.YEAR, tRDF.MONTH, tRDF.DAY ); //LOG( tData->reportVaultPath ); @@ -339,12 +339,13 @@ SESSION_DATA *servaSessionManager::reopenSession( uint64_t session_id ){ tData->m_pDataReport = new SQLite_Connector(); if ( tData->m_pDataReport ) { if( !tData->m_pDataReport->Connect( tName, 0, true) ) { - //Cleanup + LOG_ERROR("Cannot Connect to RDB!"); delete( tData->m_pDataReport ); free( tData ); tData = NULL; }; } else { + LOG_ERROR("Cannot Create Connector to RDB!"); free( tData ); tData = NULL; }; @@ -361,12 +362,13 @@ SESSION_DATA *servaSessionManager::reopenSession( uint64_t session_id ){ 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 + LOG_ERROR("Cannot Connect to RDB!"); delete( tData->m_pDataReport ); free( tData ); tData = NULL; }; } else { + LOG_ERROR("Cannot Create Connector to RDB!"); free( tData ); tData = NULL; }; @@ -376,8 +378,12 @@ SESSION_DATA *servaSessionManager::reopenSession( uint64_t session_id ){ free( tData ); tData = NULL; }; - } else return NULL; - if ( tData ) m_mSessions[tData->track_id] = tData; + }; + + if ( tData ){ + LOG("Assign Session To Vector!"); + m_mSessions[tData->track_id] = tData; + }; return tData; }; @@ -419,10 +425,10 @@ SESSION_DATA *servaSessionManager::updateSession( uint64_t tack_id, uint64_t mod if( checkRDFDir( tBase, tRDF, true, getUserUid(web_access_user), getUserGid(web_access_group), STORAGE_DIR_MODE ) ){ #ifdef DEBUG - LOG("Connect to Report Database"); + LOG("Connect to Report Database US"); #endif sprintf( tData->reportVaultPath, "%s/%s/%s/%s", tBase, tRDF.YEAR, tRDF.MONTH, tRDF.DAY ); - //LOG( tData->reportVaultPath ); + LOG( tData->reportVaultPath ); char tName[MAX_PATH]; sprintf( tName, "%s/report.db", tData->reportVaultPath ); @@ -431,12 +437,13 @@ SESSION_DATA *servaSessionManager::updateSession( uint64_t tack_id, uint64_t mod tData->m_pDataReport = new SQLite_Connector(); if ( tData->m_pDataReport ) { if( !tData->m_pDataReport->Connect( tName, 0, true) ) { - //Cleanup + LOG_ERROR("Cannot Connect to RDB!"); delete( tData->m_pDataReport ); free( tData ); tData = NULL; }; } else { + LOG_ERROR("Cannot Create Connector to RDB!"); free( tData ); tData = NULL; }; @@ -453,12 +460,13 @@ SESSION_DATA *servaSessionManager::updateSession( uint64_t tack_id, uint64_t mod 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 + LOG_ERROR("Cannot Connect to RDB!"); delete( tData->m_pDataReport ); free( tData ); tData = NULL; }; } else { + LOG_ERROR("Cannot Create Connector to RDB!"); free( tData ); tData = NULL; }; @@ -468,12 +476,14 @@ SESSION_DATA *servaSessionManager::updateSession( uint64_t tack_id, uint64_t mod free( tData ); tData = NULL; }; - } else return NULL; + } else { + LOG_ERROR("Cannot Allocate Session Data [malloc]!"); + }; if ( tData ) { - //module_id?? + //LOG("All Seems to be good!"); tData->db_id = m_pDBC->sessionCreate( tData->track_id, tData->sts, tData->sms, tData->uuid, 'A' ); if ( tData->db_id == 0 ) { - //Cleanup + LOG_ERROR("Cannot Create Session!"); delete( tData->m_pDataReport ); free( tData ); tData = NULL; @@ -516,7 +526,7 @@ bool servaSessionManager::validate(){ dE = idx; bMustDelete = true; }; - } + }; }; }; if ( bMustDelete ) { @@ -530,13 +540,17 @@ 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; + 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; +#ifdef DEBUG_EXTRA + LOG("Drop Session!"); +#endif for( M_SESSIONS::iterator idx = m_mSessions.begin(); idx != m_mSessions.end(); idx++ ){ if ( (*idx).second ) { if( (*idx).second->db_id == session_id ) { @@ -559,9 +573,9 @@ bool servaSessionManager::dropSession( uint64_t session_id ){ bool servaSessionManager::eraseSession( uint64_t session_id ){ //Erase just not important sessions // In case The session is Opened! - +#ifdef DEBUG_EXTRA LOG("Eraze Session!"); - +#endif dropSession( session_id ); SESSION_DATA * tData = m_pDBC->getSessionData( session_id ); if ( tData ) { @@ -571,9 +585,9 @@ bool servaSessionManager::eraseSession( uint64_t session_id ){ REPORT_DIRINFO tRDF; fillRDF( tData->sts, tRDF ); sprintf( tData->reportVaultPath, "%s/%s/%s/%s", tBase, tRDF.YEAR, tRDF.MONTH, tRDF.DAY ); - +#ifdef DEBUG_EXTRA LOG( tData->reportVaultPath ); - +#endif if( fileExist( tData->reportVaultPath ) ){ char tName[MAX_PATH]; sprintf( tName, "%s/report.db", tData->reportVaultPath ); @@ -584,15 +598,13 @@ bool servaSessionManager::eraseSession( uint64_t session_id ){ if( tData->m_pDataReport->Connect( tName, 0, true) ) { char tB[1024]; sprintf( tB, "DELETE FROM `events` WHERE `session_id`=%"PRIu64 , session_id ); - LOG( tB ); tData->m_pDataReport->SilentQuery( tB ); sprintf( tB, "SELECT `uuid`, `ext` FROM `videos` WHERE `session_id`=%"PRIu64 , session_id ); - LOG( tB ); AAssoc *result = tData->m_pDataReport->Query( tB ); - if( result!= NULL ) { + if( result != NULL ) { if( result->size() > 0 ) { Assoc * cArr; - for ( uint8_t idx = 0; idx < result->size(); idx++ ) { + for ( uint16_t idx = 0; idx < result->size(); idx++ ) { Assoc::iterator it; char fN[MAX_PATH], uA[65], uX[6]; cArr = result->at(idx); @@ -603,21 +615,29 @@ bool servaSessionManager::eraseSession( uint64_t session_id ){ }; it = cArr->find("ext"); if( it != cArr->end() ){ - strncpy( uX, it->second.c_str(), 6 ); + strncpy( uX, it->second.c_str(), 5 ); uX[5]=(char)0; }; sprintf( fN,"%s/%s.%s", tData->reportVaultPath, uA, uX ); - if( fileExist( fN ) ) unlink( fN ); + if( fileExist( fN ) ) { +#ifdef DEBUG_EXTRA + LOG("Deleting ..."); +#endif + unlink( fN ); +#ifdef DEBUG_EXTRA + LOG("Deleted!"); + } else { + LOG("Not Exists!"); +#endif + }; }; }; deleteResult( result ); }; sprintf( tB, "DELETE FROM `videos` WHERE `session_id`=%"PRIu64 , session_id ); - LOG( tB ); tData->m_pDataReport->SilentQuery( tB ); //Check if still have othes Sessions sprintf( tB, "SELECT count( `id` ) as CNT FROM `events`" ); - LOG( tB ); result = tData->m_pDataReport->Query( tB ); if( result!= NULL ) { if( result->size() > 0 ) { @@ -631,17 +651,21 @@ bool servaSessionManager::eraseSession( uint64_t session_id ){ delete( tData->m_pDataReport ); // close database }; if ( must_unlink ){ +#ifdef DEBUG_EXTRA LOG("Remove Database!"); LOG( tName ); +#endif unlink( tName ); char tCMD[MAX_PATH]; sprintf( tCMD, "rm -R -f %s", tData->reportVaultPath ); +#ifdef DEBUG_EXTRA LOG("Remove Folder!"); LOG( tCMD ); +#endif system( tCMD ); }; } else { - LOG("Report Database Not Found!"); + LOG_ERROR("Report Database Not Found!"); }; }; }; diff --git a/lib/data/sqlite/sqlite_class.cpp b/lib/data/sqlite/sqlite_class.cpp index 45d3703d..e5caf7da 100644 --- a/lib/data/sqlite/sqlite_class.cpp +++ b/lib/data/sqlite/sqlite_class.cpp @@ -137,7 +137,9 @@ bool SQLite_Connector::Connect( CSTR FileName, int AUX_FLAGS, bool Persistent ){ m_mAccessMutex.lock(); m_bPersistentConnection = Persistent; if( m_bIsConnected ){ +#ifdef DEBUG_ALL LOG("Connected -> Disconnect!"); +#endif m_bIsConnected = false; if( m_pDBLink != NULL ){ if( SQLITE_OK != sqlite3_close( m_pDBLink ) ) { @@ -149,9 +151,13 @@ bool SQLite_Connector::Connect( CSTR FileName, int AUX_FLAGS, bool Persistent ){ sprintf( m_pDBName, "%s", FileName ); m_nFLAGS = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | AUX_FLAGS; if( m_bPersistentConnection ){ +#ifdef DEBUG_ALL LOG("Making Connection...."); +#endif if( SQLITE_OK == sqlite3_open_v2( m_pDBName, &m_pDBLink, m_nFLAGS, NULL ) ) m_bIsConnected = true; +#ifdef DEBUG_ALL LOG("Done!"); +#endif } else { m_bIsConnected = true; };