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.

4822 lines
174 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
4 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_bIsServerLocal = false;
  30. m_nSiteID = 0;
  31. m_pDatabase = NULL;
  32. };
  33. argusDBC::~argusDBC(){
  34. m_bIsConnected = false;
  35. if( m_pDatabase != NULL ) delete( m_pDatabase );
  36. m_pDatabase = NULL;
  37. _instance = NULL;
  38. };
  39. bool argusDBC::connect( void ){
  40. config_setting_t * tSetting;
  41. m_bIsConnected = false;
  42. if( m_pSettings!= NULL ) {
  43. tSetting = config_setting_get_member( m_pSettings, "DATABASE_HOST" );
  44. if( tSetting == NULL ){
  45. tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING );
  46. config_setting_set_string( tSetting, "localhost" );
  47. basicSettingsProvider::getInstance()->compromise();
  48. LOG("No DB Host Setting! Using default!");
  49. };
  50. sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
  51. //Check if using local database
  52. if( strstr( m_pDbHost, "localhost" )!= NULL ){
  53. m_bIsServerLocal = true;
  54. } else {
  55. // Check if setting is local IP address
  56. };
  57. tSetting = config_setting_get_member(m_pSettings, "DATABASE_NAME");
  58. if( tSetting == NULL ){
  59. tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING );
  60. config_setting_set_string( tSetting, "dfsl_gunter" );
  61. basicSettingsProvider::getInstance()->compromise();
  62. LOG("No DB Database Setting! Using default!");
  63. };
  64. sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting));
  65. tSetting = config_setting_get_member( m_pSettings, "DATABASE_USER" );
  66. if( tSetting == NULL ){
  67. tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING );
  68. config_setting_set_string( tSetting, "dbroot" );
  69. basicSettingsProvider::getInstance()->compromise();
  70. LOG("No DB User Setting! Using default!");
  71. };
  72. sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting));
  73. tSetting = config_setting_get_member( m_pSettings, "DATABASE_PASSWORD" );
  74. if( tSetting == NULL ){
  75. tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING );
  76. config_setting_set_string( tSetting, "123567" );
  77. basicSettingsProvider::getInstance()->compromise();
  78. LOG("No DB Password Setting! Using default!");
  79. };
  80. sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting));
  81. basicSettingsProvider::getInstance()->validate();
  82. m_pDatabase = new MySQL_Connector();
  83. if( m_pDatabase == NULL )return false;
  84. m_bIsConnected = m_pDatabase->Connect( m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword );
  85. } else {
  86. LOG_ERROR("No Settings Provided!");
  87. };
  88. return m_bIsConnected;
  89. };
  90. void argusDBC::deleteCamCapPicture( uint32_t PicID ){
  91. if(m_bIsConnected) {
  92. char tQBuf[MAX_PATH_LEN];
  93. sprintf( tQBuf, "DELETE FROM `pictures` WHERE `id`=%d", PicID );
  94. #ifdef DEBUG_EXTRA
  95. LOG(tQBuf);
  96. #endif
  97. m_pDatabase->SilentQuery( tQBuf );
  98. };
  99. };
  100. void argusDBC::deleteNode( uint32_t NodeID ){
  101. if(m_bIsConnected) {
  102. char tQBuf[MAX_PATH_LEN];
  103. sprintf( tQBuf, "DELETE FROM `nodes` WHERE `id`=%d", NodeID );
  104. #ifdef DEBUG
  105. LOG(tQBuf);
  106. #endif
  107. m_pDatabase->SilentQuery( tQBuf );
  108. };
  109. };
  110. void argusDBC::deleteCamera( uint32_t CamID ){
  111. if(m_bIsConnected) {
  112. char tQBuf[MAX_PATH_LEN];
  113. sprintf( tQBuf, "DELETE FROM `cameras` WHERE `id`=%d", CamID );
  114. #ifdef DEBUG
  115. LOG(tQBuf);
  116. #endif
  117. m_pDatabase->SilentQuery( tQBuf );
  118. };
  119. };
  120. void argusDBC::deleteResource( uint32_t ResourceID ){
  121. if(m_bIsConnected) {
  122. char tQBuf[MAX_PATH_LEN];
  123. sprintf( tQBuf, "DELETE FROM `resources` WHERE `id`=%d", ResourceID );
  124. #ifdef DEBUG
  125. LOG(tQBuf);
  126. #endif
  127. m_pDatabase->SilentQuery( tQBuf );
  128. };
  129. };
  130. void argusDBC::deleteSensor( uint32_t SensorID ){
  131. if(m_bIsConnected) {
  132. char tQBuf[MAX_PATH_LEN];
  133. sprintf( tQBuf, "DELETE FROM `lrf_sensors` WHERE `id`=%d", SensorID );
  134. #ifdef DEBUG
  135. LOG(tQBuf);
  136. #endif
  137. m_pDatabase->SilentQuery( tQBuf );
  138. };
  139. };
  140. void argusDBC::deleteNodeEvents( uint32_t NodeID ){
  141. if(m_bIsConnected) {
  142. char tQBuf[MAX_PATH_LEN];
  143. sprintf(tQBuf, "DELETE `ep` FROM `events_2_pictures` `ep` LEFT JOIN `events_archive` `ea` ON ( `ep`.`evt_id` = `ea`.`id` ) WHERE `ea`.`node_id`=%d", NodeID);
  144. #ifdef DEBUG
  145. LOG(tQBuf);
  146. #endif
  147. m_pDatabase->SilentQuery( tQBuf );
  148. sprintf(tQBuf, "DELETE `ep` FROM `events_2_videos` `ep` LEFT JOIN `events_archive` `ea` ON ( `ep`.`evt_id` = `ea`.`id` ) WHERE `ea`.`node_id`=%d", NodeID);
  149. #ifdef DEBUG
  150. LOG(tQBuf);
  151. #endif
  152. m_pDatabase->SilentQuery( tQBuf );
  153. sprintf( tQBuf, "DELETE FROM `events_archive` WHERE `node_id`=%d", NodeID );
  154. #ifdef DEBUG
  155. LOG(tQBuf);
  156. #endif
  157. m_pDatabase->SilentQuery( tQBuf );
  158. sprintf( tQBuf, "DELETE FROM `events_cloud` WHERE `node_id`=%d", NodeID );
  159. #ifdef DEBUG
  160. LOG(tQBuf);
  161. #endif
  162. m_pDatabase->SilentQuery( tQBuf );
  163. };
  164. };
  165. void argusDBC::deleteUART( uint32_t UARTID ){
  166. if(m_bIsConnected) {
  167. char tQBuf[MAX_PATH_LEN];
  168. sprintf( tQBuf, "DELETE FROM `uart_settings` WHERE `id`=%d", UARTID );
  169. #ifdef DEBUG
  170. LOG(tQBuf);
  171. #endif
  172. m_pDatabase->SilentQuery( tQBuf );
  173. };
  174. };
  175. void argusDBC::deleteConnections( uint32_t NodeID ){
  176. if(m_bIsConnected) {
  177. char tQBuf[MAX_PATH_LEN];
  178. sprintf( tQBuf, "DELETE FROM `connections` WHERE `from`=%d OR `to`=%d", NodeID, NodeID );
  179. #ifdef DEBUG
  180. LOG(tQBuf);
  181. #endif
  182. m_pDatabase->SilentQuery( tQBuf );
  183. };
  184. };
  185. void argusDBC::deleteMediaStream( uint32_t MediaID ){
  186. if(m_bIsConnected) {
  187. char tQBuf[MAX_PATH_LEN];
  188. sprintf( tQBuf, "DELETE FROM `media_streams` WHERE `id`=%d", MediaID );
  189. #ifdef DEBUG
  190. LOG(tQBuf);
  191. #endif
  192. m_pDatabase->SilentQuery( tQBuf );
  193. };
  194. };
  195. void argusDBC::deleteNIF( uint32_t NifID ){
  196. if(m_bIsConnected) {
  197. char tQBuf[MAX_PATH_LEN];
  198. sprintf( tQBuf, "DELETE FROM `network_interfaces` WHERE `id`=%d", NifID );
  199. #ifdef DEBUG
  200. LOG(tQBuf);
  201. #endif
  202. m_pDatabase->SilentQuery( tQBuf );
  203. };
  204. };
  205. void argusDBC::deleteNIS( uint32_t NisID ){
  206. if(m_bIsConnected) {
  207. char tQBuf[MAX_PATH_LEN];
  208. sprintf( tQBuf, "DELETE FROM `network_infrastructure` WHERE `id`=%d", NisID );
  209. #ifdef DEBUG
  210. LOG(tQBuf);
  211. #endif
  212. m_pDatabase->SilentQuery( tQBuf );
  213. };
  214. };
  215. bool argusDBC::cleanEvents2PictureBinding( uint32_t PicID ){
  216. if(m_bIsConnected) {
  217. char tQBuf[MAX_PATH_LEN];
  218. sprintf( tQBuf, "DELETE FROM `events_2_pictures` WHERE `picture_id`=%d", PicID );
  219. #ifdef DEBUG_EXTRA
  220. LOG(tQBuf);
  221. #endif
  222. m_pDatabase->SilentQuery( tQBuf );
  223. return true;
  224. };
  225. return false;
  226. };
  227. bool argusDBC::cleanEvents2VideoBinding( uint32_t VidID ){
  228. if(m_bIsConnected) {
  229. char tQBuf[MAX_PATH_LEN];
  230. sprintf( tQBuf, "DELETE FROM `events_2_videos` WHERE `video_id`=%d", VidID );
  231. #ifdef DEBUG_EXTRA
  232. LOG(tQBuf);
  233. #endif
  234. m_pDatabase->SilentQuery( tQBuf );
  235. return true;
  236. };
  237. return false;
  238. };
  239. bool argusDBC::cleanResources( uint32_t ServerNodeID, bool all ){
  240. if(m_bIsConnected) {
  241. char tQBuf[MAX_PATH_LEN];
  242. if( all ) {
  243. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE `node_id`=%d", ServerNodeID );
  244. } else {
  245. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE ( `node_id`=%d ) AND ( `type`=100 OR `type`=101 OR `type`=103 OR `type`=120 )", ServerNodeID );
  246. };
  247. #ifdef DEBUG_EXTRA
  248. LOG(tQBuf);
  249. #endif
  250. m_pDatabase->SilentQuery( tQBuf );
  251. return true;
  252. };
  253. return false;
  254. };
  255. bool argusDBC::cleanNodeEvents( uint32_t NodeID, bool all ){
  256. if(m_bIsConnected) {
  257. char tQBuf[MAX_PATH_LEN];
  258. if( all ) {
  259. sprintf( tQBuf, "DELETE FROM `events_cloud` WHERE `node_id`=%d", NodeID );
  260. m_pDatabase->SilentQuery( tQBuf );
  261. sprintf( tQBuf, "DELETE FROM `events_archive` WHERE `node_id`=%d", NodeID );
  262. m_pDatabase->SilentQuery( tQBuf );
  263. } else {
  264. sprintf( tQBuf, "DELETE FROM `events_cloud` WHERE `node_id`=%d", NodeID );
  265. };
  266. #ifdef DEBUG_EXTRA
  267. LOG(tQBuf);
  268. #endif
  269. m_pDatabase->SilentQuery( tQBuf );
  270. return true;
  271. };
  272. return false;
  273. };
  274. bool argusDBC::cleanLRFMask( uint32_t maskID, bool deleteMask ){
  275. if(m_bIsConnected) {
  276. char tQBuf[MAX_PATH_LEN];
  277. sprintf( tQBuf, "DELETE FROM `lrf_mask_trace_zones` WHERE `zone_id` IN ( SELECT `id` FROM `lrf_mask_traces` WHERE `mask_id`=%d )", maskID );
  278. #ifdef DEBUG_EXTRA
  279. LOG(tQBuf);
  280. #endif
  281. m_pDatabase->SilentQuery( tQBuf );
  282. sprintf( tQBuf, "DELETE FROM `lrf_mask_traces` WHERE `mask_id`=%d", maskID );
  283. #ifdef DEBUG_EXTRA
  284. LOG(tQBuf);
  285. #endif
  286. m_pDatabase->SilentQuery( tQBuf );
  287. sprintf( tQBuf, "DELETE FROM `lrf_mask_vertex_points` WHERE `vertex_id` IN ( SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d )", maskID );
  288. #ifdef DEBUG_EXTRA
  289. LOG(tQBuf);
  290. #endif
  291. m_pDatabase->SilentQuery( tQBuf );
  292. sprintf( tQBuf, "DELETE FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", maskID );
  293. #ifdef DEBUG_EXTRA
  294. LOG(tQBuf);
  295. #endif
  296. m_pDatabase->SilentQuery( tQBuf );
  297. //Delete Mask Itself!
  298. if ( deleteMask ) {
  299. sprintf( tQBuf, "DELETE FROM `lrf_masks` WHERE `id`=%d", maskID );
  300. #ifdef DEBUG_EXTRA
  301. LOG(tQBuf);
  302. #endif
  303. m_pDatabase->SilentQuery( tQBuf );
  304. };
  305. return true;
  306. };
  307. return false;
  308. };
  309. bool argusDBC::updateCamRange( uint32_t camID, float range ){
  310. if(m_bIsConnected) {
  311. char tQBuf[MAX_PATH_LEN];
  312. sprintf(tQBuf,"UPDATE cameras SET `max_range`=%.3f WHERE `id`=%d",
  313. range,
  314. camID
  315. );
  316. #ifdef DEBUG_EXTRA
  317. LOG(tQBuf);
  318. #endif
  319. m_pDatabase->SilentQuery( tQBuf );
  320. return true;
  321. };
  322. return false;
  323. };
  324. bool argusDBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){
  325. if(m_bIsConnected) {
  326. char tQBuf[MAX_PATH_LEN];
  327. char tIpBuf[CTEXT];
  328. char *tPos;
  329. char *tPos2;
  330. tPos = strstr(Addr,"//");
  331. if( tPos != NULL ) {
  332. tPos2 = strstr( tPos + 2,"/");
  333. if( tPos2 != NULL ) {
  334. int len;
  335. len = tPos2 - tPos - 2;
  336. strncpy(tIpBuf,tPos + 2,len);
  337. tIpBuf[len] = (char)0;
  338. } else {
  339. LOG_ERROR("Pos 2 - err");
  340. tIpBuf[0] = (char)0;
  341. };
  342. } else {
  343. LOG_ERROR("Pos 0 - err");
  344. tIpBuf[0] = (char)0;
  345. };
  346. sprintf(tQBuf,"UPDATE cameras SET `online`=1,`onvif_ctrl`='%s', `ip`='%s' WHERE `uuid`='%s' AND `site_id`=%d",
  347. Addr,
  348. tIpBuf,
  349. uuid,
  350. SiteID
  351. );
  352. #ifdef DEBUG_EXTRA
  353. LOG(tQBuf);
  354. #endif
  355. m_pDatabase->SilentQuery( tQBuf );
  356. return true;
  357. };
  358. return false;
  359. };
  360. bool argusDBC::updateIPCam( uint32_t SiteID, uint32_t CamID, CSTR Addr ){
  361. if(m_bIsConnected) {
  362. char tQBuf[MAX_PATH_LEN];
  363. char tIpBuf[CTEXT];
  364. char *tPos;
  365. char *tPos2;
  366. tPos = strstr(Addr,"//");
  367. if( tPos != NULL ) {
  368. tPos2 = strstr( tPos + 2,"/");
  369. if( tPos2 != NULL ) {
  370. int len;
  371. len = tPos2 - tPos - 2;
  372. strncpy(tIpBuf,tPos + 2,len);
  373. tIpBuf[len] = (char)0;
  374. } else {
  375. LOG_ERROR("Pos 2 - err");
  376. tIpBuf[0] = (char)0;
  377. };
  378. } else {
  379. LOG_ERROR("Pos 0 - err");
  380. tIpBuf[0] = (char)0;
  381. };
  382. sprintf(tQBuf,"UPDATE cameras SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE id=%d AND `site_id`=%d",
  383. Addr,
  384. tIpBuf,
  385. CamID,
  386. SiteID
  387. );
  388. #ifdef DEBUG_EXTRA
  389. LOG(tQBuf);
  390. #endif
  391. m_pDatabase->SilentQuery( tQBuf );
  392. sprintf(tQBuf,"UPDATE media_streams SET `valid`=1 WHERE source_id=%d AND source_type='D'", CamID );
  393. #ifdef DEBUG_EXTRA
  394. LOG(tQBuf);
  395. #endif
  396. m_pDatabase->SilentQuery( tQBuf );
  397. return true;
  398. };
  399. return false;
  400. };
  401. /*
  402. bool argusDBC::addIPCam( uint32_t SiteID, resultWoWo *tPtr ){
  403. if(m_bIsConnected) {
  404. char tQBuf[1024];
  405. char tIpBuf[32];
  406. char tProto[32];
  407. char tPath[CTEXT];
  408. char *tPos;
  409. char *tPos2;
  410. memcpy( tProto, tPtr->XAddrs, 5 );
  411. tProto[5] = (char)0;
  412. if( tProto[4] == ':') tProto[4] = (char)0;
  413. memset( tPath, 0, CTEXT );
  414. tPos = strstr(tPtr->XAddrs,"//");
  415. if( tPos != NULL ) {
  416. tPos2 = strstr( tPos + 2,"/");
  417. if( tPos2 != NULL ) {
  418. int len,len2,len3;
  419. len = tPos2 - tPos - 2;
  420. strncpy( tIpBuf, tPos + 2, len);
  421. tIpBuf[len] = (char)0;
  422. strncpy( tPath, tPos + 2 + len, CTEXT );
  423. } else {
  424. LOG_ERROR("Pos 2 - err");
  425. tIpBuf[0] = (char)0;
  426. };
  427. } else {
  428. LOG_ERROR("Pos 0 - err");
  429. tIpBuf[0] = (char)0;
  430. };
  431. 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'",
  432. tPtr->RefID,
  433. //tPtr->XAddrs,
  434. tPath,
  435. tIpBuf,
  436. SiteID,
  437. tPtr->MAC,
  438. tPtr->Hardware,
  439. tPtr->Name,
  440. tProto,
  441. //tPtr->XAddrs,
  442. tIpBuf
  443. );
  444. #ifdef DEBUG_EXTRA
  445. LOG(tQBuf);
  446. #endif
  447. m_pDatabase->SilentQuery( tQBuf );
  448. return true;
  449. };
  450. return false;
  451. };
  452. */
  453. bool argusDBC::addIPCam( uint32_t SiteID, OBSERVER_RESULT *tPtr ){
  454. if(m_bIsConnected) {
  455. char tQBuf[1024];
  456. char tIpBuf[32];
  457. char tProto[32];
  458. char tPath[CTEXT];
  459. char *tPos;
  460. char *tPos2;
  461. memcpy( tProto, tPtr->XAddrs, 5 );
  462. tProto[5] = (char)0;
  463. if( tProto[4] == ':') tProto[4] = (char)0;
  464. memset( tPath, 0, CTEXT );
  465. tPos = strstr(tPtr->XAddrs,"//");
  466. if( tPos != NULL ) {
  467. tPos2 = strstr( tPos + 2,"/");
  468. if( tPos2 != NULL ) {
  469. int len,len2,len3;
  470. len = tPos2 - tPos - 2;
  471. strncpy( tIpBuf, tPos + 2, len);
  472. tIpBuf[len] = (char)0;
  473. strncpy( tPath, tPos + 2 + len, CTEXT );
  474. } else {
  475. LOG_ERROR("Pos 2 - err");
  476. tIpBuf[0] = (char)0;
  477. };
  478. } else {
  479. LOG_ERROR("Pos 0 - err");
  480. tIpBuf[0] = (char)0;
  481. };
  482. 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'",
  483. tPtr->RefID,
  484. //tPtr->XAddrs,
  485. tPath,
  486. tIpBuf,
  487. SiteID,
  488. tPtr->MAC,
  489. tPtr->Hardware,
  490. tPtr->Name,
  491. tProto,
  492. //tPtr->XAddrs,
  493. tIpBuf
  494. );
  495. #ifdef DEBUG_EXTRA
  496. LOG(tQBuf);
  497. #endif
  498. m_pDatabase->SilentQuery( tQBuf );
  499. return true;
  500. };
  501. return false;
  502. };
  503. bool argusDBC::transferEvtToArchive( uint32_t SECONDS ){
  504. if(m_bIsConnected) {
  505. if( SECONDS > 0 ) {
  506. char tQBuf[CTEXT];
  507. 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 );
  508. m_pDatabase->SilentQuery( tQBuf );
  509. return true;
  510. };
  511. };
  512. return false;
  513. }
  514. /*
  515. bool argusDBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){
  516. if(m_bIsConnected){
  517. char tQBuf[CTEXT];
  518. AAssoc *result;
  519. sprintf(tQBuf, "SELECT * FROM events_cloud WHERE `ts`>%d AND `ts_ms`>%d", tss, tsms );
  520. result = m_pDatabase->Query( tQBuf );
  521. if( result!= NULL ) {
  522. DBC_EVT_DATA *tPtr;
  523. Assoc *cArr;
  524. for(int i=0;i<result->size();i++) {
  525. cArr = result->at(i);
  526. tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA));
  527. if( tPtr!= NULL ) {
  528. Assoc::iterator it;
  529. memset(tPtr,0,sizeof(DBC_EVT_DATA));
  530. it = cArr->find("id");
  531. if( it != cArr->end() ){
  532. tPtr->id = atoi( it->second.c_str() );
  533. };
  534. it = cArr->find("node_id");
  535. if( it != cArr->end() ){
  536. tPtr->node_id = atoi( it->second.c_str() );
  537. };
  538. it = cArr->find("uuid");
  539. if( it != cArr->end() ){
  540. strncpy( tPtr->uuid, it->second.c_str(),64 );
  541. };
  542. it = cArr->find("ts");
  543. if( it != cArr->end() ){
  544. tPtr->ts_s = atoi( it->second.c_str() );
  545. };
  546. it = cArr->find("ts_ms");
  547. if( it != cArr->end() ){
  548. tPtr->ts_ms = atoi( it->second.c_str() );
  549. };
  550. it = cArr->find("evt_type");
  551. if( it != cArr->end() ){
  552. tPtr->type = atoi( it->second.c_str() );
  553. };
  554. it = cArr->find("range_digital");
  555. if( it != cArr->end() ){
  556. tPtr->range_digital = atoi( it->second.c_str() );
  557. };
  558. it = cArr->find("azimuth");
  559. if( it != cArr->end() ){
  560. tPtr->az = atof( it->second.c_str() );
  561. };
  562. it = cArr->find("elevation");
  563. if( it != cArr->end() ){
  564. tPtr->el = atof( it->second.c_str() );
  565. };
  566. it = cArr->find("range");
  567. if( it != cArr->end() ){
  568. tPtr->ra = atof( it->second.c_str() );
  569. };
  570. it = cArr->find("area");
  571. if( it != cArr->end() ){
  572. tPtr->area = atof( it->second.c_str() );
  573. };
  574. it = cArr->find("lat");
  575. if( it != cArr->end() ){
  576. tPtr->lat = atof( it->second.c_str() );
  577. };
  578. it = cArr->find("lon");
  579. if( it != cArr->end() ){
  580. tPtr->lon = atof( it->second.c_str() );
  581. };
  582. it = cArr->find("alt");
  583. if( it != cArr->end() ){
  584. tPtr->alt = atof( it->second.c_str() );
  585. };
  586. it = cArr->find("ref_uuid");
  587. if( it != cArr->end() ){
  588. strncpy( tPtr->uuid, it->second.c_str(),64 );
  589. };
  590. char tBuf[CLOG];
  591. sprintf(tBuf,"Evt: %d %d %d", tPtr->type, tPtr->ts_s, tPtr->ts_ms );
  592. LOG(tBuf);
  593. VR.push_back(tPtr);
  594. };
  595. };
  596. };
  597. deleteResult( result );
  598. if( m_pDatabase->isConnected()) return true;
  599. };
  600. return false;
  601. };
  602. */
  603. //Is safe to remove???
  604. bool argusDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){
  605. if(m_bIsConnected){
  606. char tQBuf[CTEXT];
  607. AAssoc *result;
  608. sprintf(tQBuf, "SELECT * FROM cameras WHERE `site_id`=%d AND `type`=2 AND `status`=2", SiteID );
  609. #ifdef DEBUG_EXTRA
  610. LOG(tQBuf);
  611. #endif
  612. result = m_pDatabase->Query( tQBuf );
  613. if( result!= NULL ) {
  614. DBC_CAM_DATA *tVal;
  615. Assoc *cArr;
  616. for(int i=0;i<result->size();i++) {
  617. LOG("Cam_Record!");
  618. cArr = result->at(i);
  619. tVal = (DBC_CAM_DATA*)malloc(sizeof(DBC_CAM_DATA));
  620. if( tVal!= NULL ) {
  621. Assoc::iterator it;
  622. memset(tVal,0,sizeof(DBC_CAM_DATA));
  623. it = cArr->find("id");
  624. if( it != cArr->end() ){
  625. tVal->id = atoi( it->second.c_str() );
  626. };
  627. it = cArr->find("site_id");
  628. if( it != cArr->end() ){
  629. tVal->site_id = atoi( it->second.c_str() );
  630. };
  631. it = cArr->find("node_id");
  632. if( it != cArr->end() ){
  633. tVal->node_id = atoi( it->second.c_str() );
  634. };
  635. it = cArr->find("online");
  636. if( it != cArr->end() ){
  637. tVal->online = (bool) atoi( it->second.c_str() );
  638. };
  639. it = cArr->find("type");
  640. if( it != cArr->end() ){
  641. tVal->type = atoi( it->second.c_str() );
  642. };
  643. it = cArr->find("name");
  644. if( it != cArr->end() ){
  645. strncpy( tVal->name, it->second.c_str(), 64 );
  646. };
  647. it = cArr->find("hardware");
  648. if( it != cArr->end() ){
  649. strncpy( tVal->hardware, it->second.c_str(), 32 );
  650. };
  651. it = cArr->find("status");
  652. if( it != cArr->end() ){
  653. tVal->status = atoi( it->second.c_str() );
  654. };
  655. it = cArr->find("session");
  656. if( it != cArr->end() ){
  657. strncpy( tVal->session, it->second.c_str(), 32 );
  658. };
  659. it = cArr->find("protocol");
  660. if( it != cArr->end() ){
  661. tVal->protocol = atoi( it->second.c_str() );
  662. };
  663. it = cArr->find("protocol_aux");
  664. if( it != cArr->end() ){
  665. tVal->protocol_aux = atoi( it->second.c_str() );
  666. };
  667. it = cArr->find("x");
  668. if( it != cArr->end() ){
  669. tVal->x = atof( it->second.c_str() );
  670. };
  671. it = cArr->find("y");
  672. if( it != cArr->end() ){
  673. tVal->y = atof( it->second.c_str() );
  674. };
  675. it = cArr->find("z");
  676. if( it != cArr->end() ){
  677. tVal->z = atof( it->second.c_str() );
  678. };
  679. it = cArr->find("x_rot");
  680. if( it != cArr->end() ){
  681. tVal->x_rot = atof( it->second.c_str() );
  682. };
  683. it = cArr->find("y_rot");
  684. if( it != cArr->end() ){
  685. tVal->y_rot = atof( it->second.c_str() );
  686. };
  687. it = cArr->find("z_rot");
  688. if( it != cArr->end() ){
  689. tVal->z_rot = atof( it->second.c_str() );
  690. };
  691. it = cArr->find("imager_type");
  692. if( it != cArr->end() ){
  693. tVal->imager_type = atoi( it->second.c_str() );
  694. };
  695. it = cArr->find("lense_f");
  696. if( it != cArr->end() ){
  697. tVal->lens_f = atoi( it->second.c_str() );
  698. };
  699. it = cArr->find("zoom");
  700. if( it != cArr->end() ){
  701. tVal->zoom = atof( it->second.c_str() );
  702. };
  703. it = cArr->find("access_login");
  704. if( it != cArr->end() ){
  705. strncpy( tVal->username, it->second.c_str(), 32 );
  706. };
  707. it = cArr->find("access_pass");
  708. if( it != cArr->end() ){
  709. strncpy( tVal->password, it->second.c_str(), 32 );
  710. };
  711. it = cArr->find("uuid");
  712. if( it != cArr->end() ){
  713. strncpy( tVal->uuid, it->second.c_str(), 64 );
  714. };
  715. it = cArr->find("mac");
  716. if( it != cArr->end() ){
  717. strncpy( tVal->mac, it->second.c_str(), 17 );
  718. };
  719. it = cArr->find("ip");
  720. if( it != cArr->end() ){
  721. strncpy( tVal->ip, it->second.c_str(), 17 );
  722. };
  723. it = cArr->find("port");
  724. if( it != cArr->end() ){
  725. tVal->port = atoi( it->second.c_str() );
  726. };
  727. it = cArr->find("onvif_access");
  728. if( it != cArr->end() ){
  729. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  730. };
  731. it = cArr->find("onvif_ctrl");
  732. if( it != cArr->end() ){
  733. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  734. };
  735. it = cArr->find("ptz_token");
  736. if( it != cArr->end() ){
  737. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  738. };
  739. VR.push_back(tVal);
  740. };
  741. //??
  742. //delete(cArr);
  743. };
  744. };
  745. deleteResult( result );
  746. #ifdef DEBUG
  747. sprintf( tQBuf,"Now %d Camera Records in System", VR.size());
  748. LOG(tQBuf);
  749. #endif
  750. if( m_pDatabase->isConnected()) return true;
  751. };
  752. return false;
  753. };
  754. DBC_INT_LIST *argusDBC::listNodes( uint32_t SiteID, uint32_t ServerID, bool all ){
  755. DBC_INT_LIST * tVal = NULL;
  756. if( m_bIsConnected ){
  757. char tQBuf[1024];
  758. AAssoc *result;
  759. if( all ) {
  760. if ( ServerID == 0 ) {
  761. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d", SiteID);
  762. } else {
  763. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `server_id`=%d", SiteID, ServerID );
  764. };
  765. } else {
  766. if ( ServerID == 0 ){
  767. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `type` > 0", SiteID );
  768. } else {
  769. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `server_id`=%d AND `type` > 0", SiteID, ServerID );
  770. };
  771. };
  772. #ifdef DEBUG_EXTRA
  773. LOG(tQBuf);
  774. #endif
  775. result = m_pDatabase->Query( tQBuf );
  776. if( result!= NULL ) {
  777. if( result->size() > 0 ) {
  778. Assoc *cArr;
  779. tVal = new DBC_INT_LIST();
  780. if( tVal != NULL ) {
  781. Assoc::iterator it;
  782. for(int i=0; i <result->size();i++) {
  783. cArr = result->at(i);
  784. it = cArr->find("id");
  785. if( it != cArr->end() ){
  786. tVal->push_back( atoi( it->second.c_str() ));
  787. };
  788. };
  789. };
  790. };
  791. };
  792. deleteResult( result );
  793. };
  794. return tVal;
  795. };
  796. DBC_INT_LIST *argusDBC::listNewNodes( uint32_t SiteID, uint32_t ServerID, DBC_INT_LIST *old_ids ){
  797. DBC_INT_LIST * tVal = NULL;
  798. char tParam[CTEXT];
  799. //memset( tParam, 0, CTEXT );
  800. sprintf(tParam,"0");
  801. if( old_ids != NULL ) {
  802. char tBuffer[CTEXT];
  803. for(int i = 0; i< old_ids->size(); i++ ) {
  804. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  805. strncpy( tParam, tBuffer, CTEXT );
  806. };
  807. };
  808. if( m_bIsConnected ){
  809. char tQBuf[CTEXT];
  810. AAssoc *result;
  811. if ( ServerID == 0 ) {
  812. sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, tParam);
  813. } else {
  814. sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `server_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, ServerID, tParam );
  815. };
  816. #ifdef DEBUG_EXTRA
  817. LOG(tQBuf);
  818. #endif
  819. result = m_pDatabase->Query( tQBuf );
  820. if( result!= NULL ) {
  821. if( result->size() > 0 ) {
  822. Assoc *cArr;
  823. tVal = new DBC_INT_LIST();
  824. if( tVal != NULL ) {
  825. Assoc::iterator it;
  826. for(int i=0;i<result->size();i++) {
  827. cArr = result->at(i);
  828. it = cArr->find("id");
  829. if( it != cArr->end() ){
  830. tVal->push_back( atoi( it->second.c_str() ));
  831. };
  832. };
  833. };
  834. };
  835. };
  836. deleteResult( result );
  837. };
  838. return tVal;
  839. };
  840. void argusDBC::lazyEventArchiver( uint32_t DalayTime ){
  841. if( m_bIsConnected ){
  842. char tQBuf[CTEXT];
  843. AAssoc *result;
  844. uint32_t LastID = 0;
  845. sprintf( tQBuf, "SELECT * FROM `events_cloud` WHERE ( UNIX_TIMESTAMP(NOW()) - `ts` ) > %d ORDER BY `id` ASC LIMIT 10", DalayTime );
  846. #ifdef DEBUG_EXTRA
  847. LOG(tQBuf);
  848. #endif
  849. result = m_pDatabase->Query( tQBuf );
  850. if( result!= NULL ) {
  851. if( result->size() > 0 ) {
  852. Assoc *cArr;
  853. for(int i=0;i<result->size();i++){
  854. uint32_t nodeid=0;
  855. char uuid[64]={0};
  856. uint32_t ts=0;
  857. uint32_t ts_ms=0;
  858. uint32_t evt_t=0;
  859. uint32_t range_d=0;
  860. float az=.0f, el=.0f, ra=.0f, ar=.0f, lat=.0f, lon=.0f, alt=.0f;
  861. uint32_t ref_id=0;
  862. char ref_uuid[64]={0};
  863. Assoc::iterator it;
  864. cArr = result->at(i);
  865. it = cArr->find("id");
  866. if( it != cArr->end() ){
  867. LastID = atoi( it->second.c_str());
  868. };
  869. it = cArr->find("node_id");
  870. if( it != cArr->end() ){
  871. nodeid = atoi( it->second.c_str());
  872. };
  873. it = cArr->find("uuid");
  874. if( it != cArr->end() ){
  875. strncpy( uuid, it->second.c_str(), 64 );
  876. };
  877. it = cArr->find("ts");
  878. if( it != cArr->end() ){
  879. ts = atoi( it->second.c_str());
  880. };
  881. it = cArr->find("ts_ms");
  882. if( it != cArr->end() ){
  883. ts_ms = atoi( it->second.c_str());
  884. };
  885. it = cArr->find("evt_type");
  886. if( it != cArr->end() ){
  887. evt_t = atoi( it->second.c_str());
  888. };
  889. it = cArr->find("range_digital");
  890. if( it != cArr->end() ){
  891. range_d = atoi( it->second.c_str());
  892. };
  893. it = cArr->find("azimuth");
  894. if( it != cArr->end() ){
  895. az = (float)atof( it->second.c_str());
  896. };
  897. it = cArr->find("elevation");
  898. if( it != cArr->end() ){
  899. el = (float)atof( it->second.c_str());
  900. };
  901. it = cArr->find("range");
  902. if( it != cArr->end() ){
  903. ra = (float)atof( it->second.c_str());
  904. };
  905. it = cArr->find("area");
  906. if( it != cArr->end() ){
  907. ar = (float)atof( it->second.c_str());
  908. };
  909. it = cArr->find("lat");
  910. if( it != cArr->end() ){
  911. lat = (float)atof( it->second.c_str());
  912. };
  913. it = cArr->find("lon");
  914. if( it != cArr->end() ){
  915. lon = (float)atof( it->second.c_str());
  916. };
  917. it = cArr->find("alt");
  918. if( it != cArr->end() ){
  919. alt = (float)atof( it->second.c_str());
  920. };
  921. it = cArr->find("ref_id");
  922. if( it != cArr->end() ){
  923. ref_id = atoi( it->second.c_str());
  924. };
  925. it = cArr->find("ref_uuid");
  926. if( it != cArr->end() ){
  927. strncpy( ref_uuid, it->second.c_str(), 64 );
  928. };
  929. sprintf(tQBuf, "INSERT INTO `events_archive` SET `node_id`=%d, `uuid`='%s', `ts`=%d, `ts_ms`=%d, `evt_type`=%d, `range_digital`=%d, `azimuth`=%0.8f, `elevation`=%0.8f, `range`=%0.2f, `area`=%0.5f, `lat`=%0.8f, `lon`=%0.8f, `alt`=%0.3f, `ref_id`=%d, `ref_uuid`='%s'",
  930. nodeid,
  931. uuid,
  932. ts,
  933. ts_ms,
  934. evt_t,
  935. range_d,
  936. az,
  937. el,
  938. ra,
  939. ar,
  940. lat,
  941. lon,
  942. alt,
  943. ref_id,
  944. ref_uuid
  945. );
  946. uint32_t IID = (uint32_t) m_pDatabase->QueryID(tQBuf);
  947. sprintf(tQBuf,"UPDATE `events_2_pictures` SET `event_id`=%d WHERE `event_id`=%d", IID, LastID );
  948. //m_pDatabase->SilentQuery(tQBuf);
  949. sprintf(tQBuf,"UPDATE `events_2_videos` SET `event_id`=%d WHERE `event_id`=%d", IID, LastID );
  950. //m_pDatabase->SilentQuery(tQBuf);
  951. };
  952. };
  953. };
  954. deleteResult( result );
  955. };
  956. };
  957. DBC_INT_LIST *argusDBC::listCamMediaStreams( uint32_t CAMID ){
  958. DBC_INT_LIST * tVal = NULL;
  959. if(m_bIsConnected){
  960. char tQBuf[CTEXT];
  961. AAssoc *result;
  962. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `source_id`=%d AND `valid`=1", CAMID );
  963. #ifdef DEBUG_EXTRA
  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 = new DBC_INT_LIST();
  971. if( tVal != NULL ) {
  972. Assoc::iterator it;
  973. for(int i=0;i<result->size();i++) {
  974. cArr = result->at(i);
  975. it = cArr->find("id");
  976. if( it != cArr->end() ){
  977. tVal->push_back( atoi( it->second.c_str() ));
  978. };
  979. };
  980. };
  981. };
  982. };
  983. deleteResult( result );
  984. };
  985. return tVal;
  986. };
  987. DBC_INT_LIST *argusDBC::listStreamCapPictures( uint32_t StreamID, uint32_t cnt ){
  988. DBC_INT_LIST * tVal = NULL;
  989. if(m_bIsConnected){
  990. char tQBuf[CTEXT];
  991. AAssoc *result;
  992. sprintf(tQBuf, "SELECT `id` FROM `pictures` WHERE `media_stream_id`=%d LIMIT %d", StreamID, cnt );
  993. #ifdef DEBUG_EXTRA
  994. LOG(tQBuf);
  995. #endif
  996. result = m_pDatabase->Query( tQBuf );
  997. if( result!= NULL ) {
  998. if( result->size() > 0 ) {
  999. Assoc *cArr;
  1000. tVal = new DBC_INT_LIST();
  1001. if( tVal != NULL ) {
  1002. Assoc::iterator it;
  1003. for(int i=0;i<result->size();i++) {
  1004. cArr = result->at(i);
  1005. it = cArr->find("id");
  1006. if( it != cArr->end() ){
  1007. tVal->push_back( atoi( it->second.c_str() ));
  1008. };
  1009. };
  1010. };
  1011. };
  1012. };
  1013. deleteResult( result );
  1014. };
  1015. return tVal;
  1016. };
  1017. DBC_NETWORK_DATA *argusDBC::getNetworkData( uint32_t net_id ){
  1018. DBC_NETWORK_DATA * tVal = NULL;
  1019. if(m_bIsConnected){
  1020. char tQBuf[CTEXT];
  1021. AAssoc *result;
  1022. sprintf(tQBuf, "SELECT * FROM `networks` WHERE `id`=%d", net_id );
  1023. #ifdef DEBUG_EXTRA
  1024. LOG(tQBuf);
  1025. #endif
  1026. result = m_pDatabase->Query( tQBuf );
  1027. if( result!= NULL ) {
  1028. if( result->size() > 0 ) {
  1029. Assoc *cArr;
  1030. tVal = (DBC_NETWORK_DATA*) malloc(sizeof(DBC_NETWORK_DATA));
  1031. if( tVal != NULL ) {
  1032. memset(tVal, 0, sizeof(DBC_NETWORK_DATA));
  1033. Assoc::iterator it;
  1034. tVal->id = net_id;
  1035. cArr = result->at(0);
  1036. it = cArr->find("nif_id");
  1037. if( it != cArr->end() ){
  1038. tVal->nif_id = atoi(it->second.c_str());
  1039. };
  1040. it = cArr->find("type");
  1041. if( it != cArr->end() ){
  1042. tVal->type = (ARGUS_NETWORK_TYPE) atoi(it->second.c_str());
  1043. };
  1044. it = cArr->find("address");
  1045. if( it != cArr->end() ){
  1046. strncpy( tVal->address, it->second.c_str(), 65 );
  1047. tVal->address[64]=(char)0;
  1048. };
  1049. it = cArr->find("gateway");
  1050. if( it != cArr->end() ){
  1051. strncpy(tVal->gateway, it->second.c_str(), 65);
  1052. tVal->gateway[64]=(char)0;
  1053. };
  1054. it = cArr->find("mask");
  1055. if( it != cArr->end() ){
  1056. strncpy( tVal->netmask, it->second.c_str(), 65 );
  1057. tVal->netmask[64]=(char)0;
  1058. };
  1059. it = cArr->find("broadcast");
  1060. if( it != cArr->end() ){
  1061. strncpy( tVal->broadcast, it->second.c_str(), 65 );
  1062. tVal->broadcast[64]=(char)0;
  1063. };
  1064. };
  1065. };
  1066. };
  1067. deleteResult( result );
  1068. };
  1069. return tVal;
  1070. };
  1071. DBC_NET_IF_DATA *argusDBC::getNIF_Data( uint32_t nif_id ){
  1072. DBC_NET_IF_DATA * tVal = NULL;
  1073. if(m_bIsConnected){
  1074. char tQBuf[CTEXT];
  1075. AAssoc *result;
  1076. sprintf(tQBuf, "SELECT `type`, `mode`, `device_name`, `mac`, `aux_id` FROM `network_interfaces` WHERE `id`=%d", nif_id );
  1077. #ifdef DEBUG_EXTRA
  1078. LOG(tQBuf);
  1079. #endif
  1080. result = m_pDatabase->Query( tQBuf );
  1081. if( result!= NULL ) {
  1082. if( result->size() > 0 ) {
  1083. Assoc *cArr;
  1084. tVal = (DBC_NET_IF_DATA*) malloc(sizeof(DBC_NET_IF_DATA));
  1085. if( tVal != NULL ) {
  1086. Assoc::iterator it;
  1087. tVal->id = nif_id;
  1088. cArr = result->at(0);
  1089. it = cArr->find("type");
  1090. if( it != cArr->end() ){
  1091. tVal->type = atoi(it->second.c_str());
  1092. };
  1093. it = cArr->find("mode");
  1094. if( it != cArr->end() ){
  1095. tVal->mode = atoi(it->second.c_str());
  1096. };
  1097. it = cArr->find("device_name");
  1098. if( it != cArr->end() ){
  1099. strncpy( tVal->device_name, it->second.c_str(),11);
  1100. tVal->device_name[10]=(char)0;
  1101. };
  1102. it = cArr->find("mac");
  1103. if( it != cArr->end() ){
  1104. strncpy( tVal->mac, it->second.c_str(), 33 );
  1105. tVal->mac[32]=(char)0;
  1106. };
  1107. it = cArr->find("aux_id");
  1108. if( it != cArr->end() ){
  1109. tVal->aux_id = atoi(it->second.c_str());
  1110. };
  1111. };
  1112. };
  1113. };
  1114. deleteResult( result );
  1115. };
  1116. return tVal;
  1117. };
  1118. uint32_t argusDBC::getNetworkInfrastructureID( uint32_t nif_id ){
  1119. uint32_t tVal = 0;
  1120. if(m_bIsConnected){
  1121. char tQBuf[CTEXT];
  1122. AAssoc *result;
  1123. sprintf(tQBuf, "SELECT id FROM `network_infrastructure` WHERE `nif_id`=%d", nif_id );
  1124. #ifdef DEBUG
  1125. LOG(tQBuf);
  1126. #endif
  1127. result = m_pDatabase->Query( tQBuf );
  1128. if( result!= NULL ) {
  1129. if( result->size() > 0 ) {
  1130. Assoc *cArr;
  1131. Assoc::iterator it;
  1132. cArr = result->at(0);
  1133. it = cArr->find("id");
  1134. if( it != cArr->end() ){
  1135. tVal = atoi( it->second.c_str() );
  1136. };
  1137. };
  1138. };
  1139. deleteResult( result );
  1140. };
  1141. return tVal;
  1142. };
  1143. CSTR argusDBC::getNodeName( uint32_t NodeID ){
  1144. CSTR tVal = NULL;
  1145. if(m_bIsConnected){
  1146. char tQBuf[CTEXT];
  1147. AAssoc *result;
  1148. sprintf(tQBuf, "SELECT `name` FROM `nodes` WHERE `id`=%d", NodeID );
  1149. #ifdef DEBUG
  1150. LOG(tQBuf);
  1151. #endif
  1152. result = m_pDatabase->Query( tQBuf );
  1153. if( result!= NULL ) {
  1154. if( result->size() > 0 ) {
  1155. Assoc *cArr;
  1156. Assoc::iterator it;
  1157. cArr = result->at(0);
  1158. it = cArr->find("name");
  1159. if( it != cArr->end() ){
  1160. tVal = strdup( it->second.c_str() );
  1161. };
  1162. };
  1163. };
  1164. deleteResult( result );
  1165. };
  1166. return tVal;
  1167. };
  1168. uint32_t argusDBC::getNodeAuxID( uint32_t NodeID ){
  1169. uint32_t tVal;
  1170. if(m_bIsConnected){
  1171. char tQBuf[CTEXT];
  1172. AAssoc *result;
  1173. sprintf(tQBuf, "SELECT `aux_id` FROM `nodes` WHERE `id`=%d", NodeID );
  1174. #ifdef DEBUG
  1175. LOG(tQBuf);
  1176. #endif
  1177. result = m_pDatabase->Query( tQBuf );
  1178. if( result!= NULL ) {
  1179. if( result->size() > 0 ) {
  1180. Assoc *cArr;
  1181. Assoc::iterator it;
  1182. cArr = result->at(0);
  1183. it = cArr->find("aux_id");
  1184. if( it != cArr->end() ){
  1185. tVal = atoi( it->second.c_str() );
  1186. };
  1187. };
  1188. };
  1189. deleteResult( result );
  1190. };
  1191. return tVal;
  1192. };
  1193. uint32_t argusDBC::getNodeAuxParam( uint32_t NodeID ){
  1194. uint32_t tVal;
  1195. if(m_bIsConnected){
  1196. char tQBuf[CTEXT];
  1197. AAssoc *result;
  1198. sprintf(tQBuf, "SELECT `aux_parameter` FROM `nodes` WHERE `id`=%d", NodeID );
  1199. #ifdef DEBUG
  1200. LOG(tQBuf);
  1201. #endif
  1202. result = m_pDatabase->Query( tQBuf );
  1203. if( result!= NULL ) {
  1204. if( result->size() > 0 ) {
  1205. Assoc *cArr;
  1206. Assoc::iterator it;
  1207. cArr = result->at(0);
  1208. it = cArr->find("aux_parameter");
  1209. if( it != cArr->end() ){
  1210. tVal = atoi( it->second.c_str() );
  1211. };
  1212. };
  1213. };
  1214. deleteResult( result );
  1215. };
  1216. return tVal;
  1217. };
  1218. uint32_t argusDBC::getWiFi_ID( uint32_t nif_id ){
  1219. uint32_t tVal = 0;
  1220. if(m_bIsConnected){
  1221. char tQBuf[CTEXT];
  1222. AAssoc *result;
  1223. sprintf(tQBuf, "SELECT `id` FROM `wifis` WHERE `nif_id`=%d", nif_id );
  1224. #ifdef DEBUG
  1225. LOG(tQBuf);
  1226. #endif
  1227. result = m_pDatabase->Query( tQBuf );
  1228. if( result!= NULL ) {
  1229. if( result->size() > 0 ) {
  1230. Assoc *cArr;
  1231. Assoc::iterator it;
  1232. cArr = result->at(0);
  1233. it = cArr->find("id");
  1234. if( it != cArr->end() ){
  1235. tVal = atoi( it->second.c_str() );
  1236. };
  1237. };
  1238. };
  1239. deleteResult( result );
  1240. };
  1241. return tVal;
  1242. };
  1243. uint32_t argusDBC::getNIF_ID( CSTR key ){
  1244. uint32_t tVal = 0;
  1245. if(m_bIsConnected){
  1246. char tQBuf[CTEXT];
  1247. AAssoc *result;
  1248. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `key`='%s'", key );
  1249. #ifdef DEBUG_EXTRA
  1250. LOG(tQBuf);
  1251. #endif
  1252. result = m_pDatabase->Query( tQBuf );
  1253. if( result!= NULL ) {
  1254. if( result->size() > 0 ) {
  1255. Assoc *cArr;
  1256. Assoc::iterator it;
  1257. cArr = result->at(0);
  1258. it = cArr->find("id");
  1259. if( it != cArr->end() ){
  1260. tVal = atoi( it->second.c_str() );
  1261. };
  1262. };
  1263. };
  1264. deleteResult( result );
  1265. };
  1266. return tVal;
  1267. };
  1268. uint32_t argusDBC::getNIF_IDbyDevice( CSTR device ){
  1269. uint32_t tVal = 0;
  1270. if(m_bIsConnected){
  1271. char tQBuf[CTEXT];
  1272. AAssoc *result;
  1273. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `device_name`='%s'", device );
  1274. #ifdef DEBUG
  1275. LOG(tQBuf);
  1276. #endif
  1277. result = m_pDatabase->Query( tQBuf );
  1278. if( result!= NULL ) {
  1279. if( result->size() > 0 ) {
  1280. Assoc *cArr;
  1281. Assoc::iterator it;
  1282. cArr = result->at(0);
  1283. it = cArr->find("id");
  1284. if( it != cArr->end() ){
  1285. tVal = atoi( it->second.c_str() );
  1286. };
  1287. };
  1288. };
  1289. deleteResult( result );
  1290. };
  1291. return tVal;
  1292. };
  1293. DBC_NODE_DATA *argusDBC::getNodeData( uint32_t ID ){
  1294. DBC_NODE_DATA * tVal = NULL;
  1295. if(m_bIsConnected){
  1296. char tQBuf[CTEXT];
  1297. AAssoc *result;
  1298. sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );
  1299. #ifdef DEBUG_EXTRA
  1300. LOG(tQBuf);
  1301. #endif
  1302. result = m_pDatabase->Query( tQBuf );
  1303. if( result!= NULL ) {
  1304. if( result->size() > 0 ) {
  1305. Assoc *cArr;
  1306. tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
  1307. if( tVal != NULL ) {
  1308. memset( tVal, 0, sizeof(DBC_NODE_DATA));
  1309. Assoc::iterator it;
  1310. cArr = result->at(0);
  1311. it = cArr->find("id");
  1312. if( it != cArr->end() ){
  1313. tVal->node_id = atoi( it->second.c_str() );
  1314. };
  1315. it = cArr->find("type");
  1316. if( it != cArr->end() ){
  1317. tVal->type = (ARGUS_NODE_TYPE) atoi( it->second.c_str() );
  1318. };
  1319. it = cArr->find("aux_id");
  1320. if( it != cArr->end() ){
  1321. tVal->aux_id = atoi( it->second.c_str() );
  1322. };
  1323. it = cArr->find("aux_parameter");
  1324. if( it != cArr->end() ){
  1325. tVal->aux_parameter = atoi( it->second.c_str() );
  1326. };
  1327. it = cArr->find("name");
  1328. if( it != cArr->end() ){
  1329. sprintf( tVal->name, it->second.c_str() );
  1330. };
  1331. it = cArr->find("ts_s");
  1332. if( it != cArr->end() ){
  1333. tVal->tss = atoi( it->second.c_str() );
  1334. };
  1335. it = cArr->find("ts_ms");
  1336. if( it != cArr->end() ){
  1337. tVal->tsm = atoi( it->second.c_str() );
  1338. };
  1339. it = cArr->find("online");
  1340. if( it != cArr->end() ){
  1341. tVal->online = (bool)atoi( it->second.c_str() );
  1342. };
  1343. };
  1344. };
  1345. };
  1346. deleteResult( result );
  1347. };
  1348. return tVal;
  1349. };
  1350. DBC_APF_DATA *argusDBC::getAPFData( uint32_t APFID ){
  1351. DBC_APF_DATA * tVal = NULL;
  1352. if(m_bIsConnected){
  1353. char tQBuf[CTEXT];
  1354. AAssoc *result;
  1355. sprintf(tQBuf, "SELECT * FROM `target_filter_apf` WHERE `id`=%d", APFID );
  1356. #ifdef DEBUG
  1357. LOG(tQBuf);
  1358. #endif
  1359. result = m_pDatabase->Query( tQBuf );
  1360. if( result!= NULL ) {
  1361. if( result->size() > 0 ) {
  1362. Assoc *cArr;
  1363. tVal = (DBC_APF_DATA*) malloc(sizeof(DBC_APF_DATA));
  1364. if( tVal != NULL ) {
  1365. memset( tVal, 0 , sizeof(DBC_APF_DATA));
  1366. Assoc::iterator it;
  1367. cArr = result->at(0);
  1368. it = cArr->find("mode");
  1369. if( it != cArr->end() ){
  1370. sprintf( tVal->mode, it->second.c_str() );
  1371. };
  1372. it = cArr->find("port");
  1373. if( it != cArr->end() ){
  1374. tVal->port = atoi( it->second.c_str() );
  1375. };
  1376. it = cArr->find("lat");
  1377. if( it != cArr->end() ){
  1378. tVal->lat = atof( it->second.c_str() );
  1379. };
  1380. it = cArr->find("lon");
  1381. if( it != cArr->end() ){
  1382. tVal->lon = atof( it->second.c_str() );
  1383. };
  1384. it = cArr->find("alt");
  1385. if( it != cArr->end() ){
  1386. tVal->alt = atof( it->second.c_str() );
  1387. };
  1388. it = cArr->find("roll");
  1389. if( it != cArr->end() ){
  1390. tVal->roll = atof( it->second.c_str() );
  1391. };
  1392. it = cArr->find("pitch");
  1393. if( it != cArr->end() ){
  1394. tVal->pitch = atof( it->second.c_str() );
  1395. };
  1396. it = cArr->find("yaw");
  1397. if( it != cArr->end() ){
  1398. tVal->yaw = atof( it->second.c_str() );
  1399. };
  1400. it = cArr->find("dx");
  1401. if( it != cArr->end() ){
  1402. tVal->dx = atof( it->second.c_str() );
  1403. };
  1404. it = cArr->find("dy");
  1405. if( it != cArr->end() ){
  1406. tVal->dy = atof( it->second.c_str() );
  1407. };
  1408. it = cArr->find("dz");
  1409. if( it != cArr->end() ){
  1410. tVal->dz = atof( it->second.c_str() );
  1411. };
  1412. };
  1413. };
  1414. };
  1415. deleteResult( result );
  1416. };
  1417. return tVal;
  1418. };
  1419. DBC_FH_DATA *argusDBC::getFlyHunterData( uint32_t ID ){
  1420. DBC_FH_DATA * tVal = NULL;
  1421. if(m_bIsConnected){
  1422. char tQBuf[CTEXT];
  1423. AAssoc *result;
  1424. sprintf(tQBuf, "SELECT * FROM `modules_fly_hunter` WHERE `id`=%d", ID );
  1425. #ifdef DEBUG
  1426. LOG(tQBuf);
  1427. #endif
  1428. result = m_pDatabase->Query( tQBuf );
  1429. if( result!= NULL ) {
  1430. if( result->size() > 0 ) {
  1431. Assoc *cArr;
  1432. tVal = (DBC_FH_DATA*) malloc(sizeof(DBC_FH_DATA));
  1433. if( tVal != NULL ) {
  1434. memset( tVal, 0 , sizeof(DBC_FH_DATA));
  1435. Assoc::iterator it;
  1436. cArr = result->at(0);
  1437. it = cArr->find("name");
  1438. if( it != cArr->end() ){
  1439. sprintf( tVal->name, it->second.c_str() );
  1440. };
  1441. it = cArr->find("lat");
  1442. if( it != cArr->end() ){
  1443. tVal->lat = atof( it->second.c_str() );
  1444. };
  1445. it = cArr->find("lon");
  1446. if( it != cArr->end() ){
  1447. tVal->lon = atof( it->second.c_str() );
  1448. };
  1449. it = cArr->find("alt");
  1450. if( it != cArr->end() ){
  1451. tVal->alt = atof( it->second.c_str() );
  1452. };
  1453. it = cArr->find("dc_module_id");
  1454. if( it != cArr->end() ){
  1455. tVal->dc_id = atoi( it->second.c_str() );
  1456. };
  1457. it = cArr->find("uart_id");
  1458. if( it != cArr->end() ){
  1459. tVal->uart_id = atoi( it->second.c_str() );
  1460. };
  1461. };
  1462. };
  1463. };
  1464. deleteResult( result );
  1465. };
  1466. return tVal;
  1467. };
  1468. bool argusDBC::fillShadow2D( uint32_t ID, SHADOW & SH ){
  1469. if( m_bIsConnected ){
  1470. char tQBuf[CTEXT];
  1471. AAssoc *result;
  1472. sprintf(tQBuf, "SELECT `lv`.`id`, `lm`.`layer`, `lm`.`status` FROM `lrf_mask_vertexes` `lv` LEFT JOIN `lrf_masks` `lm` ON (`lm`.`id` = `lv`.`mask_id`) WHERE `lm`.`sensor_id`=%d ORDER BY `lv`.`id`", ID );
  1473. LOG(tQBuf);
  1474. result = m_pDatabase->Query( tQBuf );
  1475. if( result!= NULL ) {
  1476. if( result->size() > 0 ) {
  1477. SH.m_nEnabled = 0xFFFFFFFF;
  1478. SH.m_nPolygonCount = result->size();
  1479. SH.pPolygones = (SHADOW_POLY *) calloc( SH.m_nPolygonCount, sizeof( SHADOW_POLY ) );
  1480. if ( SH.pPolygones ) {
  1481. Assoc * cArr;
  1482. for ( uint8_t idx = 0; idx < result->size(); idx++ ) {
  1483. Assoc::iterator it;
  1484. cArr = result->at(idx);
  1485. it = cArr->find("id");
  1486. if( it != cArr->end() ){
  1487. SH.pPolygones[idx].m_nDBID = atoi(it->second.c_str());
  1488. };
  1489. it = cArr->find("layer");
  1490. if( it != cArr->end() ){
  1491. SH.pPolygones[idx].bType = atoi(it->second.c_str());
  1492. };
  1493. it = cArr->find("status");
  1494. if( it != cArr->end() ){
  1495. SH.m_nEnabled &= ( it->second.c_str()[0] == 'E' )?0xFFFFFFFF:~(1<<SH.pPolygones[idx].bType);
  1496. };
  1497. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", SH.pPolygones[idx].m_nDBID );
  1498. LOG(tQBuf);
  1499. AAssoc *v_result = m_pDatabase->Query( tQBuf );
  1500. if( v_result!= NULL ) {
  1501. if( v_result->size() > 0 ) {
  1502. SH.pPolygones[idx].wCount = v_result->size();
  1503. SH.pPolygones[idx].pPoint = (HZ_POINT *) calloc( SH.pPolygones[idx].wCount, sizeof( HZ_POINT ) );
  1504. if(SH.pPolygones[idx].pPoint ) {
  1505. for ( uint32_t zdx =0; zdx < SH.pPolygones[idx].wCount; zdx++ ) {
  1506. cArr = v_result->at(zdx);
  1507. it = cArr->find("x");
  1508. if( it != cArr->end() ){
  1509. SH.pPolygones[idx].pPoint[zdx].wX = atoi(it->second.c_str());
  1510. };
  1511. it = cArr->find("y");
  1512. if( it != cArr->end() ){
  1513. SH.pPolygones[idx].pPoint[zdx].wY = atoi(it->second.c_str());
  1514. };
  1515. LOG("Point Added!");
  1516. };
  1517. } else {
  1518. LOG("No mem for Points!");
  1519. };
  1520. } else {
  1521. LOG("No Points!");
  1522. SH.pPolygones[idx].wCount = 0;
  1523. SH.pPolygones[idx].pPoint = NULL;
  1524. };
  1525. deleteResult( v_result );
  1526. };
  1527. };
  1528. };
  1529. };
  1530. deleteResult( result );
  1531. };
  1532. return true;
  1533. };
  1534. return false;
  1535. };
  1536. DBC_SITE_DATA *argusDBC::getSiteData( uint32_t ID ){
  1537. DBC_SITE_DATA * tVal = NULL;
  1538. if(m_bIsConnected){
  1539. char tQBuf[CTEXT];
  1540. AAssoc *result;
  1541. sprintf(tQBuf, "SELECT * FROM sites WHERE `id`=%d", ID );
  1542. #ifdef DEBUG
  1543. LOG(tQBuf);
  1544. #endif
  1545. result = m_pDatabase->Query( tQBuf );
  1546. if( result!= NULL ) {
  1547. if( result->size() > 0 ) {
  1548. Assoc *cArr;
  1549. tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA));
  1550. if( tVal != NULL ) {
  1551. memset( tVal, 0 , sizeof(DBC_SITE_DATA));
  1552. Assoc::iterator it;
  1553. cArr = result->at(0);
  1554. it = cArr->find("account_id");
  1555. if( it != cArr->end() ){
  1556. tVal->account_id = atoi( it->second.c_str() );
  1557. };
  1558. it = cArr->find("name");
  1559. if( it != cArr->end() ){
  1560. sprintf( tVal->name, it->second.c_str() );
  1561. };
  1562. it = cArr->find("server_ident");
  1563. if( it != cArr->end() ){
  1564. sprintf( tVal->ident, it->second.c_str() );
  1565. };
  1566. it = cArr->find("anchor_lat");
  1567. if( it != cArr->end() ){
  1568. tVal->lat = atof( it->second.c_str() );
  1569. };
  1570. it = cArr->find("anchor_lon");
  1571. if( it != cArr->end() ){
  1572. tVal->lon = atof( it->second.c_str() );
  1573. };
  1574. it = cArr->find("anchor_alt");
  1575. if( it != cArr->end() ){
  1576. tVal->alt = atof( it->second.c_str() );
  1577. };
  1578. it = cArr->find("hemisphere");
  1579. if( it != cArr->end() ){
  1580. tVal->SH = ( it->second.c_str()[0] == 'S' );
  1581. };
  1582. it = cArr->find("map_id");
  1583. if( it != cArr->end() ){
  1584. tVal->map_id = atoi( it->second.c_str() );
  1585. };
  1586. it = cArr->find("local_binding");
  1587. if( it != cArr->end() ){
  1588. tVal->local_binding = (bool) atoi(it->second.c_str());
  1589. };
  1590. };
  1591. };
  1592. };
  1593. deleteResult( result );
  1594. };
  1595. return tVal;
  1596. };
  1597. DBC_TARGET_FLITER_DATA *argusDBC::getTargetFilterData( uint32_t ID ){
  1598. DBC_TARGET_FLITER_DATA * tVal = NULL;
  1599. if(m_bIsConnected){
  1600. char tQBuf[CTEXT];
  1601. AAssoc *result;
  1602. sprintf(tQBuf, "SELECT * FROM target_filters WHERE `id`=%d", ID );
  1603. #ifdef DEBUG
  1604. LOG(tQBuf);
  1605. #endif
  1606. result = m_pDatabase->Query( tQBuf );
  1607. if( result!= NULL ) {
  1608. if( result->size() > 0 ) {
  1609. Assoc *cArr;
  1610. tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA));
  1611. if( tVal != NULL ) {
  1612. memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA));
  1613. Assoc::iterator it;
  1614. tVal->id = ID;
  1615. cArr = result->at(0);
  1616. it = cArr->find("type");
  1617. if( it != cArr->end() ){
  1618. tVal->type = atoi( it->second.c_str() );
  1619. };
  1620. it = cArr->find("aux_id");
  1621. if( it != cArr->end() ){
  1622. tVal->aux_id = atoi( it->second.c_str() );
  1623. };
  1624. };
  1625. };
  1626. };
  1627. deleteResult( result );
  1628. };
  1629. return tVal;
  1630. };
  1631. DBC_LRF_DATA *argusDBC::getLRFData( uint32_t ID ){
  1632. DBC_LRF_DATA * tVal = NULL;
  1633. if(m_bIsConnected){
  1634. char tQBuf[CTEXT];
  1635. AAssoc *result;
  1636. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  1637. #ifdef DEBUG
  1638. LOG(tQBuf);
  1639. #endif
  1640. result = m_pDatabase->Query( tQBuf );
  1641. if( result!= NULL ) {
  1642. if( result->size() > 0 ) {
  1643. Assoc *cArr;
  1644. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  1645. if( tVal != NULL ) {
  1646. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  1647. Assoc::iterator it;
  1648. tVal->id = ID;
  1649. cArr = result->at(0);
  1650. it = cArr->find("data_status");
  1651. if( it != cArr->end() ){
  1652. tVal->data_status = atoi( it->second.c_str() );
  1653. };
  1654. it = cArr->find("serial");
  1655. if( it != cArr->end() ){
  1656. strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 );
  1657. tVal->serial[sizeof(tVal->serial)-1]=(char)0;
  1658. };
  1659. it = cArr->find("version");
  1660. if( it != cArr->end() ){
  1661. strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 );
  1662. tVal->version[sizeof(tVal->version)-1]=(char)0;
  1663. };
  1664. it = cArr->find("x");
  1665. if( it != cArr->end() ){
  1666. tVal->x = atof( it->second.c_str() );
  1667. };
  1668. it = cArr->find("y");
  1669. if( it != cArr->end() ){
  1670. tVal->y = atof( it->second.c_str() );
  1671. };
  1672. it = cArr->find("z");
  1673. if( it != cArr->end() ){
  1674. tVal->z = atof( it->second.c_str() );
  1675. };
  1676. it = cArr->find("x_rot");
  1677. if( it != cArr->end() ){
  1678. tVal->x_rot = atof( it->second.c_str() );
  1679. };
  1680. it = cArr->find("y_rot");
  1681. if( it != cArr->end() ){
  1682. tVal->y_rot = atof( it->second.c_str() );
  1683. };
  1684. it = cArr->find("z_rot");
  1685. if( it != cArr->end() ){
  1686. tVal->z_rot = atof( it->second.c_str() );
  1687. };
  1688. it = cArr->find("uart_id");
  1689. if( it != cArr->end() ){
  1690. tVal->uart_id = atoi( it->second.c_str() );
  1691. };
  1692. it = cArr->find("device_id");
  1693. if( it != cArr->end() ){
  1694. tVal->device_id = atoi( it->second.c_str() );
  1695. };
  1696. it = cArr->find("ip_address");
  1697. if( it != cArr->end() ){
  1698. sprintf( tVal->master_host, it->second.c_str() );
  1699. };
  1700. it = cArr->find("aux_ip_address");
  1701. if( it != cArr->end() ){
  1702. sprintf( tVal->slave_host, it->second.c_str() );
  1703. };
  1704. it = cArr->find("port");
  1705. if( it != cArr->end() ){
  1706. tVal->master_port = atoi( it->second.c_str() );
  1707. };
  1708. it = cArr->find("aux_port");
  1709. if( it != cArr->end() ){
  1710. tVal->slave_port = atoi( it->second.c_str() );
  1711. };
  1712. it = cArr->find("auto_draw");
  1713. if( it != cArr->end() ){
  1714. tVal->auto_draw = atoi( it->second.c_str() );
  1715. };
  1716. it = cArr->find("filter_id");
  1717. if( it != cArr->end() ){
  1718. tVal->filter_id = atoi( it->second.c_str() );
  1719. };
  1720. //it = cArr->find("enabled_lrf");
  1721. //if( it != cArr->end() ){
  1722. // tVal->enabled_lrf = atoi( it->second.c_str() );
  1723. //};
  1724. it = cArr->find("max_range");
  1725. if( it != cArr->end() ){
  1726. tVal->max_range = atof( it->second.c_str() );
  1727. };
  1728. it = cArr->find("base_shift");
  1729. if( it != cArr->end() ){
  1730. tVal->base_shift = atoi( it->second.c_str() );
  1731. };
  1732. it = cArr->find("mirror_shift");
  1733. if( it != cArr->end() ){
  1734. tVal->mirror_shift = atoi( it->second.c_str() );
  1735. };
  1736. it = cArr->find("detection_profile_id");
  1737. if( it != cArr->end() ){
  1738. tVal->detection_profile_id = atoi( it->second.c_str() );
  1739. };
  1740. it = cArr->find("draw_lrf_id");
  1741. if( it != cArr->end() ){
  1742. tVal->draw_lrf_id = atoi( it->second.c_str() );
  1743. };
  1744. it = cArr->find("width_table_id");
  1745. if( it != cArr->end() ){
  1746. tVal->width_table_id = atoi( it->second.c_str() );
  1747. };
  1748. it = cArr->find("zoom_table_id");
  1749. if( it != cArr->end() ){
  1750. tVal->zoom_table_id = atoi( it->second.c_str() );
  1751. };
  1752. it = cArr->find("embd_cam");
  1753. if( it != cArr->end() ){
  1754. tVal->embd_cam = atoi( it->second.c_str() );
  1755. };
  1756. it = cArr->find("embd_cam_auto");
  1757. if( it != cArr->end() ){
  1758. tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
  1759. };
  1760. it = cArr->find("embd_dc");
  1761. if( it != cArr->end() ){
  1762. tVal->embd_dc = atoi( it->second.c_str() );
  1763. };
  1764. it = cArr->find("autoreset");
  1765. if( it != cArr->end() ){
  1766. tVal->autoreset = (bool)atoi( it->second.c_str() );
  1767. };
  1768. it = cArr->find("force_settings");
  1769. if( it != cArr->end() ){
  1770. tVal->force_settings = (bool)atoi( it->second.c_str() );
  1771. };
  1772. };
  1773. };
  1774. };
  1775. deleteResult( result );
  1776. };
  1777. return tVal;
  1778. };
  1779. uint8_t argusDBC::getLRFDataStatus( uint32_t ID ){
  1780. uint8_t RetVal = 0;
  1781. if(m_bIsConnected){
  1782. char tQBuf[CTEXT];
  1783. AAssoc *result;
  1784. sprintf(tQBuf, "SELECT `data_status` FROM `lrf_sensors` WHERE `id`=%d", ID );
  1785. #ifdef DEBUG
  1786. LOG(tQBuf);
  1787. #endif
  1788. result = m_pDatabase->Query( tQBuf );
  1789. if( result!= NULL ) {
  1790. if( result->size() > 0 ) {
  1791. Assoc *cArr;
  1792. Assoc::iterator it;
  1793. cArr = result->at(0);
  1794. it = cArr->find("data_status");
  1795. if( it != cArr->end() ){
  1796. RetVal = atoi( it->second.c_str() );
  1797. };
  1798. };
  1799. };
  1800. deleteResult( result );
  1801. };
  1802. return RetVal;
  1803. };
  1804. PLGS_2D_PARAMETERS argusDBC::getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){
  1805. PLGS_2D_PARAMETERS retVal = NULL;
  1806. if(m_bIsConnected){
  1807. char tQBuf[CTEXT];
  1808. AAssoc *result;
  1809. sprintf(tQBuf, "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'%c'", lrfID, profileID,((master)?'1':'0') );
  1810. #ifdef DEBUG
  1811. LOG(tQBuf);
  1812. #endif
  1813. result = m_pDatabase->Query( tQBuf );
  1814. if( result!= NULL ) {
  1815. if( result->size() > 0 ) {
  1816. retVal = (PLGS_2D_PARAMETERS) malloc(sizeof(LGS_2D_PARAMETERS));
  1817. memset( retVal, 0, sizeof(LGS_2D_PARAMETERS));
  1818. Assoc *cArr;
  1819. Assoc::iterator it;
  1820. cArr = result->at(0);
  1821. it = cArr->find("order");
  1822. if( it != cArr->end() ){
  1823. retVal->nOrder = atoi(it->second.c_str());
  1824. };
  1825. it = cArr->find("offset");
  1826. if( it != cArr->end() ){
  1827. retVal->nOffset = atoi(it->second.c_str());
  1828. };
  1829. it = cArr->find("delta");
  1830. if( it != cArr->end() ){
  1831. retVal->nDelta = atoi(it->second.c_str());
  1832. };
  1833. it = cArr->find("flip");
  1834. if( it != cArr->end() ){
  1835. retVal->nFlip = atoi(it->second.c_str());
  1836. };
  1837. it = cArr->find("width");
  1838. if( it != cArr->end() ){
  1839. retVal->nWidth = atoi(it->second.c_str());
  1840. };
  1841. it = cArr->find("sst");
  1842. if( it != cArr->end() ){
  1843. retVal->bSST = atoi(it->second.c_str());
  1844. };
  1845. it = cArr->find("sun");
  1846. if( it != cArr->end() ){
  1847. retVal->nSun = atoi(it->second.c_str());
  1848. };
  1849. };
  1850. };
  1851. deleteResult( result );
  1852. };
  1853. return retVal;
  1854. };
  1855. CSTR argusDBC::getLRFDraw( uint32_t DBID ){
  1856. CSTR RetVal = NULL;
  1857. if(m_bIsConnected){
  1858. char tQBuf[CTEXT];
  1859. AAssoc *result;
  1860. sprintf(tQBuf, "SELECT `md5` FROM `lrf_draw` WHERE `node_id`=%d", DBID );
  1861. #ifdef DEBUG
  1862. LOG(tQBuf);
  1863. #endif
  1864. result = m_pDatabase->Query( tQBuf );
  1865. if( result!= NULL ) {
  1866. if( result->size() > 0 ) {
  1867. Assoc *cArr;
  1868. Assoc::iterator it;
  1869. cArr = result->at(0);
  1870. it = cArr->find("md5");
  1871. if( it != cArr->end() ){
  1872. RetVal = strdup( it->second.c_str() );
  1873. };
  1874. };
  1875. };
  1876. deleteResult( result );
  1877. };
  1878. return RetVal;
  1879. };
  1880. uint32_t argusDBC::getLRFMaskID( uint32_t deviceID, uint8_t lrfID, uint8_t layer ){
  1881. uint32_t RetVal = 0;
  1882. if(m_bIsConnected){
  1883. char tQBuf[CTEXT];
  1884. AAssoc *result;
  1885. sprintf(tQBuf, "SELECT `id` FROM `lrf_masks` WHERE `sensor_id`=%d AND `lrf_id`=%d AND `layer`=%d ", deviceID, lrfID, layer );
  1886. #ifdef DEBUG
  1887. LOG(tQBuf);
  1888. #endif
  1889. result = m_pDatabase->Query( tQBuf );
  1890. if( result!= NULL ) {
  1891. if( result->size() > 0 ) {
  1892. Assoc *cArr;
  1893. Assoc::iterator it;
  1894. cArr = result->at(0);
  1895. it = cArr->find("id");
  1896. if( it != cArr->end() ){
  1897. RetVal = atoi( it->second.c_str() );
  1898. };
  1899. };
  1900. };
  1901. deleteResult( result );
  1902. };
  1903. return RetVal;
  1904. };
  1905. /*
  1906. DBC_PUSHED_CMD *argusDBC::getLRFPushedCMD( uint32_t ID ){
  1907. DBC_PUSHED_CMD *RetVal = NULL;
  1908. if(m_bIsConnected){
  1909. char tQBuf[CTEXT];
  1910. AAssoc *result;
  1911. sprintf(tQBuf, "SELECT `pushed_cmd`, `pushed_param` FROM `lrf_sensors` WHERE `id`=%d AND `pushed_cmd` > 0", ID );
  1912. #ifdef DEBUG
  1913. //LOG(tQBuf);
  1914. #endif
  1915. result = m_pDatabase->Query( tQBuf );
  1916. if( result!= NULL ) {
  1917. if( result->size() > 0 ) {
  1918. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  1919. if( RetVal ) {
  1920. Assoc *cArr;
  1921. Assoc::iterator it;
  1922. cArr = result->at(0);
  1923. it = cArr->find("pushed_cmd");
  1924. if( it != cArr->end() ){
  1925. RetVal->CMD = atoi( it->second.c_str() );
  1926. };
  1927. it = cArr->find("pushed_param");
  1928. if( it != cArr->end() ){
  1929. RetVal->PARAM = atoi( it->second.c_str() );
  1930. };
  1931. };
  1932. };
  1933. //Only If Result is Fetched - Clear Current CMD
  1934. sprintf(tQBuf, "UPDATE `lrf_sensors` SET `pushed_cmd`=0, `pushed_param`=0 WHERE `id`=%d", ID );
  1935. m_pDatabase->SilentQuery( tQBuf );
  1936. };
  1937. deleteResult( result );
  1938. };
  1939. return RetVal;
  1940. };
  1941. */
  1942. DBC_INT_LIST *argusDBC::listModules( uint32_t ServerID ){
  1943. DBC_INT_LIST * tVal = NULL;
  1944. if(m_bIsConnected){
  1945. char tQBuf[CTEXT];
  1946. AAssoc *result;
  1947. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1948. #ifdef DEBUG
  1949. //LOG(tQBuf);
  1950. #endif
  1951. result = m_pDatabase->Query( tQBuf );
  1952. if( result!= NULL ) {
  1953. if( result->size() > 0 ) {
  1954. Assoc *cArr;
  1955. tVal = new DBC_INT_LIST();
  1956. if( tVal != NULL ) {
  1957. Assoc::iterator it;
  1958. for(int i=0;i<result->size();i++) {
  1959. cArr = result->at(i);
  1960. it = cArr->find("id");
  1961. if( it != cArr->end() ){
  1962. tVal->push_back( atoi( it->second.c_str() ));
  1963. };
  1964. };
  1965. };
  1966. };
  1967. };
  1968. deleteResult( result );
  1969. };
  1970. return tVal;
  1971. };
  1972. DBC_INT_LIST *argusDBC::listFilters( uint32_t ServerID ){
  1973. DBC_INT_LIST * tVal = NULL;
  1974. if(m_bIsConnected){
  1975. char tQBuf[CTEXT];
  1976. AAssoc *result;
  1977. sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1978. #ifdef DEBUG_ALL
  1979. LOG(tQBuf);
  1980. #endif
  1981. result = m_pDatabase->Query( tQBuf );
  1982. if( result!= NULL ) {
  1983. if( result->size() > 0 ) {
  1984. Assoc *cArr;
  1985. tVal = new DBC_INT_LIST();
  1986. if( tVal != NULL ) {
  1987. Assoc::iterator it;
  1988. for(int i=0;i<result->size();i++) {
  1989. cArr = result->at(i);
  1990. it = cArr->find("id");
  1991. if( it != cArr->end() ){
  1992. tVal->push_back( atoi( it->second.c_str() ));
  1993. };
  1994. };
  1995. };
  1996. };
  1997. };
  1998. deleteResult( result );
  1999. };
  2000. return tVal;
  2001. };
  2002. DBC_INT_LIST *argusDBC::listLRFMaskVertexes( uint32_t MaskID ){
  2003. DBC_INT_LIST * tVal = NULL;
  2004. if(m_bIsConnected){
  2005. char tQBuf[CTEXT];
  2006. AAssoc *result;
  2007. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", MaskID );
  2008. #ifdef DEBUG_ALL
  2009. LOG(tQBuf);
  2010. #endif
  2011. result = m_pDatabase->Query( tQBuf );
  2012. if( result!= NULL ) {
  2013. if( result->size() > 0 ) {
  2014. Assoc *cArr;
  2015. tVal = new DBC_INT_LIST();
  2016. if( tVal != NULL ) {
  2017. Assoc::iterator it;
  2018. for(int i=0;i<result->size();i++) {
  2019. cArr = result->at(i);
  2020. it = cArr->find("id");
  2021. if( it != cArr->end() ){
  2022. tVal->push_back( atoi( it->second.c_str() ));
  2023. };
  2024. };
  2025. };
  2026. };
  2027. };
  2028. deleteResult( result );
  2029. };
  2030. return tVal;
  2031. };
  2032. DBC_INT_LIST *argusDBC::listLRFMaskVertexPoints( uint32_t VertexID ){
  2033. DBC_INT_LIST * tVal = NULL;
  2034. if(m_bIsConnected){
  2035. char tQBuf[CTEXT];
  2036. AAssoc *result;
  2037. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", VertexID );
  2038. #ifdef DEBUG_ALL
  2039. LOG(tQBuf);
  2040. #endif
  2041. result = m_pDatabase->Query( tQBuf );
  2042. if( result!= NULL ) {
  2043. if( result->size() > 0 ) {
  2044. Assoc *cArr;
  2045. tVal = new DBC_INT_LIST();
  2046. if( tVal != NULL ) {
  2047. Assoc::iterator it;
  2048. for(int i=0;i<result->size();i++) {
  2049. cArr = result->at(i);
  2050. it = cArr->find("id");
  2051. if( it != cArr->end() ){
  2052. tVal->push_back( atoi( it->second.c_str() ));
  2053. };
  2054. };
  2055. };
  2056. };
  2057. };
  2058. deleteResult( result );
  2059. };
  2060. return tVal;
  2061. };
  2062. DBC_INT_LIST *argusDBC::listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){
  2063. DBC_INT_LIST * tVal = NULL;
  2064. if(m_bIsConnected){
  2065. char tQBuf[CTEXT];
  2066. AAssoc *result;
  2067. switch( listMode ){
  2068. 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;
  2069. 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;
  2070. default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
  2071. };
  2072. #ifdef DEBUG_ALL
  2073. LOG(tQBuf);
  2074. #endif
  2075. result = m_pDatabase->Query( tQBuf );
  2076. if( result!= NULL ) {
  2077. if( result->size() > 0 ) {
  2078. Assoc *cArr;
  2079. tVal = new DBC_INT_LIST();
  2080. if( tVal != NULL ) {
  2081. Assoc::iterator it;
  2082. for(int i=0;i<result->size();i++) {
  2083. cArr = result->at(i);
  2084. it = cArr->find("id");
  2085. if( it != cArr->end() ){
  2086. tVal->push_back( atoi( it->second.c_str() ));
  2087. };
  2088. };
  2089. };
  2090. };
  2091. };
  2092. deleteResult( result );
  2093. };
  2094. return tVal;
  2095. };
  2096. DBC_INT_LIST *argusDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){
  2097. DBC_INT_LIST * tVal = NULL;
  2098. if(m_bIsConnected){
  2099. char tQBuf[CTEXT];
  2100. AAssoc *result;
  2101. switch( listMode ){
  2102. case LIST_VALID_RECORDS:
  2103. sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `nd`.`site_id`=%d AND `ms`.`valid`=1 AND `nd`.`online`=1", SiteId );
  2104. break;
  2105. case LIST_INVALID_RECORDS:
  2106. sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `nd`.`site_id`=%d AND `ms`.`valid`=1 AND `nd`.`online`=0", SiteId );
  2107. break;
  2108. default:
  2109. sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `nd`.`site_id`=%d AND `ms`.`valid`=1", SiteId );
  2110. };
  2111. #ifdef DEBUG_ALL
  2112. LOG(tQBuf);
  2113. #endif
  2114. result = m_pDatabase->Query( tQBuf );
  2115. if( result!= NULL ) {
  2116. if( result->size() > 0 ) {
  2117. Assoc *cArr;
  2118. tVal = new DBC_INT_LIST();
  2119. if( tVal != NULL ) {
  2120. Assoc::iterator it;
  2121. for(int i=0;i<result->size();i++) {
  2122. cArr = result->at(i);
  2123. it = cArr->find("id");
  2124. if( it != cArr->end() ){
  2125. tVal->push_back( atoi( it->second.c_str() ));
  2126. };
  2127. };
  2128. };
  2129. };
  2130. };
  2131. deleteResult( result );
  2132. };
  2133. return tVal;
  2134. };
  2135. DBC_INT_LIST *argusDBC::listDetectionProfileIDs( uint32_t nodeID ){
  2136. DBC_INT_LIST * tVal = NULL;
  2137. if(m_bIsConnected){
  2138. char tQBuf[CTEXT];
  2139. AAssoc *result;
  2140. sprintf(tQBuf, "SELECT `profile_id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  2141. #ifdef DEBUG_ALL
  2142. LOG(tQBuf);
  2143. #endif
  2144. result = m_pDatabase->Query( tQBuf );
  2145. if( result!= NULL ) {
  2146. if( result->size() > 0 ) {
  2147. Assoc *cArr;
  2148. tVal = new DBC_INT_LIST();
  2149. if( tVal != NULL ) {
  2150. Assoc::iterator it;
  2151. for(int i=0;i<result->size();i++) {
  2152. cArr = result->at(i);
  2153. it = cArr->find("profile_id");
  2154. if( it != cArr->end() ){
  2155. tVal->push_back( atoi( it->second.c_str() ));
  2156. };
  2157. };
  2158. };
  2159. };
  2160. };
  2161. deleteResult( result );
  2162. };
  2163. return tVal;
  2164. };
  2165. DBC_INT_LIST *argusDBC::listDetectionProfiles( uint32_t nodeID ){
  2166. DBC_INT_LIST * tVal = NULL;
  2167. if(m_bIsConnected){
  2168. char tQBuf[CTEXT];
  2169. AAssoc *result;
  2170. sprintf(tQBuf, "SELECT `id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  2171. #ifdef DEBUG_ALL
  2172. LOG(tQBuf);
  2173. #endif
  2174. result = m_pDatabase->Query( tQBuf );
  2175. if( result!= NULL ) {
  2176. if( result->size() > 0 ) {
  2177. Assoc *cArr;
  2178. tVal = new DBC_INT_LIST();
  2179. if( tVal != NULL ) {
  2180. Assoc::iterator it;
  2181. for(int i=0;i<result->size();i++) {
  2182. cArr = result->at(i);
  2183. it = cArr->find("id");
  2184. if( it != cArr->end() ){
  2185. tVal->push_back( atoi( it->second.c_str() ));
  2186. };
  2187. };
  2188. };
  2189. };
  2190. };
  2191. deleteResult( result );
  2192. };
  2193. return tVal;
  2194. };
  2195. /*
  2196. DBC_INT_LIST *argusDBC::listSockets( uint32_t NodeID ){
  2197. DBC_INT_LIST * tVal = NULL;
  2198. if(m_bIsConnected){
  2199. char tQBuf[CTEXT];
  2200. AAssoc *result;
  2201. sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );
  2202. #ifdef DEBUG
  2203. LOG(tQBuf);
  2204. #endif
  2205. result = m_pDatabase->Query( tQBuf );
  2206. if( result!= NULL ) {
  2207. if( result->size() > 0 ) {
  2208. Assoc *cArr;
  2209. tVal = new DBC_INT_LIST();
  2210. if( tVal != NULL ) {
  2211. Assoc::iterator it;
  2212. for(int i=0;i<result->size();i++) {
  2213. cArr = result->at(i);
  2214. it = cArr->find("id");
  2215. if( it != cArr->end() ){
  2216. tVal->push_back( atoi( it->second.c_str() ));
  2217. };
  2218. };
  2219. };
  2220. };
  2221. };
  2222. deleteResult( result );
  2223. };
  2224. return tVal;
  2225. };
  2226. */
  2227. DBC_INT_LIST *argusDBC::listResources( uint32_t NodeID ){
  2228. DBC_INT_LIST * tVal = NULL;
  2229. if(m_bIsConnected){
  2230. char tQBuf[CTEXT];
  2231. AAssoc *result;
  2232. if( NodeID ) {
  2233. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d AND `active`=1 AND `used`=1", NodeID );
  2234. } else {
  2235. sprintf(tQBuf, "SELECT `re`.`id` FROM `resources` `re` LEFT JOIN `nodes` `no` ON( `re`.`node_id` = `no`.`id` ) WHERE `no`.`site_id`=%d AND `re`.`used`=1", m_nSiteID );// AND `re`.`active`=1", m_nSiteID );
  2236. };
  2237. #ifdef DEBUG
  2238. LOG(tQBuf);
  2239. #endif
  2240. result = m_pDatabase->Query( tQBuf );
  2241. if( result!= NULL ) {
  2242. if( result->size() > 0 ) {
  2243. Assoc *cArr;
  2244. tVal = new DBC_INT_LIST();
  2245. if( tVal != NULL ) {
  2246. Assoc::iterator it;
  2247. for(int i=0;i<result->size();i++) {
  2248. cArr = result->at(i);
  2249. it = cArr->find("id");
  2250. if( it != cArr->end() ){
  2251. tVal->push_back( atoi( it->second.c_str() ));
  2252. };
  2253. };
  2254. };
  2255. };
  2256. };
  2257. deleteResult( result );
  2258. };
  2259. return tVal;
  2260. };
  2261. simplePolygone *argusDBC::loadLRFMaskVertex( uint32_t vid ){
  2262. simplePolygone *tVal = NULL;
  2263. if(m_bIsConnected){
  2264. char tQBuf[CTEXT];
  2265. AAssoc *result;
  2266. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertexes` WHERE `id`=%d", vid );
  2267. #ifdef DEBUG
  2268. LOG(tQBuf);
  2269. #endif
  2270. result = m_pDatabase->Query( tQBuf );
  2271. if( result!= NULL ) {
  2272. if( result->size() > 0 ) {
  2273. tVal = (simplePolygone *) malloc(sizeof(simplePolygone));
  2274. if ( tVal ) {
  2275. Assoc * cArr;
  2276. memset( tVal, 0, sizeof(simplePolygone));
  2277. Assoc::iterator it;
  2278. cArr = result->at(0);
  2279. it = cArr->find("r");
  2280. if( it != cArr->end() ){
  2281. tVal->color[0] = atoi( it->second.c_str() );
  2282. };
  2283. it = cArr->find("g");
  2284. if( it != cArr->end() ){
  2285. tVal->color[1] = atoi( it->second.c_str() );
  2286. };
  2287. it = cArr->find("b");
  2288. if( it != cArr->end() ){
  2289. tVal->color[2] = atoi( it->second.c_str() );
  2290. };
  2291. AAssoc *points;
  2292. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", vid );
  2293. #ifdef DEBUG
  2294. LOG(tQBuf);
  2295. #endif
  2296. points = m_pDatabase->Query( tQBuf );
  2297. if( points!= NULL ) {
  2298. if ( points->size() ) {
  2299. tVal->count = points->size();
  2300. tVal->points = (simplePoint *) calloc( points->size(), sizeof(simplePoint) );
  2301. if( tVal->points!= NULL ) {
  2302. for (int i = 0; i < points->size(); i++) {
  2303. cArr = points->at( i );
  2304. it = cArr->find("x");
  2305. if( it != cArr->end() ){
  2306. tVal->points[i].setX( atoi( it->second.c_str() ) );
  2307. };
  2308. it = cArr->find("y");
  2309. if( it != cArr->end() ){
  2310. tVal->points[i].setY( atoi( it->second.c_str() ) );
  2311. };
  2312. };
  2313. };
  2314. };
  2315. };
  2316. deleteResult( points );
  2317. };
  2318. };
  2319. };
  2320. deleteResult( result );
  2321. };
  2322. return tVal;
  2323. };
  2324. DBC_INT_LIST *argusDBC::listNetworks( uint32_t nif_id ){
  2325. DBC_INT_LIST * tVal = NULL;
  2326. if(m_bIsConnected){
  2327. char tQBuf[CTEXT];
  2328. AAssoc *result;
  2329. sprintf(tQBuf, "SELECT `id` FROM `networks` WHERE `nif_id`=%d", nif_id );
  2330. #ifdef DEBUG_ALL
  2331. LOG(tQBuf);
  2332. #endif
  2333. result = m_pDatabase->Query( tQBuf );
  2334. if( result!= NULL ) {
  2335. if( result->size() > 0 ) {
  2336. Assoc *cArr;
  2337. tVal = new DBC_INT_LIST();
  2338. if( tVal != NULL ) {
  2339. Assoc::iterator it;
  2340. for(int i=0;i<result->size();i++) {
  2341. cArr = result->at(i);
  2342. it = cArr->find("id");
  2343. if( it != cArr->end() ){
  2344. tVal->push_back( atoi( it->second.c_str() ));
  2345. };
  2346. };
  2347. };
  2348. };
  2349. };
  2350. deleteResult( result );
  2351. };
  2352. return tVal;
  2353. };
  2354. DBC_INT_LIST *argusDBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ){
  2355. DBC_INT_LIST * tVal = NULL;
  2356. char tParam[CTEXT];
  2357. //memset( tParam, 0, CTEXT );
  2358. sprintf(tParam,"0");
  2359. if( old_ids != NULL ) {
  2360. char tBuffer[CTEXT];
  2361. for(int i = 0; i< old_ids->size(); i++ ) {
  2362. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  2363. strncpy( tParam, tBuffer, CTEXT );
  2364. };
  2365. };
  2366. if(m_bIsConnected){
  2367. char tQBuf[CTEXT];
  2368. AAssoc *result;
  2369. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", ServerID, tParam );
  2370. #ifdef DEBUG_ALL
  2371. LOG(tQBuf);
  2372. #endif
  2373. result = m_pDatabase->Query( tQBuf );
  2374. if( result!= NULL ) {
  2375. if( result->size() > 0 ) {
  2376. Assoc *cArr;
  2377. tVal = new DBC_INT_LIST();
  2378. if( tVal != NULL ) {
  2379. Assoc::iterator it;
  2380. for(int i=0;i<result->size();i++) {
  2381. cArr = result->at(i);
  2382. it = cArr->find("id");
  2383. if( it != cArr->end() ){
  2384. tVal->push_back( atoi( it->second.c_str() ));
  2385. };
  2386. };
  2387. };
  2388. };
  2389. };
  2390. deleteResult( result );
  2391. };
  2392. return tVal;
  2393. };
  2394. uint32_t argusDBC::getCamId( CSTR UUID ){
  2395. uint32_t RetVal = 0;
  2396. if(m_bIsConnected){
  2397. char tQBuf[CTEXT];
  2398. AAssoc *result;
  2399. sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
  2400. #ifdef DEBUG_ALL
  2401. LOG(tQBuf);
  2402. #endif
  2403. result = m_pDatabase->Query( tQBuf );
  2404. if( result!= NULL ) {
  2405. if( result->size() > 0 ) {
  2406. Assoc *cArr;
  2407. Assoc::iterator it;
  2408. cArr = result->at(0);
  2409. it = cArr->find("id");
  2410. if( it != cArr->end() ){
  2411. RetVal = atoi( it->second.c_str() );
  2412. };
  2413. };
  2414. };
  2415. deleteResult( result );
  2416. };
  2417. return RetVal;
  2418. };
  2419. DBC_CAP_DATA *argusDBC::getCamCapPictureData( uint32_t PicID ){
  2420. DBC_CAP_DATA *tVal = NULL;
  2421. if(m_bIsConnected){
  2422. char tQBuf[CTEXT];
  2423. AAssoc *result;
  2424. sprintf(tQBuf, "SELECT md5, ext FROM pictures WHERE `id`=%d", PicID );
  2425. #ifdef DEBUG_ALL
  2426. LOG(tQBuf);
  2427. #endif
  2428. result = m_pDatabase->Query( tQBuf );
  2429. if( result!= NULL ) {
  2430. if( result->size() > 0 ) {
  2431. Assoc *cArr;
  2432. tVal = (DBC_CAP_DATA*) malloc(sizeof(DBC_CAP_DATA));
  2433. if( tVal != NULL ) {
  2434. memset( tVal, 0 , sizeof(DBC_CAP_DATA));
  2435. Assoc::iterator it;
  2436. cArr = result->at(0);
  2437. it = cArr->find("md5");
  2438. if( it != cArr->end() ){
  2439. strncpy(tVal->md5, it->second.c_str(), 32);
  2440. };
  2441. it = cArr->find("ext");
  2442. if( it != cArr->end() ){
  2443. strncpy(tVal->ext, it->second.c_str(), 3 );
  2444. };
  2445. };
  2446. };
  2447. };
  2448. deleteResult( result );
  2449. };
  2450. return tVal;
  2451. };
  2452. DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
  2453. DBC_CAM_DATA *tVal = NULL;
  2454. if(m_bIsConnected){
  2455. char tQBuf[CTEXT];
  2456. AAssoc *result;
  2457. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  2458. #ifdef DEBUG_ALL
  2459. LOG(tQBuf);
  2460. #endif
  2461. result = m_pDatabase->Query( tQBuf );
  2462. if( result!= NULL ) {
  2463. if( result->size() > 0 ) {
  2464. Assoc *cArr;
  2465. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  2466. if( tVal != NULL ) {
  2467. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  2468. tVal->id = ID;
  2469. Assoc::iterator it;
  2470. cArr = result->at(0);
  2471. it = cArr->find("site_id");
  2472. if( it != cArr->end() ){
  2473. tVal->site_id = atoi( it->second.c_str() );
  2474. };
  2475. it = cArr->find("node_id");
  2476. if( it != cArr->end() ){
  2477. tVal->node_id = atoi( it->second.c_str() );
  2478. };
  2479. it = cArr->find("online");
  2480. if( it != cArr->end() ){
  2481. tVal->online = (bool) atoi( it->second.c_str() );
  2482. };
  2483. it = cArr->find("type");
  2484. if( it != cArr->end() ){
  2485. tVal->type = atoi( it->second.c_str() );
  2486. };
  2487. it = cArr->find("name");
  2488. if( it != cArr->end() ){
  2489. strncpy( tVal->name, it->second.c_str(), 64 );
  2490. };
  2491. it = cArr->find("hardware");
  2492. if( it != cArr->end() ){
  2493. strncpy( tVal->hardware, it->second.c_str(), 32 );
  2494. };
  2495. it = cArr->find("status");
  2496. if( it != cArr->end() ){
  2497. tVal->status = atoi( it->second.c_str() );
  2498. };
  2499. it = cArr->find("session");
  2500. if( it != cArr->end() ){
  2501. strncpy( tVal->session, it->second.c_str(), 32 );
  2502. };
  2503. it = cArr->find("protocol");
  2504. if( it != cArr->end() ){
  2505. tVal->protocol = atoi( it->second.c_str() );
  2506. };
  2507. it = cArr->find("protocol_aux");
  2508. if( it != cArr->end() ){
  2509. tVal->protocol_aux = atoi( it->second.c_str() );
  2510. };
  2511. it = cArr->find("uart_id");
  2512. if( it != cArr->end() ){
  2513. tVal->uart_id = atoi( it->second.c_str() );
  2514. };
  2515. it = cArr->find("x");
  2516. if( it != cArr->end() ){
  2517. tVal->x = atof( it->second.c_str() );
  2518. };
  2519. it = cArr->find("y");
  2520. if( it != cArr->end() ){
  2521. tVal->y = atof( it->second.c_str() );
  2522. };
  2523. it = cArr->find("z");
  2524. if( it != cArr->end() ){
  2525. tVal->z = atof( it->second.c_str() );
  2526. };
  2527. it = cArr->find("x_rot");
  2528. if( it != cArr->end() ){
  2529. tVal->x_rot = atof( it->second.c_str() );
  2530. };
  2531. it = cArr->find("y_rot");
  2532. if( it != cArr->end() ){
  2533. tVal->y_rot = atof( it->second.c_str() );
  2534. };
  2535. it = cArr->find("z_rot");
  2536. if( it != cArr->end() ){
  2537. tVal->z_rot = atof( it->second.c_str() );
  2538. };
  2539. it = cArr->find("imager_type");
  2540. if( it != cArr->end() ){
  2541. tVal->imager_type = atoi( it->second.c_str() );
  2542. };
  2543. it = cArr->find("lens_f");
  2544. if( it != cArr->end() ){
  2545. tVal->lens_f = atoi( it->second.c_str() );
  2546. };
  2547. it = cArr->find("ptz_speed_step");
  2548. if( it != cArr->end() ){
  2549. tVal->ptz_speed_step = atof( it->second.c_str() );
  2550. };
  2551. it = cArr->find("pan_model");
  2552. if( it != cArr->end() ){
  2553. tVal->pan_model = atoi( it->second.c_str() );
  2554. };
  2555. it = cArr->find("pan_angles");
  2556. if( it != cArr->end() ){
  2557. tVal->pan_angles = atoi( it->second.c_str() );
  2558. };
  2559. it = cArr->find("tilt_model");
  2560. if( it != cArr->end() ){
  2561. tVal->tilt_model = atoi( it->second.c_str() );
  2562. };
  2563. it = cArr->find("tilt_angles");
  2564. if( it != cArr->end() ){
  2565. tVal->tilt_angles = atoi( it->second.c_str() );
  2566. };
  2567. it = cArr->find("zoom_model");
  2568. if( it != cArr->end() ){
  2569. tVal->zoom_model = atoi( it->second.c_str() );
  2570. };
  2571. it = cArr->find("zoom");
  2572. if( it != cArr->end() ){
  2573. tVal->zoom = atof( it->second.c_str() );
  2574. };
  2575. //it = cArr->find("max_range");
  2576. //if( it != cArr->end() ){
  2577. // tVal->max_range = atof( it->second.c_str() );
  2578. //};
  2579. it = cArr->find("access_login");
  2580. if( it != cArr->end() ){
  2581. strncpy( tVal->username, it->second.c_str(), 16 );
  2582. };
  2583. it = cArr->find("access_pass");
  2584. if( it != cArr->end() ){
  2585. strncpy( tVal->password, it->second.c_str(), 16 );
  2586. };
  2587. it = cArr->find("uuid");
  2588. if( it != cArr->end() ){
  2589. strncpy( tVal->uuid, it->second.c_str(), 64 );
  2590. };
  2591. it = cArr->find("mac");
  2592. if( it != cArr->end() ){
  2593. strncpy( tVal->mac, it->second.c_str(), 16 );
  2594. };
  2595. it = cArr->find("ip");
  2596. if( it != cArr->end() ){
  2597. strncpy( tVal->ip, it->second.c_str(), 16 );
  2598. };
  2599. it = cArr->find("port");
  2600. if( it != cArr->end() ){
  2601. tVal->port = atoi( it->second.c_str() );
  2602. };
  2603. it = cArr->find("onvif_access");
  2604. if( it != cArr->end() ){
  2605. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  2606. };
  2607. it = cArr->find("onvif_ctrl");
  2608. if( it != cArr->end() ){
  2609. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  2610. };
  2611. it = cArr->find("ptz_token");
  2612. if( it != cArr->end() ){
  2613. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  2614. };
  2615. it = cArr->find("trigger_mode");
  2616. if( it != cArr->end() ){
  2617. tVal->triggering_mode = atoi( it->second.c_str() );
  2618. };
  2619. it = cArr->find("auth_mode");
  2620. if( it != cArr->end() ){
  2621. tVal->auth_mode = atoi( it->second.c_str() );
  2622. };
  2623. };
  2624. };
  2625. };
  2626. deleteResult( result );
  2627. };
  2628. return tVal;
  2629. };
  2630. DBC_PUSHED_CMD *argusDBC::getActivePushedCMD( uint32_t NodeID ){
  2631. DBC_PUSHED_CMD *RetVal = NULL;
  2632. if(m_bIsConnected){
  2633. char tQBuf[CTEXT];
  2634. AAssoc *result;
  2635. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status` > 0 AND `status` < 100", NodeID );
  2636. #ifdef DEBUG_ALL
  2637. LOG(tQBuf);
  2638. #endif
  2639. result = m_pDatabase->Query( tQBuf );
  2640. if( result!= NULL ) {
  2641. if( result->size() > 0 ) {
  2642. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2643. if( RetVal ) {
  2644. Assoc * cArr;
  2645. Assoc::iterator it;
  2646. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2647. cArr = result->at(0);
  2648. it = cArr->find("id");
  2649. if( it != cArr->end() ){
  2650. RetVal->id = atoi( it->second.c_str() );
  2651. };
  2652. it = cArr->find("cmd");
  2653. if( it != cArr->end() ){
  2654. RetVal->CMD = atoi( it->second.c_str() );
  2655. };
  2656. it = cArr->find("parameter");
  2657. if( it != cArr->end() ){
  2658. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2659. RetVal->PARAM[255] = (char)0;
  2660. };
  2661. };
  2662. };
  2663. };
  2664. deleteResult( result );
  2665. };
  2666. return RetVal;
  2667. };
  2668. DBC_PUSHED_CMD *argusDBC::getPushedCMD( uint32_t CmdID ){
  2669. DBC_PUSHED_CMD *RetVal = NULL;
  2670. if(m_bIsConnected){
  2671. char tQBuf[CTEXT];
  2672. AAssoc *result;
  2673. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `id`=%d", CmdID );
  2674. #ifdef DEBUG_ALL
  2675. LOG(tQBuf);
  2676. #endif
  2677. result = m_pDatabase->Query( tQBuf );
  2678. if( result!= NULL ) {
  2679. if( result->size() > 0 ) {
  2680. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2681. if( RetVal ) {
  2682. Assoc * cArr;
  2683. Assoc::iterator it;
  2684. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2685. cArr = result->at(0);
  2686. it = cArr->find("id");
  2687. if( it != cArr->end() ){
  2688. RetVal->id = atoi( it->second.c_str() );
  2689. };
  2690. it = cArr->find("cmd");
  2691. if( it != cArr->end() ){
  2692. RetVal->CMD = atoi( it->second.c_str() );
  2693. };
  2694. it = cArr->find("parameter");
  2695. if( it != cArr->end() ){
  2696. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2697. RetVal->PARAM[255] = (char)0;
  2698. };
  2699. };
  2700. };
  2701. };
  2702. deleteResult( result );
  2703. };
  2704. return RetVal;
  2705. };
  2706. DBC_PUSHED_CMD *argusDBC::getNodePushedCMD( uint32_t NodeID ){
  2707. DBC_PUSHED_CMD *RetVal = NULL;
  2708. if(m_bIsConnected){
  2709. char tQBuf[CTEXT];
  2710. AAssoc *result;
  2711. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 LIMIT 1", NodeID );
  2712. #ifdef DEBUG_ALL
  2713. LOG(tQBuf);
  2714. #endif
  2715. result = m_pDatabase->Query( tQBuf );
  2716. if( result!= NULL ) {
  2717. if( result->size() > 0 ) {
  2718. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2719. if( RetVal ) {
  2720. Assoc * cArr;
  2721. Assoc::iterator it;
  2722. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2723. cArr = result->at(0);
  2724. it = cArr->find("id");
  2725. if( it != cArr->end() ){
  2726. RetVal->id = atoi( it->second.c_str() );
  2727. };
  2728. it = cArr->find("cmd");
  2729. if( it != cArr->end() ){
  2730. RetVal->CMD = atoi( it->second.c_str() );
  2731. };
  2732. it = cArr->find("parameter");
  2733. if( it != cArr->end() ){
  2734. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2735. RetVal->PARAM[255] = (char)0;
  2736. };
  2737. //Only If Result is Fetched - Clear Current CMD
  2738. //sprintf(tQBuf, "DELETE FROM `nodes_qcq` WHERE `id`=%d", RetVal->id );
  2739. //m_pDatabase->SilentQuery( tQBuf );
  2740. };
  2741. };
  2742. };
  2743. deleteResult( result );
  2744. };
  2745. return RetVal;
  2746. };
  2747. bool argusDBC::updateNodePushedCMD( uint32_t CmdID, uint8_t status ){
  2748. if(m_bIsConnected){
  2749. char tQBuf[CTEXT];
  2750. sprintf(tQBuf, "UPDATE `nodes_qcq` SET `status`=%d WHERE `id`=%d ", status, CmdID );
  2751. #ifdef DEBUG_ALL
  2752. LOG(tQBuf);
  2753. #endif
  2754. m_pDatabase->SilentQuery( tQBuf );
  2755. return true;
  2756. };
  2757. return false;
  2758. };
  2759. DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){
  2760. DBC_MODULE_DATA *tVal = NULL;
  2761. if(m_bIsConnected){
  2762. char tQBuf[CTEXT];
  2763. AAssoc *result;
  2764. sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
  2765. #ifdef DEBUG_ALL
  2766. LOG(tQBuf);
  2767. #endif
  2768. result = m_pDatabase->Query( tQBuf );
  2769. if( result!= NULL ) {
  2770. if( result->size() > 0 ) {
  2771. Assoc *cArr;
  2772. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  2773. if( tVal != NULL ) {
  2774. Assoc::iterator it;
  2775. cArr = result->at(0);
  2776. it = cArr->find("id");
  2777. if( it != cArr->end() ){
  2778. tVal->module_id = atoi( it->second.c_str() );
  2779. };
  2780. it = cArr->find("aux_id");
  2781. if( it != cArr->end() ){
  2782. tVal->aux_id = atoi( it->second.c_str() );
  2783. };
  2784. it = cArr->find("type");
  2785. if( it != cArr->end() ){
  2786. tVal->type = atoi( it->second.c_str() );
  2787. };
  2788. it = cArr->find("enabled");
  2789. if( it != cArr->end() ){
  2790. tVal->enabled = (bool)atoi( it->second.c_str() );
  2791. };
  2792. };
  2793. };
  2794. };
  2795. deleteResult( result );
  2796. };
  2797. return tVal;
  2798. };
  2799. /*
  2800. DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
  2801. DBC_SOCKET_DATA *tVal = NULL;
  2802. if(m_bIsConnected){
  2803. char tQBuf[CTEXT];
  2804. AAssoc *result;
  2805. sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );
  2806. #ifdef DEBUG
  2807. //LOG(tQBuf);
  2808. #endif
  2809. result = m_pDatabase->Query( tQBuf );
  2810. if( result!= NULL ) {
  2811. if( result->size() > 0 ) {
  2812. Assoc *cArr;
  2813. tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
  2814. if( tVal != NULL ) {
  2815. Assoc::iterator it;
  2816. cArr = result->at(0);
  2817. it = cArr->find("id");
  2818. if( it != cArr->end() ){
  2819. tVal->socket_id = atoi( it->second.c_str() );
  2820. };
  2821. it = cArr->find("aux_id");
  2822. if( it != cArr->end() ){
  2823. tVal->aux_id = atoi( it->second.c_str() );
  2824. };
  2825. it = cArr->find("type");
  2826. if( it != cArr->end() ){
  2827. tVal->type = atoi( it->second.c_str() );
  2828. };
  2829. it = cArr->find("binded");
  2830. if( it != cArr->end() ){
  2831. tVal->binded = (bool)atoi( it->second.c_str() );
  2832. };
  2833. };
  2834. };
  2835. };
  2836. deleteResult( result );
  2837. };
  2838. return tVal;
  2839. };
  2840. */
  2841. DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){
  2842. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  2843. if(m_bIsConnected){
  2844. char tQBuf[CTEXT];
  2845. AAssoc *result;
  2846. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  2847. #ifdef DEBUG_ALL
  2848. LOG(tQBuf);
  2849. #endif
  2850. result = m_pDatabase->Query( tQBuf );
  2851. if( result!= NULL ) {
  2852. if( result->size() > 0 ) {
  2853. Assoc *cArr;
  2854. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  2855. if( tVal != NULL ) {
  2856. memset( tVal, 0, sizeof(DBC_MEDIA_STREAM_DATA) );
  2857. Assoc::iterator it;
  2858. cArr = result->at(0);
  2859. tVal->id = ID;
  2860. it = cArr->find("source_id");
  2861. if( it != cArr->end() ){
  2862. tVal->source_id = atoi( it->second.c_str() );
  2863. };
  2864. it = cArr->find("site_id");
  2865. if( it != cArr->end() ){
  2866. tVal->site_id = atoi( it->second.c_str() );
  2867. };
  2868. it = cArr->find("source_type");
  2869. if( it != cArr->end() ){
  2870. sprintf( tVal->source_type, it->second.c_str() );
  2871. };
  2872. it = cArr->find("valid");
  2873. if( it != cArr->end() ){
  2874. tVal->valid = (bool) atoi( it->second.c_str() );
  2875. };
  2876. it = cArr->find("token");
  2877. if( it != cArr->end() ){
  2878. sprintf( tVal->token, it->second.c_str() );
  2879. };
  2880. it = cArr->find("img_width");
  2881. if( it != cArr->end() ){
  2882. tVal->width = atoi( it->second.c_str() );
  2883. };
  2884. it = cArr->find("img_height");
  2885. if( it != cArr->end() ){
  2886. tVal->height = atoi( it->second.c_str() );
  2887. };
  2888. it = cArr->find("fps");
  2889. if( it != cArr->end() ){
  2890. tVal->fps = atoi( it->second.c_str() );
  2891. };
  2892. it = cArr->find("compression_type");
  2893. if( it != cArr->end() ){
  2894. sprintf(tVal->c_type, it->second.c_str());
  2895. };
  2896. it = cArr->find("mrl_proto");
  2897. if( it != cArr->end() ){
  2898. sprintf( tVal->mrl_proto, it->second.c_str() );
  2899. };
  2900. it = cArr->find("mrl_port");
  2901. if( it != cArr->end() ){
  2902. tVal->mrl_port = atoi( it->second.c_str() );
  2903. };
  2904. it = cArr->find("mrl");
  2905. if( it != cArr->end() ){
  2906. sprintf( tVal->mrl, it->second.c_str() );
  2907. };
  2908. };
  2909. };
  2910. };
  2911. deleteResult( result );
  2912. };
  2913. return tVal;
  2914. };
  2915. DBC_MEDIA_SERVER_DATA *argusDBC::getMediaServerData( uint32_t ID ){
  2916. DBC_MEDIA_SERVER_DATA *tVal = NULL;
  2917. if(m_bIsConnected){
  2918. char tQBuf[CTEXT];
  2919. AAssoc *result;
  2920. sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
  2921. #ifdef DEBUG_ALL
  2922. LOG(tQBuf);
  2923. #endif
  2924. result = m_pDatabase->Query( tQBuf );
  2925. if( result!= NULL ) {
  2926. if( result->size() > 0 ) {
  2927. Assoc *cArr;
  2928. tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
  2929. if( tVal != NULL ) {
  2930. Assoc::iterator it;
  2931. cArr = result->at(0);
  2932. tVal->id = ID;
  2933. it = cArr->find("secret_key");
  2934. if( it != cArr->end() ){
  2935. sprintf( tVal->key, it->second.c_str() );
  2936. };
  2937. it = cArr->find("ip");
  2938. if( it != cArr->end() ){
  2939. sprintf( tVal->ip, it->second.c_str() );
  2940. };
  2941. it = cArr->find("REST_port");
  2942. if( it != cArr->end() ){
  2943. tVal->port = atoi( it->second.c_str() );
  2944. };
  2945. it = cArr->find("virtual_host");
  2946. if( it != cArr->end() ){
  2947. sprintf( tVal->host, it->second.c_str() );
  2948. };
  2949. it = cArr->find("recording");
  2950. if( it != cArr->end() ){
  2951. tVal->recording = (bool)atoi( it->second.c_str() );
  2952. };
  2953. it = cArr->find("local");
  2954. if( it != cArr->end() ){
  2955. tVal->local = (bool)atoi( it->second.c_str() );
  2956. };
  2957. it = cArr->find("docRoot");
  2958. if( it != cArr->end() ){
  2959. sprintf( tVal->docRoot, it->second.c_str() );
  2960. };
  2961. sprintf( tVal->name,"ZLMedia_%d", tVal->id );
  2962. };
  2963. };
  2964. };
  2965. deleteResult( result );
  2966. };
  2967. return tVal;
  2968. };
  2969. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamDataBySource( uint32_t ID ){
  2970. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2971. if(m_bIsConnected){
  2972. char tQBuf[MAX_PATH_LEN];
  2973. AAssoc *result;
  2974. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
  2975. #ifdef DEBUG_ALL
  2976. LOG(tQBuf);
  2977. #endif
  2978. result = m_pDatabase->Query( tQBuf );
  2979. if( result!= NULL ) {
  2980. if( result->size() > 0 ) {
  2981. Assoc *cArr;
  2982. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2983. if( tVal != NULL ) {
  2984. Assoc::iterator it;
  2985. cArr = result->at(0);
  2986. tVal->id = ID;
  2987. it = cArr->find("media_stream_id");
  2988. if( it != cArr->end() ){
  2989. tVal->media_stream_id = atoi( it->second.c_str() );
  2990. };
  2991. it = cArr->find("online");
  2992. if( it != cArr->end() ){
  2993. tVal->online = atoi( it->second.c_str() );
  2994. };
  2995. it = cArr->find("key");
  2996. if( it != cArr->end() ){
  2997. sprintf( tVal->key, it->second.c_str() );
  2998. };
  2999. it = cArr->find("mrl");
  3000. if( it != cArr->end() ){
  3001. sprintf( tVal->mrl, it->second.c_str() );
  3002. };
  3003. };
  3004. };
  3005. };
  3006. deleteResult( result );
  3007. };
  3008. return tVal;
  3009. };
  3010. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
  3011. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  3012. if(m_bIsConnected){
  3013. char tQBuf[MAX_PATH_LEN];
  3014. AAssoc *result;
  3015. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
  3016. #ifdef DEBUG_ALL
  3017. LOG(tQBuf);
  3018. #endif
  3019. result = m_pDatabase->Query( tQBuf );
  3020. if( result!= NULL ) {
  3021. if( result->size() > 0 ) {
  3022. Assoc *cArr;
  3023. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  3024. if( tVal != NULL ) {
  3025. Assoc::iterator it;
  3026. cArr = result->at(0);
  3027. tVal->id = ID;
  3028. it = cArr->find("media_stream_id");
  3029. if( it != cArr->end() ){
  3030. tVal->media_stream_id = atoi( it->second.c_str() );
  3031. };
  3032. it = cArr->find("online");
  3033. if( it != cArr->end() ){
  3034. tVal->online = atoi( it->second.c_str() );
  3035. };
  3036. it = cArr->find("key");
  3037. if( it != cArr->end() ){
  3038. sprintf( tVal->key, it->second.c_str() );
  3039. };
  3040. it = cArr->find("mrl");
  3041. if( it != cArr->end() ){
  3042. sprintf( tVal->mrl, it->second.c_str() );
  3043. };
  3044. };
  3045. };
  3046. };
  3047. deleteResult( result );
  3048. };
  3049. return tVal;
  3050. };
  3051. void argusDBC::registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ){
  3052. if(m_bIsConnected){
  3053. m_nSiteID = SiteID;
  3054. char tQBuf[MAX_PATH_LEN];
  3055. sprintf( tQBuf, "INSERT INTO servers SET `site_id`=%d, `identity`='%s', `version_string`='%s', `online`=1, `ts`=UNIX_TIMESTAMP(now()), pid=%d ON DUPLICATE KEY UPDATE `version_string`='%s', `ts`=UNIX_TIMESTAMP(now()), `online`=1, pid=%d",
  3056. SiteID, identity, ARGUS_BUILD_STRING, PID, ARGUS_BUILD_STRING, PID );
  3057. #ifdef DEBUG
  3058. LOG(tQBuf);
  3059. #endif
  3060. m_pDatabase->SilentQuery( tQBuf );
  3061. *ServID = getServerID( identity );
  3062. if( *ServID ) {
  3063. 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, *ServID );
  3064. #ifdef DEBUG_ALL
  3065. LOG(tQBuf);
  3066. #endif
  3067. *ServNode = ( uint32_t ) m_pDatabase->QueryID( tQBuf );
  3068. if( *ServNode == 0 ){
  3069. *ServNode = getServerNode( *ServID );
  3070. };
  3071. // Clenup Nodes and services ...
  3072. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `server_id`=%d ", *ServID );
  3073. #ifdef DEBUG_ALL
  3074. LOG(tQBuf);
  3075. #endif
  3076. m_pDatabase->SilentQuery( tQBuf );
  3077. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  3078. #ifdef DEBUG_ALL
  3079. LOG(tQBuf);
  3080. #endif
  3081. m_pDatabase->SilentQuery( tQBuf );
  3082. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  3083. #ifdef DEBUG_ALL
  3084. LOG(tQBuf);
  3085. #endif
  3086. m_pDatabase->SilentQuery( tQBuf );
  3087. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  3088. #ifdef DEBUG_ALL
  3089. LOG(tQBuf);
  3090. #endif
  3091. m_pDatabase->SilentQuery( tQBuf );
  3092. //cleanResources( tServerNodeID );
  3093. setNodeOnline( *ServNode );
  3094. }
  3095. };
  3096. };
  3097. void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
  3098. if( setNodeOffline( NodeID ) ){
  3099. char tQBuf[CTEXT];
  3100. sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", ServerID );
  3101. #ifdef DEBUG_ALL
  3102. LOG(tQBuf);
  3103. #endif
  3104. m_pDatabase->SilentQuery( tQBuf );
  3105. };
  3106. };
  3107. bool argusDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  3108. if(m_bIsConnected){
  3109. char tQBuf[CTEXT];
  3110. if( NodeID ) {
  3111. sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );
  3112. #ifdef DEBUG_ALL
  3113. LOG(tQBuf);
  3114. #endif
  3115. m_pDatabase->SilentQuery( tQBuf );
  3116. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  3117. #ifdef DEBUG_ALL
  3118. LOG(tQBuf);
  3119. #endif
  3120. m_pDatabase->SilentQuery( tQBuf );
  3121. return true;
  3122. };
  3123. };
  3124. return false;
  3125. };
  3126. bool argusDBC::setNodeOffline( uint32_t NodeID ){
  3127. if(m_bIsConnected){
  3128. char tQBuf[CTEXT];
  3129. if( NodeID ) {
  3130. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  3131. #ifdef DEBUG_ALL
  3132. LOG(tQBuf);
  3133. #endif
  3134. m_pDatabase->SilentQuery( tQBuf );
  3135. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  3136. #ifdef DEBUG_ALL
  3137. LOG(tQBuf);
  3138. #endif
  3139. m_pDatabase->SilentQuery( tQBuf );
  3140. return true;
  3141. };
  3142. };
  3143. return false;
  3144. };
  3145. DBC_RESOURCE_DATA *argusDBC::getResourceData( uint32_t ResourceID ){
  3146. DBC_RESOURCE_DATA *tVal = NULL;
  3147. if( m_bIsConnected ){
  3148. char tQBuf[CTEXT];
  3149. AAssoc *result;
  3150. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );
  3151. #ifdef DEBUG_ALL
  3152. LOG(tQBuf);
  3153. #endif
  3154. result = m_pDatabase->Query( tQBuf );
  3155. if( result!= NULL ) {
  3156. if( result->size() > 0 ) {
  3157. Assoc *cArr;
  3158. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  3159. if( tVal != NULL ) {
  3160. Assoc::iterator it;
  3161. cArr = result->at(0);
  3162. tVal->id = ResourceID;
  3163. it = cArr->find("node_id");
  3164. if( it != cArr->end() ){
  3165. tVal->node_id = atoi( it->second.c_str() );
  3166. };
  3167. it = cArr->find("type");
  3168. if( it != cArr->end() ){
  3169. tVal->type = atoi( it->second.c_str() );
  3170. };
  3171. it = cArr->find("aux_id");
  3172. if( it != cArr->end() ){
  3173. tVal->aux_id = atoi( it->second.c_str() );
  3174. };
  3175. it = cArr->find("device");
  3176. if( it != cArr->end() ){
  3177. strncpy( tVal->device, it->second.c_str(), 64 );
  3178. tVal->device[63] = (char)0;
  3179. };
  3180. };
  3181. };
  3182. };
  3183. deleteResult( result );
  3184. };
  3185. return tVal;
  3186. };
  3187. uint32_t argusDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){
  3188. uint32_t RetVal = 0;
  3189. if(m_bIsConnected){
  3190. char tQBuf[CTEXT];
  3191. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );
  3192. #ifdef DEBUG_ALL
  3193. LOG(tQBuf);
  3194. #endif
  3195. AAssoc *result;
  3196. result = m_pDatabase->Query( tQBuf );
  3197. if( result!= NULL ) {
  3198. if( result->size() > 0 ) {
  3199. Assoc * cArr;
  3200. Assoc::iterator it;
  3201. cArr = result->at(0);
  3202. it = cArr->find("id");
  3203. if( it != cArr->end() ){
  3204. RetVal = atoi( it->second.c_str() );
  3205. };
  3206. };
  3207. };
  3208. deleteResult( result );
  3209. };
  3210. return RetVal;
  3211. };
  3212. uint32_t argusDBC::getServerID( CSTR identity ){
  3213. uint32_t RetVal = 0;
  3214. if(m_bIsConnected){
  3215. char tQBuf[CTEXT];
  3216. sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
  3217. #ifdef DEBUG_ALL
  3218. LOG(tQBuf);
  3219. #endif
  3220. AAssoc *result;
  3221. result = m_pDatabase->Query( tQBuf );
  3222. if( result!= NULL ) {
  3223. if( result->size() > 0 ) {
  3224. Assoc * cArr;
  3225. Assoc::iterator it;
  3226. cArr = result->at(0);
  3227. it = cArr->find("id");
  3228. if( it != cArr->end() ){
  3229. RetVal = atoi( it->second.c_str() );
  3230. };
  3231. };
  3232. };
  3233. deleteResult( result );
  3234. };
  3235. return RetVal;
  3236. };
  3237. uint32_t argusDBC::getServerNode( uint32_t SID ){
  3238. uint32_t RetVal = 0;
  3239. if(m_bIsConnected){
  3240. char tQBuf[CTEXT];
  3241. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  3242. #ifdef DEBUG_ALL
  3243. LOG(tQBuf);
  3244. #endif
  3245. AAssoc *result;
  3246. result = m_pDatabase->Query( tQBuf );
  3247. if( result!= NULL ) {
  3248. if( result->size() > 0 ) {
  3249. Assoc * cArr;
  3250. Assoc::iterator it;
  3251. cArr = result->at(0);
  3252. it = cArr->find("id");
  3253. if( it != cArr->end() ){
  3254. RetVal = atoi( it->second.c_str() );
  3255. };
  3256. };
  3257. };
  3258. deleteResult( result );
  3259. };
  3260. return RetVal;
  3261. };
  3262. uint32_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
  3263. uint32_t RetVal = 0;
  3264. if(m_bIsConnected){
  3265. char tQBuf[1024];
  3266. char tM5[33];
  3267. CSTR tMD5 = MD5String( path );
  3268. if( tMD5 != NULL ) {
  3269. memcpy( tM5, tMD5, 33 );
  3270. tM5[32]=(char)0;
  3271. free( tMD5 );
  3272. 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",
  3273. SiteID, tM5, width, height, path );//, width, height );
  3274. #ifdef DEBUG_ALL
  3275. LOG(tQBuf);
  3276. #endif
  3277. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3278. };
  3279. };
  3280. return RetVal;
  3281. };
  3282. /*
  3283. uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
  3284. uint32_t retVal = 0;
  3285. if(m_bIsConnected){
  3286. char tQBuf[2048];
  3287. char tM5[33];
  3288. CSTR tMD5 = MD5String( path );
  3289. if( tMD5 != NULL ) {
  3290. memcpy( tM5, tMD5, 33 );
  3291. free( tMD5 );
  3292. if( multidrop ) {
  3293. 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'",
  3294. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  3295. } else {
  3296. 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'",
  3297. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  3298. };
  3299. #ifdef DEBUG
  3300. LOG(tQBuf);
  3301. #endif
  3302. //m_pDatabase->SilentQuery( tQBuf );
  3303. retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3304. };
  3305. };
  3306. return retVal;
  3307. };
  3308. */
  3309. bool argusDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_ID ){
  3310. if(m_bIsConnected){
  3311. char tQBuf[2048];
  3312. 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 );
  3313. #ifdef DEBUG_ALL
  3314. LOG(tQBuf);
  3315. #endif
  3316. m_pDatabase->SilentQuery( tQBuf );
  3317. return true;
  3318. };
  3319. return false;
  3320. };
  3321. uint32_t argusDBC::addResource( uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID ){
  3322. uint32_t RetVal = 0;
  3323. if( m_bIsConnected ){
  3324. char tQBuf[2048];
  3325. sprintf( tQBuf, "%d:%d:%s", NodeID, type, devName );
  3326. CSTR tMD5 = MD5String( tQBuf );
  3327. if( tMD5 ) {
  3328. sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d", NodeID, type, tMD5, auxID, devName, auxID );
  3329. //sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, auxID, devName, auxID, devName );
  3330. free( tMD5 );
  3331. #ifdef DEBUG_ALL
  3332. LOG(tQBuf);
  3333. #endif
  3334. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3335. if( RetVal == 0 ) {
  3336. RetVal = getResourceID( NodeID, type, auxID );
  3337. };
  3338. };
  3339. };
  3340. return RetVal;
  3341. };
  3342. /*
  3343. uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
  3344. uint32_t retVal = 0;
  3345. if(m_bIsConnected){
  3346. char tQBuf[2048];
  3347. char tM5[33];
  3348. CSTR tMD5 = MD5String( path );
  3349. if( tMD5 != NULL ) {
  3350. memcpy( tM5, tMD5, 33 );
  3351. free( tMD5 );
  3352. sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
  3353. #ifdef DEBUG
  3354. LOG(tQBuf);
  3355. #endif
  3356. AAssoc *result;
  3357. result = m_pDatabase->Query( tQBuf );
  3358. if( result!= NULL ) {
  3359. if( result->size() > 0 ) {
  3360. Assoc * cArr;
  3361. Assoc::iterator it;
  3362. cArr = result->at(0);
  3363. it = cArr->find("id");
  3364. if( it != cArr->end() ){
  3365. retVal = atoi( it->second.c_str() );
  3366. };
  3367. };
  3368. };
  3369. deleteResult( result );
  3370. };
  3371. };
  3372. return retVal;
  3373. };
  3374. */
  3375. /*
  3376. CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
  3377. if(m_bIsConnected){
  3378. char tQBuf[CTEXT];
  3379. sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  3380. NodeID, Type );
  3381. #ifdef DEBUG
  3382. LOG(tQBuf);
  3383. #endif
  3384. AAssoc *result;
  3385. result = m_pDatabase->Query( tQBuf );
  3386. if( result!= NULL ) {
  3387. if( result->size() > 0 ) {
  3388. Assoc * cArr;
  3389. Assoc::iterator it;
  3390. cArr = result->at(0);
  3391. it = cArr->find("name");
  3392. if( it != cArr->end() ){
  3393. strncpy( tQBuf, it->second.c_str(), CTEXT );
  3394. };
  3395. };
  3396. };
  3397. deleteResult( result );
  3398. return strdup(tQBuf);
  3399. };
  3400. return NULL;
  3401. };
  3402. */
  3403. KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
  3404. KAFKA_SETTINGS *tVal = NULL;
  3405. if( m_bIsConnected ) {
  3406. char tQBuf[CTEXT];
  3407. AAssoc *result;
  3408. sprintf( tQBuf, "SELECT * FROM modules_kafka WHERE module_id = %d", ModuleID );
  3409. #ifdef DEBUG_ALL
  3410. LOG(tQBuf);
  3411. #endif
  3412. result = m_pDatabase->Query( tQBuf );
  3413. if( result!= NULL ) {
  3414. if( result->size() > 0 ) {
  3415. Assoc *cArr;
  3416. tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
  3417. if( tVal != NULL ) {
  3418. memset( tVal, 0, sizeof(KAFKA_SETTINGS) );
  3419. Assoc::iterator it;
  3420. cArr = result->at(0);
  3421. it = cArr->find("brocker_address");
  3422. if( it != cArr->end() ){
  3423. strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
  3424. };
  3425. it = cArr->find("brocker_port");
  3426. if( it != cArr->end() ){
  3427. tVal->brocker_port = atoi( it->second.c_str() );
  3428. };
  3429. it = cArr->find("use_ssl");
  3430. if( it != cArr->end() ){
  3431. tVal->use_ssl = (bool)atoi( it->second.c_str() );
  3432. };
  3433. it = cArr->find("auth_cert");
  3434. if( it != cArr->end() ){
  3435. tVal->auth_by_cert = (bool)atoi( it->second.c_str() );
  3436. };
  3437. it = cArr->find("auth_cred");
  3438. if( it != cArr->end() ){
  3439. tVal->auth_by_cred = (bool)atoi( it->second.c_str() );
  3440. };
  3441. it = cArr->find("vault_md5");
  3442. if( it != cArr->end() ){
  3443. strncpy( tVal->vault_md5, it->second.c_str(), 32 );
  3444. };
  3445. it = cArr->find("truststore");
  3446. if( it != cArr->end() ){
  3447. tVal->truststore = (bool)atoi( it->second.c_str() );
  3448. };
  3449. it = cArr->find("certstore");
  3450. if( it != cArr->end() ){
  3451. tVal->certstore = (bool)atoi( it->second.c_str() );
  3452. };
  3453. it = cArr->find("keystore");
  3454. if( it != cArr->end() ){
  3455. tVal->keystore = (bool)atoi( it->second.c_str() );
  3456. };
  3457. it = cArr->find("cred_username");
  3458. if( it != cArr->end() ){
  3459. strncpy( tVal->cred_username, it->second.c_str(), 32 );
  3460. };
  3461. it = cArr->find("cred_password");
  3462. if( it != cArr->end() ){
  3463. strncpy( tVal->cred_password, it->second.c_str(), 32 );
  3464. };
  3465. };
  3466. };
  3467. };
  3468. deleteResult( result );
  3469. };
  3470. return tVal;
  3471. };
  3472. KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
  3473. KAFKA_TEMPLATE *tVal = NULL;
  3474. if( m_bIsConnected ) {
  3475. char tQBuf[CTEXT];
  3476. AAssoc *result;
  3477. sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
  3478. #ifdef DEBUG_ALL
  3479. LOG(tQBuf);
  3480. #endif
  3481. result = m_pDatabase->Query( tQBuf );
  3482. if( result!= NULL ) {
  3483. if( result->size() > 0 ) {
  3484. Assoc *cArr;
  3485. tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
  3486. if( tVal != NULL ) {
  3487. Assoc::iterator it;
  3488. cArr = result->at(0);
  3489. it = cArr->find("topic");
  3490. if( it != cArr->end() ){
  3491. memset( tVal->topic, 0, 128 );
  3492. strncpy( tVal->topic , it->second.c_str(), 127 );
  3493. };
  3494. it = cArr->find("template");
  3495. if( it != cArr->end() ){
  3496. tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
  3497. if( tVal->tpl!= NULL) {
  3498. memset( tVal->tpl, 0, it->second.length() + 1 );
  3499. strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
  3500. };
  3501. };
  3502. };
  3503. };
  3504. };
  3505. deleteResult( result );
  3506. };
  3507. return tVal;
  3508. };
  3509. DBC_UART_DATA *argusDBC::getUartData( uint32_t UartID ){
  3510. DBC_UART_DATA *tVal = NULL;
  3511. if( m_bIsConnected ) {
  3512. char tQBuf[MAX_PATH_LEN];
  3513. AAssoc *result;
  3514. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  3515. #ifdef DEBUG_ALL
  3516. LOG(tQBuf);
  3517. #endif
  3518. result = m_pDatabase->Query( tQBuf );
  3519. if( result!= NULL ) {
  3520. if( result->size() > 0 ) {
  3521. Assoc *cArr;
  3522. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  3523. if( tVal != NULL ) {
  3524. Assoc::iterator it;
  3525. cArr = result->at(0);
  3526. it = cArr->find("type");
  3527. if( it != cArr->end() ){
  3528. tVal->type = atoi( it->second.c_str() );
  3529. };
  3530. it = cArr->find("speed");
  3531. if( it != cArr->end() ){
  3532. tVal->speed = atoi( it->second.c_str() );
  3533. };
  3534. it = cArr->find("mode");
  3535. if( it != cArr->end() ){
  3536. tVal->mode = atoi( it->second.c_str() );
  3537. };
  3538. it = cArr->find("port");
  3539. if( it != cArr->end() ){
  3540. tVal->port = atoi( it->second.c_str() );
  3541. };
  3542. it = cArr->find("path");
  3543. if( it != cArr->end() ){
  3544. strncpy( tVal->path, it->second.c_str(), 128 );
  3545. };
  3546. };
  3547. };
  3548. };
  3549. deleteResult( result );
  3550. };
  3551. return tVal;
  3552. };
  3553. uint32_t argusDBC::getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){
  3554. uint32_t RetVal = 0;
  3555. if(m_bIsConnected){
  3556. char tQBuf[CTEXT];
  3557. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path );
  3558. #ifdef DEBUG_ALL
  3559. LOG(tQBuf);
  3560. #endif
  3561. AAssoc *result;
  3562. result = m_pDatabase->Query( tQBuf );
  3563. if( result!= NULL ) {
  3564. if( result->size() > 0 ) {
  3565. Assoc * cArr;
  3566. Assoc::iterator it;
  3567. cArr = result->at(0);
  3568. it = cArr->find("id");
  3569. if( it != cArr->end() ){
  3570. RetVal = atoi( it->second.c_str() );
  3571. };
  3572. };
  3573. };
  3574. deleteResult( result );
  3575. };
  3576. return RetVal;
  3577. };
  3578. bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
  3579. if( m_bIsConnected ) {
  3580. char tQBuf[MAX_PATH_LEN];
  3581. if( key == NULL ) {
  3582. if( mrl == NULL ) {
  3583. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
  3584. } else {
  3585. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
  3586. };
  3587. } else {
  3588. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
  3589. key,
  3590. mrl,
  3591. id
  3592. );
  3593. };
  3594. #ifdef DEBUG_ALL
  3595. LOG(tQBuf);
  3596. #endif
  3597. m_pDatabase->SilentQuery( tQBuf );
  3598. return true;
  3599. };
  3600. return false;
  3601. };
  3602. bool argusDBC::updateResourceAUX( uint32_t ResID, uint32_t AUX ){
  3603. if( m_bIsConnected ) {
  3604. char tQBuf[MAX_PATH_LEN];
  3605. sprintf( tQBuf, "UPDATE `resources` SET `aux_id`=%d WHERE `id`=%d", AUX, ResID );
  3606. #ifdef DEBUG
  3607. LOG(tQBuf);
  3608. #endif
  3609. m_pDatabase->SilentQuery( tQBuf );
  3610. return true;
  3611. };
  3612. return false;
  3613. };
  3614. 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 ){
  3615. if( m_bIsConnected ) {
  3616. char tQBuf[MAX_PATH_LEN];
  3617. 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",
  3618. nCores,
  3619. cpu1,
  3620. cpu5,
  3621. cpu15,
  3622. mem,
  3623. disk,
  3624. dtsize,
  3625. dcsize,
  3626. mtsize,
  3627. mcsize,
  3628. ServerID
  3629. );
  3630. #ifdef DEBUG_ALL
  3631. LOG(tQBuf);
  3632. #endif
  3633. m_pDatabase->SilentQuery( tQBuf );
  3634. return true;
  3635. };
  3636. return false;
  3637. };
  3638. uint32_t argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){
  3639. uint32_t RetVal = 0;
  3640. if( m_bIsConnected ) {
  3641. char tQBuf[MAX_PATH_LEN];
  3642. 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",
  3643. SiteID,
  3644. status,
  3645. CNT,
  3646. SERIAL,
  3647. status,
  3648. CNT
  3649. );
  3650. #ifdef DEBUG_ALL
  3651. LOG(tQBuf);
  3652. #endif
  3653. uint64_t cid = m_pDatabase->QueryID( tQBuf );
  3654. if( cid == 0 ) {
  3655. AAssoc *result;
  3656. sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'",
  3657. SiteID,
  3658. SERIAL
  3659. );
  3660. #ifdef DEBUG_ALL
  3661. LOG(tQBuf);
  3662. #endif
  3663. result = m_pDatabase->Query( tQBuf );
  3664. if( result!= NULL ) {
  3665. if( result->size() > 0 ) {
  3666. Assoc * cArr;
  3667. Assoc::iterator it;
  3668. cArr = result->at(0);
  3669. it = cArr->find("id");
  3670. if( it != cArr->end() ){
  3671. cid = atoi( it->second.c_str() );
  3672. };
  3673. };
  3674. deleteResult( result );
  3675. };
  3676. };
  3677. if( cid!= 0 ) {
  3678. for( uint8_t idx = 0; idx < CNT; idx++ ) {
  3679. if( status & ( 1 << idx ) ){
  3680. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'",
  3681. (uint32_t) cid,
  3682. idx
  3683. );
  3684. } else {
  3685. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'",
  3686. (uint32_t) cid,
  3687. idx
  3688. );
  3689. }
  3690. #ifdef DEBUG_ALL
  3691. LOG(tQBuf);
  3692. #endif
  3693. m_pDatabase->SilentQuery( tQBuf );
  3694. };
  3695. };
  3696. };
  3697. return RetVal;
  3698. };
  3699. uint32_t argusDBC::addLocalUART( uint32_t NodeID, uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode, uint16_t port ){
  3700. uint32_t RetVal = 0;
  3701. if( m_bIsConnected ) {
  3702. char tQBuf[MAX_PATH_LEN];
  3703. sprintf( tQBuf, "INSERT INTO `uart_settings` SET `node_id`=%d, `type`=%d, `speed`=%d, `bit`=%d, `parity`='%c', `stop_bit`=%.1f, `mode`=%d, `port`=%d, `path`='%s' ON DUPLICATE KEY UPDATE `id`=`id`",
  3704. NodeID,
  3705. utype,
  3706. speed,
  3707. bit,
  3708. parity,
  3709. stop_bit,
  3710. mode,
  3711. port,
  3712. PATH
  3713. );
  3714. #ifdef DEBUG_ALL
  3715. LOG(tQBuf);
  3716. #endif
  3717. RetVal = m_pDatabase->QueryID( tQBuf );
  3718. if( RetVal == 0 ) {
  3719. RetVal = getUartID( NodeID, utype, PATH );
  3720. };
  3721. };
  3722. return RetVal;
  3723. };
  3724. uint32_t argusDBC::addLocalNIF( CSTR device, CSTR mac, ARGUS_NIF_TYPE dtype, ARGUS_NIF_MODE dmode, uint32_t aux_id ){
  3725. uint32_t RetVal = 0;
  3726. if( m_bIsConnected ) {
  3727. char tQBuf[MAX_PATH_LEN];
  3728. char * tKey = MD5String( device );
  3729. if( tKey != NULL ) {
  3730. sprintf( tQBuf, "INSERT INTO `network_interfaces` SET `type`=%d, `key`='%s', `device_name`='%s', `mac`='%s', `mode`=%d, `aux_id`=%d ON DUPLICATE KEY UPDATE `mode`=%d, `aux_id`=%d, `mac`='%s'",
  3731. dtype,
  3732. tKey,
  3733. device,
  3734. mac,
  3735. dmode,
  3736. aux_id,
  3737. dmode,
  3738. aux_id,
  3739. mac
  3740. );
  3741. #ifdef DEBUG
  3742. LOG(tQBuf);
  3743. #endif
  3744. RetVal = m_pDatabase->QueryID( tQBuf );
  3745. if( RetVal == 0 ) {
  3746. RetVal = getNIF_ID( tKey );
  3747. };
  3748. free( tKey );
  3749. };
  3750. };
  3751. return RetVal;
  3752. };
  3753. uint32_t argusDBC::addLocalWiFi( uint32_t NIF_ID, ARGUS_WIFI_MODE mode, CSTR SSID, CSTR password, ARGUS_WIFI_ENCRIPTION encryption, uint32_t router_id ){
  3754. uint32_t RetVal = 0;
  3755. if( m_bIsConnected ) {
  3756. char tQBuf[MAX_PATH_LEN];
  3757. sprintf( tQBuf, "INSERT INTO `wifis` SET `nif_id`=%d, `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d ON DUPLICATE KEY UPDATE `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d",
  3758. NIF_ID,
  3759. mode,
  3760. router_id,
  3761. SSID,
  3762. password,
  3763. encryption,
  3764. mode,
  3765. router_id,
  3766. SSID,
  3767. password,
  3768. encryption
  3769. );
  3770. #ifdef DEBUG
  3771. LOG(tQBuf);
  3772. #endif
  3773. RetVal = m_pDatabase->QueryID( tQBuf );
  3774. if( RetVal == 0 ) {
  3775. RetVal = getWiFi_ID( NIF_ID );
  3776. };
  3777. };
  3778. return RetVal;
  3779. };
  3780. uint32_t argusDBC::addLRFMask( uint32_t devID, uint8_t lrfID, uint8_t layerID ){
  3781. uint32_t RetVal = 0;
  3782. if( m_bIsConnected ) {
  3783. char tQBuf[MAX_PATH_LEN];
  3784. sprintf( tQBuf, "INSERT INTO `lrf_masks` SET `sensor_id`=%d, `lrf_id`=%d, `layer`=%d ON DUPLICATE KEY UPDATE `id`=`id`",
  3785. devID,
  3786. lrfID,
  3787. layerID
  3788. );
  3789. #ifdef DEBUG
  3790. LOG(tQBuf);
  3791. #endif
  3792. RetVal = m_pDatabase->QueryID( tQBuf );
  3793. if( RetVal == 0 ) {
  3794. RetVal = getLRFMaskID( devID, lrfID, layerID );
  3795. };
  3796. };
  3797. return RetVal;
  3798. };
  3799. uint32_t argusDBC::addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b ){
  3800. uint32_t RetVal = 0;
  3801. if( m_bIsConnected ) {
  3802. char tQBuf[MAX_PATH_LEN];
  3803. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertexes` SET `mask_id`=%d, `r`=%d, `g`=%d, `b`=%d",
  3804. maskID,
  3805. r,
  3806. g,
  3807. b
  3808. );
  3809. #ifdef DEBUG
  3810. LOG(tQBuf);
  3811. #endif
  3812. RetVal = m_pDatabase->QueryID( tQBuf );
  3813. };
  3814. return RetVal;
  3815. };
  3816. bool argusDBC::addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ){
  3817. if( m_bIsConnected ) {
  3818. char tQBuf[MAX_PATH_LEN];
  3819. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertex_points` SET `vertex_id`=%d, `x`=%d, `y`=%d",
  3820. polyID,
  3821. x,
  3822. y
  3823. );
  3824. #ifdef DEBUG
  3825. LOG(tQBuf);
  3826. #endif
  3827. m_pDatabase->SilentQuery( tQBuf );
  3828. return true;
  3829. };
  3830. return false;
  3831. };
  3832. uint32_t argusDBC::addLocalNetwork( uint32_t NIF_ID, ARGUS_NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){
  3833. uint32_t RetVal = 0;
  3834. if( m_bIsConnected ) {
  3835. char tQBuf[MAX_PATH_LEN];
  3836. sprintf( tQBuf, "INSERT INTO `networks` SET `nif_id`=%d, `type`=%d, `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s' ON DUPLICATE KEY UPDATE `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s'",
  3837. NIF_ID,
  3838. net_type,
  3839. address,
  3840. gateway,
  3841. mask,
  3842. broadcast,
  3843. address,
  3844. gateway,
  3845. mask,
  3846. broadcast
  3847. );
  3848. #ifdef DEBUG
  3849. LOG(tQBuf);
  3850. #endif
  3851. RetVal = m_pDatabase->QueryID( tQBuf );
  3852. // On Update IF data no need to return ID
  3853. //if( RetVal == 0 ) {
  3854. // RetVal = getNetworkInterfaceID( tKey );
  3855. //};
  3856. };
  3857. return RetVal;
  3858. };
  3859. uint32_t argusDBC::addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp, CSTR BRANG, CSTR ERANG, CSTR MASK, CSTR LEASE_TIME ){
  3860. uint32_t RetVal = 0;
  3861. if( m_bIsConnected ) {
  3862. char tQBuf[MAX_PATH_LEN];
  3863. bool ena_routing = true;
  3864. if( OUTBOUND_NIF == 0 ){
  3865. ena_routing = false;
  3866. };
  3867. if( ena_dhcp ){
  3868. if ( BRANG == NULL || ERANG == NULL || MASK == NULL || LEASE_TIME == NULL ) {
  3869. LOG_ERROR("Wrong DHCP parameters to create Network Infrastructure!");
  3870. return 0;
  3871. };
  3872. sprintf(tQBuf, "INSERT INTO `network_infrastructure` SET `nif_id`=%d, `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s' ON DUPLICATE KEY UPDATE `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s'",
  3873. NIF_ID,
  3874. ena_routing,
  3875. OUTBOUND_NIF,
  3876. BRANG,
  3877. ERANG,
  3878. MASK,
  3879. LEASE_TIME,
  3880. ena_routing,
  3881. OUTBOUND_NIF,
  3882. BRANG,
  3883. ERANG,
  3884. MASK,
  3885. LEASE_TIME
  3886. );
  3887. } else {
  3888. if( ena_routing ){
  3889. sprintf(tQBuf, "INSERT INTO `network_infrastructure` SET `nif_id`=%d, `enable_routing`=1, `outbond_nif`=%d ON DUPLICATE KEY UPDATE `enable_routing`=1, `outbond_nif`=%d",
  3890. NIF_ID,
  3891. OUTBOUND_NIF,
  3892. OUTBOUND_NIF
  3893. );
  3894. } else {
  3895. LOG_ERROR("No Special Service Defined To Network Infrastructure!");
  3896. return 0;
  3897. };
  3898. };
  3899. #ifdef DEBUG_ALL
  3900. LOG(tQBuf);
  3901. #endif
  3902. RetVal = m_pDatabase->QueryID( tQBuf );
  3903. // On Update IF data no need to return ID
  3904. if( RetVal == 0 ) {
  3905. RetVal = getNetworkInfrastructureID( NIF_ID );
  3906. };
  3907. };
  3908. return RetVal;
  3909. };
  3910. bool argusDBC::addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID, uint8_t type, bool rendered ){
  3911. if( m_bIsConnected ) {
  3912. char tQBuf[MAX_PATH_LEN];
  3913. if ( rendered ) {
  3914. sprintf(tQBuf, "INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d, `lrf_id`=%d, `type`=%d, `rendered`='Y' ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='Y'",
  3915. DBID,
  3916. ID,
  3917. SIZE,
  3918. kID,
  3919. type,
  3920. ID,
  3921. SIZE
  3922. );
  3923. } else {
  3924. sprintf(tQBuf, "INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d, `lrf_id`=%d, `type`=%d ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='N'",
  3925. DBID,
  3926. ID,
  3927. SIZE,
  3928. kID,
  3929. type,
  3930. ID,
  3931. SIZE
  3932. );
  3933. };
  3934. #ifdef DEBUG
  3935. LOG(tQBuf);
  3936. #endif
  3937. m_pDatabase->SilentQuery( tQBuf );
  3938. return true;
  3939. };
  3940. return false;
  3941. };
  3942. uint32_t argusDBC::addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint8_t k_id, uint16_t dig_r, float EL, float AZ, float RANGE, float AREA, float lat, float lon, float alt, uint32_t RefID, CSTR RefUUID ){
  3943. uint32_t RetVal = 0;
  3944. if( m_bIsConnected ) {
  3945. char tQBuf[MAX_PATH_LEN];
  3946. if( RefUUID == NULL ) {
  3947. sprintf( tQBuf,"INSERT INTO events_archive SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%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",
  3948. SRC,
  3949. UUID,
  3950. tss,
  3951. tsms,
  3952. evt_type,
  3953. k_id,
  3954. dig_r,
  3955. AZ,
  3956. EL,
  3957. RANGE,
  3958. AREA,
  3959. lat,
  3960. lon,
  3961. alt
  3962. );
  3963. } else {
  3964. sprintf( tQBuf,"INSERT INTO events_archive SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%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'",
  3965. SRC,
  3966. UUID,
  3967. tss,
  3968. tsms,
  3969. evt_type,
  3970. k_id,
  3971. dig_r,
  3972. AZ,
  3973. EL,
  3974. RANGE,
  3975. AREA,
  3976. lat,
  3977. lon,
  3978. alt,
  3979. RefUUID
  3980. );
  3981. };
  3982. #ifdef DEBUG_ALL
  3983. LOG(tQBuf);
  3984. #endif
  3985. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3986. if( RetVal ) {
  3987. if (RefUUID == NULL) {
  3988. sprintf( tQBuf,"INSERT INTO events_cloud SET id=%d, node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%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",
  3989. RetVal,
  3990. SRC,
  3991. UUID,
  3992. tss,
  3993. tsms,
  3994. evt_type,
  3995. k_id,
  3996. dig_r,
  3997. AZ,
  3998. EL,
  3999. RANGE,
  4000. AREA,
  4001. lat,
  4002. lon,
  4003. alt
  4004. );
  4005. } else {
  4006. sprintf( tQBuf,"INSERT INTO events_cloud SET id=%d, node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%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'",
  4007. RetVal,
  4008. SRC,
  4009. UUID,
  4010. tss,
  4011. tsms,
  4012. evt_type,
  4013. k_id,
  4014. dig_r,
  4015. AZ,
  4016. EL,
  4017. RANGE,
  4018. AREA,
  4019. lat,
  4020. lon,
  4021. alt,
  4022. RefUUID
  4023. );
  4024. };
  4025. m_pDatabase->SilentQuery( tQBuf );
  4026. };
  4027. // Cleanup Mem Targets Older then 1 Hour
  4028. sprintf( tQBuf, "DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - 3600 )" );
  4029. m_pDatabase->SilentQuery( tQBuf );
  4030. };
  4031. return RetVal;
  4032. };
  4033. bool argusDBC::addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ){
  4034. bool rVal = false;
  4035. if( th_data != NULL && th_size ){
  4036. if( m_bIsConnected ){
  4037. CSTR tPData = m_pDatabase->escapeBinary( (uint8_t *) th_data, th_size );
  4038. if ( tPData ) {
  4039. CSTR tQBuf = (CSTR)malloc(BUF_4MB);
  4040. if( tQBuf ) {
  4041. sprintf( tQBuf, "DELETE FROM `lrf_draw` WHERE `node_id`=%d AND `lrf_id`=%d AND `type`=%d", DBID, lrf, type );
  4042. LOG( tQBuf );
  4043. m_pDatabase->SilentQuery( tQBuf );
  4044. sprintf( tQBuf, "INSERT INTO lrf_draw(node_id,ts,lrf_id,type,size,data) VALUES(%d,NOW(),%d,%d,%d,'%s')", DBID, lrf, type, th_size, tPData );
  4045. m_pDatabase->SilentQuery( tQBuf );
  4046. LOG( "Inserted Draw OK!" );
  4047. free( tQBuf );
  4048. rVal = true;
  4049. } else {
  4050. LOG_ERROR("Error Allocating Query Buffer!");
  4051. };
  4052. free( tPData );
  4053. } else {
  4054. LOG_ERROR( "Error escaping Pic Data!");
  4055. };
  4056. };
  4057. };
  4058. return rVal;
  4059. };
  4060. bool argusDBC::addVideoEvent( uint32_t evtID, uint32_t videoID, uint32_t clen ){
  4061. if( m_bIsConnected ) {
  4062. char tQBuf[MAX_PATH_LEN];
  4063. sprintf( tQBuf, "INSERT INTO `events_2_videos` SET `evt_id`=%d, `video_id`=%d, `frame`=%d", evtID, videoID, clen );
  4064. #ifdef DEBUG_ALL
  4065. LOG(tQBuf);
  4066. #endif
  4067. m_pDatabase->SilentQuery( tQBuf );
  4068. return true;
  4069. };
  4070. return true;
  4071. };
  4072. /*
  4073. bool argusDBC::addPictureEvent( uint32_t evtID, uint32_t pictureoID ){
  4074. if( m_bIsConnected ) {
  4075. char tQBuf[MAX_PATH_LEN];
  4076. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", evtID, pictureoID );
  4077. #ifdef DEBUG_ALL
  4078. LOG(tQBuf);
  4079. #endif
  4080. m_pDatabase->SilentQuery( tQBuf );
  4081. return true;
  4082. };
  4083. return true;
  4084. };
  4085. */
  4086. uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, CSTR ext, uint32_t ts, uint32_t tsms, uint32_t fps ){
  4087. uint32_t tID = 0;
  4088. if( m_bIsConnected ) {
  4089. char tQBuf[MAX_PATH_LEN];
  4090. sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `uts`=%d, `uts_ms`=%d, `md5`='%s', `ext`='%s', `fps`=%d ", streamID, ts, tsms, md5, ext, fps );
  4091. #ifdef DEBUG_ALL
  4092. LOG(tQBuf);
  4093. #endif
  4094. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  4095. }
  4096. return tID;
  4097. };
  4098. bool argusDBC::addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ){
  4099. bool rVal = false;
  4100. if( ptr != NULL ){
  4101. if( m_bIsConnected ){
  4102. CSTR tPData = m_pDatabase->escapeBinary( ptr->data, ptr->data_size );
  4103. if ( tPData ) {
  4104. uint32_t pic_id;
  4105. CSTR tQBuf = (CSTR)malloc(BUF_4MB);
  4106. if( tQBuf ) {
  4107. //sprintf( tQBuf, "INSERT INTO `pictures` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'",
  4108. sprintf( tQBuf, "INSERT INTO pictures(media_stream_id,ts,md5,ext,data) VALUES(%d,NOW(),'%s','%s','%s')",
  4109. ptr->stream_id, ptr->md5, ext, tPData );
  4110. pic_id = (uint32_t) m_pDatabase->QueryID( tQBuf );
  4111. if ( pic_id ) {
  4112. for( DBC_INT_LIST::iterator idx = ptr->assoc_event_ids.begin(); idx < ptr->assoc_event_ids.end(); idx++ ) {
  4113. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", (*idx), pic_id );
  4114. m_pDatabase->SilentQuery( tQBuf );
  4115. };
  4116. rVal = true;
  4117. };
  4118. free( tQBuf );
  4119. } else {
  4120. LOG_ERROR("Error Allocating Query Buffer!");
  4121. };
  4122. free( tPData );
  4123. } else {
  4124. LOG_ERROR( "Error escaping Pic Data!");
  4125. };
  4126. };
  4127. };
  4128. return rVal;
  4129. };
  4130. 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 ){
  4131. if( m_bIsConnected ) {
  4132. char tQBuf[MAX_PATH_LEN];
  4133. if( master ) {
  4134. sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles` SET `aux_id`=%d, `profile_id`=%d, `master`=b'1', `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d ON DUPLICATE KEY UPDATE `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
  4135. lrfID,
  4136. profileID,
  4137. nOrder,
  4138. nOffset,
  4139. nDelta,
  4140. nFlip,
  4141. nWidth,
  4142. bSST,
  4143. nSun,
  4144. GP,
  4145. spikes,
  4146. nOrder,
  4147. nOffset,
  4148. nDelta,
  4149. nFlip,
  4150. nWidth,
  4151. bSST,
  4152. nSun,
  4153. GP,
  4154. spikes );
  4155. } else {
  4156. sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles` SET `aux_id`=%d, `profile_id`=%d, `master`=b'0', `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d ON DUPLICATE KEY UPDATE `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
  4157. lrfID,
  4158. profileID,
  4159. nOrder,
  4160. nOffset,
  4161. nDelta,
  4162. nFlip,
  4163. nWidth,
  4164. bSST,
  4165. nSun,
  4166. GP,
  4167. spikes,
  4168. nOrder,
  4169. nOffset,
  4170. nDelta,
  4171. nFlip,
  4172. nWidth,
  4173. bSST,
  4174. nSun,
  4175. GP,
  4176. spikes );
  4177. };
  4178. #ifdef DEBUG_ALL
  4179. LOG(tQBuf);
  4180. #endif
  4181. m_pDatabase->SilentQuery( tQBuf );
  4182. return true;
  4183. };
  4184. return false;
  4185. };
  4186. bool argusDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  4187. if( m_bIsConnected ) {
  4188. char tQBuf[MAX_PATH_LEN];
  4189. CSTR tES = m_pDatabase->escapeString( Serial );
  4190. if( tES ) {
  4191. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  4192. free( tES );
  4193. #ifdef DEBUG_ALL
  4194. LOG(tQBuf);
  4195. #endif
  4196. m_pDatabase->SilentQuery( tQBuf );
  4197. return true;
  4198. };
  4199. };
  4200. return false;
  4201. };
  4202. bool argusDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  4203. if( m_bIsConnected ) {
  4204. char tQBuf[MAX_PATH_LEN];
  4205. CSTR tES = m_pDatabase->escapeString( version );
  4206. if( tES ) {
  4207. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  4208. free( tES );
  4209. #ifdef DEBUG_ALL
  4210. LOG(tQBuf);
  4211. #endif
  4212. m_pDatabase->SilentQuery( tQBuf );
  4213. return true;
  4214. };
  4215. };
  4216. return false;
  4217. };
  4218. bool argusDBC::update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr ){
  4219. if( m_bIsConnected ) {
  4220. char tQBuf[MAX_PATH_LEN];
  4221. sprintf( tQBuf, "INSERT INTO `lrf_runtime_status` SET `lrf_id`=%d ON DUPLICATE KEY UPDATE `lrf_id`=`lrf_id`", lrfID );
  4222. #ifdef DEBUG_ALL
  4223. LOG(tQBuf);
  4224. #endif
  4225. m_pDatabase->SilentQuery( tQBuf );
  4226. sprintf( tQBuf,
  4227. "UPDATE `lrf_runtime_status` SET "
  4228. "`hw_status`=%d,"
  4229. "`detecting_kernels`=%d,"
  4230. "`th_ready`=%d,"
  4231. "`master_flips`=%d,"
  4232. "`slave_flips`=%d,"
  4233. "`twinc`=%d,"
  4234. "`master_mp_0`=%d,"
  4235. "`master_mp_1`=%d,"
  4236. "`master_mp_2`=%d,"
  4237. "`master_mp_3`=%d,"
  4238. "`master_mp_4`=%d,"
  4239. "`master_mp_5`=%d,"
  4240. "`master_mp_6`=%d,"
  4241. "`master_mp_7`=%d,"
  4242. "`master_gp_0`=%d,"
  4243. "`master_gp_1`=%d,"
  4244. "`master_gp_2`=%d,"
  4245. "`master_gp_3`=%d,"
  4246. "`master_gp_4`=%d,"
  4247. "`master_gp_5`=%d,"
  4248. "`master_gp_6`=%d,"
  4249. "`master_gp_7`=%d,"
  4250. "`master_wp_0`=%d,"
  4251. "`master_wp_1`=%d,"
  4252. "`master_wp_2`=%d,"
  4253. "`master_wp_3`=%d,"
  4254. "`master_wp_4`=%d,"
  4255. "`master_wp_5`=%d,"
  4256. "`master_wp_6`=%d,"
  4257. "`master_wp_7`=%d,"
  4258. "`slave_mp_0`=%d,"
  4259. "`slave_mp_1`=%d,"
  4260. "`slave_mp_2`=%d,"
  4261. "`slave_mp_3`=%d,"
  4262. "`slave_mp_4`=%d,"
  4263. "`slave_mp_5`=%d,"
  4264. "`slave_mp_6`=%d,"
  4265. "`slave_mp_7`=%d,"
  4266. "`slave_gp_0`=%d,"
  4267. "`slave_gp_1`=%d,"
  4268. "`slave_gp_2`=%d,"
  4269. "`slave_gp_3`=%d,"
  4270. "`slave_gp_4`=%d,"
  4271. "`slave_gp_5`=%d,"
  4272. "`slave_gp_6`=%d,"
  4273. "`slave_gp_7`=%d,"
  4274. "`slave_wp_0`=%d,"
  4275. "`slave_wp_1`=%d,"
  4276. "`slave_wp_2`=%d,"
  4277. "`slave_wp_3`=%d,"
  4278. "`slave_wp_4`=%d,"
  4279. "`slave_wp_5`=%d,"
  4280. "`slave_wp_6`=%d,"
  4281. "`slave_wp_7`=%d"
  4282. " WHERE `lrf_id`=%d",
  4283. ptr->HW_STATUS,
  4284. ptr->DETECTING_LRF,
  4285. ptr->TH_READY,
  4286. ptr->MASTER_FLIP_CNT,
  4287. ptr->SLAVE_FLIP_CNT,
  4288. ptr->TWINC_STATUS,
  4289. ptr->MASTER_MP[0],
  4290. ptr->MASTER_MP[1],
  4291. ptr->MASTER_MP[2],
  4292. ptr->MASTER_MP[3],
  4293. ptr->MASTER_MP[4],
  4294. ptr->MASTER_MP[5],
  4295. ptr->MASTER_MP[6],
  4296. ptr->MASTER_MP[7],
  4297. ptr->MASTER_GP[0],
  4298. ptr->MASTER_GP[1],
  4299. ptr->MASTER_GP[2],
  4300. ptr->MASTER_GP[3],
  4301. ptr->MASTER_GP[4],
  4302. ptr->MASTER_GP[5],
  4303. ptr->MASTER_GP[6],
  4304. ptr->MASTER_GP[7],
  4305. ptr->MASTER_WP[0],
  4306. ptr->MASTER_WP[1],
  4307. ptr->MASTER_WP[2],
  4308. ptr->MASTER_WP[3],
  4309. ptr->MASTER_WP[4],
  4310. ptr->MASTER_WP[5],
  4311. ptr->MASTER_WP[6],
  4312. ptr->MASTER_WP[7],
  4313. ptr->SLAVE_MP[0],
  4314. ptr->SLAVE_MP[1],
  4315. ptr->SLAVE_MP[2],
  4316. ptr->SLAVE_MP[3],
  4317. ptr->SLAVE_MP[4],
  4318. ptr->SLAVE_MP[5],
  4319. ptr->SLAVE_MP[6],
  4320. ptr->SLAVE_MP[7],
  4321. ptr->SLAVE_GP[0],
  4322. ptr->SLAVE_GP[1],
  4323. ptr->SLAVE_GP[2],
  4324. ptr->SLAVE_GP[3],
  4325. ptr->SLAVE_GP[4],
  4326. ptr->SLAVE_GP[5],
  4327. ptr->SLAVE_GP[6],
  4328. ptr->SLAVE_GP[7],
  4329. ptr->SLAVE_WP[0],
  4330. ptr->SLAVE_WP[1],
  4331. ptr->SLAVE_WP[2],
  4332. ptr->SLAVE_WP[3],
  4333. ptr->SLAVE_WP[4],
  4334. ptr->SLAVE_WP[5],
  4335. ptr->SLAVE_WP[6],
  4336. ptr->SLAVE_WP[7],
  4337. lrfID
  4338. );
  4339. #ifdef DEBUG_ALL
  4340. LOG(tQBuf);
  4341. #endif
  4342. m_pDatabase->SilentQuery( tQBuf );
  4343. return true;
  4344. };
  4345. return false;
  4346. };
  4347. bool argusDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  4348. if( m_bIsConnected ) {
  4349. char tQBuf[MAX_PATH_LEN];
  4350. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  4351. #ifdef DEBUG_ALL
  4352. LOG(tQBuf);
  4353. #endif
  4354. m_pDatabase->SilentQuery( tQBuf );
  4355. return true;
  4356. };
  4357. return false;
  4358. };
  4359. bool argusDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  4360. if( m_bIsConnected ) {
  4361. char tQBuf[MAX_PATH_LEN];
  4362. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  4363. #ifdef DEBUG_ALL
  4364. LOG(tQBuf);
  4365. #endif
  4366. m_pDatabase->SilentQuery( tQBuf );
  4367. return true;
  4368. };
  4369. return false;
  4370. };
  4371. bool argusDBC::setLRFMaskStatus( uint32_t maskID, bool status ){
  4372. if( m_bIsConnected ) {
  4373. char tQBuf[MAX_PATH_LEN];
  4374. char S[2];
  4375. if (status ) {
  4376. S[0] = 'E';
  4377. S[1] = (char)0;
  4378. } else {
  4379. S[0] = 'D';
  4380. S[1] = (char)0;
  4381. };
  4382. sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='%s' WHERE `id`=%d", S, maskID );
  4383. #ifdef DEBUG_ALL
  4384. LOG(tQBuf);
  4385. #endif
  4386. m_pDatabase->SilentQuery( tQBuf );
  4387. return true;
  4388. };
  4389. return false;
  4390. };
  4391. bool argusDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  4392. if( m_bIsConnected ) {
  4393. char tQBuf[MAX_PATH_LEN];
  4394. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  4395. #ifdef DEBUG_ALL
  4396. LOG(tQBuf);
  4397. #endif
  4398. m_pDatabase->SilentQuery( tQBuf );
  4399. return true;
  4400. };
  4401. return false;
  4402. };
  4403. bool argusDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  4404. if( m_bIsConnected ) {
  4405. char tQBuf[MAX_PATH_LEN];
  4406. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  4407. #ifdef DEBUG_ALL
  4408. LOG(tQBuf);
  4409. #endif
  4410. m_pDatabase->SilentQuery( tQBuf );
  4411. return true;
  4412. };
  4413. return false;
  4414. };
  4415. bool argusDBC::setStreamValid( uint32_t streamID, bool status ){
  4416. if( m_bIsConnected ) {
  4417. char tQBuf[MAX_PATH_LEN];
  4418. if ( status ) {
  4419. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID);
  4420. } else {
  4421. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `id`=%d", streamID);
  4422. };
  4423. #ifdef DEBUG_ALL
  4424. LOG(tQBuf);
  4425. #endif
  4426. m_pDatabase->SilentQuery( tQBuf );
  4427. return true;
  4428. };
  4429. return false;
  4430. };
  4431. bool argusDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
  4432. if( m_bIsConnected ) {
  4433. char tQBuf[MAX_PATH_LEN];
  4434. 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",
  4435. filterID,
  4436. Tag,
  4437. x,y,z,
  4438. x,y,z
  4439. );
  4440. #ifdef DEBUG_ALL
  4441. LOG(tQBuf);
  4442. #endif
  4443. m_pDatabase->SilentQuery( tQBuf );
  4444. return true;
  4445. };
  4446. return false;
  4447. };
  4448. DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){
  4449. DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL;
  4450. if( m_bIsConnected ) {
  4451. char tQBuf[MAX_PATH_LEN];
  4452. AAssoc *result;
  4453. sprintf( tQBuf, "SELECT * FROM `module_embed_video_settings` WHERE `id`=%d", ID );
  4454. #ifdef DEBUG_ALL
  4455. LOG(tQBuf);
  4456. #endif
  4457. result = m_pDatabase->Query( tQBuf );
  4458. if( result!= NULL ) {
  4459. if( result->size() > 0 ) {
  4460. Assoc *cArr;
  4461. tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  4462. if( tPtr!= NULL ) {
  4463. Assoc::iterator it;
  4464. memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  4465. cArr = result->at(0);
  4466. it = cArr->find("output_mode");
  4467. if( it != cArr->end() ){
  4468. tPtr->output_mode = atoi( it->second.c_str() );
  4469. };
  4470. it = cArr->find("web_port");
  4471. if( it != cArr->end() ){
  4472. tPtr->port = atoi( it->second.c_str() );
  4473. };
  4474. it = cArr->find("width");
  4475. if( it != cArr->end() ){
  4476. tPtr->width = atoi( it->second.c_str() );
  4477. };
  4478. it = cArr->find("height");
  4479. if( it != cArr->end() ){
  4480. tPtr->height = atoi( it->second.c_str() );
  4481. };
  4482. it = cArr->find("compression_quality");
  4483. if( it != cArr->end() ){
  4484. tPtr->compression_quality = atoi( it->second.c_str() );
  4485. };
  4486. it = cArr->find("show_ts");
  4487. if( it != cArr->end() ){
  4488. tPtr->show_ts = (bool)atoi( it->second.c_str() );
  4489. };
  4490. it = cArr->find("ts_x");
  4491. if( it != cArr->end() ){
  4492. tPtr->ts_x = atoi( it->second.c_str() );
  4493. };
  4494. it = cArr->find("ts_y");
  4495. if( it != cArr->end() ){
  4496. tPtr->ts_y = atoi( it->second.c_str() );
  4497. };
  4498. it = cArr->find("ts_font_face");
  4499. if( it != cArr->end() ){
  4500. tPtr->ts_font_face = atoi( it->second.c_str() );
  4501. };
  4502. it = cArr->find("ts_font_scale");
  4503. if( it != cArr->end() ){
  4504. tPtr->ts_font_scale = atof( it->second.c_str() );
  4505. };
  4506. it = cArr->find("ts_font_thickness");
  4507. if( it != cArr->end() ){
  4508. tPtr->ts_font_thickness = atoi( it->second.c_str() );
  4509. };
  4510. it = cArr->find("ts_line_type");
  4511. if( it != cArr->end() ){
  4512. tPtr->ts_line_type = atoi( it->second.c_str() );
  4513. };
  4514. it = cArr->find("ts_transperant");
  4515. if( it != cArr->end() ){
  4516. tPtr->ts_transperant = (bool)atoi( it->second.c_str() );
  4517. };
  4518. it = cArr->find("show_label");
  4519. if( it != cArr->end() ){
  4520. tPtr->show_label = (bool)atoi( it->second.c_str() );
  4521. };
  4522. it = cArr->find("label_x");
  4523. if( it != cArr->end() ){
  4524. tPtr->label_x = atoi( it->second.c_str() );
  4525. };
  4526. it = cArr->find("label_y");
  4527. if( it != cArr->end() ){
  4528. tPtr->label_y = atoi( it->second.c_str() );
  4529. };
  4530. it = cArr->find("label_font_face");
  4531. if( it != cArr->end() ){
  4532. tPtr->label_font_face = atoi( it->second.c_str() );
  4533. };
  4534. it = cArr->find("label_font_scale");
  4535. if( it != cArr->end() ){
  4536. tPtr->label_font_scale = atof( it->second.c_str() );
  4537. };
  4538. it = cArr->find("label_font_thickness");
  4539. if( it != cArr->end() ){
  4540. tPtr->label_font_thickness = atoi( it->second.c_str() );
  4541. };
  4542. it = cArr->find("label_line_type");
  4543. if( it != cArr->end() ){
  4544. tPtr->label_line_type = atoi( it->second.c_str() );
  4545. };
  4546. it = cArr->find("label_transperant");
  4547. if( it != cArr->end() ){
  4548. tPtr->label_transperant = (bool) atoi( it->second.c_str() );
  4549. };
  4550. it = cArr->find("show_logo");
  4551. if( it != cArr->end() ){
  4552. tPtr->show_logo = (bool) atoi( it->second.c_str() );
  4553. };
  4554. it = cArr->find("logo_w");
  4555. if( it != cArr->end() ){
  4556. tPtr->logo_w = atoi( it->second.c_str() );
  4557. };
  4558. it = cArr->find("logo_h");
  4559. if( it != cArr->end() ){
  4560. tPtr->logo_h = atoi( it->second.c_str() );
  4561. };
  4562. it = cArr->find("logo_x");
  4563. if( it != cArr->end() ){
  4564. tPtr->logo_x = atoi( it->second.c_str() );
  4565. };
  4566. it = cArr->find("logo_y");
  4567. if( it != cArr->end() ){
  4568. tPtr->logo_y = atoi( it->second.c_str() );
  4569. };
  4570. it = cArr->find("logo_md5");
  4571. if( it != cArr->end() ){
  4572. strncpy( tPtr->logo_md5, it->second.c_str(),32);
  4573. tPtr->logo_md5[32]=(char)0;
  4574. };
  4575. };
  4576. };
  4577. };
  4578. deleteResult( result );
  4579. };
  4580. return tPtr;
  4581. };
  4582. DBC_EVT_RECORD *argusDBC::getEventByUUID( CSTR UUID ){
  4583. DBC_EVT_RECORD *tPtr = NULL;
  4584. if( m_bIsConnected ) {
  4585. char tQBuf[MAX_PATH_LEN];
  4586. AAssoc *result;
  4587. sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
  4588. #ifdef DEBUG_ALL
  4589. LOG(tQBuf);
  4590. #endif
  4591. result = m_pDatabase->Query( tQBuf );
  4592. if( result!= NULL ) {
  4593. if( result->size() > 0 ) {
  4594. Assoc *cArr;
  4595. tPtr = (DBC_EVT_RECORD*)malloc(sizeof(DBC_EVT_RECORD));
  4596. if( tPtr!= NULL ) {
  4597. Assoc::iterator it;
  4598. memset(tPtr,0,sizeof(DBC_EVT_RECORD));
  4599. cArr = result->at(0);
  4600. it = cArr->find("id");
  4601. if( it != cArr->end() ){
  4602. tPtr->id = atoi( it->second.c_str() );
  4603. };
  4604. it = cArr->find("node_id");
  4605. if( it != cArr->end() ){
  4606. tPtr->node_id = atoi( it->second.c_str() );
  4607. };
  4608. it = cArr->find("uuid");
  4609. if( it != cArr->end() ){
  4610. strncpy( tPtr->uuid, it->second.c_str(),64 );
  4611. };
  4612. it = cArr->find("ts");
  4613. if( it != cArr->end() ){
  4614. tPtr->ts_s = atoi( it->second.c_str() );
  4615. };
  4616. it = cArr->find("ts_ms");
  4617. if( it != cArr->end() ){
  4618. tPtr->ts_ms = atoi( it->second.c_str() );
  4619. };
  4620. it = cArr->find("evt_type");
  4621. if( it != cArr->end() ){
  4622. tPtr->type = atoi( it->second.c_str() );
  4623. };
  4624. it = cArr->find("range_digital");
  4625. if( it != cArr->end() ){
  4626. tPtr->range_digital = atoi( it->second.c_str() );
  4627. };
  4628. it = cArr->find("azimuth");
  4629. if( it != cArr->end() ){
  4630. tPtr->az = atof( it->second.c_str() );
  4631. };
  4632. it = cArr->find("elevation");
  4633. if( it != cArr->end() ){
  4634. tPtr->el = atof( it->second.c_str() );
  4635. };
  4636. it = cArr->find("range");
  4637. if( it != cArr->end() ){
  4638. tPtr->ra = atof( it->second.c_str() );
  4639. };
  4640. it = cArr->find("area");
  4641. if( it != cArr->end() ){
  4642. tPtr->area = atof( it->second.c_str() );
  4643. };
  4644. it = cArr->find("lat");
  4645. if( it != cArr->end() ){
  4646. tPtr->lat = atof( it->second.c_str() );
  4647. };
  4648. it = cArr->find("lon");
  4649. if( it != cArr->end() ){
  4650. tPtr->lon = atof( it->second.c_str() );
  4651. };
  4652. it = cArr->find("alt");
  4653. if( it != cArr->end() ){
  4654. tPtr->alt = atof( it->second.c_str() );
  4655. };
  4656. it = cArr->find("ref_id");
  4657. if( it != cArr->end() ){
  4658. tPtr->ref_id = atoi( it->second.c_str() );
  4659. };
  4660. it = cArr->find("ref_uuid");
  4661. if( it != cArr->end() ){
  4662. strncpy( tPtr->ref_uuid, it->second.c_str(),64 );
  4663. };
  4664. };
  4665. };
  4666. };
  4667. deleteResult( result );
  4668. };
  4669. return tPtr;
  4670. };
  4671. #undef LOG
  4672. #undef LOG_ERROR