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.
895 lines
34 KiB
895 lines
34 KiB
#include "rgooseDBConnector.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "ADBC", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "ADBC", this, _LOG_ERROR, X )
|
|
|
|
ARGUS_DBC::ARGUS_DBC( config_setting_t * Settings ){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DBC" );
|
|
m_bIsConnected = false;
|
|
m_pDatabase = NULL;
|
|
};
|
|
|
|
ARGUS_DBC::~ARGUS_DBC(){
|
|
};
|
|
|
|
bool ARGUS_DBC::connect( void ){
|
|
config_setting_t * tSetting;
|
|
m_bIsConnected = false;
|
|
if( m_pSettings!= NULL ) {
|
|
tSetting = config_setting_get_member( m_pSettings, "DATABASE_HOST" );
|
|
if( tSetting == NULL ){
|
|
tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING );
|
|
config_setting_set_string( tSetting, "localhost" );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("No DB Host Setting! Using default!");
|
|
};
|
|
sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
|
|
tSetting = config_setting_get_member( m_pSettings, "DATABASE_NAME" );
|
|
if( tSetting == NULL ){
|
|
tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING );
|
|
config_setting_set_string( tSetting, "dfsl_gunter" );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("No DB Database Setting! Using default!");
|
|
};
|
|
sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting));
|
|
tSetting = config_setting_get_member( m_pSettings, "DATABASE_USER" );
|
|
if( tSetting == NULL ){
|
|
tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING );
|
|
config_setting_set_string( tSetting, "dbroot" );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("No DB User Setting! Using default!");
|
|
};
|
|
sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting));
|
|
tSetting = config_setting_get_member( m_pSettings, "DATABASE_PASSWORD" );
|
|
if( tSetting == NULL ){
|
|
tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING );
|
|
config_setting_set_string( tSetting, "123567" );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("No DB Password Setting! Using default!");
|
|
};
|
|
sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting));
|
|
basicSettingsProvider::getInstance()->validate();
|
|
m_pDatabase = new MySQL_Connector();
|
|
if( m_pDatabase == NULL )return false;
|
|
m_bIsConnected = m_pDatabase->Connect( m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword );
|
|
} else {
|
|
LOG_ERROR("No Settings Provided!");
|
|
};
|
|
return m_bIsConnected;
|
|
};
|
|
|
|
bool ARGUS_DBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){
|
|
if(m_bIsConnected) {
|
|
char tQBuf[MAX_PATH_LEN];
|
|
char tIpBuf[CTEXT];
|
|
char *tPos;
|
|
char *tPos2;
|
|
LOG("Cam Update");
|
|
tPos = strstr(Addr,"//");
|
|
if( tPos != NULL ) {
|
|
tPos2 = strstr( tPos + 2,"/");
|
|
if( tPos2 != NULL ) {
|
|
int len;
|
|
len = tPos2 - tPos - 2;
|
|
strncpy(tIpBuf,tPos + 2,len);
|
|
tIpBuf[len] = (char)0;
|
|
} else {
|
|
LOG("Pos 2 - err");
|
|
tIpBuf[0] = (char)0;
|
|
};
|
|
} else {
|
|
LOG("Pos 0 - err");
|
|
tIpBuf[0] = (char)0;
|
|
};
|
|
sprintf(tQBuf,"INSERT INTO cameras SET `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d ON DUPLICATE KEY UPDATE `onvif_ctrl`='%s', `ip`='%s'",
|
|
uuid,
|
|
Addr,
|
|
tIpBuf,
|
|
SiteID,
|
|
Addr,
|
|
tIpBuf
|
|
);
|
|
LOG(tQBuf);
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool ARGUS_DBC::updateIPCam( uint32_t SiteID, resultWoWo *tPtr ){
|
|
if(m_bIsConnected) {
|
|
char tQBuf[MAX_PATH_LEN];
|
|
char tIpBuf[CTEXT];
|
|
char *tPos;
|
|
char *tPos2;
|
|
LOG("Cam Update WoWo");
|
|
tPos = strstr(tPtr->XAddrs,"//");
|
|
if( tPos != NULL ) {
|
|
tPos2 = strstr( tPos + 2,"/");
|
|
if( tPos2 != NULL ) {
|
|
int len;
|
|
len = tPos2 - tPos - 2;
|
|
strncpy(tIpBuf,tPos + 2,len);
|
|
tIpBuf[len] = (char)0;
|
|
} else {
|
|
LOG("Pos 2 - err");
|
|
tIpBuf[0] = (char)0;
|
|
};
|
|
} else {
|
|
LOG("Pos 0 - err");
|
|
tIpBuf[0] = (char)0;
|
|
};
|
|
sprintf(tQBuf,"INSERT INTO cameras SET `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s' ON DUPLICATE KEY UPDATE `onvif_ctrl`='%s', `ip`='%s'",
|
|
tPtr->RefID,
|
|
tPtr->XAddrs,
|
|
tIpBuf,
|
|
SiteID,
|
|
tPtr->MAC,
|
|
tPtr->Hardware,
|
|
tPtr->Name,
|
|
tPtr->XAddrs,
|
|
tIpBuf
|
|
);
|
|
LOG(tQBuf);
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool ARGUS_DBC::transferEvtToArchive( uint32_t SECONDS ){
|
|
if(m_bIsConnected) {
|
|
if( SECONDS > 0 ) {
|
|
char tQBuf[CTEXT];
|
|
sprintf(tQBuf,"INSERT INTO events_archive ( SELECT * FROM events_cloud ec WHERE ec.ts < ( UNIX_TIMESTAMP(NOW()) - %d ) ); DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - %d );", SECONDS, SECONDS );
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
bool ARGUS_DBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT * FROM events_cloud WHERE `ts`>%d AND `ts_ms`>%d", tss, tsms );
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
EventRecordDBC *tPtr;
|
|
Assoc *cArr;
|
|
for(int i=0;i<result->size();i++) {
|
|
cArr = result->at(i);
|
|
tPtr = (EventRecordDBC*)malloc(sizeof(EventRecordDBC));
|
|
if( tPtr!= NULL ) {
|
|
Assoc::iterator it;
|
|
memset(tPtr,0,sizeof(EventRecordDBC));
|
|
it = cArr->find("ts");
|
|
if( it != cArr->end() ){
|
|
tPtr->ts_s = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("ts_ms");
|
|
if( it != cArr->end() ){
|
|
tPtr->ts_ms = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("evt_type");
|
|
if( it != cArr->end() ){
|
|
tPtr->type = atoi( it->second.c_str() );
|
|
};
|
|
char tBuf[CLOG];
|
|
sprintf(tBuf,"Evt: %d %d %d", tPtr->type, tPtr->ts_s, tPtr->ts_ms );
|
|
LOG(tBuf);
|
|
VR.push_back(tPtr);
|
|
};
|
|
delete(cArr);
|
|
};
|
|
//result->clear();
|
|
//delete(result);
|
|
};
|
|
deleteResult( result );
|
|
if( m_pDatabase->isConnected()) return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool ARGUS_DBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT * FROM cameras WHERE `site_id`=%d AND `type`=2 AND `status`=2", SiteID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
DBC_CAM_DATA *tVal;
|
|
Assoc *cArr;
|
|
for(int i=0;i<result->size();i++) {
|
|
LOG("Cam_Record!");
|
|
cArr = result->at(i);
|
|
tVal = (DBC_CAM_DATA*)malloc(sizeof(DBC_CAM_DATA));
|
|
if( tVal!= NULL ) {
|
|
Assoc::iterator it;
|
|
memset(tVal,0,sizeof(DBC_CAM_DATA));
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
tVal->id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("enabled");
|
|
if( it != cArr->end() ){
|
|
tVal->enabled = (bool) atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("online");
|
|
if( it != cArr->end() ){
|
|
tVal->online = (bool) atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("type");
|
|
if( it != cArr->end() ){
|
|
tVal->type = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("caps");
|
|
if( it != cArr->end() ){
|
|
tVal->caps = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("status");
|
|
if( it != cArr->end() ){
|
|
tVal->status = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("protocol");
|
|
if( it != cArr->end() ){
|
|
tVal->protocol = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("lat");
|
|
if( it != cArr->end() ){
|
|
tVal->lat = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("lon");
|
|
if( it != cArr->end() ){
|
|
tVal->lon = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("alt");
|
|
if( it != cArr->end() ){
|
|
tVal->alt = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("picth");
|
|
if( it != cArr->end() ){
|
|
tVal->pitch = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("roll");
|
|
if( it != cArr->end() ){
|
|
tVal->roll = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("yaw");
|
|
if( it != cArr->end() ){
|
|
tVal->yaw = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("min_f");
|
|
if( it != cArr->end() ){
|
|
tVal->min_f = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("max_f");
|
|
if( it != cArr->end() ){
|
|
tVal->max_f = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("imager_size");
|
|
if( it != cArr->end() ){
|
|
tVal->imager_size = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("imager_ratio");
|
|
if( it != cArr->end() ){
|
|
tVal->imager_ratio = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("uuid");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->uuid, it->second.c_str(), CLOG );
|
|
};
|
|
it = cArr->find("port");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->port, it->second.c_str(), 5 );
|
|
};
|
|
it = cArr->find("ip");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->ip, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("hardware");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->hardware, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("session");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->session, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("access_login");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->username, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("access_pass");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->password, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("name");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->name, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("onvif_ctrl");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->onvif_ctrl, it->second.c_str(), 16 );
|
|
};
|
|
VR.push_back(tVal);
|
|
};
|
|
delete(cArr);
|
|
};
|
|
//result->clear();
|
|
//delete(result);
|
|
};
|
|
deleteResult( result );
|
|
sprintf( tQBuf,"Now %d Camera Records in System", VR.size());
|
|
LOG(tQBuf);
|
|
if( m_pDatabase->isConnected()) return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
|
|
DBC_INT_LIST *ARGUS_DBC::listNodes( uint32_t SiteID ){
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0", SiteID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
for(int i=0;i<result->size();i++) {
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
tVal->push_back( atoi( it->second.c_str() ));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_INT_LIST *ARGUS_DBC::listNewNodes( uint32_t SiteID, DBC_INT_LIST *old_ids ){
|
|
DBC_INT_LIST * tVal = NULL;
|
|
char tParam[CTEXT];
|
|
//memset( tParam, 0, CTEXT );
|
|
sprintf(tParam,"0");
|
|
if( old_ids != NULL ) {
|
|
char tBuffer[CTEXT];
|
|
for(int i = 0; i< old_ids->size(); i++ ) {
|
|
sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
|
|
strncpy( tParam, tBuffer, CTEXT );
|
|
};
|
|
};
|
|
if( m_bIsConnected ){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, tParam );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
for(int i=0;i<result->size();i++) {
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
tVal->push_back( atoi( it->second.c_str() ));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
|
|
DBC_NODE_DATA *ARGUS_DBC::getNodeData( uint32_t ID ){
|
|
DBC_NODE_DATA * tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
tVal->node_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("type");
|
|
if( it != cArr->end() ){
|
|
tVal->type = (ARGUS_NODE_TYPE) atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("aux_id");
|
|
if( it != cArr->end() ){
|
|
tVal->aux_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("name");
|
|
if( it != cArr->end() ){
|
|
sprintf( tVal->name, it->second.c_str() );
|
|
};
|
|
it = cArr->find("ts_s");
|
|
if( it != cArr->end() ){
|
|
tVal->tss = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("ts_ms");
|
|
if( it != cArr->end() ){
|
|
tVal->tsm = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("online");
|
|
if( it != cArr->end() ){
|
|
tVal->online = (bool)atoi( it->second.c_str() );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_INT_LIST *ARGUS_DBC::listModules( uint32_t ServerID ){
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT id FROM server_modules WHERE `server_id`=%d", ServerID );
|
|
#ifdef DEBUG
|
|
//LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
for(int i=0;i<result->size();i++) {
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
tVal->push_back( atoi( it->second.c_str() ));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_INT_LIST *ARGUS_DBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ){
|
|
DBC_INT_LIST * tVal = NULL;
|
|
char tParam[CTEXT];
|
|
//memset( tParam, 0, CTEXT );
|
|
sprintf(tParam,"0");
|
|
if( old_ids != NULL ) {
|
|
char tBuffer[CTEXT];
|
|
for(int i = 0; i< old_ids->size(); i++ ) {
|
|
sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
|
|
strncpy( tParam, tBuffer, CTEXT );
|
|
};
|
|
};
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT id FROM server_modules WHERE `server_id`=%d AND `id` NOT IN (%s)", ServerID, tParam );
|
|
#ifdef DEBUG
|
|
//LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
for(int i=0;i<result->size();i++) {
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
tVal->push_back( atoi( it->second.c_str() ));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_CAM_DATA *ARGUS_DBC::getCamData( uint32_t ID ){
|
|
DBC_CAM_DATA *tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
|
|
if( tVal != NULL ) {
|
|
memset( tVal, 0 , sizeof(DBC_CAM_DATA));
|
|
tVal->id = ID;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("enabled");
|
|
if( it != cArr->end() ){
|
|
tVal->enabled = (bool) atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("online");
|
|
if( it != cArr->end() ){
|
|
tVal->online = (bool) atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("type");
|
|
if( it != cArr->end() ){
|
|
tVal->type = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("caps");
|
|
if( it != cArr->end() ){
|
|
tVal->caps = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("status");
|
|
if( it != cArr->end() ){
|
|
tVal->status = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("protocol");
|
|
if( it != cArr->end() ){
|
|
tVal->protocol = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("lat");
|
|
if( it != cArr->end() ){
|
|
tVal->lat = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("lon");
|
|
if( it != cArr->end() ){
|
|
tVal->lon = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("alt");
|
|
if( it != cArr->end() ){
|
|
tVal->alt = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("picth");
|
|
if( it != cArr->end() ){
|
|
tVal->pitch = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("roll");
|
|
if( it != cArr->end() ){
|
|
tVal->roll = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("yaw");
|
|
if( it != cArr->end() ){
|
|
tVal->yaw = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("min_f");
|
|
if( it != cArr->end() ){
|
|
tVal->min_f = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("max_f");
|
|
if( it != cArr->end() ){
|
|
tVal->max_f = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("imager_size");
|
|
if( it != cArr->end() ){
|
|
tVal->imager_size = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("imager_ratio");
|
|
if( it != cArr->end() ){
|
|
tVal->imager_ratio = atof( it->second.c_str() );
|
|
};
|
|
it = cArr->find("uuid");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->uuid, it->second.c_str(), CLOG );
|
|
};
|
|
it = cArr->find("port");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->port, it->second.c_str(), 5 );
|
|
};
|
|
it = cArr->find("ip");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->ip, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("hardware");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->hardware, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("session");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->session, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("access_login");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->username, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("access_pass");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->password, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("name");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->name, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("onvif_ctrl");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->onvif_ctrl, it->second.c_str(), 16 );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_MODULE_DATA *ARGUS_DBC::getModuleData( uint32_t ID ){
|
|
DBC_MODULE_DATA *tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
tVal->module_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("aux_id");
|
|
if( it != cArr->end() ){
|
|
tVal->aux_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("type");
|
|
if( it != cArr->end() ){
|
|
tVal->type = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("enabled");
|
|
if( it != cArr->end() ){
|
|
tVal->enabled = (bool)atoi( it->second.c_str() );
|
|
};
|
|
};
|
|
//result->clear();
|
|
};
|
|
//delete( result );
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_MEDIA_SERVER_DATA *ARGUS_DBC::getMediaServerData( uint32_t ID ){
|
|
DBC_MEDIA_SERVER_DATA *tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
tVal->id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("secret_key");
|
|
if( it != cArr->end() ){
|
|
sprintf( tVal->key, it->second.c_str() );
|
|
};
|
|
it = cArr->find("ip");
|
|
if( it != cArr->end() ){
|
|
sprintf( tVal->ip, it->second.c_str() );
|
|
};
|
|
it = cArr->find("REST_port");
|
|
if( it != cArr->end() ){
|
|
tVal->port = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("virtual_host");
|
|
if( it != cArr->end() ){
|
|
sprintf( tVal->host, it->second.c_str() );
|
|
};
|
|
it = cArr->find("recording");
|
|
if( it != cArr->end() ){
|
|
tVal->recording = (bool)atoi( it->second.c_str() );
|
|
};
|
|
sprintf( tVal->name,"ZLMedia_%d", tVal->id );
|
|
};
|
|
//result->clear();
|
|
};
|
|
//delete( result );
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
void ARGUS_DBC::registerServer(uint32_t SiteID, CSTR identity ){
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
sprintf(tQBuf,"INSERT INTO servers SET `site_id`=%d, `identity`='%s', `online`=1 ON DUPLICATE KEY UPDATE `online`=1", SiteID, identity );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
|
|
uint32_t sid = getServerID( identity );
|
|
if( sid ) {
|
|
sprintf(tQBuf,"INSERT INTO nodes SET `site_id`=%d, `aux_id`='%d', `type`= 0, `online`=1, `name`='Server Node' ON DUPLICATE KEY UPDATE `online`=1", SiteID, sid );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
};
|
|
};
|
|
};
|
|
|
|
void ARGUS_DBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
sprintf(tQBuf,"UPDATE servers SET `online`=0 WHERE `id` = %d", ServerID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
setNodeOffline( NodeID );
|
|
};
|
|
};
|
|
|
|
void ARGUS_DBC::setNodeOnline( uint32_t NodeID ){
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
if( NodeID ) {
|
|
sprintf(tQBuf,"UPDATE nodes SET `online`=1 WHERE `id` = %d", NodeID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
sprintf(tQBuf,"UPDATE sockets SET `state`=1 WHERE `node_id` = %d", NodeID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
};
|
|
};
|
|
};
|
|
|
|
void ARGUS_DBC::setNodeOffline( uint32_t NodeID ){
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
if( NodeID ) {
|
|
sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
sprintf(tQBuf,"UPDATE sockets SET `state`=0 WHERE `node_id` = %d", NodeID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
};
|
|
};
|
|
};
|
|
|
|
uint32_t ARGUS_DBC::getServerID( CSTR identity ){
|
|
uint32_t RetVal = 0;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
AAssoc *result;
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
RetVal = atoi( it->second.c_str() );
|
|
};
|
|
//result->clear();
|
|
};
|
|
//delete( result );
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return RetVal;
|
|
};
|
|
|
|
uint32_t ARGUS_DBC::getServerNode( uint32_t SID ){
|
|
uint32_t RetVal = 0;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
AAssoc *result;
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
RetVal = atoi( it->second.c_str() );
|
|
};
|
|
//result->clear();
|
|
};
|
|
//delete( result );
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return RetVal;
|
|
};
|
|
|
|
void ARGUS_DBC::addNodeSocket( uint32_t NodeID, uint8_t SocketType, CSTR path, CSTR name ){
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
CSTR tMD5;
|
|
tMD5 = MD5String( path );
|
|
sprintf(tQBuf,"INSERT INTO sockets SET `node_id`=%d, `type`=%d, `md5`='%s', `path`='%s', `state`=1, `name`='%s' ON DUPLICATE KEY UPDATE `state`=1, `name`='%s'",
|
|
NodeID, SocketType, tMD5, path, name, name );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
free( tMD5 );
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
};
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|