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.

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