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.

114 lines
3.3 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "onvifclientevent.hpp"
  2. OnvifClientEventNotify::OnvifClientEventNotify(struct soap* pData)
  3. : m_EventCnt(0), PullPointSubscriptionBindingService(*pData)
  4. {
  5. }
  6. inline OnvifClientEvent::OnvifClientEvent(OnvifClientDevice &device)
  7. : m_Device(device), eventBinding(SOAP_C_UTFSTRING)
  8. {
  9. }
  10. inline OnvifClientEvent::~OnvifClientEvent()
  11. {
  12. }
  13. ONVIFLIB_API inline int OnvifClientEvent::Subscribe(string &notifyUrl)
  14. {
  15. string strUrl;
  16. string strUser;
  17. string strPass;
  18. _wsnt__Subscribe subscribe;
  19. _wsnt__SubscribeResponse subscribeResponse;
  20. string strTimeOut = "PT60S";
  21. if (m_Device.GetUserPasswd(strUser, strPass) == false
  22. || m_Device.GetEventUrl(strUrl) == false)
  23. {
  24. return SOAP_ERR;
  25. }
  26. subscribe.ConsumerReference.Address = (char *)(notifyUrl.c_str());
  27. subscribe.InitialTerminationTime = &strTimeOut;
  28. eventBinding.soap_endpoint = strUrl.c_str();
  29. soap_wsse_add_Security(&eventBinding);
  30. soap_wsse_add_UsernameTokenDigest(&eventBinding, "Id",
  31. strUser.c_str() , strPass.c_str());
  32. soap_wsa_add_From(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
  33. soap_wsa_add_ReplyTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
  34. soap_wsa_add_FaultTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
  35. int ret = eventBinding.Subscribe(&subscribe,&subscribeResponse);
  36. if (ret == SOAP_OK)
  37. {
  38. m_RenewEndpoint = subscribeResponse.SubscriptionReference.Address;
  39. printf("SubscriptionReference %s\n", m_RenewEndpoint.c_str());
  40. }
  41. return ret;
  42. }
  43. ONVIFLIB_API int OnvifClientEvent::UnSubscribe()
  44. {
  45. string strUrl;
  46. string strUser;
  47. string strPass;
  48. _wsnt__Unsubscribe unsubscribe;
  49. _wsnt__UnsubscribeResponse unsubscribeResponse;
  50. if (m_Device.GetUserPasswd(strUser, strPass) == false
  51. || m_Device.GetEventUrl(strUrl) == false)
  52. {
  53. return SOAP_ERR;
  54. }
  55. eventBinding.soap_endpoint = strUrl.c_str();
  56. soap_wsse_add_Security(&eventBinding);
  57. soap_wsse_add_UsernameTokenDigest(&eventBinding, "Id",
  58. strUser.c_str() , strPass.c_str());
  59. soap_wsa_add_From(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
  60. soap_wsa_add_ReplyTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
  61. soap_wsa_add_FaultTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
  62. eventBinding.header->wsa5__To = const_cast<char *>(m_RenewEndpoint.c_str());
  63. return eventBinding.Unsubscribe(&unsubscribe,&unsubscribeResponse);
  64. }
  65. ONVIFLIB_API int OnvifClientEvent::Renew()
  66. {
  67. string strUrl;
  68. string strUser;
  69. string strPass;
  70. _wsnt__Renew req;
  71. _wsnt__RenewResponse resp;
  72. string strTimeOut = "PT60S";
  73. if (m_Device.GetUserPasswd(strUser, strPass) == false
  74. || m_Device.GetEventUrl(strUrl) == false)
  75. {
  76. return SOAP_ERR;
  77. }
  78. req.TerminationTime = &strTimeOut;
  79. eventBinding.soap_endpoint = strUrl.c_str();
  80. soap_wsse_add_Security(&eventBinding);
  81. soap_wsse_add_UsernameTokenDigest(&eventBinding, "Id",
  82. strUser.c_str() , strPass.c_str());
  83. //soap_wsa_add_From(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
  84. soap_wsa_add_ReplyTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
  85. //soap_wsa_add_FaultTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
  86. eventBinding.header->wsa5__To = const_cast<char *>(m_RenewEndpoint.c_str());
  87. int ret = eventBinding.Renew(&req,&resp);
  88. return ret;
  89. }