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.

3603 lines
131 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("x");
  440. if( it != cArr->end() ){
  441. tVal->x = atof( it->second.c_str() );
  442. };
  443. it = cArr->find("y");
  444. if( it != cArr->end() ){
  445. tVal->y = atof( it->second.c_str() );
  446. };
  447. it = cArr->find("z");
  448. if( it != cArr->end() ){
  449. tVal->z = atof( it->second.c_str() );
  450. };
  451. it = cArr->find("x_rot");
  452. if( it != cArr->end() ){
  453. tVal->x_rot = atof( it->second.c_str() );
  454. };
  455. it = cArr->find("y_rot");
  456. if( it != cArr->end() ){
  457. tVal->y_rot = atof( it->second.c_str() );
  458. };
  459. it = cArr->find("z_rot");
  460. if( it != cArr->end() ){
  461. tVal->z_rot = 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::getNetworkInfrastructureID( uint32_t nif_id ){
  845. uint32_t tVal = 0;
  846. if(m_bIsConnected){
  847. char tQBuf[CTEXT];
  848. AAssoc *result;
  849. sprintf(tQBuf, "SELECT id FROM `network_infrastructure` WHERE `nif_id`=%d", nif_id );
  850. #ifdef DEBUG
  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. uint32_t argusDBC::getWiFi_ID( uint32_t nif_id ){
  870. uint32_t tVal = 0;
  871. if(m_bIsConnected){
  872. char tQBuf[CTEXT];
  873. AAssoc *result;
  874. sprintf(tQBuf, "SELECT `id` FROM `wifis` WHERE `nif_id`=%d", nif_id );
  875. #ifdef DEBUG
  876. LOG(tQBuf);
  877. #endif
  878. result = m_pDatabase->Query( tQBuf );
  879. if( result!= NULL ) {
  880. if( result->size() > 0 ) {
  881. Assoc *cArr;
  882. Assoc::iterator it;
  883. cArr = result->at(0);
  884. it = cArr->find("id");
  885. if( it != cArr->end() ){
  886. tVal = atoi( it->second.c_str() );
  887. };
  888. };
  889. };
  890. deleteResult( result );
  891. };
  892. return tVal;
  893. };
  894. uint32_t argusDBC::getNIF_ID( CSTR key ){
  895. uint32_t tVal = 0;
  896. if(m_bIsConnected){
  897. char tQBuf[CTEXT];
  898. AAssoc *result;
  899. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `key`='%s'", key );
  900. #ifdef DEBUG_EXTRA
  901. LOG(tQBuf);
  902. #endif
  903. result = m_pDatabase->Query( tQBuf );
  904. if( result!= NULL ) {
  905. if( result->size() > 0 ) {
  906. Assoc *cArr;
  907. Assoc::iterator it;
  908. cArr = result->at(0);
  909. it = cArr->find("id");
  910. if( it != cArr->end() ){
  911. tVal = atoi( it->second.c_str() );
  912. };
  913. };
  914. };
  915. deleteResult( result );
  916. };
  917. return tVal;
  918. };
  919. uint32_t argusDBC::getNIF_IDbyDevice( CSTR device ){
  920. uint32_t tVal = 0;
  921. if(m_bIsConnected){
  922. char tQBuf[CTEXT];
  923. AAssoc *result;
  924. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `device_name`='%s'", device );
  925. #ifdef DEBUG
  926. LOG(tQBuf);
  927. #endif
  928. result = m_pDatabase->Query( tQBuf );
  929. if( result!= NULL ) {
  930. if( result->size() > 0 ) {
  931. Assoc *cArr;
  932. Assoc::iterator it;
  933. cArr = result->at(0);
  934. it = cArr->find("id");
  935. if( it != cArr->end() ){
  936. tVal = atoi( it->second.c_str() );
  937. };
  938. };
  939. };
  940. deleteResult( result );
  941. };
  942. return tVal;
  943. };
  944. DBC_NODE_DATA *argusDBC::getNodeData( uint32_t ID ){
  945. DBC_NODE_DATA * tVal = NULL;
  946. if(m_bIsConnected){
  947. char tQBuf[CTEXT];
  948. AAssoc *result;
  949. sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );
  950. #ifdef DEBUG_EXTRA
  951. LOG(tQBuf);
  952. #endif
  953. result = m_pDatabase->Query( tQBuf );
  954. if( result!= NULL ) {
  955. if( result->size() > 0 ) {
  956. Assoc *cArr;
  957. tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
  958. if( tVal != NULL ) {
  959. memset( tVal, 0, sizeof(DBC_NODE_DATA));
  960. Assoc::iterator it;
  961. cArr = result->at(0);
  962. it = cArr->find("id");
  963. if( it != cArr->end() ){
  964. tVal->node_id = atoi( it->second.c_str() );
  965. };
  966. it = cArr->find("type");
  967. if( it != cArr->end() ){
  968. tVal->type = (ARGUS_NODE_TYPE) atoi( it->second.c_str() );
  969. };
  970. it = cArr->find("aux_id");
  971. if( it != cArr->end() ){
  972. tVal->aux_id = atoi( it->second.c_str() );
  973. };
  974. it = cArr->find("aux_parameter");
  975. if( it != cArr->end() ){
  976. tVal->aux_parameter = atoi( it->second.c_str() );
  977. };
  978. it = cArr->find("name");
  979. if( it != cArr->end() ){
  980. sprintf( tVal->name, it->second.c_str() );
  981. };
  982. it = cArr->find("ts_s");
  983. if( it != cArr->end() ){
  984. tVal->tss = atoi( it->second.c_str() );
  985. };
  986. it = cArr->find("ts_ms");
  987. if( it != cArr->end() ){
  988. tVal->tsm = atoi( it->second.c_str() );
  989. };
  990. it = cArr->find("online");
  991. if( it != cArr->end() ){
  992. tVal->online = (bool)atoi( it->second.c_str() );
  993. };
  994. };
  995. };
  996. };
  997. deleteResult( result );
  998. };
  999. return tVal;
  1000. };
  1001. DBC_APF_DATA *argusDBC::getAPFData( uint32_t APFID ){
  1002. DBC_APF_DATA * tVal = NULL;
  1003. if(m_bIsConnected){
  1004. char tQBuf[CTEXT];
  1005. AAssoc *result;
  1006. sprintf(tQBuf, "SELECT * FROM `target_filter_apf` WHERE `id`=%d", APFID );
  1007. #ifdef DEBUG
  1008. LOG(tQBuf);
  1009. #endif
  1010. result = m_pDatabase->Query( tQBuf );
  1011. if( result!= NULL ) {
  1012. if( result->size() > 0 ) {
  1013. Assoc *cArr;
  1014. tVal = (DBC_APF_DATA*) malloc(sizeof(DBC_APF_DATA));
  1015. if( tVal != NULL ) {
  1016. memset( tVal, 0 , sizeof(DBC_APF_DATA));
  1017. Assoc::iterator it;
  1018. cArr = result->at(0);
  1019. it = cArr->find("mode");
  1020. if( it != cArr->end() ){
  1021. sprintf( tVal->mode, it->second.c_str() );
  1022. };
  1023. it = cArr->find("port");
  1024. if( it != cArr->end() ){
  1025. tVal->port = atoi( it->second.c_str() );
  1026. };
  1027. it = cArr->find("lat");
  1028. if( it != cArr->end() ){
  1029. tVal->lat = atof( it->second.c_str() );
  1030. };
  1031. it = cArr->find("lon");
  1032. if( it != cArr->end() ){
  1033. tVal->lon = atof( it->second.c_str() );
  1034. };
  1035. it = cArr->find("alt");
  1036. if( it != cArr->end() ){
  1037. tVal->alt = atof( it->second.c_str() );
  1038. };
  1039. it = cArr->find("roll");
  1040. if( it != cArr->end() ){
  1041. tVal->roll = atof( it->second.c_str() );
  1042. };
  1043. it = cArr->find("pitch");
  1044. if( it != cArr->end() ){
  1045. tVal->pitch = atof( it->second.c_str() );
  1046. };
  1047. it = cArr->find("yaw");
  1048. if( it != cArr->end() ){
  1049. tVal->yaw = atof( it->second.c_str() );
  1050. };
  1051. it = cArr->find("dx");
  1052. if( it != cArr->end() ){
  1053. tVal->dx = atof( it->second.c_str() );
  1054. };
  1055. it = cArr->find("dy");
  1056. if( it != cArr->end() ){
  1057. tVal->dy = atof( it->second.c_str() );
  1058. };
  1059. it = cArr->find("dz");
  1060. if( it != cArr->end() ){
  1061. tVal->dz = atof( it->second.c_str() );
  1062. };
  1063. };
  1064. };
  1065. };
  1066. deleteResult( result );
  1067. };
  1068. return tVal;
  1069. };
  1070. DBC_FH_DATA *argusDBC::getFlyHunterData( uint32_t ID ){
  1071. DBC_FH_DATA * tVal = NULL;
  1072. if(m_bIsConnected){
  1073. char tQBuf[CTEXT];
  1074. AAssoc *result;
  1075. sprintf(tQBuf, "SELECT * FROM `modules_fly_hunter` WHERE `id`=%d", ID );
  1076. #ifdef DEBUG
  1077. LOG(tQBuf);
  1078. #endif
  1079. result = m_pDatabase->Query( tQBuf );
  1080. if( result!= NULL ) {
  1081. if( result->size() > 0 ) {
  1082. Assoc *cArr;
  1083. tVal = (DBC_FH_DATA*) malloc(sizeof(DBC_FH_DATA));
  1084. if( tVal != NULL ) {
  1085. memset( tVal, 0 , sizeof(DBC_FH_DATA));
  1086. Assoc::iterator it;
  1087. cArr = result->at(0);
  1088. it = cArr->find("name");
  1089. if( it != cArr->end() ){
  1090. sprintf( tVal->name, it->second.c_str() );
  1091. };
  1092. it = cArr->find("lat");
  1093. if( it != cArr->end() ){
  1094. tVal->lat = atof( it->second.c_str() );
  1095. };
  1096. it = cArr->find("lon");
  1097. if( it != cArr->end() ){
  1098. tVal->lon = atof( it->second.c_str() );
  1099. };
  1100. it = cArr->find("alt");
  1101. if( it != cArr->end() ){
  1102. tVal->alt = atof( it->second.c_str() );
  1103. };
  1104. it = cArr->find("dc_module_id");
  1105. if( it != cArr->end() ){
  1106. tVal->dc_id = atoi( it->second.c_str() );
  1107. };
  1108. it = cArr->find("uart_id");
  1109. if( it != cArr->end() ){
  1110. tVal->uart_id = atoi( it->second.c_str() );
  1111. };
  1112. };
  1113. };
  1114. };
  1115. deleteResult( result );
  1116. };
  1117. return tVal;
  1118. };
  1119. DBC_SITE_DATA *argusDBC::getSiteData( uint32_t ID ){
  1120. DBC_SITE_DATA * tVal = NULL;
  1121. if(m_bIsConnected){
  1122. char tQBuf[CTEXT];
  1123. AAssoc *result;
  1124. sprintf(tQBuf, "SELECT * FROM sites WHERE `id`=%d", ID );
  1125. #ifdef DEBUG
  1126. LOG(tQBuf);
  1127. #endif
  1128. result = m_pDatabase->Query( tQBuf );
  1129. if( result!= NULL ) {
  1130. if( result->size() > 0 ) {
  1131. Assoc *cArr;
  1132. tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA));
  1133. if( tVal != NULL ) {
  1134. memset( tVal, 0 , sizeof(DBC_SITE_DATA));
  1135. Assoc::iterator it;
  1136. cArr = result->at(0);
  1137. it = cArr->find("account_id");
  1138. if( it != cArr->end() ){
  1139. tVal->account_id = atoi( it->second.c_str() );
  1140. };
  1141. it = cArr->find("name");
  1142. if( it != cArr->end() ){
  1143. sprintf( tVal->name, it->second.c_str() );
  1144. };
  1145. it = cArr->find("server_ident");
  1146. if( it != cArr->end() ){
  1147. sprintf( tVal->ident, it->second.c_str() );
  1148. };
  1149. it = cArr->find("anchor_lat");
  1150. if( it != cArr->end() ){
  1151. tVal->lat = atof( it->second.c_str() );
  1152. };
  1153. it = cArr->find("anchor_lon");
  1154. if( it != cArr->end() ){
  1155. tVal->lon = atof( it->second.c_str() );
  1156. };
  1157. it = cArr->find("anchor_alt");
  1158. if( it != cArr->end() ){
  1159. tVal->alt = atof( it->second.c_str() );
  1160. };
  1161. it = cArr->find("hemisphere");
  1162. if( it != cArr->end() ){
  1163. tVal->SH = ( it->second.c_str()[0] == 'S' );
  1164. };
  1165. it = cArr->find("map_id");
  1166. if( it != cArr->end() ){
  1167. tVal->map_id = atoi( it->second.c_str() );
  1168. };
  1169. };
  1170. };
  1171. };
  1172. deleteResult( result );
  1173. };
  1174. return tVal;
  1175. };
  1176. DBC_TARGET_FLITER_DATA *argusDBC::getTargetFilterData( uint32_t ID ){
  1177. DBC_TARGET_FLITER_DATA * tVal = NULL;
  1178. if(m_bIsConnected){
  1179. char tQBuf[CTEXT];
  1180. AAssoc *result;
  1181. sprintf(tQBuf, "SELECT * FROM target_filters WHERE `id`=%d", ID );
  1182. #ifdef DEBUG
  1183. LOG(tQBuf);
  1184. #endif
  1185. result = m_pDatabase->Query( tQBuf );
  1186. if( result!= NULL ) {
  1187. if( result->size() > 0 ) {
  1188. Assoc *cArr;
  1189. tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA));
  1190. if( tVal != NULL ) {
  1191. memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA));
  1192. Assoc::iterator it;
  1193. tVal->id = ID;
  1194. cArr = result->at(0);
  1195. it = cArr->find("type");
  1196. if( it != cArr->end() ){
  1197. tVal->type = atoi( it->second.c_str() );
  1198. };
  1199. it = cArr->find("aux_id");
  1200. if( it != cArr->end() ){
  1201. tVal->aux_id = atoi( it->second.c_str() );
  1202. };
  1203. };
  1204. };
  1205. };
  1206. deleteResult( result );
  1207. };
  1208. return tVal;
  1209. };
  1210. DBC_LRF_DATA *argusDBC::getLRFData( uint32_t ID ){
  1211. DBC_LRF_DATA * tVal = NULL;
  1212. if(m_bIsConnected){
  1213. char tQBuf[CTEXT];
  1214. AAssoc *result;
  1215. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  1216. #ifdef DEBUG
  1217. LOG(tQBuf);
  1218. #endif
  1219. result = m_pDatabase->Query( tQBuf );
  1220. if( result!= NULL ) {
  1221. if( result->size() > 0 ) {
  1222. Assoc *cArr;
  1223. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  1224. if( tVal != NULL ) {
  1225. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  1226. Assoc::iterator it;
  1227. tVal->id = ID;
  1228. cArr = result->at(0);
  1229. it = cArr->find("data_status");
  1230. if( it != cArr->end() ){
  1231. tVal->data_status = atoi( it->second.c_str() );
  1232. };
  1233. it = cArr->find("serial");
  1234. if( it != cArr->end() ){
  1235. strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 );
  1236. tVal->serial[sizeof(tVal->serial)-1]=(char)0;
  1237. };
  1238. it = cArr->find("version");
  1239. if( it != cArr->end() ){
  1240. strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 );
  1241. tVal->version[sizeof(tVal->version)-1]=(char)0;
  1242. };
  1243. it = cArr->find("x");
  1244. if( it != cArr->end() ){
  1245. tVal->x = atof( it->second.c_str() );
  1246. };
  1247. it = cArr->find("y");
  1248. if( it != cArr->end() ){
  1249. tVal->y = atof( it->second.c_str() );
  1250. };
  1251. it = cArr->find("z");
  1252. if( it != cArr->end() ){
  1253. tVal->z = atof( it->second.c_str() );
  1254. };
  1255. it = cArr->find("x_rot");
  1256. if( it != cArr->end() ){
  1257. tVal->x_rot = atof( it->second.c_str() );
  1258. };
  1259. it = cArr->find("y_rot");
  1260. if( it != cArr->end() ){
  1261. tVal->y_rot = atof( it->second.c_str() );
  1262. };
  1263. it = cArr->find("z_rot");
  1264. if( it != cArr->end() ){
  1265. tVal->z_rot = atof( it->second.c_str() );
  1266. };
  1267. it = cArr->find("uart_id");
  1268. if( it != cArr->end() ){
  1269. tVal->uart_id = atoi( it->second.c_str() );
  1270. };
  1271. it = cArr->find("device_id");
  1272. if( it != cArr->end() ){
  1273. tVal->device_id = atoi( it->second.c_str() );
  1274. };
  1275. it = cArr->find("ip_address");
  1276. if( it != cArr->end() ){
  1277. sprintf( tVal->master_host, it->second.c_str() );
  1278. };
  1279. it = cArr->find("aux_ip_address");
  1280. if( it != cArr->end() ){
  1281. sprintf( tVal->slave_host, it->second.c_str() );
  1282. };
  1283. it = cArr->find("port");
  1284. if( it != cArr->end() ){
  1285. tVal->master_port = atoi( it->second.c_str() );
  1286. };
  1287. it = cArr->find("aux_port");
  1288. if( it != cArr->end() ){
  1289. tVal->slave_port = atoi( it->second.c_str() );
  1290. };
  1291. it = cArr->find("auto_draw");
  1292. if( it != cArr->end() ){
  1293. tVal->auto_draw = atoi( it->second.c_str() );
  1294. };
  1295. it = cArr->find("filter_id");
  1296. if( it != cArr->end() ){
  1297. tVal->filter_id = atoi( it->second.c_str() );
  1298. };
  1299. //it = cArr->find("enabled_lrf");
  1300. //if( it != cArr->end() ){
  1301. // tVal->enabled_lrf = atoi( it->second.c_str() );
  1302. //};
  1303. it = cArr->find("max_range");
  1304. if( it != cArr->end() ){
  1305. tVal->max_range = atof( it->second.c_str() );
  1306. };
  1307. it = cArr->find("base_shift");
  1308. if( it != cArr->end() ){
  1309. tVal->base_shift = atoi( it->second.c_str() );
  1310. };
  1311. it = cArr->find("mirror_shift");
  1312. if( it != cArr->end() ){
  1313. tVal->mirror_shift = atoi( it->second.c_str() );
  1314. };
  1315. it = cArr->find("detection_profile_id");
  1316. if( it != cArr->end() ){
  1317. tVal->detection_profile_id = atoi( it->second.c_str() );
  1318. };
  1319. it = cArr->find("width_table_id");
  1320. if( it != cArr->end() ){
  1321. tVal->width_table_id = atoi( it->second.c_str() );
  1322. };
  1323. it = cArr->find("zoom_table_id");
  1324. if( it != cArr->end() ){
  1325. tVal->zoom_table_id = atoi( it->second.c_str() );
  1326. };
  1327. it = cArr->find("embd_cam");
  1328. if( it != cArr->end() ){
  1329. tVal->embd_cam = atoi( it->second.c_str() );
  1330. };
  1331. it = cArr->find("embd_cam_auto");
  1332. if( it != cArr->end() ){
  1333. tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
  1334. };
  1335. it = cArr->find("embd_dc");
  1336. if( it != cArr->end() ){
  1337. tVal->embd_dc = atoi( it->second.c_str() );
  1338. };
  1339. it = cArr->find("autoreset");
  1340. if( it != cArr->end() ){
  1341. tVal->autoreset = (bool)atoi( it->second.c_str() );
  1342. };
  1343. };
  1344. };
  1345. };
  1346. deleteResult( result );
  1347. };
  1348. return tVal;
  1349. };
  1350. uint8_t argusDBC::getLRFDataStatus( uint32_t ID ){
  1351. uint8_t RetVal = 0;
  1352. if(m_bIsConnected){
  1353. char tQBuf[CTEXT];
  1354. AAssoc *result;
  1355. sprintf(tQBuf, "SELECT * FROM `lrf_sensors` WHERE `id`=%d", ID );
  1356. #ifdef DEBUG
  1357. LOG(tQBuf);
  1358. #endif
  1359. result = m_pDatabase->Query( tQBuf );
  1360. if( result!= NULL ) {
  1361. if( result->size() > 0 ) {
  1362. Assoc *cArr;
  1363. Assoc::iterator it;
  1364. cArr = result->at(0);
  1365. it = cArr->find("data_status");
  1366. if( it != cArr->end() ){
  1367. RetVal = atoi( it->second.c_str() );
  1368. };
  1369. };
  1370. };
  1371. deleteResult( result );
  1372. };
  1373. return RetVal;
  1374. };
  1375. /*
  1376. DBC_PUSHED_CMD *argusDBC::getLRFPushedCMD( uint32_t ID ){
  1377. DBC_PUSHED_CMD *RetVal = NULL;
  1378. if(m_bIsConnected){
  1379. char tQBuf[CTEXT];
  1380. AAssoc *result;
  1381. sprintf(tQBuf, "SELECT `pushed_cmd`, `pushed_param` FROM `lrf_sensors` WHERE `id`=%d AND `pushed_cmd` > 0", ID );
  1382. #ifdef DEBUG
  1383. //LOG(tQBuf);
  1384. #endif
  1385. result = m_pDatabase->Query( tQBuf );
  1386. if( result!= NULL ) {
  1387. if( result->size() > 0 ) {
  1388. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  1389. if( RetVal ) {
  1390. Assoc *cArr;
  1391. Assoc::iterator it;
  1392. cArr = result->at(0);
  1393. it = cArr->find("pushed_cmd");
  1394. if( it != cArr->end() ){
  1395. RetVal->CMD = atoi( it->second.c_str() );
  1396. };
  1397. it = cArr->find("pushed_param");
  1398. if( it != cArr->end() ){
  1399. RetVal->PARAM = atoi( it->second.c_str() );
  1400. };
  1401. };
  1402. };
  1403. //Only If Result is Fetched - Clear Current CMD
  1404. sprintf(tQBuf, "UPDATE `lrf_sensors` SET `pushed_cmd`=0, `pushed_param`=0 WHERE `id`=%d", ID );
  1405. m_pDatabase->SilentQuery( tQBuf );
  1406. };
  1407. deleteResult( result );
  1408. };
  1409. return RetVal;
  1410. };
  1411. */
  1412. DBC_INT_LIST *argusDBC::listModules( uint32_t ServerID ){
  1413. DBC_INT_LIST * tVal = NULL;
  1414. if(m_bIsConnected){
  1415. char tQBuf[CTEXT];
  1416. AAssoc *result;
  1417. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1418. #ifdef DEBUG
  1419. //LOG(tQBuf);
  1420. #endif
  1421. result = m_pDatabase->Query( tQBuf );
  1422. if( result!= NULL ) {
  1423. if( result->size() > 0 ) {
  1424. Assoc *cArr;
  1425. tVal = new DBC_INT_LIST();
  1426. if( tVal != NULL ) {
  1427. Assoc::iterator it;
  1428. for(int i=0;i<result->size();i++) {
  1429. cArr = result->at(i);
  1430. it = cArr->find("id");
  1431. if( it != cArr->end() ){
  1432. tVal->push_back( atoi( it->second.c_str() ));
  1433. };
  1434. };
  1435. };
  1436. };
  1437. };
  1438. deleteResult( result );
  1439. };
  1440. return tVal;
  1441. };
  1442. DBC_INT_LIST *argusDBC::listFilters( uint32_t ServerID ){
  1443. DBC_INT_LIST * tVal = NULL;
  1444. if(m_bIsConnected){
  1445. char tQBuf[CTEXT];
  1446. AAssoc *result;
  1447. sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1448. #ifdef DEBUG_ALL
  1449. LOG(tQBuf);
  1450. #endif
  1451. result = m_pDatabase->Query( tQBuf );
  1452. if( result!= NULL ) {
  1453. if( result->size() > 0 ) {
  1454. Assoc *cArr;
  1455. tVal = new DBC_INT_LIST();
  1456. if( tVal != NULL ) {
  1457. Assoc::iterator it;
  1458. for(int i=0;i<result->size();i++) {
  1459. cArr = result->at(i);
  1460. it = cArr->find("id");
  1461. if( it != cArr->end() ){
  1462. tVal->push_back( atoi( it->second.c_str() ));
  1463. };
  1464. };
  1465. };
  1466. };
  1467. };
  1468. deleteResult( result );
  1469. };
  1470. return tVal;
  1471. };
  1472. DBC_INT_LIST *argusDBC::listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){
  1473. DBC_INT_LIST * tVal = NULL;
  1474. if(m_bIsConnected){
  1475. char tQBuf[CTEXT];
  1476. AAssoc *result;
  1477. switch( listMode ){
  1478. 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;
  1479. 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;
  1480. default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
  1481. };
  1482. #ifdef DEBUG_ALL
  1483. LOG(tQBuf);
  1484. #endif
  1485. result = m_pDatabase->Query( tQBuf );
  1486. if( result!= NULL ) {
  1487. if( result->size() > 0 ) {
  1488. Assoc *cArr;
  1489. tVal = new DBC_INT_LIST();
  1490. if( tVal != NULL ) {
  1491. Assoc::iterator it;
  1492. for(int i=0;i<result->size();i++) {
  1493. cArr = result->at(i);
  1494. it = cArr->find("id");
  1495. if( it != cArr->end() ){
  1496. tVal->push_back( atoi( it->second.c_str() ));
  1497. };
  1498. };
  1499. };
  1500. };
  1501. };
  1502. deleteResult( result );
  1503. };
  1504. return tVal;
  1505. };
  1506. DBC_INT_LIST *argusDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){
  1507. DBC_INT_LIST * tVal = NULL;
  1508. if(m_bIsConnected){
  1509. char tQBuf[CTEXT];
  1510. AAssoc *result;
  1511. switch( listMode ){
  1512. case LIST_VALID_RECORDS:
  1513. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `valid`=1 AND `site_id`=%d", SiteId );
  1514. break;
  1515. case LIST_INVALID_RECORDS:
  1516. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `valid`=0 AND `site_id`=%d", SiteId );
  1517. break;
  1518. default:
  1519. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `site_id`=%d", SiteId );
  1520. };
  1521. #ifdef DEBUG_ALL
  1522. LOG(tQBuf);
  1523. #endif
  1524. result = m_pDatabase->Query( tQBuf );
  1525. if( result!= NULL ) {
  1526. if( result->size() > 0 ) {
  1527. Assoc *cArr;
  1528. tVal = new DBC_INT_LIST();
  1529. if( tVal != NULL ) {
  1530. Assoc::iterator it;
  1531. for(int i=0;i<result->size();i++) {
  1532. cArr = result->at(i);
  1533. it = cArr->find("id");
  1534. if( it != cArr->end() ){
  1535. tVal->push_back( atoi( it->second.c_str() ));
  1536. };
  1537. };
  1538. };
  1539. };
  1540. };
  1541. deleteResult( result );
  1542. };
  1543. return tVal;
  1544. };
  1545. DBC_INT_LIST *argusDBC::listDetectionProfileIDs( uint32_t nodeID ){
  1546. DBC_INT_LIST * tVal = NULL;
  1547. if(m_bIsConnected){
  1548. char tQBuf[CTEXT];
  1549. AAssoc *result;
  1550. sprintf(tQBuf, "SELECT `profile_id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  1551. #ifdef DEBUG_ALL
  1552. LOG(tQBuf);
  1553. #endif
  1554. result = m_pDatabase->Query( tQBuf );
  1555. if( result!= NULL ) {
  1556. if( result->size() > 0 ) {
  1557. Assoc *cArr;
  1558. tVal = new DBC_INT_LIST();
  1559. if( tVal != NULL ) {
  1560. Assoc::iterator it;
  1561. for(int i=0;i<result->size();i++) {
  1562. cArr = result->at(i);
  1563. it = cArr->find("profile_id");
  1564. if( it != cArr->end() ){
  1565. tVal->push_back( atoi( it->second.c_str() ));
  1566. };
  1567. };
  1568. };
  1569. };
  1570. };
  1571. deleteResult( result );
  1572. };
  1573. return tVal;
  1574. };
  1575. DBC_INT_LIST *argusDBC::listDetectionProfiles( uint32_t nodeID ){
  1576. DBC_INT_LIST * tVal = NULL;
  1577. if(m_bIsConnected){
  1578. char tQBuf[CTEXT];
  1579. AAssoc *result;
  1580. sprintf(tQBuf, "SELECT `id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  1581. #ifdef DEBUG_ALL
  1582. LOG(tQBuf);
  1583. #endif
  1584. result = m_pDatabase->Query( tQBuf );
  1585. if( result!= NULL ) {
  1586. if( result->size() > 0 ) {
  1587. Assoc *cArr;
  1588. tVal = new DBC_INT_LIST();
  1589. if( tVal != NULL ) {
  1590. Assoc::iterator it;
  1591. for(int i=0;i<result->size();i++) {
  1592. cArr = result->at(i);
  1593. it = cArr->find("id");
  1594. if( it != cArr->end() ){
  1595. tVal->push_back( atoi( it->second.c_str() ));
  1596. };
  1597. };
  1598. };
  1599. };
  1600. };
  1601. deleteResult( result );
  1602. };
  1603. return tVal;
  1604. };
  1605. /*
  1606. DBC_INT_LIST *argusDBC::listSockets( uint32_t NodeID ){
  1607. DBC_INT_LIST * tVal = NULL;
  1608. if(m_bIsConnected){
  1609. char tQBuf[CTEXT];
  1610. AAssoc *result;
  1611. sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );
  1612. #ifdef DEBUG
  1613. LOG(tQBuf);
  1614. #endif
  1615. result = m_pDatabase->Query( tQBuf );
  1616. if( result!= NULL ) {
  1617. if( result->size() > 0 ) {
  1618. Assoc *cArr;
  1619. tVal = new DBC_INT_LIST();
  1620. if( tVal != NULL ) {
  1621. Assoc::iterator it;
  1622. for(int i=0;i<result->size();i++) {
  1623. cArr = result->at(i);
  1624. it = cArr->find("id");
  1625. if( it != cArr->end() ){
  1626. tVal->push_back( atoi( it->second.c_str() ));
  1627. };
  1628. };
  1629. };
  1630. };
  1631. };
  1632. deleteResult( result );
  1633. };
  1634. return tVal;
  1635. };
  1636. */
  1637. DBC_INT_LIST *argusDBC::listResources( uint32_t NodeID ){
  1638. DBC_INT_LIST * tVal = NULL;
  1639. if(m_bIsConnected){
  1640. char tQBuf[CTEXT];
  1641. AAssoc *result;
  1642. if( NodeID ) {
  1643. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d AND `active`=1 AND `used`=1", NodeID );
  1644. } else {
  1645. 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 AND `re`.`used`=1", m_nSiteID );
  1646. };
  1647. #ifdef DEBUG
  1648. LOG(tQBuf);
  1649. #endif
  1650. result = m_pDatabase->Query( tQBuf );
  1651. if( result!= NULL ) {
  1652. if( result->size() > 0 ) {
  1653. Assoc *cArr;
  1654. tVal = new DBC_INT_LIST();
  1655. if( tVal != NULL ) {
  1656. Assoc::iterator it;
  1657. for(int i=0;i<result->size();i++) {
  1658. cArr = result->at(i);
  1659. it = cArr->find("id");
  1660. if( it != cArr->end() ){
  1661. tVal->push_back( atoi( it->second.c_str() ));
  1662. };
  1663. };
  1664. };
  1665. };
  1666. };
  1667. deleteResult( result );
  1668. };
  1669. return tVal;
  1670. };
  1671. DBC_INT_LIST *argusDBC::listNetworks( uint32_t nif_id ){
  1672. DBC_INT_LIST * tVal = NULL;
  1673. if(m_bIsConnected){
  1674. char tQBuf[CTEXT];
  1675. AAssoc *result;
  1676. sprintf(tQBuf, "SELECT `id` FROM `networks` WHERE `nif_id`=%d", nif_id );
  1677. #ifdef DEBUG_ALL
  1678. LOG(tQBuf);
  1679. #endif
  1680. result = m_pDatabase->Query( tQBuf );
  1681. if( result!= NULL ) {
  1682. if( result->size() > 0 ) {
  1683. Assoc *cArr;
  1684. tVal = new DBC_INT_LIST();
  1685. if( tVal != NULL ) {
  1686. Assoc::iterator it;
  1687. for(int i=0;i<result->size();i++) {
  1688. cArr = result->at(i);
  1689. it = cArr->find("id");
  1690. if( it != cArr->end() ){
  1691. tVal->push_back( atoi( it->second.c_str() ));
  1692. };
  1693. };
  1694. };
  1695. };
  1696. };
  1697. deleteResult( result );
  1698. };
  1699. return tVal;
  1700. };
  1701. DBC_INT_LIST *argusDBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ){
  1702. DBC_INT_LIST * tVal = NULL;
  1703. char tParam[CTEXT];
  1704. //memset( tParam, 0, CTEXT );
  1705. sprintf(tParam,"0");
  1706. if( old_ids != NULL ) {
  1707. char tBuffer[CTEXT];
  1708. for(int i = 0; i< old_ids->size(); i++ ) {
  1709. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  1710. strncpy( tParam, tBuffer, CTEXT );
  1711. };
  1712. };
  1713. if(m_bIsConnected){
  1714. char tQBuf[CTEXT];
  1715. AAssoc *result;
  1716. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", ServerID, tParam );
  1717. #ifdef DEBUG_ALL
  1718. LOG(tQBuf);
  1719. #endif
  1720. result = m_pDatabase->Query( tQBuf );
  1721. if( result!= NULL ) {
  1722. if( result->size() > 0 ) {
  1723. Assoc *cArr;
  1724. tVal = new DBC_INT_LIST();
  1725. if( tVal != NULL ) {
  1726. Assoc::iterator it;
  1727. for(int i=0;i<result->size();i++) {
  1728. cArr = result->at(i);
  1729. it = cArr->find("id");
  1730. if( it != cArr->end() ){
  1731. tVal->push_back( atoi( it->second.c_str() ));
  1732. };
  1733. };
  1734. };
  1735. };
  1736. };
  1737. deleteResult( result );
  1738. };
  1739. return tVal;
  1740. };
  1741. uint32_t argusDBC::getCamId( CSTR UUID ){
  1742. uint32_t RetVal = 0;
  1743. if(m_bIsConnected){
  1744. char tQBuf[CTEXT];
  1745. AAssoc *result;
  1746. sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
  1747. #ifdef DEBUG_ALL
  1748. LOG(tQBuf);
  1749. #endif
  1750. result = m_pDatabase->Query( tQBuf );
  1751. if( result!= NULL ) {
  1752. if( result->size() > 0 ) {
  1753. Assoc *cArr;
  1754. Assoc::iterator it;
  1755. cArr = result->at(0);
  1756. it = cArr->find("id");
  1757. if( it != cArr->end() ){
  1758. RetVal = atoi( it->second.c_str() );
  1759. };
  1760. };
  1761. };
  1762. deleteResult( result );
  1763. };
  1764. return RetVal;
  1765. };
  1766. DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
  1767. DBC_CAM_DATA *tVal = NULL;
  1768. if(m_bIsConnected){
  1769. char tQBuf[CTEXT];
  1770. AAssoc *result;
  1771. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  1772. #ifdef DEBUG_ALL
  1773. LOG(tQBuf);
  1774. #endif
  1775. result = m_pDatabase->Query( tQBuf );
  1776. if( result!= NULL ) {
  1777. if( result->size() > 0 ) {
  1778. Assoc *cArr;
  1779. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  1780. if( tVal != NULL ) {
  1781. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  1782. tVal->id = ID;
  1783. Assoc::iterator it;
  1784. cArr = result->at(0);
  1785. it = cArr->find("site_id");
  1786. if( it != cArr->end() ){
  1787. tVal->site_id = atoi( it->second.c_str() );
  1788. };
  1789. it = cArr->find("node_id");
  1790. if( it != cArr->end() ){
  1791. tVal->node_id = atoi( it->second.c_str() );
  1792. };
  1793. it = cArr->find("online");
  1794. if( it != cArr->end() ){
  1795. tVal->online = (bool) atoi( it->second.c_str() );
  1796. };
  1797. it = cArr->find("type");
  1798. if( it != cArr->end() ){
  1799. tVal->type = atoi( it->second.c_str() );
  1800. };
  1801. it = cArr->find("name");
  1802. if( it != cArr->end() ){
  1803. strncpy( tVal->name, it->second.c_str(), 64 );
  1804. };
  1805. it = cArr->find("hardware");
  1806. if( it != cArr->end() ){
  1807. strncpy( tVal->hardware, it->second.c_str(), 32 );
  1808. };
  1809. it = cArr->find("status");
  1810. if( it != cArr->end() ){
  1811. tVal->status = atoi( it->second.c_str() );
  1812. };
  1813. it = cArr->find("session");
  1814. if( it != cArr->end() ){
  1815. strncpy( tVal->session, it->second.c_str(), 32 );
  1816. };
  1817. it = cArr->find("protocol");
  1818. if( it != cArr->end() ){
  1819. tVal->protocol = atoi( it->second.c_str() );
  1820. };
  1821. it = cArr->find("protocol_aux");
  1822. if( it != cArr->end() ){
  1823. tVal->protocol_aux = atoi( it->second.c_str() );
  1824. };
  1825. it = cArr->find("uart_id");
  1826. if( it != cArr->end() ){
  1827. tVal->uart_id = atoi( it->second.c_str() );
  1828. };
  1829. it = cArr->find("x");
  1830. if( it != cArr->end() ){
  1831. tVal->x = atof( it->second.c_str() );
  1832. };
  1833. it = cArr->find("y");
  1834. if( it != cArr->end() ){
  1835. tVal->y = atof( it->second.c_str() );
  1836. };
  1837. it = cArr->find("z");
  1838. if( it != cArr->end() ){
  1839. tVal->z = atof( it->second.c_str() );
  1840. };
  1841. it = cArr->find("x_rot");
  1842. if( it != cArr->end() ){
  1843. tVal->x_rot = atof( it->second.c_str() );
  1844. };
  1845. it = cArr->find("x_rot");
  1846. if( it != cArr->end() ){
  1847. tVal->y_rot = atof( it->second.c_str() );
  1848. };
  1849. it = cArr->find("x_rot");
  1850. if( it != cArr->end() ){
  1851. tVal->z_rot = atof( it->second.c_str() );
  1852. };
  1853. it = cArr->find("imager_type");
  1854. if( it != cArr->end() ){
  1855. tVal->imager_type = atoi( it->second.c_str() );
  1856. };
  1857. it = cArr->find("min_f");
  1858. if( it != cArr->end() ){
  1859. tVal->min_f = atof( it->second.c_str() );
  1860. };
  1861. it = cArr->find("max_f");
  1862. if( it != cArr->end() ){
  1863. tVal->max_f = atof( it->second.c_str() );
  1864. };
  1865. it = cArr->find("ptz_speed_step");
  1866. if( it != cArr->end() ){
  1867. tVal->ptz_speed_step = atof( it->second.c_str() );
  1868. };
  1869. it = cArr->find("pan_model");
  1870. if( it != cArr->end() ){
  1871. tVal->pan_model = atoi( it->second.c_str() );
  1872. };
  1873. it = cArr->find("pan_angles");
  1874. if( it != cArr->end() ){
  1875. tVal->pan_angles = atoi( it->second.c_str() );
  1876. };
  1877. it = cArr->find("tilt_model");
  1878. if( it != cArr->end() ){
  1879. tVal->tilt_model = atoi( it->second.c_str() );
  1880. };
  1881. it = cArr->find("tilt_angles");
  1882. if( it != cArr->end() ){
  1883. tVal->tilt_angles = atoi( it->second.c_str() );
  1884. };
  1885. it = cArr->find("max_range");
  1886. if( it != cArr->end() ){
  1887. tVal->max_range = atof( it->second.c_str() );
  1888. };
  1889. it = cArr->find("access_login");
  1890. if( it != cArr->end() ){
  1891. strncpy( tVal->username, it->second.c_str(), 16 );
  1892. };
  1893. it = cArr->find("access_pass");
  1894. if( it != cArr->end() ){
  1895. strncpy( tVal->password, it->second.c_str(), 16 );
  1896. };
  1897. it = cArr->find("uuid");
  1898. if( it != cArr->end() ){
  1899. strncpy( tVal->uuid, it->second.c_str(), 64 );
  1900. };
  1901. it = cArr->find("mac");
  1902. if( it != cArr->end() ){
  1903. strncpy( tVal->mac, it->second.c_str(), 16 );
  1904. };
  1905. it = cArr->find("ip");
  1906. if( it != cArr->end() ){
  1907. strncpy( tVal->ip, it->second.c_str(), 16 );
  1908. };
  1909. it = cArr->find("port");
  1910. if( it != cArr->end() ){
  1911. tVal->port = atoi( it->second.c_str() );
  1912. };
  1913. it = cArr->find("onvif_access");
  1914. if( it != cArr->end() ){
  1915. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  1916. };
  1917. it = cArr->find("onvif_ctrl");
  1918. if( it != cArr->end() ){
  1919. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  1920. };
  1921. it = cArr->find("ptz_token");
  1922. if( it != cArr->end() ){
  1923. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  1924. };
  1925. };
  1926. };
  1927. };
  1928. deleteResult( result );
  1929. };
  1930. return tVal;
  1931. };
  1932. DBC_PUSHED_CMD *argusDBC::getNodePushedCMD( uint32_t NodeID ){
  1933. DBC_PUSHED_CMD *RetVal = NULL;
  1934. if(m_bIsConnected){
  1935. char tQBuf[CTEXT];
  1936. AAssoc *result;
  1937. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 LIMIT 1", NodeID );
  1938. #ifdef DEBUG_ALL
  1939. LOG(tQBuf);
  1940. #endif
  1941. result = m_pDatabase->Query( tQBuf );
  1942. if( result!= NULL ) {
  1943. if( result->size() > 0 ) {
  1944. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  1945. if( RetVal ) {
  1946. Assoc * cArr;
  1947. Assoc::iterator it;
  1948. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  1949. cArr = result->at(0);
  1950. it = cArr->find("id");
  1951. if( it != cArr->end() ){
  1952. RetVal->id = atoi( it->second.c_str() );
  1953. };
  1954. it = cArr->find("cmd");
  1955. if( it != cArr->end() ){
  1956. RetVal->CMD = atoi( it->second.c_str() );
  1957. };
  1958. it = cArr->find("parameter");
  1959. if( it != cArr->end() ){
  1960. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  1961. RetVal->PARAM[255] = (char)0;
  1962. };
  1963. //Only If Result is Fetched - Clear Current CMD
  1964. sprintf(tQBuf, "DELETE FROM `nodes_qcq` WHERE `id`=%d", RetVal->id );
  1965. m_pDatabase->SilentQuery( tQBuf );
  1966. };
  1967. };
  1968. };
  1969. deleteResult( result );
  1970. };
  1971. return RetVal;
  1972. };
  1973. DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){
  1974. DBC_MODULE_DATA *tVal = NULL;
  1975. if(m_bIsConnected){
  1976. char tQBuf[CTEXT];
  1977. AAssoc *result;
  1978. sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
  1979. #ifdef DEBUG_ALL
  1980. LOG(tQBuf);
  1981. #endif
  1982. result = m_pDatabase->Query( tQBuf );
  1983. if( result!= NULL ) {
  1984. if( result->size() > 0 ) {
  1985. Assoc *cArr;
  1986. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  1987. if( tVal != NULL ) {
  1988. Assoc::iterator it;
  1989. cArr = result->at(0);
  1990. it = cArr->find("id");
  1991. if( it != cArr->end() ){
  1992. tVal->module_id = atoi( it->second.c_str() );
  1993. };
  1994. it = cArr->find("aux_id");
  1995. if( it != cArr->end() ){
  1996. tVal->aux_id = atoi( it->second.c_str() );
  1997. };
  1998. it = cArr->find("type");
  1999. if( it != cArr->end() ){
  2000. tVal->type = atoi( it->second.c_str() );
  2001. };
  2002. it = cArr->find("enabled");
  2003. if( it != cArr->end() ){
  2004. tVal->enabled = (bool)atoi( it->second.c_str() );
  2005. };
  2006. };
  2007. };
  2008. };
  2009. deleteResult( result );
  2010. };
  2011. return tVal;
  2012. };
  2013. /*
  2014. DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
  2015. DBC_SOCKET_DATA *tVal = NULL;
  2016. if(m_bIsConnected){
  2017. char tQBuf[CTEXT];
  2018. AAssoc *result;
  2019. sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );
  2020. #ifdef DEBUG
  2021. //LOG(tQBuf);
  2022. #endif
  2023. result = m_pDatabase->Query( tQBuf );
  2024. if( result!= NULL ) {
  2025. if( result->size() > 0 ) {
  2026. Assoc *cArr;
  2027. tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
  2028. if( tVal != NULL ) {
  2029. Assoc::iterator it;
  2030. cArr = result->at(0);
  2031. it = cArr->find("id");
  2032. if( it != cArr->end() ){
  2033. tVal->socket_id = atoi( it->second.c_str() );
  2034. };
  2035. it = cArr->find("aux_id");
  2036. if( it != cArr->end() ){
  2037. tVal->aux_id = atoi( it->second.c_str() );
  2038. };
  2039. it = cArr->find("type");
  2040. if( it != cArr->end() ){
  2041. tVal->type = atoi( it->second.c_str() );
  2042. };
  2043. it = cArr->find("binded");
  2044. if( it != cArr->end() ){
  2045. tVal->binded = (bool)atoi( it->second.c_str() );
  2046. };
  2047. };
  2048. };
  2049. };
  2050. deleteResult( result );
  2051. };
  2052. return tVal;
  2053. };
  2054. */
  2055. DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){
  2056. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  2057. if(m_bIsConnected){
  2058. char tQBuf[CTEXT];
  2059. AAssoc *result;
  2060. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  2061. #ifdef DEBUG_ALL
  2062. LOG(tQBuf);
  2063. #endif
  2064. result = m_pDatabase->Query( tQBuf );
  2065. if( result!= NULL ) {
  2066. if( result->size() > 0 ) {
  2067. Assoc *cArr;
  2068. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  2069. if( tVal != NULL ) {
  2070. Assoc::iterator it;
  2071. cArr = result->at(0);
  2072. tVal->id = ID;
  2073. it = cArr->find("source_id");
  2074. if( it != cArr->end() ){
  2075. tVal->source_id = atoi( it->second.c_str() );
  2076. };
  2077. it = cArr->find("site_id");
  2078. if( it != cArr->end() ){
  2079. tVal->site_id = atoi( it->second.c_str() );
  2080. };
  2081. it = cArr->find("source_type");
  2082. if( it != cArr->end() ){
  2083. sprintf( tVal->source_type, it->second.c_str() );
  2084. };
  2085. it = cArr->find("valid");
  2086. if( it != cArr->end() ){
  2087. tVal->valid = (bool) atoi( it->second.c_str() );
  2088. };
  2089. it = cArr->find("token");
  2090. if( it != cArr->end() ){
  2091. sprintf( tVal->token, it->second.c_str() );
  2092. };
  2093. it = cArr->find("img_width");
  2094. if( it != cArr->end() ){
  2095. tVal->width = atoi( it->second.c_str() );
  2096. };
  2097. it = cArr->find("img_height");
  2098. if( it != cArr->end() ){
  2099. tVal->height = atoi( it->second.c_str() );
  2100. };
  2101. it = cArr->find("mrl_proto");
  2102. if( it != cArr->end() ){
  2103. sprintf( tVal->mrl_proto, it->second.c_str() );
  2104. };
  2105. it = cArr->find("mrl_port");
  2106. if( it != cArr->end() ){
  2107. tVal->mrl_port = atoi( it->second.c_str() );
  2108. };
  2109. it = cArr->find("mrl");
  2110. if( it != cArr->end() ){
  2111. sprintf( tVal->mrl, it->second.c_str() );
  2112. };
  2113. };
  2114. };
  2115. };
  2116. deleteResult( result );
  2117. };
  2118. return tVal;
  2119. };
  2120. DBC_MEDIA_SERVER_DATA *argusDBC::getMediaServerData( uint32_t ID ){
  2121. DBC_MEDIA_SERVER_DATA *tVal = NULL;
  2122. if(m_bIsConnected){
  2123. char tQBuf[CTEXT];
  2124. AAssoc *result;
  2125. sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
  2126. #ifdef DEBUG_ALL
  2127. LOG(tQBuf);
  2128. #endif
  2129. result = m_pDatabase->Query( tQBuf );
  2130. if( result!= NULL ) {
  2131. if( result->size() > 0 ) {
  2132. Assoc *cArr;
  2133. tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
  2134. if( tVal != NULL ) {
  2135. Assoc::iterator it;
  2136. cArr = result->at(0);
  2137. tVal->id = ID;
  2138. it = cArr->find("secret_key");
  2139. if( it != cArr->end() ){
  2140. sprintf( tVal->key, it->second.c_str() );
  2141. };
  2142. it = cArr->find("ip");
  2143. if( it != cArr->end() ){
  2144. sprintf( tVal->ip, it->second.c_str() );
  2145. };
  2146. it = cArr->find("REST_port");
  2147. if( it != cArr->end() ){
  2148. tVal->port = atoi( it->second.c_str() );
  2149. };
  2150. it = cArr->find("virtual_host");
  2151. if( it != cArr->end() ){
  2152. sprintf( tVal->host, it->second.c_str() );
  2153. };
  2154. it = cArr->find("recording");
  2155. if( it != cArr->end() ){
  2156. tVal->recording = (bool)atoi( it->second.c_str() );
  2157. };
  2158. it = cArr->find("local");
  2159. if( it != cArr->end() ){
  2160. tVal->local = (bool)atoi( it->second.c_str() );
  2161. };
  2162. it = cArr->find("docRoot");
  2163. if( it != cArr->end() ){
  2164. sprintf( tVal->docRoot, it->second.c_str() );
  2165. };
  2166. sprintf( tVal->name,"ZLMedia_%d", tVal->id );
  2167. };
  2168. };
  2169. };
  2170. deleteResult( result );
  2171. };
  2172. return tVal;
  2173. };
  2174. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamDataBySource( uint32_t ID ){
  2175. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2176. if(m_bIsConnected){
  2177. char tQBuf[MAX_PATH_LEN];
  2178. AAssoc *result;
  2179. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
  2180. #ifdef DEBUG_ALL
  2181. LOG(tQBuf);
  2182. #endif
  2183. result = m_pDatabase->Query( tQBuf );
  2184. if( result!= NULL ) {
  2185. if( result->size() > 0 ) {
  2186. Assoc *cArr;
  2187. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2188. if( tVal != NULL ) {
  2189. Assoc::iterator it;
  2190. cArr = result->at(0);
  2191. tVal->id = ID;
  2192. it = cArr->find("media_stream_id");
  2193. if( it != cArr->end() ){
  2194. tVal->media_stream_id = atoi( it->second.c_str() );
  2195. };
  2196. it = cArr->find("online");
  2197. if( it != cArr->end() ){
  2198. tVal->online = atoi( it->second.c_str() );
  2199. };
  2200. it = cArr->find("key");
  2201. if( it != cArr->end() ){
  2202. sprintf( tVal->key, it->second.c_str() );
  2203. };
  2204. it = cArr->find("mrl");
  2205. if( it != cArr->end() ){
  2206. sprintf( tVal->mrl, it->second.c_str() );
  2207. };
  2208. };
  2209. };
  2210. };
  2211. deleteResult( result );
  2212. };
  2213. return tVal;
  2214. };
  2215. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
  2216. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2217. if(m_bIsConnected){
  2218. char tQBuf[MAX_PATH_LEN];
  2219. AAssoc *result;
  2220. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
  2221. #ifdef DEBUG_ALL
  2222. LOG(tQBuf);
  2223. #endif
  2224. result = m_pDatabase->Query( tQBuf );
  2225. if( result!= NULL ) {
  2226. if( result->size() > 0 ) {
  2227. Assoc *cArr;
  2228. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2229. if( tVal != NULL ) {
  2230. Assoc::iterator it;
  2231. cArr = result->at(0);
  2232. tVal->id = ID;
  2233. it = cArr->find("media_stream_id");
  2234. if( it != cArr->end() ){
  2235. tVal->media_stream_id = atoi( it->second.c_str() );
  2236. };
  2237. it = cArr->find("online");
  2238. if( it != cArr->end() ){
  2239. tVal->online = atoi( it->second.c_str() );
  2240. };
  2241. it = cArr->find("key");
  2242. if( it != cArr->end() ){
  2243. sprintf( tVal->key, it->second.c_str() );
  2244. };
  2245. it = cArr->find("mrl");
  2246. if( it != cArr->end() ){
  2247. sprintf( tVal->mrl, it->second.c_str() );
  2248. };
  2249. };
  2250. };
  2251. };
  2252. deleteResult( result );
  2253. };
  2254. return tVal;
  2255. };
  2256. void argusDBC::registerServer(uint32_t SiteID, CSTR identity, int PID ){
  2257. if(m_bIsConnected){
  2258. m_nSiteID = SiteID;
  2259. char tQBuf[CTEXT];
  2260. 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 );
  2261. #ifdef DEBUG_ALL
  2262. LOG(tQBuf);
  2263. #endif
  2264. m_pDatabase->SilentQuery( tQBuf );
  2265. // Clenup Nodes and services ...
  2266. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `site_id`=%d ", SiteID );
  2267. #ifdef DEBUG_ALL
  2268. LOG(tQBuf);
  2269. #endif
  2270. m_pDatabase->SilentQuery( tQBuf );
  2271. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  2272. #ifdef DEBUG_ALL
  2273. LOG(tQBuf);
  2274. #endif
  2275. m_pDatabase->SilentQuery( tQBuf );
  2276. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  2277. #ifdef DEBUG_ALL
  2278. LOG(tQBuf);
  2279. #endif
  2280. m_pDatabase->SilentQuery( tQBuf );
  2281. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  2282. #ifdef DEBUG_ALL
  2283. LOG(tQBuf);
  2284. #endif
  2285. m_pDatabase->SilentQuery( tQBuf );
  2286. uint32_t tServerID = getServerID( identity );
  2287. if( tServerID ) {
  2288. 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 );
  2289. #ifdef DEBUG_ALL
  2290. LOG(tQBuf);
  2291. #endif
  2292. uint32_t tServerNodeID = ( uint32_t ) m_pDatabase->QueryID( tQBuf );
  2293. if( tServerNodeID == 0 ){
  2294. tServerNodeID = getServerNode( tServerID );
  2295. };
  2296. //cleanResources( tServerNodeID );
  2297. setNodeOnline( tServerNodeID );
  2298. };
  2299. };
  2300. };
  2301. void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
  2302. if( setNodeOffline( NodeID ) ){
  2303. char tQBuf[CTEXT];
  2304. sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", ServerID );
  2305. #ifdef DEBUG_ALL
  2306. LOG(tQBuf);
  2307. #endif
  2308. m_pDatabase->SilentQuery( tQBuf );
  2309. };
  2310. };
  2311. bool argusDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  2312. if(m_bIsConnected){
  2313. char tQBuf[CTEXT];
  2314. if( NodeID ) {
  2315. sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );
  2316. #ifdef DEBUG_ALL
  2317. LOG(tQBuf);
  2318. #endif
  2319. m_pDatabase->SilentQuery( tQBuf );
  2320. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  2321. #ifdef DEBUG_ALL
  2322. LOG(tQBuf);
  2323. #endif
  2324. m_pDatabase->SilentQuery( tQBuf );
  2325. return true;
  2326. };
  2327. };
  2328. return false;
  2329. };
  2330. bool argusDBC::setNodeOffline( uint32_t NodeID ){
  2331. if(m_bIsConnected){
  2332. char tQBuf[CTEXT];
  2333. if( NodeID ) {
  2334. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  2335. #ifdef DEBUG_ALL
  2336. LOG(tQBuf);
  2337. #endif
  2338. m_pDatabase->SilentQuery( tQBuf );
  2339. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  2340. #ifdef DEBUG_ALL
  2341. LOG(tQBuf);
  2342. #endif
  2343. m_pDatabase->SilentQuery( tQBuf );
  2344. return true;
  2345. };
  2346. };
  2347. return false;
  2348. };
  2349. DBC_RESOURCE_DATA *argusDBC::getResourceData( uint32_t ResourceID ){
  2350. DBC_RESOURCE_DATA *tVal = NULL;
  2351. if( m_bIsConnected ){
  2352. char tQBuf[CTEXT];
  2353. AAssoc *result;
  2354. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );
  2355. #ifdef DEBUG_ALL
  2356. LOG(tQBuf);
  2357. #endif
  2358. result = m_pDatabase->Query( tQBuf );
  2359. if( result!= NULL ) {
  2360. if( result->size() > 0 ) {
  2361. Assoc *cArr;
  2362. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  2363. if( tVal != NULL ) {
  2364. Assoc::iterator it;
  2365. cArr = result->at(0);
  2366. tVal->id = ResourceID;
  2367. it = cArr->find("node_id");
  2368. if( it != cArr->end() ){
  2369. tVal->node_id = atoi( it->second.c_str() );
  2370. };
  2371. it = cArr->find("type");
  2372. if( it != cArr->end() ){
  2373. tVal->type = atoi( it->second.c_str() );
  2374. };
  2375. it = cArr->find("aux_id");
  2376. if( it != cArr->end() ){
  2377. tVal->aux_id = atoi( it->second.c_str() );
  2378. };
  2379. it = cArr->find("device");
  2380. if( it != cArr->end() ){
  2381. strncpy( tVal->device, it->second.c_str(), 64 );
  2382. tVal->device[63] = (char)0;
  2383. };
  2384. };
  2385. };
  2386. };
  2387. deleteResult( result );
  2388. };
  2389. return tVal;
  2390. };
  2391. uint32_t argusDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){
  2392. uint32_t RetVal = 0;
  2393. if(m_bIsConnected){
  2394. char tQBuf[CTEXT];
  2395. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );
  2396. #ifdef DEBUG_ALL
  2397. LOG(tQBuf);
  2398. #endif
  2399. AAssoc *result;
  2400. result = m_pDatabase->Query( tQBuf );
  2401. if( result!= NULL ) {
  2402. if( result->size() > 0 ) {
  2403. Assoc * cArr;
  2404. Assoc::iterator it;
  2405. cArr = result->at(0);
  2406. it = cArr->find("id");
  2407. if( it != cArr->end() ){
  2408. RetVal = atoi( it->second.c_str() );
  2409. };
  2410. };
  2411. };
  2412. deleteResult( result );
  2413. };
  2414. return RetVal;
  2415. };
  2416. uint32_t argusDBC::getServerID( CSTR identity ){
  2417. uint32_t RetVal = 0;
  2418. if(m_bIsConnected){
  2419. char tQBuf[CTEXT];
  2420. sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
  2421. #ifdef DEBUG_ALL
  2422. LOG(tQBuf);
  2423. #endif
  2424. AAssoc *result;
  2425. result = m_pDatabase->Query( tQBuf );
  2426. if( result!= NULL ) {
  2427. if( result->size() > 0 ) {
  2428. Assoc * cArr;
  2429. Assoc::iterator it;
  2430. cArr = result->at(0);
  2431. it = cArr->find("id");
  2432. if( it != cArr->end() ){
  2433. RetVal = atoi( it->second.c_str() );
  2434. };
  2435. };
  2436. };
  2437. deleteResult( result );
  2438. };
  2439. return RetVal;
  2440. };
  2441. uint32_t argusDBC::getServerNode( uint32_t SID ){
  2442. uint32_t RetVal = 0;
  2443. if(m_bIsConnected){
  2444. char tQBuf[CTEXT];
  2445. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  2446. #ifdef DEBUG_ALL
  2447. LOG(tQBuf);
  2448. #endif
  2449. AAssoc *result;
  2450. result = m_pDatabase->Query( tQBuf );
  2451. if( result!= NULL ) {
  2452. if( result->size() > 0 ) {
  2453. Assoc * cArr;
  2454. Assoc::iterator it;
  2455. cArr = result->at(0);
  2456. it = cArr->find("id");
  2457. if( it != cArr->end() ){
  2458. RetVal = atoi( it->second.c_str() );
  2459. };
  2460. };
  2461. };
  2462. deleteResult( result );
  2463. };
  2464. return RetVal;
  2465. };
  2466. uint32_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
  2467. uint32_t RetVal = 0;
  2468. if(m_bIsConnected){
  2469. char tQBuf[1024];
  2470. char tM5[33];
  2471. CSTR tMD5 = MD5String( path );
  2472. if( tMD5 != NULL ) {
  2473. memcpy( tM5, tMD5, 33 );
  2474. tM5[32]=(char)0;
  2475. free( tMD5 );
  2476. 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",
  2477. SiteID, tM5, width, height, path, width, height );
  2478. #ifdef DEBUG_ALL
  2479. LOG(tQBuf);
  2480. #endif
  2481. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2482. };
  2483. };
  2484. return RetVal;
  2485. };
  2486. /*
  2487. uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
  2488. uint32_t retVal = 0;
  2489. if(m_bIsConnected){
  2490. char tQBuf[2048];
  2491. char tM5[33];
  2492. CSTR tMD5 = MD5String( path );
  2493. if( tMD5 != NULL ) {
  2494. memcpy( tM5, tMD5, 33 );
  2495. free( tMD5 );
  2496. if( multidrop ) {
  2497. 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'",
  2498. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  2499. } else {
  2500. 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'",
  2501. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  2502. };
  2503. #ifdef DEBUG
  2504. LOG(tQBuf);
  2505. #endif
  2506. //m_pDatabase->SilentQuery( tQBuf );
  2507. retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2508. };
  2509. };
  2510. return retVal;
  2511. };
  2512. */
  2513. bool argusDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_ID ){
  2514. if(m_bIsConnected){
  2515. char tQBuf[2048];
  2516. 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 );
  2517. #ifdef DEBUG_ALL
  2518. LOG(tQBuf);
  2519. #endif
  2520. m_pDatabase->SilentQuery( tQBuf );
  2521. return true;
  2522. };
  2523. return false;
  2524. };
  2525. uint32_t argusDBC::addResource( uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID ){
  2526. uint32_t RetVal = 0;
  2527. if( m_bIsConnected ){
  2528. char tQBuf[2048];
  2529. //CSTR tMD5 = MD5String( devName );
  2530. //if( tMD5 ) {
  2531. //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 );
  2532. 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 );
  2533. // free( tMD5 );
  2534. #ifdef DEBUG_ALL
  2535. LOG(tQBuf);
  2536. #endif
  2537. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2538. if( RetVal == 0 ) {
  2539. RetVal = getResourceID( NodeID, type, auxID );
  2540. };
  2541. //};
  2542. };
  2543. return RetVal;
  2544. };
  2545. /*
  2546. uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
  2547. uint32_t retVal = 0;
  2548. if(m_bIsConnected){
  2549. char tQBuf[2048];
  2550. char tM5[33];
  2551. CSTR tMD5 = MD5String( path );
  2552. if( tMD5 != NULL ) {
  2553. memcpy( tM5, tMD5, 33 );
  2554. free( tMD5 );
  2555. sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
  2556. #ifdef DEBUG
  2557. LOG(tQBuf);
  2558. #endif
  2559. AAssoc *result;
  2560. result = m_pDatabase->Query( tQBuf );
  2561. if( result!= NULL ) {
  2562. if( result->size() > 0 ) {
  2563. Assoc * cArr;
  2564. Assoc::iterator it;
  2565. cArr = result->at(0);
  2566. it = cArr->find("id");
  2567. if( it != cArr->end() ){
  2568. retVal = atoi( it->second.c_str() );
  2569. };
  2570. };
  2571. };
  2572. deleteResult( result );
  2573. };
  2574. };
  2575. return retVal;
  2576. };
  2577. */
  2578. /*
  2579. CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
  2580. if(m_bIsConnected){
  2581. char tQBuf[CTEXT];
  2582. sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  2583. NodeID, Type );
  2584. #ifdef DEBUG
  2585. LOG(tQBuf);
  2586. #endif
  2587. AAssoc *result;
  2588. result = m_pDatabase->Query( tQBuf );
  2589. if( result!= NULL ) {
  2590. if( result->size() > 0 ) {
  2591. Assoc * cArr;
  2592. Assoc::iterator it;
  2593. cArr = result->at(0);
  2594. it = cArr->find("name");
  2595. if( it != cArr->end() ){
  2596. strncpy( tQBuf, it->second.c_str(), CTEXT );
  2597. };
  2598. };
  2599. };
  2600. deleteResult( result );
  2601. return strdup(tQBuf);
  2602. };
  2603. return NULL;
  2604. };
  2605. */
  2606. KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
  2607. KAFKA_SETTINGS *tVal = NULL;
  2608. if( m_bIsConnected ) {
  2609. char tQBuf[CTEXT];
  2610. AAssoc *result;
  2611. sprintf( tQBuf, "SELECT brocker_address, brocker_port FROM modules_kafka WHERE module_id = %d", ModuleID );
  2612. #ifdef DEBUG_ALL
  2613. LOG(tQBuf);
  2614. #endif
  2615. result = m_pDatabase->Query( tQBuf );
  2616. if( result!= NULL ) {
  2617. if( result->size() > 0 ) {
  2618. Assoc *cArr;
  2619. tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
  2620. if( tVal != NULL ) {
  2621. Assoc::iterator it;
  2622. cArr = result->at(0);
  2623. it = cArr->find("brocker_address");
  2624. if( it != cArr->end() ){
  2625. strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
  2626. };
  2627. it = cArr->find("brocker_port");
  2628. if( it != cArr->end() ){
  2629. tVal->brocker_port = atoi( it->second.c_str() );
  2630. };
  2631. };
  2632. };
  2633. };
  2634. deleteResult( result );
  2635. };
  2636. return tVal;
  2637. };
  2638. KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
  2639. KAFKA_TEMPLATE *tVal = NULL;
  2640. if( m_bIsConnected ) {
  2641. char tQBuf[CTEXT];
  2642. AAssoc *result;
  2643. sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
  2644. #ifdef DEBUG_ALL
  2645. LOG(tQBuf);
  2646. #endif
  2647. result = m_pDatabase->Query( tQBuf );
  2648. if( result!= NULL ) {
  2649. if( result->size() > 0 ) {
  2650. Assoc *cArr;
  2651. tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
  2652. if( tVal != NULL ) {
  2653. Assoc::iterator it;
  2654. cArr = result->at(0);
  2655. it = cArr->find("topic");
  2656. if( it != cArr->end() ){
  2657. memset( tVal->topic, 0, 128 );
  2658. strncpy( tVal->topic , it->second.c_str(), 127 );
  2659. };
  2660. it = cArr->find("template");
  2661. if( it != cArr->end() ){
  2662. tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
  2663. if( tVal->tpl!= NULL) {
  2664. memset( tVal->tpl, 0, it->second.length() + 1 );
  2665. strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
  2666. };
  2667. };
  2668. };
  2669. };
  2670. };
  2671. deleteResult( result );
  2672. };
  2673. return tVal;
  2674. };
  2675. DBC_UART_DATA *argusDBC::getUartData( uint32_t UartID ){
  2676. DBC_UART_DATA *tVal = NULL;
  2677. if( m_bIsConnected ) {
  2678. char tQBuf[MAX_PATH_LEN];
  2679. AAssoc *result;
  2680. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  2681. #ifdef DEBUG_ALL
  2682. LOG(tQBuf);
  2683. #endif
  2684. result = m_pDatabase->Query( tQBuf );
  2685. if( result!= NULL ) {
  2686. if( result->size() > 0 ) {
  2687. Assoc *cArr;
  2688. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  2689. if( tVal != NULL ) {
  2690. Assoc::iterator it;
  2691. cArr = result->at(0);
  2692. it = cArr->find("type");
  2693. if( it != cArr->end() ){
  2694. tVal->type = atoi( it->second.c_str() );
  2695. };
  2696. it = cArr->find("speed");
  2697. if( it != cArr->end() ){
  2698. tVal->speed = atoi( it->second.c_str() );
  2699. };
  2700. it = cArr->find("mode");
  2701. if( it != cArr->end() ){
  2702. tVal->mode = atoi( it->second.c_str() );
  2703. };
  2704. it = cArr->find("port");
  2705. if( it != cArr->end() ){
  2706. tVal->port = atoi( it->second.c_str() );
  2707. };
  2708. it = cArr->find("path");
  2709. if( it != cArr->end() ){
  2710. strncpy( tVal->path, it->second.c_str(), 128 );
  2711. };
  2712. };
  2713. };
  2714. };
  2715. deleteResult( result );
  2716. };
  2717. return tVal;
  2718. };
  2719. uint32_t argusDBC::getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){
  2720. uint32_t RetVal = 0;
  2721. if(m_bIsConnected){
  2722. char tQBuf[CTEXT];
  2723. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path );
  2724. #ifdef DEBUG_ALL
  2725. LOG(tQBuf);
  2726. #endif
  2727. AAssoc *result;
  2728. result = m_pDatabase->Query( tQBuf );
  2729. if( result!= NULL ) {
  2730. if( result->size() > 0 ) {
  2731. Assoc * cArr;
  2732. Assoc::iterator it;
  2733. cArr = result->at(0);
  2734. it = cArr->find("id");
  2735. if( it != cArr->end() ){
  2736. RetVal = atoi( it->second.c_str() );
  2737. };
  2738. };
  2739. };
  2740. deleteResult( result );
  2741. };
  2742. return RetVal;
  2743. };
  2744. bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
  2745. if( m_bIsConnected ) {
  2746. char tQBuf[MAX_PATH_LEN];
  2747. if( key == NULL ) {
  2748. if( mrl == NULL ) {
  2749. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
  2750. } else {
  2751. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
  2752. };
  2753. } else {
  2754. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
  2755. key,
  2756. mrl,
  2757. id
  2758. );
  2759. };
  2760. #ifdef DEBUG_ALL
  2761. LOG(tQBuf);
  2762. #endif
  2763. m_pDatabase->SilentQuery( tQBuf );
  2764. return true;
  2765. };
  2766. return false;
  2767. };
  2768. bool argusDBC::updateResourceAUX( uint32_t ResID, uint32_t AUX ){
  2769. if( m_bIsConnected ) {
  2770. char tQBuf[MAX_PATH_LEN];
  2771. sprintf( tQBuf, "UPDATE `resources` SET `aux_id`=%d WHERE `id`=%d", AUX, ResID );
  2772. #ifdef DEBUG
  2773. LOG(tQBuf);
  2774. #endif
  2775. m_pDatabase->SilentQuery( tQBuf );
  2776. return true;
  2777. };
  2778. return false;
  2779. };
  2780. 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 ){
  2781. if( m_bIsConnected ) {
  2782. char tQBuf[MAX_PATH_LEN];
  2783. 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",
  2784. nCores,
  2785. cpu1,
  2786. cpu5,
  2787. cpu15,
  2788. mem,
  2789. disk,
  2790. dtsize,
  2791. dcsize,
  2792. mtsize,
  2793. mcsize,
  2794. ServerID
  2795. );
  2796. #ifdef DEBUG_ALL
  2797. LOG(tQBuf);
  2798. #endif
  2799. m_pDatabase->SilentQuery( tQBuf );
  2800. return true;
  2801. };
  2802. return false;
  2803. };
  2804. uint32_t argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){
  2805. uint32_t RetVal = 0;
  2806. if( m_bIsConnected ) {
  2807. char tQBuf[MAX_PATH_LEN];
  2808. 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",
  2809. SiteID,
  2810. status,
  2811. CNT,
  2812. SERIAL,
  2813. status,
  2814. CNT
  2815. );
  2816. #ifdef DEBUG_ALL
  2817. LOG(tQBuf);
  2818. #endif
  2819. uint64_t cid = m_pDatabase->QueryID( tQBuf );
  2820. if( cid == 0 ) {
  2821. AAssoc *result;
  2822. sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'",
  2823. SiteID,
  2824. SERIAL
  2825. );
  2826. #ifdef DEBUG_ALL
  2827. LOG(tQBuf);
  2828. #endif
  2829. result = m_pDatabase->Query( tQBuf );
  2830. if( result!= NULL ) {
  2831. if( result->size() > 0 ) {
  2832. Assoc * cArr;
  2833. Assoc::iterator it;
  2834. cArr = result->at(0);
  2835. it = cArr->find("id");
  2836. if( it != cArr->end() ){
  2837. cid = atoi( it->second.c_str() );
  2838. };
  2839. };
  2840. deleteResult( result );
  2841. };
  2842. };
  2843. if( cid!= 0 ) {
  2844. for( uint8_t idx = 0; idx < CNT; idx++ ) {
  2845. if( status & ( 1 << idx ) ){
  2846. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'",
  2847. (uint32_t) cid,
  2848. idx
  2849. );
  2850. } else {
  2851. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'",
  2852. (uint32_t) cid,
  2853. idx
  2854. );
  2855. }
  2856. #ifdef DEBUG_ALL
  2857. LOG(tQBuf);
  2858. #endif
  2859. m_pDatabase->SilentQuery( tQBuf );
  2860. };
  2861. };
  2862. };
  2863. return RetVal;
  2864. };
  2865. uint32_t argusDBC::addLocalUART( uint32_t NodeID, uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode, uint16_t port ){
  2866. uint32_t RetVal = 0;
  2867. if( m_bIsConnected ) {
  2868. char tQBuf[MAX_PATH_LEN];
  2869. sprintf( tQBuf, "INSERT INTO `uart_settings` SET `node_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`",
  2870. NodeID,
  2871. utype,
  2872. speed,
  2873. bit,
  2874. parity,
  2875. stop_bit,
  2876. mode,
  2877. port,
  2878. PATH
  2879. );
  2880. #ifdef DEBUG_ALL
  2881. LOG(tQBuf);
  2882. #endif
  2883. RetVal = m_pDatabase->QueryID( tQBuf );
  2884. if( RetVal == 0 ) {
  2885. RetVal = getUartID( NodeID, utype, PATH );
  2886. };
  2887. };
  2888. return RetVal;
  2889. };
  2890. uint32_t argusDBC::addLocalNIF( CSTR device, CSTR mac, ARGUS_NIF_TYPE dtype, ARGUS_NIF_MODE dmode, uint32_t aux_id ){
  2891. uint32_t RetVal = 0;
  2892. if( m_bIsConnected ) {
  2893. char tQBuf[MAX_PATH_LEN];
  2894. char * tKey = MD5String( device );
  2895. if( tKey != NULL ) {
  2896. sprintf( tQBuf, "INSERT INTO `network_interfaces` SET `type`=%d, `key`='%s', `device_name`='%s', `mac`='%s', `mode`=%d, `aux_id`=%d ON DUPLICATE KEY UPDATE `mode`=%d, `aux_id`=%d, `mac`='%s'",
  2897. dtype,
  2898. tKey,
  2899. device,
  2900. mac,
  2901. dmode,
  2902. aux_id,
  2903. dmode,
  2904. aux_id,
  2905. mac
  2906. );
  2907. #ifdef DEBUG
  2908. LOG(tQBuf);
  2909. #endif
  2910. RetVal = m_pDatabase->QueryID( tQBuf );
  2911. if( RetVal == 0 ) {
  2912. RetVal = getNIF_ID( tKey );
  2913. };
  2914. free( tKey );
  2915. };
  2916. };
  2917. return RetVal;
  2918. };
  2919. uint32_t argusDBC::addLocalWiFi( uint32_t NIF_ID, ARGUS_WIFI_MODE mode, CSTR SSID, CSTR password, ARGUS_WIFI_ENCRIPTION encryption, uint32_t router_id ){
  2920. uint32_t RetVal = 0;
  2921. if( m_bIsConnected ) {
  2922. char tQBuf[MAX_PATH_LEN];
  2923. sprintf( tQBuf, "INSERT INTO `wifis` SET `nif_id`=%d, `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d ON DUPLICATE KEY UPDATE `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d",
  2924. NIF_ID,
  2925. mode,
  2926. router_id,
  2927. SSID,
  2928. password,
  2929. encryption,
  2930. mode,
  2931. router_id,
  2932. SSID,
  2933. password,
  2934. encryption
  2935. );
  2936. #ifdef DEBUG
  2937. LOG(tQBuf);
  2938. #endif
  2939. RetVal = m_pDatabase->QueryID( tQBuf );
  2940. if( RetVal == 0 ) {
  2941. RetVal = getWiFi_ID( NIF_ID );
  2942. };
  2943. };
  2944. return RetVal;
  2945. };
  2946. uint32_t argusDBC::addLocalNetwork( uint32_t NIF_ID, ARGUS_NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){
  2947. uint32_t RetVal = 0;
  2948. if( m_bIsConnected ) {
  2949. char tQBuf[MAX_PATH_LEN];
  2950. 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'",
  2951. NIF_ID,
  2952. net_type,
  2953. address,
  2954. gateway,
  2955. mask,
  2956. broadcast,
  2957. address,
  2958. gateway,
  2959. mask,
  2960. broadcast
  2961. );
  2962. #ifdef DEBUG
  2963. LOG(tQBuf);
  2964. #endif
  2965. RetVal = m_pDatabase->QueryID( tQBuf );
  2966. // On Update IF data no need to return ID
  2967. //if( RetVal == 0 ) {
  2968. // RetVal = getNetworkInterfaceID( tKey );
  2969. //};
  2970. };
  2971. return RetVal;
  2972. };
  2973. uint32_t argusDBC::addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp, CSTR BRANG, CSTR ERANG, CSTR MASK, CSTR LEASE_TIME ){
  2974. uint32_t RetVal = 0;
  2975. if( m_bIsConnected ) {
  2976. char tQBuf[MAX_PATH_LEN];
  2977. bool ena_routing = true;
  2978. if( OUTBOUND_NIF == 0 ){
  2979. ena_routing = false;
  2980. };
  2981. if( ena_dhcp ){
  2982. if ( BRANG == NULL || ERANG == NULL || MASK == NULL || LEASE_TIME == NULL ) {
  2983. LOG_ERROR("Wrong DHCP parameters to create Network Infrastructure!");
  2984. return 0;
  2985. };
  2986. sprintf(tQBuf, "INSERT INTO `network_infrastructure` SET `nif_id`=%d, `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s' ON DUPLICATE KEY UPDATE `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s'",
  2987. NIF_ID,
  2988. ena_routing,
  2989. OUTBOUND_NIF,
  2990. BRANG,
  2991. ERANG,
  2992. MASK,
  2993. LEASE_TIME,
  2994. ena_routing,
  2995. OUTBOUND_NIF,
  2996. BRANG,
  2997. ERANG,
  2998. MASK,
  2999. LEASE_TIME
  3000. );
  3001. } else {
  3002. if( ena_routing ){
  3003. sprintf(tQBuf, "INSERT INTO `network_infrastructure` SET `nif_id`=%d, `enable_routing`=1, `outbond_nif`=%d ON DUPLICATE KEY UPDATE `enable_routing`=1, `outbond_nif`=%d",
  3004. NIF_ID,
  3005. OUTBOUND_NIF,
  3006. OUTBOUND_NIF
  3007. );
  3008. } else {
  3009. LOG_ERROR("No Special Service Defined To Network Infrastructure!");
  3010. return 0;
  3011. };
  3012. };
  3013. #ifdef DEBUG_ALL
  3014. LOG(tQBuf);
  3015. #endif
  3016. RetVal = m_pDatabase->QueryID( tQBuf );
  3017. // On Update IF data no need to return ID
  3018. if( RetVal == 0 ) {
  3019. RetVal = getNetworkInfrastructureID( NIF_ID );
  3020. };
  3021. };
  3022. return RetVal;
  3023. };
  3024. bool argusDBC::addDraw( uint32_t DBID, uint16_t SIZE, CSTR ID ){
  3025. if( m_bIsConnected ) {
  3026. char tQBuf[MAX_PATH_LEN];
  3027. 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'",
  3028. DBID,
  3029. ID,
  3030. SIZE,
  3031. ID,
  3032. SIZE
  3033. );
  3034. #ifdef DEBUG_ALL
  3035. LOG(tQBuf);
  3036. #endif
  3037. m_pDatabase->SilentQuery( tQBuf );
  3038. return true;
  3039. };
  3040. return false;
  3041. };
  3042. 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 ){
  3043. uint32_t RetVal = 0;
  3044. if( m_bIsConnected ) {
  3045. char tQBuf[MAX_PATH_LEN];
  3046. if( RefUUID == NULL ) {
  3047. 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",
  3048. SRC,
  3049. UUID,
  3050. tss,
  3051. tsms,
  3052. evt_type,
  3053. dig_r,
  3054. AZ,
  3055. EL,
  3056. RANGE,
  3057. AREA,
  3058. lat,
  3059. lon,
  3060. alt
  3061. );
  3062. } else {
  3063. 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'",
  3064. SRC,
  3065. UUID,
  3066. tss,
  3067. tsms,
  3068. evt_type,
  3069. dig_r,
  3070. AZ,
  3071. EL,
  3072. RANGE,
  3073. AREA,
  3074. lat,
  3075. lon,
  3076. alt,
  3077. RefUUID
  3078. );
  3079. };
  3080. #ifdef DEBUG_ALL
  3081. LOG(tQBuf);
  3082. #endif
  3083. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3084. };
  3085. return RetVal;
  3086. };
  3087. bool argusDBC::addVideoEvent( uint32_t evtID, uint32_t videoID ){
  3088. if( m_bIsConnected ) {
  3089. char tQBuf[MAX_PATH_LEN];
  3090. sprintf( tQBuf, "INSERT INTO `events_2_videos` SET `evt_id`=%d, `video_id`=%d", evtID, videoID );
  3091. #ifdef DEBUG_ALL
  3092. LOG(tQBuf);
  3093. #endif
  3094. m_pDatabase->SilentQuery( tQBuf );
  3095. return true;
  3096. };
  3097. return true;
  3098. };
  3099. bool argusDBC::addPictureEvent( uint32_t evtID, uint32_t pictureoID ){
  3100. if( m_bIsConnected ) {
  3101. char tQBuf[MAX_PATH_LEN];
  3102. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", evtID, pictureoID );
  3103. #ifdef DEBUG_ALL
  3104. LOG(tQBuf);
  3105. #endif
  3106. m_pDatabase->SilentQuery( tQBuf );
  3107. return true;
  3108. };
  3109. return true;
  3110. };
  3111. uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, uint32_t partID ){
  3112. uint32_t tID = 0;
  3113. if( m_bIsConnected ) {
  3114. char tQBuf[MAX_PATH_LEN];
  3115. sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `part_id`=%d ", streamID, md5, partID );
  3116. #ifdef DEBUG_ALL
  3117. LOG(tQBuf);
  3118. #endif
  3119. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3120. }
  3121. return tID;
  3122. };
  3123. uint32_t argusDBC::addPicture( uint32_t streamID, CSTR md5, CSTR ext ){
  3124. uint32_t tID = 0;
  3125. if( m_bIsConnected ) {
  3126. char tQBuf[MAX_PATH_LEN];
  3127. sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'", streamID, md5, ext );
  3128. #ifdef DEBUG_ALL
  3129. LOG(tQBuf);
  3130. #endif
  3131. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3132. }
  3133. return tID;
  3134. };
  3135. 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 ){
  3136. if( m_bIsConnected ) {
  3137. char tQBuf[MAX_PATH_LEN];
  3138. if( master ) {
  3139. 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'",
  3140. nOrder,
  3141. nOffset,
  3142. nDelta,
  3143. nFlip,
  3144. nWidth,
  3145. bSST,
  3146. nSun,
  3147. GP,
  3148. spikes,
  3149. lrfID,
  3150. profileID );
  3151. } else {
  3152. 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'",
  3153. nOrder,
  3154. nOffset,
  3155. nDelta,
  3156. nFlip,
  3157. nWidth,
  3158. bSST,
  3159. nSun,
  3160. GP,
  3161. spikes,
  3162. lrfID,
  3163. profileID );
  3164. };
  3165. #ifdef DEBUG_ALL
  3166. LOG(tQBuf);
  3167. #endif
  3168. m_pDatabase->SilentQuery( tQBuf );
  3169. return true;
  3170. };
  3171. return false;
  3172. };
  3173. bool argusDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  3174. if( m_bIsConnected ) {
  3175. char tQBuf[MAX_PATH_LEN];
  3176. CSTR tES = m_pDatabase->escapeString( Serial );
  3177. if( tES ) {
  3178. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  3179. free( tES );
  3180. #ifdef DEBUG_ALL
  3181. LOG(tQBuf);
  3182. #endif
  3183. m_pDatabase->SilentQuery( tQBuf );
  3184. return true;
  3185. };
  3186. };
  3187. return false;
  3188. };
  3189. bool argusDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  3190. if( m_bIsConnected ) {
  3191. char tQBuf[MAX_PATH_LEN];
  3192. CSTR tES = m_pDatabase->escapeString( version );
  3193. if( tES ) {
  3194. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  3195. free( tES );
  3196. #ifdef DEBUG_ALL
  3197. LOG(tQBuf);
  3198. #endif
  3199. m_pDatabase->SilentQuery( tQBuf );
  3200. return true;
  3201. };
  3202. };
  3203. return false;
  3204. };
  3205. bool argusDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  3206. if( m_bIsConnected ) {
  3207. char tQBuf[MAX_PATH_LEN];
  3208. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  3209. #ifdef DEBUG_ALL
  3210. LOG(tQBuf);
  3211. #endif
  3212. m_pDatabase->SilentQuery( tQBuf );
  3213. return true;
  3214. };
  3215. return false;
  3216. };
  3217. bool argusDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  3218. if( m_bIsConnected ) {
  3219. char tQBuf[MAX_PATH_LEN];
  3220. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  3221. #ifdef DEBUG_ALL
  3222. LOG(tQBuf);
  3223. #endif
  3224. m_pDatabase->SilentQuery( tQBuf );
  3225. return true;
  3226. };
  3227. return false;
  3228. };
  3229. bool argusDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  3230. if( m_bIsConnected ) {
  3231. char tQBuf[MAX_PATH_LEN];
  3232. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  3233. #ifdef DEBUG_ALL
  3234. LOG(tQBuf);
  3235. #endif
  3236. m_pDatabase->SilentQuery( tQBuf );
  3237. return true;
  3238. };
  3239. return false;
  3240. };
  3241. bool argusDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  3242. if( m_bIsConnected ) {
  3243. char tQBuf[MAX_PATH_LEN];
  3244. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  3245. #ifdef DEBUG_ALL
  3246. LOG(tQBuf);
  3247. #endif
  3248. m_pDatabase->SilentQuery( tQBuf );
  3249. return true;
  3250. };
  3251. return false;
  3252. };
  3253. bool argusDBC::setStreamValid( uint32_t streamID ){
  3254. if( m_bIsConnected ) {
  3255. char tQBuf[MAX_PATH_LEN];
  3256. sprintf( tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID );
  3257. #ifdef DEBUG_ALL
  3258. LOG(tQBuf);
  3259. #endif
  3260. m_pDatabase->SilentQuery( tQBuf );
  3261. return true;
  3262. };
  3263. return false;
  3264. };
  3265. bool argusDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
  3266. if( m_bIsConnected ) {
  3267. char tQBuf[MAX_PATH_LEN];
  3268. 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",
  3269. filterID,
  3270. Tag,
  3271. x,y,z,
  3272. x,y,z
  3273. );
  3274. #ifdef DEBUG_ALL
  3275. LOG(tQBuf);
  3276. #endif
  3277. m_pDatabase->SilentQuery( tQBuf );
  3278. return true;
  3279. };
  3280. return false;
  3281. };
  3282. DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){
  3283. DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL;
  3284. if( m_bIsConnected ) {
  3285. char tQBuf[MAX_PATH_LEN];
  3286. AAssoc *result;
  3287. sprintf( tQBuf, "SELECT * FROM `module_embed_video_settings` WHERE `id`=%d", ID );
  3288. #ifdef DEBUG_ALL
  3289. LOG(tQBuf);
  3290. #endif
  3291. result = m_pDatabase->Query( tQBuf );
  3292. if( result!= NULL ) {
  3293. if( result->size() > 0 ) {
  3294. Assoc *cArr;
  3295. tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  3296. if( tPtr!= NULL ) {
  3297. Assoc::iterator it;
  3298. memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  3299. cArr = result->at(0);
  3300. it = cArr->find("web_port");
  3301. if( it != cArr->end() ){
  3302. tPtr->port = atoi( it->second.c_str() );
  3303. };
  3304. it = cArr->find("width");
  3305. if( it != cArr->end() ){
  3306. tPtr->width = atoi( it->second.c_str() );
  3307. };
  3308. it = cArr->find("height");
  3309. if( it != cArr->end() ){
  3310. tPtr->height = atoi( it->second.c_str() );
  3311. };
  3312. it = cArr->find("compression_quality");
  3313. if( it != cArr->end() ){
  3314. tPtr->compression_quality = atoi( it->second.c_str() );
  3315. };
  3316. it = cArr->find("show_ts");
  3317. if( it != cArr->end() ){
  3318. tPtr->show_ts = (bool)atoi( it->second.c_str() );
  3319. };
  3320. it = cArr->find("ts_x");
  3321. if( it != cArr->end() ){
  3322. tPtr->ts_x = atoi( it->second.c_str() );
  3323. };
  3324. it = cArr->find("ts_y");
  3325. if( it != cArr->end() ){
  3326. tPtr->ts_y = atoi( it->second.c_str() );
  3327. };
  3328. it = cArr->find("ts_font_face");
  3329. if( it != cArr->end() ){
  3330. tPtr->ts_font_face = atoi( it->second.c_str() );
  3331. };
  3332. it = cArr->find("ts_font_scale");
  3333. if( it != cArr->end() ){
  3334. tPtr->ts_font_scale = atof( it->second.c_str() );
  3335. };
  3336. it = cArr->find("ts_font_thickness");
  3337. if( it != cArr->end() ){
  3338. tPtr->ts_font_thickness = atoi( it->second.c_str() );
  3339. };
  3340. it = cArr->find("ts_line_type");
  3341. if( it != cArr->end() ){
  3342. tPtr->ts_line_type = atoi( it->second.c_str() );
  3343. };
  3344. it = cArr->find("ts_transperant");
  3345. if( it != cArr->end() ){
  3346. tPtr->ts_transperant = (bool)atoi( it->second.c_str() );
  3347. };
  3348. it = cArr->find("show_label");
  3349. if( it != cArr->end() ){
  3350. tPtr->show_label = (bool)atoi( it->second.c_str() );
  3351. };
  3352. it = cArr->find("label_x");
  3353. if( it != cArr->end() ){
  3354. tPtr->label_x = atoi( it->second.c_str() );
  3355. };
  3356. it = cArr->find("label_y");
  3357. if( it != cArr->end() ){
  3358. tPtr->label_y = atoi( it->second.c_str() );
  3359. };
  3360. it = cArr->find("label_font_face");
  3361. if( it != cArr->end() ){
  3362. tPtr->label_font_face = atoi( it->second.c_str() );
  3363. };
  3364. it = cArr->find("label_font_scale");
  3365. if( it != cArr->end() ){
  3366. tPtr->label_font_scale = atof( it->second.c_str() );
  3367. };
  3368. it = cArr->find("label_font_thickness");
  3369. if( it != cArr->end() ){
  3370. tPtr->label_font_thickness = atoi( it->second.c_str() );
  3371. };
  3372. it = cArr->find("label_line_type");
  3373. if( it != cArr->end() ){
  3374. tPtr->label_line_type = atoi( it->second.c_str() );
  3375. };
  3376. it = cArr->find("label_transperant");
  3377. if( it != cArr->end() ){
  3378. tPtr->label_transperant = (bool) atoi( it->second.c_str() );
  3379. };
  3380. it = cArr->find("show_logo");
  3381. if( it != cArr->end() ){
  3382. tPtr->show_logo = (bool) atoi( it->second.c_str() );
  3383. };
  3384. it = cArr->find("logo_w");
  3385. if( it != cArr->end() ){
  3386. tPtr->logo_w = atoi( it->second.c_str() );
  3387. };
  3388. it = cArr->find("logo_h");
  3389. if( it != cArr->end() ){
  3390. tPtr->logo_h = atoi( it->second.c_str() );
  3391. };
  3392. it = cArr->find("logo_x");
  3393. if( it != cArr->end() ){
  3394. tPtr->logo_x = atoi( it->second.c_str() );
  3395. };
  3396. it = cArr->find("logo_y");
  3397. if( it != cArr->end() ){
  3398. tPtr->logo_y = atoi( it->second.c_str() );
  3399. };
  3400. it = cArr->find("logo_md5");
  3401. if( it != cArr->end() ){
  3402. strncpy( tPtr->logo_md5, it->second.c_str(),32);
  3403. tPtr->logo_md5[32]=(char)0;
  3404. };
  3405. };
  3406. };
  3407. };
  3408. deleteResult( result );
  3409. };
  3410. return tPtr;
  3411. };
  3412. DBC_EVT_DATA *argusDBC::getEventByUUID( CSTR UUID ){
  3413. DBC_EVT_DATA *tPtr = NULL;
  3414. if( m_bIsConnected ) {
  3415. char tQBuf[MAX_PATH_LEN];
  3416. AAssoc *result;
  3417. sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
  3418. #ifdef DEBUG_ALL
  3419. LOG(tQBuf);
  3420. #endif
  3421. result = m_pDatabase->Query( tQBuf );
  3422. if( result!= NULL ) {
  3423. if( result->size() > 0 ) {
  3424. Assoc *cArr;
  3425. tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA));
  3426. if( tPtr!= NULL ) {
  3427. Assoc::iterator it;
  3428. memset(tPtr,0,sizeof(DBC_EVT_DATA));
  3429. cArr = result->at(0);
  3430. it = cArr->find("id");
  3431. if( it != cArr->end() ){
  3432. tPtr->id = atoi( it->second.c_str() );
  3433. };
  3434. it = cArr->find("node_id");
  3435. if( it != cArr->end() ){
  3436. tPtr->node_id = atoi( it->second.c_str() );
  3437. };
  3438. it = cArr->find("uuid");
  3439. if( it != cArr->end() ){
  3440. strncpy( tPtr->uuid, it->second.c_str(),64 );
  3441. };
  3442. it = cArr->find("ts");
  3443. if( it != cArr->end() ){
  3444. tPtr->ts_s = atoi( it->second.c_str() );
  3445. };
  3446. it = cArr->find("ts_ms");
  3447. if( it != cArr->end() ){
  3448. tPtr->ts_ms = atoi( it->second.c_str() );
  3449. };
  3450. it = cArr->find("evt_type");
  3451. if( it != cArr->end() ){
  3452. tPtr->type = atoi( it->second.c_str() );
  3453. };
  3454. it = cArr->find("range_digital");
  3455. if( it != cArr->end() ){
  3456. tPtr->range_digital = atoi( it->second.c_str() );
  3457. };
  3458. it = cArr->find("azimuth");
  3459. if( it != cArr->end() ){
  3460. tPtr->az = atof( it->second.c_str() );
  3461. };
  3462. it = cArr->find("elevation");
  3463. if( it != cArr->end() ){
  3464. tPtr->el = atof( it->second.c_str() );
  3465. };
  3466. it = cArr->find("range");
  3467. if( it != cArr->end() ){
  3468. tPtr->ra = atof( it->second.c_str() );
  3469. };
  3470. it = cArr->find("area");
  3471. if( it != cArr->end() ){
  3472. tPtr->area = atof( it->second.c_str() );
  3473. };
  3474. it = cArr->find("lat");
  3475. if( it != cArr->end() ){
  3476. tPtr->lat = atof( it->second.c_str() );
  3477. };
  3478. it = cArr->find("lon");
  3479. if( it != cArr->end() ){
  3480. tPtr->lon = atof( it->second.c_str() );
  3481. };
  3482. it = cArr->find("alt");
  3483. if( it != cArr->end() ){
  3484. tPtr->alt = atof( it->second.c_str() );
  3485. };
  3486. it = cArr->find("ref_id");
  3487. if( it != cArr->end() ){
  3488. tPtr->ref_id = atoi( it->second.c_str() );
  3489. };
  3490. it = cArr->find("ref_uuid");
  3491. if( it != cArr->end() ){
  3492. strncpy( tPtr->ref_uuid, it->second.c_str(),64 );
  3493. };
  3494. };
  3495. };
  3496. };
  3497. deleteResult( result );
  3498. };
  3499. return tPtr;
  3500. };
  3501. #undef LOG
  3502. #undef LOG_ERROR