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.

3440 lines
126 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
5 years ago
​
5 years ago
​
5 years ago
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "rgooseDBConnector.h"
  2. #define LOG( X ) m_pLog->Log( "ADBC", this, X )
  3. #ifdef DEBUG
  4. #define LOG_ERROR( X ) {\
  5. char _tBfrErrMSG2w34[256];\
  6. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  7. m_pLog->Log( "ADBC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  8. }
  9. #else
  10. #define LOG_ERROR( X ) m_pLog->Log( "ADBC", this, _LOG_ERROR, X );
  11. #endif
  12. argusDBC *argusDBC::_instance = NULL;
  13. /**
  14. * Returns the single instance of the object.
  15. */
  16. argusDBC* argusDBC::getInstance( config_setting_t * Settings ) {
  17. // check if the instance has been created yet
  18. if( 0 == _instance ){
  19. // if not, then create it
  20. _instance = new argusDBC( Settings );
  21. };
  22. // return the single instance
  23. return _instance;
  24. };
  25. argusDBC::argusDBC( config_setting_t * Settings ){
  26. m_pLog = basicLogCollection::getInstance();
  27. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DBC" );
  28. m_bIsConnected = false;
  29. m_nSiteID = 0;
  30. m_pDatabase = NULL;
  31. };
  32. argusDBC::~argusDBC(){
  33. m_bIsConnected = false;
  34. if( m_pDatabase != NULL ) delete( m_pDatabase );
  35. m_pDatabase = NULL;
  36. _instance = NULL;
  37. };
  38. bool argusDBC::connect( void ){
  39. config_setting_t * tSetting;
  40. m_bIsConnected = false;
  41. if( m_pSettings!= NULL ) {
  42. tSetting = config_setting_get_member( m_pSettings, "DATABASE_HOST" );
  43. if( tSetting == NULL ){
  44. tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING );
  45. config_setting_set_string( tSetting, "localhost" );
  46. basicSettingsProvider::getInstance()->compromise();
  47. LOG("No DB Host Setting! Using default!");
  48. };
  49. sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
  50. tSetting = config_setting_get_member( m_pSettings, "DATABASE_NAME" );
  51. if( tSetting == NULL ){
  52. tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING );
  53. config_setting_set_string( tSetting, "dfsl_gunter" );
  54. basicSettingsProvider::getInstance()->compromise();
  55. LOG("No DB Database Setting! Using default!");
  56. };
  57. sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting));
  58. tSetting = config_setting_get_member( m_pSettings, "DATABASE_USER" );
  59. if( tSetting == NULL ){
  60. tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING );
  61. config_setting_set_string( tSetting, "dbroot" );
  62. basicSettingsProvider::getInstance()->compromise();
  63. LOG("No DB User Setting! Using default!");
  64. };
  65. sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting));
  66. tSetting = config_setting_get_member( m_pSettings, "DATABASE_PASSWORD" );
  67. if( tSetting == NULL ){
  68. tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING );
  69. config_setting_set_string( tSetting, "123567" );
  70. basicSettingsProvider::getInstance()->compromise();
  71. LOG("No DB Password Setting! Using default!");
  72. };
  73. sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting));
  74. basicSettingsProvider::getInstance()->validate();
  75. m_pDatabase = new MySQL_Connector();
  76. if( m_pDatabase == NULL )return false;
  77. m_bIsConnected = m_pDatabase->Connect( m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword );
  78. } else {
  79. LOG_ERROR("No Settings Provided!");
  80. };
  81. return m_bIsConnected;
  82. };
  83. bool argusDBC::cleanResources( uint32_t ServerNodeID, bool all ){
  84. if(m_bIsConnected) {
  85. char tQBuf[MAX_PATH_LEN];
  86. if( all ) {
  87. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE `node_id`=%d", ServerNodeID );
  88. } else {
  89. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE ( `node_id`=%d ) AND ( `type`=100 OR `type`=101 OR `type`=103 OR `type`=120 )", ServerNodeID );
  90. };
  91. #ifdef DEBUG_EXTRA
  92. LOG(tQBuf);
  93. #endif
  94. m_pDatabase->SilentQuery( tQBuf );
  95. return true;
  96. };
  97. return false;
  98. };
  99. bool argusDBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){
  100. if(m_bIsConnected) {
  101. char tQBuf[MAX_PATH_LEN];
  102. char tIpBuf[CTEXT];
  103. char *tPos;
  104. char *tPos2;
  105. tPos = strstr(Addr,"//");
  106. if( tPos != NULL ) {
  107. tPos2 = strstr( tPos + 2,"/");
  108. if( tPos2 != NULL ) {
  109. int len;
  110. len = tPos2 - tPos - 2;
  111. strncpy(tIpBuf,tPos + 2,len);
  112. tIpBuf[len] = (char)0;
  113. } else {
  114. LOG_ERROR("Pos 2 - err");
  115. tIpBuf[0] = (char)0;
  116. };
  117. } else {
  118. LOG_ERROR("Pos 0 - err");
  119. tIpBuf[0] = (char)0;
  120. };
  121. sprintf(tQBuf,"UPDATE cameras SET `online`=1,`onvif_ctrl`='%s', `ip`='%s' WHERE `uuid`='%s' AND `site_id`=%d",
  122. Addr,
  123. tIpBuf,
  124. uuid,
  125. SiteID
  126. );
  127. #ifdef DEBUG_EXTRA
  128. LOG(tQBuf);
  129. #endif
  130. m_pDatabase->SilentQuery( tQBuf );
  131. return true;
  132. };
  133. return false;
  134. };
  135. bool argusDBC::updateIPCam( uint32_t SiteID, uint32_t CamID, CSTR Addr ){
  136. if(m_bIsConnected) {
  137. char tQBuf[MAX_PATH_LEN];
  138. char tIpBuf[CTEXT];
  139. char *tPos;
  140. char *tPos2;
  141. tPos = strstr(Addr,"//");
  142. if( tPos != NULL ) {
  143. tPos2 = strstr( tPos + 2,"/");
  144. if( tPos2 != NULL ) {
  145. int len;
  146. len = tPos2 - tPos - 2;
  147. strncpy(tIpBuf,tPos + 2,len);
  148. tIpBuf[len] = (char)0;
  149. } else {
  150. LOG_ERROR("Pos 2 - err");
  151. tIpBuf[0] = (char)0;
  152. };
  153. } else {
  154. LOG_ERROR("Pos 0 - err");
  155. tIpBuf[0] = (char)0;
  156. };
  157. sprintf(tQBuf,"UPDATE cameras SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE id=%d AND `site_id`=%d",
  158. Addr,
  159. tIpBuf,
  160. CamID,
  161. SiteID
  162. );
  163. #ifdef DEBUG_EXTRA
  164. LOG(tQBuf);
  165. #endif
  166. m_pDatabase->SilentQuery( tQBuf );
  167. sprintf(tQBuf,"UPDATE media_streams SET `valid`=1 WHERE source_id=%d AND source_type='D'", CamID );
  168. #ifdef DEBUG_EXTRA
  169. LOG(tQBuf);
  170. #endif
  171. m_pDatabase->SilentQuery( tQBuf );
  172. return true;
  173. };
  174. return false;
  175. };
  176. /*
  177. bool argusDBC::addIPCam( uint32_t SiteID, resultWoWo *tPtr ){
  178. if(m_bIsConnected) {
  179. char tQBuf[1024];
  180. char tIpBuf[32];
  181. char tProto[32];
  182. char tPath[CTEXT];
  183. char *tPos;
  184. char *tPos2;
  185. memcpy( tProto, tPtr->XAddrs, 5 );
  186. tProto[5] = (char)0;
  187. if( tProto[4] == ':') tProto[4] = (char)0;
  188. memset( tPath, 0, CTEXT );
  189. tPos = strstr(tPtr->XAddrs,"//");
  190. if( tPos != NULL ) {
  191. tPos2 = strstr( tPos + 2,"/");
  192. if( tPos2 != NULL ) {
  193. int len,len2,len3;
  194. len = tPos2 - tPos - 2;
  195. strncpy( tIpBuf, tPos + 2, len);
  196. tIpBuf[len] = (char)0;
  197. strncpy( tPath, tPos + 2 + len, CTEXT );
  198. } else {
  199. LOG_ERROR("Pos 2 - err");
  200. tIpBuf[0] = (char)0;
  201. };
  202. } else {
  203. LOG_ERROR("Pos 0 - err");
  204. tIpBuf[0] = (char)0;
  205. };
  206. 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'",
  207. tPtr->RefID,
  208. //tPtr->XAddrs,
  209. tPath,
  210. tIpBuf,
  211. SiteID,
  212. tPtr->MAC,
  213. tPtr->Hardware,
  214. tPtr->Name,
  215. tProto,
  216. //tPtr->XAddrs,
  217. tIpBuf
  218. );
  219. #ifdef DEBUG_EXTRA
  220. LOG(tQBuf);
  221. #endif
  222. m_pDatabase->SilentQuery( tQBuf );
  223. return true;
  224. };
  225. return false;
  226. };
  227. */
  228. bool argusDBC::addIPCam( uint32_t SiteID, OBSERVER_RESULT *tPtr ){
  229. if(m_bIsConnected) {
  230. char tQBuf[1024];
  231. char tIpBuf[32];
  232. char tProto[32];
  233. char tPath[CTEXT];
  234. char *tPos;
  235. char *tPos2;
  236. memcpy( tProto, tPtr->XAddrs, 5 );
  237. tProto[5] = (char)0;
  238. if( tProto[4] == ':') tProto[4] = (char)0;
  239. memset( tPath, 0, CTEXT );
  240. tPos = strstr(tPtr->XAddrs,"//");
  241. if( tPos != NULL ) {
  242. tPos2 = strstr( tPos + 2,"/");
  243. if( tPos2 != NULL ) {
  244. int len,len2,len3;
  245. len = tPos2 - tPos - 2;
  246. strncpy( tIpBuf, tPos + 2, len);
  247. tIpBuf[len] = (char)0;
  248. strncpy( tPath, tPos + 2 + len, CTEXT );
  249. } else {
  250. LOG_ERROR("Pos 2 - err");
  251. tIpBuf[0] = (char)0;
  252. };
  253. } else {
  254. LOG_ERROR("Pos 0 - err");
  255. tIpBuf[0] = (char)0;
  256. };
  257. 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'",
  258. tPtr->RefID,
  259. //tPtr->XAddrs,
  260. tPath,
  261. tIpBuf,
  262. SiteID,
  263. tPtr->MAC,
  264. tPtr->Hardware,
  265. tPtr->Name,
  266. tProto,
  267. //tPtr->XAddrs,
  268. tIpBuf
  269. );
  270. #ifdef DEBUG_EXTRA
  271. LOG(tQBuf);
  272. #endif
  273. m_pDatabase->SilentQuery( tQBuf );
  274. return true;
  275. };
  276. return false;
  277. };
  278. bool argusDBC::transferEvtToArchive( uint32_t SECONDS ){
  279. if(m_bIsConnected) {
  280. if( SECONDS > 0 ) {
  281. char tQBuf[CTEXT];
  282. 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 );
  283. m_pDatabase->SilentQuery( tQBuf );
  284. return true;
  285. };
  286. };
  287. return false;
  288. }
  289. bool argusDBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){
  290. if(m_bIsConnected){
  291. char tQBuf[CTEXT];
  292. AAssoc *result;
  293. sprintf(tQBuf, "SELECT * FROM events_cloud WHERE `ts`>%d AND `ts_ms`>%d", tss, tsms );
  294. result = m_pDatabase->Query( tQBuf );
  295. if( result!= NULL ) {
  296. DBC_EVT_DATA *tPtr;
  297. Assoc *cArr;
  298. for(int i=0;i<result->size();i++) {
  299. cArr = result->at(i);
  300. tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA));
  301. if( tPtr!= NULL ) {
  302. Assoc::iterator it;
  303. memset(tPtr,0,sizeof(DBC_EVT_DATA));
  304. it = cArr->find("id");
  305. if( it != cArr->end() ){
  306. tPtr->id = atoi( it->second.c_str() );
  307. };
  308. it = cArr->find("node_id");
  309. if( it != cArr->end() ){
  310. tPtr->node_id = atoi( it->second.c_str() );
  311. };
  312. it = cArr->find("uuid");
  313. if( it != cArr->end() ){
  314. strncpy( tPtr->uuid, it->second.c_str(),64 );
  315. };
  316. it = cArr->find("ts");
  317. if( it != cArr->end() ){
  318. tPtr->ts_s = atoi( it->second.c_str() );
  319. };
  320. it = cArr->find("ts_ms");
  321. if( it != cArr->end() ){
  322. tPtr->ts_ms = atoi( it->second.c_str() );
  323. };
  324. it = cArr->find("evt_type");
  325. if( it != cArr->end() ){
  326. tPtr->type = atoi( it->second.c_str() );
  327. };
  328. it = cArr->find("range_digital");
  329. if( it != cArr->end() ){
  330. tPtr->range_digital = atoi( it->second.c_str() );
  331. };
  332. it = cArr->find("azimuth");
  333. if( it != cArr->end() ){
  334. tPtr->az = atof( it->second.c_str() );
  335. };
  336. it = cArr->find("elevation");
  337. if( it != cArr->end() ){
  338. tPtr->el = atof( it->second.c_str() );
  339. };
  340. it = cArr->find("range");
  341. if( it != cArr->end() ){
  342. tPtr->ra = atof( it->second.c_str() );
  343. };
  344. it = cArr->find("area");
  345. if( it != cArr->end() ){
  346. tPtr->area = atof( it->second.c_str() );
  347. };
  348. it = cArr->find("lat");
  349. if( it != cArr->end() ){
  350. tPtr->lat = atof( it->second.c_str() );
  351. };
  352. it = cArr->find("lon");
  353. if( it != cArr->end() ){
  354. tPtr->lon = atof( it->second.c_str() );
  355. };
  356. it = cArr->find("alt");
  357. if( it != cArr->end() ){
  358. tPtr->alt = atof( it->second.c_str() );
  359. };
  360. it = cArr->find("ref_uuid");
  361. if( it != cArr->end() ){
  362. strncpy( tPtr->uuid, it->second.c_str(),64 );
  363. };
  364. char tBuf[CLOG];
  365. sprintf(tBuf,"Evt: %d %d %d", tPtr->type, tPtr->ts_s, tPtr->ts_ms );
  366. LOG(tBuf);
  367. VR.push_back(tPtr);
  368. };
  369. };
  370. };
  371. deleteResult( result );
  372. if( m_pDatabase->isConnected()) return true;
  373. };
  374. return false;
  375. };
  376. bool argusDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){
  377. if(m_bIsConnected){
  378. char tQBuf[CTEXT];
  379. AAssoc *result;
  380. sprintf(tQBuf, "SELECT * FROM cameras WHERE `site_id`=%d AND `type`=2 AND `status`=2", SiteID );
  381. #ifdef DEBUG_EXTRA
  382. LOG(tQBuf);
  383. #endif
  384. result = m_pDatabase->Query( tQBuf );
  385. if( result!= NULL ) {
  386. DBC_CAM_DATA *tVal;
  387. Assoc *cArr;
  388. for(int i=0;i<result->size();i++) {
  389. LOG("Cam_Record!");
  390. cArr = result->at(i);
  391. tVal = (DBC_CAM_DATA*)malloc(sizeof(DBC_CAM_DATA));
  392. if( tVal!= NULL ) {
  393. Assoc::iterator it;
  394. memset(tVal,0,sizeof(DBC_CAM_DATA));
  395. it = cArr->find("id");
  396. if( it != cArr->end() ){
  397. tVal->id = atoi( it->second.c_str() );
  398. };
  399. it = cArr->find("site_id");
  400. if( it != cArr->end() ){
  401. tVal->site_id = atoi( it->second.c_str() );
  402. };
  403. it = cArr->find("node_id");
  404. if( it != cArr->end() ){
  405. tVal->node_id = atoi( it->second.c_str() );
  406. };
  407. it = cArr->find("online");
  408. if( it != cArr->end() ){
  409. tVal->online = (bool) atoi( it->second.c_str() );
  410. };
  411. it = cArr->find("type");
  412. if( it != cArr->end() ){
  413. tVal->type = atoi( it->second.c_str() );
  414. };
  415. it = cArr->find("name");
  416. if( it != cArr->end() ){
  417. strncpy( tVal->name, it->second.c_str(), 64 );
  418. };
  419. it = cArr->find("hardware");
  420. if( it != cArr->end() ){
  421. strncpy( tVal->hardware, it->second.c_str(), 32 );
  422. };
  423. it = cArr->find("status");
  424. if( it != cArr->end() ){
  425. tVal->status = atoi( it->second.c_str() );
  426. };
  427. it = cArr->find("session");
  428. if( it != cArr->end() ){
  429. strncpy( tVal->session, it->second.c_str(), 32 );
  430. };
  431. it = cArr->find("protocol");
  432. if( it != cArr->end() ){
  433. tVal->protocol = atoi( it->second.c_str() );
  434. };
  435. it = cArr->find("protocol_aux");
  436. if( it != cArr->end() ){
  437. tVal->protocol_aux = atoi( it->second.c_str() );
  438. };
  439. it = cArr->find("lat");
  440. if( it != cArr->end() ){
  441. tVal->lat = atof( it->second.c_str() );
  442. };
  443. it = cArr->find("lon");
  444. if( it != cArr->end() ){
  445. tVal->lon = atof( it->second.c_str() );
  446. };
  447. it = cArr->find("alt");
  448. if( it != cArr->end() ){
  449. tVal->alt = atof( it->second.c_str() );
  450. };
  451. it = cArr->find("picth");
  452. if( it != cArr->end() ){
  453. tVal->pitch = atof( it->second.c_str() );
  454. };
  455. it = cArr->find("roll");
  456. if( it != cArr->end() ){
  457. tVal->roll = atof( it->second.c_str() );
  458. };
  459. it = cArr->find("yaw");
  460. if( it != cArr->end() ){
  461. tVal->yaw = atof( it->second.c_str() );
  462. };
  463. it = cArr->find("imager_type");
  464. if( it != cArr->end() ){
  465. tVal->imager_type = atoi( it->second.c_str() );
  466. };
  467. it = cArr->find("min_f");
  468. if( it != cArr->end() ){
  469. tVal->min_f = atof( it->second.c_str() );
  470. };
  471. it = cArr->find("max_f");
  472. if( it != cArr->end() ){
  473. tVal->max_f = atof( it->second.c_str() );
  474. };
  475. it = cArr->find("access_login");
  476. if( it != cArr->end() ){
  477. strncpy( tVal->username, it->second.c_str(), 16 );
  478. };
  479. it = cArr->find("access_pass");
  480. if( it != cArr->end() ){
  481. strncpy( tVal->password, it->second.c_str(), 16 );
  482. };
  483. it = cArr->find("uuid");
  484. if( it != cArr->end() ){
  485. strncpy( tVal->uuid, it->second.c_str(), CLOG );
  486. };
  487. it = cArr->find("mac");
  488. if( it != cArr->end() ){
  489. strncpy( tVal->mac, it->second.c_str(), 16 );
  490. };
  491. it = cArr->find("ip");
  492. if( it != cArr->end() ){
  493. strncpy( tVal->ip, it->second.c_str(), 16 );
  494. };
  495. it = cArr->find("port");
  496. if( it != cArr->end() ){
  497. tVal->port = atoi( it->second.c_str() );
  498. };
  499. it = cArr->find("onvif_access");
  500. if( it != cArr->end() ){
  501. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  502. };
  503. it = cArr->find("onvif_ctrl");
  504. if( it != cArr->end() ){
  505. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  506. };
  507. it = cArr->find("ptz_token");
  508. if( it != cArr->end() ){
  509. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  510. };
  511. VR.push_back(tVal);
  512. };
  513. //??
  514. //delete(cArr);
  515. };
  516. };
  517. deleteResult( result );
  518. #ifdef DEBUG
  519. sprintf( tQBuf,"Now %d Camera Records in System", VR.size());
  520. LOG(tQBuf);
  521. #endif
  522. if( m_pDatabase->isConnected()) return true;
  523. };
  524. return false;
  525. };
  526. DBC_INT_LIST *argusDBC::listNodes( uint32_t SiteID ){
  527. DBC_INT_LIST * tVal = NULL;
  528. if( m_bIsConnected ){
  529. char tQBuf[1024];
  530. AAssoc *result;
  531. sprintf( tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `type` > 0", SiteID );
  532. #ifdef DEBUG_EXTRA
  533. LOG(tQBuf);
  534. #endif
  535. result = m_pDatabase->Query( tQBuf );
  536. if( result!= NULL ) {
  537. if( result->size() > 0 ) {
  538. Assoc *cArr;
  539. tVal = new DBC_INT_LIST();
  540. if( tVal != NULL ) {
  541. Assoc::iterator it;
  542. for(int i=0; i <result->size();i++) {
  543. cArr = result->at(i);
  544. it = cArr->find("id");
  545. if( it != cArr->end() ){
  546. tVal->push_back( atoi( it->second.c_str() ));
  547. };
  548. };
  549. };
  550. };
  551. };
  552. deleteResult( result );
  553. };
  554. return tVal;
  555. };
  556. DBC_INT_LIST *argusDBC::listNewNodes( uint32_t SiteID, DBC_INT_LIST *old_ids ){
  557. DBC_INT_LIST * tVal = NULL;
  558. char tParam[CTEXT];
  559. //memset( tParam, 0, CTEXT );
  560. sprintf(tParam,"0");
  561. if( old_ids != NULL ) {
  562. char tBuffer[CTEXT];
  563. for(int i = 0; i< old_ids->size(); i++ ) {
  564. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  565. strncpy( tParam, tBuffer, CTEXT );
  566. };
  567. };
  568. if( m_bIsConnected ){
  569. char tQBuf[CTEXT];
  570. AAssoc *result;
  571. sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, tParam );
  572. #ifdef DEBUG_EXTRA
  573. LOG(tQBuf);
  574. #endif
  575. result = m_pDatabase->Query( tQBuf );
  576. if( result!= NULL ) {
  577. if( result->size() > 0 ) {
  578. Assoc *cArr;
  579. tVal = new DBC_INT_LIST();
  580. if( tVal != NULL ) {
  581. Assoc::iterator it;
  582. for(int i=0;i<result->size();i++) {
  583. cArr = result->at(i);
  584. it = cArr->find("id");
  585. if( it != cArr->end() ){
  586. tVal->push_back( atoi( it->second.c_str() ));
  587. };
  588. };
  589. };
  590. };
  591. };
  592. deleteResult( result );
  593. };
  594. return tVal;
  595. };
  596. void argusDBC::lazyEventArchiver( uint32_t DalayTime ){
  597. if( m_bIsConnected ){
  598. char tQBuf[CTEXT];
  599. AAssoc *result;
  600. uint32_t LastID = 0;
  601. sprintf( tQBuf, "SELECT * FROM `events_cloud` WHERE ( UNIX_TIMESTAMP(NOW()) - `ts` ) > %d ORDER BY `id` ASC LIMIT 10", DalayTime );
  602. #ifdef DEBUG_EXTRA
  603. LOG(tQBuf);
  604. #endif
  605. result = m_pDatabase->Query( tQBuf );
  606. if( result!= NULL ) {
  607. if( result->size() > 0 ) {
  608. Assoc *cArr;
  609. for(int i=0;i<result->size();i++){
  610. uint32_t nodeid=0;
  611. char uuid[64]={0};
  612. uint32_t ts=0;
  613. uint32_t ts_ms=0;
  614. uint32_t evt_t=0;
  615. uint32_t range_d=0;
  616. float az=.0f, el=.0f, ra=.0f, ar=.0f, lat=.0f, lon=.0f, alt=.0f;
  617. uint32_t ref_id=0;
  618. char ref_uuid[64]={0};
  619. Assoc::iterator it;
  620. cArr = result->at(i);
  621. it = cArr->find("id");
  622. if( it != cArr->end() ){
  623. LastID = atoi( it->second.c_str());
  624. };
  625. it = cArr->find("node_id");
  626. if( it != cArr->end() ){
  627. nodeid = atoi( it->second.c_str());
  628. };
  629. it = cArr->find("uuid");
  630. if( it != cArr->end() ){
  631. strncpy( uuid, it->second.c_str(), 64 );
  632. };
  633. it = cArr->find("ts");
  634. if( it != cArr->end() ){
  635. ts = atoi( it->second.c_str());
  636. };
  637. it = cArr->find("ts_ms");
  638. if( it != cArr->end() ){
  639. ts_ms = atoi( it->second.c_str());
  640. };
  641. it = cArr->find("evt_type");
  642. if( it != cArr->end() ){
  643. evt_t = atoi( it->second.c_str());
  644. };
  645. it = cArr->find("range_digital");
  646. if( it != cArr->end() ){
  647. range_d = atoi( it->second.c_str());
  648. };
  649. it = cArr->find("azimuth");
  650. if( it != cArr->end() ){
  651. az = (float)atof( it->second.c_str());
  652. };
  653. it = cArr->find("elevation");
  654. if( it != cArr->end() ){
  655. el = (float)atof( it->second.c_str());
  656. };
  657. it = cArr->find("range");
  658. if( it != cArr->end() ){
  659. ra = (float)atof( it->second.c_str());
  660. };
  661. it = cArr->find("area");
  662. if( it != cArr->end() ){
  663. ar = (float)atof( it->second.c_str());
  664. };
  665. it = cArr->find("lat");
  666. if( it != cArr->end() ){
  667. lat = (float)atof( it->second.c_str());
  668. };
  669. it = cArr->find("lon");
  670. if( it != cArr->end() ){
  671. lon = (float)atof( it->second.c_str());
  672. };
  673. it = cArr->find("alt");
  674. if( it != cArr->end() ){
  675. alt = (float)atof( it->second.c_str());
  676. };
  677. it = cArr->find("ref_id");
  678. if( it != cArr->end() ){
  679. ref_id = atoi( it->second.c_str());
  680. };
  681. it = cArr->find("ref_uuid");
  682. if( it != cArr->end() ){
  683. strncpy( ref_uuid, it->second.c_str(), 64 );
  684. };
  685. sprintf(tQBuf, "INSERT INTO `events_archive` SET `node_id`=%d, `uuid`='%s', `ts`=%d, `ts_ms`=%d, `evt_type`=%d, `range_digital`=%d, `azimuth`=%0.8f, `elevation`=%0.8f, `range`=%0.2f, `area`=%0.5f, `lat`=%0.8f, `lon`=%0.8f, `alt`=%0.3f, `ref_id`=%d, `ref_uuid`='%s'",
  686. nodeid,
  687. uuid,
  688. ts,
  689. ts_ms,
  690. evt_t,
  691. range_d,
  692. az,
  693. el,
  694. ra,
  695. ar,
  696. lat,
  697. lon,
  698. alt,
  699. ref_id,
  700. ref_uuid
  701. );
  702. uint32_t IID = (uint32_t) m_pDatabase->QueryID(tQBuf);
  703. sprintf(tQBuf,"UPDATE `events_2_pictures` SET `event_id`=%d WHERE `event_id`=%d", IID, LastID );
  704. m_pDatabase->SilentQuery(tQBuf);
  705. sprintf(tQBuf,"UPDATE `events_2_videos` SET `event_id`=%d WHERE `event_id`=%d", IID, LastID );
  706. m_pDatabase->SilentQuery(tQBuf);
  707. };
  708. };
  709. };
  710. deleteResult( result );
  711. };
  712. };
  713. DBC_INT_LIST *argusDBC::listCamMediaStreams( uint32_t CAMID ){
  714. DBC_INT_LIST * tVal = NULL;
  715. if(m_bIsConnected){
  716. char tQBuf[CTEXT];
  717. AAssoc *result;
  718. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `source_id`=%d AND `valid`=1", CAMID );
  719. #ifdef DEBUG_EXTRA
  720. LOG(tQBuf);
  721. #endif
  722. result = m_pDatabase->Query( tQBuf );
  723. if( result!= NULL ) {
  724. if( result->size() > 0 ) {
  725. Assoc *cArr;
  726. tVal = new DBC_INT_LIST();
  727. if( tVal != NULL ) {
  728. Assoc::iterator it;
  729. for(int i=0;i<result->size();i++) {
  730. cArr = result->at(i);
  731. it = cArr->find("id");
  732. if( it != cArr->end() ){
  733. tVal->push_back( atoi( it->second.c_str() ));
  734. };
  735. };
  736. };
  737. };
  738. };
  739. deleteResult( result );
  740. };
  741. return tVal;
  742. };
  743. DBC_NETWORK_DATA *argusDBC::getNetworkData( uint32_t net_id ){
  744. DBC_NETWORK_DATA * tVal = NULL;
  745. if(m_bIsConnected){
  746. char tQBuf[CTEXT];
  747. AAssoc *result;
  748. sprintf(tQBuf, "SELECT * FROM `networks` WHERE `id`=%d", net_id );
  749. #ifdef DEBUG_EXTRA
  750. LOG(tQBuf);
  751. #endif
  752. result = m_pDatabase->Query( tQBuf );
  753. if( result!= NULL ) {
  754. if( result->size() > 0 ) {
  755. Assoc *cArr;
  756. tVal = (DBC_NETWORK_DATA*) malloc(sizeof(DBC_NETWORK_DATA));
  757. if( tVal != NULL ) {
  758. memset(tVal, 0, sizeof(DBC_NETWORK_DATA));
  759. Assoc::iterator it;
  760. tVal->id = net_id;
  761. cArr = result->at(0);
  762. it = cArr->find("nif_id");
  763. if( it != cArr->end() ){
  764. tVal->nif_id = atoi(it->second.c_str());
  765. };
  766. it = cArr->find("type");
  767. if( it != cArr->end() ){
  768. tVal->type = (ARGUS_NETWORK_TYPE) atoi(it->second.c_str());
  769. };
  770. it = cArr->find("address");
  771. if( it != cArr->end() ){
  772. strncpy( tVal->address, it->second.c_str(), 65 );
  773. tVal->address[64]=(char)0;
  774. };
  775. it = cArr->find("gateway");
  776. if( it != cArr->end() ){
  777. strncpy(tVal->gateway, it->second.c_str(), 65);
  778. tVal->gateway[64]=(char)0;
  779. };
  780. it = cArr->find("mask");
  781. if( it != cArr->end() ){
  782. strncpy( tVal->netmask, it->second.c_str(), 65 );
  783. tVal->netmask[64]=(char)0;
  784. };
  785. it = cArr->find("broadcast");
  786. if( it != cArr->end() ){
  787. strncpy( tVal->broadcast, it->second.c_str(), 65 );
  788. tVal->broadcast[64]=(char)0;
  789. };
  790. };
  791. };
  792. };
  793. deleteResult( result );
  794. };
  795. return tVal;
  796. };
  797. DBC_NET_IF_DATA *argusDBC::getNIF_Data( uint32_t nif_id ){
  798. DBC_NET_IF_DATA * tVal = NULL;
  799. if(m_bIsConnected){
  800. char tQBuf[CTEXT];
  801. AAssoc *result;
  802. sprintf(tQBuf, "SELECT `type`, `mode`, `device_name`, `mac`, `aux_id` FROM `network_interfaces` WHERE `id`=%d", nif_id );
  803. #ifdef DEBUG_EXTRA
  804. LOG(tQBuf);
  805. #endif
  806. result = m_pDatabase->Query( tQBuf );
  807. if( result!= NULL ) {
  808. if( result->size() > 0 ) {
  809. Assoc *cArr;
  810. tVal = (DBC_NET_IF_DATA*) malloc(sizeof(DBC_NET_IF_DATA));
  811. if( tVal != NULL ) {
  812. Assoc::iterator it;
  813. tVal->id = nif_id;
  814. cArr = result->at(0);
  815. it = cArr->find("type");
  816. if( it != cArr->end() ){
  817. tVal->type = atoi(it->second.c_str());
  818. };
  819. it = cArr->find("mode");
  820. if( it != cArr->end() ){
  821. tVal->mode = atoi(it->second.c_str());
  822. };
  823. it = cArr->find("device_name");
  824. if( it != cArr->end() ){
  825. strncpy( tVal->device_name, it->second.c_str(),11);
  826. tVal->device_name[10]=(char)0;
  827. };
  828. it = cArr->find("mac");
  829. if( it != cArr->end() ){
  830. strncpy( tVal->mac, it->second.c_str(), 33 );
  831. tVal->mac[32]=(char)0;
  832. };
  833. it = cArr->find("aux_id");
  834. if( it != cArr->end() ){
  835. tVal->aux_id = atoi(it->second.c_str());
  836. };
  837. };
  838. };
  839. };
  840. deleteResult( result );
  841. };
  842. return tVal;
  843. };
  844. uint32_t argusDBC::getNIF_ID( CSTR key ){
  845. uint32_t tVal = 0;
  846. if(m_bIsConnected){
  847. char tQBuf[CTEXT];
  848. AAssoc *result;
  849. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `key`='%s'", key );
  850. #ifdef DEBUG_EXTRA
  851. LOG(tQBuf);
  852. #endif
  853. result = m_pDatabase->Query( tQBuf );
  854. if( result!= NULL ) {
  855. if( result->size() > 0 ) {
  856. Assoc *cArr;
  857. Assoc::iterator it;
  858. cArr = result->at(0);
  859. it = cArr->find("id");
  860. if( it != cArr->end() ){
  861. tVal = atoi( it->second.c_str() );
  862. };
  863. };
  864. };
  865. deleteResult( result );
  866. };
  867. return tVal;
  868. };
  869. DBC_NODE_DATA *argusDBC::getNodeData( uint32_t ID ){
  870. DBC_NODE_DATA * tVal = NULL;
  871. if(m_bIsConnected){
  872. char tQBuf[CTEXT];
  873. AAssoc *result;
  874. sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );
  875. #ifdef DEBUG_EXTRA
  876. LOG(tQBuf);
  877. #endif
  878. result = m_pDatabase->Query( tQBuf );
  879. if( result!= NULL ) {
  880. if( result->size() > 0 ) {
  881. Assoc *cArr;
  882. tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
  883. if( tVal != NULL ) {
  884. memset( tVal, 0, sizeof(DBC_NODE_DATA));
  885. Assoc::iterator it;
  886. cArr = result->at(0);
  887. it = cArr->find("id");
  888. if( it != cArr->end() ){
  889. tVal->node_id = atoi( it->second.c_str() );
  890. };
  891. it = cArr->find("type");
  892. if( it != cArr->end() ){
  893. tVal->type = (ARGUS_NODE_TYPE) atoi( it->second.c_str() );
  894. };
  895. it = cArr->find("aux_id");
  896. if( it != cArr->end() ){
  897. tVal->aux_id = atoi( it->second.c_str() );
  898. };
  899. it = cArr->find("aux_parameter");
  900. if( it != cArr->end() ){
  901. tVal->aux_parameter = atoi( it->second.c_str() );
  902. };
  903. it = cArr->find("name");
  904. if( it != cArr->end() ){
  905. sprintf( tVal->name, it->second.c_str() );
  906. };
  907. it = cArr->find("ts_s");
  908. if( it != cArr->end() ){
  909. tVal->tss = atoi( it->second.c_str() );
  910. };
  911. it = cArr->find("ts_ms");
  912. if( it != cArr->end() ){
  913. tVal->tsm = atoi( it->second.c_str() );
  914. };
  915. it = cArr->find("online");
  916. if( it != cArr->end() ){
  917. tVal->online = (bool)atoi( it->second.c_str() );
  918. };
  919. };
  920. };
  921. };
  922. deleteResult( result );
  923. };
  924. return tVal;
  925. };
  926. DBC_APF_DATA *argusDBC::getAPFData( uint32_t APFID ){
  927. DBC_APF_DATA * tVal = NULL;
  928. if(m_bIsConnected){
  929. char tQBuf[CTEXT];
  930. AAssoc *result;
  931. sprintf(tQBuf, "SELECT * FROM `target_filter_apf` WHERE `id`=%d", APFID );
  932. #ifdef DEBUG
  933. LOG(tQBuf);
  934. #endif
  935. result = m_pDatabase->Query( tQBuf );
  936. if( result!= NULL ) {
  937. if( result->size() > 0 ) {
  938. Assoc *cArr;
  939. tVal = (DBC_APF_DATA*) malloc(sizeof(DBC_APF_DATA));
  940. if( tVal != NULL ) {
  941. memset( tVal, 0 , sizeof(DBC_APF_DATA));
  942. Assoc::iterator it;
  943. cArr = result->at(0);
  944. it = cArr->find("mode");
  945. if( it != cArr->end() ){
  946. sprintf( tVal->mode, it->second.c_str() );
  947. };
  948. it = cArr->find("port");
  949. if( it != cArr->end() ){
  950. tVal->port = atoi( it->second.c_str() );
  951. };
  952. it = cArr->find("lat");
  953. if( it != cArr->end() ){
  954. tVal->lat = atof( it->second.c_str() );
  955. };
  956. it = cArr->find("lon");
  957. if( it != cArr->end() ){
  958. tVal->lon = atof( it->second.c_str() );
  959. };
  960. it = cArr->find("alt");
  961. if( it != cArr->end() ){
  962. tVal->alt = atof( it->second.c_str() );
  963. };
  964. it = cArr->find("roll");
  965. if( it != cArr->end() ){
  966. tVal->roll = atof( it->second.c_str() );
  967. };
  968. it = cArr->find("pitch");
  969. if( it != cArr->end() ){
  970. tVal->pitch = atof( it->second.c_str() );
  971. };
  972. it = cArr->find("yaw");
  973. if( it != cArr->end() ){
  974. tVal->yaw = atof( it->second.c_str() );
  975. };
  976. it = cArr->find("dx");
  977. if( it != cArr->end() ){
  978. tVal->dx = atof( it->second.c_str() );
  979. };
  980. it = cArr->find("dy");
  981. if( it != cArr->end() ){
  982. tVal->dy = atof( it->second.c_str() );
  983. };
  984. it = cArr->find("dz");
  985. if( it != cArr->end() ){
  986. tVal->dz = atof( it->second.c_str() );
  987. };
  988. };
  989. };
  990. };
  991. deleteResult( result );
  992. };
  993. return tVal;
  994. };
  995. DBC_FH_DATA *argusDBC::getFlyHunterData( uint32_t ID ){
  996. DBC_FH_DATA * tVal = NULL;
  997. if(m_bIsConnected){
  998. char tQBuf[CTEXT];
  999. AAssoc *result;
  1000. sprintf(tQBuf, "SELECT * FROM `modules_fly_hunter` WHERE `id`=%d", ID );
  1001. #ifdef DEBUG
  1002. LOG(tQBuf);
  1003. #endif
  1004. result = m_pDatabase->Query( tQBuf );
  1005. if( result!= NULL ) {
  1006. if( result->size() > 0 ) {
  1007. Assoc *cArr;
  1008. tVal = (DBC_FH_DATA*) malloc(sizeof(DBC_FH_DATA));
  1009. if( tVal != NULL ) {
  1010. memset( tVal, 0 , sizeof(DBC_FH_DATA));
  1011. Assoc::iterator it;
  1012. cArr = result->at(0);
  1013. it = cArr->find("name");
  1014. if( it != cArr->end() ){
  1015. sprintf( tVal->name, it->second.c_str() );
  1016. };
  1017. it = cArr->find("lat");
  1018. if( it != cArr->end() ){
  1019. tVal->lat = atof( it->second.c_str() );
  1020. };
  1021. it = cArr->find("lon");
  1022. if( it != cArr->end() ){
  1023. tVal->lon = atof( it->second.c_str() );
  1024. };
  1025. it = cArr->find("alt");
  1026. if( it != cArr->end() ){
  1027. tVal->alt = atof( it->second.c_str() );
  1028. };
  1029. it = cArr->find("dc_module_id");
  1030. if( it != cArr->end() ){
  1031. tVal->dc_id = atoi( it->second.c_str() );
  1032. };
  1033. it = cArr->find("uart_id");
  1034. if( it != cArr->end() ){
  1035. tVal->uart_id = atoi( it->second.c_str() );
  1036. };
  1037. };
  1038. };
  1039. };
  1040. deleteResult( result );
  1041. };
  1042. return tVal;
  1043. };
  1044. DBC_SITE_DATA *argusDBC::getSiteData( uint32_t ID ){
  1045. DBC_SITE_DATA * tVal = NULL;
  1046. if(m_bIsConnected){
  1047. char tQBuf[CTEXT];
  1048. AAssoc *result;
  1049. sprintf(tQBuf, "SELECT * FROM sites WHERE `id`=%d", ID );
  1050. #ifdef DEBUG
  1051. LOG(tQBuf);
  1052. #endif
  1053. result = m_pDatabase->Query( tQBuf );
  1054. if( result!= NULL ) {
  1055. if( result->size() > 0 ) {
  1056. Assoc *cArr;
  1057. tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA));
  1058. if( tVal != NULL ) {
  1059. memset( tVal, 0 , sizeof(DBC_SITE_DATA));
  1060. Assoc::iterator it;
  1061. cArr = result->at(0);
  1062. it = cArr->find("account_id");
  1063. if( it != cArr->end() ){
  1064. tVal->account_id = atoi( it->second.c_str() );
  1065. };
  1066. it = cArr->find("name");
  1067. if( it != cArr->end() ){
  1068. sprintf( tVal->name, it->second.c_str() );
  1069. };
  1070. it = cArr->find("server_ident");
  1071. if( it != cArr->end() ){
  1072. sprintf( tVal->ident, it->second.c_str() );
  1073. };
  1074. it = cArr->find("anchor_lat");
  1075. if( it != cArr->end() ){
  1076. tVal->lat = atof( it->second.c_str() );
  1077. };
  1078. it = cArr->find("anchor_lon");
  1079. if( it != cArr->end() ){
  1080. tVal->lon = atof( it->second.c_str() );
  1081. };
  1082. it = cArr->find("anchor_alt");
  1083. if( it != cArr->end() ){
  1084. tVal->alt = atof( it->second.c_str() );
  1085. };
  1086. it = cArr->find("hemisphere");
  1087. if( it != cArr->end() ){
  1088. tVal->SH = ( it->second.c_str()[0] == 'S' );
  1089. };
  1090. it = cArr->find("map_id");
  1091. if( it != cArr->end() ){
  1092. tVal->map_id = atoi( it->second.c_str() );
  1093. };
  1094. };
  1095. };
  1096. };
  1097. deleteResult( result );
  1098. };
  1099. return tVal;
  1100. };
  1101. DBC_TARGET_FLITER_DATA *argusDBC::getTargetFilterData( uint32_t ID ){
  1102. DBC_TARGET_FLITER_DATA * tVal = NULL;
  1103. if(m_bIsConnected){
  1104. char tQBuf[CTEXT];
  1105. AAssoc *result;
  1106. sprintf(tQBuf, "SELECT * FROM target_filters WHERE `id`=%d", ID );
  1107. #ifdef DEBUG
  1108. LOG(tQBuf);
  1109. #endif
  1110. result = m_pDatabase->Query( tQBuf );
  1111. if( result!= NULL ) {
  1112. if( result->size() > 0 ) {
  1113. Assoc *cArr;
  1114. tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA));
  1115. if( tVal != NULL ) {
  1116. memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA));
  1117. Assoc::iterator it;
  1118. tVal->id = ID;
  1119. cArr = result->at(0);
  1120. it = cArr->find("type");
  1121. if( it != cArr->end() ){
  1122. tVal->type = atoi( it->second.c_str() );
  1123. };
  1124. it = cArr->find("aux_id");
  1125. if( it != cArr->end() ){
  1126. tVal->aux_id = atoi( it->second.c_str() );
  1127. };
  1128. };
  1129. };
  1130. };
  1131. deleteResult( result );
  1132. };
  1133. return tVal;
  1134. };
  1135. DBC_LRF_DATA *argusDBC::getLRFData( uint32_t ID ){
  1136. DBC_LRF_DATA * tVal = NULL;
  1137. if(m_bIsConnected){
  1138. char tQBuf[CTEXT];
  1139. AAssoc *result;
  1140. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  1141. #ifdef DEBUG
  1142. LOG(tQBuf);
  1143. #endif
  1144. result = m_pDatabase->Query( tQBuf );
  1145. if( result!= NULL ) {
  1146. if( result->size() > 0 ) {
  1147. Assoc *cArr;
  1148. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  1149. if( tVal != NULL ) {
  1150. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  1151. Assoc::iterator it;
  1152. tVal->id = ID;
  1153. cArr = result->at(0);
  1154. it = cArr->find("data_status");
  1155. if( it != cArr->end() ){
  1156. tVal->data_status = atoi( it->second.c_str() );
  1157. };
  1158. it = cArr->find("serial");
  1159. if( it != cArr->end() ){
  1160. strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 );
  1161. tVal->serial[sizeof(tVal->serial)-1]=(char)0;
  1162. };
  1163. it = cArr->find("version");
  1164. if( it != cArr->end() ){
  1165. strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 );
  1166. tVal->version[sizeof(tVal->version)-1]=(char)0;
  1167. };
  1168. it = cArr->find("lat");
  1169. if( it != cArr->end() ){
  1170. tVal->lat = atof( it->second.c_str() );
  1171. };
  1172. it = cArr->find("lon");
  1173. if( it != cArr->end() ){
  1174. tVal->lon = atof( it->second.c_str() );
  1175. };
  1176. it = cArr->find("alt");
  1177. if( it != cArr->end() ){
  1178. tVal->alt = atof( it->second.c_str() );
  1179. };
  1180. it = cArr->find("pitch");
  1181. if( it != cArr->end() ){
  1182. tVal->pitch = atof( it->second.c_str() );
  1183. };
  1184. it = cArr->find("yaw");
  1185. if( it != cArr->end() ){
  1186. tVal->yaw = atof( it->second.c_str() );
  1187. };
  1188. it = cArr->find("roll");
  1189. if( it != cArr->end() ){
  1190. tVal->roll = atof( it->second.c_str() );
  1191. };
  1192. it = cArr->find("uart_id");
  1193. if( it != cArr->end() ){
  1194. tVal->uart_id = atoi( it->second.c_str() );
  1195. };
  1196. it = cArr->find("device_id");
  1197. if( it != cArr->end() ){
  1198. tVal->device_id = atoi( it->second.c_str() );
  1199. };
  1200. it = cArr->find("ip_address");
  1201. if( it != cArr->end() ){
  1202. sprintf( tVal->master_host, it->second.c_str() );
  1203. };
  1204. it = cArr->find("aux_ip_address");
  1205. if( it != cArr->end() ){
  1206. sprintf( tVal->slave_host, it->second.c_str() );
  1207. };
  1208. it = cArr->find("port");
  1209. if( it != cArr->end() ){
  1210. tVal->master_port = atoi( it->second.c_str() );
  1211. };
  1212. it = cArr->find("aux_port");
  1213. if( it != cArr->end() ){
  1214. tVal->slave_port = atoi( it->second.c_str() );
  1215. };
  1216. it = cArr->find("auto_draw");
  1217. if( it != cArr->end() ){
  1218. tVal->auto_draw = atoi( it->second.c_str() );
  1219. };
  1220. it = cArr->find("filter_id");
  1221. if( it != cArr->end() ){
  1222. tVal->filter_id = atoi( it->second.c_str() );
  1223. };
  1224. //it = cArr->find("enabled_lrf");
  1225. //if( it != cArr->end() ){
  1226. // tVal->enabled_lrf = atoi( it->second.c_str() );
  1227. //};
  1228. it = cArr->find("max_range");
  1229. if( it != cArr->end() ){
  1230. tVal->max_range = atof( it->second.c_str() );
  1231. };
  1232. it = cArr->find("base_shift");
  1233. if( it != cArr->end() ){
  1234. tVal->base_shift = atoi( it->second.c_str() );
  1235. };
  1236. it = cArr->find("mirror_shift");
  1237. if( it != cArr->end() ){
  1238. tVal->mirror_shift = atoi( it->second.c_str() );
  1239. };
  1240. it = cArr->find("detection_profile_id");
  1241. if( it != cArr->end() ){
  1242. tVal->detection_profile_id = atoi( it->second.c_str() );
  1243. };
  1244. it = cArr->find("width_table_id");
  1245. if( it != cArr->end() ){
  1246. tVal->width_table_id = atoi( it->second.c_str() );
  1247. };
  1248. it = cArr->find("zoom_table_id");
  1249. if( it != cArr->end() ){
  1250. tVal->zoom_table_id = atoi( it->second.c_str() );
  1251. };
  1252. it = cArr->find("embd_cam");
  1253. if( it != cArr->end() ){
  1254. tVal->embd_cam = atoi( it->second.c_str() );
  1255. };
  1256. it = cArr->find("embd_cam_auto");
  1257. if( it != cArr->end() ){
  1258. tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
  1259. };
  1260. it = cArr->find("embd_dc");
  1261. if( it != cArr->end() ){
  1262. tVal->embd_dc = atoi( it->second.c_str() );
  1263. };
  1264. it = cArr->find("autoreset");
  1265. if( it != cArr->end() ){
  1266. tVal->autoreset = (bool)atoi( it->second.c_str() );
  1267. };
  1268. };
  1269. };
  1270. };
  1271. deleteResult( result );
  1272. };
  1273. return tVal;
  1274. };
  1275. uint8_t argusDBC::getLRFDataStatus( uint32_t ID ){
  1276. uint8_t RetVal = 0;
  1277. if(m_bIsConnected){
  1278. char tQBuf[CTEXT];
  1279. AAssoc *result;
  1280. sprintf(tQBuf, "SELECT * FROM `lrf_sensors` WHERE `id`=%d", ID );
  1281. #ifdef DEBUG
  1282. LOG(tQBuf);
  1283. #endif
  1284. result = m_pDatabase->Query( tQBuf );
  1285. if( result!= NULL ) {
  1286. if( result->size() > 0 ) {
  1287. Assoc *cArr;
  1288. Assoc::iterator it;
  1289. cArr = result->at(0);
  1290. it = cArr->find("data_status");
  1291. if( it != cArr->end() ){
  1292. RetVal = atoi( it->second.c_str() );
  1293. };
  1294. };
  1295. };
  1296. deleteResult( result );
  1297. };
  1298. return RetVal;
  1299. };
  1300. /*
  1301. DBC_PUSHED_CMD *argusDBC::getLRFPushedCMD( uint32_t ID ){
  1302. DBC_PUSHED_CMD *RetVal = NULL;
  1303. if(m_bIsConnected){
  1304. char tQBuf[CTEXT];
  1305. AAssoc *result;
  1306. sprintf(tQBuf, "SELECT `pushed_cmd`, `pushed_param` FROM `lrf_sensors` WHERE `id`=%d AND `pushed_cmd` > 0", ID );
  1307. #ifdef DEBUG
  1308. //LOG(tQBuf);
  1309. #endif
  1310. result = m_pDatabase->Query( tQBuf );
  1311. if( result!= NULL ) {
  1312. if( result->size() > 0 ) {
  1313. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  1314. if( RetVal ) {
  1315. Assoc *cArr;
  1316. Assoc::iterator it;
  1317. cArr = result->at(0);
  1318. it = cArr->find("pushed_cmd");
  1319. if( it != cArr->end() ){
  1320. RetVal->CMD = atoi( it->second.c_str() );
  1321. };
  1322. it = cArr->find("pushed_param");
  1323. if( it != cArr->end() ){
  1324. RetVal->PARAM = atoi( it->second.c_str() );
  1325. };
  1326. };
  1327. };
  1328. //Only If Result is Fetched - Clear Current CMD
  1329. sprintf(tQBuf, "UPDATE `lrf_sensors` SET `pushed_cmd`=0, `pushed_param`=0 WHERE `id`=%d", ID );
  1330. m_pDatabase->SilentQuery( tQBuf );
  1331. };
  1332. deleteResult( result );
  1333. };
  1334. return RetVal;
  1335. };
  1336. */
  1337. DBC_INT_LIST *argusDBC::listModules( uint32_t ServerID ){
  1338. DBC_INT_LIST * tVal = NULL;
  1339. if(m_bIsConnected){
  1340. char tQBuf[CTEXT];
  1341. AAssoc *result;
  1342. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1343. #ifdef DEBUG
  1344. //LOG(tQBuf);
  1345. #endif
  1346. result = m_pDatabase->Query( tQBuf );
  1347. if( result!= NULL ) {
  1348. if( result->size() > 0 ) {
  1349. Assoc *cArr;
  1350. tVal = new DBC_INT_LIST();
  1351. if( tVal != NULL ) {
  1352. Assoc::iterator it;
  1353. for(int i=0;i<result->size();i++) {
  1354. cArr = result->at(i);
  1355. it = cArr->find("id");
  1356. if( it != cArr->end() ){
  1357. tVal->push_back( atoi( it->second.c_str() ));
  1358. };
  1359. };
  1360. };
  1361. };
  1362. };
  1363. deleteResult( result );
  1364. };
  1365. return tVal;
  1366. };
  1367. DBC_INT_LIST *argusDBC::listFilters( uint32_t ServerID ){
  1368. DBC_INT_LIST * tVal = NULL;
  1369. if(m_bIsConnected){
  1370. char tQBuf[CTEXT];
  1371. AAssoc *result;
  1372. sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1373. #ifdef DEBUG_ALL
  1374. LOG(tQBuf);
  1375. #endif
  1376. result = m_pDatabase->Query( tQBuf );
  1377. if( result!= NULL ) {
  1378. if( result->size() > 0 ) {
  1379. Assoc *cArr;
  1380. tVal = new DBC_INT_LIST();
  1381. if( tVal != NULL ) {
  1382. Assoc::iterator it;
  1383. for(int i=0;i<result->size();i++) {
  1384. cArr = result->at(i);
  1385. it = cArr->find("id");
  1386. if( it != cArr->end() ){
  1387. tVal->push_back( atoi( it->second.c_str() ));
  1388. };
  1389. };
  1390. };
  1391. };
  1392. };
  1393. deleteResult( result );
  1394. };
  1395. return tVal;
  1396. };
  1397. DBC_INT_LIST *argusDBC::listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){
  1398. DBC_INT_LIST * tVal = NULL;
  1399. if(m_bIsConnected){
  1400. char tQBuf[CTEXT];
  1401. AAssoc *result;
  1402. switch( listMode ){
  1403. 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;
  1404. 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;
  1405. default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
  1406. };
  1407. #ifdef DEBUG_ALL
  1408. LOG(tQBuf);
  1409. #endif
  1410. result = m_pDatabase->Query( tQBuf );
  1411. if( result!= NULL ) {
  1412. if( result->size() > 0 ) {
  1413. Assoc *cArr;
  1414. tVal = new DBC_INT_LIST();
  1415. if( tVal != NULL ) {
  1416. Assoc::iterator it;
  1417. for(int i=0;i<result->size();i++) {
  1418. cArr = result->at(i);
  1419. it = cArr->find("id");
  1420. if( it != cArr->end() ){
  1421. tVal->push_back( atoi( it->second.c_str() ));
  1422. };
  1423. };
  1424. };
  1425. };
  1426. };
  1427. deleteResult( result );
  1428. };
  1429. return tVal;
  1430. };
  1431. DBC_INT_LIST *argusDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){
  1432. DBC_INT_LIST * tVal = NULL;
  1433. if(m_bIsConnected){
  1434. char tQBuf[CTEXT];
  1435. AAssoc *result;
  1436. switch( listMode ){
  1437. case LIST_VALID_RECORDS:
  1438. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `valid`=1 AND `site_id`=%d", SiteId );
  1439. break;
  1440. case LIST_INVALID_RECORDS:
  1441. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `valid`=0 AND `site_id`=%d", SiteId );
  1442. break;
  1443. default:
  1444. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `site_id`=%d", SiteId );
  1445. };
  1446. #ifdef DEBUG_ALL
  1447. LOG(tQBuf);
  1448. #endif
  1449. result = m_pDatabase->Query( tQBuf );
  1450. if( result!= NULL ) {
  1451. if( result->size() > 0 ) {
  1452. Assoc *cArr;
  1453. tVal = new DBC_INT_LIST();
  1454. if( tVal != NULL ) {
  1455. Assoc::iterator it;
  1456. for(int i=0;i<result->size();i++) {
  1457. cArr = result->at(i);
  1458. it = cArr->find("id");
  1459. if( it != cArr->end() ){
  1460. tVal->push_back( atoi( it->second.c_str() ));
  1461. };
  1462. };
  1463. };
  1464. };
  1465. };
  1466. deleteResult( result );
  1467. };
  1468. return tVal;
  1469. };
  1470. DBC_INT_LIST *argusDBC::listDetectionProfileIDs( uint32_t nodeID ){
  1471. DBC_INT_LIST * tVal = NULL;
  1472. if(m_bIsConnected){
  1473. char tQBuf[CTEXT];
  1474. AAssoc *result;
  1475. sprintf(tQBuf, "SELECT `profile_id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  1476. #ifdef DEBUG_ALL
  1477. LOG(tQBuf);
  1478. #endif
  1479. result = m_pDatabase->Query( tQBuf );
  1480. if( result!= NULL ) {
  1481. if( result->size() > 0 ) {
  1482. Assoc *cArr;
  1483. tVal = new DBC_INT_LIST();
  1484. if( tVal != NULL ) {
  1485. Assoc::iterator it;
  1486. for(int i=0;i<result->size();i++) {
  1487. cArr = result->at(i);
  1488. it = cArr->find("profile_id");
  1489. if( it != cArr->end() ){
  1490. tVal->push_back( atoi( it->second.c_str() ));
  1491. };
  1492. };
  1493. };
  1494. };
  1495. };
  1496. deleteResult( result );
  1497. };
  1498. return tVal;
  1499. };
  1500. DBC_INT_LIST *argusDBC::listDetectionProfiles( uint32_t nodeID ){
  1501. DBC_INT_LIST * tVal = NULL;
  1502. if(m_bIsConnected){
  1503. char tQBuf[CTEXT];
  1504. AAssoc *result;
  1505. sprintf(tQBuf, "SELECT `id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  1506. #ifdef DEBUG_ALL
  1507. LOG(tQBuf);
  1508. #endif
  1509. result = m_pDatabase->Query( tQBuf );
  1510. if( result!= NULL ) {
  1511. if( result->size() > 0 ) {
  1512. Assoc *cArr;
  1513. tVal = new DBC_INT_LIST();
  1514. if( tVal != NULL ) {
  1515. Assoc::iterator it;
  1516. for(int i=0;i<result->size();i++) {
  1517. cArr = result->at(i);
  1518. it = cArr->find("id");
  1519. if( it != cArr->end() ){
  1520. tVal->push_back( atoi( it->second.c_str() ));
  1521. };
  1522. };
  1523. };
  1524. };
  1525. };
  1526. deleteResult( result );
  1527. };
  1528. return tVal;
  1529. };
  1530. /*
  1531. DBC_INT_LIST *argusDBC::listSockets( uint32_t NodeID ){
  1532. DBC_INT_LIST * tVal = NULL;
  1533. if(m_bIsConnected){
  1534. char tQBuf[CTEXT];
  1535. AAssoc *result;
  1536. sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );
  1537. #ifdef DEBUG
  1538. LOG(tQBuf);
  1539. #endif
  1540. result = m_pDatabase->Query( tQBuf );
  1541. if( result!= NULL ) {
  1542. if( result->size() > 0 ) {
  1543. Assoc *cArr;
  1544. tVal = new DBC_INT_LIST();
  1545. if( tVal != NULL ) {
  1546. Assoc::iterator it;
  1547. for(int i=0;i<result->size();i++) {
  1548. cArr = result->at(i);
  1549. it = cArr->find("id");
  1550. if( it != cArr->end() ){
  1551. tVal->push_back( atoi( it->second.c_str() ));
  1552. };
  1553. };
  1554. };
  1555. };
  1556. };
  1557. deleteResult( result );
  1558. };
  1559. return tVal;
  1560. };
  1561. */
  1562. DBC_INT_LIST *argusDBC::listResources( uint32_t NodeID ){
  1563. DBC_INT_LIST * tVal = NULL;
  1564. if(m_bIsConnected){
  1565. char tQBuf[CTEXT];
  1566. AAssoc *result;
  1567. if( NodeID ) {
  1568. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d AND `active`=1", NodeID );
  1569. } else {
  1570. sprintf(tQBuf, "SELECT `re`.`id` FROM `resources` `re` LEFT JOIN `nodes` `no` ON( `re`.`node_id` = `no`.`id` ) WHERE `no`.`site_id`=%d AND `re`.`active`=1", m_nSiteID );
  1571. };
  1572. #ifdef DEBUG
  1573. LOG(tQBuf);
  1574. #endif
  1575. result = m_pDatabase->Query( tQBuf );
  1576. if( result!= NULL ) {
  1577. if( result->size() > 0 ) {
  1578. Assoc *cArr;
  1579. tVal = new DBC_INT_LIST();
  1580. if( tVal != NULL ) {
  1581. Assoc::iterator it;
  1582. for(int i=0;i<result->size();i++) {
  1583. cArr = result->at(i);
  1584. it = cArr->find("id");
  1585. if( it != cArr->end() ){
  1586. tVal->push_back( atoi( it->second.c_str() ));
  1587. };
  1588. };
  1589. };
  1590. };
  1591. };
  1592. deleteResult( result );
  1593. };
  1594. return tVal;
  1595. };
  1596. DBC_INT_LIST *argusDBC::listNetworks( uint32_t nif_id ){
  1597. DBC_INT_LIST * tVal = NULL;
  1598. if(m_bIsConnected){
  1599. char tQBuf[CTEXT];
  1600. AAssoc *result;
  1601. sprintf(tQBuf, "SELECT `id` FROM `networks` WHERE `nif_id`=%d", nif_id );
  1602. #ifdef DEBUG_ALL
  1603. LOG(tQBuf);
  1604. #endif
  1605. result = m_pDatabase->Query( tQBuf );
  1606. if( result!= NULL ) {
  1607. if( result->size() > 0 ) {
  1608. Assoc *cArr;
  1609. tVal = new DBC_INT_LIST();
  1610. if( tVal != NULL ) {
  1611. Assoc::iterator it;
  1612. for(int i=0;i<result->size();i++) {
  1613. cArr = result->at(i);
  1614. it = cArr->find("id");
  1615. if( it != cArr->end() ){
  1616. tVal->push_back( atoi( it->second.c_str() ));
  1617. };
  1618. };
  1619. };
  1620. };
  1621. };
  1622. deleteResult( result );
  1623. };
  1624. return tVal;
  1625. };
  1626. DBC_INT_LIST *argusDBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ){
  1627. DBC_INT_LIST * tVal = NULL;
  1628. char tParam[CTEXT];
  1629. //memset( tParam, 0, CTEXT );
  1630. sprintf(tParam,"0");
  1631. if( old_ids != NULL ) {
  1632. char tBuffer[CTEXT];
  1633. for(int i = 0; i< old_ids->size(); i++ ) {
  1634. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  1635. strncpy( tParam, tBuffer, CTEXT );
  1636. };
  1637. };
  1638. if(m_bIsConnected){
  1639. char tQBuf[CTEXT];
  1640. AAssoc *result;
  1641. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", ServerID, tParam );
  1642. #ifdef DEBUG_ALL
  1643. LOG(tQBuf);
  1644. #endif
  1645. result = m_pDatabase->Query( tQBuf );
  1646. if( result!= NULL ) {
  1647. if( result->size() > 0 ) {
  1648. Assoc *cArr;
  1649. tVal = new DBC_INT_LIST();
  1650. if( tVal != NULL ) {
  1651. Assoc::iterator it;
  1652. for(int i=0;i<result->size();i++) {
  1653. cArr = result->at(i);
  1654. it = cArr->find("id");
  1655. if( it != cArr->end() ){
  1656. tVal->push_back( atoi( it->second.c_str() ));
  1657. };
  1658. };
  1659. };
  1660. };
  1661. };
  1662. deleteResult( result );
  1663. };
  1664. return tVal;
  1665. };
  1666. uint32_t argusDBC::getCamId( CSTR UUID ){
  1667. uint32_t RetVal = 0;
  1668. if(m_bIsConnected){
  1669. char tQBuf[CTEXT];
  1670. AAssoc *result;
  1671. sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
  1672. #ifdef DEBUG_ALL
  1673. LOG(tQBuf);
  1674. #endif
  1675. result = m_pDatabase->Query( tQBuf );
  1676. if( result!= NULL ) {
  1677. if( result->size() > 0 ) {
  1678. Assoc *cArr;
  1679. Assoc::iterator it;
  1680. cArr = result->at(0);
  1681. it = cArr->find("id");
  1682. if( it != cArr->end() ){
  1683. RetVal = atoi( it->second.c_str() );
  1684. };
  1685. };
  1686. };
  1687. deleteResult( result );
  1688. };
  1689. return RetVal;
  1690. };
  1691. DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
  1692. DBC_CAM_DATA *tVal = NULL;
  1693. if(m_bIsConnected){
  1694. char tQBuf[CTEXT];
  1695. AAssoc *result;
  1696. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  1697. #ifdef DEBUG_ALL
  1698. LOG(tQBuf);
  1699. #endif
  1700. result = m_pDatabase->Query( tQBuf );
  1701. if( result!= NULL ) {
  1702. if( result->size() > 0 ) {
  1703. Assoc *cArr;
  1704. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  1705. if( tVal != NULL ) {
  1706. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  1707. tVal->id = ID;
  1708. Assoc::iterator it;
  1709. cArr = result->at(0);
  1710. it = cArr->find("site_id");
  1711. if( it != cArr->end() ){
  1712. tVal->site_id = atoi( it->second.c_str() );
  1713. };
  1714. it = cArr->find("node_id");
  1715. if( it != cArr->end() ){
  1716. tVal->node_id = atoi( it->second.c_str() );
  1717. };
  1718. it = cArr->find("online");
  1719. if( it != cArr->end() ){
  1720. tVal->online = (bool) atoi( it->second.c_str() );
  1721. };
  1722. it = cArr->find("type");
  1723. if( it != cArr->end() ){
  1724. tVal->type = atoi( it->second.c_str() );
  1725. };
  1726. it = cArr->find("name");
  1727. if( it != cArr->end() ){
  1728. strncpy( tVal->name, it->second.c_str(), 64 );
  1729. };
  1730. it = cArr->find("hardware");
  1731. if( it != cArr->end() ){
  1732. strncpy( tVal->hardware, it->second.c_str(), 32 );
  1733. };
  1734. it = cArr->find("status");
  1735. if( it != cArr->end() ){
  1736. tVal->status = atoi( it->second.c_str() );
  1737. };
  1738. it = cArr->find("session");
  1739. if( it != cArr->end() ){
  1740. strncpy( tVal->session, it->second.c_str(), 32 );
  1741. };
  1742. it = cArr->find("protocol");
  1743. if( it != cArr->end() ){
  1744. tVal->protocol = atoi( it->second.c_str() );
  1745. };
  1746. it = cArr->find("protocol_aux");
  1747. if( it != cArr->end() ){
  1748. tVal->protocol_aux = atoi( it->second.c_str() );
  1749. };
  1750. it = cArr->find("uart_id");
  1751. if( it != cArr->end() ){
  1752. tVal->uart_id = atoi( it->second.c_str() );
  1753. };
  1754. it = cArr->find("lat");
  1755. if( it != cArr->end() ){
  1756. tVal->lat = atof( it->second.c_str() );
  1757. };
  1758. it = cArr->find("lon");
  1759. if( it != cArr->end() ){
  1760. tVal->lon = atof( it->second.c_str() );
  1761. };
  1762. it = cArr->find("alt");
  1763. if( it != cArr->end() ){
  1764. tVal->alt = atof( it->second.c_str() );
  1765. };
  1766. it = cArr->find("picth");
  1767. if( it != cArr->end() ){
  1768. tVal->pitch = atof( it->second.c_str() );
  1769. };
  1770. it = cArr->find("roll");
  1771. if( it != cArr->end() ){
  1772. tVal->roll = atof( it->second.c_str() );
  1773. };
  1774. it = cArr->find("yaw");
  1775. if( it != cArr->end() ){
  1776. tVal->yaw = atof( it->second.c_str() );
  1777. };
  1778. it = cArr->find("imager_type");
  1779. if( it != cArr->end() ){
  1780. tVal->imager_type = atoi( it->second.c_str() );
  1781. };
  1782. it = cArr->find("min_f");
  1783. if( it != cArr->end() ){
  1784. tVal->min_f = atof( it->second.c_str() );
  1785. };
  1786. it = cArr->find("max_f");
  1787. if( it != cArr->end() ){
  1788. tVal->max_f = atof( it->second.c_str() );
  1789. };
  1790. it = cArr->find("ptz_speed_step");
  1791. if( it != cArr->end() ){
  1792. tVal->ptz_speed_step = atof( it->second.c_str() );
  1793. };
  1794. it = cArr->find("pan_model");
  1795. if( it != cArr->end() ){
  1796. tVal->pan_model = atoi( it->second.c_str() );
  1797. };
  1798. it = cArr->find("pan_angles");
  1799. if( it != cArr->end() ){
  1800. tVal->pan_angles = atoi( it->second.c_str() );
  1801. };
  1802. it = cArr->find("tilt_model");
  1803. if( it != cArr->end() ){
  1804. tVal->tilt_model = atoi( it->second.c_str() );
  1805. };
  1806. it = cArr->find("tilt_angles");
  1807. if( it != cArr->end() ){
  1808. tVal->tilt_angles = atoi( it->second.c_str() );
  1809. };
  1810. it = cArr->find("max_range");
  1811. if( it != cArr->end() ){
  1812. tVal->max_range = atof( it->second.c_str() );
  1813. };
  1814. it = cArr->find("access_login");
  1815. if( it != cArr->end() ){
  1816. strncpy( tVal->username, it->second.c_str(), 16 );
  1817. };
  1818. it = cArr->find("access_pass");
  1819. if( it != cArr->end() ){
  1820. strncpy( tVal->password, it->second.c_str(), 16 );
  1821. };
  1822. it = cArr->find("uuid");
  1823. if( it != cArr->end() ){
  1824. strncpy( tVal->uuid, it->second.c_str(), 64 );
  1825. };
  1826. it = cArr->find("mac");
  1827. if( it != cArr->end() ){
  1828. strncpy( tVal->mac, it->second.c_str(), 16 );
  1829. };
  1830. it = cArr->find("ip");
  1831. if( it != cArr->end() ){
  1832. strncpy( tVal->ip, it->second.c_str(), 16 );
  1833. };
  1834. it = cArr->find("port");
  1835. if( it != cArr->end() ){
  1836. tVal->port = atoi( it->second.c_str() );
  1837. };
  1838. it = cArr->find("onvif_access");
  1839. if( it != cArr->end() ){
  1840. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  1841. };
  1842. it = cArr->find("onvif_ctrl");
  1843. if( it != cArr->end() ){
  1844. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  1845. };
  1846. it = cArr->find("ptz_token");
  1847. if( it != cArr->end() ){
  1848. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  1849. };
  1850. };
  1851. };
  1852. };
  1853. deleteResult( result );
  1854. };
  1855. return tVal;
  1856. };
  1857. DBC_PUSHED_CMD *argusDBC::getNodePushedCMD( uint32_t NodeID ){
  1858. DBC_PUSHED_CMD *RetVal = NULL;
  1859. if(m_bIsConnected){
  1860. char tQBuf[CTEXT];
  1861. AAssoc *result;
  1862. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 LIMIT 1", NodeID );
  1863. #ifdef DEBUG_ALL
  1864. LOG(tQBuf);
  1865. #endif
  1866. result = m_pDatabase->Query( tQBuf );
  1867. if( result!= NULL ) {
  1868. if( result->size() > 0 ) {
  1869. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  1870. if( RetVal ) {
  1871. Assoc * cArr;
  1872. Assoc::iterator it;
  1873. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  1874. cArr = result->at(0);
  1875. it = cArr->find("id");
  1876. if( it != cArr->end() ){
  1877. RetVal->id = atoi( it->second.c_str() );
  1878. };
  1879. it = cArr->find("cmd");
  1880. if( it != cArr->end() ){
  1881. RetVal->CMD = atoi( it->second.c_str() );
  1882. };
  1883. it = cArr->find("parameter");
  1884. if( it != cArr->end() ){
  1885. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  1886. RetVal->PARAM[255] = (char)0;
  1887. };
  1888. //Only If Result is Fetched - Clear Current CMD
  1889. sprintf(tQBuf, "DELETE FROM `nodes_qcq` WHERE `id`=%d", RetVal->id );
  1890. m_pDatabase->SilentQuery( tQBuf );
  1891. };
  1892. };
  1893. };
  1894. deleteResult( result );
  1895. };
  1896. return RetVal;
  1897. };
  1898. DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){
  1899. DBC_MODULE_DATA *tVal = NULL;
  1900. if(m_bIsConnected){
  1901. char tQBuf[CTEXT];
  1902. AAssoc *result;
  1903. sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
  1904. #ifdef DEBUG_ALL
  1905. LOG(tQBuf);
  1906. #endif
  1907. result = m_pDatabase->Query( tQBuf );
  1908. if( result!= NULL ) {
  1909. if( result->size() > 0 ) {
  1910. Assoc *cArr;
  1911. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  1912. if( tVal != NULL ) {
  1913. Assoc::iterator it;
  1914. cArr = result->at(0);
  1915. it = cArr->find("id");
  1916. if( it != cArr->end() ){
  1917. tVal->module_id = atoi( it->second.c_str() );
  1918. };
  1919. it = cArr->find("aux_id");
  1920. if( it != cArr->end() ){
  1921. tVal->aux_id = atoi( it->second.c_str() );
  1922. };
  1923. it = cArr->find("type");
  1924. if( it != cArr->end() ){
  1925. tVal->type = atoi( it->second.c_str() );
  1926. };
  1927. it = cArr->find("enabled");
  1928. if( it != cArr->end() ){
  1929. tVal->enabled = (bool)atoi( it->second.c_str() );
  1930. };
  1931. };
  1932. };
  1933. };
  1934. deleteResult( result );
  1935. };
  1936. return tVal;
  1937. };
  1938. /*
  1939. DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
  1940. DBC_SOCKET_DATA *tVal = NULL;
  1941. if(m_bIsConnected){
  1942. char tQBuf[CTEXT];
  1943. AAssoc *result;
  1944. sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );
  1945. #ifdef DEBUG
  1946. //LOG(tQBuf);
  1947. #endif
  1948. result = m_pDatabase->Query( tQBuf );
  1949. if( result!= NULL ) {
  1950. if( result->size() > 0 ) {
  1951. Assoc *cArr;
  1952. tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
  1953. if( tVal != NULL ) {
  1954. Assoc::iterator it;
  1955. cArr = result->at(0);
  1956. it = cArr->find("id");
  1957. if( it != cArr->end() ){
  1958. tVal->socket_id = atoi( it->second.c_str() );
  1959. };
  1960. it = cArr->find("aux_id");
  1961. if( it != cArr->end() ){
  1962. tVal->aux_id = atoi( it->second.c_str() );
  1963. };
  1964. it = cArr->find("type");
  1965. if( it != cArr->end() ){
  1966. tVal->type = atoi( it->second.c_str() );
  1967. };
  1968. it = cArr->find("binded");
  1969. if( it != cArr->end() ){
  1970. tVal->binded = (bool)atoi( it->second.c_str() );
  1971. };
  1972. };
  1973. };
  1974. };
  1975. deleteResult( result );
  1976. };
  1977. return tVal;
  1978. };
  1979. */
  1980. DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){
  1981. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  1982. if(m_bIsConnected){
  1983. char tQBuf[CTEXT];
  1984. AAssoc *result;
  1985. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  1986. #ifdef DEBUG_ALL
  1987. LOG(tQBuf);
  1988. #endif
  1989. result = m_pDatabase->Query( tQBuf );
  1990. if( result!= NULL ) {
  1991. if( result->size() > 0 ) {
  1992. Assoc *cArr;
  1993. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  1994. if( tVal != NULL ) {
  1995. Assoc::iterator it;
  1996. cArr = result->at(0);
  1997. tVal->id = ID;
  1998. it = cArr->find("source_id");
  1999. if( it != cArr->end() ){
  2000. tVal->source_id = atoi( it->second.c_str() );
  2001. };
  2002. it = cArr->find("site_id");
  2003. if( it != cArr->end() ){
  2004. tVal->site_id = atoi( it->second.c_str() );
  2005. };
  2006. it = cArr->find("source_type");
  2007. if( it != cArr->end() ){
  2008. sprintf( tVal->source_type, it->second.c_str() );
  2009. };
  2010. it = cArr->find("valid");
  2011. if( it != cArr->end() ){
  2012. tVal->valid = (bool) atoi( it->second.c_str() );
  2013. };
  2014. it = cArr->find("token");
  2015. if( it != cArr->end() ){
  2016. sprintf( tVal->token, it->second.c_str() );
  2017. };
  2018. it = cArr->find("img_width");
  2019. if( it != cArr->end() ){
  2020. tVal->width = atoi( it->second.c_str() );
  2021. };
  2022. it = cArr->find("img_height");
  2023. if( it != cArr->end() ){
  2024. tVal->height = atoi( it->second.c_str() );
  2025. };
  2026. it = cArr->find("mrl_proto");
  2027. if( it != cArr->end() ){
  2028. sprintf( tVal->mrl_proto, it->second.c_str() );
  2029. };
  2030. it = cArr->find("mrl_port");
  2031. if( it != cArr->end() ){
  2032. tVal->mrl_port = atoi( it->second.c_str() );
  2033. };
  2034. it = cArr->find("mrl");
  2035. if( it != cArr->end() ){
  2036. sprintf( tVal->mrl, it->second.c_str() );
  2037. };
  2038. };
  2039. };
  2040. };
  2041. deleteResult( result );
  2042. };
  2043. return tVal;
  2044. };
  2045. DBC_MEDIA_SERVER_DATA *argusDBC::getMediaServerData( uint32_t ID ){
  2046. DBC_MEDIA_SERVER_DATA *tVal = NULL;
  2047. if(m_bIsConnected){
  2048. char tQBuf[CTEXT];
  2049. AAssoc *result;
  2050. sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
  2051. #ifdef DEBUG_ALL
  2052. LOG(tQBuf);
  2053. #endif
  2054. result = m_pDatabase->Query( tQBuf );
  2055. if( result!= NULL ) {
  2056. if( result->size() > 0 ) {
  2057. Assoc *cArr;
  2058. tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
  2059. if( tVal != NULL ) {
  2060. Assoc::iterator it;
  2061. cArr = result->at(0);
  2062. tVal->id = ID;
  2063. it = cArr->find("secret_key");
  2064. if( it != cArr->end() ){
  2065. sprintf( tVal->key, it->second.c_str() );
  2066. };
  2067. it = cArr->find("ip");
  2068. if( it != cArr->end() ){
  2069. sprintf( tVal->ip, it->second.c_str() );
  2070. };
  2071. it = cArr->find("REST_port");
  2072. if( it != cArr->end() ){
  2073. tVal->port = atoi( it->second.c_str() );
  2074. };
  2075. it = cArr->find("virtual_host");
  2076. if( it != cArr->end() ){
  2077. sprintf( tVal->host, it->second.c_str() );
  2078. };
  2079. it = cArr->find("recording");
  2080. if( it != cArr->end() ){
  2081. tVal->recording = (bool)atoi( it->second.c_str() );
  2082. };
  2083. it = cArr->find("local");
  2084. if( it != cArr->end() ){
  2085. tVal->local = (bool)atoi( it->second.c_str() );
  2086. };
  2087. it = cArr->find("docRoot");
  2088. if( it != cArr->end() ){
  2089. sprintf( tVal->docRoot, it->second.c_str() );
  2090. };
  2091. sprintf( tVal->name,"ZLMedia_%d", tVal->id );
  2092. };
  2093. };
  2094. };
  2095. deleteResult( result );
  2096. };
  2097. return tVal;
  2098. };
  2099. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamDataBySource( uint32_t ID ){
  2100. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2101. if(m_bIsConnected){
  2102. char tQBuf[MAX_PATH_LEN];
  2103. AAssoc *result;
  2104. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
  2105. #ifdef DEBUG_ALL
  2106. LOG(tQBuf);
  2107. #endif
  2108. result = m_pDatabase->Query( tQBuf );
  2109. if( result!= NULL ) {
  2110. if( result->size() > 0 ) {
  2111. Assoc *cArr;
  2112. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2113. if( tVal != NULL ) {
  2114. Assoc::iterator it;
  2115. cArr = result->at(0);
  2116. tVal->id = ID;
  2117. it = cArr->find("media_stream_id");
  2118. if( it != cArr->end() ){
  2119. tVal->media_stream_id = atoi( it->second.c_str() );
  2120. };
  2121. it = cArr->find("online");
  2122. if( it != cArr->end() ){
  2123. tVal->online = atoi( it->second.c_str() );
  2124. };
  2125. it = cArr->find("key");
  2126. if( it != cArr->end() ){
  2127. sprintf( tVal->key, it->second.c_str() );
  2128. };
  2129. it = cArr->find("mrl");
  2130. if( it != cArr->end() ){
  2131. sprintf( tVal->mrl, it->second.c_str() );
  2132. };
  2133. };
  2134. };
  2135. };
  2136. deleteResult( result );
  2137. };
  2138. return tVal;
  2139. };
  2140. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
  2141. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2142. if(m_bIsConnected){
  2143. char tQBuf[MAX_PATH_LEN];
  2144. AAssoc *result;
  2145. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
  2146. #ifdef DEBUG_ALL
  2147. LOG(tQBuf);
  2148. #endif
  2149. result = m_pDatabase->Query( tQBuf );
  2150. if( result!= NULL ) {
  2151. if( result->size() > 0 ) {
  2152. Assoc *cArr;
  2153. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2154. if( tVal != NULL ) {
  2155. Assoc::iterator it;
  2156. cArr = result->at(0);
  2157. tVal->id = ID;
  2158. it = cArr->find("media_stream_id");
  2159. if( it != cArr->end() ){
  2160. tVal->media_stream_id = atoi( it->second.c_str() );
  2161. };
  2162. it = cArr->find("online");
  2163. if( it != cArr->end() ){
  2164. tVal->online = atoi( it->second.c_str() );
  2165. };
  2166. it = cArr->find("key");
  2167. if( it != cArr->end() ){
  2168. sprintf( tVal->key, it->second.c_str() );
  2169. };
  2170. it = cArr->find("mrl");
  2171. if( it != cArr->end() ){
  2172. sprintf( tVal->mrl, it->second.c_str() );
  2173. };
  2174. };
  2175. };
  2176. };
  2177. deleteResult( result );
  2178. };
  2179. return tVal;
  2180. };
  2181. void argusDBC::registerServer(uint32_t SiteID, CSTR identity, int PID ){
  2182. if(m_bIsConnected){
  2183. m_nSiteID = SiteID;
  2184. char tQBuf[CTEXT];
  2185. sprintf(tQBuf,"INSERT INTO servers SET `site_id`=%d, `identity`='%s', `online`=1, `ts`=UNIX_TIMESTAMP(now()), pid=%d ON DUPLICATE KEY UPDATE `ts`=UNIX_TIMESTAMP(now()), `online`=1, pid=%d", SiteID, identity, PID, PID );
  2186. #ifdef DEBUG_ALL
  2187. LOG(tQBuf);
  2188. #endif
  2189. m_pDatabase->SilentQuery( tQBuf );
  2190. // Clenup Nodes and services ...
  2191. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `site_id`=%d ", SiteID );
  2192. #ifdef DEBUG_ALL
  2193. LOG(tQBuf);
  2194. #endif
  2195. m_pDatabase->SilentQuery( tQBuf );
  2196. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  2197. #ifdef DEBUG_ALL
  2198. LOG(tQBuf);
  2199. #endif
  2200. m_pDatabase->SilentQuery( tQBuf );
  2201. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  2202. #ifdef DEBUG_ALL
  2203. LOG(tQBuf);
  2204. #endif
  2205. m_pDatabase->SilentQuery( tQBuf );
  2206. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  2207. #ifdef DEBUG_ALL
  2208. LOG(tQBuf);
  2209. #endif
  2210. m_pDatabase->SilentQuery( tQBuf );
  2211. uint32_t tServerID = getServerID( identity );
  2212. if( tServerID ) {
  2213. 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", m_nSiteID, tServerID );
  2214. #ifdef DEBUG_ALL
  2215. LOG(tQBuf);
  2216. #endif
  2217. uint32_t tServerNodeID = ( uint32_t ) m_pDatabase->QueryID( tQBuf );
  2218. if( tServerNodeID == 0 ){
  2219. tServerNodeID = getServerNode( tServerID );
  2220. };
  2221. //cleanResources( tServerNodeID );
  2222. setNodeOnline( tServerNodeID );
  2223. };
  2224. };
  2225. };
  2226. void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
  2227. if( setNodeOffline( NodeID ) ){
  2228. char tQBuf[CTEXT];
  2229. sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", ServerID );
  2230. #ifdef DEBUG_ALL
  2231. LOG(tQBuf);
  2232. #endif
  2233. m_pDatabase->SilentQuery( tQBuf );
  2234. };
  2235. };
  2236. bool argusDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  2237. if(m_bIsConnected){
  2238. char tQBuf[CTEXT];
  2239. if( NodeID ) {
  2240. sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );
  2241. #ifdef DEBUG_ALL
  2242. LOG(tQBuf);
  2243. #endif
  2244. m_pDatabase->SilentQuery( tQBuf );
  2245. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  2246. #ifdef DEBUG_ALL
  2247. LOG(tQBuf);
  2248. #endif
  2249. m_pDatabase->SilentQuery( tQBuf );
  2250. return true;
  2251. };
  2252. };
  2253. return false;
  2254. };
  2255. bool argusDBC::setNodeOffline( uint32_t NodeID ){
  2256. if(m_bIsConnected){
  2257. char tQBuf[CTEXT];
  2258. if( NodeID ) {
  2259. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  2260. #ifdef DEBUG_ALL
  2261. LOG(tQBuf);
  2262. #endif
  2263. m_pDatabase->SilentQuery( tQBuf );
  2264. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  2265. #ifdef DEBUG_ALL
  2266. LOG(tQBuf);
  2267. #endif
  2268. m_pDatabase->SilentQuery( tQBuf );
  2269. return true;
  2270. };
  2271. };
  2272. return false;
  2273. };
  2274. DBC_RESOURCE_DATA *argusDBC::getResourceData( uint32_t ResourceID ){
  2275. DBC_RESOURCE_DATA *tVal = NULL;
  2276. if( m_bIsConnected ){
  2277. char tQBuf[CTEXT];
  2278. AAssoc *result;
  2279. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );
  2280. #ifdef DEBUG_ALL
  2281. LOG(tQBuf);
  2282. #endif
  2283. result = m_pDatabase->Query( tQBuf );
  2284. if( result!= NULL ) {
  2285. if( result->size() > 0 ) {
  2286. Assoc *cArr;
  2287. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  2288. if( tVal != NULL ) {
  2289. Assoc::iterator it;
  2290. cArr = result->at(0);
  2291. tVal->id = ResourceID;
  2292. it = cArr->find("node_id");
  2293. if( it != cArr->end() ){
  2294. tVal->node_id = atoi( it->second.c_str() );
  2295. };
  2296. it = cArr->find("type");
  2297. if( it != cArr->end() ){
  2298. tVal->type = atoi( it->second.c_str() );
  2299. };
  2300. it = cArr->find("aux_id");
  2301. if( it != cArr->end() ){
  2302. tVal->aux_id = atoi( it->second.c_str() );
  2303. };
  2304. it = cArr->find("device");
  2305. if( it != cArr->end() ){
  2306. strncpy( tVal->device, it->second.c_str(), 64 );
  2307. tVal->device[63] = (char)0;
  2308. };
  2309. };
  2310. };
  2311. };
  2312. deleteResult( result );
  2313. };
  2314. return tVal;
  2315. };
  2316. uint32_t argusDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){
  2317. uint32_t RetVal = 0;
  2318. if(m_bIsConnected){
  2319. char tQBuf[CTEXT];
  2320. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );
  2321. #ifdef DEBUG_ALL
  2322. LOG(tQBuf);
  2323. #endif
  2324. AAssoc *result;
  2325. result = m_pDatabase->Query( tQBuf );
  2326. if( result!= NULL ) {
  2327. if( result->size() > 0 ) {
  2328. Assoc * cArr;
  2329. Assoc::iterator it;
  2330. cArr = result->at(0);
  2331. it = cArr->find("id");
  2332. if( it != cArr->end() ){
  2333. RetVal = atoi( it->second.c_str() );
  2334. };
  2335. };
  2336. };
  2337. deleteResult( result );
  2338. };
  2339. return RetVal;
  2340. };
  2341. uint32_t argusDBC::getServerID( CSTR identity ){
  2342. uint32_t RetVal = 0;
  2343. if(m_bIsConnected){
  2344. char tQBuf[CTEXT];
  2345. sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
  2346. #ifdef DEBUG_ALL
  2347. LOG(tQBuf);
  2348. #endif
  2349. AAssoc *result;
  2350. result = m_pDatabase->Query( tQBuf );
  2351. if( result!= NULL ) {
  2352. if( result->size() > 0 ) {
  2353. Assoc * cArr;
  2354. Assoc::iterator it;
  2355. cArr = result->at(0);
  2356. it = cArr->find("id");
  2357. if( it != cArr->end() ){
  2358. RetVal = atoi( it->second.c_str() );
  2359. };
  2360. };
  2361. };
  2362. deleteResult( result );
  2363. };
  2364. return RetVal;
  2365. };
  2366. uint32_t argusDBC::getServerNode( uint32_t SID ){
  2367. uint32_t RetVal = 0;
  2368. if(m_bIsConnected){
  2369. char tQBuf[CTEXT];
  2370. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  2371. #ifdef DEBUG_ALL
  2372. LOG(tQBuf);
  2373. #endif
  2374. AAssoc *result;
  2375. result = m_pDatabase->Query( tQBuf );
  2376. if( result!= NULL ) {
  2377. if( result->size() > 0 ) {
  2378. Assoc * cArr;
  2379. Assoc::iterator it;
  2380. cArr = result->at(0);
  2381. it = cArr->find("id");
  2382. if( it != cArr->end() ){
  2383. RetVal = atoi( it->second.c_str() );
  2384. };
  2385. };
  2386. };
  2387. deleteResult( result );
  2388. };
  2389. return RetVal;
  2390. };
  2391. uint32_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
  2392. uint32_t RetVal = 0;
  2393. if(m_bIsConnected){
  2394. char tQBuf[1024];
  2395. char tM5[33];
  2396. CSTR tMD5 = MD5String( path );
  2397. if( tMD5 != NULL ) {
  2398. memcpy( tM5, tMD5, 33 );
  2399. tM5[32]=(char)0;
  2400. free( tMD5 );
  2401. 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",
  2402. SiteID, tM5, width, height, path, width, height );
  2403. #ifdef DEBUG_ALL
  2404. LOG(tQBuf);
  2405. #endif
  2406. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2407. };
  2408. };
  2409. return RetVal;
  2410. };
  2411. /*
  2412. uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
  2413. uint32_t retVal = 0;
  2414. if(m_bIsConnected){
  2415. char tQBuf[2048];
  2416. char tM5[33];
  2417. CSTR tMD5 = MD5String( path );
  2418. if( tMD5 != NULL ) {
  2419. memcpy( tM5, tMD5, 33 );
  2420. free( tMD5 );
  2421. if( multidrop ) {
  2422. 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'",
  2423. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  2424. } else {
  2425. 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'",
  2426. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  2427. };
  2428. #ifdef DEBUG
  2429. LOG(tQBuf);
  2430. #endif
  2431. //m_pDatabase->SilentQuery( tQBuf );
  2432. retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2433. };
  2434. };
  2435. return retVal;
  2436. };
  2437. */
  2438. bool argusDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_ID ){
  2439. if(m_bIsConnected){
  2440. char tQBuf[2048];
  2441. sprintf(tQBuf,"INSERT INTO `notifications` SET `site_id`=%d, `ts`=NOW(), `lvl`=%d, `type`=%d, `obj_id`=%d ON DUPLICATE KEY UPDATE `status`='A', `ts`=NOW()", m_nSiteID, DIS_LVL, MSG_ID, OBJ_ID );
  2442. #ifdef DEBUG_ALL
  2443. LOG(tQBuf);
  2444. #endif
  2445. m_pDatabase->SilentQuery( tQBuf );
  2446. return true;
  2447. };
  2448. return false;
  2449. };
  2450. uint32_t argusDBC::addResource( uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID ){
  2451. uint32_t RetVal = 0;
  2452. if( m_bIsConnected ){
  2453. char tQBuf[2048];
  2454. //CSTR tMD5 = MD5String( devName );
  2455. //if( tMD5 ) {
  2456. //sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, tMD5, auxID, devName, auxID, devName );
  2457. sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, auxID, devName, auxID, devName );
  2458. // free( tMD5 );
  2459. #ifdef DEBUG_ALL
  2460. LOG(tQBuf);
  2461. #endif
  2462. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2463. if( RetVal == 0 ) {
  2464. RetVal = getResourceID( NodeID, type, auxID );
  2465. };
  2466. //};
  2467. };
  2468. return RetVal;
  2469. };
  2470. /*
  2471. uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
  2472. uint32_t retVal = 0;
  2473. if(m_bIsConnected){
  2474. char tQBuf[2048];
  2475. char tM5[33];
  2476. CSTR tMD5 = MD5String( path );
  2477. if( tMD5 != NULL ) {
  2478. memcpy( tM5, tMD5, 33 );
  2479. free( tMD5 );
  2480. sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
  2481. #ifdef DEBUG
  2482. LOG(tQBuf);
  2483. #endif
  2484. AAssoc *result;
  2485. result = m_pDatabase->Query( tQBuf );
  2486. if( result!= NULL ) {
  2487. if( result->size() > 0 ) {
  2488. Assoc * cArr;
  2489. Assoc::iterator it;
  2490. cArr = result->at(0);
  2491. it = cArr->find("id");
  2492. if( it != cArr->end() ){
  2493. retVal = atoi( it->second.c_str() );
  2494. };
  2495. };
  2496. };
  2497. deleteResult( result );
  2498. };
  2499. };
  2500. return retVal;
  2501. };
  2502. */
  2503. /*
  2504. CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
  2505. if(m_bIsConnected){
  2506. char tQBuf[CTEXT];
  2507. sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  2508. NodeID, Type );
  2509. #ifdef DEBUG
  2510. LOG(tQBuf);
  2511. #endif
  2512. AAssoc *result;
  2513. result = m_pDatabase->Query( tQBuf );
  2514. if( result!= NULL ) {
  2515. if( result->size() > 0 ) {
  2516. Assoc * cArr;
  2517. Assoc::iterator it;
  2518. cArr = result->at(0);
  2519. it = cArr->find("name");
  2520. if( it != cArr->end() ){
  2521. strncpy( tQBuf, it->second.c_str(), CTEXT );
  2522. };
  2523. };
  2524. };
  2525. deleteResult( result );
  2526. return strdup(tQBuf);
  2527. };
  2528. return NULL;
  2529. };
  2530. */
  2531. KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
  2532. KAFKA_SETTINGS *tVal = NULL;
  2533. if( m_bIsConnected ) {
  2534. char tQBuf[CTEXT];
  2535. AAssoc *result;
  2536. sprintf( tQBuf, "SELECT brocker_address, brocker_port FROM modules_kafka WHERE module_id = %d", ModuleID );
  2537. #ifdef DEBUG_ALL
  2538. LOG(tQBuf);
  2539. #endif
  2540. result = m_pDatabase->Query( tQBuf );
  2541. if( result!= NULL ) {
  2542. if( result->size() > 0 ) {
  2543. Assoc *cArr;
  2544. tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
  2545. if( tVal != NULL ) {
  2546. Assoc::iterator it;
  2547. cArr = result->at(0);
  2548. it = cArr->find("brocker_address");
  2549. if( it != cArr->end() ){
  2550. strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
  2551. };
  2552. it = cArr->find("brocker_port");
  2553. if( it != cArr->end() ){
  2554. tVal->brocker_port = atoi( it->second.c_str() );
  2555. };
  2556. };
  2557. };
  2558. };
  2559. deleteResult( result );
  2560. };
  2561. return tVal;
  2562. };
  2563. KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
  2564. KAFKA_TEMPLATE *tVal = NULL;
  2565. if( m_bIsConnected ) {
  2566. char tQBuf[CTEXT];
  2567. AAssoc *result;
  2568. sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
  2569. #ifdef DEBUG_ALL
  2570. LOG(tQBuf);
  2571. #endif
  2572. result = m_pDatabase->Query( tQBuf );
  2573. if( result!= NULL ) {
  2574. if( result->size() > 0 ) {
  2575. Assoc *cArr;
  2576. tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
  2577. if( tVal != NULL ) {
  2578. Assoc::iterator it;
  2579. cArr = result->at(0);
  2580. it = cArr->find("topic");
  2581. if( it != cArr->end() ){
  2582. memset( tVal->topic, 0, 128 );
  2583. strncpy( tVal->topic , it->second.c_str(), 127 );
  2584. };
  2585. it = cArr->find("template");
  2586. if( it != cArr->end() ){
  2587. tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
  2588. if( tVal->tpl!= NULL) {
  2589. memset( tVal->tpl, 0, it->second.length() + 1 );
  2590. strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
  2591. };
  2592. };
  2593. };
  2594. };
  2595. };
  2596. deleteResult( result );
  2597. };
  2598. return tVal;
  2599. };
  2600. DBC_UART_DATA *argusDBC::getUartData( uint32_t UartID ){
  2601. DBC_UART_DATA *tVal = NULL;
  2602. if( m_bIsConnected ) {
  2603. char tQBuf[MAX_PATH_LEN];
  2604. AAssoc *result;
  2605. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  2606. #ifdef DEBUG_ALL
  2607. LOG(tQBuf);
  2608. #endif
  2609. result = m_pDatabase->Query( tQBuf );
  2610. if( result!= NULL ) {
  2611. if( result->size() > 0 ) {
  2612. Assoc *cArr;
  2613. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  2614. if( tVal != NULL ) {
  2615. Assoc::iterator it;
  2616. cArr = result->at(0);
  2617. it = cArr->find("type");
  2618. if( it != cArr->end() ){
  2619. tVal->type = atoi( it->second.c_str() );
  2620. };
  2621. it = cArr->find("speed");
  2622. if( it != cArr->end() ){
  2623. tVal->speed = atoi( it->second.c_str() );
  2624. };
  2625. it = cArr->find("mode");
  2626. if( it != cArr->end() ){
  2627. tVal->mode = atoi( it->second.c_str() );
  2628. };
  2629. it = cArr->find("port");
  2630. if( it != cArr->end() ){
  2631. tVal->port = atoi( it->second.c_str() );
  2632. };
  2633. it = cArr->find("path");
  2634. if( it != cArr->end() ){
  2635. strncpy( tVal->path, it->second.c_str(), 128 );
  2636. };
  2637. };
  2638. };
  2639. };
  2640. deleteResult( result );
  2641. };
  2642. return tVal;
  2643. };
  2644. uint32_t argusDBC::getUartID( uint32_t RessourceID ){
  2645. uint32_t RetVal = 0;
  2646. if(m_bIsConnected){
  2647. char tQBuf[CTEXT];
  2648. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `resource_id`=%d", RessourceID );
  2649. #ifdef DEBUG_ALL
  2650. LOG(tQBuf);
  2651. #endif
  2652. AAssoc *result;
  2653. result = m_pDatabase->Query( tQBuf );
  2654. if( result!= NULL ) {
  2655. if( result->size() > 0 ) {
  2656. Assoc * cArr;
  2657. Assoc::iterator it;
  2658. cArr = result->at(0);
  2659. it = cArr->find("id");
  2660. if( it != cArr->end() ){
  2661. RetVal = atoi( it->second.c_str() );
  2662. };
  2663. };
  2664. };
  2665. deleteResult( result );
  2666. };
  2667. return RetVal;
  2668. };
  2669. bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
  2670. if( m_bIsConnected ) {
  2671. char tQBuf[MAX_PATH_LEN];
  2672. if( key == NULL ) {
  2673. if( mrl == NULL ) {
  2674. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
  2675. } else {
  2676. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
  2677. };
  2678. } else {
  2679. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
  2680. key,
  2681. mrl,
  2682. id
  2683. );
  2684. };
  2685. #ifdef DEBUG_ALL
  2686. LOG(tQBuf);
  2687. #endif
  2688. m_pDatabase->SilentQuery( tQBuf );
  2689. return true;
  2690. };
  2691. return false;
  2692. };
  2693. bool argusDBC::updateResourceAUX( uint32_t ResID, uint32_t AUX ){
  2694. if( m_bIsConnected ) {
  2695. char tQBuf[MAX_PATH_LEN];
  2696. sprintf( tQBuf, "UPDATE `resources` SET `aux_id`=%d WHERE `id`=%d", AUX, ResID );
  2697. #ifdef DEBUG
  2698. LOG(tQBuf);
  2699. #endif
  2700. m_pDatabase->SilentQuery( tQBuf );
  2701. return true;
  2702. };
  2703. return false;
  2704. };
  2705. bool argusDBC::updateServerUtilisation( uint32_t ServerID, uint32_t nCores, float cpu1, float cpu5, float cpu15, float mem, float disk, uint64_t dtsize, uint64_t dcsize, uint64_t mtsize, uint64_t mcsize ){
  2706. if( m_bIsConnected ) {
  2707. char tQBuf[MAX_PATH_LEN];
  2708. sprintf( tQBuf, "UPDATE `servers` SET `ts`=UNIX_TIMESTAMP(now()), `cpu_cores`=%d, `stat_cpu1`=%0.2f, `stat_cpu5`=%0.2f, `stat_cpu15`=%0.2f, `stat_mem`=%0.2f, `stat_disk`=%0.2f, `val_mem_tottal`=%" PRIu64 ", `val_mem_current`=%" PRIu64 ", `val_disk_tottal`=%" PRIu64 ", `val_disk_current`=%" PRIu64 " WHERE `id`=%d",
  2709. nCores,
  2710. cpu1,
  2711. cpu5,
  2712. cpu15,
  2713. mem,
  2714. disk,
  2715. dtsize,
  2716. dcsize,
  2717. mtsize,
  2718. mcsize,
  2719. ServerID
  2720. );
  2721. #ifdef DEBUG_ALL
  2722. LOG(tQBuf);
  2723. #endif
  2724. m_pDatabase->SilentQuery( tQBuf );
  2725. return true;
  2726. };
  2727. return false;
  2728. };
  2729. uint32_t argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){
  2730. uint32_t RetVal = 0;
  2731. if( m_bIsConnected ) {
  2732. char tQBuf[MAX_PATH_LEN];
  2733. sprintf( tQBuf, "INSERT INTO modules_dcr SET site_id=%d, status=%d, channels=%d, serial_id='%s' ON DUPLICATE KEY UPDATE status=%d, channels=%d",
  2734. SiteID,
  2735. status,
  2736. CNT,
  2737. SERIAL,
  2738. status,
  2739. CNT
  2740. );
  2741. #ifdef DEBUG_ALL
  2742. LOG(tQBuf);
  2743. #endif
  2744. uint64_t cid = m_pDatabase->QueryID( tQBuf );
  2745. if( cid == 0 ) {
  2746. AAssoc *result;
  2747. sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'",
  2748. SiteID,
  2749. SERIAL
  2750. );
  2751. #ifdef DEBUG_ALL
  2752. LOG(tQBuf);
  2753. #endif
  2754. result = m_pDatabase->Query( tQBuf );
  2755. if( result!= NULL ) {
  2756. if( result->size() > 0 ) {
  2757. Assoc * cArr;
  2758. Assoc::iterator it;
  2759. cArr = result->at(0);
  2760. it = cArr->find("id");
  2761. if( it != cArr->end() ){
  2762. cid = atoi( it->second.c_str() );
  2763. };
  2764. };
  2765. deleteResult( result );
  2766. };
  2767. };
  2768. if( cid!= 0 ) {
  2769. for( uint8_t idx = 0; idx < CNT; idx++ ) {
  2770. if( status & ( 1 << idx ) ){
  2771. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'",
  2772. (uint32_t) cid,
  2773. idx
  2774. );
  2775. } else {
  2776. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'",
  2777. (uint32_t) cid,
  2778. idx
  2779. );
  2780. }
  2781. #ifdef DEBUG_ALL
  2782. LOG(tQBuf);
  2783. #endif
  2784. m_pDatabase->SilentQuery( tQBuf );
  2785. };
  2786. };
  2787. };
  2788. return RetVal;
  2789. };
  2790. uint32_t argusDBC::addLocalUART( uint32_t ResID, uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode, uint16_t port ){
  2791. uint32_t RetVal = 0;
  2792. if( m_bIsConnected ) {
  2793. char tQBuf[MAX_PATH_LEN];
  2794. sprintf( tQBuf, "INSERT INTO `uart_settings` SET `resource_id`=%d, `type`=%d, `speed`=%d, `bit`=%d, `parity`='%c', `stop_bit`=%.1f, `mode`=%d, `port`=%d, `path`='%s' ON DUPLICATE KEY UPDATE `id`=`id`",
  2795. ResID,
  2796. utype,
  2797. speed,
  2798. bit,
  2799. parity,
  2800. stop_bit,
  2801. mode,
  2802. port,
  2803. PATH
  2804. );
  2805. #ifdef DEBUG_ALL
  2806. LOG(tQBuf);
  2807. #endif
  2808. RetVal = m_pDatabase->QueryID( tQBuf );
  2809. if( RetVal == 0 ) {
  2810. RetVal = getUartID( ResID );
  2811. };
  2812. };
  2813. return RetVal;
  2814. };
  2815. uint32_t argusDBC::addLocalNIF( CSTR device, CSTR mac, ARGUS_NIF_TYPE dtype ){
  2816. uint32_t RetVal = 0;
  2817. if( m_bIsConnected ) {
  2818. char tQBuf[MAX_PATH_LEN];
  2819. char * tKey = MD5String( device );
  2820. if( tKey != NULL ) {
  2821. sprintf( tQBuf, "INSERT INTO `network_interfaces` SET `type`=%d, `key`='%s', `device_name`='%s', `mac`='%s' ON DUPLICATE KEY UPDATE `id`=`id`",
  2822. dtype,
  2823. tKey,
  2824. device,
  2825. mac
  2826. );
  2827. #ifdef DEBUG
  2828. LOG(tQBuf);
  2829. #endif
  2830. RetVal = m_pDatabase->QueryID( tQBuf );
  2831. if( RetVal == 0 ) {
  2832. RetVal = getNIF_ID( tKey );
  2833. };
  2834. free( tKey );
  2835. };
  2836. };
  2837. return RetVal;
  2838. };
  2839. uint32_t argusDBC::addLocalNetwork( uint32_t NIF_ID, ARGUS_NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){
  2840. uint32_t RetVal = 0;
  2841. if( m_bIsConnected ) {
  2842. char tQBuf[MAX_PATH_LEN];
  2843. sprintf( tQBuf, "INSERT INTO `networks` SET `nif_id`=%d, `type`=%d, `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s' ON DUPLICATE KEY UPDATE `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s'",
  2844. NIF_ID,
  2845. net_type,
  2846. address,
  2847. gateway,
  2848. mask,
  2849. broadcast,
  2850. address,
  2851. gateway,
  2852. mask,
  2853. broadcast
  2854. );
  2855. #ifdef DEBUG_ALL
  2856. LOG(tQBuf);
  2857. #endif
  2858. RetVal = m_pDatabase->QueryID( tQBuf );
  2859. // On Update IF data no need to return ID
  2860. //if( RetVal == 0 ) {
  2861. // RetVal = getNetworkInterfaceID( tKey );
  2862. //};
  2863. };
  2864. return RetVal;
  2865. };
  2866. bool argusDBC::addDraw( uint32_t DBID, uint16_t SIZE, CSTR ID ){
  2867. if( m_bIsConnected ) {
  2868. char tQBuf[MAX_PATH_LEN];
  2869. sprintf( tQBuf,"INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='N'",
  2870. DBID,
  2871. ID,
  2872. SIZE,
  2873. ID,
  2874. SIZE
  2875. );
  2876. #ifdef DEBUG_ALL
  2877. LOG(tQBuf);
  2878. #endif
  2879. m_pDatabase->SilentQuery( tQBuf );
  2880. return true;
  2881. };
  2882. return false;
  2883. };
  2884. uint32_t argusDBC::addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint16_t dig_r, float AZ, float EL, float RANGE, float AREA, float lat, float lon, float alt, uint32_t RefID, CSTR RefUUID ){
  2885. uint32_t RetVal = 0;
  2886. if( m_bIsConnected ) {
  2887. char tQBuf[MAX_PATH_LEN];
  2888. if( RefUUID == NULL ) {
  2889. sprintf( tQBuf,"INSERT INTO events_cloud SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f",
  2890. SRC,
  2891. UUID,
  2892. tss,
  2893. tsms,
  2894. evt_type,
  2895. dig_r,
  2896. AZ,
  2897. EL,
  2898. RANGE,
  2899. AREA,
  2900. lat,
  2901. lon,
  2902. alt
  2903. );
  2904. } else {
  2905. sprintf( tQBuf,"INSERT INTO events_cloud SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f, ref_uuid='%s'",
  2906. SRC,
  2907. UUID,
  2908. tss,
  2909. tsms,
  2910. evt_type,
  2911. dig_r,
  2912. AZ,
  2913. EL,
  2914. RANGE,
  2915. AREA,
  2916. lat,
  2917. lon,
  2918. alt,
  2919. RefUUID
  2920. );
  2921. };
  2922. #ifdef DEBUG_ALL
  2923. LOG(tQBuf);
  2924. #endif
  2925. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2926. };
  2927. return RetVal;
  2928. };
  2929. bool argusDBC::addVideoEvent( uint32_t evtID, uint32_t videoID ){
  2930. if( m_bIsConnected ) {
  2931. char tQBuf[MAX_PATH_LEN];
  2932. sprintf( tQBuf, "INSERT INTO `events_2_videos` SET `evt_id`=%d, `video_id`=%d", evtID, videoID );
  2933. #ifdef DEBUG_ALL
  2934. LOG(tQBuf);
  2935. #endif
  2936. m_pDatabase->SilentQuery( tQBuf );
  2937. return true;
  2938. };
  2939. return true;
  2940. };
  2941. bool argusDBC::addPictureEvent( uint32_t evtID, uint32_t pictureoID ){
  2942. if( m_bIsConnected ) {
  2943. char tQBuf[MAX_PATH_LEN];
  2944. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", evtID, pictureoID );
  2945. #ifdef DEBUG_ALL
  2946. LOG(tQBuf);
  2947. #endif
  2948. m_pDatabase->SilentQuery( tQBuf );
  2949. return true;
  2950. };
  2951. return true;
  2952. };
  2953. uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, uint32_t partID ){
  2954. uint32_t tID = 0;
  2955. if( m_bIsConnected ) {
  2956. char tQBuf[MAX_PATH_LEN];
  2957. sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `part_id`=%d ", streamID, md5, partID );
  2958. #ifdef DEBUG_ALL
  2959. LOG(tQBuf);
  2960. #endif
  2961. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2962. }
  2963. return tID;
  2964. };
  2965. uint32_t argusDBC::addPicture( uint32_t streamID, CSTR md5, CSTR ext ){
  2966. uint32_t tID = 0;
  2967. if( m_bIsConnected ) {
  2968. char tQBuf[MAX_PATH_LEN];
  2969. sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'", streamID, md5, ext );
  2970. #ifdef DEBUG_ALL
  2971. LOG(tQBuf);
  2972. #endif
  2973. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2974. }
  2975. return tID;
  2976. };
  2977. bool argusDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master, uint16_t nOrder, uint16_t nOffset, uint16_t nDelta, uint16_t nWidth, uint16_t nFlip, uint16_t nSun, uint8_t bSST, uint32_t GP, uint32_t spikes ){
  2978. if( m_bIsConnected ) {
  2979. char tQBuf[MAX_PATH_LEN];
  2980. if( master ) {
  2981. sprintf( tQBuf, "UPDATE `lrf_detection_profiles` SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'1'",
  2982. nOrder,
  2983. nOffset,
  2984. nDelta,
  2985. nFlip,
  2986. nWidth,
  2987. bSST,
  2988. nSun,
  2989. GP,
  2990. spikes,
  2991. lrfID,
  2992. profileID );
  2993. } else {
  2994. sprintf( tQBuf, "UPDATE `lrf_detection_profiles` SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'0'",
  2995. nOrder,
  2996. nOffset,
  2997. nDelta,
  2998. nFlip,
  2999. nWidth,
  3000. bSST,
  3001. nSun,
  3002. GP,
  3003. spikes,
  3004. lrfID,
  3005. profileID );
  3006. };
  3007. #ifdef DEBUG_ALL
  3008. LOG(tQBuf);
  3009. #endif
  3010. m_pDatabase->SilentQuery( tQBuf );
  3011. return true;
  3012. };
  3013. return false;
  3014. };
  3015. bool argusDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  3016. if( m_bIsConnected ) {
  3017. char tQBuf[MAX_PATH_LEN];
  3018. CSTR tES = m_pDatabase->escapeString( Serial );
  3019. if( tES ) {
  3020. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  3021. free( tES );
  3022. #ifdef DEBUG_ALL
  3023. LOG(tQBuf);
  3024. #endif
  3025. m_pDatabase->SilentQuery( tQBuf );
  3026. return true;
  3027. };
  3028. };
  3029. return false;
  3030. };
  3031. bool argusDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  3032. if( m_bIsConnected ) {
  3033. char tQBuf[MAX_PATH_LEN];
  3034. CSTR tES = m_pDatabase->escapeString( version );
  3035. if( tES ) {
  3036. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  3037. free( tES );
  3038. #ifdef DEBUG_ALL
  3039. LOG(tQBuf);
  3040. #endif
  3041. m_pDatabase->SilentQuery( tQBuf );
  3042. return true;
  3043. };
  3044. };
  3045. return false;
  3046. };
  3047. bool argusDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  3048. if( m_bIsConnected ) {
  3049. char tQBuf[MAX_PATH_LEN];
  3050. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  3051. #ifdef DEBUG_ALL
  3052. LOG(tQBuf);
  3053. #endif
  3054. m_pDatabase->SilentQuery( tQBuf );
  3055. return true;
  3056. };
  3057. return false;
  3058. };
  3059. bool argusDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  3060. if( m_bIsConnected ) {
  3061. char tQBuf[MAX_PATH_LEN];
  3062. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  3063. #ifdef DEBUG_ALL
  3064. LOG(tQBuf);
  3065. #endif
  3066. m_pDatabase->SilentQuery( tQBuf );
  3067. return true;
  3068. };
  3069. return false;
  3070. };
  3071. bool argusDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  3072. if( m_bIsConnected ) {
  3073. char tQBuf[MAX_PATH_LEN];
  3074. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  3075. #ifdef DEBUG_ALL
  3076. LOG(tQBuf);
  3077. #endif
  3078. m_pDatabase->SilentQuery( tQBuf );
  3079. return true;
  3080. };
  3081. return false;
  3082. };
  3083. bool argusDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  3084. if( m_bIsConnected ) {
  3085. char tQBuf[MAX_PATH_LEN];
  3086. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  3087. #ifdef DEBUG_ALL
  3088. LOG(tQBuf);
  3089. #endif
  3090. m_pDatabase->SilentQuery( tQBuf );
  3091. return true;
  3092. };
  3093. return false;
  3094. };
  3095. bool argusDBC::setStreamValid( uint32_t streamID ){
  3096. if( m_bIsConnected ) {
  3097. char tQBuf[MAX_PATH_LEN];
  3098. sprintf( tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID );
  3099. #ifdef DEBUG_ALL
  3100. LOG(tQBuf);
  3101. #endif
  3102. m_pDatabase->SilentQuery( tQBuf );
  3103. return true;
  3104. };
  3105. return false;
  3106. };
  3107. bool argusDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
  3108. if( m_bIsConnected ) {
  3109. char tQBuf[MAX_PATH_LEN];
  3110. sprintf( tQBuf, "INSERT INTO `target_filter_apf_boxes` SET `filter_id`=%d, `tag`='%s', `ts`=NOW(), `x`=%0.3f, `y`=%0.3f, `z`=%0.3f ON DUPLICATE KEY UPDATE `ts`=NOW(), `x`=%0.3f, `y`=%0.3f, `z`=%0.3f",
  3111. filterID,
  3112. Tag,
  3113. x,y,z,
  3114. x,y,z
  3115. );
  3116. #ifdef DEBUG_ALL
  3117. LOG(tQBuf);
  3118. #endif
  3119. m_pDatabase->SilentQuery( tQBuf );
  3120. return true;
  3121. };
  3122. return false;
  3123. };
  3124. DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){
  3125. DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL;
  3126. if( m_bIsConnected ) {
  3127. char tQBuf[MAX_PATH_LEN];
  3128. AAssoc *result;
  3129. sprintf( tQBuf, "SELECT * FROM `module_embed_video_settings` WHERE `id`=%d", ID );
  3130. #ifdef DEBUG_ALL
  3131. LOG(tQBuf);
  3132. #endif
  3133. result = m_pDatabase->Query( tQBuf );
  3134. if( result!= NULL ) {
  3135. if( result->size() > 0 ) {
  3136. Assoc *cArr;
  3137. tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  3138. if( tPtr!= NULL ) {
  3139. Assoc::iterator it;
  3140. memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  3141. cArr = result->at(0);
  3142. it = cArr->find("web_port");
  3143. if( it != cArr->end() ){
  3144. tPtr->port = atoi( it->second.c_str() );
  3145. };
  3146. it = cArr->find("width");
  3147. if( it != cArr->end() ){
  3148. tPtr->width = atoi( it->second.c_str() );
  3149. };
  3150. it = cArr->find("height");
  3151. if( it != cArr->end() ){
  3152. tPtr->height = atoi( it->second.c_str() );
  3153. };
  3154. it = cArr->find("compression_quality");
  3155. if( it != cArr->end() ){
  3156. tPtr->compression_quality = atoi( it->second.c_str() );
  3157. };
  3158. it = cArr->find("show_ts");
  3159. if( it != cArr->end() ){
  3160. tPtr->show_ts = (bool)atoi( it->second.c_str() );
  3161. };
  3162. it = cArr->find("ts_x");
  3163. if( it != cArr->end() ){
  3164. tPtr->ts_x = atoi( it->second.c_str() );
  3165. };
  3166. it = cArr->find("ts_y");
  3167. if( it != cArr->end() ){
  3168. tPtr->ts_y = atoi( it->second.c_str() );
  3169. };
  3170. it = cArr->find("ts_font_face");
  3171. if( it != cArr->end() ){
  3172. tPtr->ts_font_face = atoi( it->second.c_str() );
  3173. };
  3174. it = cArr->find("ts_font_scale");
  3175. if( it != cArr->end() ){
  3176. tPtr->ts_font_scale = atof( it->second.c_str() );
  3177. };
  3178. it = cArr->find("ts_font_thickness");
  3179. if( it != cArr->end() ){
  3180. tPtr->ts_font_thickness = atoi( it->second.c_str() );
  3181. };
  3182. it = cArr->find("ts_line_type");
  3183. if( it != cArr->end() ){
  3184. tPtr->ts_line_type = atoi( it->second.c_str() );
  3185. };
  3186. it = cArr->find("ts_transperant");
  3187. if( it != cArr->end() ){
  3188. tPtr->ts_transperant = (bool)atoi( it->second.c_str() );
  3189. };
  3190. it = cArr->find("show_label");
  3191. if( it != cArr->end() ){
  3192. tPtr->show_label = (bool)atoi( it->second.c_str() );
  3193. };
  3194. it = cArr->find("label_x");
  3195. if( it != cArr->end() ){
  3196. tPtr->label_x = atoi( it->second.c_str() );
  3197. };
  3198. it = cArr->find("label_y");
  3199. if( it != cArr->end() ){
  3200. tPtr->label_y = atoi( it->second.c_str() );
  3201. };
  3202. it = cArr->find("label_font_face");
  3203. if( it != cArr->end() ){
  3204. tPtr->label_font_face = atoi( it->second.c_str() );
  3205. };
  3206. it = cArr->find("label_font_scale");
  3207. if( it != cArr->end() ){
  3208. tPtr->label_font_scale = atof( it->second.c_str() );
  3209. };
  3210. it = cArr->find("label_font_thickness");
  3211. if( it != cArr->end() ){
  3212. tPtr->label_font_thickness = atoi( it->second.c_str() );
  3213. };
  3214. it = cArr->find("label_line_type");
  3215. if( it != cArr->end() ){
  3216. tPtr->label_line_type = atoi( it->second.c_str() );
  3217. };
  3218. it = cArr->find("label_transperant");
  3219. if( it != cArr->end() ){
  3220. tPtr->label_transperant = (bool) atoi( it->second.c_str() );
  3221. };
  3222. it = cArr->find("show_logo");
  3223. if( it != cArr->end() ){
  3224. tPtr->show_logo = (bool) atoi( it->second.c_str() );
  3225. };
  3226. it = cArr->find("logo_w");
  3227. if( it != cArr->end() ){
  3228. tPtr->logo_w = atoi( it->second.c_str() );
  3229. };
  3230. it = cArr->find("logo_h");
  3231. if( it != cArr->end() ){
  3232. tPtr->logo_h = atoi( it->second.c_str() );
  3233. };
  3234. it = cArr->find("logo_x");
  3235. if( it != cArr->end() ){
  3236. tPtr->logo_x = atoi( it->second.c_str() );
  3237. };
  3238. it = cArr->find("logo_y");
  3239. if( it != cArr->end() ){
  3240. tPtr->logo_y = atoi( it->second.c_str() );
  3241. };
  3242. it = cArr->find("logo_md5");
  3243. if( it != cArr->end() ){
  3244. strncpy( tPtr->logo_md5, it->second.c_str(),32);
  3245. tPtr->logo_md5[32]=(char)0;
  3246. };
  3247. };
  3248. };
  3249. };
  3250. deleteResult( result );
  3251. };
  3252. return tPtr;
  3253. };
  3254. DBC_EVT_DATA *argusDBC::getEventByUUID( CSTR UUID ){
  3255. DBC_EVT_DATA *tPtr = NULL;
  3256. if( m_bIsConnected ) {
  3257. char tQBuf[MAX_PATH_LEN];
  3258. AAssoc *result;
  3259. sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
  3260. #ifdef DEBUG_ALL
  3261. LOG(tQBuf);
  3262. #endif
  3263. result = m_pDatabase->Query( tQBuf );
  3264. if( result!= NULL ) {
  3265. if( result->size() > 0 ) {
  3266. Assoc *cArr;
  3267. tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA));
  3268. if( tPtr!= NULL ) {
  3269. Assoc::iterator it;
  3270. memset(tPtr,0,sizeof(DBC_EVT_DATA));
  3271. cArr = result->at(0);
  3272. it = cArr->find("id");
  3273. if( it != cArr->end() ){
  3274. tPtr->id = atoi( it->second.c_str() );
  3275. };
  3276. it = cArr->find("node_id");
  3277. if( it != cArr->end() ){
  3278. tPtr->node_id = atoi( it->second.c_str() );
  3279. };
  3280. it = cArr->find("uuid");
  3281. if( it != cArr->end() ){
  3282. strncpy( tPtr->uuid, it->second.c_str(),64 );
  3283. };
  3284. it = cArr->find("ts");
  3285. if( it != cArr->end() ){
  3286. tPtr->ts_s = atoi( it->second.c_str() );
  3287. };
  3288. it = cArr->find("ts_ms");
  3289. if( it != cArr->end() ){
  3290. tPtr->ts_ms = atoi( it->second.c_str() );
  3291. };
  3292. it = cArr->find("evt_type");
  3293. if( it != cArr->end() ){
  3294. tPtr->type = atoi( it->second.c_str() );
  3295. };
  3296. it = cArr->find("range_digital");
  3297. if( it != cArr->end() ){
  3298. tPtr->range_digital = atoi( it->second.c_str() );
  3299. };
  3300. it = cArr->find("azimuth");
  3301. if( it != cArr->end() ){
  3302. tPtr->az = atof( it->second.c_str() );
  3303. };
  3304. it = cArr->find("elevation");
  3305. if( it != cArr->end() ){
  3306. tPtr->el = atof( it->second.c_str() );
  3307. };
  3308. it = cArr->find("range");
  3309. if( it != cArr->end() ){
  3310. tPtr->ra = atof( it->second.c_str() );
  3311. };
  3312. it = cArr->find("area");
  3313. if( it != cArr->end() ){
  3314. tPtr->area = atof( it->second.c_str() );
  3315. };
  3316. it = cArr->find("lat");
  3317. if( it != cArr->end() ){
  3318. tPtr->lat = atof( it->second.c_str() );
  3319. };
  3320. it = cArr->find("lon");
  3321. if( it != cArr->end() ){
  3322. tPtr->lon = atof( it->second.c_str() );
  3323. };
  3324. it = cArr->find("alt");
  3325. if( it != cArr->end() ){
  3326. tPtr->alt = atof( it->second.c_str() );
  3327. };
  3328. it = cArr->find("ref_id");
  3329. if( it != cArr->end() ){
  3330. tPtr->ref_id = atoi( it->second.c_str() );
  3331. };
  3332. it = cArr->find("ref_uuid");
  3333. if( it != cArr->end() ){
  3334. strncpy( tPtr->ref_uuid, it->second.c_str(),64 );
  3335. };
  3336. };
  3337. };
  3338. };
  3339. deleteResult( result );
  3340. };
  3341. return tPtr;
  3342. };
  3343. #undef LOG
  3344. #undef LOG_ERROR