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.

4765 lines
173 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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::getWiFi_ID( uint32_t nif_id ){
  1169. uint32_t tVal = 0;
  1170. if(m_bIsConnected){
  1171. char tQBuf[CTEXT];
  1172. AAssoc *result;
  1173. sprintf(tQBuf, "SELECT `id` FROM `wifis` WHERE `nif_id`=%d", nif_id );
  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("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::getNIF_ID( CSTR key ){
  1194. uint32_t tVal = 0;
  1195. if(m_bIsConnected){
  1196. char tQBuf[CTEXT];
  1197. AAssoc *result;
  1198. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `key`='%s'", key );
  1199. #ifdef DEBUG_EXTRA
  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("id");
  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::getNIF_IDbyDevice( CSTR device ){
  1219. uint32_t tVal = 0;
  1220. if(m_bIsConnected){
  1221. char tQBuf[CTEXT];
  1222. AAssoc *result;
  1223. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `device_name`='%s'", device );
  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. DBC_NODE_DATA *argusDBC::getNodeData( uint32_t ID ){
  1244. DBC_NODE_DATA * tVal = NULL;
  1245. if(m_bIsConnected){
  1246. char tQBuf[CTEXT];
  1247. AAssoc *result;
  1248. sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );
  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. tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
  1257. if( tVal != NULL ) {
  1258. memset( tVal, 0, sizeof(DBC_NODE_DATA));
  1259. Assoc::iterator it;
  1260. cArr = result->at(0);
  1261. it = cArr->find("id");
  1262. if( it != cArr->end() ){
  1263. tVal->node_id = atoi( it->second.c_str() );
  1264. };
  1265. it = cArr->find("type");
  1266. if( it != cArr->end() ){
  1267. tVal->type = (ARGUS_NODE_TYPE) atoi( it->second.c_str() );
  1268. };
  1269. it = cArr->find("aux_id");
  1270. if( it != cArr->end() ){
  1271. tVal->aux_id = atoi( it->second.c_str() );
  1272. };
  1273. it = cArr->find("aux_parameter");
  1274. if( it != cArr->end() ){
  1275. tVal->aux_parameter = atoi( it->second.c_str() );
  1276. };
  1277. it = cArr->find("name");
  1278. if( it != cArr->end() ){
  1279. sprintf( tVal->name, it->second.c_str() );
  1280. };
  1281. it = cArr->find("ts_s");
  1282. if( it != cArr->end() ){
  1283. tVal->tss = atoi( it->second.c_str() );
  1284. };
  1285. it = cArr->find("ts_ms");
  1286. if( it != cArr->end() ){
  1287. tVal->tsm = atoi( it->second.c_str() );
  1288. };
  1289. it = cArr->find("online");
  1290. if( it != cArr->end() ){
  1291. tVal->online = (bool)atoi( it->second.c_str() );
  1292. };
  1293. };
  1294. };
  1295. };
  1296. deleteResult( result );
  1297. };
  1298. return tVal;
  1299. };
  1300. DBC_APF_DATA *argusDBC::getAPFData( uint32_t APFID ){
  1301. DBC_APF_DATA * tVal = NULL;
  1302. if(m_bIsConnected){
  1303. char tQBuf[CTEXT];
  1304. AAssoc *result;
  1305. sprintf(tQBuf, "SELECT * FROM `target_filter_apf` WHERE `id`=%d", APFID );
  1306. #ifdef DEBUG
  1307. LOG(tQBuf);
  1308. #endif
  1309. result = m_pDatabase->Query( tQBuf );
  1310. if( result!= NULL ) {
  1311. if( result->size() > 0 ) {
  1312. Assoc *cArr;
  1313. tVal = (DBC_APF_DATA*) malloc(sizeof(DBC_APF_DATA));
  1314. if( tVal != NULL ) {
  1315. memset( tVal, 0 , sizeof(DBC_APF_DATA));
  1316. Assoc::iterator it;
  1317. cArr = result->at(0);
  1318. it = cArr->find("mode");
  1319. if( it != cArr->end() ){
  1320. sprintf( tVal->mode, it->second.c_str() );
  1321. };
  1322. it = cArr->find("port");
  1323. if( it != cArr->end() ){
  1324. tVal->port = atoi( it->second.c_str() );
  1325. };
  1326. it = cArr->find("lat");
  1327. if( it != cArr->end() ){
  1328. tVal->lat = atof( it->second.c_str() );
  1329. };
  1330. it = cArr->find("lon");
  1331. if( it != cArr->end() ){
  1332. tVal->lon = atof( it->second.c_str() );
  1333. };
  1334. it = cArr->find("alt");
  1335. if( it != cArr->end() ){
  1336. tVal->alt = atof( it->second.c_str() );
  1337. };
  1338. it = cArr->find("roll");
  1339. if( it != cArr->end() ){
  1340. tVal->roll = atof( it->second.c_str() );
  1341. };
  1342. it = cArr->find("pitch");
  1343. if( it != cArr->end() ){
  1344. tVal->pitch = atof( it->second.c_str() );
  1345. };
  1346. it = cArr->find("yaw");
  1347. if( it != cArr->end() ){
  1348. tVal->yaw = atof( it->second.c_str() );
  1349. };
  1350. it = cArr->find("dx");
  1351. if( it != cArr->end() ){
  1352. tVal->dx = atof( it->second.c_str() );
  1353. };
  1354. it = cArr->find("dy");
  1355. if( it != cArr->end() ){
  1356. tVal->dy = atof( it->second.c_str() );
  1357. };
  1358. it = cArr->find("dz");
  1359. if( it != cArr->end() ){
  1360. tVal->dz = atof( it->second.c_str() );
  1361. };
  1362. };
  1363. };
  1364. };
  1365. deleteResult( result );
  1366. };
  1367. return tVal;
  1368. };
  1369. DBC_FH_DATA *argusDBC::getFlyHunterData( uint32_t ID ){
  1370. DBC_FH_DATA * tVal = NULL;
  1371. if(m_bIsConnected){
  1372. char tQBuf[CTEXT];
  1373. AAssoc *result;
  1374. sprintf(tQBuf, "SELECT * FROM `modules_fly_hunter` WHERE `id`=%d", ID );
  1375. #ifdef DEBUG
  1376. LOG(tQBuf);
  1377. #endif
  1378. result = m_pDatabase->Query( tQBuf );
  1379. if( result!= NULL ) {
  1380. if( result->size() > 0 ) {
  1381. Assoc *cArr;
  1382. tVal = (DBC_FH_DATA*) malloc(sizeof(DBC_FH_DATA));
  1383. if( tVal != NULL ) {
  1384. memset( tVal, 0 , sizeof(DBC_FH_DATA));
  1385. Assoc::iterator it;
  1386. cArr = result->at(0);
  1387. it = cArr->find("name");
  1388. if( it != cArr->end() ){
  1389. sprintf( tVal->name, it->second.c_str() );
  1390. };
  1391. it = cArr->find("lat");
  1392. if( it != cArr->end() ){
  1393. tVal->lat = atof( it->second.c_str() );
  1394. };
  1395. it = cArr->find("lon");
  1396. if( it != cArr->end() ){
  1397. tVal->lon = atof( it->second.c_str() );
  1398. };
  1399. it = cArr->find("alt");
  1400. if( it != cArr->end() ){
  1401. tVal->alt = atof( it->second.c_str() );
  1402. };
  1403. it = cArr->find("dc_module_id");
  1404. if( it != cArr->end() ){
  1405. tVal->dc_id = atoi( it->second.c_str() );
  1406. };
  1407. it = cArr->find("uart_id");
  1408. if( it != cArr->end() ){
  1409. tVal->uart_id = atoi( it->second.c_str() );
  1410. };
  1411. };
  1412. };
  1413. };
  1414. deleteResult( result );
  1415. };
  1416. return tVal;
  1417. };
  1418. bool argusDBC::fillShadow2D( uint32_t ID, SHADOW & SH ){
  1419. if( m_bIsConnected ){
  1420. char tQBuf[CTEXT];
  1421. AAssoc *result;
  1422. 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 );
  1423. LOG(tQBuf);
  1424. result = m_pDatabase->Query( tQBuf );
  1425. if( result!= NULL ) {
  1426. if( result->size() > 0 ) {
  1427. SH.m_nEnabled = 0xFFFFFFFF;
  1428. SH.m_nPolygonCount = result->size();
  1429. SH.pPolygones = (SHADOW_POLY *) calloc( SH.m_nPolygonCount, sizeof( SHADOW_POLY ) );
  1430. if ( SH.pPolygones ) {
  1431. Assoc * cArr;
  1432. for ( uint8_t idx = 0; idx < result->size(); idx++ ) {
  1433. Assoc::iterator it;
  1434. cArr = result->at(idx);
  1435. it = cArr->find("id");
  1436. if( it != cArr->end() ){
  1437. SH.pPolygones[idx].m_nDBID = atoi(it->second.c_str());
  1438. };
  1439. it = cArr->find("layer");
  1440. if( it != cArr->end() ){
  1441. SH.pPolygones[idx].bType = atoi(it->second.c_str());
  1442. };
  1443. it = cArr->find("status");
  1444. if( it != cArr->end() ){
  1445. SH.m_nEnabled &= ( it->second.c_str()[0] == 'E' )?0xFFFFFFFF:~(1<<SH.pPolygones[idx].bType);
  1446. };
  1447. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", SH.pPolygones[idx].m_nDBID );
  1448. LOG(tQBuf);
  1449. AAssoc *v_result = m_pDatabase->Query( tQBuf );
  1450. if( v_result!= NULL ) {
  1451. if( v_result->size() > 0 ) {
  1452. SH.pPolygones[idx].wCount = v_result->size();
  1453. SH.pPolygones[idx].pPoint = (HZ_POINT *) calloc( SH.pPolygones[idx].wCount, sizeof( HZ_POINT ) );
  1454. if(SH.pPolygones[idx].pPoint ) {
  1455. for ( uint32_t zdx =0; zdx < SH.pPolygones[idx].wCount; zdx++ ) {
  1456. cArr = v_result->at(zdx);
  1457. it = cArr->find("x");
  1458. if( it != cArr->end() ){
  1459. SH.pPolygones[idx].pPoint[zdx].wX = atoi(it->second.c_str());
  1460. };
  1461. it = cArr->find("y");
  1462. if( it != cArr->end() ){
  1463. SH.pPolygones[idx].pPoint[zdx].wY = atoi(it->second.c_str());
  1464. };
  1465. LOG("Point Added!");
  1466. };
  1467. } else {
  1468. LOG("No mem for Points!");
  1469. };
  1470. } else {
  1471. LOG("No Points!");
  1472. SH.pPolygones[idx].wCount = 0;
  1473. SH.pPolygones[idx].pPoint = NULL;
  1474. };
  1475. deleteResult( v_result );
  1476. };
  1477. };
  1478. };
  1479. };
  1480. deleteResult( result );
  1481. };
  1482. return true;
  1483. };
  1484. return false;
  1485. };
  1486. DBC_SITE_DATA *argusDBC::getSiteData( uint32_t ID ){
  1487. DBC_SITE_DATA * tVal = NULL;
  1488. if(m_bIsConnected){
  1489. char tQBuf[CTEXT];
  1490. AAssoc *result;
  1491. sprintf(tQBuf, "SELECT * FROM sites WHERE `id`=%d", ID );
  1492. #ifdef DEBUG
  1493. LOG(tQBuf);
  1494. #endif
  1495. result = m_pDatabase->Query( tQBuf );
  1496. if( result!= NULL ) {
  1497. if( result->size() > 0 ) {
  1498. Assoc *cArr;
  1499. tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA));
  1500. if( tVal != NULL ) {
  1501. memset( tVal, 0 , sizeof(DBC_SITE_DATA));
  1502. Assoc::iterator it;
  1503. cArr = result->at(0);
  1504. it = cArr->find("account_id");
  1505. if( it != cArr->end() ){
  1506. tVal->account_id = atoi( it->second.c_str() );
  1507. };
  1508. it = cArr->find("name");
  1509. if( it != cArr->end() ){
  1510. sprintf( tVal->name, it->second.c_str() );
  1511. };
  1512. it = cArr->find("server_ident");
  1513. if( it != cArr->end() ){
  1514. sprintf( tVal->ident, it->second.c_str() );
  1515. };
  1516. it = cArr->find("anchor_lat");
  1517. if( it != cArr->end() ){
  1518. tVal->lat = atof( it->second.c_str() );
  1519. };
  1520. it = cArr->find("anchor_lon");
  1521. if( it != cArr->end() ){
  1522. tVal->lon = atof( it->second.c_str() );
  1523. };
  1524. it = cArr->find("anchor_alt");
  1525. if( it != cArr->end() ){
  1526. tVal->alt = atof( it->second.c_str() );
  1527. };
  1528. it = cArr->find("hemisphere");
  1529. if( it != cArr->end() ){
  1530. tVal->SH = ( it->second.c_str()[0] == 'S' );
  1531. };
  1532. it = cArr->find("map_id");
  1533. if( it != cArr->end() ){
  1534. tVal->map_id = atoi( it->second.c_str() );
  1535. };
  1536. it = cArr->find("local_binding");
  1537. if( it != cArr->end() ){
  1538. tVal->local_binding = (bool) atoi(it->second.c_str());
  1539. };
  1540. };
  1541. };
  1542. };
  1543. deleteResult( result );
  1544. };
  1545. return tVal;
  1546. };
  1547. DBC_TARGET_FLITER_DATA *argusDBC::getTargetFilterData( uint32_t ID ){
  1548. DBC_TARGET_FLITER_DATA * tVal = NULL;
  1549. if(m_bIsConnected){
  1550. char tQBuf[CTEXT];
  1551. AAssoc *result;
  1552. sprintf(tQBuf, "SELECT * FROM target_filters WHERE `id`=%d", ID );
  1553. #ifdef DEBUG
  1554. LOG(tQBuf);
  1555. #endif
  1556. result = m_pDatabase->Query( tQBuf );
  1557. if( result!= NULL ) {
  1558. if( result->size() > 0 ) {
  1559. Assoc *cArr;
  1560. tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA));
  1561. if( tVal != NULL ) {
  1562. memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA));
  1563. Assoc::iterator it;
  1564. tVal->id = ID;
  1565. cArr = result->at(0);
  1566. it = cArr->find("type");
  1567. if( it != cArr->end() ){
  1568. tVal->type = atoi( it->second.c_str() );
  1569. };
  1570. it = cArr->find("aux_id");
  1571. if( it != cArr->end() ){
  1572. tVal->aux_id = atoi( it->second.c_str() );
  1573. };
  1574. };
  1575. };
  1576. };
  1577. deleteResult( result );
  1578. };
  1579. return tVal;
  1580. };
  1581. DBC_LRF_DATA *argusDBC::getLRFData( uint32_t ID ){
  1582. DBC_LRF_DATA * tVal = NULL;
  1583. if(m_bIsConnected){
  1584. char tQBuf[CTEXT];
  1585. AAssoc *result;
  1586. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  1587. #ifdef DEBUG
  1588. LOG(tQBuf);
  1589. #endif
  1590. result = m_pDatabase->Query( tQBuf );
  1591. if( result!= NULL ) {
  1592. if( result->size() > 0 ) {
  1593. Assoc *cArr;
  1594. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  1595. if( tVal != NULL ) {
  1596. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  1597. Assoc::iterator it;
  1598. tVal->id = ID;
  1599. cArr = result->at(0);
  1600. it = cArr->find("data_status");
  1601. if( it != cArr->end() ){
  1602. tVal->data_status = atoi( it->second.c_str() );
  1603. };
  1604. it = cArr->find("serial");
  1605. if( it != cArr->end() ){
  1606. strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 );
  1607. tVal->serial[sizeof(tVal->serial)-1]=(char)0;
  1608. };
  1609. it = cArr->find("version");
  1610. if( it != cArr->end() ){
  1611. strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 );
  1612. tVal->version[sizeof(tVal->version)-1]=(char)0;
  1613. };
  1614. it = cArr->find("x");
  1615. if( it != cArr->end() ){
  1616. tVal->x = atof( it->second.c_str() );
  1617. };
  1618. it = cArr->find("y");
  1619. if( it != cArr->end() ){
  1620. tVal->y = atof( it->second.c_str() );
  1621. };
  1622. it = cArr->find("z");
  1623. if( it != cArr->end() ){
  1624. tVal->z = atof( it->second.c_str() );
  1625. };
  1626. it = cArr->find("x_rot");
  1627. if( it != cArr->end() ){
  1628. tVal->x_rot = atof( it->second.c_str() );
  1629. };
  1630. it = cArr->find("y_rot");
  1631. if( it != cArr->end() ){
  1632. tVal->y_rot = atof( it->second.c_str() );
  1633. };
  1634. it = cArr->find("z_rot");
  1635. if( it != cArr->end() ){
  1636. tVal->z_rot = atof( it->second.c_str() );
  1637. };
  1638. it = cArr->find("uart_id");
  1639. if( it != cArr->end() ){
  1640. tVal->uart_id = atoi( it->second.c_str() );
  1641. };
  1642. it = cArr->find("device_id");
  1643. if( it != cArr->end() ){
  1644. tVal->device_id = atoi( it->second.c_str() );
  1645. };
  1646. it = cArr->find("ip_address");
  1647. if( it != cArr->end() ){
  1648. sprintf( tVal->master_host, it->second.c_str() );
  1649. };
  1650. it = cArr->find("aux_ip_address");
  1651. if( it != cArr->end() ){
  1652. sprintf( tVal->slave_host, it->second.c_str() );
  1653. };
  1654. it = cArr->find("port");
  1655. if( it != cArr->end() ){
  1656. tVal->master_port = atoi( it->second.c_str() );
  1657. };
  1658. it = cArr->find("aux_port");
  1659. if( it != cArr->end() ){
  1660. tVal->slave_port = atoi( it->second.c_str() );
  1661. };
  1662. it = cArr->find("auto_draw");
  1663. if( it != cArr->end() ){
  1664. tVal->auto_draw = atoi( it->second.c_str() );
  1665. };
  1666. it = cArr->find("filter_id");
  1667. if( it != cArr->end() ){
  1668. tVal->filter_id = atoi( it->second.c_str() );
  1669. };
  1670. //it = cArr->find("enabled_lrf");
  1671. //if( it != cArr->end() ){
  1672. // tVal->enabled_lrf = atoi( it->second.c_str() );
  1673. //};
  1674. it = cArr->find("max_range");
  1675. if( it != cArr->end() ){
  1676. tVal->max_range = atof( it->second.c_str() );
  1677. };
  1678. it = cArr->find("base_shift");
  1679. if( it != cArr->end() ){
  1680. tVal->base_shift = atoi( it->second.c_str() );
  1681. };
  1682. it = cArr->find("mirror_shift");
  1683. if( it != cArr->end() ){
  1684. tVal->mirror_shift = atoi( it->second.c_str() );
  1685. };
  1686. it = cArr->find("detection_profile_id");
  1687. if( it != cArr->end() ){
  1688. tVal->detection_profile_id = atoi( it->second.c_str() );
  1689. };
  1690. it = cArr->find("draw_lrf_id");
  1691. if( it != cArr->end() ){
  1692. tVal->draw_lrf_id = atoi( it->second.c_str() );
  1693. };
  1694. it = cArr->find("width_table_id");
  1695. if( it != cArr->end() ){
  1696. tVal->width_table_id = atoi( it->second.c_str() );
  1697. };
  1698. it = cArr->find("zoom_table_id");
  1699. if( it != cArr->end() ){
  1700. tVal->zoom_table_id = atoi( it->second.c_str() );
  1701. };
  1702. it = cArr->find("embd_cam");
  1703. if( it != cArr->end() ){
  1704. tVal->embd_cam = atoi( it->second.c_str() );
  1705. };
  1706. it = cArr->find("embd_cam_auto");
  1707. if( it != cArr->end() ){
  1708. tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
  1709. };
  1710. it = cArr->find("embd_dc");
  1711. if( it != cArr->end() ){
  1712. tVal->embd_dc = atoi( it->second.c_str() );
  1713. };
  1714. it = cArr->find("autoreset");
  1715. if( it != cArr->end() ){
  1716. tVal->autoreset = (bool)atoi( it->second.c_str() );
  1717. };
  1718. it = cArr->find("force_settings");
  1719. if( it != cArr->end() ){
  1720. tVal->force_settings = (bool)atoi( it->second.c_str() );
  1721. };
  1722. };
  1723. };
  1724. };
  1725. deleteResult( result );
  1726. };
  1727. return tVal;
  1728. };
  1729. uint8_t argusDBC::getLRFDataStatus( uint32_t ID ){
  1730. uint8_t RetVal = 0;
  1731. if(m_bIsConnected){
  1732. char tQBuf[CTEXT];
  1733. AAssoc *result;
  1734. sprintf(tQBuf, "SELECT `data_status` FROM `lrf_sensors` WHERE `id`=%d", ID );
  1735. #ifdef DEBUG
  1736. LOG(tQBuf);
  1737. #endif
  1738. result = m_pDatabase->Query( tQBuf );
  1739. if( result!= NULL ) {
  1740. if( result->size() > 0 ) {
  1741. Assoc *cArr;
  1742. Assoc::iterator it;
  1743. cArr = result->at(0);
  1744. it = cArr->find("data_status");
  1745. if( it != cArr->end() ){
  1746. RetVal = atoi( it->second.c_str() );
  1747. };
  1748. };
  1749. };
  1750. deleteResult( result );
  1751. };
  1752. return RetVal;
  1753. };
  1754. PLGS_2D_PARAMETERS argusDBC::getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){
  1755. PLGS_2D_PARAMETERS retVal = NULL;
  1756. if(m_bIsConnected){
  1757. char tQBuf[CTEXT];
  1758. AAssoc *result;
  1759. sprintf(tQBuf, "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'%c'", lrfID, profileID,((master)?'1':'0') );
  1760. #ifdef DEBUG
  1761. LOG(tQBuf);
  1762. #endif
  1763. result = m_pDatabase->Query( tQBuf );
  1764. if( result!= NULL ) {
  1765. if( result->size() > 0 ) {
  1766. retVal = (PLGS_2D_PARAMETERS) malloc(sizeof(LGS_2D_PARAMETERS));
  1767. memset( retVal, 0, sizeof(LGS_2D_PARAMETERS));
  1768. Assoc *cArr;
  1769. Assoc::iterator it;
  1770. cArr = result->at(0);
  1771. it = cArr->find("order");
  1772. if( it != cArr->end() ){
  1773. retVal->nOrder = atoi(it->second.c_str());
  1774. };
  1775. it = cArr->find("offset");
  1776. if( it != cArr->end() ){
  1777. retVal->nOffset = atoi(it->second.c_str());
  1778. };
  1779. it = cArr->find("delta");
  1780. if( it != cArr->end() ){
  1781. retVal->nDelta = atoi(it->second.c_str());
  1782. };
  1783. it = cArr->find("flip");
  1784. if( it != cArr->end() ){
  1785. retVal->nFlip = atoi(it->second.c_str());
  1786. };
  1787. it = cArr->find("width");
  1788. if( it != cArr->end() ){
  1789. retVal->nWidth = atoi(it->second.c_str());
  1790. };
  1791. it = cArr->find("sst");
  1792. if( it != cArr->end() ){
  1793. retVal->bSST = atoi(it->second.c_str());
  1794. };
  1795. it = cArr->find("sun");
  1796. if( it != cArr->end() ){
  1797. retVal->nSun = atoi(it->second.c_str());
  1798. };
  1799. };
  1800. };
  1801. deleteResult( result );
  1802. };
  1803. return retVal;
  1804. };
  1805. CSTR argusDBC::getLRFDraw( uint32_t DBID ){
  1806. CSTR RetVal = NULL;
  1807. if(m_bIsConnected){
  1808. char tQBuf[CTEXT];
  1809. AAssoc *result;
  1810. sprintf(tQBuf, "SELECT `md5` FROM `lrf_draw` WHERE `node_id`=%d", DBID );
  1811. #ifdef DEBUG
  1812. LOG(tQBuf);
  1813. #endif
  1814. result = m_pDatabase->Query( tQBuf );
  1815. if( result!= NULL ) {
  1816. if( result->size() > 0 ) {
  1817. Assoc *cArr;
  1818. Assoc::iterator it;
  1819. cArr = result->at(0);
  1820. it = cArr->find("md5");
  1821. if( it != cArr->end() ){
  1822. RetVal = strdup( it->second.c_str() );
  1823. };
  1824. };
  1825. };
  1826. deleteResult( result );
  1827. };
  1828. return RetVal;
  1829. };
  1830. uint32_t argusDBC::getLRFMaskID( uint32_t deviceID, uint8_t lrfID, uint8_t layer ){
  1831. uint32_t RetVal = 0;
  1832. if(m_bIsConnected){
  1833. char tQBuf[CTEXT];
  1834. AAssoc *result;
  1835. sprintf(tQBuf, "SELECT `id` FROM `lrf_masks` WHERE `sensor_id`=%d AND `lrf_id`=%d AND `layer`=%d ", deviceID, lrfID, layer );
  1836. #ifdef DEBUG
  1837. LOG(tQBuf);
  1838. #endif
  1839. result = m_pDatabase->Query( tQBuf );
  1840. if( result!= NULL ) {
  1841. if( result->size() > 0 ) {
  1842. Assoc *cArr;
  1843. Assoc::iterator it;
  1844. cArr = result->at(0);
  1845. it = cArr->find("id");
  1846. if( it != cArr->end() ){
  1847. RetVal = atoi( it->second.c_str() );
  1848. };
  1849. };
  1850. };
  1851. deleteResult( result );
  1852. };
  1853. return RetVal;
  1854. };
  1855. /*
  1856. DBC_PUSHED_CMD *argusDBC::getLRFPushedCMD( uint32_t ID ){
  1857. DBC_PUSHED_CMD *RetVal = NULL;
  1858. if(m_bIsConnected){
  1859. char tQBuf[CTEXT];
  1860. AAssoc *result;
  1861. sprintf(tQBuf, "SELECT `pushed_cmd`, `pushed_param` FROM `lrf_sensors` WHERE `id`=%d AND `pushed_cmd` > 0", ID );
  1862. #ifdef DEBUG
  1863. //LOG(tQBuf);
  1864. #endif
  1865. result = m_pDatabase->Query( tQBuf );
  1866. if( result!= NULL ) {
  1867. if( result->size() > 0 ) {
  1868. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  1869. if( RetVal ) {
  1870. Assoc *cArr;
  1871. Assoc::iterator it;
  1872. cArr = result->at(0);
  1873. it = cArr->find("pushed_cmd");
  1874. if( it != cArr->end() ){
  1875. RetVal->CMD = atoi( it->second.c_str() );
  1876. };
  1877. it = cArr->find("pushed_param");
  1878. if( it != cArr->end() ){
  1879. RetVal->PARAM = atoi( it->second.c_str() );
  1880. };
  1881. };
  1882. };
  1883. //Only If Result is Fetched - Clear Current CMD
  1884. sprintf(tQBuf, "UPDATE `lrf_sensors` SET `pushed_cmd`=0, `pushed_param`=0 WHERE `id`=%d", ID );
  1885. m_pDatabase->SilentQuery( tQBuf );
  1886. };
  1887. deleteResult( result );
  1888. };
  1889. return RetVal;
  1890. };
  1891. */
  1892. DBC_INT_LIST *argusDBC::listModules( uint32_t ServerID ){
  1893. DBC_INT_LIST * tVal = NULL;
  1894. if(m_bIsConnected){
  1895. char tQBuf[CTEXT];
  1896. AAssoc *result;
  1897. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1898. #ifdef DEBUG
  1899. //LOG(tQBuf);
  1900. #endif
  1901. result = m_pDatabase->Query( tQBuf );
  1902. if( result!= NULL ) {
  1903. if( result->size() > 0 ) {
  1904. Assoc *cArr;
  1905. tVal = new DBC_INT_LIST();
  1906. if( tVal != NULL ) {
  1907. Assoc::iterator it;
  1908. for(int i=0;i<result->size();i++) {
  1909. cArr = result->at(i);
  1910. it = cArr->find("id");
  1911. if( it != cArr->end() ){
  1912. tVal->push_back( atoi( it->second.c_str() ));
  1913. };
  1914. };
  1915. };
  1916. };
  1917. };
  1918. deleteResult( result );
  1919. };
  1920. return tVal;
  1921. };
  1922. DBC_INT_LIST *argusDBC::listFilters( uint32_t ServerID ){
  1923. DBC_INT_LIST * tVal = NULL;
  1924. if(m_bIsConnected){
  1925. char tQBuf[CTEXT];
  1926. AAssoc *result;
  1927. sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1928. #ifdef DEBUG_ALL
  1929. LOG(tQBuf);
  1930. #endif
  1931. result = m_pDatabase->Query( tQBuf );
  1932. if( result!= NULL ) {
  1933. if( result->size() > 0 ) {
  1934. Assoc *cArr;
  1935. tVal = new DBC_INT_LIST();
  1936. if( tVal != NULL ) {
  1937. Assoc::iterator it;
  1938. for(int i=0;i<result->size();i++) {
  1939. cArr = result->at(i);
  1940. it = cArr->find("id");
  1941. if( it != cArr->end() ){
  1942. tVal->push_back( atoi( it->second.c_str() ));
  1943. };
  1944. };
  1945. };
  1946. };
  1947. };
  1948. deleteResult( result );
  1949. };
  1950. return tVal;
  1951. };
  1952. DBC_INT_LIST *argusDBC::listLRFMaskVertexes( uint32_t MaskID ){
  1953. DBC_INT_LIST * tVal = NULL;
  1954. if(m_bIsConnected){
  1955. char tQBuf[CTEXT];
  1956. AAssoc *result;
  1957. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", MaskID );
  1958. #ifdef DEBUG_ALL
  1959. LOG(tQBuf);
  1960. #endif
  1961. result = m_pDatabase->Query( tQBuf );
  1962. if( result!= NULL ) {
  1963. if( result->size() > 0 ) {
  1964. Assoc *cArr;
  1965. tVal = new DBC_INT_LIST();
  1966. if( tVal != NULL ) {
  1967. Assoc::iterator it;
  1968. for(int i=0;i<result->size();i++) {
  1969. cArr = result->at(i);
  1970. it = cArr->find("id");
  1971. if( it != cArr->end() ){
  1972. tVal->push_back( atoi( it->second.c_str() ));
  1973. };
  1974. };
  1975. };
  1976. };
  1977. };
  1978. deleteResult( result );
  1979. };
  1980. return tVal;
  1981. };
  1982. DBC_INT_LIST *argusDBC::listLRFMaskVertexPoints( uint32_t VertexID ){
  1983. DBC_INT_LIST * tVal = NULL;
  1984. if(m_bIsConnected){
  1985. char tQBuf[CTEXT];
  1986. AAssoc *result;
  1987. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", VertexID );
  1988. #ifdef DEBUG_ALL
  1989. LOG(tQBuf);
  1990. #endif
  1991. result = m_pDatabase->Query( tQBuf );
  1992. if( result!= NULL ) {
  1993. if( result->size() > 0 ) {
  1994. Assoc *cArr;
  1995. tVal = new DBC_INT_LIST();
  1996. if( tVal != NULL ) {
  1997. Assoc::iterator it;
  1998. for(int i=0;i<result->size();i++) {
  1999. cArr = result->at(i);
  2000. it = cArr->find("id");
  2001. if( it != cArr->end() ){
  2002. tVal->push_back( atoi( it->second.c_str() ));
  2003. };
  2004. };
  2005. };
  2006. };
  2007. };
  2008. deleteResult( result );
  2009. };
  2010. return tVal;
  2011. };
  2012. DBC_INT_LIST *argusDBC::listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){
  2013. DBC_INT_LIST * tVal = NULL;
  2014. if(m_bIsConnected){
  2015. char tQBuf[CTEXT];
  2016. AAssoc *result;
  2017. switch( listMode ){
  2018. 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;
  2019. 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;
  2020. default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
  2021. };
  2022. #ifdef DEBUG_ALL
  2023. LOG(tQBuf);
  2024. #endif
  2025. result = m_pDatabase->Query( tQBuf );
  2026. if( result!= NULL ) {
  2027. if( result->size() > 0 ) {
  2028. Assoc *cArr;
  2029. tVal = new DBC_INT_LIST();
  2030. if( tVal != NULL ) {
  2031. Assoc::iterator it;
  2032. for(int i=0;i<result->size();i++) {
  2033. cArr = result->at(i);
  2034. it = cArr->find("id");
  2035. if( it != cArr->end() ){
  2036. tVal->push_back( atoi( it->second.c_str() ));
  2037. };
  2038. };
  2039. };
  2040. };
  2041. };
  2042. deleteResult( result );
  2043. };
  2044. return tVal;
  2045. };
  2046. DBC_INT_LIST *argusDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){
  2047. DBC_INT_LIST * tVal = NULL;
  2048. if(m_bIsConnected){
  2049. char tQBuf[CTEXT];
  2050. AAssoc *result;
  2051. switch( listMode ){
  2052. case LIST_VALID_RECORDS:
  2053. 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 );
  2054. break;
  2055. case LIST_INVALID_RECORDS:
  2056. 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 );
  2057. break;
  2058. default:
  2059. 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 );
  2060. };
  2061. #ifdef DEBUG_ALL
  2062. LOG(tQBuf);
  2063. #endif
  2064. result = m_pDatabase->Query( tQBuf );
  2065. if( result!= NULL ) {
  2066. if( result->size() > 0 ) {
  2067. Assoc *cArr;
  2068. tVal = new DBC_INT_LIST();
  2069. if( tVal != NULL ) {
  2070. Assoc::iterator it;
  2071. for(int i=0;i<result->size();i++) {
  2072. cArr = result->at(i);
  2073. it = cArr->find("id");
  2074. if( it != cArr->end() ){
  2075. tVal->push_back( atoi( it->second.c_str() ));
  2076. };
  2077. };
  2078. };
  2079. };
  2080. };
  2081. deleteResult( result );
  2082. };
  2083. return tVal;
  2084. };
  2085. DBC_INT_LIST *argusDBC::listDetectionProfileIDs( uint32_t nodeID ){
  2086. DBC_INT_LIST * tVal = NULL;
  2087. if(m_bIsConnected){
  2088. char tQBuf[CTEXT];
  2089. AAssoc *result;
  2090. sprintf(tQBuf, "SELECT `profile_id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  2091. #ifdef DEBUG_ALL
  2092. LOG(tQBuf);
  2093. #endif
  2094. result = m_pDatabase->Query( tQBuf );
  2095. if( result!= NULL ) {
  2096. if( result->size() > 0 ) {
  2097. Assoc *cArr;
  2098. tVal = new DBC_INT_LIST();
  2099. if( tVal != NULL ) {
  2100. Assoc::iterator it;
  2101. for(int i=0;i<result->size();i++) {
  2102. cArr = result->at(i);
  2103. it = cArr->find("profile_id");
  2104. if( it != cArr->end() ){
  2105. tVal->push_back( atoi( it->second.c_str() ));
  2106. };
  2107. };
  2108. };
  2109. };
  2110. };
  2111. deleteResult( result );
  2112. };
  2113. return tVal;
  2114. };
  2115. DBC_INT_LIST *argusDBC::listDetectionProfiles( uint32_t nodeID ){
  2116. DBC_INT_LIST * tVal = NULL;
  2117. if(m_bIsConnected){
  2118. char tQBuf[CTEXT];
  2119. AAssoc *result;
  2120. sprintf(tQBuf, "SELECT `id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  2121. #ifdef DEBUG_ALL
  2122. LOG(tQBuf);
  2123. #endif
  2124. result = m_pDatabase->Query( tQBuf );
  2125. if( result!= NULL ) {
  2126. if( result->size() > 0 ) {
  2127. Assoc *cArr;
  2128. tVal = new DBC_INT_LIST();
  2129. if( tVal != NULL ) {
  2130. Assoc::iterator it;
  2131. for(int i=0;i<result->size();i++) {
  2132. cArr = result->at(i);
  2133. it = cArr->find("id");
  2134. if( it != cArr->end() ){
  2135. tVal->push_back( atoi( it->second.c_str() ));
  2136. };
  2137. };
  2138. };
  2139. };
  2140. };
  2141. deleteResult( result );
  2142. };
  2143. return tVal;
  2144. };
  2145. /*
  2146. DBC_INT_LIST *argusDBC::listSockets( uint32_t NodeID ){
  2147. DBC_INT_LIST * tVal = NULL;
  2148. if(m_bIsConnected){
  2149. char tQBuf[CTEXT];
  2150. AAssoc *result;
  2151. sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );
  2152. #ifdef DEBUG
  2153. LOG(tQBuf);
  2154. #endif
  2155. result = m_pDatabase->Query( tQBuf );
  2156. if( result!= NULL ) {
  2157. if( result->size() > 0 ) {
  2158. Assoc *cArr;
  2159. tVal = new DBC_INT_LIST();
  2160. if( tVal != NULL ) {
  2161. Assoc::iterator it;
  2162. for(int i=0;i<result->size();i++) {
  2163. cArr = result->at(i);
  2164. it = cArr->find("id");
  2165. if( it != cArr->end() ){
  2166. tVal->push_back( atoi( it->second.c_str() ));
  2167. };
  2168. };
  2169. };
  2170. };
  2171. };
  2172. deleteResult( result );
  2173. };
  2174. return tVal;
  2175. };
  2176. */
  2177. DBC_INT_LIST *argusDBC::listResources( uint32_t NodeID ){
  2178. DBC_INT_LIST * tVal = NULL;
  2179. if(m_bIsConnected){
  2180. char tQBuf[CTEXT];
  2181. AAssoc *result;
  2182. if( NodeID ) {
  2183. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d AND `active`=1 AND `used`=1", NodeID );
  2184. } else {
  2185. 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 );
  2186. };
  2187. #ifdef DEBUG
  2188. LOG(tQBuf);
  2189. #endif
  2190. result = m_pDatabase->Query( tQBuf );
  2191. if( result!= NULL ) {
  2192. if( result->size() > 0 ) {
  2193. Assoc *cArr;
  2194. tVal = new DBC_INT_LIST();
  2195. if( tVal != NULL ) {
  2196. Assoc::iterator it;
  2197. for(int i=0;i<result->size();i++) {
  2198. cArr = result->at(i);
  2199. it = cArr->find("id");
  2200. if( it != cArr->end() ){
  2201. tVal->push_back( atoi( it->second.c_str() ));
  2202. };
  2203. };
  2204. };
  2205. };
  2206. };
  2207. deleteResult( result );
  2208. };
  2209. return tVal;
  2210. };
  2211. simplePolygone *argusDBC::loadLRFMaskVertex( uint32_t vid ){
  2212. simplePolygone *tVal = NULL;
  2213. if(m_bIsConnected){
  2214. char tQBuf[CTEXT];
  2215. AAssoc *result;
  2216. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertexes` WHERE `id`=%d", vid );
  2217. #ifdef DEBUG
  2218. LOG(tQBuf);
  2219. #endif
  2220. result = m_pDatabase->Query( tQBuf );
  2221. if( result!= NULL ) {
  2222. if( result->size() > 0 ) {
  2223. tVal = (simplePolygone *) malloc(sizeof(simplePolygone));
  2224. if ( tVal ) {
  2225. Assoc * cArr;
  2226. memset( tVal, 0, sizeof(simplePolygone));
  2227. Assoc::iterator it;
  2228. cArr = result->at(0);
  2229. it = cArr->find("r");
  2230. if( it != cArr->end() ){
  2231. tVal->color[0] = atoi( it->second.c_str() );
  2232. };
  2233. it = cArr->find("g");
  2234. if( it != cArr->end() ){
  2235. tVal->color[1] = atoi( it->second.c_str() );
  2236. };
  2237. it = cArr->find("b");
  2238. if( it != cArr->end() ){
  2239. tVal->color[2] = atoi( it->second.c_str() );
  2240. };
  2241. AAssoc *points;
  2242. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", vid );
  2243. #ifdef DEBUG
  2244. LOG(tQBuf);
  2245. #endif
  2246. points = m_pDatabase->Query( tQBuf );
  2247. if( points!= NULL ) {
  2248. if ( points->size() ) {
  2249. tVal->count = points->size();
  2250. tVal->points = (simplePoint *) calloc( points->size(), sizeof(simplePoint) );
  2251. if( tVal->points!= NULL ) {
  2252. for (int i = 0; i < points->size(); i++) {
  2253. cArr = points->at( i );
  2254. it = cArr->find("x");
  2255. if( it != cArr->end() ){
  2256. tVal->points[i].setX( atoi( it->second.c_str() ) );
  2257. };
  2258. it = cArr->find("y");
  2259. if( it != cArr->end() ){
  2260. tVal->points[i].setY( atoi( it->second.c_str() ) );
  2261. };
  2262. };
  2263. };
  2264. };
  2265. };
  2266. deleteResult( points );
  2267. };
  2268. };
  2269. };
  2270. deleteResult( result );
  2271. };
  2272. return tVal;
  2273. };
  2274. DBC_INT_LIST *argusDBC::listNetworks( uint32_t nif_id ){
  2275. DBC_INT_LIST * tVal = NULL;
  2276. if(m_bIsConnected){
  2277. char tQBuf[CTEXT];
  2278. AAssoc *result;
  2279. sprintf(tQBuf, "SELECT `id` FROM `networks` WHERE `nif_id`=%d", nif_id );
  2280. #ifdef DEBUG_ALL
  2281. LOG(tQBuf);
  2282. #endif
  2283. result = m_pDatabase->Query( tQBuf );
  2284. if( result!= NULL ) {
  2285. if( result->size() > 0 ) {
  2286. Assoc *cArr;
  2287. tVal = new DBC_INT_LIST();
  2288. if( tVal != NULL ) {
  2289. Assoc::iterator it;
  2290. for(int i=0;i<result->size();i++) {
  2291. cArr = result->at(i);
  2292. it = cArr->find("id");
  2293. if( it != cArr->end() ){
  2294. tVal->push_back( atoi( it->second.c_str() ));
  2295. };
  2296. };
  2297. };
  2298. };
  2299. };
  2300. deleteResult( result );
  2301. };
  2302. return tVal;
  2303. };
  2304. DBC_INT_LIST *argusDBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ){
  2305. DBC_INT_LIST * tVal = NULL;
  2306. char tParam[CTEXT];
  2307. //memset( tParam, 0, CTEXT );
  2308. sprintf(tParam,"0");
  2309. if( old_ids != NULL ) {
  2310. char tBuffer[CTEXT];
  2311. for(int i = 0; i< old_ids->size(); i++ ) {
  2312. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  2313. strncpy( tParam, tBuffer, CTEXT );
  2314. };
  2315. };
  2316. if(m_bIsConnected){
  2317. char tQBuf[CTEXT];
  2318. AAssoc *result;
  2319. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", ServerID, tParam );
  2320. #ifdef DEBUG_ALL
  2321. LOG(tQBuf);
  2322. #endif
  2323. result = m_pDatabase->Query( tQBuf );
  2324. if( result!= NULL ) {
  2325. if( result->size() > 0 ) {
  2326. Assoc *cArr;
  2327. tVal = new DBC_INT_LIST();
  2328. if( tVal != NULL ) {
  2329. Assoc::iterator it;
  2330. for(int i=0;i<result->size();i++) {
  2331. cArr = result->at(i);
  2332. it = cArr->find("id");
  2333. if( it != cArr->end() ){
  2334. tVal->push_back( atoi( it->second.c_str() ));
  2335. };
  2336. };
  2337. };
  2338. };
  2339. };
  2340. deleteResult( result );
  2341. };
  2342. return tVal;
  2343. };
  2344. uint32_t argusDBC::getCamId( CSTR UUID ){
  2345. uint32_t RetVal = 0;
  2346. if(m_bIsConnected){
  2347. char tQBuf[CTEXT];
  2348. AAssoc *result;
  2349. sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
  2350. #ifdef DEBUG_ALL
  2351. LOG(tQBuf);
  2352. #endif
  2353. result = m_pDatabase->Query( tQBuf );
  2354. if( result!= NULL ) {
  2355. if( result->size() > 0 ) {
  2356. Assoc *cArr;
  2357. Assoc::iterator it;
  2358. cArr = result->at(0);
  2359. it = cArr->find("id");
  2360. if( it != cArr->end() ){
  2361. RetVal = atoi( it->second.c_str() );
  2362. };
  2363. };
  2364. };
  2365. deleteResult( result );
  2366. };
  2367. return RetVal;
  2368. };
  2369. DBC_CAP_DATA *argusDBC::getCamCapPictureData( uint32_t PicID ){
  2370. DBC_CAP_DATA *tVal = NULL;
  2371. if(m_bIsConnected){
  2372. char tQBuf[CTEXT];
  2373. AAssoc *result;
  2374. sprintf(tQBuf, "SELECT md5, ext FROM pictures WHERE `id`=%d", PicID );
  2375. #ifdef DEBUG_ALL
  2376. LOG(tQBuf);
  2377. #endif
  2378. result = m_pDatabase->Query( tQBuf );
  2379. if( result!= NULL ) {
  2380. if( result->size() > 0 ) {
  2381. Assoc *cArr;
  2382. tVal = (DBC_CAP_DATA*) malloc(sizeof(DBC_CAP_DATA));
  2383. if( tVal != NULL ) {
  2384. memset( tVal, 0 , sizeof(DBC_CAP_DATA));
  2385. Assoc::iterator it;
  2386. cArr = result->at(0);
  2387. it = cArr->find("md5");
  2388. if( it != cArr->end() ){
  2389. strncpy(tVal->md5, it->second.c_str(), 32);
  2390. };
  2391. it = cArr->find("ext");
  2392. if( it != cArr->end() ){
  2393. strncpy(tVal->ext, it->second.c_str(), 3 );
  2394. };
  2395. };
  2396. };
  2397. };
  2398. deleteResult( result );
  2399. };
  2400. return tVal;
  2401. };
  2402. DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
  2403. DBC_CAM_DATA *tVal = NULL;
  2404. if(m_bIsConnected){
  2405. char tQBuf[CTEXT];
  2406. AAssoc *result;
  2407. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  2408. #ifdef DEBUG_ALL
  2409. LOG(tQBuf);
  2410. #endif
  2411. result = m_pDatabase->Query( tQBuf );
  2412. if( result!= NULL ) {
  2413. if( result->size() > 0 ) {
  2414. Assoc *cArr;
  2415. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  2416. if( tVal != NULL ) {
  2417. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  2418. tVal->id = ID;
  2419. Assoc::iterator it;
  2420. cArr = result->at(0);
  2421. it = cArr->find("site_id");
  2422. if( it != cArr->end() ){
  2423. tVal->site_id = atoi( it->second.c_str() );
  2424. };
  2425. it = cArr->find("node_id");
  2426. if( it != cArr->end() ){
  2427. tVal->node_id = atoi( it->second.c_str() );
  2428. };
  2429. it = cArr->find("online");
  2430. if( it != cArr->end() ){
  2431. tVal->online = (bool) atoi( it->second.c_str() );
  2432. };
  2433. it = cArr->find("type");
  2434. if( it != cArr->end() ){
  2435. tVal->type = atoi( it->second.c_str() );
  2436. };
  2437. it = cArr->find("name");
  2438. if( it != cArr->end() ){
  2439. strncpy( tVal->name, it->second.c_str(), 64 );
  2440. };
  2441. it = cArr->find("hardware");
  2442. if( it != cArr->end() ){
  2443. strncpy( tVal->hardware, it->second.c_str(), 32 );
  2444. };
  2445. it = cArr->find("status");
  2446. if( it != cArr->end() ){
  2447. tVal->status = atoi( it->second.c_str() );
  2448. };
  2449. it = cArr->find("session");
  2450. if( it != cArr->end() ){
  2451. strncpy( tVal->session, it->second.c_str(), 32 );
  2452. };
  2453. it = cArr->find("protocol");
  2454. if( it != cArr->end() ){
  2455. tVal->protocol = atoi( it->second.c_str() );
  2456. };
  2457. it = cArr->find("protocol_aux");
  2458. if( it != cArr->end() ){
  2459. tVal->protocol_aux = atoi( it->second.c_str() );
  2460. };
  2461. it = cArr->find("uart_id");
  2462. if( it != cArr->end() ){
  2463. tVal->uart_id = atoi( it->second.c_str() );
  2464. };
  2465. it = cArr->find("x");
  2466. if( it != cArr->end() ){
  2467. tVal->x = atof( it->second.c_str() );
  2468. };
  2469. it = cArr->find("y");
  2470. if( it != cArr->end() ){
  2471. tVal->y = atof( it->second.c_str() );
  2472. };
  2473. it = cArr->find("z");
  2474. if( it != cArr->end() ){
  2475. tVal->z = atof( it->second.c_str() );
  2476. };
  2477. it = cArr->find("x_rot");
  2478. if( it != cArr->end() ){
  2479. tVal->x_rot = atof( it->second.c_str() );
  2480. };
  2481. it = cArr->find("y_rot");
  2482. if( it != cArr->end() ){
  2483. tVal->y_rot = atof( it->second.c_str() );
  2484. };
  2485. it = cArr->find("z_rot");
  2486. if( it != cArr->end() ){
  2487. tVal->z_rot = atof( it->second.c_str() );
  2488. };
  2489. it = cArr->find("imager_type");
  2490. if( it != cArr->end() ){
  2491. tVal->imager_type = atoi( it->second.c_str() );
  2492. };
  2493. it = cArr->find("lens_f");
  2494. if( it != cArr->end() ){
  2495. tVal->lens_f = atoi( it->second.c_str() );
  2496. };
  2497. it = cArr->find("ptz_speed_step");
  2498. if( it != cArr->end() ){
  2499. tVal->ptz_speed_step = atof( it->second.c_str() );
  2500. };
  2501. it = cArr->find("pan_model");
  2502. if( it != cArr->end() ){
  2503. tVal->pan_model = atoi( it->second.c_str() );
  2504. };
  2505. it = cArr->find("pan_angles");
  2506. if( it != cArr->end() ){
  2507. tVal->pan_angles = atoi( it->second.c_str() );
  2508. };
  2509. it = cArr->find("tilt_model");
  2510. if( it != cArr->end() ){
  2511. tVal->tilt_model = atoi( it->second.c_str() );
  2512. };
  2513. it = cArr->find("tilt_angles");
  2514. if( it != cArr->end() ){
  2515. tVal->tilt_angles = atoi( it->second.c_str() );
  2516. };
  2517. it = cArr->find("zoom_model");
  2518. if( it != cArr->end() ){
  2519. tVal->zoom_model = atoi( it->second.c_str() );
  2520. };
  2521. it = cArr->find("zoom");
  2522. if( it != cArr->end() ){
  2523. tVal->zoom = atof( it->second.c_str() );
  2524. };
  2525. //it = cArr->find("max_range");
  2526. //if( it != cArr->end() ){
  2527. // tVal->max_range = atof( it->second.c_str() );
  2528. //};
  2529. it = cArr->find("access_login");
  2530. if( it != cArr->end() ){
  2531. strncpy( tVal->username, it->second.c_str(), 16 );
  2532. };
  2533. it = cArr->find("access_pass");
  2534. if( it != cArr->end() ){
  2535. strncpy( tVal->password, it->second.c_str(), 16 );
  2536. };
  2537. it = cArr->find("uuid");
  2538. if( it != cArr->end() ){
  2539. strncpy( tVal->uuid, it->second.c_str(), 64 );
  2540. };
  2541. it = cArr->find("mac");
  2542. if( it != cArr->end() ){
  2543. strncpy( tVal->mac, it->second.c_str(), 16 );
  2544. };
  2545. it = cArr->find("ip");
  2546. if( it != cArr->end() ){
  2547. strncpy( tVal->ip, it->second.c_str(), 16 );
  2548. };
  2549. it = cArr->find("port");
  2550. if( it != cArr->end() ){
  2551. tVal->port = atoi( it->second.c_str() );
  2552. };
  2553. it = cArr->find("onvif_access");
  2554. if( it != cArr->end() ){
  2555. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  2556. };
  2557. it = cArr->find("onvif_ctrl");
  2558. if( it != cArr->end() ){
  2559. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  2560. };
  2561. it = cArr->find("ptz_token");
  2562. if( it != cArr->end() ){
  2563. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  2564. };
  2565. it = cArr->find("trigger_mode");
  2566. if( it != cArr->end() ){
  2567. tVal->triggering_mode = atoi( it->second.c_str() );
  2568. };
  2569. it = cArr->find("auth_mode");
  2570. if( it != cArr->end() ){
  2571. tVal->auth_mode = atoi( it->second.c_str() );
  2572. };
  2573. };
  2574. };
  2575. };
  2576. deleteResult( result );
  2577. };
  2578. return tVal;
  2579. };
  2580. DBC_PUSHED_CMD *argusDBC::getActivePushedCMD( uint32_t NodeID ){
  2581. DBC_PUSHED_CMD *RetVal = NULL;
  2582. if(m_bIsConnected){
  2583. char tQBuf[CTEXT];
  2584. AAssoc *result;
  2585. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status` > 0 AND `status` < 100", NodeID );
  2586. #ifdef DEBUG_ALL
  2587. LOG(tQBuf);
  2588. #endif
  2589. result = m_pDatabase->Query( tQBuf );
  2590. if( result!= NULL ) {
  2591. if( result->size() > 0 ) {
  2592. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2593. if( RetVal ) {
  2594. Assoc * cArr;
  2595. Assoc::iterator it;
  2596. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2597. cArr = result->at(0);
  2598. it = cArr->find("id");
  2599. if( it != cArr->end() ){
  2600. RetVal->id = atoi( it->second.c_str() );
  2601. };
  2602. it = cArr->find("cmd");
  2603. if( it != cArr->end() ){
  2604. RetVal->CMD = atoi( it->second.c_str() );
  2605. };
  2606. it = cArr->find("parameter");
  2607. if( it != cArr->end() ){
  2608. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2609. RetVal->PARAM[255] = (char)0;
  2610. };
  2611. };
  2612. };
  2613. };
  2614. deleteResult( result );
  2615. };
  2616. return RetVal;
  2617. };
  2618. DBC_PUSHED_CMD *argusDBC::getPushedCMD( uint32_t CmdID ){
  2619. DBC_PUSHED_CMD *RetVal = NULL;
  2620. if(m_bIsConnected){
  2621. char tQBuf[CTEXT];
  2622. AAssoc *result;
  2623. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `id`=%d", CmdID );
  2624. #ifdef DEBUG_ALL
  2625. LOG(tQBuf);
  2626. #endif
  2627. result = m_pDatabase->Query( tQBuf );
  2628. if( result!= NULL ) {
  2629. if( result->size() > 0 ) {
  2630. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2631. if( RetVal ) {
  2632. Assoc * cArr;
  2633. Assoc::iterator it;
  2634. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2635. cArr = result->at(0);
  2636. it = cArr->find("id");
  2637. if( it != cArr->end() ){
  2638. RetVal->id = atoi( it->second.c_str() );
  2639. };
  2640. it = cArr->find("cmd");
  2641. if( it != cArr->end() ){
  2642. RetVal->CMD = atoi( it->second.c_str() );
  2643. };
  2644. it = cArr->find("parameter");
  2645. if( it != cArr->end() ){
  2646. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2647. RetVal->PARAM[255] = (char)0;
  2648. };
  2649. };
  2650. };
  2651. };
  2652. deleteResult( result );
  2653. };
  2654. return RetVal;
  2655. };
  2656. DBC_PUSHED_CMD *argusDBC::getNodePushedCMD( uint32_t NodeID ){
  2657. DBC_PUSHED_CMD *RetVal = NULL;
  2658. if(m_bIsConnected){
  2659. char tQBuf[CTEXT];
  2660. AAssoc *result;
  2661. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 LIMIT 1", NodeID );
  2662. #ifdef DEBUG_ALL
  2663. LOG(tQBuf);
  2664. #endif
  2665. result = m_pDatabase->Query( tQBuf );
  2666. if( result!= NULL ) {
  2667. if( result->size() > 0 ) {
  2668. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2669. if( RetVal ) {
  2670. Assoc * cArr;
  2671. Assoc::iterator it;
  2672. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2673. cArr = result->at(0);
  2674. it = cArr->find("id");
  2675. if( it != cArr->end() ){
  2676. RetVal->id = atoi( it->second.c_str() );
  2677. };
  2678. it = cArr->find("cmd");
  2679. if( it != cArr->end() ){
  2680. RetVal->CMD = atoi( it->second.c_str() );
  2681. };
  2682. it = cArr->find("parameter");
  2683. if( it != cArr->end() ){
  2684. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2685. RetVal->PARAM[255] = (char)0;
  2686. };
  2687. //Only If Result is Fetched - Clear Current CMD
  2688. //sprintf(tQBuf, "DELETE FROM `nodes_qcq` WHERE `id`=%d", RetVal->id );
  2689. //m_pDatabase->SilentQuery( tQBuf );
  2690. };
  2691. };
  2692. };
  2693. deleteResult( result );
  2694. };
  2695. return RetVal;
  2696. };
  2697. bool argusDBC::updateNodePushedCMD( uint32_t CmdID, uint8_t status ){
  2698. if(m_bIsConnected){
  2699. char tQBuf[CTEXT];
  2700. sprintf(tQBuf, "UPDATE `nodes_qcq` SET `status`=%d WHERE `id`=%d ", status, CmdID );
  2701. #ifdef DEBUG_ALL
  2702. LOG(tQBuf);
  2703. #endif
  2704. m_pDatabase->SilentQuery( tQBuf );
  2705. return true;
  2706. };
  2707. return false;
  2708. };
  2709. DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){
  2710. DBC_MODULE_DATA *tVal = NULL;
  2711. if(m_bIsConnected){
  2712. char tQBuf[CTEXT];
  2713. AAssoc *result;
  2714. sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
  2715. #ifdef DEBUG_ALL
  2716. LOG(tQBuf);
  2717. #endif
  2718. result = m_pDatabase->Query( tQBuf );
  2719. if( result!= NULL ) {
  2720. if( result->size() > 0 ) {
  2721. Assoc *cArr;
  2722. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  2723. if( tVal != NULL ) {
  2724. Assoc::iterator it;
  2725. cArr = result->at(0);
  2726. it = cArr->find("id");
  2727. if( it != cArr->end() ){
  2728. tVal->module_id = atoi( it->second.c_str() );
  2729. };
  2730. it = cArr->find("aux_id");
  2731. if( it != cArr->end() ){
  2732. tVal->aux_id = atoi( it->second.c_str() );
  2733. };
  2734. it = cArr->find("type");
  2735. if( it != cArr->end() ){
  2736. tVal->type = atoi( it->second.c_str() );
  2737. };
  2738. it = cArr->find("enabled");
  2739. if( it != cArr->end() ){
  2740. tVal->enabled = (bool)atoi( it->second.c_str() );
  2741. };
  2742. };
  2743. };
  2744. };
  2745. deleteResult( result );
  2746. };
  2747. return tVal;
  2748. };
  2749. /*
  2750. DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
  2751. DBC_SOCKET_DATA *tVal = NULL;
  2752. if(m_bIsConnected){
  2753. char tQBuf[CTEXT];
  2754. AAssoc *result;
  2755. sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );
  2756. #ifdef DEBUG
  2757. //LOG(tQBuf);
  2758. #endif
  2759. result = m_pDatabase->Query( tQBuf );
  2760. if( result!= NULL ) {
  2761. if( result->size() > 0 ) {
  2762. Assoc *cArr;
  2763. tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
  2764. if( tVal != NULL ) {
  2765. Assoc::iterator it;
  2766. cArr = result->at(0);
  2767. it = cArr->find("id");
  2768. if( it != cArr->end() ){
  2769. tVal->socket_id = atoi( it->second.c_str() );
  2770. };
  2771. it = cArr->find("aux_id");
  2772. if( it != cArr->end() ){
  2773. tVal->aux_id = atoi( it->second.c_str() );
  2774. };
  2775. it = cArr->find("type");
  2776. if( it != cArr->end() ){
  2777. tVal->type = atoi( it->second.c_str() );
  2778. };
  2779. it = cArr->find("binded");
  2780. if( it != cArr->end() ){
  2781. tVal->binded = (bool)atoi( it->second.c_str() );
  2782. };
  2783. };
  2784. };
  2785. };
  2786. deleteResult( result );
  2787. };
  2788. return tVal;
  2789. };
  2790. */
  2791. DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){
  2792. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  2793. if(m_bIsConnected){
  2794. char tQBuf[CTEXT];
  2795. AAssoc *result;
  2796. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  2797. #ifdef DEBUG_ALL
  2798. LOG(tQBuf);
  2799. #endif
  2800. result = m_pDatabase->Query( tQBuf );
  2801. if( result!= NULL ) {
  2802. if( result->size() > 0 ) {
  2803. Assoc *cArr;
  2804. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  2805. if( tVal != NULL ) {
  2806. memset( tVal, 0, sizeof(DBC_MEDIA_STREAM_DATA) );
  2807. Assoc::iterator it;
  2808. cArr = result->at(0);
  2809. tVal->id = ID;
  2810. it = cArr->find("source_id");
  2811. if( it != cArr->end() ){
  2812. tVal->source_id = atoi( it->second.c_str() );
  2813. };
  2814. it = cArr->find("site_id");
  2815. if( it != cArr->end() ){
  2816. tVal->site_id = atoi( it->second.c_str() );
  2817. };
  2818. it = cArr->find("source_type");
  2819. if( it != cArr->end() ){
  2820. sprintf( tVal->source_type, it->second.c_str() );
  2821. };
  2822. it = cArr->find("valid");
  2823. if( it != cArr->end() ){
  2824. tVal->valid = (bool) atoi( it->second.c_str() );
  2825. };
  2826. it = cArr->find("token");
  2827. if( it != cArr->end() ){
  2828. sprintf( tVal->token, it->second.c_str() );
  2829. };
  2830. it = cArr->find("img_width");
  2831. if( it != cArr->end() ){
  2832. tVal->width = atoi( it->second.c_str() );
  2833. };
  2834. it = cArr->find("img_height");
  2835. if( it != cArr->end() ){
  2836. tVal->height = atoi( it->second.c_str() );
  2837. };
  2838. it = cArr->find("fps");
  2839. if( it != cArr->end() ){
  2840. tVal->fps = atoi( it->second.c_str() );
  2841. };
  2842. it = cArr->find("compression_type");
  2843. if( it != cArr->end() ){
  2844. sprintf(tVal->c_type, it->second.c_str());
  2845. };
  2846. it = cArr->find("mrl_proto");
  2847. if( it != cArr->end() ){
  2848. sprintf( tVal->mrl_proto, it->second.c_str() );
  2849. };
  2850. it = cArr->find("mrl_port");
  2851. if( it != cArr->end() ){
  2852. tVal->mrl_port = atoi( it->second.c_str() );
  2853. };
  2854. it = cArr->find("mrl");
  2855. if( it != cArr->end() ){
  2856. sprintf( tVal->mrl, it->second.c_str() );
  2857. };
  2858. };
  2859. };
  2860. };
  2861. deleteResult( result );
  2862. };
  2863. return tVal;
  2864. };
  2865. DBC_MEDIA_SERVER_DATA *argusDBC::getMediaServerData( uint32_t ID ){
  2866. DBC_MEDIA_SERVER_DATA *tVal = NULL;
  2867. if(m_bIsConnected){
  2868. char tQBuf[CTEXT];
  2869. AAssoc *result;
  2870. sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
  2871. #ifdef DEBUG_ALL
  2872. LOG(tQBuf);
  2873. #endif
  2874. result = m_pDatabase->Query( tQBuf );
  2875. if( result!= NULL ) {
  2876. if( result->size() > 0 ) {
  2877. Assoc *cArr;
  2878. tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
  2879. if( tVal != NULL ) {
  2880. Assoc::iterator it;
  2881. cArr = result->at(0);
  2882. tVal->id = ID;
  2883. it = cArr->find("secret_key");
  2884. if( it != cArr->end() ){
  2885. sprintf( tVal->key, it->second.c_str() );
  2886. };
  2887. it = cArr->find("ip");
  2888. if( it != cArr->end() ){
  2889. sprintf( tVal->ip, it->second.c_str() );
  2890. };
  2891. it = cArr->find("REST_port");
  2892. if( it != cArr->end() ){
  2893. tVal->port = atoi( it->second.c_str() );
  2894. };
  2895. it = cArr->find("virtual_host");
  2896. if( it != cArr->end() ){
  2897. sprintf( tVal->host, it->second.c_str() );
  2898. };
  2899. it = cArr->find("recording");
  2900. if( it != cArr->end() ){
  2901. tVal->recording = (bool)atoi( it->second.c_str() );
  2902. };
  2903. it = cArr->find("local");
  2904. if( it != cArr->end() ){
  2905. tVal->local = (bool)atoi( it->second.c_str() );
  2906. };
  2907. it = cArr->find("docRoot");
  2908. if( it != cArr->end() ){
  2909. sprintf( tVal->docRoot, it->second.c_str() );
  2910. };
  2911. sprintf( tVal->name,"ZLMedia_%d", tVal->id );
  2912. };
  2913. };
  2914. };
  2915. deleteResult( result );
  2916. };
  2917. return tVal;
  2918. };
  2919. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamDataBySource( uint32_t ID ){
  2920. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2921. if(m_bIsConnected){
  2922. char tQBuf[MAX_PATH_LEN];
  2923. AAssoc *result;
  2924. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
  2925. #ifdef DEBUG_ALL
  2926. LOG(tQBuf);
  2927. #endif
  2928. result = m_pDatabase->Query( tQBuf );
  2929. if( result!= NULL ) {
  2930. if( result->size() > 0 ) {
  2931. Assoc *cArr;
  2932. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2933. if( tVal != NULL ) {
  2934. Assoc::iterator it;
  2935. cArr = result->at(0);
  2936. tVal->id = ID;
  2937. it = cArr->find("media_stream_id");
  2938. if( it != cArr->end() ){
  2939. tVal->media_stream_id = atoi( it->second.c_str() );
  2940. };
  2941. it = cArr->find("online");
  2942. if( it != cArr->end() ){
  2943. tVal->online = atoi( it->second.c_str() );
  2944. };
  2945. it = cArr->find("key");
  2946. if( it != cArr->end() ){
  2947. sprintf( tVal->key, it->second.c_str() );
  2948. };
  2949. it = cArr->find("mrl");
  2950. if( it != cArr->end() ){
  2951. sprintf( tVal->mrl, it->second.c_str() );
  2952. };
  2953. };
  2954. };
  2955. };
  2956. deleteResult( result );
  2957. };
  2958. return tVal;
  2959. };
  2960. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
  2961. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2962. if(m_bIsConnected){
  2963. char tQBuf[MAX_PATH_LEN];
  2964. AAssoc *result;
  2965. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
  2966. #ifdef DEBUG_ALL
  2967. LOG(tQBuf);
  2968. #endif
  2969. result = m_pDatabase->Query( tQBuf );
  2970. if( result!= NULL ) {
  2971. if( result->size() > 0 ) {
  2972. Assoc *cArr;
  2973. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2974. if( tVal != NULL ) {
  2975. Assoc::iterator it;
  2976. cArr = result->at(0);
  2977. tVal->id = ID;
  2978. it = cArr->find("media_stream_id");
  2979. if( it != cArr->end() ){
  2980. tVal->media_stream_id = atoi( it->second.c_str() );
  2981. };
  2982. it = cArr->find("online");
  2983. if( it != cArr->end() ){
  2984. tVal->online = atoi( it->second.c_str() );
  2985. };
  2986. it = cArr->find("key");
  2987. if( it != cArr->end() ){
  2988. sprintf( tVal->key, it->second.c_str() );
  2989. };
  2990. it = cArr->find("mrl");
  2991. if( it != cArr->end() ){
  2992. sprintf( tVal->mrl, it->second.c_str() );
  2993. };
  2994. };
  2995. };
  2996. };
  2997. deleteResult( result );
  2998. };
  2999. return tVal;
  3000. };
  3001. void argusDBC::registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ){
  3002. if(m_bIsConnected){
  3003. m_nSiteID = SiteID;
  3004. char tQBuf[MAX_PATH_LEN];
  3005. 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",
  3006. SiteID, identity, ARGUS_BUILD_STRING, PID, ARGUS_BUILD_STRING, PID );
  3007. #ifdef DEBUG
  3008. LOG(tQBuf);
  3009. #endif
  3010. m_pDatabase->SilentQuery( tQBuf );
  3011. *ServID = getServerID( identity );
  3012. if( *ServID ) {
  3013. 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 );
  3014. #ifdef DEBUG_ALL
  3015. LOG(tQBuf);
  3016. #endif
  3017. *ServNode = ( uint32_t ) m_pDatabase->QueryID( tQBuf );
  3018. if( *ServNode == 0 ){
  3019. *ServNode = getServerNode( *ServID );
  3020. };
  3021. // Clenup Nodes and services ...
  3022. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `server_id`=%d ", *ServID );
  3023. #ifdef DEBUG_ALL
  3024. LOG(tQBuf);
  3025. #endif
  3026. m_pDatabase->SilentQuery( tQBuf );
  3027. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  3028. #ifdef DEBUG_ALL
  3029. LOG(tQBuf);
  3030. #endif
  3031. m_pDatabase->SilentQuery( tQBuf );
  3032. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  3033. #ifdef DEBUG_ALL
  3034. LOG(tQBuf);
  3035. #endif
  3036. m_pDatabase->SilentQuery( tQBuf );
  3037. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  3038. #ifdef DEBUG_ALL
  3039. LOG(tQBuf);
  3040. #endif
  3041. m_pDatabase->SilentQuery( tQBuf );
  3042. //cleanResources( tServerNodeID );
  3043. setNodeOnline( *ServNode );
  3044. }
  3045. };
  3046. };
  3047. void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
  3048. if( setNodeOffline( NodeID ) ){
  3049. char tQBuf[CTEXT];
  3050. sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", ServerID );
  3051. #ifdef DEBUG_ALL
  3052. LOG(tQBuf);
  3053. #endif
  3054. m_pDatabase->SilentQuery( tQBuf );
  3055. };
  3056. };
  3057. bool argusDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  3058. if(m_bIsConnected){
  3059. char tQBuf[CTEXT];
  3060. if( NodeID ) {
  3061. sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );
  3062. #ifdef DEBUG_ALL
  3063. LOG(tQBuf);
  3064. #endif
  3065. m_pDatabase->SilentQuery( tQBuf );
  3066. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  3067. #ifdef DEBUG_ALL
  3068. LOG(tQBuf);
  3069. #endif
  3070. m_pDatabase->SilentQuery( tQBuf );
  3071. return true;
  3072. };
  3073. };
  3074. return false;
  3075. };
  3076. bool argusDBC::setNodeOffline( uint32_t NodeID ){
  3077. if(m_bIsConnected){
  3078. char tQBuf[CTEXT];
  3079. if( NodeID ) {
  3080. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  3081. #ifdef DEBUG_ALL
  3082. LOG(tQBuf);
  3083. #endif
  3084. m_pDatabase->SilentQuery( tQBuf );
  3085. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  3086. #ifdef DEBUG_ALL
  3087. LOG(tQBuf);
  3088. #endif
  3089. m_pDatabase->SilentQuery( tQBuf );
  3090. return true;
  3091. };
  3092. };
  3093. return false;
  3094. };
  3095. DBC_RESOURCE_DATA *argusDBC::getResourceData( uint32_t ResourceID ){
  3096. DBC_RESOURCE_DATA *tVal = NULL;
  3097. if( m_bIsConnected ){
  3098. char tQBuf[CTEXT];
  3099. AAssoc *result;
  3100. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );
  3101. #ifdef DEBUG_ALL
  3102. LOG(tQBuf);
  3103. #endif
  3104. result = m_pDatabase->Query( tQBuf );
  3105. if( result!= NULL ) {
  3106. if( result->size() > 0 ) {
  3107. Assoc *cArr;
  3108. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  3109. if( tVal != NULL ) {
  3110. Assoc::iterator it;
  3111. cArr = result->at(0);
  3112. tVal->id = ResourceID;
  3113. it = cArr->find("node_id");
  3114. if( it != cArr->end() ){
  3115. tVal->node_id = atoi( it->second.c_str() );
  3116. };
  3117. it = cArr->find("type");
  3118. if( it != cArr->end() ){
  3119. tVal->type = atoi( it->second.c_str() );
  3120. };
  3121. it = cArr->find("aux_id");
  3122. if( it != cArr->end() ){
  3123. tVal->aux_id = atoi( it->second.c_str() );
  3124. };
  3125. it = cArr->find("device");
  3126. if( it != cArr->end() ){
  3127. strncpy( tVal->device, it->second.c_str(), 64 );
  3128. tVal->device[63] = (char)0;
  3129. };
  3130. };
  3131. };
  3132. };
  3133. deleteResult( result );
  3134. };
  3135. return tVal;
  3136. };
  3137. uint32_t argusDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){
  3138. uint32_t RetVal = 0;
  3139. if(m_bIsConnected){
  3140. char tQBuf[CTEXT];
  3141. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );
  3142. #ifdef DEBUG_ALL
  3143. LOG(tQBuf);
  3144. #endif
  3145. AAssoc *result;
  3146. result = m_pDatabase->Query( tQBuf );
  3147. if( result!= NULL ) {
  3148. if( result->size() > 0 ) {
  3149. Assoc * cArr;
  3150. Assoc::iterator it;
  3151. cArr = result->at(0);
  3152. it = cArr->find("id");
  3153. if( it != cArr->end() ){
  3154. RetVal = atoi( it->second.c_str() );
  3155. };
  3156. };
  3157. };
  3158. deleteResult( result );
  3159. };
  3160. return RetVal;
  3161. };
  3162. uint32_t argusDBC::getServerID( CSTR identity ){
  3163. uint32_t RetVal = 0;
  3164. if(m_bIsConnected){
  3165. char tQBuf[CTEXT];
  3166. sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
  3167. #ifdef DEBUG_ALL
  3168. LOG(tQBuf);
  3169. #endif
  3170. AAssoc *result;
  3171. result = m_pDatabase->Query( tQBuf );
  3172. if( result!= NULL ) {
  3173. if( result->size() > 0 ) {
  3174. Assoc * cArr;
  3175. Assoc::iterator it;
  3176. cArr = result->at(0);
  3177. it = cArr->find("id");
  3178. if( it != cArr->end() ){
  3179. RetVal = atoi( it->second.c_str() );
  3180. };
  3181. };
  3182. };
  3183. deleteResult( result );
  3184. };
  3185. return RetVal;
  3186. };
  3187. uint32_t argusDBC::getServerNode( uint32_t SID ){
  3188. uint32_t RetVal = 0;
  3189. if(m_bIsConnected){
  3190. char tQBuf[CTEXT];
  3191. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  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::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
  3213. uint32_t RetVal = 0;
  3214. if(m_bIsConnected){
  3215. char tQBuf[1024];
  3216. char tM5[33];
  3217. CSTR tMD5 = MD5String( path );
  3218. if( tMD5 != NULL ) {
  3219. memcpy( tM5, tMD5, 33 );
  3220. tM5[32]=(char)0;
  3221. free( tMD5 );
  3222. 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",
  3223. SiteID, tM5, width, height, path );//, width, height );
  3224. #ifdef DEBUG_ALL
  3225. LOG(tQBuf);
  3226. #endif
  3227. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3228. };
  3229. };
  3230. return RetVal;
  3231. };
  3232. /*
  3233. uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
  3234. uint32_t retVal = 0;
  3235. if(m_bIsConnected){
  3236. char tQBuf[2048];
  3237. char tM5[33];
  3238. CSTR tMD5 = MD5String( path );
  3239. if( tMD5 != NULL ) {
  3240. memcpy( tM5, tMD5, 33 );
  3241. free( tMD5 );
  3242. if( multidrop ) {
  3243. 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'",
  3244. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  3245. } else {
  3246. 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'",
  3247. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  3248. };
  3249. #ifdef DEBUG
  3250. LOG(tQBuf);
  3251. #endif
  3252. //m_pDatabase->SilentQuery( tQBuf );
  3253. retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3254. };
  3255. };
  3256. return retVal;
  3257. };
  3258. */
  3259. bool argusDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_ID ){
  3260. if(m_bIsConnected){
  3261. char tQBuf[2048];
  3262. 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 );
  3263. #ifdef DEBUG_ALL
  3264. LOG(tQBuf);
  3265. #endif
  3266. m_pDatabase->SilentQuery( tQBuf );
  3267. return true;
  3268. };
  3269. return false;
  3270. };
  3271. uint32_t argusDBC::addResource( uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID ){
  3272. uint32_t RetVal = 0;
  3273. if( m_bIsConnected ){
  3274. char tQBuf[2048];
  3275. sprintf( tQBuf, "%d:%d:%s", NodeID, type, devName );
  3276. CSTR tMD5 = MD5String( tQBuf );
  3277. if( tMD5 ) {
  3278. 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 );
  3279. //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 );
  3280. free( tMD5 );
  3281. #ifdef DEBUG_ALL
  3282. LOG(tQBuf);
  3283. #endif
  3284. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3285. if( RetVal == 0 ) {
  3286. RetVal = getResourceID( NodeID, type, auxID );
  3287. };
  3288. };
  3289. };
  3290. return RetVal;
  3291. };
  3292. /*
  3293. uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
  3294. uint32_t retVal = 0;
  3295. if(m_bIsConnected){
  3296. char tQBuf[2048];
  3297. char tM5[33];
  3298. CSTR tMD5 = MD5String( path );
  3299. if( tMD5 != NULL ) {
  3300. memcpy( tM5, tMD5, 33 );
  3301. free( tMD5 );
  3302. sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
  3303. #ifdef DEBUG
  3304. LOG(tQBuf);
  3305. #endif
  3306. AAssoc *result;
  3307. result = m_pDatabase->Query( tQBuf );
  3308. if( result!= NULL ) {
  3309. if( result->size() > 0 ) {
  3310. Assoc * cArr;
  3311. Assoc::iterator it;
  3312. cArr = result->at(0);
  3313. it = cArr->find("id");
  3314. if( it != cArr->end() ){
  3315. retVal = atoi( it->second.c_str() );
  3316. };
  3317. };
  3318. };
  3319. deleteResult( result );
  3320. };
  3321. };
  3322. return retVal;
  3323. };
  3324. */
  3325. /*
  3326. CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
  3327. if(m_bIsConnected){
  3328. char tQBuf[CTEXT];
  3329. sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  3330. NodeID, Type );
  3331. #ifdef DEBUG
  3332. LOG(tQBuf);
  3333. #endif
  3334. AAssoc *result;
  3335. result = m_pDatabase->Query( tQBuf );
  3336. if( result!= NULL ) {
  3337. if( result->size() > 0 ) {
  3338. Assoc * cArr;
  3339. Assoc::iterator it;
  3340. cArr = result->at(0);
  3341. it = cArr->find("name");
  3342. if( it != cArr->end() ){
  3343. strncpy( tQBuf, it->second.c_str(), CTEXT );
  3344. };
  3345. };
  3346. };
  3347. deleteResult( result );
  3348. return strdup(tQBuf);
  3349. };
  3350. return NULL;
  3351. };
  3352. */
  3353. KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
  3354. KAFKA_SETTINGS *tVal = NULL;
  3355. if( m_bIsConnected ) {
  3356. char tQBuf[CTEXT];
  3357. AAssoc *result;
  3358. sprintf( tQBuf, "SELECT * FROM modules_kafka WHERE module_id = %d", ModuleID );
  3359. #ifdef DEBUG_ALL
  3360. LOG(tQBuf);
  3361. #endif
  3362. result = m_pDatabase->Query( tQBuf );
  3363. if( result!= NULL ) {
  3364. if( result->size() > 0 ) {
  3365. Assoc *cArr;
  3366. tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
  3367. if( tVal != NULL ) {
  3368. memset( tVal, 0, sizeof(KAFKA_SETTINGS) );
  3369. Assoc::iterator it;
  3370. cArr = result->at(0);
  3371. it = cArr->find("brocker_address");
  3372. if( it != cArr->end() ){
  3373. strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
  3374. };
  3375. it = cArr->find("brocker_port");
  3376. if( it != cArr->end() ){
  3377. tVal->brocker_port = atoi( it->second.c_str() );
  3378. };
  3379. it = cArr->find("use_ssl");
  3380. if( it != cArr->end() ){
  3381. tVal->use_ssl = (bool)atoi( it->second.c_str() );
  3382. };
  3383. it = cArr->find("auth_cert");
  3384. if( it != cArr->end() ){
  3385. tVal->auth_by_cert = (bool)atoi( it->second.c_str() );
  3386. };
  3387. it = cArr->find("auth_cred");
  3388. if( it != cArr->end() ){
  3389. tVal->auth_by_cred = (bool)atoi( it->second.c_str() );
  3390. };
  3391. it = cArr->find("vault_md5");
  3392. if( it != cArr->end() ){
  3393. strncpy( tVal->vault_md5, it->second.c_str(), 32 );
  3394. };
  3395. it = cArr->find("truststore");
  3396. if( it != cArr->end() ){
  3397. tVal->truststore = (bool)atoi( it->second.c_str() );
  3398. };
  3399. it = cArr->find("certstore");
  3400. if( it != cArr->end() ){
  3401. tVal->certstore = (bool)atoi( it->second.c_str() );
  3402. };
  3403. it = cArr->find("keystore");
  3404. if( it != cArr->end() ){
  3405. tVal->keystore = (bool)atoi( it->second.c_str() );
  3406. };
  3407. it = cArr->find("cred_username");
  3408. if( it != cArr->end() ){
  3409. strncpy( tVal->cred_username, it->second.c_str(), 32 );
  3410. };
  3411. it = cArr->find("cred_password");
  3412. if( it != cArr->end() ){
  3413. strncpy( tVal->cred_password, it->second.c_str(), 32 );
  3414. };
  3415. };
  3416. };
  3417. };
  3418. deleteResult( result );
  3419. };
  3420. return tVal;
  3421. };
  3422. KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
  3423. KAFKA_TEMPLATE *tVal = NULL;
  3424. if( m_bIsConnected ) {
  3425. char tQBuf[CTEXT];
  3426. AAssoc *result;
  3427. sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
  3428. #ifdef DEBUG_ALL
  3429. LOG(tQBuf);
  3430. #endif
  3431. result = m_pDatabase->Query( tQBuf );
  3432. if( result!= NULL ) {
  3433. if( result->size() > 0 ) {
  3434. Assoc *cArr;
  3435. tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
  3436. if( tVal != NULL ) {
  3437. Assoc::iterator it;
  3438. cArr = result->at(0);
  3439. it = cArr->find("topic");
  3440. if( it != cArr->end() ){
  3441. memset( tVal->topic, 0, 128 );
  3442. strncpy( tVal->topic , it->second.c_str(), 127 );
  3443. };
  3444. it = cArr->find("template");
  3445. if( it != cArr->end() ){
  3446. tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
  3447. if( tVal->tpl!= NULL) {
  3448. memset( tVal->tpl, 0, it->second.length() + 1 );
  3449. strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
  3450. };
  3451. };
  3452. };
  3453. };
  3454. };
  3455. deleteResult( result );
  3456. };
  3457. return tVal;
  3458. };
  3459. DBC_UART_DATA *argusDBC::getUartData( uint32_t UartID ){
  3460. DBC_UART_DATA *tVal = NULL;
  3461. if( m_bIsConnected ) {
  3462. char tQBuf[MAX_PATH_LEN];
  3463. AAssoc *result;
  3464. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  3465. #ifdef DEBUG_ALL
  3466. LOG(tQBuf);
  3467. #endif
  3468. result = m_pDatabase->Query( tQBuf );
  3469. if( result!= NULL ) {
  3470. if( result->size() > 0 ) {
  3471. Assoc *cArr;
  3472. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  3473. if( tVal != NULL ) {
  3474. Assoc::iterator it;
  3475. cArr = result->at(0);
  3476. it = cArr->find("type");
  3477. if( it != cArr->end() ){
  3478. tVal->type = atoi( it->second.c_str() );
  3479. };
  3480. it = cArr->find("speed");
  3481. if( it != cArr->end() ){
  3482. tVal->speed = atoi( it->second.c_str() );
  3483. };
  3484. it = cArr->find("mode");
  3485. if( it != cArr->end() ){
  3486. tVal->mode = atoi( it->second.c_str() );
  3487. };
  3488. it = cArr->find("port");
  3489. if( it != cArr->end() ){
  3490. tVal->port = atoi( it->second.c_str() );
  3491. };
  3492. it = cArr->find("path");
  3493. if( it != cArr->end() ){
  3494. strncpy( tVal->path, it->second.c_str(), 128 );
  3495. };
  3496. };
  3497. };
  3498. };
  3499. deleteResult( result );
  3500. };
  3501. return tVal;
  3502. };
  3503. uint32_t argusDBC::getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){
  3504. uint32_t RetVal = 0;
  3505. if(m_bIsConnected){
  3506. char tQBuf[CTEXT];
  3507. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path );
  3508. #ifdef DEBUG_ALL
  3509. LOG(tQBuf);
  3510. #endif
  3511. AAssoc *result;
  3512. result = m_pDatabase->Query( tQBuf );
  3513. if( result!= NULL ) {
  3514. if( result->size() > 0 ) {
  3515. Assoc * cArr;
  3516. Assoc::iterator it;
  3517. cArr = result->at(0);
  3518. it = cArr->find("id");
  3519. if( it != cArr->end() ){
  3520. RetVal = atoi( it->second.c_str() );
  3521. };
  3522. };
  3523. };
  3524. deleteResult( result );
  3525. };
  3526. return RetVal;
  3527. };
  3528. bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
  3529. if( m_bIsConnected ) {
  3530. char tQBuf[MAX_PATH_LEN];
  3531. if( key == NULL ) {
  3532. if( mrl == NULL ) {
  3533. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
  3534. } else {
  3535. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
  3536. };
  3537. } else {
  3538. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
  3539. key,
  3540. mrl,
  3541. id
  3542. );
  3543. };
  3544. #ifdef DEBUG_ALL
  3545. LOG(tQBuf);
  3546. #endif
  3547. m_pDatabase->SilentQuery( tQBuf );
  3548. return true;
  3549. };
  3550. return false;
  3551. };
  3552. bool argusDBC::updateResourceAUX( uint32_t ResID, uint32_t AUX ){
  3553. if( m_bIsConnected ) {
  3554. char tQBuf[MAX_PATH_LEN];
  3555. sprintf( tQBuf, "UPDATE `resources` SET `aux_id`=%d WHERE `id`=%d", AUX, ResID );
  3556. #ifdef DEBUG
  3557. LOG(tQBuf);
  3558. #endif
  3559. m_pDatabase->SilentQuery( tQBuf );
  3560. return true;
  3561. };
  3562. return false;
  3563. };
  3564. 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 ){
  3565. if( m_bIsConnected ) {
  3566. char tQBuf[MAX_PATH_LEN];
  3567. 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",
  3568. nCores,
  3569. cpu1,
  3570. cpu5,
  3571. cpu15,
  3572. mem,
  3573. disk,
  3574. dtsize,
  3575. dcsize,
  3576. mtsize,
  3577. mcsize,
  3578. ServerID
  3579. );
  3580. #ifdef DEBUG_ALL
  3581. LOG(tQBuf);
  3582. #endif
  3583. m_pDatabase->SilentQuery( tQBuf );
  3584. return true;
  3585. };
  3586. return false;
  3587. };
  3588. uint32_t argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){
  3589. uint32_t RetVal = 0;
  3590. if( m_bIsConnected ) {
  3591. char tQBuf[MAX_PATH_LEN];
  3592. 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",
  3593. SiteID,
  3594. status,
  3595. CNT,
  3596. SERIAL,
  3597. status,
  3598. CNT
  3599. );
  3600. #ifdef DEBUG_ALL
  3601. LOG(tQBuf);
  3602. #endif
  3603. uint64_t cid = m_pDatabase->QueryID( tQBuf );
  3604. if( cid == 0 ) {
  3605. AAssoc *result;
  3606. sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'",
  3607. SiteID,
  3608. SERIAL
  3609. );
  3610. #ifdef DEBUG_ALL
  3611. LOG(tQBuf);
  3612. #endif
  3613. result = m_pDatabase->Query( tQBuf );
  3614. if( result!= NULL ) {
  3615. if( result->size() > 0 ) {
  3616. Assoc * cArr;
  3617. Assoc::iterator it;
  3618. cArr = result->at(0);
  3619. it = cArr->find("id");
  3620. if( it != cArr->end() ){
  3621. cid = atoi( it->second.c_str() );
  3622. };
  3623. };
  3624. deleteResult( result );
  3625. };
  3626. };
  3627. if( cid!= 0 ) {
  3628. for( uint8_t idx = 0; idx < CNT; idx++ ) {
  3629. if( status & ( 1 << idx ) ){
  3630. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'",
  3631. (uint32_t) cid,
  3632. idx
  3633. );
  3634. } else {
  3635. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'",
  3636. (uint32_t) cid,
  3637. idx
  3638. );
  3639. }
  3640. #ifdef DEBUG_ALL
  3641. LOG(tQBuf);
  3642. #endif
  3643. m_pDatabase->SilentQuery( tQBuf );
  3644. };
  3645. };
  3646. };
  3647. return RetVal;
  3648. };
  3649. 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 ){
  3650. uint32_t RetVal = 0;
  3651. if( m_bIsConnected ) {
  3652. char tQBuf[MAX_PATH_LEN];
  3653. 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`",
  3654. NodeID,
  3655. utype,
  3656. speed,
  3657. bit,
  3658. parity,
  3659. stop_bit,
  3660. mode,
  3661. port,
  3662. PATH
  3663. );
  3664. #ifdef DEBUG_ALL
  3665. LOG(tQBuf);
  3666. #endif
  3667. RetVal = m_pDatabase->QueryID( tQBuf );
  3668. if( RetVal == 0 ) {
  3669. RetVal = getUartID( NodeID, utype, PATH );
  3670. };
  3671. };
  3672. return RetVal;
  3673. };
  3674. uint32_t argusDBC::addLocalNIF( CSTR device, CSTR mac, ARGUS_NIF_TYPE dtype, ARGUS_NIF_MODE dmode, uint32_t aux_id ){
  3675. uint32_t RetVal = 0;
  3676. if( m_bIsConnected ) {
  3677. char tQBuf[MAX_PATH_LEN];
  3678. char * tKey = MD5String( device );
  3679. if( tKey != NULL ) {
  3680. 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'",
  3681. dtype,
  3682. tKey,
  3683. device,
  3684. mac,
  3685. dmode,
  3686. aux_id,
  3687. dmode,
  3688. aux_id,
  3689. mac
  3690. );
  3691. #ifdef DEBUG
  3692. LOG(tQBuf);
  3693. #endif
  3694. RetVal = m_pDatabase->QueryID( tQBuf );
  3695. if( RetVal == 0 ) {
  3696. RetVal = getNIF_ID( tKey );
  3697. };
  3698. free( tKey );
  3699. };
  3700. };
  3701. return RetVal;
  3702. };
  3703. uint32_t argusDBC::addLocalWiFi( uint32_t NIF_ID, ARGUS_WIFI_MODE mode, CSTR SSID, CSTR password, ARGUS_WIFI_ENCRIPTION encryption, uint32_t router_id ){
  3704. uint32_t RetVal = 0;
  3705. if( m_bIsConnected ) {
  3706. char tQBuf[MAX_PATH_LEN];
  3707. 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",
  3708. NIF_ID,
  3709. mode,
  3710. router_id,
  3711. SSID,
  3712. password,
  3713. encryption,
  3714. mode,
  3715. router_id,
  3716. SSID,
  3717. password,
  3718. encryption
  3719. );
  3720. #ifdef DEBUG
  3721. LOG(tQBuf);
  3722. #endif
  3723. RetVal = m_pDatabase->QueryID( tQBuf );
  3724. if( RetVal == 0 ) {
  3725. RetVal = getWiFi_ID( NIF_ID );
  3726. };
  3727. };
  3728. return RetVal;
  3729. };
  3730. uint32_t argusDBC::addLRFMask( uint32_t devID, uint8_t lrfID, uint8_t layerID ){
  3731. uint32_t RetVal = 0;
  3732. if( m_bIsConnected ) {
  3733. char tQBuf[MAX_PATH_LEN];
  3734. sprintf( tQBuf, "INSERT INTO `lrf_masks` SET `sensor_id`=%d, `lrf_id`=%d, `layer`=%d ON DUPLICATE KEY UPDATE `id`=`id`",
  3735. devID,
  3736. lrfID,
  3737. layerID
  3738. );
  3739. #ifdef DEBUG
  3740. LOG(tQBuf);
  3741. #endif
  3742. RetVal = m_pDatabase->QueryID( tQBuf );
  3743. if( RetVal == 0 ) {
  3744. RetVal = getLRFMaskID( devID, lrfID, layerID );
  3745. };
  3746. };
  3747. return RetVal;
  3748. };
  3749. uint32_t argusDBC::addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b ){
  3750. uint32_t RetVal = 0;
  3751. if( m_bIsConnected ) {
  3752. char tQBuf[MAX_PATH_LEN];
  3753. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertexes` SET `mask_id`=%d, `r`=%d, `g`=%d, `b`=%d",
  3754. maskID,
  3755. r,
  3756. g,
  3757. b
  3758. );
  3759. #ifdef DEBUG
  3760. LOG(tQBuf);
  3761. #endif
  3762. RetVal = m_pDatabase->QueryID( tQBuf );
  3763. };
  3764. return RetVal;
  3765. };
  3766. bool argusDBC::addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ){
  3767. if( m_bIsConnected ) {
  3768. char tQBuf[MAX_PATH_LEN];
  3769. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertex_points` SET `vertex_id`=%d, `x`=%d, `y`=%d",
  3770. polyID,
  3771. x,
  3772. y
  3773. );
  3774. #ifdef DEBUG
  3775. LOG(tQBuf);
  3776. #endif
  3777. m_pDatabase->SilentQuery( tQBuf );
  3778. return true;
  3779. };
  3780. return false;
  3781. };
  3782. uint32_t argusDBC::addLocalNetwork( uint32_t NIF_ID, ARGUS_NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){
  3783. uint32_t RetVal = 0;
  3784. if( m_bIsConnected ) {
  3785. char tQBuf[MAX_PATH_LEN];
  3786. 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'",
  3787. NIF_ID,
  3788. net_type,
  3789. address,
  3790. gateway,
  3791. mask,
  3792. broadcast,
  3793. address,
  3794. gateway,
  3795. mask,
  3796. broadcast
  3797. );
  3798. #ifdef DEBUG
  3799. LOG(tQBuf);
  3800. #endif
  3801. RetVal = m_pDatabase->QueryID( tQBuf );
  3802. // On Update IF data no need to return ID
  3803. //if( RetVal == 0 ) {
  3804. // RetVal = getNetworkInterfaceID( tKey );
  3805. //};
  3806. };
  3807. return RetVal;
  3808. };
  3809. uint32_t argusDBC::addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp, CSTR BRANG, CSTR ERANG, CSTR MASK, CSTR LEASE_TIME ){
  3810. uint32_t RetVal = 0;
  3811. if( m_bIsConnected ) {
  3812. char tQBuf[MAX_PATH_LEN];
  3813. bool ena_routing = true;
  3814. if( OUTBOUND_NIF == 0 ){
  3815. ena_routing = false;
  3816. };
  3817. if( ena_dhcp ){
  3818. if ( BRANG == NULL || ERANG == NULL || MASK == NULL || LEASE_TIME == NULL ) {
  3819. LOG_ERROR("Wrong DHCP parameters to create Network Infrastructure!");
  3820. return 0;
  3821. };
  3822. 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'",
  3823. NIF_ID,
  3824. ena_routing,
  3825. OUTBOUND_NIF,
  3826. BRANG,
  3827. ERANG,
  3828. MASK,
  3829. LEASE_TIME,
  3830. ena_routing,
  3831. OUTBOUND_NIF,
  3832. BRANG,
  3833. ERANG,
  3834. MASK,
  3835. LEASE_TIME
  3836. );
  3837. } else {
  3838. if( ena_routing ){
  3839. 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",
  3840. NIF_ID,
  3841. OUTBOUND_NIF,
  3842. OUTBOUND_NIF
  3843. );
  3844. } else {
  3845. LOG_ERROR("No Special Service Defined To Network Infrastructure!");
  3846. return 0;
  3847. };
  3848. };
  3849. #ifdef DEBUG_ALL
  3850. LOG(tQBuf);
  3851. #endif
  3852. RetVal = m_pDatabase->QueryID( tQBuf );
  3853. // On Update IF data no need to return ID
  3854. if( RetVal == 0 ) {
  3855. RetVal = getNetworkInfrastructureID( NIF_ID );
  3856. };
  3857. };
  3858. return RetVal;
  3859. };
  3860. bool argusDBC::addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID, uint8_t type, bool rendered ){
  3861. if( m_bIsConnected ) {
  3862. char tQBuf[MAX_PATH_LEN];
  3863. if ( rendered ) {
  3864. 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'",
  3865. DBID,
  3866. ID,
  3867. SIZE,
  3868. kID,
  3869. type,
  3870. ID,
  3871. SIZE
  3872. );
  3873. } else {
  3874. 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'",
  3875. DBID,
  3876. ID,
  3877. SIZE,
  3878. kID,
  3879. type,
  3880. ID,
  3881. SIZE
  3882. );
  3883. };
  3884. #ifdef DEBUG
  3885. LOG(tQBuf);
  3886. #endif
  3887. m_pDatabase->SilentQuery( tQBuf );
  3888. return true;
  3889. };
  3890. return false;
  3891. };
  3892. 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 ){
  3893. uint32_t RetVal = 0;
  3894. if( m_bIsConnected ) {
  3895. char tQBuf[MAX_PATH_LEN];
  3896. if( RefUUID == NULL ) {
  3897. 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",
  3898. SRC,
  3899. UUID,
  3900. tss,
  3901. tsms,
  3902. evt_type,
  3903. k_id,
  3904. dig_r,
  3905. AZ,
  3906. EL,
  3907. RANGE,
  3908. AREA,
  3909. lat,
  3910. lon,
  3911. alt
  3912. );
  3913. } else {
  3914. 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'",
  3915. SRC,
  3916. UUID,
  3917. tss,
  3918. tsms,
  3919. evt_type,
  3920. k_id,
  3921. dig_r,
  3922. AZ,
  3923. EL,
  3924. RANGE,
  3925. AREA,
  3926. lat,
  3927. lon,
  3928. alt,
  3929. RefUUID
  3930. );
  3931. };
  3932. #ifdef DEBUG_ALL
  3933. LOG(tQBuf);
  3934. #endif
  3935. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3936. if( RetVal ) {
  3937. if (RefUUID == NULL) {
  3938. 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",
  3939. RetVal,
  3940. SRC,
  3941. UUID,
  3942. tss,
  3943. tsms,
  3944. evt_type,
  3945. k_id,
  3946. dig_r,
  3947. AZ,
  3948. EL,
  3949. RANGE,
  3950. AREA,
  3951. lat,
  3952. lon,
  3953. alt
  3954. );
  3955. } else {
  3956. 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'",
  3957. RetVal,
  3958. SRC,
  3959. UUID,
  3960. tss,
  3961. tsms,
  3962. evt_type,
  3963. k_id,
  3964. dig_r,
  3965. AZ,
  3966. EL,
  3967. RANGE,
  3968. AREA,
  3969. lat,
  3970. lon,
  3971. alt,
  3972. RefUUID
  3973. );
  3974. };
  3975. m_pDatabase->SilentQuery( tQBuf );
  3976. };
  3977. // Cleanup Mem Targets Older then 1 Hour
  3978. sprintf( tQBuf, "DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - 3600 )" );
  3979. m_pDatabase->SilentQuery( tQBuf );
  3980. };
  3981. return RetVal;
  3982. };
  3983. bool argusDBC::addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ){
  3984. bool rVal = false;
  3985. if( th_data != NULL && th_size ){
  3986. if( m_bIsConnected ){
  3987. CSTR tPData = m_pDatabase->escapeBinary( (uint8_t *) th_data, th_size );
  3988. if ( tPData ) {
  3989. CSTR tQBuf = (CSTR)malloc(BUF_4MB);
  3990. if( tQBuf ) {
  3991. sprintf( tQBuf, "DELETE FROM `lrf_draw` WHERE `node_id`=%d AND `lrf_id`=%d AND `type`=%d", DBID, lrf, type );
  3992. LOG( tQBuf );
  3993. m_pDatabase->SilentQuery( tQBuf );
  3994. 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 );
  3995. m_pDatabase->SilentQuery( tQBuf );
  3996. LOG( "Inserted Draw OK!" );
  3997. free( tQBuf );
  3998. rVal = true;
  3999. } else {
  4000. LOG_ERROR("Error Allocating Query Buffer!");
  4001. };
  4002. free( tPData );
  4003. } else {
  4004. LOG_ERROR( "Error escaping Pic Data!");
  4005. };
  4006. };
  4007. };
  4008. return rVal;
  4009. };
  4010. bool argusDBC::addVideoEvent( uint32_t evtID, uint32_t videoID ){
  4011. if( m_bIsConnected ) {
  4012. char tQBuf[MAX_PATH_LEN];
  4013. sprintf( tQBuf, "INSERT INTO `events_2_videos` SET `evt_id`=%d, `video_id`=%d", evtID, videoID );
  4014. #ifdef DEBUG_ALL
  4015. LOG(tQBuf);
  4016. #endif
  4017. m_pDatabase->SilentQuery( tQBuf );
  4018. return true;
  4019. };
  4020. return true;
  4021. };
  4022. /*
  4023. bool argusDBC::addPictureEvent( uint32_t evtID, uint32_t pictureoID ){
  4024. if( m_bIsConnected ) {
  4025. char tQBuf[MAX_PATH_LEN];
  4026. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", evtID, pictureoID );
  4027. #ifdef DEBUG_ALL
  4028. LOG(tQBuf);
  4029. #endif
  4030. m_pDatabase->SilentQuery( tQBuf );
  4031. return true;
  4032. };
  4033. return true;
  4034. };
  4035. */
  4036. uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, uint32_t partID ){
  4037. uint32_t tID = 0;
  4038. if( m_bIsConnected ) {
  4039. char tQBuf[MAX_PATH_LEN];
  4040. sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `part_id`=%d ", streamID, md5, partID );
  4041. #ifdef DEBUG_ALL
  4042. LOG(tQBuf);
  4043. #endif
  4044. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  4045. }
  4046. return tID;
  4047. };
  4048. bool argusDBC::addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ){
  4049. bool rVal = false;
  4050. if( ptr != NULL ){
  4051. if( m_bIsConnected ){
  4052. CSTR tPData = m_pDatabase->escapeBinary( ptr->data, ptr->data_size );
  4053. if ( tPData ) {
  4054. uint32_t pic_id;
  4055. CSTR tQBuf = (CSTR)malloc(BUF_4MB);
  4056. if( tQBuf ) {
  4057. //sprintf( tQBuf, "INSERT INTO `pictures` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'",
  4058. sprintf( tQBuf, "INSERT INTO pictures(media_stream_id,ts,md5,ext,data) VALUES(%d,NOW(),'%s','%s','%s')",
  4059. ptr->stream_id, ptr->md5, ext, tPData );
  4060. pic_id = (uint32_t) m_pDatabase->QueryID( tQBuf );
  4061. if ( pic_id ) {
  4062. for( DBC_INT_LIST::iterator idx = ptr->assoc_event_ids.begin(); idx < ptr->assoc_event_ids.end(); idx++ ) {
  4063. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", (*idx), pic_id );
  4064. m_pDatabase->SilentQuery( tQBuf );
  4065. };
  4066. rVal = true;
  4067. };
  4068. free( tQBuf );
  4069. } else {
  4070. LOG_ERROR("Error Allocating Query Buffer!");
  4071. };
  4072. free( tPData );
  4073. } else {
  4074. LOG_ERROR( "Error escaping Pic Data!");
  4075. };
  4076. };
  4077. };
  4078. return rVal;
  4079. };
  4080. 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 ){
  4081. if( m_bIsConnected ) {
  4082. char tQBuf[MAX_PATH_LEN];
  4083. if( master ) {
  4084. 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",
  4085. lrfID,
  4086. profileID,
  4087. nOrder,
  4088. nOffset,
  4089. nDelta,
  4090. nFlip,
  4091. nWidth,
  4092. bSST,
  4093. nSun,
  4094. GP,
  4095. spikes,
  4096. nOrder,
  4097. nOffset,
  4098. nDelta,
  4099. nFlip,
  4100. nWidth,
  4101. bSST,
  4102. nSun,
  4103. GP,
  4104. spikes );
  4105. } else {
  4106. 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",
  4107. lrfID,
  4108. profileID,
  4109. nOrder,
  4110. nOffset,
  4111. nDelta,
  4112. nFlip,
  4113. nWidth,
  4114. bSST,
  4115. nSun,
  4116. GP,
  4117. spikes,
  4118. nOrder,
  4119. nOffset,
  4120. nDelta,
  4121. nFlip,
  4122. nWidth,
  4123. bSST,
  4124. nSun,
  4125. GP,
  4126. spikes );
  4127. };
  4128. #ifdef DEBUG_ALL
  4129. LOG(tQBuf);
  4130. #endif
  4131. m_pDatabase->SilentQuery( tQBuf );
  4132. return true;
  4133. };
  4134. return false;
  4135. };
  4136. bool argusDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  4137. if( m_bIsConnected ) {
  4138. char tQBuf[MAX_PATH_LEN];
  4139. CSTR tES = m_pDatabase->escapeString( Serial );
  4140. if( tES ) {
  4141. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  4142. free( tES );
  4143. #ifdef DEBUG_ALL
  4144. LOG(tQBuf);
  4145. #endif
  4146. m_pDatabase->SilentQuery( tQBuf );
  4147. return true;
  4148. };
  4149. };
  4150. return false;
  4151. };
  4152. bool argusDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  4153. if( m_bIsConnected ) {
  4154. char tQBuf[MAX_PATH_LEN];
  4155. CSTR tES = m_pDatabase->escapeString( version );
  4156. if( tES ) {
  4157. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  4158. free( tES );
  4159. #ifdef DEBUG_ALL
  4160. LOG(tQBuf);
  4161. #endif
  4162. m_pDatabase->SilentQuery( tQBuf );
  4163. return true;
  4164. };
  4165. };
  4166. return false;
  4167. };
  4168. bool argusDBC::update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr ){
  4169. if( m_bIsConnected ) {
  4170. char tQBuf[MAX_PATH_LEN];
  4171. sprintf( tQBuf, "INSERT INTO `lrf_runtime_status` SET `lrf_id`=%d ON DUPLICATE KEY UPDATE `lrf_id`=`lrf_id`", lrfID );
  4172. #ifdef DEBUG_ALL
  4173. LOG(tQBuf);
  4174. #endif
  4175. m_pDatabase->SilentQuery( tQBuf );
  4176. sprintf( tQBuf,
  4177. "UPDATE `lrf_runtime_status` SET "
  4178. "`hw_status`=%d,"
  4179. "`detecting_kernels`=%d,"
  4180. "`th_ready`=%d,"
  4181. "`master_flips`=%d,"
  4182. "`slave_flips`=%d,"
  4183. "`twinc`=%d,"
  4184. "`master_mp_0`=%d,"
  4185. "`master_mp_1`=%d,"
  4186. "`master_mp_2`=%d,"
  4187. "`master_mp_3`=%d,"
  4188. "`master_mp_4`=%d,"
  4189. "`master_mp_5`=%d,"
  4190. "`master_mp_6`=%d,"
  4191. "`master_mp_7`=%d,"
  4192. "`master_gp_0`=%d,"
  4193. "`master_gp_1`=%d,"
  4194. "`master_gp_2`=%d,"
  4195. "`master_gp_3`=%d,"
  4196. "`master_gp_4`=%d,"
  4197. "`master_gp_5`=%d,"
  4198. "`master_gp_6`=%d,"
  4199. "`master_gp_7`=%d,"
  4200. "`master_wp_0`=%d,"
  4201. "`master_wp_1`=%d,"
  4202. "`master_wp_2`=%d,"
  4203. "`master_wp_3`=%d,"
  4204. "`master_wp_4`=%d,"
  4205. "`master_wp_5`=%d,"
  4206. "`master_wp_6`=%d,"
  4207. "`master_wp_7`=%d,"
  4208. "`slave_mp_0`=%d,"
  4209. "`slave_mp_1`=%d,"
  4210. "`slave_mp_2`=%d,"
  4211. "`slave_mp_3`=%d,"
  4212. "`slave_mp_4`=%d,"
  4213. "`slave_mp_5`=%d,"
  4214. "`slave_mp_6`=%d,"
  4215. "`slave_mp_7`=%d,"
  4216. "`slave_gp_0`=%d,"
  4217. "`slave_gp_1`=%d,"
  4218. "`slave_gp_2`=%d,"
  4219. "`slave_gp_3`=%d,"
  4220. "`slave_gp_4`=%d,"
  4221. "`slave_gp_5`=%d,"
  4222. "`slave_gp_6`=%d,"
  4223. "`slave_gp_7`=%d,"
  4224. "`slave_wp_0`=%d,"
  4225. "`slave_wp_1`=%d,"
  4226. "`slave_wp_2`=%d,"
  4227. "`slave_wp_3`=%d,"
  4228. "`slave_wp_4`=%d,"
  4229. "`slave_wp_5`=%d,"
  4230. "`slave_wp_6`=%d,"
  4231. "`slave_wp_7`=%d"
  4232. " WHERE `lrf_id`=%d",
  4233. ptr->HW_STATUS,
  4234. ptr->DETECTING_LRF,
  4235. ptr->TH_READY,
  4236. ptr->MASTER_FLIP_CNT,
  4237. ptr->SLAVE_FLIP_CNT,
  4238. ptr->TWINC_STATUS,
  4239. ptr->MASTER_MP[0],
  4240. ptr->MASTER_MP[1],
  4241. ptr->MASTER_MP[2],
  4242. ptr->MASTER_MP[3],
  4243. ptr->MASTER_MP[4],
  4244. ptr->MASTER_MP[5],
  4245. ptr->MASTER_MP[6],
  4246. ptr->MASTER_MP[7],
  4247. ptr->MASTER_GP[0],
  4248. ptr->MASTER_GP[1],
  4249. ptr->MASTER_GP[2],
  4250. ptr->MASTER_GP[3],
  4251. ptr->MASTER_GP[4],
  4252. ptr->MASTER_GP[5],
  4253. ptr->MASTER_GP[6],
  4254. ptr->MASTER_GP[7],
  4255. ptr->MASTER_WP[0],
  4256. ptr->MASTER_WP[1],
  4257. ptr->MASTER_WP[2],
  4258. ptr->MASTER_WP[3],
  4259. ptr->MASTER_WP[4],
  4260. ptr->MASTER_WP[5],
  4261. ptr->MASTER_WP[6],
  4262. ptr->MASTER_WP[7],
  4263. ptr->SLAVE_MP[0],
  4264. ptr->SLAVE_MP[1],
  4265. ptr->SLAVE_MP[2],
  4266. ptr->SLAVE_MP[3],
  4267. ptr->SLAVE_MP[4],
  4268. ptr->SLAVE_MP[5],
  4269. ptr->SLAVE_MP[6],
  4270. ptr->SLAVE_MP[7],
  4271. ptr->SLAVE_GP[0],
  4272. ptr->SLAVE_GP[1],
  4273. ptr->SLAVE_GP[2],
  4274. ptr->SLAVE_GP[3],
  4275. ptr->SLAVE_GP[4],
  4276. ptr->SLAVE_GP[5],
  4277. ptr->SLAVE_GP[6],
  4278. ptr->SLAVE_GP[7],
  4279. ptr->SLAVE_WP[0],
  4280. ptr->SLAVE_WP[1],
  4281. ptr->SLAVE_WP[2],
  4282. ptr->SLAVE_WP[3],
  4283. ptr->SLAVE_WP[4],
  4284. ptr->SLAVE_WP[5],
  4285. ptr->SLAVE_WP[6],
  4286. ptr->SLAVE_WP[7],
  4287. lrfID
  4288. );
  4289. #ifdef DEBUG_ALL
  4290. LOG(tQBuf);
  4291. #endif
  4292. m_pDatabase->SilentQuery( tQBuf );
  4293. return true;
  4294. };
  4295. return false;
  4296. };
  4297. bool argusDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  4298. if( m_bIsConnected ) {
  4299. char tQBuf[MAX_PATH_LEN];
  4300. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  4301. #ifdef DEBUG_ALL
  4302. LOG(tQBuf);
  4303. #endif
  4304. m_pDatabase->SilentQuery( tQBuf );
  4305. return true;
  4306. };
  4307. return false;
  4308. };
  4309. bool argusDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  4310. if( m_bIsConnected ) {
  4311. char tQBuf[MAX_PATH_LEN];
  4312. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  4313. #ifdef DEBUG_ALL
  4314. LOG(tQBuf);
  4315. #endif
  4316. m_pDatabase->SilentQuery( tQBuf );
  4317. return true;
  4318. };
  4319. return false;
  4320. };
  4321. bool argusDBC::setLRFMaskStatus( uint32_t maskID, bool status ){
  4322. if( m_bIsConnected ) {
  4323. char tQBuf[MAX_PATH_LEN];
  4324. char S[2];
  4325. if (status ) {
  4326. S[0] = 'E';
  4327. S[1] = (char)0;
  4328. } else {
  4329. S[0] = 'D';
  4330. S[1] = (char)0;
  4331. };
  4332. sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='%s' WHERE `id`=%d", S, maskID );
  4333. #ifdef DEBUG_ALL
  4334. LOG(tQBuf);
  4335. #endif
  4336. m_pDatabase->SilentQuery( tQBuf );
  4337. return true;
  4338. };
  4339. return false;
  4340. };
  4341. bool argusDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  4342. if( m_bIsConnected ) {
  4343. char tQBuf[MAX_PATH_LEN];
  4344. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  4345. #ifdef DEBUG_ALL
  4346. LOG(tQBuf);
  4347. #endif
  4348. m_pDatabase->SilentQuery( tQBuf );
  4349. return true;
  4350. };
  4351. return false;
  4352. };
  4353. bool argusDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  4354. if( m_bIsConnected ) {
  4355. char tQBuf[MAX_PATH_LEN];
  4356. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  4357. #ifdef DEBUG_ALL
  4358. LOG(tQBuf);
  4359. #endif
  4360. m_pDatabase->SilentQuery( tQBuf );
  4361. return true;
  4362. };
  4363. return false;
  4364. };
  4365. bool argusDBC::setStreamValid( uint32_t streamID, bool status ){
  4366. if( m_bIsConnected ) {
  4367. char tQBuf[MAX_PATH_LEN];
  4368. if ( status ) {
  4369. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID);
  4370. } else {
  4371. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `id`=%d", streamID);
  4372. };
  4373. #ifdef DEBUG_ALL
  4374. LOG(tQBuf);
  4375. #endif
  4376. m_pDatabase->SilentQuery( tQBuf );
  4377. return true;
  4378. };
  4379. return false;
  4380. };
  4381. bool argusDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
  4382. if( m_bIsConnected ) {
  4383. char tQBuf[MAX_PATH_LEN];
  4384. 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",
  4385. filterID,
  4386. Tag,
  4387. x,y,z,
  4388. x,y,z
  4389. );
  4390. #ifdef DEBUG_ALL
  4391. LOG(tQBuf);
  4392. #endif
  4393. m_pDatabase->SilentQuery( tQBuf );
  4394. return true;
  4395. };
  4396. return false;
  4397. };
  4398. DBC_MODULE_EMBED_VIDEO_DATA *argusDBC::getEmbedVideoData( uint32_t ID ){
  4399. DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL;
  4400. if( m_bIsConnected ) {
  4401. char tQBuf[MAX_PATH_LEN];
  4402. AAssoc *result;
  4403. sprintf( tQBuf, "SELECT * FROM `module_embed_video_settings` WHERE `id`=%d", ID );
  4404. #ifdef DEBUG_ALL
  4405. LOG(tQBuf);
  4406. #endif
  4407. result = m_pDatabase->Query( tQBuf );
  4408. if( result!= NULL ) {
  4409. if( result->size() > 0 ) {
  4410. Assoc *cArr;
  4411. tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  4412. if( tPtr!= NULL ) {
  4413. Assoc::iterator it;
  4414. memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  4415. cArr = result->at(0);
  4416. it = cArr->find("web_port");
  4417. if( it != cArr->end() ){
  4418. tPtr->port = atoi( it->second.c_str() );
  4419. };
  4420. it = cArr->find("width");
  4421. if( it != cArr->end() ){
  4422. tPtr->width = atoi( it->second.c_str() );
  4423. };
  4424. it = cArr->find("height");
  4425. if( it != cArr->end() ){
  4426. tPtr->height = atoi( it->second.c_str() );
  4427. };
  4428. it = cArr->find("compression_quality");
  4429. if( it != cArr->end() ){
  4430. tPtr->compression_quality = atoi( it->second.c_str() );
  4431. };
  4432. it = cArr->find("show_ts");
  4433. if( it != cArr->end() ){
  4434. tPtr->show_ts = (bool)atoi( it->second.c_str() );
  4435. };
  4436. it = cArr->find("ts_x");
  4437. if( it != cArr->end() ){
  4438. tPtr->ts_x = atoi( it->second.c_str() );
  4439. };
  4440. it = cArr->find("ts_y");
  4441. if( it != cArr->end() ){
  4442. tPtr->ts_y = atoi( it->second.c_str() );
  4443. };
  4444. it = cArr->find("ts_font_face");
  4445. if( it != cArr->end() ){
  4446. tPtr->ts_font_face = atoi( it->second.c_str() );
  4447. };
  4448. it = cArr->find("ts_font_scale");
  4449. if( it != cArr->end() ){
  4450. tPtr->ts_font_scale = atof( it->second.c_str() );
  4451. };
  4452. it = cArr->find("ts_font_thickness");
  4453. if( it != cArr->end() ){
  4454. tPtr->ts_font_thickness = atoi( it->second.c_str() );
  4455. };
  4456. it = cArr->find("ts_line_type");
  4457. if( it != cArr->end() ){
  4458. tPtr->ts_line_type = atoi( it->second.c_str() );
  4459. };
  4460. it = cArr->find("ts_transperant");
  4461. if( it != cArr->end() ){
  4462. tPtr->ts_transperant = (bool)atoi( it->second.c_str() );
  4463. };
  4464. it = cArr->find("show_label");
  4465. if( it != cArr->end() ){
  4466. tPtr->show_label = (bool)atoi( it->second.c_str() );
  4467. };
  4468. it = cArr->find("label_x");
  4469. if( it != cArr->end() ){
  4470. tPtr->label_x = atoi( it->second.c_str() );
  4471. };
  4472. it = cArr->find("label_y");
  4473. if( it != cArr->end() ){
  4474. tPtr->label_y = atoi( it->second.c_str() );
  4475. };
  4476. it = cArr->find("label_font_face");
  4477. if( it != cArr->end() ){
  4478. tPtr->label_font_face = atoi( it->second.c_str() );
  4479. };
  4480. it = cArr->find("label_font_scale");
  4481. if( it != cArr->end() ){
  4482. tPtr->label_font_scale = atof( it->second.c_str() );
  4483. };
  4484. it = cArr->find("label_font_thickness");
  4485. if( it != cArr->end() ){
  4486. tPtr->label_font_thickness = atoi( it->second.c_str() );
  4487. };
  4488. it = cArr->find("label_line_type");
  4489. if( it != cArr->end() ){
  4490. tPtr->label_line_type = atoi( it->second.c_str() );
  4491. };
  4492. it = cArr->find("label_transperant");
  4493. if( it != cArr->end() ){
  4494. tPtr->label_transperant = (bool) atoi( it->second.c_str() );
  4495. };
  4496. it = cArr->find("show_logo");
  4497. if( it != cArr->end() ){
  4498. tPtr->show_logo = (bool) atoi( it->second.c_str() );
  4499. };
  4500. it = cArr->find("logo_w");
  4501. if( it != cArr->end() ){
  4502. tPtr->logo_w = atoi( it->second.c_str() );
  4503. };
  4504. it = cArr->find("logo_h");
  4505. if( it != cArr->end() ){
  4506. tPtr->logo_h = atoi( it->second.c_str() );
  4507. };
  4508. it = cArr->find("logo_x");
  4509. if( it != cArr->end() ){
  4510. tPtr->logo_x = atoi( it->second.c_str() );
  4511. };
  4512. it = cArr->find("logo_y");
  4513. if( it != cArr->end() ){
  4514. tPtr->logo_y = atoi( it->second.c_str() );
  4515. };
  4516. it = cArr->find("logo_md5");
  4517. if( it != cArr->end() ){
  4518. strncpy( tPtr->logo_md5, it->second.c_str(),32);
  4519. tPtr->logo_md5[32]=(char)0;
  4520. };
  4521. };
  4522. };
  4523. };
  4524. deleteResult( result );
  4525. };
  4526. return tPtr;
  4527. };
  4528. DBC_EVT_RECORD *argusDBC::getEventByUUID( CSTR UUID ){
  4529. DBC_EVT_RECORD *tPtr = NULL;
  4530. if( m_bIsConnected ) {
  4531. char tQBuf[MAX_PATH_LEN];
  4532. AAssoc *result;
  4533. sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
  4534. #ifdef DEBUG_ALL
  4535. LOG(tQBuf);
  4536. #endif
  4537. result = m_pDatabase->Query( tQBuf );
  4538. if( result!= NULL ) {
  4539. if( result->size() > 0 ) {
  4540. Assoc *cArr;
  4541. tPtr = (DBC_EVT_RECORD*)malloc(sizeof(DBC_EVT_RECORD));
  4542. if( tPtr!= NULL ) {
  4543. Assoc::iterator it;
  4544. memset(tPtr,0,sizeof(DBC_EVT_RECORD));
  4545. cArr = result->at(0);
  4546. it = cArr->find("id");
  4547. if( it != cArr->end() ){
  4548. tPtr->id = atoi( it->second.c_str() );
  4549. };
  4550. it = cArr->find("node_id");
  4551. if( it != cArr->end() ){
  4552. tPtr->node_id = atoi( it->second.c_str() );
  4553. };
  4554. it = cArr->find("uuid");
  4555. if( it != cArr->end() ){
  4556. strncpy( tPtr->uuid, it->second.c_str(),64 );
  4557. };
  4558. it = cArr->find("ts");
  4559. if( it != cArr->end() ){
  4560. tPtr->ts_s = atoi( it->second.c_str() );
  4561. };
  4562. it = cArr->find("ts_ms");
  4563. if( it != cArr->end() ){
  4564. tPtr->ts_ms = atoi( it->second.c_str() );
  4565. };
  4566. it = cArr->find("evt_type");
  4567. if( it != cArr->end() ){
  4568. tPtr->type = atoi( it->second.c_str() );
  4569. };
  4570. it = cArr->find("range_digital");
  4571. if( it != cArr->end() ){
  4572. tPtr->range_digital = atoi( it->second.c_str() );
  4573. };
  4574. it = cArr->find("azimuth");
  4575. if( it != cArr->end() ){
  4576. tPtr->az = atof( it->second.c_str() );
  4577. };
  4578. it = cArr->find("elevation");
  4579. if( it != cArr->end() ){
  4580. tPtr->el = atof( it->second.c_str() );
  4581. };
  4582. it = cArr->find("range");
  4583. if( it != cArr->end() ){
  4584. tPtr->ra = atof( it->second.c_str() );
  4585. };
  4586. it = cArr->find("area");
  4587. if( it != cArr->end() ){
  4588. tPtr->area = atof( it->second.c_str() );
  4589. };
  4590. it = cArr->find("lat");
  4591. if( it != cArr->end() ){
  4592. tPtr->lat = atof( it->second.c_str() );
  4593. };
  4594. it = cArr->find("lon");
  4595. if( it != cArr->end() ){
  4596. tPtr->lon = atof( it->second.c_str() );
  4597. };
  4598. it = cArr->find("alt");
  4599. if( it != cArr->end() ){
  4600. tPtr->alt = atof( it->second.c_str() );
  4601. };
  4602. it = cArr->find("ref_id");
  4603. if( it != cArr->end() ){
  4604. tPtr->ref_id = atoi( it->second.c_str() );
  4605. };
  4606. it = cArr->find("ref_uuid");
  4607. if( it != cArr->end() ){
  4608. strncpy( tPtr->ref_uuid, it->second.c_str(),64 );
  4609. };
  4610. };
  4611. };
  4612. };
  4613. deleteResult( result );
  4614. };
  4615. return tPtr;
  4616. };
  4617. #undef LOG
  4618. #undef LOG_ERROR