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.
1519 lines
56 KiB
1519 lines
56 KiB
#include "rgooseDBConnector.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "ADBC", this, X )
|
|
|
|
#ifdef DEBUG
|
|
#define LOG_ERROR( X ) {\
|
|
char _tBfrErrMSG2w34[256];\
|
|
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
|
|
m_pLog->Log( "ADBC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
|
|
}
|
|
#else
|
|
#define LOG_ERROR( X ) m_pLog->Log( "ADBC", this, _LOG_ERROR, X );
|
|
#endif
|
|
|
|
argusDBC *argusDBC::_instance = NULL;
|
|
|
|
/**
|
|
* Returns the single instance of the object.
|
|
*/
|
|
argusDBC* argusDBC::getInstance( config_setting_t * Settings ) {
|
|
// check if the instance has been created yet
|
|
if( 0 == _instance ){
|
|
// if not, then create it
|
|
_instance = new argusDBC( Settings );
|
|
};
|
|
// return the single instance
|
|
return _instance;
|
|
};
|
|
|
|
|
|
argusDBC::argusDBC( config_setting_t * Settings ){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DBC" );
|
|
m_bIsConnected = false;
|
|
m_pDatabase = NULL;
|
|
};
|
|
|
|
argusDBC::~argusDBC(){
|
|
};
|
|
|
|
bool argusDBC::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 argusDBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){
|
|
if(m_bIsConnected) {
|
|
char tQBuf[MAX_PATH_LEN];
|
|
char tIpBuf[CTEXT];
|
|
char *tPos;
|
|
char *tPos2;
|
|
#ifdef DEBUG
|
|
LOG("Cam Update");
|
|
#endif
|
|
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_ERROR("Pos 2 - err");
|
|
tIpBuf[0] = (char)0;
|
|
};
|
|
} else {
|
|
LOG_ERROR("Pos 0 - err");
|
|
tIpBuf[0] = (char)0;
|
|
};
|
|
sprintf(tQBuf,"UPDATE cameras SET `online`=1,`onvif_ctrl`='%s', `ip`='%s' WHERE `uuid`='%s' AND `site_id`=%d",
|
|
Addr,
|
|
tIpBuf,
|
|
uuid,
|
|
SiteID
|
|
);
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool argusDBC::updateIPCam( uint32_t SiteID, uint32_t CamID, CSTR Addr ){
|
|
if(m_bIsConnected) {
|
|
char tQBuf[MAX_PATH_LEN];
|
|
char tIpBuf[CTEXT];
|
|
char *tPos;
|
|
char *tPos2;
|
|
#ifdef DEBUG
|
|
LOG("Cam Update");
|
|
#endif
|
|
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_ERROR("Pos 2 - err");
|
|
tIpBuf[0] = (char)0;
|
|
};
|
|
} else {
|
|
LOG_ERROR("Pos 0 - err");
|
|
tIpBuf[0] = (char)0;
|
|
};
|
|
sprintf(tQBuf,"UPDATE cameras SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE id=%d AND `site_id`=%d",
|
|
Addr,
|
|
tIpBuf,
|
|
CamID,
|
|
SiteID
|
|
);
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
sprintf(tQBuf,"UPDATE media_streams SET `valid`=1 WHERE source_id=%d AND source_type='D'", CamID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool argusDBC::addIPCam( uint32_t SiteID, resultWoWo *tPtr ){
|
|
if(m_bIsConnected) {
|
|
char tQBuf[1024];
|
|
char tIpBuf[32];
|
|
char tProto[32];
|
|
char tPath[CTEXT];
|
|
char *tPos;
|
|
char *tPos2;
|
|
#ifdef DEBUG
|
|
LOG("Add New Camera Record");
|
|
#endif
|
|
memcpy( tProto, tPtr->XAddrs, 5 );
|
|
tProto[5] = (char)0;
|
|
if( tProto[4] == ':') tProto[4] = (char)0;
|
|
memset( tPath, 0, CTEXT );
|
|
tPos = strstr(tPtr->XAddrs,"//");
|
|
if( tPos != NULL ) {
|
|
tPos2 = strstr( tPos + 2,"/");
|
|
if( tPos2 != NULL ) {
|
|
int len,len2,len3;
|
|
len = tPos2 - tPos - 2;
|
|
strncpy( tIpBuf, tPos + 2, len);
|
|
tIpBuf[len] = (char)0;
|
|
strncpy( tPath, tPos + 2 + len, CTEXT );
|
|
} else {
|
|
LOG_ERROR("Pos 2 - err");
|
|
tIpBuf[0] = (char)0;
|
|
};
|
|
} else {
|
|
LOG_ERROR("Pos 0 - err");
|
|
tIpBuf[0] = (char)0;
|
|
};
|
|
sprintf(tQBuf,"INSERT INTO cameras SET `online`=1, `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s', `onvif_access`='%s' ON DUPLICATE KEY UPDATE `online`=1, `ip`='%s'",
|
|
tPtr->RefID,
|
|
//tPtr->XAddrs,
|
|
tPath,
|
|
tIpBuf,
|
|
SiteID,
|
|
tPtr->MAC,
|
|
tPtr->Hardware,
|
|
tPtr->Name,
|
|
tProto,
|
|
//tPtr->XAddrs,
|
|
tIpBuf
|
|
);
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool argusDBC::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 argusDBC::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);
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
if( m_pDatabase->isConnected()) return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool argusDBC::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("site_id");
|
|
if( it != cArr->end() ){
|
|
tVal->site_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("node_id");
|
|
if( it != cArr->end() ){
|
|
tVal->node_id = 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("name");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->name, it->second.c_str(), 64 );
|
|
};
|
|
it = cArr->find("hardware");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->hardware, it->second.c_str(), 32 );
|
|
};
|
|
it = cArr->find("status");
|
|
if( it != cArr->end() ){
|
|
tVal->status = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("session");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->session, it->second.c_str(), 32 );
|
|
};
|
|
it = cArr->find("protocol");
|
|
if( it != cArr->end() ){
|
|
tVal->protocol = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("protocol_aux");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->protocol_aux, it->second.c_str(), 64 );
|
|
};
|
|
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("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("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("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("uuid");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->uuid, it->second.c_str(), CLOG );
|
|
};
|
|
it = cArr->find("mac");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->mac, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("ip");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->ip, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("port");
|
|
if( it != cArr->end() ){
|
|
tVal->port = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("onvif_access");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->onvif_access, it->second.c_str(), 5);
|
|
};
|
|
it = cArr->find("onvif_ctrl");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
|
|
};
|
|
it = cArr->find("ptz_token");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->ptz_token, it->second.c_str(), 64);
|
|
};
|
|
VR.push_back(tVal);
|
|
};
|
|
//??
|
|
//delete(cArr);
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
#ifdef DEBUG
|
|
sprintf( tQBuf,"Now %d Camera Records in System", VR.size());
|
|
LOG(tQBuf);
|
|
#endif
|
|
if( m_pDatabase->isConnected()) return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
|
|
DBC_INT_LIST *argusDBC::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 *argusDBC::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 *argusDBC::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 *argusDBC::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 AND `enabled`=1", 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 *argusDBC::listMediaStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
switch( listMode ){
|
|
case LIST_VALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=1 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break;
|
|
case LIST_INVALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=0 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break;
|
|
default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
|
|
};
|
|
#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 *argusDBC::listSockets( uint32_t NodeID ){
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );
|
|
#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 *argusDBC::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 `enabled`=1 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;
|
|
};
|
|
uint32_t argusDBC::getCamId( CSTR UUID ){
|
|
uint32_t RetVal = 0;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
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() );
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return RetVal;
|
|
};
|
|
|
|
DBC_CAM_DATA *argusDBC::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("site_id");
|
|
if( it != cArr->end() ){
|
|
tVal->site_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("node_id");
|
|
if( it != cArr->end() ){
|
|
tVal->node_id = 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("name");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->name, it->second.c_str(), 64 );
|
|
};
|
|
it = cArr->find("hardware");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->hardware, it->second.c_str(), 32 );
|
|
};
|
|
it = cArr->find("status");
|
|
if( it != cArr->end() ){
|
|
tVal->status = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("session");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->session, it->second.c_str(), 32 );
|
|
};
|
|
it = cArr->find("protocol");
|
|
if( it != cArr->end() ){
|
|
tVal->protocol = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("protocol_aux");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->protocol_aux, it->second.c_str(), 64 );
|
|
};
|
|
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("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("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("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("uuid");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->uuid, it->second.c_str(), 64 );
|
|
};
|
|
it = cArr->find("mac");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->mac, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("ip");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->ip, it->second.c_str(), 16 );
|
|
};
|
|
it = cArr->find("port");
|
|
if( it != cArr->end() ){
|
|
tVal->port = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("onvif_access");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->onvif_access, it->second.c_str(), 5);
|
|
};
|
|
it = cArr->find("onvif_ctrl");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
|
|
};
|
|
it = cArr->find("ptz_token");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->ptz_token, it->second.c_str(), 64);
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_MODULE_DATA *argusDBC::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() );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
|
|
DBC_SOCKET_DATA *tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT * FROM sockets 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_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if( it != cArr->end() ){
|
|
tVal->socket_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("binded");
|
|
if( it != cArr->end() ){
|
|
tVal->binded = (bool)atoi( it->second.c_str() );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){
|
|
DBC_MEDIA_STREAM_DATA *tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT * FROM media_streams 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_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
tVal->id = ID;
|
|
it = cArr->find("source_id");
|
|
if( it != cArr->end() ){
|
|
tVal->source_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("site_id");
|
|
if( it != cArr->end() ){
|
|
tVal->site_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("source_type");
|
|
if( it != cArr->end() ){
|
|
sprintf( tVal->source_type, it->second.c_str() );
|
|
};
|
|
it = cArr->find("valid");
|
|
if( it != cArr->end() ){
|
|
tVal->valid = (bool) atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("token");
|
|
if( it != cArr->end() ){
|
|
sprintf( tVal->token, it->second.c_str() );
|
|
};
|
|
it = cArr->find("mrl_proto");
|
|
if( it != cArr->end() ){
|
|
sprintf( tVal->mrl_proto, it->second.c_str() );
|
|
};
|
|
it = cArr->find("mrl_port");
|
|
if( it != cArr->end() ){
|
|
tVal->mrl_port = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("mrl");
|
|
if( it != cArr->end() ){
|
|
sprintf( tVal->mrl, it->second.c_str() );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_MEDIA_SERVER_DATA *argusDBC::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);
|
|
tVal->id = ID;
|
|
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 );
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
|
|
DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
|
|
if(m_bIsConnected){
|
|
char tQBuf[MAX_PATH_LEN];
|
|
AAssoc *result;
|
|
sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams 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_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
tVal->id = ID;
|
|
it = cArr->find("media_stream_id");
|
|
if( it != cArr->end() ){
|
|
tVal->media_stream_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("online");
|
|
if( it != cArr->end() ){
|
|
tVal->online = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("key");
|
|
if( it != cArr->end() ){
|
|
sprintf( tVal->key, it->second.c_str() );
|
|
};
|
|
it = cArr->find("mrl");
|
|
if( it != cArr->end() ){
|
|
sprintf( tVal->mrl, it->second.c_str() );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
void argusDBC::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 );
|
|
|
|
|
|
// Clenup Nodes and services ...
|
|
sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `site_id`=%d ", SiteID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
|
|
sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
|
|
sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
|
|
#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 argusDBC::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 argusDBC::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 argusDBC::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 argusDBC::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() );
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return RetVal;
|
|
};
|
|
|
|
uint32_t argusDBC::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() );
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return RetVal;
|
|
};
|
|
|
|
uint64_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
|
|
uint64_t RetVal = 0;
|
|
if(m_bIsConnected){
|
|
char tQBuf[1024];
|
|
char tM5[33];
|
|
CSTR tMD5 = MD5String( path );
|
|
if( tMD5 != NULL ) {
|
|
memcpy( tM5, tMD5, 33 );
|
|
tM5[32]=(char)0;
|
|
free( tMD5 );
|
|
sprintf( tQBuf, "INSERT INTO media_streams SET `site_id`=%d, `source_id`=0, source_type='A', `valid`=1, `name`='Local Frame Grabber', `token`='%s', `img_width`=%d, `img_height`=%d, `mrl_proto`='v4l2', `mrl_port`='', `picture_proto`='', mrl='%s' ON DUPLICATE KEY UPDATE id=id, `valid`=1, img_width=%d, img_height=%d",
|
|
SiteID, tM5, width, height, path, width, height );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = m_pDatabase->QueryID( tQBuf );
|
|
};
|
|
|
|
};
|
|
LOG("Func Finished");
|
|
return RetVal;
|
|
};
|
|
|
|
uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
|
|
uint32_t retVal = 0;
|
|
if(m_bIsConnected){
|
|
char tQBuf[2048];
|
|
char tM5[33];
|
|
CSTR tMD5 = MD5String( path );
|
|
if( tMD5 != NULL ) {
|
|
memcpy( tM5, tMD5, 33 );
|
|
free( tMD5 );
|
|
if( multidrop ) {
|
|
sprintf(tQBuf,"INSERT INTO `sockets` SET `node_id`=%d, `type`=%d, `mode`=%d, `multidrop`=1, `md5`='%s', `path`='%s', `name`='%s', `aux_id`=%d ON DUPLICATE KEY UPDATE `id`=`id`, `name`='%s'",
|
|
NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
|
|
} else {
|
|
sprintf(tQBuf,"INSERT INTO `sockets` SET `node_id`=%d, `type`=%d, `mode`=%d, `multidrop`=0, `md5`='%s', `path`='%s', `name`='%s', `aux_id`=%d ON DUPLICATE KEY UPDATE `id`=`id`, `name`='%s'",
|
|
NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
|
|
};
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
//m_pDatabase->SilentQuery( tQBuf );
|
|
retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
|
|
};
|
|
};
|
|
return retVal;
|
|
};
|
|
|
|
uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
|
|
uint32_t retVal = 0;
|
|
if(m_bIsConnected){
|
|
char tQBuf[2048];
|
|
char tM5[33];
|
|
CSTR tMD5 = MD5String( path );
|
|
if( tMD5 != NULL ) {
|
|
memcpy( tM5, tMD5, 33 );
|
|
free( tMD5 );
|
|
sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
|
|
#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() );
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
};
|
|
return retVal;
|
|
};
|
|
|
|
CSTR argusDBC::getNodeIP4( uint32_t NodeID ){
|
|
return getSocketName( NodeID, ARGUS_NODE_SOCK_TYPE_NETWORK_IPV4 );
|
|
};
|
|
|
|
CSTR argusDBC::getNodeIP6( uint32_t NodeID ){
|
|
return getSocketName( NodeID, ARGUS_NODE_SOCK_TYPE_NETWORK_IPV6 );
|
|
};
|
|
|
|
CSTR argusDBC::getSocketPath( uint32_t NodeID, uint32_t Type ){
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
sprintf( tQBuf, "SELECT `path` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
|
|
NodeID, Type );
|
|
#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("path");
|
|
if( it != cArr->end() ){
|
|
strncpy( tQBuf, it->second.c_str(), CTEXT );
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
return strdup(tQBuf);
|
|
};
|
|
return NULL;
|
|
};
|
|
|
|
CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
|
|
if(m_bIsConnected){
|
|
char tQBuf[CTEXT];
|
|
sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
|
|
NodeID, Type );
|
|
#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("name");
|
|
if( it != cArr->end() ){
|
|
strncpy( tQBuf, it->second.c_str(), CTEXT );
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
return strdup(tQBuf);
|
|
};
|
|
return NULL;
|
|
};
|
|
|
|
KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
|
|
KAFKA_SETTINGS *tVal = NULL;
|
|
if( m_bIsConnected ) {
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf( tQBuf, "SELECT brocker_address, brocker_port FROM modules_kafka WHERE module_id = %d", ModuleID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("brocker_address");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
|
|
};
|
|
it = cArr->find("brocker_port");
|
|
if( it != cArr->end() ){
|
|
tVal->brocker_port = atoi( it->second.c_str() );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
|
|
KAFKA_TEMPLATE *tVal = NULL;
|
|
if( m_bIsConnected ) {
|
|
char tQBuf[CTEXT];
|
|
AAssoc *result;
|
|
sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("topic");
|
|
if( it != cArr->end() ){
|
|
memset( tVal->topic, 0, 128 );
|
|
strncpy( tVal->topic , it->second.c_str(), 127 );
|
|
};
|
|
it = cArr->find("template");
|
|
if( it != cArr->end() ){
|
|
tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
|
|
if( tVal->tpl!= NULL) {
|
|
memset( tVal->tpl, 0, it->second.length() + 1 );
|
|
strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
DBC_UART_DATA *argusDBC::getSettingsUART( uint32_t SocketID ){
|
|
DBC_UART_DATA *tVal = NULL;
|
|
if( m_bIsConnected ) {
|
|
char tQBuf[MAX_PATH_LEN];
|
|
AAssoc *result;
|
|
sprintf( tQBuf, "SELECT us.speed, so.path FROM uart_settings us LEFT JOIN sockets so ON ( so.id = us.socket_id ) WHERE us.socket_id = %d", SocketID );
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDatabase->Query( tQBuf );
|
|
if( result!= NULL ) {
|
|
if( result->size() > 0 ) {
|
|
Assoc *cArr;
|
|
tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
|
|
if( tVal != NULL ) {
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
//tVal->socket_id = SocketID;
|
|
it = cArr->find("speed");
|
|
if( it != cArr->end() ){
|
|
tVal->speed = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("path");
|
|
if( it != cArr->end() ){
|
|
strncpy( tVal->device, it->second.c_str(), 255 );
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult( result );
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
|
|
if( m_bIsConnected ) {
|
|
char tQBuf[MAX_PATH_LEN];
|
|
#ifdef DEBUG
|
|
LOG("Stream Update");
|
|
#endif
|
|
if( key == NULL ) {
|
|
if( mrl == NULL ) {
|
|
sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
|
|
} else {
|
|
sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
|
|
};
|
|
} else {
|
|
sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
|
|
key,
|
|
mrl,
|
|
id
|
|
);
|
|
};
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDatabase->SilentQuery( tQBuf );
|
|
return true;
|
|
};
|
|
return false;
|
|
};
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|