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.

1282 lines
33 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
5 months ago
​
​
​
​
5 months ago
​
5 months ago
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
5 months ago
​
​
​
​
​
5 months ago
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
5 months ago
​
​
5 months ago
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
5 months ago
​
​
​
5 months ago
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
5 months ago
​
5 months ago
5 months ago
​
5 months ago
​
5 months ago
​
5 months ago
​
5 months ago
​
​
​
​
​
5 months ago
​
5 months ago
​
​
5 months ago
​
5 months ago
​
5 months ago
​
​
5 months ago
5 months ago
​
5 months ago
​
5 months ago
5 months ago
​
​
​
​
​
​
​
5 months ago
​
​
​
5 months ago
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
5 months ago
​
​
5 months ago
​
​
​
​
​
​
​
5 months ago
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. const char *BRPC_TYPE_TAG[8]={
  21. "F_FLAG",
  22. "T_OCTET",
  23. "T_WORD",
  24. "T_INT",
  25. "T_DWORD",
  26. "P_OCTET",
  27. "P_STRING",
  28. "P_UNICODE"
  29. };
  30. const char *BRPC_OP_TAG[2]={
  31. "READ",
  32. "WRITE"
  33. };
  34. inline bool checkBool(const char * A)
  35. {
  36. if (A == NULL)
  37. {
  38. return false;
  39. }
  40. return (A[0] == 'T' || A[0] == 't' || A[0] == '1');
  41. }
  42. inline bool checkOnOff(const char * A)
  43. {
  44. if (A == NULL)
  45. {
  46. return false;
  47. }
  48. return (A[1] == 'N' || A[1] == 'n' || A[0] == '1');
  49. }
  50. inline onvifOnOffAuto checkOnOffAuto(const char * A)
  51. {
  52. if (A == NULL)
  53. {
  54. return AUTO;
  55. }
  56. if (A[1] == 'N' || A[1] == 'n' || A[0] == '1')
  57. {
  58. return ON;
  59. }
  60. return OFF;
  61. }
  62. boschRCP::boschRCP()
  63. {
  64. m_pLog = basicLogCollection::getInstance();
  65. m_pIpAddress = NULL;
  66. m_pUsername = NULL;
  67. m_pPassword = NULL;
  68. m_pMediaURI = NULL;
  69. m_pSnapshotURI = NULL;
  70. m_pDeviceURI = NULL;
  71. m_pPTZURI = NULL;
  72. m_pBaseURI = NULL;
  73. m_nDeltaTime = 0;
  74. m_pCURL = NULL;
  75. m_pProxyHost = NULL;
  76. m_nProxyPort = 0;
  77. m_pProxyUsername = NULL;
  78. m_pProxyPassword = NULL;
  79. m_pLastResponse = NULL;
  80. m_bIntransingent = true;
  81. m_nDiscoveryTimeout = 30;//PONVIF_DEFAULT_DISCOVERYTIMEOUT;
  82. m_pDiscoveryBindIP = NULL; // PONVIF_DEFAULT_DISCOVERYBINDIP;
  83. m_pDiscoveryMCastIP = NULL; // PONVIF_DEFAULT_DISCOVERYMCASTIP;
  84. m_nDiscoveryMCastPort = 30;//PONVIF_DEFAULT_DISCOVERYMCASTPORT;
  85. m_bDiscoveryHideDuplicates = true;
  86. m_pHttpAccessManager = NULL;
  87. m_sCapabilities.Analytics = NULL;
  88. m_sCapabilities.Device = NULL;
  89. m_sCapabilities.Events = NULL;
  90. m_sCapabilities.Imaging = NULL;
  91. m_sCapabilities.Media = NULL;
  92. m_sCapabilities.PTZ = NULL;
  93. m_sCapabilities.Extension = NULL;
  94. m_bAuthMode = 0;
  95. LOG("Constructor Done!");
  96. }
  97. boschRCP::~boschRCP()
  98. {
  99. #ifdef DEBUG
  100. LOG("Destructor begin");
  101. #endif
  102. if (m_pIpAddress)
  103. {
  104. free(m_pIpAddress);
  105. }
  106. if (m_pUsername)
  107. {
  108. free(m_pUsername);
  109. }
  110. if (m_pPassword)
  111. {
  112. free(m_pPassword);
  113. }
  114. if (m_pMediaURI)
  115. {
  116. free(m_pMediaURI);
  117. }
  118. if (m_pSnapshotURI)
  119. {
  120. free(m_pSnapshotURI);
  121. }
  122. if (m_pDeviceURI)
  123. {
  124. free(m_pDeviceURI);
  125. }
  126. if (m_pPTZURI)
  127. {
  128. free(m_pPTZURI);
  129. }
  130. if (m_pBaseURI)
  131. {
  132. free(m_pBaseURI);
  133. }
  134. if (m_pProxyHost)
  135. {
  136. free(m_pProxyHost);
  137. }
  138. if (m_pProxyUsername)
  139. {
  140. free(m_pProxyUsername);
  141. }
  142. if (m_pProxyPassword)
  143. {
  144. free(m_pProxyPassword);
  145. }
  146. if (m_pLastResponse)
  147. {
  148. free(m_pLastResponse);
  149. }
  150. if (m_pDiscoveryBindIP)
  151. {
  152. free(m_pDiscoveryBindIP);
  153. }
  154. if (m_pDiscoveryMCastIP)
  155. {
  156. free(m_pDiscoveryMCastIP);
  157. }
  158. if (m_sCapabilities.Analytics)
  159. {
  160. free(m_sCapabilities.Analytics);
  161. }
  162. if (m_sCapabilities.Device)
  163. {
  164. free(m_sCapabilities.Device);
  165. }
  166. if (m_sCapabilities.Events)
  167. {
  168. free(m_sCapabilities.Events);
  169. }
  170. if (m_sCapabilities.Imaging)
  171. {
  172. free(m_sCapabilities.Imaging);
  173. }
  174. if (m_sCapabilities.Media)
  175. {
  176. free(m_sCapabilities.Media);
  177. }
  178. if (m_sCapabilities.PTZ)
  179. {
  180. free(m_sCapabilities.PTZ);
  181. }
  182. if (m_sCapabilities.Extension)
  183. {
  184. free(m_sCapabilities.Extension);
  185. }
  186. if (m_pCURL)
  187. {
  188. #ifdef DEBUG
  189. LOG("Try Cleanup CURL!");
  190. #endif
  191. curl_easy_cleanup(m_pCURL);
  192. m_pCURL = NULL;
  193. };
  194. #ifdef DEBUG
  195. LOG("Destructor Done!");
  196. #endif
  197. }
  198. bool boschRCP::setProxyHost(CSTR proxyHost)
  199. {
  200. if (m_pProxyHost != NULL)
  201. {
  202. free(m_pProxyHost);
  203. }
  204. if (proxyHost == NULL || strlen(proxyHost) == 0)
  205. {
  206. m_pProxyHost = NULL;
  207. return true;
  208. };
  209. m_pProxyHost = (CSTR) malloc(strlen(proxyHost) + 1);
  210. if (m_pProxyHost == NULL)
  211. {
  212. return false;
  213. }
  214. memcpy(m_pProxyHost, proxyHost, strlen(proxyHost) + 1);
  215. return true;
  216. }
  217. CSTR boschRCP::getProxyHost()
  218. {
  219. return m_pProxyHost;
  220. }
  221. bool boschRCP::setProxyPort(int proxyPort)
  222. {
  223. m_nProxyPort = proxyPort;
  224. return true;
  225. }
  226. int boschRCP::getProxyPort(void)
  227. {
  228. return m_nProxyPort;
  229. }
  230. bool boschRCP::setProxyUsername(CSTR proxyUsername)
  231. {
  232. if (m_pProxyUsername != NULL)
  233. {
  234. free(m_pProxyUsername);
  235. }
  236. if (proxyUsername == NULL || strlen(proxyUsername) == 0)
  237. {
  238. m_pProxyUsername = NULL;
  239. return true;
  240. };
  241. m_pProxyUsername = (CSTR) malloc(strlen(proxyUsername) + 1);
  242. if (m_pProxyUsername == NULL)
  243. {
  244. return false;
  245. }
  246. memcpy(m_pProxyUsername, proxyUsername, strlen(proxyUsername) + 1);
  247. return true;
  248. }
  249. CSTR boschRCP::getProxyUsername(void)
  250. {
  251. return m_pProxyUsername;
  252. }
  253. bool boschRCP::setProxyPassword(CSTR proxyPassword)
  254. {
  255. if (m_pProxyPassword != NULL)
  256. {
  257. free(m_pProxyPassword);
  258. }
  259. if (proxyPassword == NULL || strlen(proxyPassword) == 0)
  260. {
  261. m_pProxyPassword = NULL;
  262. return true;
  263. };
  264. m_pProxyPassword = (CSTR) malloc(strlen(proxyPassword) + 1);
  265. if (m_pProxyPassword == NULL)
  266. {
  267. return false;
  268. }
  269. memcpy(m_pProxyPassword, proxyPassword, strlen(proxyPassword) + 1);
  270. return true;
  271. }
  272. CSTR boschRCP::getProxyPassword()
  273. {
  274. return m_pProxyPassword;
  275. }
  276. bool boschRCP::setUsername(CSTR username)
  277. {
  278. if (m_pUsername != NULL)
  279. {
  280. free(m_pUsername);
  281. }
  282. if (username == NULL || strlen(username) == 0)
  283. {
  284. m_pUsername = NULL;
  285. return true;
  286. };
  287. m_pUsername = (CSTR) malloc(strlen(username) + 1);
  288. if (m_pUsername == NULL)
  289. {
  290. return false;
  291. }
  292. memcpy(m_pUsername, username, strlen(username) + 1);
  293. return true;
  294. }
  295. CSTR boschRCP::getUsername(void)
  296. {
  297. return m_pUsername;
  298. }
  299. bool boschRCP::setPassword(CSTR password)
  300. {
  301. if (m_pPassword != NULL)
  302. {
  303. free(m_pPassword);
  304. }
  305. if (password == NULL || strlen(password) == 0)
  306. {
  307. m_pPassword = NULL;
  308. return true;
  309. };
  310. m_pPassword = (CSTR) malloc(strlen(password) + 1);
  311. if (m_pPassword == NULL)
  312. {
  313. return false;
  314. }
  315. memcpy(m_pPassword, password, strlen(password) + 1);
  316. return true;
  317. }
  318. CSTR boschRCP::getPassword(void)
  319. {
  320. return m_pPassword;
  321. }
  322. CSTR boschRCP::getDeviceUri(void)
  323. {
  324. return m_pDeviceURI;
  325. }
  326. bool boschRCP::setDeviceUri(CSTR deviceUri)
  327. {
  328. if (deviceUri == NULL || strlen(deviceUri) == 0){
  329. if (m_pDeviceURI != NULL) free(m_pDeviceURI);
  330. m_pDeviceURI = NULL;
  331. return false;
  332. };
  333. if (strstr(deviceUri, "http") == NULL){
  334. LOG_ERROR("Malformed device URI");
  335. if (m_pDeviceURI != NULL) free(m_pDeviceURI);
  336. m_pDeviceURI = NULL;
  337. return false;
  338. };
  339. if (m_pDeviceURI != NULL) free(m_pDeviceURI);
  340. m_pDeviceURI = (CSTR) malloc(strlen(deviceUri) + 1);
  341. if (m_pDeviceURI == NULL){
  342. return false;
  343. };
  344. memcpy( m_pDeviceURI, deviceUri, strlen(deviceUri));
  345. m_pDeviceURI[strlen(deviceUri)] = (char) 0;
  346. // toDo: Must parsed Host/IP
  347. char * tT = strstr(m_pDeviceURI, "/");
  348. if (tT)
  349. {
  350. tT += 2;
  351. char * tB = strstr(tT, "/");
  352. int len = tB - tT + 1;
  353. m_pIpAddress = (CSTR) malloc(len);
  354. if (m_pIpAddress)
  355. {
  356. len--;
  357. memcpy(m_pIpAddress, tT, len);
  358. m_pIpAddress[len] = (char) 0;
  359. LOG(m_pIpAddress);
  360. };
  361. };
  362. return true;
  363. }
  364. CSTR boschRCP::getIPAddress(void)
  365. {
  366. return m_pIpAddress;
  367. }
  368. bool boschRCP::setIPAddress(CSTR ipAddress)
  369. {
  370. if (ipAddress == NULL || strlen(ipAddress) == 0)
  371. {
  372. m_pIpAddress = NULL;
  373. return false;
  374. };
  375. if (m_pIpAddress != NULL)
  376. {
  377. free(m_pIpAddress);
  378. }
  379. m_pIpAddress = (CSTR) malloc(strlen(ipAddress) + 1);
  380. if (m_pIpAddress == NULL)
  381. {
  382. return false;
  383. }
  384. memcpy(m_pIpAddress, ipAddress, strlen(ipAddress));
  385. m_pIpAddress[strlen(ipAddress)] = (char) 0;
  386. int len = strlen(ipAddress) + 28;
  387. m_pDeviceURI = (CSTR) malloc(len + 1);
  388. if (m_pDeviceURI){
  389. sprintf( m_pDeviceURI, BRCP_DEFAULT_URI_TPL, m_pIpAddress);
  390. LOG(m_pDeviceURI);
  391. };
  392. return true;
  393. }
  394. //bool boschRCP::setDiscoveryTimeout(int discoverytimeout)
  395. //{
  396. // m_nDiscoveryTimeout = discoverytimeout;
  397. // return true;
  398. //}
  399. size_t boschRCP::createRequestString( CSTR buffer, uint16_t CMD, bool RW, int8_t pl_type, void *pl ){
  400. if ( buffer == NULL) return 0;
  401. if (pl != NULL) {
  402. sprintf(buffer, "%s?command=0x%04x&type=%s&direction=%s", m_pDeviceURI, CMD, BRPC_TYPE_TAG[pl_type],(RW?"READ":"WRITE"));
  403. } else {
  404. sprintf(buffer, "%s?command=0x%04x&direction=READ", m_pDeviceURI, CMD );
  405. };
  406. size_t rValue = strlen( buffer );
  407. return rValue;
  408. }
  409. bool boschRCP::create(void)
  410. {
  411. #ifdef DEBUG_EXTRA
  412. LOG("Get Instance m_pHttpAccessManager");
  413. #endif
  414. m_pHttpAccessManager = curlRequestsManager::getInstance();
  415. if (m_pHttpAccessManager == NULL){
  416. return false;
  417. };
  418. #ifdef DEBUG_EXTRA
  419. LOG("CURL MANAGER OK");
  420. #endif
  421. try{
  422. struct tm * tTS;
  423. tTS = core_GetSystemDateAndTime();
  424. // This is UTS DTS
  425. if (tTS != NULL){
  426. #ifdef DEBUG
  427. char tB[128];
  428. 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);
  429. LOG(tB);
  430. #endif
  431. // WTF ??!!
  432. tTS->tm_year -= 1900;
  433. tTS->tm_mon -= 1;
  434. time_t tTimeStamp = timegm(tTS); // mktime( tTS );
  435. m_nDeltaTime = time(NULL) - tTimeStamp;
  436. #ifdef DEBUG
  437. sprintf(tB, "TS:[%ld] D:[%ld]", tTimeStamp, m_nDeltaTime);
  438. LOG(tB);
  439. #endif
  440. free(tTS);
  441. } else {
  442. return false;
  443. };
  444. } catch (const std::exception& e) {
  445. LOG_ERROR("Catched Exception!");
  446. return false;
  447. };
  448. return true;
  449. }
  450. /*
  451. Public wrappers for a subset of ONVIF primitives
  452. */
  453. struct tm * boschRCP::core_GetSystemDateAndTime(void)
  454. {
  455. struct tm * RetVal = NULL;
  456. char tURL[MAX_PATH];
  457. if( createRequestString( tURL, BRCP_CMD_GET_DTS, true ) == 0 ){
  458. return NULL;
  459. };
  460. #ifdef DEBUG_EXTRA
  461. LOG("Before REQ");
  462. #endif
  463. if ( _send_request( tURL, NULL, true))
  464. {
  465. XMLResults tParseResults;
  466. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  467. #ifdef DEBUG_EXTRA
  468. LOG("core_GetSystemDateAndTime");
  469. #endif
  470. if (tParseResults.error)
  471. {
  472. char tBuffer[CTEXT];
  473. sprintf(tBuffer, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  474. LOG_ERROR(tBuffer);
  475. }
  476. else
  477. {
  478. RetVal = (struct tm *) malloc(sizeof(struct tm));
  479. if (RetVal != NULL)
  480. {
  481. memset(RetVal, 0, sizeof(struct tm));
  482. XMLNode zNode = response.getChildNode("Body", 0);
  483. if (! zNode.isEmpty())
  484. {
  485. XMLNode fNode = zNode.getChildNode("GetSystemDateAndTimeResponse", 0);
  486. if (! fNode.isEmpty())
  487. {
  488. XMLNode hNode = fNode.getChildNode("SystemDateAndTime", 0);
  489. if (! hNode.isEmpty())
  490. {
  491. XMLNode tNode = hNode.getChildNode("UTCDateTime", 0);
  492. if (! tNode.isEmpty())
  493. {
  494. RetVal->tm_isdst = 0;
  495. XMLNode ttNode = tNode.getChildNode("Time", 0);
  496. XMLNode dtNode = tNode.getChildNode("Date", 0);
  497. {
  498. XMLNode t = ttNode.getChildNode("Hour", 0);
  499. RetVal->tm_hour = atoi(t.getText(0));
  500. }
  501. {
  502. XMLNode t = ttNode.getChildNode("Minute", 0);
  503. RetVal->tm_min = atoi(t.getText(0));
  504. }
  505. {
  506. XMLNode t = ttNode.getChildNode("Second", 0);
  507. RetVal->tm_sec = atoi(t.getText(0));
  508. }
  509. {
  510. XMLNode t = dtNode.getChildNode("Year", 0);
  511. RetVal->tm_year = atoi(t.getText(0));
  512. }
  513. {
  514. XMLNode t = dtNode.getChildNode("Month", 0);
  515. RetVal->tm_mon = atoi(t.getText(0));
  516. }
  517. {
  518. XMLNode t = dtNode.getChildNode("Day", 0);
  519. RetVal->tm_mday = atoi(t.getText(0));
  520. }
  521. }
  522. else
  523. {
  524. LOG_ERROR("UTCDateTime is Not Found!");
  525. };
  526. }
  527. else
  528. {
  529. LOG_ERROR("SystemDateAndTime is Not Found!");
  530. };
  531. }
  532. else
  533. {
  534. LOG_ERROR("GetSystemDateAndTimeResponse is Not Found!");
  535. };
  536. }
  537. else
  538. {
  539. LOG_ERROR("Body is Not Found!");
  540. LOG(m_pLastResponse);
  541. };
  542. };
  543. return RetVal;
  544. };
  545. } else {
  546. LOG_ERROR("GetSystemDateAndTime: Communication error");
  547. }
  548. return NULL;
  549. }
  550. bool boschRCP::ptz_GetStatus(CSTR profileToken, ptzStatus * tStatus)
  551. {
  552. /*if (m_pPTZURI == NULL)
  553. {
  554. return false;
  555. }
  556. if (tStatus == NULL)
  557. {
  558. return false;
  559. }
  560. char tBuffer[DEFAULT_BUFFER_SIZE];
  561. accessToken tTOKEN;
  562. tTOKEN = _makeToken();
  563. memset(tStatus, 0, sizeof(ptzStatus));
  564. sprintf(tBuffer, PONVIF_PACK_GET_PTZ_STATUS, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken);
  565. if (_send_request(m_pPTZURI, tBuffer, true))
  566. {
  567. XMLResults tParseResults;
  568. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  569. if (tParseResults.error)
  570. {
  571. char tBuf[CTEXT];
  572. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  573. LOG_ERROR(tBuf);
  574. }
  575. else
  576. {
  577. XMLNode aNode = response.getChildNode("Body", 0);
  578. if (aNode.isEmpty())
  579. {
  580. return NULL;
  581. }
  582. XMLNode bNode = aNode.getChildNode("GetStatusResponse", 0);
  583. if (! bNode.isEmpty())
  584. {
  585. XMLNode cNode = bNode.getChildNode("PTZStatus", 0);
  586. if (! cNode.isEmpty())
  587. {
  588. XMLNode dNode = cNode.getChildNode("Position", 0);
  589. if (! dNode.isEmpty())
  590. {
  591. XMLNode eNode = dNode.getChildNode("PanTilt", 0);
  592. if (! eNode.isEmpty())
  593. {
  594. // XMLAttribute ZZ = eNode.getAttribute(1);
  595. // LOG( ZZ.lpszName );
  596. tStatus->pan = atof(eNode.getAttribute("x")); // ZZ.lpszValue );
  597. // ZZ = eNode.getAttribute(2);
  598. // LOG( ZZ.lpszName );
  599. tStatus->tilt = atof(eNode.getAttribute("y")); // ZZ.lpszValue );
  600. };
  601. XMLNode fNode = dNode.getChildNode("Zoom", 0);
  602. if (! fNode.isEmpty())
  603. {
  604. // XMLAttribute ZZ = eNode.getAttribute(1);
  605. // LOG( ZZ.lpszName );
  606. tStatus->zoom = atof(fNode.getAttribute("x")); // ZZ.lpszValue );
  607. };
  608. };
  609. if (tStatus->pan != .0f || tStatus->tilt != .0f || tStatus->zoom != .0f)
  610. {
  611. XMLNode gNode = cNode.getChildNode("MoveStatus", 0);
  612. if (! gNode.isEmpty())
  613. {
  614. tStatus->hasMoveStatus = true;
  615. XMLNode hNode = gNode.getChildNode("PanTilt", 0);
  616. if (! hNode.isEmpty())
  617. {
  618. if (strstr(hNode.getText(0), "IDLE") != NULL)
  619. {
  620. tStatus->PanTiltIdle = true;
  621. }
  622. };
  623. XMLNode iNode = gNode.getChildNode("Zoom", 0);
  624. if (! iNode.isEmpty())
  625. {
  626. if (strstr(iNode.getText(0), "IDLE") != NULL)
  627. {
  628. tStatus->ZoomIdle = true;
  629. }
  630. };
  631. };
  632. }
  633. return true;
  634. };
  635. };
  636. };
  637. };*/
  638. return false;
  639. }
  640. /*
  641. bool boschRCP::core_GetDeviceInformation(){
  642. char tBuffer[DEFAULT_BUFFER_SIZE];
  643. accessToken tTOKEN;
  644. tTOKEN = _makeToken();
  645. if( createRequestString( tURL, BRCP_CMD_GET_DTS ) == 0 ){
  646. return NULL;
  647. };
  648. sprintf(tBuffer, PONVIF_PACK_GET_DEV_INFO, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP);
  649. if (_send_request(m_pMediaURI, tBuffer))
  650. {
  651. XMLResults tParseResults;
  652. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  653. LOG("RCPT:");
  654. printf(m_pLastResponse);
  655. if (tParseResults.error)
  656. {
  657. char tBuf[CTEXT];
  658. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  659. LOG_ERROR(tBuf);
  660. }
  661. else
  662. {
  663. // return $response['Envelope']['Body']['GetDeviceInformationResponse'];
  664. };
  665. };
  666. return false;
  667. }
  668. bool boschRCP::ptz_GetPresets(CSTR profileToken)
  669. {
  670. if (m_pPTZURI == NULL)
  671. {
  672. return false;
  673. }
  674. char tBuffer[DEFAULT_BUFFER_SIZE];
  675. accessToken tTOKEN;
  676. tTOKEN = _makeToken();
  677. sprintf(tBuffer, PONVIF_PACK_GET_PRESETS, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken);
  678. if (_send_request(m_pPTZURI, tBuffer))
  679. {
  680. // XMLResults tParseResults;
  681. // XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  682. // LOG("RCPT:");
  683. // LOG( m_pLastResponse );
  684. // if( tParseResults.error ){
  685. // char tBuf[CTEXT];
  686. // sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  687. // LOG_ERROR( tBuf );
  688. // } else {
  689. //$getpresetsresponse=$response['Envelope']['Body']['GetPresetsResponse']['Preset'];
  690. //$presets=array();
  691. // foreach ($getpresetsresponse as $preset) {
  692. // $presets[]=array('Token'=>$preset['@attributes']['token'],
  693. // 'Name'=>$preset['Name'],
  694. // 'PTZPosition'=>$preset['PTZPosition']);
  695. // }
  696. // return $presets;
  697. return true;
  698. //};
  699. };
  700. return false;
  701. }
  702. bool boschRCP::ptz_GetNode(CSTR ptzNodeToken)
  703. {
  704. if (m_pPTZURI == NULL)
  705. {
  706. return false;
  707. }
  708. char tBuffer[DEFAULT_BUFFER_SIZE];
  709. accessToken tTOKEN;
  710. tTOKEN = _makeToken();
  711. sprintf(tBuffer, PONVIF_PACK_GET_PTZ_NODE, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, ptzNodeToken);
  712. if (_send_request(m_pPTZURI, tBuffer))
  713. {
  714. XMLResults tParseResults;
  715. XMLNode response = XMLNode::parseString(m_pLastResponse, "root", &tParseResults);
  716. LOG("RCPT:");
  717. printf(m_pLastResponse);
  718. if (tParseResults.error)
  719. {
  720. char tBuf[CTEXT];
  721. sprintf(tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn);
  722. LOG_ERROR(tBuf);
  723. }
  724. else
  725. {
  726. // return $response['Envelope']['Body']['GetNodeResponse'];
  727. };
  728. };
  729. return false;
  730. }
  731. bool boschRCP::ptz_GotoPreset(CSTR profileToken, CSTR presetToken, float speed_pantilt_x, float speed_pantilt_y, float speed_zoom_x)
  732. {
  733. if (m_pPTZURI == NULL)
  734. {
  735. return false;
  736. }
  737. char tBuffer[DEFAULT_BUFFER_SIZE];
  738. accessToken tTOKEN;
  739. tTOKEN = _makeToken();
  740. 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);
  741. return _send_request(m_pPTZURI, tBuffer, true);
  742. }
  743. bool boschRCP::ptz_RemovePreset(CSTR profileToken, CSTR presetToken)
  744. {
  745. if (m_pPTZURI == NULL)
  746. {
  747. return false;
  748. }
  749. char tBuffer[DEFAULT_BUFFER_SIZE];
  750. accessToken tTOKEN;
  751. tTOKEN = _makeToken();
  752. sprintf(tBuffer, PONVIF_PACK_REMOVE_PRESET, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, presetToken);
  753. return _send_request(m_pPTZURI, tBuffer, true);
  754. }
  755. bool boschRCP::ptz_SetPreset(CSTR profileToken, CSTR presetName)
  756. {
  757. if (m_pPTZURI == NULL)
  758. {
  759. return false;
  760. }
  761. char tBuffer[DEFAULT_BUFFER_SIZE];
  762. accessToken tTOKEN;
  763. tTOKEN = _makeToken();
  764. sprintf(tBuffer, PONVIF_PACK_SET_PRESET, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, presetName);
  765. return _send_request(m_pPTZURI, tBuffer, true);
  766. }
  767. */
  768. bool boschRCP::ptz_RelativeMove(CSTR profileToken, float translation_pantilt_x, float translation_pantilt_y, float speed_pantilt_x, float speed_pantilt_y)
  769. {
  770. if (m_pPTZURI == NULL)
  771. {
  772. return false;
  773. }
  774. char tBuffer[DEFAULT_BUFFER_SIZE];
  775. accessToken tTOKEN;
  776. tTOKEN = _makeToken();
  777. //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);
  778. return _send_request( m_pPTZURI, tBuffer, true );
  779. }
  780. bool boschRCP::ptz_RelativeMoveZoom(CSTR profileToken, float zoom, float speedZoom)
  781. {
  782. if (m_pPTZURI == NULL)
  783. {
  784. return false;
  785. }
  786. char tBuffer[DEFAULT_BUFFER_SIZE];
  787. accessToken tTOKEN;
  788. tTOKEN = _makeToken();
  789. //sprintf(tBuffer, PONVIF_PACK_RELATIVE_ZOOM, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, zoom, speedZoom);
  790. return _send_request(m_pPTZURI, tBuffer, true);
  791. }
  792. bool boschRCP::ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom)
  793. {
  794. if (m_pPTZURI == NULL)
  795. {
  796. return false;
  797. }
  798. char tBuffer[DEFAULT_BUFFER_SIZE];
  799. accessToken tTOKEN;
  800. tTOKEN = _makeToken();
  801. //sprintf(tBuffer, PONVIF_PACK_ABSOLUTE_MOVE, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, position_pantilt_x, position_pantilt_y, zoom);
  802. return _send_request(m_pPTZURI, tBuffer, false);
  803. }
  804. bool boschRCP::ptz_ContinuousMove(CSTR profileToken, float velocity_pantilt_x, float velocity_pantilt_y)
  805. {
  806. if (m_pPTZURI == NULL)
  807. {
  808. return false;
  809. }
  810. char tBuffer[DEFAULT_BUFFER_SIZE];
  811. accessToken tTOKEN;
  812. tTOKEN = _makeToken();
  813. //sprintf(tBuffer, PONVIF_PACK_CONTINUOUS_MOVE, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, velocity_pantilt_x, velocity_pantilt_y);
  814. return _send_request(m_pPTZURI, tBuffer, true);
  815. }
  816. bool boschRCP::ptz_ContinuousMoveZoom(CSTR profileToken, float zoom)
  817. {
  818. if (m_pPTZURI == NULL)
  819. {
  820. return false;
  821. }
  822. char tBuffer[DEFAULT_BUFFER_SIZE];
  823. accessToken tTOKEN;
  824. tTOKEN = _makeToken();
  825. //sprintf(tBuffer, PONVIF_PACK_CONTINUOUS_ZOOM, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, zoom);
  826. return _send_request(m_pPTZURI, tBuffer, true);
  827. }
  828. bool boschRCP::ptz_Stop(CSTR profileToken, bool pantilt, bool zoom)
  829. {
  830. if ( pantilt || zoom ) profileToken = profileToken;
  831. if (m_pPTZURI == NULL)
  832. {
  833. return false;
  834. }
  835. char tBuffer[DEFAULT_BUFFER_SIZE];
  836. accessToken tTOKEN;
  837. tTOKEN = _makeToken();
  838. //sprintf(tBuffer, PONVIF_PACK_PTZ_STOP, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken); //, pantilt, zoom );
  839. return _send_request(m_pPTZURI, tBuffer, true);
  840. }
  841. /*
  842. Internal functions
  843. */
  844. accessToken boschRCP::_makeToken(void)
  845. {
  846. time_t tTS = time(NULL) - m_nDeltaTime;
  847. return _passwordDigest(m_pUsername, m_pPassword, tTS);
  848. }
  849. /*
  850. void boschRCP::_getOnvifVersion(nodeCapability & caps)
  851. {
  852. if (caps.Device != NULL)
  853. {
  854. if (caps.Device->System != NULL)
  855. {
  856. if (caps.Device->System->SupportedVersions != NULL)
  857. {
  858. m_sOnvifVersion.Major = caps.Device->System->SupportedVersions->Major;
  859. m_sOnvifVersion.Minor = caps.Device->System->SupportedVersions->Minor;
  860. };
  861. };
  862. };
  863. if (caps.PTZ != NULL)
  864. {
  865. m_pPTZURI = caps.PTZ->XAddr;
  866. };
  867. if (caps.Media != NULL)
  868. {
  869. m_pMediaURI = caps.Media->XAddr;
  870. };
  871. if (caps.Device != NULL)
  872. {
  873. m_pDeviceURI = caps.Device->XAddr;
  874. };
  875. }
  876. protected function _getActiveSources($videoSources,$profiles) {
  877. $sources=array();
  878. if (isset($videoSources['@attributes'])) {
  879. // NVT is a camera
  880. $sources[0]['sourcetoken']=$videoSources['@attributes']['token'];
  881. $this->_getProfileData($sources,0,$profiles);
  882. }
  883. else {
  884. // NVT is an encoder
  885. for ($i=0;$i<count($videoSources);$i++) {
  886. if (strtolower($videoSources[$i]['@attributes']['SignalActive'])=='true') {
  887. $sources[$i]['sourcetoken']=$videoSources[$i]['@attributes']['token'];
  888. $this->_getProfileData($sources,$i,$profiles);
  889. }
  890. } // for
  891. }
  892. return $sources;
  893. }
  894. void pOnvif::_getProfileData( sources,$i, XMLNode profiles ){
  895. //$inprofile=0;
  896. videoSourceProfile *tPtr;
  897. for( $y=0; $y < count($profiles); $y++ ){
  898. if ($profiles[$y]['VideoSourceConfiguration']['SourceToken']==$sources[$i]['sourcetoken']) {
  899. $sources[$i][$inprofile]['profilename']=$profiles[$y]['Name'];
  900. $sources[$i][$inprofile]['profiletoken']=$profiles[$y]['@attributes']['token'];
  901. if ( isset($profiles[$y]['VideoEncoderConfiguration'])) {
  902. $sources[$i][$inprofile]['encoding']=$profiles[$y]['VideoEncoderConfiguration']['Encoding'];
  903. $sources[$i][$inprofile]['width']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Width'];
  904. $sources[$i][$inprofile]['height']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Height'];
  905. $sources[$i][$inprofile]['fps']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['FrameRateLimit'];
  906. $sources[$i][$inprofile]['bitrate']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['BitrateLimit'];
  907. }
  908. if ( isset($profiles[$y]['PTZConfiguration'])) {
  909. $sources[$i][$inprofile]['ptz']['name']=$profiles[$y]['PTZConfiguration']['Name'];
  910. $sources[$i][$inprofile]['ptz']['nodetoken']=$profiles[$y]['PTZConfiguration']['NodeToken'];
  911. }
  912. $inprofile++;
  913. }
  914. }
  915. };
  916. */
  917. /*
  918. protected function _xml2array($response) {
  919. $sxe = new SimpleXMLElement($response);
  920. $dom_sxe = dom_import_simplexml($sxe);
  921. $dom = new DOMDocument('1.0');
  922. $dom_sxe = $dom->importNode($dom_sxe, true);
  923. $dom_sxe = $dom->appendChild($dom_sxe);
  924. $element = $dom->childNodes->item(0);
  925. foreach ($sxe->getDocNamespaces() as $name => $uri) {
  926. $element->removeAttributeNS($uri, $name);
  927. }
  928. $xmldata=$dom->saveXML();
  929. $xmldata=substr($xmldata,strpos($xmldata,"<Envelope>"));
  930. $xmldata=substr($xmldata,0,strpos($xmldata,"</Envelope>")+strlen("</Envelope>"));
  931. $xml=simplexml_load_string($xmldata);
  932. $data=json_decode(json_encode((array)$xml),1);
  933. $data=array($xml->getName()=>$data);
  934. return $data;
  935. }
  936. */
  937. accessToken boschRCP::_passwordDigest(CSTR username, CSTR password, time_t timestamp, uint32_t nonce)
  938. {
  939. accessToken RetVal;
  940. char tTS[CTEXT];
  941. unsigned char * tPDIGEST;
  942. if (timestamp == 0)
  943. {
  944. time_t t;
  945. struct tm * tmp;
  946. t = time(NULL);
  947. tmp = gmtime(&t);
  948. if (tmp == NULL)
  949. {
  950. LOG_ERROR("gmtime Error!");
  951. };
  952. if (strftime(tTS, 200, "%FT%TZ", tmp) == 0)
  953. {
  954. LOG_ERROR("strftime returned 0!");
  955. };
  956. }
  957. else
  958. {
  959. struct tm * tmp;
  960. tmp = gmtime(&timestamp);
  961. if (tmp == NULL)
  962. {
  963. LOG_ERROR("gmtime Error!");
  964. };
  965. if (strftime(tTS, 200, "%FT%TZ", tmp) == 0)
  966. {
  967. LOG_ERROR("strftime returned 0!");
  968. };
  969. };
  970. if (nonce == 0)
  971. {
  972. nonce = (uint32_t) rand();
  973. };
  974. unsigned char tBuff[CTEXT];
  975. int cp = 0;
  976. int index = 0;
  977. for (; index < 4; index++)
  978. {
  979. tBuff[cp++] = ((unsigned char *) (&nonce))[index];
  980. };
  981. index = 0;
  982. while (tTS[index] != '\0')
  983. {
  984. tBuff[cp++] = (unsigned char) tTS[index];
  985. index++;
  986. };
  987. index = 0;
  988. while (password[index] != '\0')
  989. {
  990. tBuff[cp++] = (unsigned char) password[index];
  991. index++;
  992. };
  993. size_t baseOutLen;
  994. unsigned char tSHA[SHA_DIGEST_LENGTH];
  995. SHA1(tBuff, cp, tSHA);
  996. // tPDIGEST = base64_encode(pack('H*', sha1(pack('H*', $nonce) . pack('a*',$timestamp).pack('a*',$password))));
  997. tPDIGEST = base64_encode(tSHA, SHA_DIGEST_LENGTH, &baseOutLen);
  998. // free( tSHA );
  999. //$passdigest=base64_encode(sha1($nonce.$timestamp.$password,true)); // alternative
  1000. strncpy(RetVal.USERNAME, username, CTEXT);
  1001. strncpy(RetVal.TIMESTAMP, tTS, CTEXT);
  1002. strncpy(RetVal.PASSDIGEST, (const char *) tPDIGEST, CTEXT);
  1003. free(tPDIGEST);
  1004. tPDIGEST = base64_encode((unsigned char *) &nonce, 4, &baseOutLen);
  1005. strncpy(RetVal.NONCE, (const char *) tPDIGEST, baseOutLen);
  1006. RetVal.NONCE[baseOutLen] = '\0';
  1007. free(tPDIGEST);
  1008. //$REQ['NONCE']=base64_encode($nonce); // alternative
  1009. return RetVal;
  1010. }
  1011. void * boschRCP::parser(void * obj, void * ptr)
  1012. {
  1013. boschRCP * ME = (boschRCP *) obj;
  1014. curlRequest * RQ = (curlRequest *) ptr;
  1015. if (ME)
  1016. {
  1017. if (ME->m_pLastResponse)
  1018. {
  1019. free(ME->m_pLastResponse);
  1020. }
  1021. ME->m_pLastResponse = (CSTR) malloc(RQ->getSize() + 1);
  1022. if (ME->m_pLastResponse)
  1023. {
  1024. memcpy(ME->m_pLastResponse, RQ->getBuffer(), RQ->getSize());
  1025. ME->m_pLastResponse[RQ->getSize()] = (char) 0;
  1026. #ifdef DEBUG_ONVIF_TRAFFIC
  1027. FILE * tf;
  1028. tf = fopen("Traffic.txt", "a+");
  1029. fprintf(tf, "~~~~~~~~~~~~~~~~~~~~\r\n");
  1030. fprintf(tf, "<<<<< [%d] %s\n", RQ->getSize(), ME->m_pLastResponse);
  1031. fprintf(tf, "~~~~~~~~~~~~~~~~~~~~\r\n");
  1032. fclose(tf);
  1033. #endif
  1034. };
  1035. ME->parser_done = true;
  1036. };
  1037. return NULL;
  1038. }
  1039. bool boschRCP::_send_request(CSTR url, CSTR post_string, bool mustReturnData)
  1040. {
  1041. #ifdef CURL_MANAGER
  1042. bool RetVal = false;
  1043. if (m_pHttpAccessManager)
  1044. {
  1045. m_mResponseProtector.lock();
  1046. curlRequest * tRC;
  1047. tRC = new curlRequest(url, (CSTR) "application/soap+xml; charset=utf-8;");
  1048. if (tRC != NULL)
  1049. {
  1050. #ifdef DEBUG_BRCP_TRAFFIC
  1051. FILE * tf;
  1052. tf = fopen("Traffic.txt", "a+");
  1053. fprintf(tf, "--------------------\r\n");
  1054. if ( post_string != NULL ) {
  1055. fprintf(tf, "REQ: %s (%d)\n", url, strlen(post_string));
  1056. fprintf(tf, ">>>>> %s\n", post_string);
  1057. } else fprintf(tf, "REQ: %s\n", url );
  1058. fprintf(tf, "--------------------\r\n");
  1059. fclose(tf);
  1060. mustReturnData = true; // In Debug Allways Read Return
  1061. #endif
  1062. tRC->setCredentials( m_pUsername, m_pPassword, m_bAuthMode );
  1063. if ( post_string != NULL ) {
  1064. tRC->setPOST(post_string, strlen(post_string));
  1065. }
  1066. if (mustReturnData)
  1067. {
  1068. tRC->setHandler((void *) this, boschRCP::parser, (void *) tRC );
  1069. if (m_pHttpAccessManager->accomplish(tRC))
  1070. {
  1071. parser_done = false;
  1072. uint8_t cnt = 200; // TO = 2 second
  1073. while (! RetVal && cnt--)
  1074. {
  1075. RetVal = parser_done;
  1076. SLEEP(10);
  1077. };
  1078. };
  1079. }
  1080. else
  1081. {
  1082. RetVal = m_pHttpAccessManager->accomplish( tRC );
  1083. };
  1084. }
  1085. else
  1086. {
  1087. LOG_ERROR("Cannot Create curlRequest!");
  1088. }
  1089. m_mResponseProtector.unlock();
  1090. };
  1091. return RetVal;
  1092. #else
  1093. char tBuffer[CTEXT];
  1094. if (m_pCURL == NULL)
  1095. {
  1096. if (m_pLastResponse == NULL)
  1097. {
  1098. m_pLastResponse = (CSTR) malloc(DEFAULT_BUFFER_SIZE);
  1099. };
  1100. m_pCURL = curl_easy_init();
  1101. if (m_pProxyHost != NULL && m_nProxyPort != 0)
  1102. {
  1103. curl_easy_setopt(m_pCURL, CURLOPT_PROXY, m_pProxyHost);
  1104. curl_easy_setopt(m_pCURL, CURLOPT_PROXYPORT, m_nProxyPort);
  1105. if (m_pProxyUsername != NULL && m_pProxyPassword != NULL)
  1106. {
  1107. sprintf(tBuffer, "%s:%s", m_pProxyUsername, m_pProxyPassword);
  1108. curl_easy_setopt(m_pCURL, CURLOPT_PROXYUSERPWD, tBuffer);
  1109. };
  1110. };
  1111. curl_easy_setopt(m_pCURL, CURLOPT_CONNECTTIMEOUT, 1);
  1112. curl_easy_setopt(m_pCURL, CURLOPT_TIMEOUT, 2);
  1113. curl_easy_setopt(m_pCURL, CURLOPT_SSL_VERIFYPEER, 0);
  1114. curl_easy_setopt(m_pCURL, CURLOPT_SSL_VERIFYHOST, 0);
  1115. curl_easy_setopt(m_pCURL, CURLOPT_VERBOSE, 0);
  1116. curl_easy_setopt(m_pCURL, CURLOPT_POST, 1);
  1117. // curl_easy_setopt( m_pCURL, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS, 0 );
  1118. // curl_easy_setopt( m_pCURL, CURLOPT_NOPROGRESS, 1 );
  1119. // curl_easy_setopt( m_pCURL, CURLOPT_NOSIGNAL, 1 );
  1120. curl_easy_setopt(m_pCURL, CURLOPT_TCP_FASTOPEN, 1);
  1121. curl_easy_setopt(m_pCURL, CURLOPT_TCP_NODELAY, 1);
  1122. // curl_easy_setopt( m_pCURL, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
  1123. curl_easy_setopt(m_pCURL, CURLOPT_WRITEFUNCTION, pOnvif::_writer);
  1124. curl_easy_setopt(m_pCURL, CURLOPT_WRITEDATA, this);
  1125. };
  1126. if (m_pCURL != NULL)
  1127. {
  1128. curl_easy_setopt(m_pCURL, CURLOPT_URL, url);
  1129. struct curl_slist * sList = NULL;
  1130. // Content-Type: application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"
  1131. // Connection: Close
  1132. sList = curl_slist_append(sList, "Content-Type: text/xml; charset=utf-8");
  1133. sprintf(tBuffer, "Content-Length: %d", strlen(post_string));
  1134. sList = curl_slist_append(sList, tBuffer);
  1135. curl_easy_setopt(m_pCURL, CURLOPT_HTTPHEADER, sList);
  1136. curl_easy_setopt(m_pCURL, CURLOPT_POSTFIELDS, post_string);
  1137. sprintf(tBuffer, "%s:%s", m_pUsername, m_pPassword);
  1138. curl_easy_setopt(m_pCURL, CURLOPT_USERPWD, tBuffer);
  1139. switch (m_bAuthMode)
  1140. {
  1141. case 0: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); break;
  1142. case 1: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); break;
  1143. case 2: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST_IE); break;
  1144. case 3: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BEARER); break;
  1145. case 4: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE); break;
  1146. case 5: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); break;
  1147. case 6: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM_WB); break;
  1148. case 7: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY); break;
  1149. case 8: curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); break;
  1150. case 9:
  1151. curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ONLY);
  1152. break;
  1153. // case 10: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_AWS_SIGV4 ); break;
  1154. };
  1155. #ifdef DEBUG
  1156. char tErrorBuffer[CURL_ERROR_SIZE];
  1157. curl_easy_setopt(m_pCURL, CURLOPT_ERRORBUFFER, tErrorBuffer);
  1158. #endif
  1159. m_pLastIndex = 0;
  1160. if (curl_easy_perform(m_pCURL))
  1161. {
  1162. LOG_ERROR("CURL Failure!");
  1163. #ifdef DEBUG
  1164. LOG_ERROR(tErrorBuffer);
  1165. #endif
  1166. }
  1167. else
  1168. {
  1169. m_pLastResponse[m_pLastIndex] = (char) 0;
  1170. return true;
  1171. };
  1172. m_pLastIndex = 0;
  1173. };
  1174. return false;
  1175. #endif
  1176. }
  1177. #ifndef CURL_MANAGER
  1178. int boschRCP::_writer(char * data, size_t size, size_t nmemb, boschRCP * Ptr)
  1179. {
  1180. if (Ptr == NULL)
  1181. {
  1182. return 0;
  1183. }
  1184. // TLOG("*");
  1185. memcpy(Ptr->m_pLastResponse + Ptr->m_pLastIndex, data, size * nmemb);
  1186. Ptr->m_pLastIndex += size * nmemb;
  1187. return size * nmemb;
  1188. }
  1189. #endif
  1190. bool boschRCP::setAuthMode(uint8_t Mode)
  1191. {
  1192. m_bAuthMode = Mode;
  1193. #ifdef DEBUG
  1194. switch (m_bAuthMode)
  1195. {
  1196. case 0 : LOG("Set Auth CURLAUTH_BASIC"); break;
  1197. case 1 : LOG("Set Auth CURLAUTH_DIGEST"); break;
  1198. case 2 : LOG("Set Auth CURLAUTH_DIGEST_IE"); break;
  1199. case 3 : LOG("Set Auth CURLAUTH_BEARER"); break;
  1200. case 4 : LOG("Set Auth CURLAUTH_NEGOTIATE"); break;
  1201. case 5 : LOG("Set Auth CURLAUTH_NTLM"); break;
  1202. case 6 : LOG("Set Auth CURLAUTH_NTLM_WB"); break;
  1203. case 7 : LOG("Set Auth CURLAUTH_ANY"); break;
  1204. case 8 : LOG("Set Auth CURLAUTH_ANYSAFE"); break;
  1205. case 9 : LOG("Set Auth CURLAUTH_ONLY"); break;
  1206. case 10: LOG("Set Auth CURLAUTH_AWS_SIGV4"); break;
  1207. };
  1208. #endif
  1209. return true;
  1210. }
  1211. #undef LOG
  1212. #undef TLOG
  1213. #undef LOG_ERROR