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.

2618 lines
77 KiB

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