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.

2449 lines
72 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "bosch_rcp.h"
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <sys/types.h> /* See NOTES */
  7. #include <sys/types.h>
  8. #define LOG(X) m_pLog->Log("pBRCP", this, X)
  9. #define TLOG(X) basicLogCollection::getInstance()->Log("pBRCP_T", NULL, X)
  10. #ifdef DEBUG
  11. #define LOG_ERROR(X) \
  12. { \
  13. char _tBfrErrMSG2w34[512]; \
  14. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  15. m_pLog->Log("pBRCP", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  16. }
  17. #else
  18. #define LOG_ERROR(X) m_pLog->Log("pBRCP", this, _LOG_ERROR, X);
  19. #endif
  20. inline bool checkBool(const char * A)
  21. {
  22. if (A == NULL)
  23. {
  24. return false;
  25. }
  26. return (A[0] == 'T' || A[0] == 't' || A[0] == '1');
  27. }
  28. inline bool checkOnOff(const char * A)
  29. {
  30. if (A == NULL)
  31. {
  32. return false;
  33. }
  34. return (A[1] == 'N' || A[1] == 'n' || A[0] == '1');
  35. }
  36. inline onvifOnOffAuto checkOnOffAuto(const char * A)
  37. {
  38. if (A == NULL)
  39. {
  40. return AUTO;
  41. }
  42. if (A[1] == 'N' || A[1] == 'n' || A[0] == '1')
  43. {
  44. return ON;
  45. }
  46. return OFF;
  47. }
  48. boschRCP::boschRCP()
  49. {
  50. m_pLog = basicLogCollection::getInstance();
  51. m_pIpAddress = NULL;
  52. m_pUsername = NULL;
  53. m_pPassword = NULL;
  54. m_pMediaURI = NULL;
  55. m_pSnapshotURI = NULL;
  56. m_pDeviceURI = NULL;
  57. m_pPTZURI = NULL;
  58. m_pBaseURI = NULL;
  59. m_nDeltaTime = 0;
  60. m_pCURL = NULL;
  61. m_pProxyHost = NULL;
  62. m_nProxyPort = 0;
  63. m_pProxyUsername = NULL;
  64. m_pProxyPassword = NULL;
  65. m_pLastResponse = NULL;
  66. m_bIntransingent = true;
  67. m_nDiscoveryTimeout = 30;//PONVIF_DEFAULT_DISCOVERYTIMEOUT;
  68. m_pDiscoveryBindIP = NULL; // PONVIF_DEFAULT_DISCOVERYBINDIP;
  69. m_pDiscoveryMCastIP = NULL; // PONVIF_DEFAULT_DISCOVERYMCASTIP;
  70. m_nDiscoveryMCastPort = 30;//PONVIF_DEFAULT_DISCOVERYMCASTPORT;
  71. m_bDiscoveryHideDuplicates = true;
  72. m_pHttpAccessManager = NULL;
  73. m_sCapabilities.Analytics = NULL;
  74. m_sCapabilities.Device = NULL;
  75. m_sCapabilities.Events = NULL;
  76. m_sCapabilities.Imaging = NULL;
  77. m_sCapabilities.Media = NULL;
  78. m_sCapabilities.PTZ = NULL;
  79. m_sCapabilities.Extension = NULL;
  80. m_bAuthMode = 0;
  81. LOG("Constructor Done!");
  82. }
  83. boschRCP::~boschRCP()
  84. {
  85. #ifdef DEBUG
  86. LOG("Destructor begin");
  87. #endif
  88. if (m_pIpAddress)
  89. {
  90. free(m_pIpAddress);
  91. }
  92. if (m_pUsername)
  93. {
  94. free(m_pUsername);
  95. }
  96. if (m_pPassword)
  97. {
  98. free(m_pPassword);
  99. }
  100. if (m_pMediaURI)
  101. {
  102. free(m_pMediaURI);
  103. }
  104. if (m_pSnapshotURI)
  105. {
  106. free(m_pSnapshotURI);
  107. }
  108. if (m_pDeviceURI)
  109. {
  110. free(m_pDeviceURI);
  111. }
  112. if (m_pPTZURI)
  113. {
  114. free(m_pPTZURI);
  115. }
  116. if (m_pBaseURI)
  117. {
  118. free(m_pBaseURI);
  119. }
  120. if (m_pProxyHost)
  121. {
  122. free(m_pProxyHost);
  123. }
  124. if (m_pProxyUsername)
  125. {
  126. free(m_pProxyUsername);
  127. }
  128. if (m_pProxyPassword)
  129. {
  130. free(m_pProxyPassword);
  131. }
  132. if (m_pLastResponse)
  133. {
  134. free(m_pLastResponse);
  135. }
  136. if (m_pDiscoveryBindIP)
  137. {
  138. free(m_pDiscoveryBindIP);
  139. }
  140. if (m_pDiscoveryMCastIP)
  141. {
  142. free(m_pDiscoveryMCastIP);
  143. }
  144. if (m_sCapabilities.Analytics)
  145. {
  146. free(m_sCapabilities.Analytics);
  147. }
  148. if (m_sCapabilities.Device)
  149. {
  150. free(m_sCapabilities.Device);
  151. }
  152. if (m_sCapabilities.Events)
  153. {
  154. free(m_sCapabilities.Events);
  155. }
  156. if (m_sCapabilities.Imaging)
  157. {
  158. free(m_sCapabilities.Imaging);
  159. }
  160. if (m_sCapabilities.Media)
  161. {
  162. free(m_sCapabilities.Media);
  163. }
  164. if (m_sCapabilities.PTZ)
  165. {
  166. free(m_sCapabilities.PTZ);
  167. }
  168. if (m_sCapabilities.Extension)
  169. {
  170. free(m_sCapabilities.Extension);
  171. }
  172. if (m_pCURL)
  173. {
  174. #ifdef DEBUG
  175. LOG("Try Cleanup CURL!");
  176. #endif
  177. curl_easy_cleanup(m_pCURL);
  178. m_pCURL = NULL;
  179. };
  180. #ifdef DEBUG
  181. LOG("Destructor Done!");
  182. #endif
  183. }
  184. bool boschRCP::setProxyHost(CSTR proxyHost)
  185. {
  186. if (m_pProxyHost != NULL)
  187. {
  188. free(m_pProxyHost);
  189. }
  190. if (proxyHost == NULL || strlen(proxyHost) == 0)
  191. {
  192. m_pProxyHost = NULL;
  193. return true;
  194. };
  195. m_pProxyHost = (CSTR) malloc(strlen(proxyHost) + 1);
  196. if (m_pProxyHost == NULL)
  197. {
  198. return false;
  199. }
  200. memcpy(m_pProxyHost, proxyHost, strlen(proxyHost) + 1);
  201. return true;
  202. }
  203. CSTR boschRCP::getProxyHost()
  204. {
  205. return m_pProxyHost;
  206. }
  207. bool boschRCP::setProxyPort(int proxyPort)
  208. {
  209. m_nProxyPort = proxyPort;
  210. return true;
  211. }
  212. int boschRCP::getProxyPort(void)
  213. {
  214. return m_nProxyPort;
  215. }
  216. bool boschRCP::setProxyUsername(CSTR proxyUsername)
  217. {
  218. if (m_pProxyUsername != NULL)
  219. {
  220. free(m_pProxyUsername);
  221. }
  222. if (proxyUsername == NULL || strlen(proxyUsername) == 0)
  223. {
  224. m_pProxyUsername = NULL;
  225. return true;
  226. };
  227. m_pProxyUsername = (CSTR) malloc(strlen(proxyUsername) + 1);
  228. if (m_pProxyUsername == NULL)
  229. {
  230. return false;
  231. }
  232. memcpy(m_pProxyUsername, proxyUsername, strlen(proxyUsername) + 1);
  233. return true;
  234. }
  235. CSTR boschRCP::getProxyUsername(void)
  236. {
  237. return m_pProxyUsername;
  238. }
  239. bool boschRCP::setProxyPassword(CSTR proxyPassword)
  240. {
  241. if (m_pProxyPassword != NULL)
  242. {
  243. free(m_pProxyPassword);
  244. }
  245. if (proxyPassword == NULL || strlen(proxyPassword) == 0)
  246. {
  247. m_pProxyPassword = NULL;
  248. return true;
  249. };
  250. m_pProxyPassword = (CSTR) malloc(strlen(proxyPassword) + 1);
  251. if (m_pProxyPassword == NULL)
  252. {
  253. return false;
  254. }
  255. memcpy(m_pProxyPassword, proxyPassword, strlen(proxyPassword) + 1);
  256. return true;
  257. }
  258. CSTR boschRCP::getProxyPassword()
  259. {
  260. return m_pProxyPassword;
  261. }
  262. bool boschRCP::setUsername(CSTR username)
  263. {
  264. if (m_pUsername != NULL)
  265. {
  266. free(m_pUsername);
  267. }
  268. if (username == NULL || strlen(username) == 0)
  269. {
  270. m_pUsername = NULL;
  271. return true;
  272. };
  273. m_pUsername = (CSTR) malloc(strlen(username) + 1);
  274. if (m_pUsername == NULL)
  275. {
  276. return false;
  277. }
  278. memcpy(m_pUsername, username, strlen(username) + 1);
  279. return true;
  280. }
  281. CSTR boschRCP::getUsername(void)
  282. {
  283. return m_pUsername;
  284. }
  285. bool boschRCP::setPassword(CSTR password)
  286. {
  287. if (m_pPassword != NULL)
  288. {
  289. free(m_pPassword);
  290. }
  291. if (password == NULL || strlen(password) == 0)
  292. {
  293. m_pPassword = NULL;
  294. return true;
  295. };
  296. m_pPassword = (CSTR) malloc(strlen(password) + 1);
  297. if (m_pPassword == NULL)
  298. {
  299. return false;
  300. }
  301. memcpy(m_pPassword, password, strlen(password) + 1);
  302. return true;
  303. }
  304. CSTR boschRCP::getPassword(void)
  305. {
  306. return m_pPassword;
  307. }
  308. CSTR boschRCP::getDeviceUri(void)
  309. {
  310. return m_pDeviceURI;
  311. }
  312. bool boschRCP::setDeviceUri(CSTR deviceUri)
  313. {
  314. if (deviceUri == NULL || strlen(deviceUri) == 0)
  315. {
  316. m_pDeviceURI = NULL;
  317. return false;
  318. };
  319. if (strstr(deviceUri, "http") == NULL)
  320. {
  321. LOG_ERROR("Malformed device URI");
  322. return false;
  323. };
  324. if (m_pDeviceURI != NULL)
  325. {
  326. free(m_pDeviceURI);
  327. }
  328. m_pDeviceURI = (CSTR) malloc(strlen(deviceUri) + 1);
  329. if (m_pDeviceURI == NULL)
  330. {
  331. return false;
  332. }
  333. memcpy(m_pDeviceURI, deviceUri, strlen(deviceUri));
  334. m_pDeviceURI[strlen(deviceUri)] = (char) 0;
  335. // toDo: Must parsed Host/IP
  336. char * tT = strstr(m_pDeviceURI, "/");
  337. if (tT)
  338. {
  339. tT += 2;
  340. char * tB = strstr(tT, "/");
  341. int len = tB - tT + 1;
  342. m_pIpAddress = (CSTR) malloc(len);
  343. if (m_pIpAddress)
  344. {
  345. len--;
  346. memcpy(m_pIpAddress, tT, len);
  347. m_pIpAddress[len] = (char) 0;
  348. LOG(m_pIpAddress);
  349. };
  350. };
  351. return true;
  352. }
  353. CSTR boschRCP::getIPAddress(void)
  354. {
  355. return m_pIpAddress;
  356. }
  357. bool boschRCP::setIPAddress(CSTR ipAddress)
  358. {
  359. if (ipAddress == NULL || strlen(ipAddress) == 0)
  360. {
  361. m_pIpAddress = NULL;
  362. return false;
  363. };
  364. if (m_pIpAddress != NULL)
  365. {
  366. free(m_pIpAddress);
  367. }
  368. m_pIpAddress = (CSTR) malloc(strlen(ipAddress) + 1);
  369. if (m_pIpAddress == NULL)
  370. {
  371. return false;
  372. }
  373. memcpy(m_pIpAddress, ipAddress, strlen(ipAddress));
  374. m_pIpAddress[strlen(ipAddress)] = (char) 0;
  375. // ToDo: Must be created URI ... sprintf(tURL, "http://%s/onvif/device_service", m_pIpAddress);
  376. int len = strlen(ipAddress) + 28;
  377. m_pDeviceURI = (CSTR) malloc(len + 1);
  378. if (m_pDeviceURI)
  379. {
  380. sprintf(m_pDeviceURI, "http://%s/onvif/device_service", m_pIpAddress);
  381. LOG(m_pDeviceURI);
  382. };
  383. return true;
  384. }
  385. videoSources * boschRCP::getSources(void)
  386. {
  387. return &m_vVideoSources;
  388. }
  389. videoSourceProfiles * boschRCP::getProfiles(void)
  390. {
  391. return &m_vVideoProfiles;
  392. }
  393. videoSourceProfiles * boschRCP::getActiveProfiles(void)
  394. {
  395. return &m_vActiveSources;
  396. }
  397. CSTR boschRCP::getMediaUri(void)
  398. {
  399. return m_pMediaURI;
  400. }
  401. CSTR boschRCP::getPTZUri(void)
  402. {
  403. return m_pPTZURI;
  404. }
  405. CSTR boschRCP::getBaseUrl(void)
  406. {
  407. return m_pBaseURI;
  408. }
  409. void boschRCP::getSupportedVersion(void) {}
  410. nodeCapability * boschRCP::getCapabilities(void)
  411. {
  412. return &m_sCapabilities;
  413. }
  414. bool boschRCP::setBreakOnError(bool intransingent)
  415. {
  416. m_bIntransingent = intransingent;
  417. return true;
  418. }
  419. CSTR boschRCP::getLastResponse(void)
  420. {
  421. return m_pLastResponse;
  422. }
  423. bool boschRCP::setDiscoveryTimeout(int discoverytimeout)
  424. {
  425. m_nDiscoveryTimeout = discoverytimeout;
  426. return true;
  427. }
  428. bool boschRCP::setDiscoveryBindIp(CSTR discoverybindip)
  429. {
  430. if (m_pDiscoveryBindIP != NULL)
  431. {
  432. free(m_pDiscoveryBindIP);
  433. }
  434. if (discoverybindip == NULL || strlen(discoverybindip) == 0)
  435. {
  436. m_pDiscoveryBindIP = NULL;
  437. return true;
  438. };
  439. m_pDiscoveryBindIP = (CSTR) malloc(strlen(discoverybindip) + 1);
  440. if (m_pDiscoveryBindIP == NULL)
  441. {
  442. return false;
  443. }
  444. memcpy(m_pDiscoveryBindIP, discoverybindip, strlen(discoverybindip) + 1);
  445. return true;
  446. }
  447. bool boschRCP::setDiscoveryMcastIp(CSTR discoverymcastip)
  448. {
  449. if (m_pDiscoveryMCastIP != NULL)
  450. {
  451. free(m_pDiscoveryMCastIP);
  452. }
  453. if (discoverymcastip == NULL || strlen(discoverymcastip) == 0)
  454. {
  455. m_pDiscoveryMCastIP = NULL;
  456. return true;
  457. };
  458. m_pDiscoveryMCastIP = (CSTR) malloc(strlen(discoverymcastip) + 1);
  459. if (m_pDiscoveryMCastIP == NULL)
  460. {
  461. return false;
  462. }
  463. memcpy(m_pDiscoveryMCastIP, discoverymcastip, strlen(discoverymcastip) + 1);
  464. return true;
  465. }
  466. bool boschRCP::setDiscoveryMcastPort(int discoverymcastport)
  467. {
  468. m_nDiscoveryMCastPort = discoverymcastport;
  469. return true;
  470. }
  471. bool boschRCP::setDiscoveryHideDuplicates(bool discoveryhideduplicates)
  472. {
  473. m_bDiscoveryHideDuplicates = discoveryhideduplicates;
  474. return true;
  475. }
  476. CSTR boschRCP::getSnapshotUri(void)
  477. {
  478. return m_pSnapshotURI;
  479. }
  480. /*
  481. WS-Discovery
  482. https://www.geeksforgeeks.org/udp-server-client-implementation-c/
  483. */
  484. discoveryResults boschRCP::discover(void)
  485. {
  486. discoveryResults RetVal;
  487. time_t tTimeout = time(NULL) + m_nDiscoveryTimeout;
  488. CSTR tPostString = PONVIF_PACK_DISCOVERY;
  489. struct sockaddr_in tSockAddr;
  490. struct hostent * h_info;
  491. #ifdef __linux__
  492. int tSocket;
  493. #else
  494. int tSocket;
  495. #endif
  496. int RetCode;
  497. char Response[DEFAULT_BUFFER_SIZE];
  498. try
  499. {
  500. // SOL_UDP = 17
  501. tSocket = socket(AF_INET, SOCK_DGRAM, 0);
  502. if (tSocket < 0)
  503. {
  504. LOG_ERROR("ERROR creating socket");
  505. return RetVal;
  506. };
  507. LOG("Socket Created!");
  508. memset(&tSockAddr, 0, sizeof(struct sockaddr_in));
  509. h_info = gethostbyname(m_pDiscoveryBindIP);
  510. if (h_info == NULL)
  511. {
  512. LOG_ERROR("Some throuble with networking on this machine (Cannot Get Hostname)!");
  513. return RetVal;
  514. };
  515. LOG("Host Found!");
  516. //*****************************************
  517. //* there we building our network address *
  518. //*****************************************
  519. memcpy(h_info->h_addr, &(tSockAddr.sin_addr), h_info->h_length);
  520. tSockAddr.sin_family = h_info->h_addrtype;
  521. tSockAddr.sin_port = htons(20000 + (20000 * rand()) / RAND_MAX);
  522. RetCode = bind(tSocket, (const sockaddr *) &tSockAddr, sizeof(struct sockaddr_in));
  523. if (RetCode != 0)
  524. {
  525. LOG_ERROR("Error Binding to Port/Address");
  526. return RetVal;
  527. };
  528. LOG("Binding Done!");
  529. #ifdef __linux__
  530. // setsockopt( tSocket, IPPROTO_IP, MCAST_JOIN_GROUP, );
  531. int tVal = 1;
  532. setsockopt(tSocket, SOL_SOCKET, SO_BROADCAST, &tVal, sizeof(int));
  533. // socket_sendto($sock, $post_string, strlen(tPostString), 0, $this->discoverymcastip, $this->discoverymcastport);
  534. sendto(tSocket, tPostString, strlen(tPostString), 0, (const sockaddr *) &tSockAddr, sizeof(struct sockaddr_in));
  535. LOG("Broadcast Ping Sent!");
  536. fcntl(tSocket, F_SETFL, fcntl(tSocket, F_GETFL, 0) | O_NONBLOCK);
  537. LOG("Socket Set Not Bloking Mode!");
  538. #else
  539. // setsockopt( tSocket, IPPROTO_IP, MCAST_JOIN_GROUP, );
  540. bool tVal = 1;
  541. setsockopt(tSocket, SOL_SOCKET, SO_BROADCAST, (const char *) &tVal, sizeof(bool));
  542. // socket_sendto($sock, $post_string, strlen(tPostString), 0, $this->discoverymcastip, $this->discoverymcastport);
  543. sendto(tSocket, tPostString, strlen(tPostString), 0, (const sockaddr *) &tSockAddr, sizeof(struct sockaddr_in));
  544. LOG("Broadcast Ping Sent!");
  545. u_long arg = 1;
  546. if (ioctlsocket(tSocket, FIONBIO, &arg) < 0)
  547. {
  548. char tBuf[128];
  549. sprintf(tBuf, "Error ioctlsocket(..., FIONBIO) (%s)", strerror(errno));
  550. LOG_ERROR(tBuf);
  551. return RetVal;
  552. };
  553. #endif
  554. while (time(NULL) < tTimeout)
  555. {
  556. // n = recvfrom(sockfd, (char *)buffer, MAXLINE, MSG_WAITALL, (struct sockaddr *) &servaddr, &len);
  557. tVal = recvfrom(tSocket, Response, DEFAULT_BUFFER_SIZE, 0, NULL, NULL);
  558. if (tVal > 0)
  559. {
  560. Response[tVal] = '\0';
  561. // if( FALSE !== socket_recvfrom( $sock, $response, 9999, 0, $from, $this->discoverymcastport )){
  562. // if( Response != NULL && $response != $post_string){
  563. LOG(Response);
  564. XMLNode node = XMLNode::parseString(Response, "root");
  565. //$response = $this->_xml2array($response);
  566. // if(!isFault( node )){
  567. //$response['Envelope']['Body']['ProbeMatches']['ProbeMatch']['IPAddr'] = $from;
  568. if (m_bDiscoveryHideDuplicates)
  569. {
  570. // $result[$from] = $response['Envelope']['Body']['ProbeMatches']['ProbeMatch'];
  571. }
  572. else
  573. {
  574. // $result[] = $response['Envelope']['Body']['ProbeMatches']['ProbeMatch'];
  575. };
  576. // };
  577. //};
  578. //};
  579. };
  580. };
  581. #ifdef __linux__
  582. close(tSocket);
  583. #else
  584. closesocket(tSocket);
  585. #endif
  586. }
  587. catch ( const std::exception& e)
  588. {
  589. LOG_ERROR("Communication at Discovery Exception Catched!");
  590. };
  591. return RetVal;
  592. }
  593. /*
  594. Public functions (basic initialization method and other collaterals)
  595. */
  596. bool boschRCP::create(void)
  597. {
  598. #ifdef DEBUG_EXTRA
  599. LOG("Get Instance m_pHttpAccessManager");
  600. #endif
  601. m_pHttpAccessManager = curlRequestsManager::getInstance();
  602. if (m_pHttpAccessManager == NULL)
  603. {
  604. return false;
  605. }
  606. #ifdef DEBUG_EXTRA
  607. LOG("CURL MANAGER OK");
  608. #endif
  609. try
  610. {
  611. struct tm * tTS;
  612. tTS = core_GetSystemDateAndTime();
  613. // This is UTS DTS
  614. if (tTS != NULL)
  615. {
  616. #ifdef DEBUG
  617. char tB[128];
  618. sprintf(tB, "TS from dev: %04d-%02d-%02d %02d:%02d:%02d", tTS->tm_year, tTS->tm_mon, tTS->tm_mday, tTS->tm_hour, tTS->tm_min, tTS->tm_sec);
  619. LOG(tB);
  620. #endif
  621. // WTF ??!!
  622. tTS->tm_year -= 1900;
  623. tTS->tm_mon -= 1;
  624. time_t tTimeStamp = timegm(tTS); // mktime( tTS );
  625. m_nDeltaTime = time(NULL) - tTimeStamp;
  626. #ifdef DEBUG
  627. sprintf(tB, "TS:[%ld] D:[%ld]", tTimeStamp, m_nDeltaTime);
  628. LOG(tB);
  629. #endif
  630. free(tTS);
  631. }
  632. else
  633. {
  634. return false;
  635. }
  636. }
  637. catch (const std::exception& e)
  638. {
  639. LOG_ERROR("Catched Exception!");
  640. return false;
  641. };
  642. if (! core_GetCapabilities())
  643. {
  644. LOG_ERROR("Error Getting Caps!");
  645. return false;
  646. };
  647. _getOnvifVersion(m_sCapabilities);
  648. // Update some Vars Online!
  649. // preg_match("/^http(.*)onvif\//",$this->mediauri,$matches);
  650. // m_pBaseURI = $matches[0];
  651. if (media_GetVideoSources())
  652. {
  653. if (media_GetProfiles())
  654. {
  655. //_getActiveSources( m_vVideoSources, m_vVideoProfiles);
  656. return true;
  657. };
  658. };
  659. LOG_ERROR("Error Profiles!");
  660. return false;
  661. }
  662. /*
  663. Public wrappers for a subset of ONVIF primitives
  664. */
  665. struct tm * boschRCP::core_GetSystemDateAndTime(void)
  666. {
  667. struct tm * RetVal = NULL;
  668. char tURL[CTEXT];
  669. if (m_pDeviceURI != NULL)
  670. {
  671. sprintf(tURL, m_pDeviceURI);
  672. }
  673. else
  674. {
  675. if (m_pIpAddress != NULL)
  676. {
  677. sprintf(tURL, "http://%s/onvif/device_service", m_pIpAddress);
  678. }
  679. else
  680. {
  681. return NULL;
  682. };
  683. };
  684. #ifdef DEBUG_EXTRA
  685. LOG("Before REQ");
  686. #endif
  687. if (_send_request(tURL, PONVIF_PACK_GET_SYS_DTS, true))
  688. {
  689. XMLResults tParseResults;
  690. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  691. #ifdef DEBUG_EXTRA
  692. LOG("core_GetSystemDateAndTime");
  693. #endif
  694. if (tParseResults.error)
  695. {
  696. char tBuffer[CTEXT];
  697. sprintf(tBuffer, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  698. LOG_ERROR(tBuffer);
  699. }
  700. else
  701. {
  702. RetVal = (struct tm *) malloc(sizeof(struct tm));
  703. if (RetVal != NULL)
  704. {
  705. memset(RetVal, 0, sizeof(struct tm));
  706. XMLNode zNode = response.getChildNode("Body", 0);
  707. if (! zNode.isEmpty())
  708. {
  709. XMLNode fNode = zNode.getChildNode("GetSystemDateAndTimeResponse", 0);
  710. if (! fNode.isEmpty())
  711. {
  712. XMLNode hNode = fNode.getChildNode("SystemDateAndTime", 0);
  713. if (! hNode.isEmpty())
  714. {
  715. XMLNode tNode = hNode.getChildNode("UTCDateTime", 0);
  716. if (! tNode.isEmpty())
  717. {
  718. RetVal->tm_isdst = 0;
  719. XMLNode ttNode = tNode.getChildNode("Time", 0);
  720. XMLNode dtNode = tNode.getChildNode("Date", 0);
  721. {
  722. XMLNode t = ttNode.getChildNode("Hour", 0);
  723. RetVal->tm_hour = atoi(t.getText(0));
  724. }
  725. {
  726. XMLNode t = ttNode.getChildNode("Minute", 0);
  727. RetVal->tm_min = atoi(t.getText(0));
  728. }
  729. {
  730. XMLNode t = ttNode.getChildNode("Second", 0);
  731. RetVal->tm_sec = atoi(t.getText(0));
  732. }
  733. {
  734. XMLNode t = dtNode.getChildNode("Year", 0);
  735. RetVal->tm_year = atoi(t.getText(0));
  736. }
  737. {
  738. XMLNode t = dtNode.getChildNode("Month", 0);
  739. RetVal->tm_mon = atoi(t.getText(0));
  740. }
  741. {
  742. XMLNode t = dtNode.getChildNode("Day", 0);
  743. RetVal->tm_mday = atoi(t.getText(0));
  744. }
  745. }
  746. else
  747. {
  748. LOG_ERROR("UTCDateTime is Not Found!");
  749. };
  750. }
  751. else
  752. {
  753. LOG_ERROR("SystemDateAndTime is Not Found!");
  754. };
  755. }
  756. else
  757. {
  758. LOG_ERROR("GetSystemDateAndTimeResponse is Not Found!");
  759. };
  760. }
  761. else
  762. {
  763. LOG_ERROR("Body is Not Found!");
  764. LOG(m_pLastResponse);
  765. };
  766. };
  767. return RetVal;
  768. };
  769. }
  770. else
  771. {
  772. LOG_ERROR("GetSystemDateAndTime: Communication error");
  773. }
  774. return NULL;
  775. }
  776. // Based on https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl
  777. bool boschRCP::core_GetCapabilities(void)
  778. {
  779. char tBuffer[DEFAULT_BUFFER_SIZE];
  780. accessToken tTOKEN;
  781. tTOKEN = _makeToken();
  782. char tURL[CTEXT];
  783. if (m_pDeviceURI != NULL)
  784. {
  785. sprintf(tURL, m_pDeviceURI);
  786. }
  787. else
  788. {
  789. if (m_pIpAddress != NULL)
  790. {
  791. sprintf(tURL, "http://%s/onvif/device_service", m_pIpAddress);
  792. }
  793. else
  794. {
  795. return NULL;
  796. };
  797. };
  798. // char tSTR[CTEXT];
  799. sprintf(tBuffer, PONVIF_PACK_GET_CAPABILITIES, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP);
  800. // sprintf( tSTR, PONVIF_PCK_GET_CAPABILITIES, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP );
  801. // build_package( tBuffer, PONVIF_ENVELOPE_SIM, tSTR );
  802. if (_send_request(tURL, tBuffer))
  803. {
  804. XMLResults tParseResults;
  805. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  806. #ifdef DEBUG_ONVIF_PRINTOUT_MESSAGES
  807. LOG("RCPT:");
  808. printf(m_pLastResponse);
  809. #endif
  810. if (tParseResults.error != eXMLErrorNone)
  811. {
  812. char tBuf[CTEXT];
  813. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  814. LOG_ERROR(tBuf);
  815. }
  816. else
  817. {
  818. XMLNode zNode = response.getChildNode("Body", 0);
  819. if (zNode.isEmpty())
  820. {
  821. return false;
  822. }
  823. XMLNode tNode = zNode.getChildNode("GetCapabilitiesResponse", 0);
  824. if (! tNode.isEmpty())
  825. {
  826. XMLNode tCaps = tNode.getChildNode("Capabilities", 0);
  827. if (! tCaps.isEmpty())
  828. {
  829. {
  830. XMLNode t = tCaps.getChildNode("Analytics", 0);
  831. if (! t.isEmpty())
  832. {
  833. m_sCapabilities.Analytics = (onvifAnalyticsCapabilities *) malloc(sizeof(onvifAnalyticsCapabilities));
  834. if (m_sCapabilities.Analytics != NULL)
  835. {
  836. memset(m_sCapabilities.Analytics, 0, sizeof(onvifAnalyticsCapabilities));
  837. {
  838. XMLNode c = t.getChildNode("XAddr", 0);
  839. sprintf(m_sCapabilities.Analytics->XAddr, "%s", c.getText(0));
  840. }
  841. {
  842. XMLNode c = t.getChildNode("RuleSupport", 0);
  843. m_sCapabilities.Analytics->RuleSupport = checkBool(c.getText(0));
  844. }
  845. {
  846. XMLNode c = t.getChildNode("AnalyticsModuleSupport", 0);
  847. m_sCapabilities.Analytics->AnalyticsModuleSupport = checkBool(c.getText(0));
  848. }
  849. };
  850. };
  851. }
  852. {
  853. XMLNode t = tCaps.getChildNode("Device", 0);
  854. if (! t.isEmpty())
  855. {
  856. m_sCapabilities.Device = (onvifDeviceCapabilities *) malloc(sizeof(onvifDeviceCapabilities));
  857. if (m_sCapabilities.Device != NULL)
  858. {
  859. memset(m_sCapabilities.Device, 0, sizeof(onvifDeviceCapabilities));
  860. {
  861. XMLNode c = t.getChildNode("XAddr", 0);
  862. sprintf(m_sCapabilities.Device->XAddr, "%s", c.getText(0));
  863. }
  864. {
  865. XMLNode c = t.getChildNode("Network", 0);
  866. if (! c.isEmpty())
  867. {
  868. m_sCapabilities.Device->Network = (onvifNetworkCapabilities *) malloc(sizeof(onvifNetworkCapabilities));
  869. if (m_sCapabilities.Device->Network != NULL)
  870. {
  871. memset(m_sCapabilities.Device->Network, 0, sizeof(onvifNetworkCapabilities));
  872. {
  873. XMLNode n = c.getChildNode("IPFilter", 0);
  874. m_sCapabilities.Device->Network->IPFilter = checkBool(n.getText(0));
  875. }
  876. {
  877. XMLNode n = c.getChildNode("ZeroConfiguration", 0);
  878. m_sCapabilities.Device->Network->ZeroConfiguration = checkBool(n.getText(0));
  879. }
  880. {
  881. XMLNode n = c.getChildNode("IPVersion6", 0);
  882. m_sCapabilities.Device->Network->IPVersion6 = checkBool(n.getText(0));
  883. }
  884. {
  885. XMLNode n = c.getChildNode("DynDNS", 0);
  886. m_sCapabilities.Device->Network->DynDNS = checkBool(n.getText(0));
  887. }
  888. {
  889. XMLNode n = c.getChildNode("Extension", 0);
  890. if (! n.isEmpty())
  891. {
  892. m_sCapabilities.Device->Network->Extension = (onvifNetworkCapabilitiesExtension *) malloc(sizeof(onvifNetworkCapabilitiesExtension));
  893. if (m_sCapabilities.Device->Network->Extension != NULL)
  894. {
  895. memset(m_sCapabilities.Device->Network->Extension, 0, sizeof(onvifNetworkCapabilitiesExtension));
  896. {
  897. XMLNode x = n.getChildNode("Dot11Configuration", 0);
  898. m_sCapabilities.Device->Network->Extension->Dot11Configuration = checkBool(x.getText(0));
  899. }
  900. };
  901. };
  902. }
  903. };
  904. };
  905. }
  906. {
  907. XMLNode c = t.getChildNode("System", 0);
  908. if (! c.isEmpty())
  909. {
  910. m_sCapabilities.Device->System = (onvifSystemCapabilities *) malloc(sizeof(onvifSystemCapabilities));
  911. if (m_sCapabilities.Device->System != NULL)
  912. {
  913. memset(m_sCapabilities.Device->System, 0, sizeof(onvifSystemCapabilities));
  914. {
  915. XMLNode n = c.getChildNode("DiscoveryResolve", 0);
  916. m_sCapabilities.Device->System->DiscoveryResolve = checkBool(n.getText(0));
  917. }
  918. {
  919. XMLNode n = c.getChildNode("DiscoveryBye", 0);
  920. m_sCapabilities.Device->System->DiscoveryBye = checkBool(n.getText(0));
  921. }
  922. {
  923. XMLNode n = c.getChildNode("RemoteDiscovery", 0);
  924. m_sCapabilities.Device->System->RemoteDiscovery = checkBool(n.getText(0));
  925. }
  926. {
  927. XMLNode n = c.getChildNode("SystemBackup", 0);
  928. m_sCapabilities.Device->System->SystemBackup = checkBool(n.getText(0));
  929. }
  930. {
  931. XMLNode n = c.getChildNode("SystemLogging", 0);
  932. m_sCapabilities.Device->System->SystemLogging = checkBool(n.getText(0));
  933. }
  934. {
  935. XMLNode n = c.getChildNode("FirmwareUpgrade", 0);
  936. m_sCapabilities.Device->System->FirmwareUpgrade = checkBool(n.getText(0));
  937. }
  938. {
  939. XMLNode n = c.getChildNode("SupportedVersions", 0);
  940. if (! n.isEmpty())
  941. {
  942. m_sCapabilities.Device->System->SupportedVersions = (onvifSupportedVersions *) malloc(sizeof(onvifSupportedVersions));
  943. if (m_sCapabilities.Device->System->SupportedVersions != NULL)
  944. {
  945. memset(m_sCapabilities.Device->System->SupportedVersions, 0, sizeof(onvifSupportedVersions));
  946. {
  947. XMLNode x = n.getChildNode("Major", 0);
  948. m_sCapabilities.Device->System->SupportedVersions->Major = atoi(x.getText(0));
  949. }
  950. {
  951. XMLNode x = n.getChildNode("Minor", 0);
  952. m_sCapabilities.Device->System->SupportedVersions->Minor = atoi(x.getText(0));
  953. }
  954. };
  955. };
  956. }
  957. {
  958. XMLNode n = c.getChildNode("Extension", 0);
  959. if (! n.isEmpty())
  960. {
  961. m_sCapabilities.Device->System->Extension = (onvifSystemCapabilitiesExtension *) malloc(sizeof(onvifSystemCapabilitiesExtension));
  962. if (m_sCapabilities.Device->System->Extension != NULL)
  963. {
  964. memset(m_sCapabilities.Device->System->Extension, 0, sizeof(onvifSystemCapabilitiesExtension));
  965. {
  966. XMLNode x = n.getChildNode("HttpFirmwareUpgrade", 0);
  967. m_sCapabilities.Device->System->Extension->HttpFirmwareUpgrade = checkBool(x.getText(0));
  968. }
  969. {
  970. XMLNode x = n.getChildNode("HttpSystemBackup", 0);
  971. m_sCapabilities.Device->System->Extension->HttpSystemBackup = checkBool(x.getText(0));
  972. }
  973. {
  974. XMLNode x = n.getChildNode("HttpSystemLogging", 0);
  975. m_sCapabilities.Device->System->Extension->HttpSystemLogging = checkBool(x.getText(0));
  976. }
  977. {
  978. XMLNode x = n.getChildNode("HttpSupportInformation", 0);
  979. m_sCapabilities.Device->System->Extension->HttpSupportInformation = checkBool(x.getText(0));
  980. }
  981. };
  982. };
  983. }
  984. };
  985. };
  986. }
  987. {
  988. XMLNode c = t.getChildNode("IO", 0);
  989. if (! c.isEmpty())
  990. {
  991. m_sCapabilities.Device->IO = (onvifIOCapabilities *) malloc(sizeof(onvifIOCapabilities));
  992. if (m_sCapabilities.Device->IO != NULL)
  993. {
  994. memset(m_sCapabilities.Device->IO, 0, sizeof(onvifIOCapabilities));
  995. {
  996. XMLNode n = c.getChildNode("InputConnectors", 0);
  997. m_sCapabilities.Device->IO->InputConnectors = atoi(n.getText(0));
  998. }
  999. {
  1000. XMLNode n = c.getChildNode("RelayOutputs", 0);
  1001. m_sCapabilities.Device->IO->RelayOutputs = atoi(n.getText(0));
  1002. }
  1003. {
  1004. XMLNode n = c.getChildNode("Extension", 0);
  1005. if (! n.isEmpty())
  1006. {
  1007. m_sCapabilities.Device->IO->Extension = (onvifIOCapabilitiesExtension *) malloc(sizeof(onvifIOCapabilitiesExtension));
  1008. if (m_sCapabilities.Device->IO->Extension != NULL)
  1009. {
  1010. memset(m_sCapabilities.Device->IO->Extension, 0, sizeof(onvifIOCapabilitiesExtension));
  1011. {
  1012. XMLNode x = n.getChildNode("Auxiliary", 0);
  1013. m_sCapabilities.Device->IO->Extension->Auxiliary = checkBool(x.getText(0));
  1014. }
  1015. };
  1016. };
  1017. }
  1018. };
  1019. };
  1020. }
  1021. {
  1022. XMLNode c = t.getChildNode("Security", 0);
  1023. if (! c.isEmpty())
  1024. {
  1025. m_sCapabilities.Device->Security = (onvifSecurityCapabilities *) malloc(sizeof(onvifSecurityCapabilities));
  1026. if (m_sCapabilities.Device->Security != NULL)
  1027. {
  1028. memset(m_sCapabilities.Device->Security, 0, sizeof(onvifSecurityCapabilities));
  1029. {
  1030. XMLNode n = c.getChildNode("TLS1.1", 0);
  1031. m_sCapabilities.Device->Security->TLS1_1 = checkBool(n.getText(0));
  1032. }
  1033. {
  1034. XMLNode n = c.getChildNode("TLS1.2", 0);
  1035. m_sCapabilities.Device->Security->TLS1_2 = checkBool(n.getText(0));
  1036. }
  1037. {
  1038. XMLNode n = c.getChildNode("OnboardKeyGeneration", 0);
  1039. m_sCapabilities.Device->Security->OnboardKeyGeneration = checkBool(n.getText(0));
  1040. }
  1041. {
  1042. XMLNode n = c.getChildNode("AccessPolicyConfig", 0);
  1043. m_sCapabilities.Device->Security->AccessPolicyConfig = checkBool(n.getText(0));
  1044. }
  1045. {
  1046. XMLNode n = c.getChildNode("X.509Token", 0);
  1047. m_sCapabilities.Device->Security->X_509Token = checkBool(n.getText(0));
  1048. }
  1049. {
  1050. XMLNode n = c.getChildNode("SAMLToken", 0);
  1051. m_sCapabilities.Device->Security->SAMLToken = checkBool(n.getText(0));
  1052. }
  1053. {
  1054. XMLNode n = c.getChildNode("KerberosToken", 0);
  1055. m_sCapabilities.Device->Security->KerberosToken = checkBool(n.getText(0));
  1056. }
  1057. {
  1058. XMLNode n = c.getChildNode("RELToken", 0);
  1059. m_sCapabilities.Device->Security->RELToken = checkBool(n.getText(0));
  1060. }
  1061. {
  1062. XMLNode n = c.getChildNode("Extension", 0);
  1063. if (! n.isEmpty())
  1064. {
  1065. m_sCapabilities.Device->Security->Extension = (onvifSecurityCapabilitiesExtension *) malloc(sizeof(onvifSecurityCapabilitiesExtension));
  1066. if (m_sCapabilities.Device->Security->Extension != NULL)
  1067. {
  1068. memset(m_sCapabilities.Device->Security->Extension, 0, sizeof(onvifSecurityCapabilitiesExtension));
  1069. {
  1070. XMLNode x = n.getChildNode("TLS1.0", 0);
  1071. m_sCapabilities.Device->Security->Extension->TLS1_0 = checkBool(x.getText(0));
  1072. }
  1073. };
  1074. };
  1075. }
  1076. };
  1077. };
  1078. }
  1079. };
  1080. };
  1081. }
  1082. {
  1083. XMLNode t = tCaps.getChildNode("Events", 0);
  1084. if (! t.isEmpty())
  1085. {
  1086. m_sCapabilities.Events = (onvifEventCapabilities *) malloc(sizeof(onvifEventCapabilities));
  1087. if (m_sCapabilities.Events != NULL)
  1088. {
  1089. memset(m_sCapabilities.Events, 0, sizeof(onvifEventCapabilities));
  1090. {
  1091. XMLNode c = t.getChildNode("XAddr", 0);
  1092. sprintf(m_sCapabilities.Events->XAddr, "%s", c.getText(0));
  1093. }
  1094. {
  1095. XMLNode c = t.getChildNode("WSSubscriptionPolicySupport", 0);
  1096. m_sCapabilities.Events->WSSubscriptionPolicySupport = checkBool(c.getText(0));
  1097. }
  1098. {
  1099. XMLNode c = t.getChildNode("WSPullPointSupport", 0);
  1100. m_sCapabilities.Events->WSPullPointSupport = checkBool(c.getText(0));
  1101. }
  1102. {
  1103. XMLNode c = t.getChildNode("WSPausableSubscriptionManagerInterfaceSupport", 0);
  1104. m_sCapabilities.Events->WSPausableSubscriptionManagerInterfaceSupport = checkBool(c.getText(0));
  1105. }
  1106. };
  1107. };
  1108. }
  1109. {
  1110. XMLNode t = tCaps.getChildNode("Imaging", 0);
  1111. if (! t.isEmpty())
  1112. {
  1113. m_sCapabilities.Imaging = (onvifImagingCapabilities *) malloc(sizeof(onvifImagingCapabilities));
  1114. if (m_sCapabilities.Imaging != NULL)
  1115. {
  1116. memset(m_sCapabilities.Imaging, 0, sizeof(onvifImagingCapabilities));
  1117. {
  1118. XMLNode c = t.getChildNode("XAddr", 0);
  1119. sprintf(m_sCapabilities.Imaging->XAddr, "%s", c.getText(0));
  1120. }
  1121. };
  1122. };
  1123. }
  1124. {
  1125. XMLNode t = tCaps.getChildNode("Media", 0);
  1126. if (! t.isEmpty())
  1127. {
  1128. m_sCapabilities.Media = (onvifMediaCapabilities *) malloc(sizeof(onvifMediaCapabilities));
  1129. if (m_sCapabilities.Media != NULL)
  1130. {
  1131. memset(m_sCapabilities.Media, 0, sizeof(onvifMediaCapabilities));
  1132. {
  1133. XMLNode c = t.getChildNode("XAddr", 0);
  1134. sprintf(m_sCapabilities.Media->XAddr, "%s", c.getText(0));
  1135. }
  1136. {
  1137. XMLNode c = t.getChildNode("StreamingCapabilities", 0);
  1138. if (! c.isEmpty())
  1139. {
  1140. m_sCapabilities.Media->StreamingCapabilities = (onvifRealTimeStreamingCapabilities *) malloc(sizeof(onvifRealTimeStreamingCapabilities));
  1141. if (m_sCapabilities.Media->StreamingCapabilities != NULL)
  1142. {
  1143. memset(m_sCapabilities.Media->StreamingCapabilities, 0, sizeof(onvifRealTimeStreamingCapabilities));
  1144. {
  1145. XMLNode n = c.getChildNode("RTPMulticast", 0);
  1146. m_sCapabilities.Media->StreamingCapabilities->RTPMulticast = checkBool(n.getText(0));
  1147. }
  1148. {
  1149. XMLNode n = c.getChildNode("RTP_TCP", 0);
  1150. m_sCapabilities.Media->StreamingCapabilities->RTP_TCP = checkBool(n.getText(0));
  1151. }
  1152. {
  1153. XMLNode n = c.getChildNode("RTP_RTSP_TCP", 0);
  1154. m_sCapabilities.Media->StreamingCapabilities->RTP_RTSP_TCP = checkBool(n.getText(0));
  1155. }
  1156. };
  1157. };
  1158. }
  1159. {
  1160. XMLNode c = t.getChildNode("Extension", 0);
  1161. if (! c.isEmpty())
  1162. {
  1163. m_sCapabilities.Media->Extension = (onvifMediaCapabilitiesExtension *) malloc(sizeof(onvifMediaCapabilitiesExtension));
  1164. if (m_sCapabilities.Media->Extension != NULL)
  1165. {
  1166. memset(m_sCapabilities.Media->Extension, 0, sizeof(onvifMediaCapabilitiesExtension));
  1167. {
  1168. XMLNode n = c.getChildNode("ProfileCapabilities", 0);
  1169. if (! n.isEmpty())
  1170. {
  1171. m_sCapabilities.Media->Extension->ProfileCapabilities = (onvifProfileCapabilities *) malloc(sizeof(onvifProfileCapabilities));
  1172. if (m_sCapabilities.Media->Extension->ProfileCapabilities != NULL)
  1173. {
  1174. memset(m_sCapabilities.Media->Extension->ProfileCapabilities, 0, sizeof(onvifProfileCapabilities));
  1175. {
  1176. XMLNode x = n.getChildNode("MaximumNumberOfProfiles", 0);
  1177. m_sCapabilities.Media->Extension->ProfileCapabilities->MaximumNumberOfProfiles = atoi(x.getText(0));
  1178. }
  1179. };
  1180. };
  1181. }
  1182. };
  1183. };
  1184. }
  1185. };
  1186. };
  1187. }
  1188. {
  1189. XMLNode t = tCaps.getChildNode("PTZ", 0);
  1190. if (! t.isEmpty())
  1191. {
  1192. m_sCapabilities.PTZ = (onvifPTZCapabilities *) malloc(sizeof(onvifPTZCapabilities));
  1193. if (m_sCapabilities.PTZ != NULL)
  1194. {
  1195. memset(m_sCapabilities.PTZ, 0, sizeof(onvifPTZCapabilities));
  1196. {
  1197. XMLNode c = t.getChildNode("XAddr", 0);
  1198. sprintf(m_sCapabilities.PTZ->XAddr, "%s", c.getText(0));
  1199. }
  1200. };
  1201. };
  1202. }
  1203. {
  1204. XMLNode t = tCaps.getChildNode("Extension", 0);
  1205. if (! t.isEmpty())
  1206. {
  1207. m_sCapabilities.Extension = (onvifCapabilitiesExtension *) malloc(sizeof(onvifCapabilitiesExtension));
  1208. if (m_sCapabilities.Extension != NULL)
  1209. {
  1210. memset(m_sCapabilities.Extension, 0, sizeof(onvifCapabilitiesExtension));
  1211. {
  1212. XMLNode c = t.getChildNode("DeviceIO", 0);
  1213. if (! c.isEmpty())
  1214. {
  1215. m_sCapabilities.Extension->DeviceIO = (onvifDeviceIOCapabilities *) malloc(sizeof(onvifDeviceIOCapabilities));
  1216. if (m_sCapabilities.Extension->DeviceIO != NULL)
  1217. {
  1218. memset(m_sCapabilities.Extension->DeviceIO, 0, sizeof(onvifDeviceIOCapabilities));
  1219. {
  1220. XMLNode n = c.getChildNode("XAddr", 0);
  1221. sprintf(m_sCapabilities.Extension->DeviceIO->XAddr, "%s", n.getText(0));
  1222. }
  1223. {
  1224. XMLNode n = c.getChildNode("VideoSources", 0);
  1225. m_sCapabilities.Extension->DeviceIO->VideoSources = atoi(n.getText(0));
  1226. }
  1227. {
  1228. XMLNode n = c.getChildNode("VideoOutputs", 0);
  1229. m_sCapabilities.Extension->DeviceIO->VideoOutputs = atoi(n.getText(0));
  1230. }
  1231. {
  1232. XMLNode n = c.getChildNode("AudioSources", 0);
  1233. m_sCapabilities.Extension->DeviceIO->AudioSources = atoi(n.getText(0));
  1234. }
  1235. {
  1236. XMLNode n = c.getChildNode("AudioOutputs", 0);
  1237. m_sCapabilities.Extension->DeviceIO->AudioOutputs = atoi(n.getText(0));
  1238. }
  1239. {
  1240. XMLNode n = c.getChildNode("RelayOutputs", 0);
  1241. m_sCapabilities.Extension->DeviceIO->RelayOutputs = atoi(n.getText(0));
  1242. }
  1243. };
  1244. };
  1245. }
  1246. {
  1247. XMLNode c = t.getChildNode("Display", 0);
  1248. if (! c.isEmpty())
  1249. {
  1250. m_sCapabilities.Extension->Display = (onvifDisplayCapabilities *) malloc(sizeof(onvifDisplayCapabilities));
  1251. if (m_sCapabilities.Extension->Display != NULL)
  1252. {
  1253. memset(m_sCapabilities.Extension->Display, 0, sizeof(onvifDisplayCapabilities));
  1254. {
  1255. XMLNode n = c.getChildNode("XAddr", 0);
  1256. sprintf(m_sCapabilities.Extension->Display->XAddr, "%s", n.getText(0));
  1257. }
  1258. {
  1259. XMLNode n = c.getChildNode("FixedLayout", 0);
  1260. m_sCapabilities.Extension->Display->FixedLayout = checkBool(n.getText(0));
  1261. }
  1262. };
  1263. };
  1264. }
  1265. {
  1266. XMLNode c = t.getChildNode("Recording", 0);
  1267. if (! c.isEmpty())
  1268. {
  1269. m_sCapabilities.Extension->Recording = (onvifRecordingCapabilities *) malloc(sizeof(onvifRecordingCapabilities));
  1270. if (m_sCapabilities.Extension->Recording != NULL)
  1271. {
  1272. memset(m_sCapabilities.Extension->Recording, 0, sizeof(onvifRecordingCapabilities));
  1273. {
  1274. XMLNode n = c.getChildNode("XAddr", 0);
  1275. sprintf(m_sCapabilities.Extension->Recording->XAddr, "%s", n.getText(0));
  1276. }
  1277. {
  1278. XMLNode n = c.getChildNode("ReceiverSource", 0);
  1279. m_sCapabilities.Extension->Recording->ReceiverSource = checkBool(n.getText(0));
  1280. }
  1281. {
  1282. XMLNode n = c.getChildNode("MediaProfileSource", 0);
  1283. m_sCapabilities.Extension->Recording->MediaProfileSource = checkBool(n.getText(0));
  1284. }
  1285. {
  1286. XMLNode n = c.getChildNode("DynamicRecordings", 0);
  1287. m_sCapabilities.Extension->Recording->DynamicRecordings = checkBool(n.getText(0));
  1288. }
  1289. {
  1290. XMLNode n = c.getChildNode("DynamicTracks", 0);
  1291. m_sCapabilities.Extension->Recording->DynamicTracks = checkBool(n.getText(0));
  1292. }
  1293. {
  1294. XMLNode n = c.getChildNode("MaxStringLength", 0);
  1295. m_sCapabilities.Extension->Recording->MaxStringLength = atoi(n.getText(0));
  1296. }
  1297. };
  1298. };
  1299. }
  1300. {
  1301. XMLNode c = t.getChildNode("Search", 0);
  1302. if (! c.isEmpty())
  1303. {
  1304. m_sCapabilities.Extension->Search = (onvifSearchCapabilities *) malloc(sizeof(onvifSearchCapabilities));
  1305. if (m_sCapabilities.Extension->Search != NULL)
  1306. {
  1307. memset(m_sCapabilities.Extension->Search, 0, sizeof(onvifSearchCapabilities));
  1308. {
  1309. XMLNode n = c.getChildNode("XAddr", 0);
  1310. sprintf(m_sCapabilities.Extension->Search->XAddr, "%s", n.getText(0));
  1311. }
  1312. {
  1313. XMLNode n = c.getChildNode("MetadataSearch", 0);
  1314. m_sCapabilities.Extension->Search->MetadataSearch = checkBool(n.getText(0));
  1315. }
  1316. };
  1317. };
  1318. }
  1319. {
  1320. XMLNode c = t.getChildNode("Replay", 0);
  1321. if (! c.isEmpty())
  1322. {
  1323. m_sCapabilities.Extension->Replay = (onvifReplayCapabilities *) malloc(sizeof(onvifReplayCapabilities));
  1324. if (m_sCapabilities.Extension->Replay != NULL)
  1325. {
  1326. memset(m_sCapabilities.Extension->Replay, 0, sizeof(onvifReplayCapabilities));
  1327. {
  1328. XMLNode n = c.getChildNode("XAddr", 0);
  1329. sprintf(m_sCapabilities.Extension->Replay->XAddr, "%s", n.getText(0));
  1330. }
  1331. };
  1332. };
  1333. }
  1334. {
  1335. XMLNode c = t.getChildNode("Receiver", 0);
  1336. if (! c.isEmpty())
  1337. {
  1338. m_sCapabilities.Extension->Receiver = (onvifReceiverCapabilities *) malloc(sizeof(onvifReceiverCapabilities));
  1339. if (m_sCapabilities.Extension->Receiver != NULL)
  1340. {
  1341. memset(m_sCapabilities.Extension->Receiver, 0, sizeof(onvifReceiverCapabilities));
  1342. {
  1343. XMLNode n = c.getChildNode("XAddr", 0);
  1344. sprintf(m_sCapabilities.Extension->Receiver->XAddr, "%s", n.getText(0));
  1345. }
  1346. {
  1347. XMLNode n = c.getChildNode("RTP_Multicast", 0);
  1348. m_sCapabilities.Extension->Receiver->RTP_Multicast = checkBool(n.getText(0));
  1349. }
  1350. {
  1351. XMLNode n = c.getChildNode("RTP_TCP", 0);
  1352. m_sCapabilities.Extension->Receiver->RTP_TCP = checkBool(n.getText(0));
  1353. }
  1354. {
  1355. XMLNode n = c.getChildNode("RTP_RTSP_TCP", 0);
  1356. m_sCapabilities.Extension->Receiver->RTP_RTSP_TCP = checkBool(n.getText(0));
  1357. }
  1358. {
  1359. XMLNode n = c.getChildNode("SupportedReceivers", 0);
  1360. m_sCapabilities.Extension->Receiver->SupportedReceivers = atoi(n.getText(0));
  1361. }
  1362. {
  1363. XMLNode n = c.getChildNode("MaximumRTSPURILength", 0);
  1364. m_sCapabilities.Extension->Receiver->MaximumRTSPURILength = atoi(n.getText(0));
  1365. }
  1366. };
  1367. };
  1368. }
  1369. {
  1370. XMLNode c = t.getChildNode("AnalyticsDevice", 0);
  1371. if (! c.isEmpty())
  1372. {
  1373. m_sCapabilities.Extension->AnalyticsDevice = (onvifAnalyticsDeviceCapabilities *) malloc(sizeof(onvifAnalyticsDeviceCapabilities));
  1374. if (m_sCapabilities.Extension->AnalyticsDevice != NULL)
  1375. {
  1376. memset(m_sCapabilities.Extension->AnalyticsDevice, 0, sizeof(onvifAnalyticsDeviceCapabilities));
  1377. {
  1378. XMLNode n = c.getChildNode("XAddr", 0);
  1379. sprintf(m_sCapabilities.Extension->AnalyticsDevice->XAddr, "%s", n.getText(0));
  1380. }
  1381. {
  1382. XMLNode n = c.getChildNode("RuleSupport", 0);
  1383. m_sCapabilities.Extension->AnalyticsDevice->RuleSupport = checkBool(n.getText(0));
  1384. }
  1385. };
  1386. };
  1387. }
  1388. };
  1389. };
  1390. }
  1391. return true;
  1392. }
  1393. else
  1394. {
  1395. LOG("Capabilities is Empty!");
  1396. };
  1397. }
  1398. else
  1399. {
  1400. LOG("GetCapabilitiesResponse is Empty!");
  1401. };
  1402. };
  1403. }
  1404. return false;
  1405. }
  1406. // based on https://www.onvif.org/ver20/imaging/wsdl/imaging.wsdl
  1407. bool boschRCP::media_GetVideoSources(void)
  1408. {
  1409. if (m_pMediaURI == NULL)
  1410. {
  1411. return false;
  1412. }
  1413. char tBuffer[DEFAULT_BUFFER_SIZE];
  1414. accessToken tTOKEN;
  1415. tTOKEN = _makeToken();
  1416. sprintf(tBuffer, PONVIF_PACK_GET_VIDEO_SOURCES, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP);
  1417. if (_send_request(m_pMediaURI, tBuffer))
  1418. {
  1419. XMLResults tParseResults;
  1420. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  1421. #ifdef DEBUG_ONVIF_PRINTOUT_MESSAGES
  1422. LOG("RCPT:");
  1423. printf(m_pLastResponse);
  1424. #endif
  1425. if (tParseResults.error)
  1426. {
  1427. char tBuf[CTEXT];
  1428. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  1429. LOG_ERROR(tBuf);
  1430. }
  1431. else
  1432. {
  1433. XMLNode zNode = response.getChildNode("Body", 0);
  1434. if (zNode.isEmpty())
  1435. {
  1436. return false;
  1437. }
  1438. XMLNode tNode = zNode.getChildNode("GetVideoSourcesResponse", 0);
  1439. if (! tNode.isEmpty())
  1440. {
  1441. for (int index = 0; index < tNode.nChildNode(); index++)
  1442. {
  1443. XMLNode cNode = tNode.getChildNode("VideoSources", index);
  1444. if (! cNode.isEmpty())
  1445. {
  1446. videoSource * tPtr;
  1447. tPtr = (videoSource *) malloc(sizeof(videoSource));
  1448. if (tPtr != NULL)
  1449. {
  1450. sprintf(tPtr->token, "%s", cNode.getAttribute("token", 0));
  1451. {
  1452. XMLNode nNode = cNode.getChildNode("Framerate", 0);
  1453. tPtr->Framerate = (float) atof(nNode.getText(0));
  1454. }
  1455. {
  1456. XMLNode nNode = cNode.getChildNode("Resolution", 0);
  1457. if (! nNode.isEmpty())
  1458. {
  1459. {
  1460. XMLNode xNode = nNode.getChildNode("Width", 0);
  1461. tPtr->Resolution.Width = atoi(xNode.getText(0));
  1462. }
  1463. {
  1464. XMLNode xNode = nNode.getChildNode("Height", 0);
  1465. tPtr->Resolution.Height = atoi(xNode.getText(0));
  1466. }
  1467. };
  1468. }
  1469. {
  1470. XMLNode nNode = cNode.getChildNode("Imaging", 0);
  1471. if (! nNode.isEmpty())
  1472. {
  1473. tPtr->Imaging = (onvifImagingSettings *) malloc(sizeof(onvifImagingSettings));
  1474. if (tPtr->Imaging != NULL)
  1475. {
  1476. memset(tPtr->Imaging, 0, sizeof(onvifImagingSettings));
  1477. {
  1478. XMLNode xNode = nNode.getChildNode("BacklightCompensation", 0);
  1479. if (! xNode.isEmpty())
  1480. {
  1481. tPtr->Imaging->BacklightCompensation = (onvifBacklightCompensation *) malloc(sizeof(onvifBacklightCompensation));
  1482. if (tPtr->Imaging->BacklightCompensation != NULL)
  1483. {
  1484. memset(tPtr->Imaging->BacklightCompensation, 0, sizeof(onvifBacklightCompensation));
  1485. {
  1486. XMLNode rNode = xNode.getChildNode("Mode", 0);
  1487. tPtr->Imaging->BacklightCompensation->Mode = checkOnOff(rNode.getText(0));
  1488. }
  1489. {
  1490. XMLNode rNode = xNode.getChildNode("Level", 0);
  1491. tPtr->Imaging->BacklightCompensation->Level = (float) atof(rNode.getText(0));
  1492. }
  1493. };
  1494. };
  1495. }
  1496. {
  1497. XMLNode xNode = nNode.getChildNode("Brightness", 0);
  1498. tPtr->Imaging->Brightness = (float) atoi(xNode.getText(0));
  1499. }
  1500. {
  1501. XMLNode xNode = nNode.getChildNode("ColorSaturation", 0);
  1502. tPtr->Imaging->ColorSaturation = (float) atoi(xNode.getText(0));
  1503. }
  1504. {
  1505. XMLNode xNode = nNode.getChildNode("Contrast", 0);
  1506. tPtr->Imaging->Contrast = (float) atoi(xNode.getText(0));
  1507. }
  1508. {
  1509. XMLNode xNode = nNode.getChildNode("Sharpness", 0);
  1510. tPtr->Imaging->Sharpness = (float) atoi(xNode.getText(0));
  1511. }
  1512. {
  1513. XMLNode xNode = nNode.getChildNode("IrCutFilter", 0);
  1514. tPtr->Imaging->IrCutFilter = checkOnOffAuto(xNode.getText(0));
  1515. }
  1516. };
  1517. };
  1518. }
  1519. m_vVideoSources.push_back(tPtr);
  1520. };
  1521. };
  1522. };
  1523. return true;
  1524. }
  1525. else
  1526. {
  1527. LOG_ERROR("GetVideoSourcesResponse EMPTY!");
  1528. };
  1529. };
  1530. }
  1531. else
  1532. {
  1533. LOG_ERROR("_send_request Failure!");
  1534. };
  1535. return false;
  1536. }
  1537. bool boschRCP::media_GetProfiles(void)
  1538. {
  1539. char tBuffer[DEFAULT_BUFFER_SIZE];
  1540. accessToken tTOKEN;
  1541. tTOKEN = _makeToken();
  1542. sprintf(tBuffer, PONVIF_PACK_GET_PROFILES, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP);
  1543. if (_send_request(m_pMediaURI, tBuffer))
  1544. {
  1545. XMLResults tParseResults;
  1546. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  1547. #ifdef DEBUG_ONVIF_PRINTOUT_MESSAGES
  1548. LOG("RCPT:");
  1549. printf(m_pLastResponse);
  1550. #endif
  1551. if (tParseResults.error)
  1552. {
  1553. char tBuf[CTEXT];
  1554. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  1555. LOG_ERROR(tBuf);
  1556. }
  1557. else
  1558. {
  1559. XMLNode zNode = response.getChildNode("Body", 0);
  1560. if (zNode.isEmpty())
  1561. {
  1562. return false;
  1563. }
  1564. XMLNode tNode = zNode.getChildNode("GetProfilesResponse", 0);
  1565. if (! tNode.isEmpty())
  1566. {
  1567. for (int index = 0; index < tNode.nChildNode(); index++)
  1568. {
  1569. XMLNode cNode = tNode.getChildNode("Profiles", index);
  1570. if (! cNode.isEmpty())
  1571. {
  1572. videoSourceProfile * tPtr;
  1573. tPtr = (videoSourceProfile *) malloc(sizeof(videoSourceProfile));
  1574. if (tPtr != NULL)
  1575. {
  1576. memset(tPtr, 0, sizeof(videoSourceProfile));
  1577. sprintf(tPtr->profiletoken, "%s", cNode.getAttribute("token", 0));
  1578. {
  1579. XMLNode nNode = cNode.getChildNode("Name", 0);
  1580. sprintf(tPtr->profilename, "%s", nNode.getText(0));
  1581. }
  1582. {
  1583. XMLNode nNode = cNode.getChildNode("VideoSourceConfiguration", 0);
  1584. if (! nNode.isEmpty())
  1585. {
  1586. XMLNode zNode = nNode.getChildNode("SourceToken", 0);
  1587. sprintf(tPtr->sourcetoken, "%s", zNode.getText(0));
  1588. };
  1589. }
  1590. {
  1591. XMLNode nNode = cNode.getChildNode("VideoEncoderConfiguration", 0);
  1592. if (! nNode.isEmpty())
  1593. {
  1594. {
  1595. XMLNode zNode = nNode.getChildNode("Encoding", 0);
  1596. sprintf(tPtr->encoding, "%s", zNode.getText(0));
  1597. }
  1598. {
  1599. XMLNode zNode = nNode.getChildNode("Resolution", 0);
  1600. {
  1601. XMLNode jNode = zNode.getChildNode("Width", 0);
  1602. tPtr->width = atoi(jNode.getText(0));
  1603. }
  1604. {
  1605. XMLNode jNode = zNode.getChildNode("Height", 0);
  1606. tPtr->height = atoi(jNode.getText(0));
  1607. }
  1608. }
  1609. {
  1610. XMLNode zNode = nNode.getChildNode("RateControl", 0);
  1611. {
  1612. XMLNode jNode = zNode.getChildNode("FrameRateLimit", 0);
  1613. tPtr->fps = atoi(jNode.getText(0));
  1614. }
  1615. {
  1616. XMLNode jNode = zNode.getChildNode("BitrateLimit", 0);
  1617. tPtr->bitrate = atoi(jNode.getText(0));
  1618. }
  1619. }
  1620. };
  1621. }
  1622. m_vVideoProfiles.push_back(tPtr);
  1623. };
  1624. };
  1625. };
  1626. return true;
  1627. };
  1628. };
  1629. };
  1630. return false;
  1631. }
  1632. bool boschRCP::media_GetServices(void)
  1633. {
  1634. char tBuffer[DEFAULT_BUFFER_SIZE];
  1635. accessToken tTOKEN;
  1636. tTOKEN = _makeToken();
  1637. sprintf(tBuffer, PONVIF_PACK_GET_SERVICES, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP);
  1638. if (_send_request(m_pMediaURI, tBuffer))
  1639. {
  1640. XMLResults tParseResults;
  1641. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  1642. LOG("RCPT:");
  1643. printf(m_pLastResponse);
  1644. if (tParseResults.error)
  1645. {
  1646. char tBuf[CTEXT];
  1647. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  1648. LOG_ERROR(tBuf);
  1649. }
  1650. else
  1651. {
  1652. };
  1653. };
  1654. return false;
  1655. }
  1656. bool boschRCP::core_GetDeviceInformation()
  1657. {
  1658. char tBuffer[DEFAULT_BUFFER_SIZE];
  1659. accessToken tTOKEN;
  1660. tTOKEN = _makeToken();
  1661. sprintf(tBuffer, PONVIF_PACK_GET_DEV_INFO, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP);
  1662. if (_send_request(m_pMediaURI, tBuffer))
  1663. {
  1664. XMLResults tParseResults;
  1665. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  1666. LOG("RCPT:");
  1667. printf(m_pLastResponse);
  1668. if (tParseResults.error)
  1669. {
  1670. char tBuf[CTEXT];
  1671. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  1672. LOG_ERROR(tBuf);
  1673. }
  1674. else
  1675. {
  1676. // return $response['Envelope']['Body']['GetDeviceInformationResponse'];
  1677. };
  1678. };
  1679. return false;
  1680. }
  1681. CSTR boschRCP::media_GetStreamUri(CSTR profileToken, CSTR stream, CSTR protocol)
  1682. {
  1683. char tBuffer[DEFAULT_BUFFER_SIZE];
  1684. accessToken tTOKEN;
  1685. tTOKEN = _makeToken();
  1686. sprintf(tBuffer, PONVIF_PACK_GET_STREAM_URI, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, stream, protocol, profileToken);
  1687. if (_send_request(m_pMediaURI, tBuffer))
  1688. {
  1689. XMLResults tParseResults;
  1690. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  1691. LOG("RCPT:");
  1692. printf(m_pLastResponse);
  1693. if (tParseResults.error)
  1694. {
  1695. char tBuf[CTEXT];
  1696. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  1697. LOG_ERROR(tBuf);
  1698. }
  1699. else
  1700. {
  1701. // Parse
  1702. // return $response['Envelope']['Body']['GetStreamUriResponse']['MediaUri']['Uri'];
  1703. };
  1704. };
  1705. return NULL;
  1706. }
  1707. CSTR boschRCP::media_GetSnapshotUri(CSTR profileToken)
  1708. {
  1709. char tBuffer[DEFAULT_BUFFER_SIZE];
  1710. accessToken tTOKEN;
  1711. tTOKEN = _makeToken();
  1712. sprintf(tBuffer, PONVIF_PACK_GET_PICTURE_URI, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken);
  1713. if (_send_request(m_pMediaURI, tBuffer))
  1714. {
  1715. XMLResults tParseResults;
  1716. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  1717. LOG("RCPT:");
  1718. printf(m_pLastResponse);
  1719. if (tParseResults.error)
  1720. {
  1721. char tBuf[CTEXT];
  1722. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  1723. LOG_ERROR(tBuf);
  1724. }
  1725. else
  1726. {
  1727. // Parse
  1728. // return $response['Envelope']['Body']['GetSnapshotUriResponse']['MediaUri']['Uri'];
  1729. };
  1730. };
  1731. return NULL;
  1732. }
  1733. bool boschRCP::ptz_GetStatus(CSTR profileToken, ptzStatus * tStatus)
  1734. {
  1735. if (m_pPTZURI == NULL)
  1736. {
  1737. return false;
  1738. }
  1739. if (tStatus == NULL)
  1740. {
  1741. return false;
  1742. }
  1743. char tBuffer[DEFAULT_BUFFER_SIZE];
  1744. accessToken tTOKEN;
  1745. tTOKEN = _makeToken();
  1746. memset(tStatus, 0, sizeof(ptzStatus));
  1747. sprintf(tBuffer, PONVIF_PACK_GET_PTZ_STATUS, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken);
  1748. if (_send_request(m_pPTZURI, tBuffer, true))
  1749. {
  1750. XMLResults tParseResults;
  1751. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  1752. if (tParseResults.error)
  1753. {
  1754. char tBuf[CTEXT];
  1755. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  1756. LOG_ERROR(tBuf);
  1757. }
  1758. else
  1759. {
  1760. XMLNode aNode = response.getChildNode("Body", 0);
  1761. if (aNode.isEmpty())
  1762. {
  1763. return NULL;
  1764. }
  1765. XMLNode bNode = aNode.getChildNode("GetStatusResponse", 0);
  1766. if (! bNode.isEmpty())
  1767. {
  1768. XMLNode cNode = bNode.getChildNode("PTZStatus", 0);
  1769. if (! cNode.isEmpty())
  1770. {
  1771. XMLNode dNode = cNode.getChildNode("Position", 0);
  1772. if (! dNode.isEmpty())
  1773. {
  1774. XMLNode eNode = dNode.getChildNode("PanTilt", 0);
  1775. if (! eNode.isEmpty())
  1776. {
  1777. // XMLAttribute ZZ = eNode.getAttribute(1);
  1778. // LOG( ZZ.lpszName );
  1779. tStatus->pan = atof(eNode.getAttribute("x")); // ZZ.lpszValue );
  1780. // ZZ = eNode.getAttribute(2);
  1781. // LOG( ZZ.lpszName );
  1782. tStatus->tilt = atof(eNode.getAttribute("y")); // ZZ.lpszValue );
  1783. };
  1784. XMLNode fNode = dNode.getChildNode("Zoom", 0);
  1785. if (! fNode.isEmpty())
  1786. {
  1787. // XMLAttribute ZZ = eNode.getAttribute(1);
  1788. // LOG( ZZ.lpszName );
  1789. tStatus->zoom = atof(fNode.getAttribute("x")); // ZZ.lpszValue );
  1790. };
  1791. };
  1792. if (tStatus->pan != .0f || tStatus->tilt != .0f || tStatus->zoom != .0f)
  1793. {
  1794. XMLNode gNode = cNode.getChildNode("MoveStatus", 0);
  1795. if (! gNode.isEmpty())
  1796. {
  1797. tStatus->hasMoveStatus = true;
  1798. XMLNode hNode = gNode.getChildNode("PanTilt", 0);
  1799. if (! hNode.isEmpty())
  1800. {
  1801. if (strstr(hNode.getText(0), "IDLE") != NULL)
  1802. {
  1803. tStatus->PanTiltIdle = true;
  1804. }
  1805. };
  1806. XMLNode iNode = gNode.getChildNode("Zoom", 0);
  1807. if (! iNode.isEmpty())
  1808. {
  1809. if (strstr(iNode.getText(0), "IDLE") != NULL)
  1810. {
  1811. tStatus->ZoomIdle = true;
  1812. }
  1813. };
  1814. };
  1815. }
  1816. return true;
  1817. };
  1818. };
  1819. };
  1820. };
  1821. return false;
  1822. }
  1823. bool boschRCP::ptz_GetPresets(CSTR profileToken)
  1824. {
  1825. if (m_pPTZURI == NULL)
  1826. {
  1827. return false;
  1828. }
  1829. char tBuffer[DEFAULT_BUFFER_SIZE];
  1830. accessToken tTOKEN;
  1831. tTOKEN = _makeToken();
  1832. sprintf(tBuffer, PONVIF_PACK_GET_PRESETS, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken);
  1833. if (_send_request(m_pPTZURI, tBuffer))
  1834. {
  1835. // XMLResults tParseResults;
  1836. // XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1837. // LOG("RCPT:");
  1838. // LOG( m_pLastResponse );
  1839. // if( tParseResults.error ){
  1840. // char tBuf[CTEXT];
  1841. // sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1842. // LOG_ERROR( tBuf );
  1843. // } else {
  1844. //$getpresetsresponse=$response['Envelope']['Body']['GetPresetsResponse']['Preset'];
  1845. //$presets=array();
  1846. // foreach ($getpresetsresponse as $preset) {
  1847. // $presets[]=array('Token'=>$preset['@attributes']['token'],
  1848. // 'Name'=>$preset['Name'],
  1849. // 'PTZPosition'=>$preset['PTZPosition']);
  1850. // }
  1851. // return $presets;
  1852. return true;
  1853. //};
  1854. };
  1855. return false;
  1856. }
  1857. bool boschRCP::ptz_GetNode(CSTR ptzNodeToken)
  1858. {
  1859. if (m_pPTZURI == NULL)
  1860. {
  1861. return false;
  1862. }
  1863. char tBuffer[DEFAULT_BUFFER_SIZE];
  1864. accessToken tTOKEN;
  1865. tTOKEN = _makeToken();
  1866. sprintf(tBuffer, PONVIF_PACK_GET_PTZ_NODE, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, ptzNodeToken);
  1867. if (_send_request(m_pPTZURI, tBuffer))
  1868. {
  1869. XMLResults tParseResults;
  1870. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  1871. LOG("RCPT:");
  1872. printf(m_pLastResponse);
  1873. if (tParseResults.error)
  1874. {
  1875. char tBuf[CTEXT];
  1876. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  1877. LOG_ERROR(tBuf);
  1878. }
  1879. else
  1880. {
  1881. // return $response['Envelope']['Body']['GetNodeResponse'];
  1882. };
  1883. };
  1884. return false;
  1885. }
  1886. bool boschRCP::ptz_GotoPreset(CSTR profileToken, CSTR presetToken, float speed_pantilt_x, float speed_pantilt_y, float speed_zoom_x)
  1887. {
  1888. if (m_pPTZURI == NULL)
  1889. {
  1890. return false;
  1891. }
  1892. char tBuffer[DEFAULT_BUFFER_SIZE];
  1893. accessToken tTOKEN;
  1894. tTOKEN = _makeToken();
  1895. sprintf(tBuffer, PONVIF_PACK_GOTO_PRESET, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, presetToken, speed_pantilt_x, speed_pantilt_y, speed_zoom_x);
  1896. return _send_request(m_pPTZURI, tBuffer, true);
  1897. }
  1898. bool boschRCP::ptz_RemovePreset(CSTR profileToken, CSTR presetToken)
  1899. {
  1900. if (m_pPTZURI == NULL)
  1901. {
  1902. return false;
  1903. }
  1904. char tBuffer[DEFAULT_BUFFER_SIZE];
  1905. accessToken tTOKEN;
  1906. tTOKEN = _makeToken();
  1907. sprintf(tBuffer, PONVIF_PACK_REMOVE_PRESET, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, presetToken);
  1908. return _send_request(m_pPTZURI, tBuffer, true);
  1909. }
  1910. bool boschRCP::ptz_SetPreset(CSTR profileToken, CSTR presetName)
  1911. {
  1912. if (m_pPTZURI == NULL)
  1913. {
  1914. return false;
  1915. }
  1916. char tBuffer[DEFAULT_BUFFER_SIZE];
  1917. accessToken tTOKEN;
  1918. tTOKEN = _makeToken();
  1919. sprintf(tBuffer, PONVIF_PACK_SET_PRESET, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, presetName);
  1920. return _send_request(m_pPTZURI, tBuffer, true);
  1921. }
  1922. bool boschRCP::ptz_RelativeMove(CSTR profileToken, float translation_pantilt_x, float translation_pantilt_y, float speed_pantilt_x, float speed_pantilt_y)
  1923. {
  1924. if (m_pPTZURI == NULL)
  1925. {
  1926. return false;
  1927. }
  1928. char tBuffer[DEFAULT_BUFFER_SIZE];
  1929. accessToken tTOKEN;
  1930. tTOKEN = _makeToken();
  1931. sprintf(tBuffer, PONVIF_PACK_RELATIVE_MOVE, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, translation_pantilt_x, translation_pantilt_y, speed_pantilt_x, speed_pantilt_y);
  1932. return _send_request(m_pPTZURI, tBuffer, true);
  1933. }
  1934. bool boschRCP::ptz_RelativeMoveZoom(CSTR profileToken, float zoom, float speedZoom)
  1935. {
  1936. if (m_pPTZURI == NULL)
  1937. {
  1938. return false;
  1939. }
  1940. char tBuffer[DEFAULT_BUFFER_SIZE];
  1941. accessToken tTOKEN;
  1942. tTOKEN = _makeToken();
  1943. sprintf(tBuffer, PONVIF_PACK_RELATIVE_ZOOM, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, zoom, speedZoom);
  1944. return _send_request(m_pPTZURI, tBuffer, true);
  1945. }
  1946. bool boschRCP::ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom)
  1947. {
  1948. if (m_pPTZURI == NULL)
  1949. {
  1950. return false;
  1951. }
  1952. char tBuffer[DEFAULT_BUFFER_SIZE];
  1953. accessToken tTOKEN;
  1954. tTOKEN = _makeToken();
  1955. sprintf(tBuffer, PONVIF_PACK_ABSOLUTE_MOVE, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, position_pantilt_x, position_pantilt_y, zoom);
  1956. return _send_request(m_pPTZURI, tBuffer, false);
  1957. }
  1958. bool boschRCP::ptz_ContinuousMove(CSTR profileToken, float velocity_pantilt_x, float velocity_pantilt_y)
  1959. {
  1960. if (m_pPTZURI == NULL)
  1961. {
  1962. return false;
  1963. }
  1964. char tBuffer[DEFAULT_BUFFER_SIZE];
  1965. accessToken tTOKEN;
  1966. tTOKEN = _makeToken();
  1967. sprintf(tBuffer, PONVIF_PACK_CONTINUOUS_MOVE, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, velocity_pantilt_x, velocity_pantilt_y);
  1968. return _send_request(m_pPTZURI, tBuffer, true);
  1969. }
  1970. bool boschRCP::ptz_ContinuousMoveZoom(CSTR profileToken, float zoom)
  1971. {
  1972. if (m_pPTZURI == NULL)
  1973. {
  1974. return false;
  1975. }
  1976. char tBuffer[DEFAULT_BUFFER_SIZE];
  1977. accessToken tTOKEN;
  1978. tTOKEN = _makeToken();
  1979. sprintf(tBuffer, PONVIF_PACK_CONTINUOUS_ZOOM, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, zoom);
  1980. return _send_request(m_pPTZURI, tBuffer, true);
  1981. }
  1982. bool boschRCP::ptz_Stop(CSTR profileToken, bool pantilt, bool zoom)
  1983. {
  1984. if ( pantilt || zoom ) profileToken = profileToken;
  1985. if (m_pPTZURI == NULL)
  1986. {
  1987. return false;
  1988. }
  1989. char tBuffer[DEFAULT_BUFFER_SIZE];
  1990. accessToken tTOKEN;
  1991. tTOKEN = _makeToken();
  1992. sprintf(tBuffer, PONVIF_PACK_PTZ_STOP, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken); //, pantilt, zoom );
  1993. return _send_request(m_pPTZURI, tBuffer, true);
  1994. }
  1995. /*
  1996. Internal functions
  1997. */
  1998. accessToken boschRCP::_makeToken(void)
  1999. {
  2000. time_t tTS = time(NULL) - m_nDeltaTime;
  2001. return _passwordDigest(m_pUsername, m_pPassword, tTS);
  2002. }
  2003. void boschRCP::_getOnvifVersion(nodeCapability & caps)
  2004. {
  2005. if (caps.Device != NULL)
  2006. {
  2007. if (caps.Device->System != NULL)
  2008. {
  2009. if (caps.Device->System->SupportedVersions != NULL)
  2010. {
  2011. m_sOnvifVersion.Major = caps.Device->System->SupportedVersions->Major;
  2012. m_sOnvifVersion.Minor = caps.Device->System->SupportedVersions->Minor;
  2013. };
  2014. };
  2015. };
  2016. if (caps.PTZ != NULL)
  2017. {
  2018. m_pPTZURI = caps.PTZ->XAddr;
  2019. };
  2020. if (caps.Media != NULL)
  2021. {
  2022. m_pMediaURI = caps.Media->XAddr;
  2023. };
  2024. if (caps.Device != NULL)
  2025. {
  2026. m_pDeviceURI = caps.Device->XAddr;
  2027. };
  2028. }
  2029. /*
  2030. protected function _getActiveSources($videoSources,$profiles) {
  2031. $sources=array();
  2032. if (isset($videoSources['@attributes'])) {
  2033. // NVT is a camera
  2034. $sources[0]['sourcetoken']=$videoSources['@attributes']['token'];
  2035. $this->_getProfileData($sources,0,$profiles);
  2036. }
  2037. else {
  2038. // NVT is an encoder
  2039. for ($i=0;$i<count($videoSources);$i++) {
  2040. if (strtolower($videoSources[$i]['@attributes']['SignalActive'])=='true') {
  2041. $sources[$i]['sourcetoken']=$videoSources[$i]['@attributes']['token'];
  2042. $this->_getProfileData($sources,$i,$profiles);
  2043. }
  2044. } // for
  2045. }
  2046. return $sources;
  2047. }
  2048. void pOnvif::_getProfileData( sources,$i, XMLNode profiles ){
  2049. //$inprofile=0;
  2050. videoSourceProfile *tPtr;
  2051. for( $y=0; $y < count($profiles); $y++ ){
  2052. if ($profiles[$y]['VideoSourceConfiguration']['SourceToken']==$sources[$i]['sourcetoken']) {
  2053. $sources[$i][$inprofile]['profilename']=$profiles[$y]['Name'];
  2054. $sources[$i][$inprofile]['profiletoken']=$profiles[$y]['@attributes']['token'];
  2055. if ( isset($profiles[$y]['VideoEncoderConfiguration'])) {
  2056. $sources[$i][$inprofile]['encoding']=$profiles[$y]['VideoEncoderConfiguration']['Encoding'];
  2057. $sources[$i][$inprofile]['width']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Width'];
  2058. $sources[$i][$inprofile]['height']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Height'];
  2059. $sources[$i][$inprofile]['fps']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['FrameRateLimit'];
  2060. $sources[$i][$inprofile]['bitrate']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['BitrateLimit'];
  2061. }
  2062. if ( isset($profiles[$y]['PTZConfiguration'])) {
  2063. $sources[$i][$inprofile]['ptz']['name']=$profiles[$y]['PTZConfiguration']['Name'];
  2064. $sources[$i][$inprofile]['ptz']['nodetoken']=$profiles[$y]['PTZConfiguration']['NodeToken'];
  2065. }
  2066. $inprofile++;
  2067. }
  2068. }
  2069. };
  2070. */
  2071. /*
  2072. protected function _xml2array($response) {
  2073. $sxe = new SimpleXMLElement($response);
  2074. $dom_sxe = dom_import_simplexml($sxe);
  2075. $dom = new DOMDocument('1.0');
  2076. $dom_sxe = $dom->importNode($dom_sxe, true);
  2077. $dom_sxe = $dom->appendChild($dom_sxe);
  2078. $element = $dom->childNodes->item(0);
  2079. foreach ($sxe->getDocNamespaces() as $name => $uri) {
  2080. $element->removeAttributeNS($uri, $name);
  2081. }
  2082. $xmldata=$dom->saveXML();
  2083. $xmldata=substr($xmldata,strpos($xmldata,"<Envelope>"));
  2084. $xmldata=substr($xmldata,0,strpos($xmldata,"</Envelope>")+strlen("</Envelope>"));
  2085. $xml=simplexml_load_string($xmldata);
  2086. $data=json_decode(json_encode((array)$xml),1);
  2087. $data=array($xml->getName()=>$data);
  2088. return $data;
  2089. }
  2090. */
  2091. accessToken boschRCP::_passwordDigest(CSTR username, CSTR password, time_t timestamp, uint32_t nonce)
  2092. {
  2093. accessToken RetVal;
  2094. char tTS[CTEXT];
  2095. unsigned char * tPDIGEST;
  2096. if (timestamp == 0)
  2097. {
  2098. time_t t;
  2099. struct tm * tmp;
  2100. t = time(NULL);
  2101. tmp = gmtime(&t);
  2102. if (tmp == NULL)
  2103. {
  2104. LOG_ERROR("gmtime Error!");
  2105. };
  2106. if (strftime(tTS, 200, "%FT%TZ", tmp) == 0)
  2107. {
  2108. LOG_ERROR("strftime returned 0!");
  2109. };
  2110. }
  2111. else
  2112. {
  2113. struct tm * tmp;
  2114. tmp = gmtime(&timestamp);
  2115. if (tmp == NULL)
  2116. {
  2117. LOG_ERROR("gmtime Error!");
  2118. };
  2119. if (strftime(tTS, 200, "%FT%TZ", tmp) == 0)
  2120. {
  2121. LOG_ERROR("strftime returned 0!");
  2122. };
  2123. };
  2124. if (nonce == 0)
  2125. {
  2126. nonce = (uint32_t) rand();
  2127. };
  2128. unsigned char tBuff[CTEXT];
  2129. int cp = 0;
  2130. int index = 0;
  2131. for (; index < 4; index++)
  2132. {
  2133. tBuff[cp++] = ((unsigned char *) (&nonce))[index];
  2134. };
  2135. index = 0;
  2136. while (tTS[index] != '\0')
  2137. {
  2138. tBuff[cp++] = (unsigned char) tTS[index];
  2139. index++;
  2140. };
  2141. index = 0;
  2142. while (password[index] != '\0')
  2143. {
  2144. tBuff[cp++] = (unsigned char) password[index];
  2145. index++;
  2146. };
  2147. size_t baseOutLen;
  2148. unsigned char tSHA[SHA_DIGEST_LENGTH];
  2149. SHA1(tBuff, cp, tSHA);
  2150. // tPDIGEST = base64_encode(pack('H*', sha1(pack('H*', $nonce) . pack('a*',$timestamp).pack('a*',$password))));
  2151. tPDIGEST = base64_encode(tSHA, SHA_DIGEST_LENGTH, &baseOutLen);
  2152. // free( tSHA );
  2153. //$passdigest=base64_encode(sha1($nonce.$timestamp.$password,true)); // alternative
  2154. strncpy(RetVal.USERNAME, username, CTEXT);
  2155. strncpy(RetVal.TIMESTAMP, tTS, CTEXT);
  2156. strncpy(RetVal.PASSDIGEST, (const char *) tPDIGEST, CTEXT);
  2157. free(tPDIGEST);
  2158. tPDIGEST = base64_encode((unsigned char *) &nonce, 4, &baseOutLen);
  2159. strncpy(RetVal.NONCE, (const char *) tPDIGEST, baseOutLen);
  2160. RetVal.NONCE[baseOutLen] = '\0';
  2161. free(tPDIGEST);
  2162. //$REQ['NONCE']=base64_encode($nonce); // alternative
  2163. return RetVal;
  2164. }
  2165. void * boschRCP::parser(void * obj, void * ptr)
  2166. {
  2167. boschRCP * ME = (boschRCP *) obj;
  2168. curlRequest * RQ = (curlRequest *) ptr;
  2169. if (ME)
  2170. {
  2171. if (ME->m_pLastResponse)
  2172. {
  2173. free(ME->m_pLastResponse);
  2174. }
  2175. ME->m_pLastResponse = (CSTR) malloc(RQ->getSize() + 1);
  2176. if (ME->m_pLastResponse)
  2177. {
  2178. memcpy(ME->m_pLastResponse, RQ->getBuffer(), RQ->getSize());
  2179. ME->m_pLastResponse[RQ->getSize()] = (char) 0;
  2180. #ifdef DEBUG_ONVIF_TRAFFIC
  2181. FILE * tf;
  2182. tf = fopen("Traffic.txt", "a+");
  2183. fprintf(tf, "~~~~~~~~~~~~~~~~~~~~\r\n");
  2184. fprintf(tf, "<<<<< [%d] %s\n", RQ->getSize(), ME->m_pLastResponse);
  2185. fprintf(tf, "~~~~~~~~~~~~~~~~~~~~\r\n");
  2186. fclose(tf);
  2187. #endif
  2188. };
  2189. ME->parser_done = true;
  2190. };
  2191. return NULL;
  2192. }
  2193. bool boschRCP::_send_request(CSTR url, CSTR post_string, bool mustReturnData)
  2194. {
  2195. #ifdef CURL_MANAGER
  2196. bool RetVal = false;
  2197. if (m_pHttpAccessManager)
  2198. {
  2199. m_mResponseProtector.lock();
  2200. curlRequest * tRC; // application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver10/device/wsdl/GetSystemDateAndTime"
  2201. tRC = new curlRequest(url, (CSTR) "application/soap+xml; charset=utf-8;");
  2202. if (tRC != NULL)
  2203. {
  2204. #ifdef DEBUG_ONVIF_TRAFFIC
  2205. FILE * tf;
  2206. tf = fopen("Traffic.txt", "a+");
  2207. fprintf(tf, "--------------------\r\n");
  2208. fprintf(tf, "REQ: %s (%d)\n", url, strlen(post_string));
  2209. fprintf(tf, ">>>>> %s\n", post_string);
  2210. fprintf(tf, "--------------------\r\n");
  2211. fclose(tf);
  2212. mustReturnData = true; // In Debug Allways Read Return
  2213. #endif
  2214. tRC->setCredentials(m_pUsername, m_pPassword, m_bAuthMode);
  2215. tRC->setPOST(post_string, strlen(post_string));
  2216. if (mustReturnData)
  2217. {
  2218. tRC->setHandler((void *) this, pOnvif::parser, (void *) tRC);
  2219. if (m_pHttpAccessManager->accomplish(tRC))
  2220. {
  2221. parser_done = false;
  2222. uint8_t cnt = 200; // TO = 2 second
  2223. while (! RetVal && cnt--)
  2224. {
  2225. RetVal = parser_done;
  2226. SLEEP(10);
  2227. };
  2228. };
  2229. }
  2230. else
  2231. {
  2232. RetVal = m_pHttpAccessManager->accomplish(tRC);
  2233. };
  2234. }
  2235. else
  2236. {
  2237. LOG_ERROR("Cannot Create curlRequest!");
  2238. }
  2239. m_mResponseProtector.unlock();
  2240. };
  2241. return RetVal;
  2242. #else
  2243. char tBuffer[CTEXT];
  2244. if (m_pCURL == NULL)
  2245. {
  2246. if (m_pLastResponse == NULL)
  2247. {
  2248. m_pLastResponse = (CSTR) malloc(DEFAULT_BUFFER_SIZE);
  2249. };
  2250. m_pCURL = curl_easy_init();
  2251. if (m_pProxyHost != NULL && m_nProxyPort != 0)
  2252. {
  2253. curl_easy_setopt(m_pCURL, CURLOPT_PROXY, m_pProxyHost);
  2254. curl_easy_setopt(m_pCURL, CURLOPT_PROXYPORT, m_nProxyPort);
  2255. if (m_pProxyUsername != NULL && m_pProxyPassword != NULL)
  2256. {
  2257. sprintf(tBuffer, "%s:%s", m_pProxyUsername, m_pProxyPassword);
  2258. curl_easy_setopt(m_pCURL, CURLOPT_PROXYUSERPWD, tBuffer);
  2259. };
  2260. };
  2261. curl_easy_setopt(m_pCURL, CURLOPT_CONNECTTIMEOUT, 1);
  2262. curl_easy_setopt(m_pCURL, CURLOPT_TIMEOUT, 2);
  2263. curl_easy_setopt(m_pCURL, CURLOPT_SSL_VERIFYPEER, 0);
  2264. curl_easy_setopt(m_pCURL, CURLOPT_SSL_VERIFYHOST, 0);
  2265. curl_easy_setopt(m_pCURL, CURLOPT_VERBOSE, 0);
  2266. curl_easy_setopt(m_pCURL, CURLOPT_POST, 1);
  2267. // curl_easy_setopt( m_pCURL, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS, 0 );
  2268. // curl_easy_setopt( m_pCURL, CURLOPT_NOPROGRESS, 1 );
  2269. // curl_easy_setopt( m_pCURL, CURLOPT_NOSIGNAL, 1 );
  2270. curl_easy_setopt(m_pCURL, CURLOPT_TCP_FASTOPEN, 1);
  2271. curl_easy_setopt(m_pCURL, CURLOPT_TCP_NODELAY, 1);
  2272. // curl_easy_setopt( m_pCURL, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
  2273. curl_easy_setopt(m_pCURL, CURLOPT_WRITEFUNCTION, pOnvif::_writer);
  2274. curl_easy_setopt(m_pCURL, CURLOPT_WRITEDATA, this);
  2275. };
  2276. if (m_pCURL != NULL)
  2277. {
  2278. curl_easy_setopt(m_pCURL, CURLOPT_URL, url);
  2279. struct curl_slist * sList = NULL;
  2280. // Content-Type: application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"
  2281. // Connection: Close
  2282. sList = curl_slist_append(sList, "Content-Type: text/xml; charset=utf-8");
  2283. sprintf(tBuffer, "Content-Length: %d", strlen(post_string));
  2284. sList = curl_slist_append(sList, tBuffer);
  2285. curl_easy_setopt(m_pCURL, CURLOPT_HTTPHEADER, sList);
  2286. curl_easy_setopt(m_pCURL, CURLOPT_POSTFIELDS, post_string);
  2287. sprintf(tBuffer, "%s:%s", m_pUsername, m_pPassword);
  2288. curl_easy_setopt(m_pCURL, CURLOPT_USERPWD, tBuffer);
  2289. switch (m_bAuthMode)
  2290. {
  2291. case 0: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); break;
  2292. case 1: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); break;
  2293. case 2: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST_IE); break;
  2294. case 3: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BEARER); break;
  2295. case 4: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE); break;
  2296. case 5: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); break;
  2297. case 6: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM_WB); break;
  2298. case 7: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY); break;
  2299. case 8: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); break;
  2300. case 9:
  2301. curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ONLY);
  2302. break;
  2303. // case 10: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_AWS_SIGV4 ); break;
  2304. };
  2305. #ifdef DEBUG
  2306. char tErrorBuffer[CURL_ERROR_SIZE];
  2307. curl_easy_setopt(m_pCURL, CURLOPT_ERRORBUFFER, tErrorBuffer);
  2308. #endif
  2309. m_pLastIndex = 0;
  2310. if (curl_easy_perform(m_pCURL))
  2311. {
  2312. LOG_ERROR("CURL Failure!");
  2313. #ifdef DEBUG
  2314. LOG_ERROR(tErrorBuffer);
  2315. #endif
  2316. }
  2317. else
  2318. {
  2319. m_pLastResponse[m_pLastIndex] = (char) 0;
  2320. return true;
  2321. };
  2322. m_pLastIndex = 0;
  2323. };
  2324. return false;
  2325. #endif
  2326. }
  2327. #ifndef CURL_MANAGER
  2328. int boschRCP::_writer(char * data, size_t size, size_t nmemb, boschRCP * Ptr)
  2329. {
  2330. if (Ptr == NULL)
  2331. {
  2332. return 0;
  2333. }
  2334. // TLOG("*");
  2335. memcpy(Ptr->m_pLastResponse + Ptr->m_pLastIndex, data, size * nmemb);
  2336. Ptr->m_pLastIndex += size * nmemb;
  2337. return size * nmemb;
  2338. }
  2339. #endif
  2340. bool boschRCP::setAuthMode(uint8_t Mode)
  2341. {
  2342. m_bAuthMode = Mode;
  2343. #ifdef DEBUG
  2344. switch (m_bAuthMode)
  2345. {
  2346. case 0 : LOG("Set Auth CURLAUTH_BASIC"); break;
  2347. case 1 : LOG("Set Auth CURLAUTH_DIGEST"); break;
  2348. case 2 : LOG("Set Auth CURLAUTH_DIGEST_IE"); break;
  2349. case 3 : LOG("Set Auth CURLAUTH_BEARER"); break;
  2350. case 4 : LOG("Set Auth CURLAUTH_NEGOTIATE"); break;
  2351. case 5 : LOG("Set Auth CURLAUTH_NTLM"); break;
  2352. case 6 : LOG("Set Auth CURLAUTH_NTLM_WB"); break;
  2353. case 7 : LOG("Set Auth CURLAUTH_ANY"); break;
  2354. case 8 : LOG("Set Auth CURLAUTH_ANYSAFE"); break;
  2355. case 9 : LOG("Set Auth CURLAUTH_ONLY"); break;
  2356. case 10: LOG("Set Auth CURLAUTH_AWS_SIGV4"); break;
  2357. };
  2358. #endif
  2359. return true;
  2360. }
  2361. #undef LOG
  2362. #undef TLOG
  2363. #undef LOG_ERROR