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.

660 lines
21 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
​
7 years ago
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
​
7 years ago
​
​
  1. #include "onvifclientdevice.hpp"
  2. ONVIFLIB_API int OnvifClientDevice::GetHostname(_tds__GetHostnameResponse &GetHostnameResponse)
  3. {
  4. string strUrl;
  5. string strUser;
  6. string strPass;
  7. if (this->GetUserPasswd(strUser, strPass) == false
  8. || this->GetUrl(strUrl) == false)
  9. {
  10. return SOAP_ERR;
  11. }
  12. deviceBindProxy.soap_endpoint = strUrl.c_str();
  13. soap_wsse_add_Security(&deviceBindProxy);
  14. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  15. _tds__GetHostname GetHostnameReq;
  16. return deviceBindProxy.GetHostname(&GetHostnameReq,&GetHostnameResponse);
  17. }
  18. ONVIFLIB_API int OnvifClientDevice::SetHostname(_tds__SetHostnameResponse &SetHostnameResponse, string Name)
  19. {
  20. string strUrl;
  21. string strUser;
  22. string strPass;
  23. if (this->GetUserPasswd(strUser, strPass) == false
  24. || this->GetUrl(strUrl) == false)
  25. {
  26. return SOAP_ERR;
  27. }
  28. deviceBindProxy.soap_endpoint = strUrl.c_str();
  29. soap_wsse_add_Security(&deviceBindProxy);
  30. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  31. _tds__SetHostname SetHostnameReq;
  32. SetHostnameReq.Name = Name;
  33. return deviceBindProxy.SetHostname(&SetHostnameReq,&SetHostnameResponse);
  34. }
  35. ONVIFLIB_API int OnvifClientDevice::GetDNS(_tds__GetDNSResponse &GetDNSResponse)
  36. {
  37. string strUrl;
  38. string strUser;
  39. string strPass;
  40. if (this->GetUserPasswd(strUser, strPass) == false
  41. || this->GetUrl(strUrl) == false)
  42. {
  43. return SOAP_ERR;
  44. }
  45. deviceBindProxy.soap_endpoint = strUrl.c_str();
  46. soap_wsse_add_Security(&deviceBindProxy);
  47. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  48. _tds__GetDNS GetDNSReq;
  49. return deviceBindProxy.GetDNS(&GetDNSReq,&GetDNSResponse);
  50. }
  51. ONVIFLIB_API int OnvifClientDevice::SetDNS(_tds__SetDNSResponse &SetDNSResponse, bool FromDHCP, vector<string,allocator<string>> SearchDomain, vector<tt__IPAddress*,allocator<tt__IPAddress*>> &DNSManual)
  52. {
  53. string strUrl;
  54. string strUser;
  55. string strPass;
  56. if (this->GetUserPasswd(strUser, strPass) == false
  57. || this->GetUrl(strUrl) == false)
  58. {
  59. return SOAP_ERR;
  60. }
  61. deviceBindProxy.soap_endpoint = strUrl.c_str();
  62. soap_wsse_add_Security(&deviceBindProxy);
  63. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  64. _tds__SetDNS SetDNSReq;
  65. SetDNSReq.FromDHCP = FromDHCP;
  66. SetDNSReq.SearchDomain = SearchDomain;
  67. SetDNSReq.DNSManual = DNSManual;
  68. return deviceBindProxy.SetDNS(&SetDNSReq,&SetDNSResponse);
  69. }
  70. ONVIFLIB_API int OnvifClientDevice::GetNTP(_tds__GetNTPResponse &GetNTPResponse)
  71. {
  72. string strUrl;
  73. string strUser;
  74. string strPass;
  75. if (this->GetUserPasswd(strUser, strPass) == false
  76. || this->GetUrl(strUrl) == false)
  77. {
  78. return SOAP_ERR;
  79. }
  80. deviceBindProxy.soap_endpoint = strUrl.c_str();
  81. soap_wsse_add_Security(&deviceBindProxy);
  82. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  83. _tds__GetNTP GetNTPReq;
  84. return deviceBindProxy.GetNTP(&GetNTPReq,&GetNTPResponse);
  85. }
  86. ONVIFLIB_API int OnvifClientDevice::SetNTP(_tds__SetNTPResponse &SetNTPResponse, bool FromDHCP, vector<tt__NetworkHost*,allocator<tt__NetworkHost*>> &NTPManual)
  87. {
  88. string strUrl;
  89. string strUser;
  90. string strPass;
  91. if (this->GetUserPasswd(strUser, strPass) == false
  92. || this->GetUrl(strUrl) == false)
  93. {
  94. return SOAP_ERR;
  95. }
  96. deviceBindProxy.soap_endpoint = strUrl.c_str();
  97. soap_wsse_add_Security(&deviceBindProxy);
  98. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  99. _tds__SetNTP SetNTPReq;
  100. SetNTPReq.FromDHCP = FromDHCP;
  101. SetNTPReq.NTPManual = NTPManual;
  102. return deviceBindProxy.SetNTP(&SetNTPReq,&SetNTPResponse);
  103. }
  104. ONVIFLIB_API int OnvifClientDevice::GetDynamicDNS(_tds__GetDynamicDNSResponse &GetDynamicDNSResponse)
  105. {
  106. string strUrl;
  107. string strUser;
  108. string strPass;
  109. if (this->GetUserPasswd(strUser, strPass) == false
  110. || this->GetUrl(strUrl) == false)
  111. {
  112. return SOAP_ERR;
  113. }
  114. deviceBindProxy.soap_endpoint = strUrl.c_str();
  115. soap_wsse_add_Security(&deviceBindProxy);
  116. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  117. _tds__GetDynamicDNS GetDynamicDNSReq;
  118. return deviceBindProxy.GetDynamicDNS(&GetDynamicDNSReq,&GetDynamicDNSResponse);
  119. }
  120. ONVIFLIB_API int OnvifClientDevice::SetDynamicDNS(_tds__SetDynamicDNSResponse &SetDynamicDNSResponse,tt__DynamicDNSType &Type,tt__DNSName &Name, LONG64 &durationTTL)
  121. {
  122. string strUrl;
  123. string strUser;
  124. string strPass;
  125. if (this->GetUserPasswd(strUser, strPass) == false
  126. || this->GetUrl(strUrl) == false)
  127. {
  128. return SOAP_ERR;
  129. }
  130. deviceBindProxy.soap_endpoint = strUrl.c_str();
  131. soap_wsse_add_Security(&deviceBindProxy);
  132. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  133. _tds__SetDynamicDNS SetDynamicDNSReq;
  134. SetDynamicDNSReq.Name = &Name;
  135. SetDynamicDNSReq.TTL = &durationTTL;
  136. SetDynamicDNSReq.Type = Type;
  137. return deviceBindProxy.SetDynamicDNS(&SetDynamicDNSReq,&SetDynamicDNSResponse);
  138. }
  139. ONVIFLIB_API int OnvifClientDevice::GetNetworkInterfaces(_tds__GetNetworkInterfacesResponse &GetNetworkInterfacesResponse)
  140. {
  141. string strUrl;
  142. string strUser;
  143. string strPass;
  144. if (this->GetUserPasswd(strUser, strPass) == false
  145. || this->GetUrl(strUrl) == false)
  146. {
  147. return SOAP_ERR;
  148. }
  149. deviceBindProxy.soap_endpoint = strUrl.c_str();
  150. soap_wsse_add_Security(&deviceBindProxy);
  151. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  152. _tds__GetNetworkInterfaces GetNetworkInterfacesReq;
  153. return deviceBindProxy.GetNetworkInterfaces(&GetNetworkInterfacesReq,&GetNetworkInterfacesResponse);
  154. }
  155. ONVIFLIB_API int OnvifClientDevice::SetNetworkInterfaces(_tds__SetNetworkInterfacesResponse &SetNetworkInterfacesResponse,string InterfaceToken,tt__NetworkInterfaceSetConfiguration &NetworkInterface)
  156. {
  157. string strUrl;
  158. string strUser;
  159. string strPass;
  160. if (this->GetUserPasswd(strUser, strPass) == false
  161. || this->GetUrl(strUrl) == false)
  162. {
  163. return SOAP_ERR;
  164. }
  165. deviceBindProxy.soap_endpoint = strUrl.c_str();
  166. soap_wsse_add_Security(&deviceBindProxy);
  167. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  168. _tds__SetNetworkInterfaces SetNetworkInterfacesReq;
  169. SetNetworkInterfacesReq.InterfaceToken = InterfaceToken;
  170. SetNetworkInterfacesReq.NetworkInterface = &NetworkInterface;
  171. return deviceBindProxy.SetNetworkInterfaces(&SetNetworkInterfacesReq,&SetNetworkInterfacesResponse);
  172. }
  173. ONVIFLIB_API int OnvifClientDevice::GetNetworkProtocols(_tds__GetNetworkProtocolsResponse &GetNetworkProtocolsResponse)
  174. {
  175. string strUrl;
  176. string strUser;
  177. string strPass;
  178. if (this->GetUserPasswd(strUser, strPass) == false
  179. || this->GetUrl(strUrl) == false)
  180. {
  181. return SOAP_ERR;
  182. }
  183. deviceBindProxy.soap_endpoint = strUrl.c_str();
  184. soap_wsse_add_Security(&deviceBindProxy);
  185. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  186. _tds__GetNetworkProtocols GetNetworkProtocolsReq;
  187. return deviceBindProxy.GetNetworkProtocols(&GetNetworkProtocolsReq,&GetNetworkProtocolsResponse);
  188. }
  189. ONVIFLIB_API int OnvifClientDevice::SetNetworkProtocols(_tds__SetNetworkProtocolsResponse &SetNetworkProtocolsResponse,vector<tt__NetworkProtocol*,allocator<tt__NetworkProtocol*>> &NetworkProtocols)
  190. {
  191. string strUrl;
  192. string strUser;
  193. string strPass;
  194. if (this->GetUserPasswd(strUser, strPass) == false
  195. || this->GetUrl(strUrl) == false)
  196. {
  197. return SOAP_ERR;
  198. }
  199. deviceBindProxy.soap_endpoint = strUrl.c_str();
  200. soap_wsse_add_Security(&deviceBindProxy);
  201. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  202. _tds__SetNetworkProtocols SetNetworkProtocolsReq;
  203. SetNetworkProtocolsReq.NetworkProtocols = NetworkProtocols;
  204. return deviceBindProxy.SetNetworkProtocols(&SetNetworkProtocolsReq,&SetNetworkProtocolsResponse);
  205. }
  206. ONVIFLIB_API int OnvifClientDevice::GetNetworkDefaultGateway(_tds__GetNetworkDefaultGatewayResponse &GetNetworkDefaultGatewayResponse)
  207. {
  208. string strUrl;
  209. string strUser;
  210. string strPass;
  211. if (this->GetUserPasswd(strUser, strPass) == false
  212. || this->GetUrl(strUrl) == false)
  213. {
  214. return SOAP_ERR;
  215. }
  216. deviceBindProxy.soap_endpoint = strUrl.c_str();
  217. soap_wsse_add_Security(&deviceBindProxy);
  218. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  219. _tds__GetNetworkDefaultGateway GetNetworkDefaultGatewayReq;
  220. return deviceBindProxy.GetNetworkDefaultGateway(&GetNetworkDefaultGatewayReq,&GetNetworkDefaultGatewayResponse);
  221. }
  222. ONVIFLIB_API int OnvifClientDevice::SetNetworkDefaultGateway(_tds__SetNetworkDefaultGatewayResponse &SetNetworkDefaultGatewayResponse,vector<string,allocator<string>> &IPv4,vector<string,allocator<string>> &IPv6)
  223. {
  224. string strUrl;
  225. string strUser;
  226. string strPass;
  227. if (this->GetUserPasswd(strUser, strPass) == false
  228. || this->GetUrl(strUrl) == false)
  229. {
  230. return SOAP_ERR;
  231. }
  232. deviceBindProxy.soap_endpoint = strUrl.c_str();
  233. soap_wsse_add_Security(&deviceBindProxy);
  234. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  235. _tds__SetNetworkDefaultGateway SetNetworkDefaultGatewayReq;
  236. SetNetworkDefaultGatewayReq.IPv4Address = IPv4;
  237. SetNetworkDefaultGatewayReq.IPv6Address = IPv6;
  238. return deviceBindProxy.SetNetworkDefaultGateway(&SetNetworkDefaultGatewayReq,&SetNetworkDefaultGatewayResponse);
  239. }
  240. ONVIFLIB_API int OnvifClientDevice::SystemReboot(_tds__SystemRebootResponse &SystemRebootResponse)
  241. {
  242. string strUrl;
  243. string strUser;
  244. string strPass;
  245. if (this->GetUserPasswd(strUser, strPass) == false
  246. || this->GetUrl(strUrl) == false)
  247. {
  248. return SOAP_ERR;
  249. }
  250. deviceBindProxy.soap_endpoint = strUrl.c_str();
  251. soap_wsse_add_Security(&deviceBindProxy);
  252. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  253. _tds__SystemReboot SystemRebootReq;
  254. return deviceBindProxy.SystemReboot(&SystemRebootReq,&SystemRebootResponse);
  255. }
  256. /* used to find time offset inside SynchronizeDateAndTimeWithCamera() */
  257. ONVIFLIB_API double OnvifClientDevice::findDiffTime(struct tm local_sys,tt__DateTime cameraTime,bool isDST)
  258. {
  259. tt__Date* camDate = cameraTime.Date;
  260. tt__Time* camTime = cameraTime.Time;
  261. // Converting tt__DateTime to tm struct to find time offset
  262. struct tm *CamDateTime = new tm;
  263. CamDateTime->tm_hour = camTime->Hour; CamDateTime->tm_min = camTime->Minute; CamDateTime->tm_sec = camTime->Second;
  264. CamDateTime->tm_mday = camDate->Day; CamDateTime->tm_mon = camDate->Month-1; CamDateTime->tm_year = camDate->Year-1900;
  265. CamDateTime->tm_isdst = isDST;
  266. if(isDST)
  267. CamDateTime->tm_hour ++;
  268. //convert camera and system tm to time_t
  269. time_t camera_time_t = mktime(CamDateTime); time_t sys_time_t = mktime(&local_sys);
  270. double diff = difftime(sys_time_t,camera_time_t);
  271. cout << "camera epoch: " << camera_time_t << "\t\tSystem epoch: " << sys_time_t << endl << "returned diff: " << diff << "\t\tcalced here: " << sys_time_t-camera_time_t << endl;
  272. return diff;
  273. }
  274. /* Most of this function is taken from the function 'soap_wsse_add_UsernameTokenDigest()' defined in wsseapi.cpp //
  275. // Used to alter the soap request for an offset time (for authorization purposes - replay attack protection) */
  276. ONVIFLIB_API int OnvifClientDevice::LocalAddUsernameTokenDigest(struct soap *soapOff,double cam_pc_offset)
  277. {
  278. string strUrl;
  279. string strUser;
  280. string strPass;
  281. if (this->GetUserPasswd(strUser, strPass) == false
  282. || this->GetUrl(strUrl) == false)
  283. {
  284. return SOAP_ERR;
  285. }
  286. /* start soap_wsse_add_UsernameTokenDigest; Taken from wsseapi.cpp*/
  287. /* All of this is taken from the function soap_wsse_add_UsernameTokenDigest() defined in wsseapi.cpp */
  288. _wsse__Security *security = soap_wsse_add_Security(soapOff);
  289. time_t now = time(NULL);
  290. now -= (time_t) cam_pc_offset; //offset so digest comes out correctly (synced times between cam and pc);
  291. const char *created = soap_dateTime2s(soapOff, now);
  292. char HA[SOAP_SMD_SHA1_SIZE], HABase64[29];
  293. char nonce[20], *nonceBase64;
  294. /*start calc_nonce(soapOff, nonce); Taken from wsseapi.cpp */
  295. time_t r = time(NULL);
  296. cout << "now time: " << r << endl;
  297. r -= (time_t) cam_pc_offset; //offset so digest comes out correctly (synced times between cam and pc);
  298. cout << "now time minus offset: " << r << endl;
  299. memcpy(nonce, &r, 4);
  300. for (int i = 4; i < 20; i += 4)
  301. { r = soap_random;
  302. memcpy(nonce + i, &r, 4);
  303. }
  304. /*end calc_nonce(soapOff, nonce); */
  305. nonceBase64 = soap_s2base64(soapOff, (unsigned char*)nonce, NULL, 20);
  306. /* start calc_digest(soapOff, created, nonce, 20, strPass, HA); Taken from wsseapi.cpp */
  307. struct soap_smd_data context;
  308. /* use smdevp engine */
  309. soap_smd_init(soapOff, &context, SOAP_SMD_DGST_SHA1, NULL, 0);
  310. soap_smd_update(soapOff, &context, nonce, 20);
  311. soap_smd_update(soapOff, &context, created, strlen(created));
  312. soap_smd_update(soapOff, &context, strPass.c_str(), strlen(strPass.c_str()));
  313. soap_smd_final(soapOff, &context, HA, NULL);
  314. /* end calc_digest(soapOff, created, nonce, 20, strPass, HA); */
  315. soap_s2base64(soapOff, (unsigned char*)HA, HABase64, SOAP_SMD_SHA1_SIZE);
  316. /* populate the UsernameToken with digest */
  317. soap_wsse_add_UsernameTokenText(soapOff, "Id", strUser.c_str(), HABase64);
  318. /* populate the remainder of the password, nonce, and created */
  319. security->UsernameToken->Password->Type = (char*)wsse_PasswordDigestURI;
  320. security->UsernameToken->Nonce = nonceBase64;
  321. security->UsernameToken->wsu__Created = soap_strdup(soapOff, created);
  322. /* end soap_wsse_add_UsernameTokenDigest */
  323. return SOAP_OK;
  324. }
  325. ONVIFLIB_API int OnvifClientDevice::SynchronizeDateAndTimeWithCamera(string &strUrl,string &strUser,string &strPass,_tds__SetSystemDateAndTimeResponse &SetSystemDateAndTimeResponse)
  326. {
  327. m_strUrl = strUrl;
  328. m_strUser = strUser;
  329. m_strPass = strPass;
  330. tt__DateTime* diffTime_tt = new tt__DateTime;
  331. _tds__GetSystemDateAndTimeResponse DateAndTimeResp;
  332. this->GetSystemDateAndTime(DateAndTimeResp);
  333. tt__DateTime* camHolder = DateAndTimeResp.SystemDateAndTime->UTCDateTime;
  334. time_t timeNow = time(NULL); struct tm* offsetStruct = gmtime(&timeNow); //offsetStruct->tm_year += 1900;
  335. double cam_pc_offset = findDiffTime(*offsetStruct,*camHolder,DateAndTimeResp.SystemDateAndTime->DaylightSavings);
  336. double diffhold = (double) timeNow; double difference = diffhold-cam_pc_offset;
  337. cout << "current time: " << diffhold << endl <<"difference calced here: " << difference << endl;
  338. //Doing some soap work
  339. soap_wsse_add_Security(&deviceBindProxy);
  340. LocalAddUsernameTokenDigest(&deviceBindProxy,cam_pc_offset);
  341. // creating and setting parameter for the set date and time request
  342. _tds__SetSystemDateAndTime SetDateTimeReq;
  343. SetDateTimeReq.DateTimeType = (tt__SetDateTimeType) 0;// DateTimeType - 0=manual, 1=NTP;
  344. SetDateTimeReq.DaylightSavings = offsetStruct->tm_isdst > 0;// DayLightSavings;
  345. // *** Timezone stuff is messy... could be cleaned up potentially -john
  346. tt__TimeZone* TiZ = new tt__TimeZone;
  347. string TimeZ = "MST7MDT,M3.2.0,M11.1.0"; // TODO: Needs to be configurable depending on what time zone is being worked in. Set for Mountain time (Denver);
  348. TiZ->TZ = TimeZ; SetDateTimeReq.TimeZone = TiZ;
  349. // set the camera time to match pc time for authentication simplicity
  350. tt__DateTime* UTCDateTime = new tt__DateTime;
  351. time_t NOW = time(NULL); struct tm* noww = gmtime(&NOW);
  352. tt__Date thisDate; thisDate.Day = noww->tm_mday; thisDate.Month = noww->tm_mon+1; thisDate.Year = noww->tm_year +1900; // added 1 to month and 1900 to year to account for how tm defines those values
  353. tt__Time thisTime; thisTime.Hour = noww->tm_hour; thisTime.Minute = noww->tm_min; thisTime.Second = noww->tm_sec;
  354. UTCDateTime->Date = &thisDate; UTCDateTime->Time = &thisTime;
  355. SetDateTimeReq.UTCDateTime = UTCDateTime;
  356. return deviceBindProxy.SetSystemDateAndTime(&SetDateTimeReq,&SetSystemDateAndTimeResponse);
  357. }
  358. ONVIFLIB_API int OnvifClientDevice::SynchronizeDateAndTimeWithCamera(_tds__SetSystemDateAndTimeResponse &SetSystemDateAndTimeResponse)
  359. {
  360. string strUrl;
  361. string strUser;
  362. string strPass;
  363. if (this->GetUserPasswd(strUser, strPass) == false
  364. || this->GetUrl(strUrl) == false)
  365. {
  366. return SOAP_ERR;
  367. }
  368. return SynchronizeDateAndTimeWithCamera(strUrl,strUser,strPass,SetSystemDateAndTimeResponse);
  369. }
  370. ONVIFLIB_API int OnvifClientDevice::SetSystemDateAndTime(_tds__SetSystemDateAndTimeResponse &SetSystemDateAndTimeResponse, tt__SetDateTimeType &DateTimeType, bool DayLightSavings, tt__TimeZone &Timezone, tt__DateTime &UTCDateTime)
  371. {
  372. _tds__SetSystemDateAndTime SetDateTimeReq;
  373. SetDateTimeReq.DateTimeType = (tt__SetDateTimeType) 1;// DateTimeType;
  374. SetDateTimeReq.DaylightSavings = DayLightSavings;
  375. SetDateTimeReq.TimeZone = &Timezone;
  376. SetDateTimeReq.UTCDateTime = &UTCDateTime;
  377. string strUrl;
  378. string strUser;
  379. string strPass;
  380. if (this->GetUserPasswd(strUser, strPass) == false
  381. || this->GetUrl(strUrl) == false)
  382. {
  383. return SOAP_ERR;
  384. }
  385. soap_wsse_add_Security(&deviceBindProxy);
  386. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", strUser.c_str() , strPass.c_str());
  387. return deviceBindProxy.SetSystemDateAndTime(&SetDateTimeReq,&SetSystemDateAndTimeResponse);
  388. }
  389. OnvifClientDevice::OnvifClientDevice(string &strUrl, string &strUser, string &strPass)
  390. :m_strUrl(strUrl), m_strUser(strUser),
  391. m_strPass(strPass), m_hasGetCap(false), deviceBindProxy(SOAP_C_UTFSTRING)
  392. {
  393. m_hasMedia = false;
  394. m_hasPTZ = false;
  395. m_hasImaging = false;
  396. m_hasReceiver = false;
  397. m_hasRecording = false;
  398. m_hasSearch = false;
  399. m_hasReplay = false;
  400. m_hasEvent = false;
  401. }
  402. OnvifClientDevice::~OnvifClientDevice(){
  403. }
  404. ONVIFLIB_API int OnvifClientDevice::GetSystemDateAndTime(_tds__GetSystemDateAndTimeResponse &SystemDateAndTimeResponse)
  405. {
  406. _tds__GetSystemDateAndTime SystemDateAndTime;
  407. deviceBindProxy.soap_endpoint = m_strUrl.c_str();
  408. return deviceBindProxy.GetSystemDateAndTime(&SystemDateAndTime,&SystemDateAndTimeResponse);
  409. }
  410. ONVIFLIB_API int OnvifClientDevice::GetDeviceInformation(_tds__GetDeviceInformationResponse &DeviceInformationResponse)
  411. {
  412. _tds__GetDeviceInformation DeviceInformationReq;
  413. //string strUrl;
  414. deviceBindProxy.soap_endpoint = m_strUrl.c_str();
  415. return deviceBindProxy.GetDeviceInformation(&DeviceInformationReq,&DeviceInformationResponse);
  416. }
  417. ONVIFLIB_API bool OnvifClientDevice::GetMediaUrl(string &strUrl)
  418. {
  419. if (m_hasGetCap == false || m_hasMedia == false)
  420. {
  421. return false;
  422. }
  423. strUrl = m_strMedia;
  424. return true;
  425. }
  426. ONVIFLIB_API bool OnvifClientDevice::GetPTZUrl(string &strUrl)
  427. {
  428. if (m_hasGetCap == false || m_hasPTZ == false)
  429. {
  430. return false;
  431. }
  432. strUrl = m_strPTZ;
  433. return true;
  434. }
  435. ONVIFLIB_API bool OnvifClientDevice::GetImagingUrl(string &strUrl)
  436. {
  437. if (m_hasGetCap == false || m_hasImaging == false)
  438. {
  439. return false;
  440. }
  441. strUrl = m_strImaging;
  442. return true;
  443. }
  444. ONVIFLIB_API bool OnvifClientDevice::GetReceiverUrl(string &strUrl)
  445. {
  446. if (m_hasGetCap == false || m_hasReceiver == false)
  447. {
  448. return false;
  449. }
  450. strUrl = m_strReceiver;
  451. return true;
  452. }
  453. ONVIFLIB_API bool OnvifClientDevice::GetRecordingUrl(string &strUrl)
  454. {
  455. if (m_hasGetCap == false || m_hasRecording == false)
  456. {
  457. return false;
  458. }
  459. strUrl = m_strRecording;
  460. return true;
  461. }
  462. ONVIFLIB_API bool OnvifClientDevice::GetSearchUrl(string &strUrl)
  463. {
  464. if (m_hasGetCap == false || m_hasSearch == false)
  465. {
  466. return false;
  467. }
  468. strUrl = m_strSearch;
  469. return true;
  470. }
  471. ONVIFLIB_API bool OnvifClientDevice::GetReplayUrl(string &strUrl)
  472. {
  473. if (m_hasGetCap == false || m_hasReplay == false)
  474. {
  475. return false;
  476. }
  477. strUrl = m_strReplay;
  478. return true;
  479. }
  480. ONVIFLIB_API bool OnvifClientDevice::GetEventUrl(string &strUrl)
  481. {
  482. if (m_hasGetCap == false || m_hasEvent == false)
  483. {
  484. return false;
  485. }
  486. strUrl = m_strEvent;
  487. return true;
  488. }
  489. ONVIFLIB_API int OnvifClientDevice::GetCapabilities()
  490. {
  491. _tds__GetCapabilitiesResponse cap;
  492. return GetCapabilities(cap);
  493. }
  494. ONVIFLIB_API int OnvifClientDevice::GetCapabilities(_tds__GetCapabilitiesResponse &cap)
  495. {
  496. deviceBindProxy.soap_endpoint = m_strUrl.c_str();
  497. soap_wsse_add_Security(&deviceBindProxy);
  498. soap_wsse_add_UsernameTokenDigest(&deviceBindProxy, "Id", m_strUser.c_str() , m_strPass.c_str());
  499. //deviceBindProxy.soap_header;
  500. //deviceBindProxy.soap.header
  501. _tds__GetCapabilities capabilities;
  502. capabilities.Category.push_back(tt__CapabilityCategory__All);
  503. if (deviceBindProxy.GetCapabilities(&capabilities,&cap)!= SOAP_OK||
  504. cap.Capabilities == NULL)
  505. {
  506. return SOAP_ERR;
  507. }
  508. /* Media */
  509. if (cap.Capabilities->Media != NULL)
  510. {
  511. m_hasMedia = true;
  512. m_strMedia = cap.Capabilities->Media->XAddr;
  513. }
  514. /* PTZ */
  515. if (cap.Capabilities->PTZ != NULL)
  516. {
  517. m_hasPTZ = true;
  518. m_strPTZ = cap.Capabilities->PTZ->XAddr;
  519. }
  520. /* Event */
  521. if (cap.Capabilities->Events != NULL)
  522. {
  523. m_hasEvent = true;
  524. m_strEvent = cap.Capabilities->Events->XAddr;
  525. }
  526. /* Imaging */
  527. if (cap.Capabilities->Imaging != NULL)
  528. {
  529. m_hasImaging = true;
  530. m_strImaging = cap.Capabilities->Imaging->XAddr;
  531. }
  532. /* Extension */
  533. if (cap.Capabilities->Extension != NULL)
  534. {
  535. /* Receiver */
  536. if (cap.Capabilities->Extension->Receiver != NULL)
  537. {
  538. m_hasReceiver = true;
  539. m_strReceiver = cap.Capabilities->Extension->Receiver->XAddr;
  540. }
  541. /* Recording */
  542. if (cap.Capabilities->Extension->Recording != NULL)
  543. {
  544. m_hasRecording = true;
  545. m_strRecording = cap.Capabilities->Extension->Recording->XAddr;
  546. }
  547. /* Search */
  548. if (cap.Capabilities->Extension->Search != NULL)
  549. {
  550. m_hasSearch = true;
  551. m_strSearch = cap.Capabilities->Extension->Search->XAddr;
  552. }
  553. /* Replay */
  554. if (cap.Capabilities->Extension->Replay != NULL)
  555. {
  556. m_hasReplay = true;
  557. m_strReplay = cap.Capabilities->Extension->Replay->XAddr;
  558. }
  559. }
  560. m_hasGetCap = true;
  561. return SOAP_OK;
  562. }