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.

1789 lines
86 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "ponvif.h"
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. #include <netdb.h>
  5. #include <sys/types.h> /* See NOTES */
  6. #include <sys/socket.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #include <string.h>
  11. #include <sys/types.h>
  12. #include <sys/socket.h>
  13. #include <arpa/inet.h>
  14. #include <netinet/in.h>
  15. //http://dspace.nplg.gov.ge/handle/1234/3051
  16. //http://dspace.nplg.gov.ge/handle/1234/3057
  17. //http://dspace.nplg.gov.ge/handle/1234/3061
  18. #define LOG( X ) m_pLog->Log( "pOnVif", this, X )
  19. #define TLOG( X ) basicLogCollection::getInstance()->Log( "TpOnVif", NULL, X )
  20. #define LOG_ERROR( X ) m_pLog->Log( "pOnVif", this, _LOG_ERROR, X )
  21. inline bool checkBool( const char *A ){
  22. if(A == NULL) return false;
  23. return ( A[0]=='T' || A[0] == 't' || A[0] == '1' );
  24. };
  25. inline bool checkOnOff( const char *A ){
  26. if(A == NULL) return false;
  27. return ( A[1]=='N' || A[1] == 'n' || A[0] == '1' );
  28. };
  29. inline onvifOnOffAuto checkOnOffAuto( const char *A ){
  30. if(A == NULL) return AUTO;
  31. if( A[1]=='N' || A[1] == 'n' || A[0] == '1' ) return ON;
  32. return OFF;
  33. };
  34. pOnvif::pOnvif(){
  35. m_pLog = basicLogCollection::getInstance();
  36. m_pIpAddress = NULL;
  37. m_pUsername = NULL;
  38. m_pPassword = NULL;
  39. m_pMediaURI = NULL;
  40. m_pSnapshotURI = NULL;
  41. m_pDeviceURI = NULL;
  42. m_pPTZURI = NULL;
  43. m_pBaseURI = NULL;
  44. m_nDeltaTime=0;
  45. m_pCURL = NULL;
  46. m_pProxyHost = NULL;
  47. m_nProxyPort = 0;
  48. m_pProxyUsername = NULL;
  49. m_pProxyPassword = NULL;
  50. m_pLastResponse = NULL;
  51. m_bIntransingent = true;
  52. m_nDiscoveryTimeout = PONVIF_DEFAULT_DISCOVERYTIMEOUT;
  53. m_pDiscoveryBindIP = NULL;//PONVIF_DEFAULT_DISCOVERYBINDIP;
  54. m_pDiscoveryMCastIP = NULL;//PONVIF_DEFAULT_DISCOVERYMCASTIP;
  55. m_nDiscoveryMCastPort = PONVIF_DEFAULT_DISCOVERYMCASTPORT;
  56. m_bDiscoveryHideDuplicates = true;
  57. m_sCapabilities.Analytics = NULL;
  58. m_sCapabilities.Device = NULL;
  59. m_sCapabilities.Events = NULL;
  60. m_sCapabilities.Imaging = NULL;
  61. m_sCapabilities.Media = NULL;
  62. m_sCapabilities.PTZ = NULL;
  63. m_sCapabilities.Extension = NULL;
  64. LOG("Constructor Done!");
  65. };
  66. pOnvif::~pOnvif(){
  67. if(m_pIpAddress) free(m_pIpAddress);
  68. if(m_pUsername) free(m_pUsername);
  69. if(m_pPassword) free(m_pPassword);
  70. if(m_pMediaURI) free(m_pMediaURI);
  71. if(m_pSnapshotURI) free(m_pSnapshotURI);
  72. if(m_pDeviceURI) free(m_pDeviceURI);
  73. if(m_pPTZURI) free(m_pPTZURI);
  74. if(m_pBaseURI) free(m_pBaseURI);
  75. if(m_pProxyHost) free(m_pProxyHost);
  76. if(m_pProxyUsername) free(m_pProxyUsername);
  77. if(m_pProxyPassword) free(m_pProxyPassword);
  78. if(m_pLastResponse) free(m_pLastResponse);
  79. if(m_pDiscoveryBindIP) free(m_pDiscoveryBindIP);
  80. if(m_pDiscoveryMCastIP) free(m_pDiscoveryMCastIP);
  81. if( m_pCURL!= NULL ) {
  82. curl_easy_cleanup(m_pCURL);
  83. };
  84. LOG("Destructor Done!");
  85. };
  86. bool pOnvif::setProxyHost( CSTR proxyHost ){
  87. if( m_pProxyHost != NULL ) free( m_pProxyHost );
  88. if( proxyHost == NULL || strlen(proxyHost) == 0 ){
  89. m_pProxyHost = NULL;
  90. return true;
  91. };
  92. m_pProxyHost = (CSTR) malloc( strlen(proxyHost)+1);
  93. if( m_pProxyHost == NULL ) return false;
  94. memcpy(m_pProxyHost,proxyHost,strlen(proxyHost)+1);
  95. return true;
  96. };
  97. CSTR pOnvif::getProxyHost(){
  98. return m_pProxyHost;
  99. };
  100. bool pOnvif::setProxyPort( int proxyPort ){
  101. m_nProxyPort = proxyPort;
  102. return true;
  103. };
  104. int pOnvif::getProxyPort( void ){
  105. return m_nProxyPort;
  106. };
  107. bool pOnvif::setProxyUsername( CSTR proxyUsername ){
  108. if( m_pProxyUsername != NULL ) free( m_pProxyUsername );
  109. if( proxyUsername == NULL || strlen(proxyUsername) == 0 ){
  110. m_pProxyUsername = NULL;
  111. return true;
  112. };
  113. m_pProxyUsername = (CSTR) malloc( strlen(proxyUsername)+1);
  114. if( m_pProxyUsername == NULL ) return false;
  115. memcpy(m_pProxyUsername,proxyUsername,strlen(proxyUsername)+1);
  116. return true;
  117. };
  118. CSTR pOnvif::getProxyUsername( void ){
  119. return m_pProxyUsername;
  120. };
  121. bool pOnvif::setProxyPassword( CSTR proxyPassword ){
  122. if( m_pProxyPassword != NULL ) free( m_pProxyPassword );
  123. if( proxyPassword == NULL || strlen(proxyPassword) == 0 ){
  124. m_pProxyPassword = NULL;
  125. return true;
  126. };
  127. m_pProxyPassword = (CSTR) malloc( strlen(proxyPassword)+1);
  128. if( m_pProxyPassword == NULL ) return false;
  129. memcpy(m_pProxyPassword,proxyPassword,strlen(proxyPassword)+1);
  130. return true;
  131. };
  132. CSTR pOnvif::getProxyPassword(){
  133. return m_pProxyPassword;
  134. };
  135. bool pOnvif::setUsername( CSTR username ){
  136. if( m_pUsername != NULL ) free( m_pUsername );
  137. if( username == NULL || strlen(username) == 0 ){
  138. m_pUsername = NULL;
  139. return true;
  140. };
  141. m_pUsername = (CSTR) malloc( strlen(username)+1);
  142. if( m_pUsername == NULL ) return false;
  143. memcpy(m_pUsername,username,strlen(username)+1);
  144. return true;
  145. };
  146. CSTR pOnvif::getUsername( void ) {
  147. return m_pUsername;
  148. };
  149. bool pOnvif::setPassword( CSTR password ){
  150. if( m_pPassword != NULL ) free( m_pPassword );
  151. if( password == NULL || strlen(password) == 0 ){
  152. m_pPassword = NULL;
  153. return true;
  154. };
  155. m_pPassword = (CSTR) malloc( strlen(password)+1);
  156. if( m_pPassword == NULL ) return false;
  157. memcpy(m_pPassword,password,strlen(password)+1);
  158. return true;
  159. };
  160. CSTR pOnvif::getPassword( void ){
  161. return m_pPassword;
  162. };
  163. CSTR pOnvif::getDeviceUri( void ){
  164. return m_pDeviceURI;
  165. };
  166. bool pOnvif::setDeviceUri( CSTR deviceUri ){
  167. if( m_pDeviceURI != NULL ) free( m_pDeviceURI );
  168. if( deviceUri == NULL || strlen(deviceUri) == 0 ){
  169. m_pDeviceURI = NULL;
  170. return true;
  171. };
  172. m_pDeviceURI = (CSTR) malloc( strlen(deviceUri)+1);
  173. if( m_pDeviceURI == NULL ) return false;
  174. memcpy(m_pDeviceURI,deviceUri,strlen(deviceUri)+1);
  175. return true;
  176. };
  177. CSTR pOnvif::getIPAddress( void ){
  178. return m_pIpAddress;
  179. };
  180. bool pOnvif::setIPAddress( CSTR ipAddress ){
  181. if( m_pIpAddress != NULL ) free( m_pIpAddress );
  182. if( ipAddress == NULL || strlen(ipAddress) == 0 ){
  183. m_pIpAddress = NULL;
  184. return true;
  185. };
  186. m_pIpAddress = (CSTR) malloc( strlen(ipAddress)+1);
  187. if( m_pIpAddress == NULL ) return false;
  188. memcpy(m_pIpAddress,ipAddress,strlen(ipAddress)+1);
  189. return true;
  190. };
  191. videoSources *pOnvif::getSources( void ){
  192. return &m_vVideoSources;
  193. };
  194. videoSourceProfiles *pOnvif::getProfiles( void ){
  195. return &m_vVideoProfiles;
  196. };
  197. videoSourceProfiles *pOnvif::getActiveProfiles( void ){
  198. return &m_vActiveSources;
  199. };
  200. CSTR pOnvif::getMediaUri( void ){
  201. return m_pMediaURI;
  202. };
  203. CSTR pOnvif::getPTZUri( void ){
  204. return m_pPTZURI;
  205. };
  206. CSTR pOnvif::getBaseUrl( void ){
  207. return m_pBaseURI;
  208. };
  209. void pOnvif::getSupportedVersion( void ){ };
  210. nodeCapability *pOnvif::getCapabilities( void ){
  211. return &m_sCapabilities;
  212. };
  213. bool pOnvif::setBreakOnError( bool intransingent ){
  214. m_bIntransingent = intransingent;
  215. return true;
  216. };
  217. CSTR pOnvif::getLastResponse( void ){
  218. return m_pLastResponse;
  219. };
  220. bool pOnvif::setDiscoveryTimeout( int discoverytimeout ){
  221. m_nDiscoveryTimeout = discoverytimeout;
  222. return true;
  223. };
  224. bool pOnvif::setDiscoveryBindIp( CSTR discoverybindip ){
  225. if( m_pDiscoveryBindIP != NULL ) free( m_pDiscoveryBindIP );
  226. if( discoverybindip == NULL || strlen(discoverybindip) == 0 ){
  227. m_pDiscoveryBindIP = NULL;
  228. return true;
  229. };
  230. m_pDiscoveryBindIP = (CSTR) malloc( strlen(discoverybindip)+1);
  231. if( m_pDiscoveryBindIP == NULL ) return false;
  232. memcpy(m_pDiscoveryBindIP,discoverybindip,strlen(discoverybindip)+1);
  233. return true;
  234. };
  235. bool pOnvif::setDiscoveryMcastIp( CSTR discoverymcastip ){
  236. if( m_pDiscoveryMCastIP != NULL ) free( m_pDiscoveryMCastIP );
  237. if( discoverymcastip == NULL || strlen(discoverymcastip) == 0 ){
  238. m_pDiscoveryMCastIP = NULL;
  239. return true;
  240. };
  241. m_pDiscoveryMCastIP = (CSTR) malloc( strlen(discoverymcastip)+1);
  242. if( m_pDiscoveryMCastIP == NULL ) return false;
  243. memcpy(m_pDiscoveryMCastIP,discoverymcastip,strlen(discoverymcastip)+1);
  244. return true;
  245. };
  246. bool pOnvif::setDiscoveryMcastPort( int discoverymcastport ){
  247. m_nDiscoveryMCastPort = discoverymcastport;
  248. return true;
  249. };
  250. bool pOnvif::setDiscoveryHideDuplicates( bool discoveryhideduplicates ){
  251. m_bDiscoveryHideDuplicates = discoveryhideduplicates;
  252. return true;
  253. };
  254. CSTR pOnvif::getSnapshotUri( void ){
  255. return m_pSnapshotURI;
  256. };
  257. /*
  258. WS-Discovery
  259. https://www.geeksforgeeks.org/udp-server-client-implementation-c/
  260. */
  261. discoveryResults pOnvif::discover( void ){
  262. discoveryResults RetVal;
  263. time_t tTimeout = time( NULL ) + m_nDiscoveryTimeout;
  264. CSTR tPostString = PONVIF_PACK_DISCOVERY;
  265. struct sockaddr_in tSockAddr;
  266. struct hostent * h_info;
  267. int tSocket;
  268. int RetCode;
  269. char Response[DEFAULT_BUFFER_SIZE];
  270. try {
  271. //SOL_UDP = 17
  272. tSocket = socket(AF_INET, SOCK_DGRAM, 0 );
  273. if( tSocket < 0 ){
  274. LOG_ERROR("ERROR creating socket");
  275. return RetVal;
  276. };
  277. LOG("Socket Created!");
  278. bzero( &tSockAddr, sizeof( struct sockaddr_in ) );
  279. h_info = gethostbyname ( m_pDiscoveryBindIP );
  280. if ( h_info == NULL ){
  281. LOG_ERROR( "Some throuble with networking on this machine (Cannot Get Hostname)!" );
  282. return RetVal;
  283. };
  284. LOG("Host Found!");
  285. //*****************************************
  286. //* there we building our network address *
  287. //*****************************************
  288. bcopy( h_info->h_addr, &(tSockAddr.sin_addr), h_info->h_length );
  289. tSockAddr.sin_family = h_info->h_addrtype;
  290. tSockAddr.sin_port = htons( 20000 + ( 20000 * rand() ) / RAND_MAX );
  291. RetCode = bind( tSocket , (const sockaddr*)&tSockAddr, sizeof( struct sockaddr_in ) );
  292. if ( RetCode != 0 ){
  293. LOG_ERROR( "Error Binding to Port/Address" );
  294. return RetVal;
  295. };
  296. LOG("Binding Done!");
  297. //setsockopt( tSocket, IPPROTO_IP, MCAST_JOIN_GROUP, );
  298. int tVal = 1;
  299. setsockopt( tSocket, SOL_SOCKET, SO_BROADCAST, &tVal, sizeof(int));
  300. //socket_sendto($sock, $post_string, strlen(tPostString), 0, $this->discoverymcastip, $this->discoverymcastport);
  301. sendto( tSocket, tPostString, strlen(tPostString), 0, (const sockaddr*)&tSockAddr, sizeof( struct sockaddr_in ));
  302. LOG("Broadcast Ping Sent!");
  303. fcntl( tSocket, F_SETFL, fcntl(tSocket, F_GETFL, 0) | O_NONBLOCK );
  304. //socket_set_nonblock($sock);
  305. LOG("Socket Set Not Bloking Mode!");
  306. while( time( NULL ) < tTimeout ){
  307. //n = recvfrom(sockfd, (char *)buffer, MAXLINE, MSG_WAITALL, (struct sockaddr *) &servaddr, &len);
  308. tVal = recvfrom( tSocket, Response, DEFAULT_BUFFER_SIZE, 0, NULL, NULL );
  309. if( tVal > 0 ){
  310. Response[tVal] = '\0';
  311. //if( FALSE !== socket_recvfrom( $sock, $response, 9999, 0, $from, $this->discoverymcastport )){
  312. //if( Response != NULL && $response != $post_string){
  313. LOG(Response);
  314. XMLNode node = XMLNode::parseString( Response, "root" );
  315. //$response = $this->_xml2array($response);
  316. //if(!isFault( node )){
  317. //$response['Envelope']['Body']['ProbeMatches']['ProbeMatch']['IPAddr'] = $from;
  318. if( m_bDiscoveryHideDuplicates ){
  319. // $result[$from] = $response['Envelope']['Body']['ProbeMatches']['ProbeMatch'];
  320. }else{
  321. // $result[] = $response['Envelope']['Body']['ProbeMatches']['ProbeMatch'];
  322. };
  323. // };
  324. //};
  325. //};
  326. };
  327. };
  328. close( tSocket );
  329. } catch ( exception e ) {
  330. LOG_ERROR( "Communication at Discovery Exception Catched!");
  331. };
  332. return RetVal;
  333. };
  334. /*
  335. Public functions (basic initialization method and other collaterals)
  336. */
  337. bool pOnvif::create( void ) {
  338. try {
  339. struct tm * tTS;
  340. tTS = core_GetSystemDateAndTime();
  341. if( tTS != NULL ){
  342. time_t tTimeStamp = mktime( tTS );
  343. m_nDeltaTime = time( NULL ) - tTimeStamp - 5;
  344. free( tTS );
  345. };
  346. } catch ( exception e ) {}
  347. if( !core_GetCapabilities() ){
  348. LOG_ERROR("Error Getting Caps!");
  349. return false;
  350. }
  351. _getOnvifVersion( m_sCapabilities );
  352. // Update some Vars Online!
  353. //preg_match("/^http(.*)onvif\//",$this->mediauri,$matches);
  354. //m_pBaseURI = $matches[0];
  355. if( media_GetVideoSources() ){
  356. if( media_GetProfiles() ) {
  357. //_getActiveSources( m_vVideoSources, m_vVideoProfiles);
  358. return true;
  359. };
  360. };
  361. return false;
  362. };
  363. /*
  364. Public wrappers for a subset of ONVIF primitives
  365. */
  366. struct tm *pOnvif::core_GetSystemDateAndTime( void ) {
  367. struct tm * RetVal = NULL;
  368. char tURL[CTEXT];
  369. sprintf( tURL, "http://%s/onvif/device_service", m_pIpAddress );
  370. if( _send_request( tURL, PONVIF_PACK_GET_SYS_DTS ) ){
  371. XMLResults tParseResults;
  372. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  373. #ifdef DEBUG_ONVIF_PRINTOUT_MESSAGES
  374. LOG("RCPT:");
  375. printf(m_pLastResponse);
  376. #endif
  377. if( tParseResults.error ){
  378. char tBuffer[CTEXT];
  379. sprintf( tBuffer, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  380. LOG_ERROR( tBuffer );
  381. } else {
  382. RetVal = ( struct tm * ) malloc( sizeof(struct tm) );
  383. if( RetVal!= NULL ) {
  384. memset( RetVal, 0, sizeof(struct tm) );
  385. XMLNode zNode = response.getChildNode("Body", 0);
  386. XMLNode fNode = zNode.getChildNode("GetSystemDateAndTimeResponse", 0);
  387. XMLNode hNode = fNode.getChildNode("SystemDateAndTime", 0);
  388. XMLNode tNode = hNode.getChildNode("UTCDateTime", 0);
  389. if( !tNode.isEmpty() ) {
  390. RetVal->tm_isdst = 0;
  391. XMLNode ttNode = tNode.getChildNode( "Time", 0 );
  392. XMLNode dtNode = tNode.getChildNode( "Date", 0 );
  393. {
  394. XMLNode t = ttNode.getChildNode("Hour",0);
  395. RetVal->tm_hour = atoi( t.getText(0) );
  396. }
  397. {
  398. XMLNode t = ttNode.getChildNode("Minute",0);
  399. RetVal->tm_min = atoi( t.getText(0) );
  400. }
  401. {
  402. XMLNode t = ttNode.getChildNode("Second",0);
  403. RetVal->tm_sec = atoi( t.getText(0) );
  404. }
  405. {
  406. XMLNode t = dtNode.getChildNode("Year",0);
  407. RetVal->tm_year = atoi( t.getText(0) );
  408. }
  409. {
  410. XMLNode t = dtNode.getChildNode("Month",0);
  411. RetVal->tm_mon = atoi( t.getText(0) );
  412. }
  413. {
  414. XMLNode t = dtNode.getChildNode("Day",0);
  415. RetVal->tm_mday = atoi( t.getText(0) );
  416. }
  417. };
  418. };
  419. return RetVal;
  420. };
  421. } else LOG_ERROR( "GetSystemDateAndTime: Communication error" );
  422. return NULL;
  423. };
  424. // Based on https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl
  425. bool pOnvif::core_GetCapabilities( void ){
  426. char tBuffer[DEFAULT_BUFFER_SIZE];
  427. accessToken tTOKEN;
  428. tTOKEN = _makeToken();
  429. char tURL[CTEXT];
  430. sprintf( tURL, "http://%s/onvif/device_service", m_pIpAddress );
  431. //char tSTR[CTEXT];
  432. sprintf( tBuffer, PONVIF_PACK_GET_CAPABILITIES, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP );
  433. //sprintf( tSTR, PONVIF_PCK_GET_CAPABILITIES, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP );
  434. //build_package( tBuffer, PONVIF_ENVELOPE_SIM, tSTR );
  435. if( _send_request( tURL, tBuffer ) ){
  436. XMLResults tParseResults;
  437. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  438. #ifdef DEBUG_ONVIF_PRINTOUT_MESSAGES
  439. LOG("RCPT:");
  440. printf(m_pLastResponse);
  441. #endif
  442. if( tParseResults.error != eXMLErrorNone ){
  443. char tBuf[CTEXT];
  444. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  445. LOG_ERROR( tBuf );
  446. } else {
  447. XMLNode zNode = response.getChildNode("Body", 0);
  448. if( zNode.isEmpty() ) return false;
  449. XMLNode tNode = zNode.getChildNode("GetCapabilitiesResponse", 0);
  450. if( !tNode.isEmpty() ) {
  451. XMLNode tCaps = tNode.getChildNode("Capabilities", 0);
  452. if( !tCaps.isEmpty() ){
  453. {
  454. XMLNode t = tCaps.getChildNode("Analytics", 0);
  455. if( !t.isEmpty() ) {
  456. m_sCapabilities.Analytics = (onvifAnalyticsCapabilities *) malloc(sizeof(onvifAnalyticsCapabilities));
  457. if( m_sCapabilities.Analytics != NULL ) {
  458. memset( m_sCapabilities.Analytics, 0, sizeof(onvifAnalyticsCapabilities));
  459. {
  460. XMLNode c = t.getChildNode("XAddr", 0);
  461. sprintf( m_sCapabilities.Analytics->XAddr,"%s", c.getText(0) );
  462. }
  463. {
  464. XMLNode c = t.getChildNode("RuleSupport", 0);
  465. m_sCapabilities.Analytics->RuleSupport = checkBool(c.getText(0));
  466. }
  467. {
  468. XMLNode c = t.getChildNode("AnalyticsModuleSupport", 0);
  469. m_sCapabilities.Analytics->AnalyticsModuleSupport = checkBool(c.getText(0));
  470. }
  471. };
  472. };
  473. }
  474. {
  475. XMLNode t = tCaps.getChildNode("Device", 0);
  476. if( !t.isEmpty() ) {
  477. m_sCapabilities.Device = (onvifDeviceCapabilities *) malloc(sizeof(onvifDeviceCapabilities));
  478. if( m_sCapabilities.Device != NULL ) {
  479. memset( m_sCapabilities.Device, 0, sizeof(onvifDeviceCapabilities));
  480. {
  481. XMLNode c = t.getChildNode("XAddr", 0);
  482. sprintf( m_sCapabilities.Device->XAddr,"%s", c.getText(0) );
  483. }
  484. {
  485. XMLNode c = t.getChildNode("Network", 0);
  486. if( !c.isEmpty() ) {
  487. m_sCapabilities.Device->Network = (onvifNetworkCapabilities *) malloc(sizeof(onvifNetworkCapabilities));
  488. if( m_sCapabilities.Device->Network!= NULL ) {
  489. memset( m_sCapabilities.Device->Network, 0 , sizeof(onvifNetworkCapabilities));
  490. {
  491. XMLNode n = c.getChildNode("IPFilter", 0);
  492. m_sCapabilities.Device->Network->IPFilter = checkBool(n.getText(0));
  493. }
  494. {
  495. XMLNode n = c.getChildNode("ZeroConfiguration", 0);
  496. m_sCapabilities.Device->Network->ZeroConfiguration = checkBool(n.getText(0));
  497. }
  498. {
  499. XMLNode n = c.getChildNode("IPVersion6", 0);
  500. m_sCapabilities.Device->Network->IPVersion6 = checkBool(n.getText(0));
  501. }
  502. {
  503. XMLNode n = c.getChildNode("DynDNS", 0);
  504. m_sCapabilities.Device->Network->DynDNS = checkBool(n.getText(0));
  505. }
  506. {
  507. XMLNode n = c.getChildNode("Extension", 0);
  508. if( !n.isEmpty() ) {
  509. m_sCapabilities.Device->Network->Extension = (onvifNetworkCapabilitiesExtension *) malloc( sizeof(onvifNetworkCapabilitiesExtension));
  510. if( m_sCapabilities.Device->Network->Extension!= NULL ) {
  511. memset(m_sCapabilities.Device->Network->Extension, 0 ,sizeof(onvifNetworkCapabilitiesExtension));
  512. {
  513. XMLNode x = n.getChildNode("Dot11Configuration", 0);
  514. m_sCapabilities.Device->Network->Extension->Dot11Configuration = checkBool(x.getText(0));
  515. }
  516. };
  517. };
  518. }
  519. };
  520. };
  521. }
  522. {
  523. XMLNode c = t.getChildNode("System", 0);
  524. if( !c.isEmpty() ) {
  525. m_sCapabilities.Device->System = (onvifSystemCapabilities*) malloc(sizeof(onvifSystemCapabilities));
  526. if( m_sCapabilities.Device->System != NULL ) {
  527. memset(m_sCapabilities.Device->System, 0, sizeof(onvifSystemCapabilities));
  528. {
  529. XMLNode n = c.getChildNode("DiscoveryResolve", 0);
  530. m_sCapabilities.Device->System->DiscoveryResolve = checkBool(n.getText(0));
  531. }
  532. {
  533. XMLNode n = c.getChildNode("DiscoveryBye", 0);
  534. m_sCapabilities.Device->System->DiscoveryBye = checkBool(n.getText(0));
  535. }
  536. {
  537. XMLNode n = c.getChildNode("RemoteDiscovery", 0);
  538. m_sCapabilities.Device->System->RemoteDiscovery = checkBool(n.getText(0));
  539. }
  540. {
  541. XMLNode n = c.getChildNode("SystemBackup", 0);
  542. m_sCapabilities.Device->System->SystemBackup = checkBool(n.getText(0));
  543. }
  544. {
  545. XMLNode n = c.getChildNode("SystemLogging", 0);
  546. m_sCapabilities.Device->System->SystemLogging = checkBool(n.getText(0));
  547. }
  548. {
  549. XMLNode n = c.getChildNode("FirmwareUpgrade", 0);
  550. m_sCapabilities.Device->System->FirmwareUpgrade = checkBool(n.getText(0));
  551. }
  552. {
  553. XMLNode n = c.getChildNode("SupportedVersions", 0);
  554. if( !n.isEmpty() ) {
  555. m_sCapabilities.Device->System->SupportedVersions = (onvifSupportedVersions*) malloc(sizeof(onvifSupportedVersions));
  556. if( m_sCapabilities.Device->System->SupportedVersions!=NULL) {
  557. memset(m_sCapabilities.Device->System->SupportedVersions, 0, sizeof(onvifSupportedVersions));
  558. {
  559. XMLNode x = n.getChildNode("Major", 0);
  560. m_sCapabilities.Device->System->SupportedVersions->Major = atoi(x.getText(0));
  561. }
  562. {
  563. XMLNode x = n.getChildNode("Minor", 0);
  564. m_sCapabilities.Device->System->SupportedVersions->Minor = atoi(x.getText(0));
  565. }
  566. };
  567. };
  568. }
  569. {
  570. XMLNode n = c.getChildNode("Extension", 0);
  571. if( !n.isEmpty() ) {
  572. m_sCapabilities.Device->System->Extension = (onvifSystemCapabilitiesExtension*) malloc(sizeof(onvifSystemCapabilitiesExtension));
  573. if( m_sCapabilities.Device->System->Extension!=NULL) {
  574. memset(m_sCapabilities.Device->System->Extension, 0, sizeof(onvifSystemCapabilitiesExtension));
  575. {
  576. XMLNode x = n.getChildNode("HttpFirmwareUpgrade", 0);
  577. m_sCapabilities.Device->System->Extension->HttpFirmwareUpgrade = checkBool(x.getText(0));
  578. }
  579. {
  580. XMLNode x = n.getChildNode("HttpSystemBackup", 0);
  581. m_sCapabilities.Device->System->Extension->HttpSystemBackup = checkBool(x.getText(0));
  582. }
  583. {
  584. XMLNode x = n.getChildNode("HttpSystemLogging", 0);
  585. m_sCapabilities.Device->System->Extension->HttpSystemLogging = checkBool(x.getText(0));
  586. }
  587. {
  588. XMLNode x = n.getChildNode("HttpSupportInformation", 0);
  589. m_sCapabilities.Device->System->Extension->HttpSupportInformation = checkBool(x.getText(0));
  590. }
  591. };
  592. };
  593. }
  594. };
  595. };
  596. }
  597. {
  598. XMLNode c = t.getChildNode("IO", 0);
  599. if( !c.isEmpty() ) {
  600. m_sCapabilities.Device->IO = (onvifIOCapabilities*) malloc(sizeof(onvifIOCapabilities));
  601. if(m_sCapabilities.Device->IO != NULL) {
  602. memset(m_sCapabilities.Device->IO, 0, sizeof(onvifIOCapabilities));
  603. {
  604. XMLNode n = c.getChildNode("InputConnectors", 0);
  605. m_sCapabilities.Device->IO->InputConnectors = atoi(n.getText(0));
  606. }
  607. {
  608. XMLNode n = c.getChildNode("RelayOutputs", 0);
  609. m_sCapabilities.Device->IO->RelayOutputs = atoi(n.getText(0));
  610. }
  611. {
  612. XMLNode n = c.getChildNode("Extension", 0);
  613. if( !n.isEmpty() ) {
  614. m_sCapabilities.Device->IO->Extension = (onvifIOCapabilitiesExtension*) malloc(sizeof(onvifIOCapabilitiesExtension));
  615. if(m_sCapabilities.Device->IO->Extension!=NULL) {
  616. memset(m_sCapabilities.Device->IO->Extension, 0, sizeof(onvifIOCapabilitiesExtension));
  617. {
  618. XMLNode x = n.getChildNode("Auxiliary", 0);
  619. m_sCapabilities.Device->IO->Extension->Auxiliary = checkBool(x.getText(0));
  620. }
  621. };
  622. };
  623. }
  624. };
  625. };
  626. }
  627. {
  628. XMLNode c = t.getChildNode("Security", 0);
  629. if( !c.isEmpty() ) {
  630. m_sCapabilities.Device->Security = (onvifSecurityCapabilities*) malloc(sizeof(onvifSecurityCapabilities));
  631. if(m_sCapabilities.Device->Security!=NULL) {
  632. memset(m_sCapabilities.Device->Security, 0, sizeof(onvifSecurityCapabilities));
  633. {
  634. XMLNode n = c.getChildNode("TLS1.1", 0);
  635. m_sCapabilities.Device->Security->TLS1_1 = checkBool(n.getText(0));
  636. }
  637. {
  638. XMLNode n = c.getChildNode("TLS1.2", 0);
  639. m_sCapabilities.Device->Security->TLS1_2 = checkBool(n.getText(0));
  640. }
  641. {
  642. XMLNode n = c.getChildNode("OnboardKeyGeneration", 0);
  643. m_sCapabilities.Device->Security->OnboardKeyGeneration = checkBool(n.getText(0));
  644. }
  645. {
  646. XMLNode n = c.getChildNode("AccessPolicyConfig", 0);
  647. m_sCapabilities.Device->Security->AccessPolicyConfig = checkBool(n.getText(0));
  648. }
  649. {
  650. XMLNode n = c.getChildNode("X.509Token", 0);
  651. m_sCapabilities.Device->Security->X_509Token = checkBool(n.getText(0));
  652. }
  653. {
  654. XMLNode n = c.getChildNode("SAMLToken", 0);
  655. m_sCapabilities.Device->Security->SAMLToken = checkBool(n.getText(0));
  656. }
  657. {
  658. XMLNode n = c.getChildNode("KerberosToken", 0);
  659. m_sCapabilities.Device->Security->KerberosToken = checkBool(n.getText(0));
  660. }
  661. {
  662. XMLNode n = c.getChildNode("RELToken", 0);
  663. m_sCapabilities.Device->Security->RELToken = checkBool(n.getText(0));
  664. }
  665. {
  666. XMLNode n = c.getChildNode("Extension", 0);
  667. if(!n.isEmpty()){
  668. m_sCapabilities.Device->Security->Extension = (onvifSecurityCapabilitiesExtension*) malloc(sizeof(onvifSecurityCapabilitiesExtension));
  669. if(m_sCapabilities.Device->Security->Extension!=NULL) {
  670. memset(m_sCapabilities.Device->Security->Extension, 0, sizeof(onvifSecurityCapabilitiesExtension));
  671. {
  672. XMLNode x = n.getChildNode("TLS1.0", 0);
  673. m_sCapabilities.Device->Security->Extension->TLS1_0 = checkBool(x.getText(0));
  674. }
  675. };
  676. };
  677. }
  678. };
  679. };
  680. }
  681. };
  682. };
  683. }
  684. {
  685. XMLNode t = tCaps.getChildNode("Events", 0);
  686. if( !t.isEmpty() ) {
  687. m_sCapabilities.Events = (onvifEventCapabilities *) malloc(sizeof(onvifEventCapabilities));
  688. if( m_sCapabilities.Events != NULL ) {
  689. memset( m_sCapabilities.Events, 0, sizeof(onvifEventCapabilities));
  690. {
  691. XMLNode c = t.getChildNode("XAddr", 0);
  692. sprintf(m_sCapabilities.Events->XAddr,"%s", c.getText(0));
  693. }
  694. {
  695. XMLNode c = t.getChildNode("WSSubscriptionPolicySupport", 0);
  696. m_sCapabilities.Events->WSSubscriptionPolicySupport = checkBool(c.getText(0));
  697. }
  698. {
  699. XMLNode c = t.getChildNode("WSPullPointSupport", 0);
  700. m_sCapabilities.Events->WSPullPointSupport = checkBool(c.getText(0));
  701. }
  702. {
  703. XMLNode c = t.getChildNode("WSPausableSubscriptionManagerInterfaceSupport", 0);
  704. m_sCapabilities.Events->WSPausableSubscriptionManagerInterfaceSupport = checkBool(c.getText(0));
  705. }
  706. };
  707. };
  708. }
  709. {
  710. XMLNode t = tCaps.getChildNode("Imaging", 0);
  711. if( !t.isEmpty() ) {
  712. m_sCapabilities.Imaging = (onvifImagingCapabilities *) malloc(sizeof(onvifImagingCapabilities));
  713. if( m_sCapabilities.Imaging != NULL ) {
  714. memset( m_sCapabilities.Imaging, 0, sizeof(onvifImagingCapabilities));
  715. {
  716. XMLNode c = t.getChildNode("XAddr", 0);
  717. sprintf(m_sCapabilities.Imaging->XAddr,"%s", c.getText(0));
  718. }
  719. };
  720. };
  721. }
  722. {
  723. XMLNode t = tCaps.getChildNode("Media", 0);
  724. if( !t.isEmpty() ) {
  725. m_sCapabilities.Media = (onvifMediaCapabilities *) malloc(sizeof(onvifMediaCapabilities));
  726. if( m_sCapabilities.Media != NULL ) {
  727. memset( m_sCapabilities.Media, 0, sizeof(onvifMediaCapabilities));
  728. {
  729. XMLNode c = t.getChildNode("XAddr", 0);
  730. sprintf(m_sCapabilities.Media->XAddr,"%s", c.getText(0));
  731. }
  732. {
  733. XMLNode c = t.getChildNode("StreamingCapabilities", 0);
  734. if( !c.isEmpty() ) {
  735. m_sCapabilities.Media->StreamingCapabilities = (onvifRealTimeStreamingCapabilities*) malloc(sizeof(onvifRealTimeStreamingCapabilities));
  736. if(m_sCapabilities.Media->StreamingCapabilities!=NULL) {
  737. memset(m_sCapabilities.Media->StreamingCapabilities, 0, sizeof(onvifRealTimeStreamingCapabilities));
  738. {
  739. XMLNode n = c.getChildNode("RTPMulticast", 0);
  740. m_sCapabilities.Media->StreamingCapabilities->RTPMulticast = checkBool(n.getText(0));
  741. }
  742. {
  743. XMLNode n = c.getChildNode("RTP_TCP", 0);
  744. m_sCapabilities.Media->StreamingCapabilities->RTP_TCP = checkBool(n.getText(0));
  745. }
  746. {
  747. XMLNode n = c.getChildNode("RTP_RTSP_TCP", 0);
  748. m_sCapabilities.Media->StreamingCapabilities->RTP_RTSP_TCP = checkBool(n.getText(0));
  749. }
  750. };
  751. };
  752. }
  753. {
  754. XMLNode c = t.getChildNode("Extension", 0);
  755. if( !c.isEmpty() ) {
  756. m_sCapabilities.Media->Extension = (onvifMediaCapabilitiesExtension*) malloc(sizeof(onvifMediaCapabilitiesExtension));
  757. if(m_sCapabilities.Media->Extension!=NULL) {
  758. memset(m_sCapabilities.Media->Extension, 0, sizeof(onvifMediaCapabilitiesExtension));
  759. {
  760. XMLNode n = c.getChildNode("ProfileCapabilities", 0);
  761. if(!n.isEmpty()){
  762. m_sCapabilities.Media->Extension->ProfileCapabilities = (onvifProfileCapabilities*) malloc(sizeof(onvifProfileCapabilities));
  763. if(m_sCapabilities.Media->Extension->ProfileCapabilities!=NULL) {
  764. memset(m_sCapabilities.Media->Extension->ProfileCapabilities, 0, sizeof(onvifProfileCapabilities));
  765. {
  766. XMLNode x = n.getChildNode("MaximumNumberOfProfiles", 0);
  767. m_sCapabilities.Media->Extension->ProfileCapabilities->MaximumNumberOfProfiles = atoi(x.getText(0));
  768. }
  769. };
  770. };
  771. }
  772. };
  773. };
  774. }
  775. };
  776. };
  777. }
  778. {
  779. XMLNode t = tCaps.getChildNode("PTZ", 0);
  780. if( !t.isEmpty() ) {
  781. m_sCapabilities.PTZ = (onvifPTZCapabilities *) malloc(sizeof(onvifPTZCapabilities));
  782. if( m_sCapabilities.PTZ != NULL ) {
  783. memset( m_sCapabilities.PTZ, 0, sizeof(onvifPTZCapabilities));
  784. {
  785. XMLNode c = t.getChildNode("XAddr", 0);
  786. sprintf(m_sCapabilities.PTZ->XAddr,"%s", c.getText(0));
  787. }
  788. };
  789. };
  790. }
  791. {
  792. XMLNode t = tCaps.getChildNode("Extension", 0);
  793. if( !t.isEmpty() ) {
  794. m_sCapabilities.Extension = (onvifCapabilitiesExtension *) malloc(sizeof(onvifCapabilitiesExtension));
  795. if( m_sCapabilities.Extension != NULL ) {
  796. memset( m_sCapabilities.Extension, 0, sizeof(onvifCapabilitiesExtension));
  797. {
  798. XMLNode c = t.getChildNode("DeviceIO", 0);
  799. if( !c.isEmpty() ) {
  800. m_sCapabilities.Extension->DeviceIO = (onvifDeviceIOCapabilities*) malloc(sizeof(onvifDeviceIOCapabilities));
  801. if(m_sCapabilities.Extension->DeviceIO!=NULL) {
  802. memset(m_sCapabilities.Extension->DeviceIO, 0, sizeof(onvifDeviceIOCapabilities));
  803. {
  804. XMLNode n = c.getChildNode("XAddr", 0);
  805. sprintf(m_sCapabilities.Extension->DeviceIO->XAddr, "%s", n.getText(0));
  806. }
  807. {
  808. XMLNode n = c.getChildNode("VideoSources", 0);
  809. m_sCapabilities.Extension->DeviceIO->VideoSources = atoi(n.getText(0));
  810. }
  811. {
  812. XMLNode n = c.getChildNode("VideoOutputs", 0);
  813. m_sCapabilities.Extension->DeviceIO->VideoOutputs = atoi(n.getText(0));
  814. }
  815. {
  816. XMLNode n = c.getChildNode("AudioSources", 0);
  817. m_sCapabilities.Extension->DeviceIO->AudioSources = atoi(n.getText(0));
  818. }
  819. {
  820. XMLNode n = c.getChildNode("AudioOutputs", 0);
  821. m_sCapabilities.Extension->DeviceIO->AudioOutputs = atoi(n.getText(0));
  822. }
  823. {
  824. XMLNode n = c.getChildNode("RelayOutputs", 0);
  825. m_sCapabilities.Extension->DeviceIO->RelayOutputs = atoi(n.getText(0));
  826. }
  827. };
  828. };
  829. }
  830. {
  831. XMLNode c = t.getChildNode("Display", 0);
  832. if( !c.isEmpty() ) {
  833. m_sCapabilities.Extension->Display = (onvifDisplayCapabilities*) malloc(sizeof(onvifDisplayCapabilities));
  834. if(m_sCapabilities.Extension->Display!=NULL) {
  835. memset(m_sCapabilities.Extension->Display, 0, sizeof(onvifDisplayCapabilities));
  836. {
  837. XMLNode n = c.getChildNode("XAddr", 0);
  838. sprintf(m_sCapabilities.Extension->Display->XAddr, "%s", n.getText(0));
  839. }
  840. {
  841. XMLNode n = c.getChildNode("FixedLayout", 0);
  842. m_sCapabilities.Extension->Display->FixedLayout = checkBool(n.getText(0));
  843. }
  844. };
  845. };
  846. }
  847. {
  848. XMLNode c = t.getChildNode("Recording", 0);
  849. if( !c.isEmpty() ) {
  850. m_sCapabilities.Extension->Recording = (onvifRecordingCapabilities*) malloc(sizeof(onvifRecordingCapabilities));
  851. if(m_sCapabilities.Extension->Recording!=NULL) {
  852. memset(m_sCapabilities.Extension->Recording, 0, sizeof(onvifRecordingCapabilities));
  853. {
  854. XMLNode n = c.getChildNode("XAddr", 0);
  855. sprintf(m_sCapabilities.Extension->Recording->XAddr, "%s", n.getText(0));
  856. }
  857. {
  858. XMLNode n = c.getChildNode("ReceiverSource", 0);
  859. m_sCapabilities.Extension->Recording->ReceiverSource = checkBool(n.getText(0));
  860. }
  861. {
  862. XMLNode n = c.getChildNode("MediaProfileSource", 0);
  863. m_sCapabilities.Extension->Recording->MediaProfileSource = checkBool(n.getText(0));
  864. }
  865. {
  866. XMLNode n = c.getChildNode("DynamicRecordings", 0);
  867. m_sCapabilities.Extension->Recording->DynamicRecordings = checkBool(n.getText(0));
  868. }
  869. {
  870. XMLNode n = c.getChildNode("DynamicTracks", 0);
  871. m_sCapabilities.Extension->Recording->DynamicTracks = checkBool(n.getText(0));
  872. }
  873. {
  874. XMLNode n = c.getChildNode("MaxStringLength", 0);
  875. m_sCapabilities.Extension->Recording->MaxStringLength = atoi(n.getText(0));
  876. }
  877. };
  878. };
  879. }
  880. {
  881. XMLNode c = t.getChildNode("Search", 0);
  882. if( !c.isEmpty() ) {
  883. m_sCapabilities.Extension->Search = (onvifSearchCapabilities*) malloc(sizeof(onvifSearchCapabilities));
  884. if(m_sCapabilities.Extension->Search!=NULL) {
  885. memset(m_sCapabilities.Extension->Search, 0, sizeof(onvifSearchCapabilities));
  886. {
  887. XMLNode n = c.getChildNode("XAddr", 0);
  888. sprintf(m_sCapabilities.Extension->Search->XAddr, "%s", n.getText(0));
  889. }
  890. {
  891. XMLNode n = c.getChildNode("MetadataSearch", 0);
  892. m_sCapabilities.Extension->Search->MetadataSearch = checkBool(n.getText(0));
  893. }
  894. };
  895. };
  896. }
  897. {
  898. XMLNode c = t.getChildNode("Replay", 0);
  899. if( !c.isEmpty() ) {
  900. m_sCapabilities.Extension->Replay = (onvifReplayCapabilities*) malloc(sizeof(onvifReplayCapabilities));
  901. if(m_sCapabilities.Extension->Replay!=NULL) {
  902. memset(m_sCapabilities.Extension->Replay, 0, sizeof(onvifReplayCapabilities));
  903. {
  904. XMLNode n = c.getChildNode("XAddr", 0);
  905. sprintf(m_sCapabilities.Extension->Replay->XAddr, "%s", n.getText(0));
  906. }
  907. };
  908. };
  909. }
  910. {
  911. XMLNode c = t.getChildNode("Receiver", 0);
  912. if( !c.isEmpty() ) {
  913. m_sCapabilities.Extension->Receiver = (onvifReceiverCapabilities*) malloc(sizeof(onvifReceiverCapabilities));
  914. if(m_sCapabilities.Extension->Receiver!=NULL) {
  915. memset(m_sCapabilities.Extension->Receiver, 0, sizeof(onvifReceiverCapabilities));
  916. {
  917. XMLNode n = c.getChildNode("XAddr", 0);
  918. sprintf(m_sCapabilities.Extension->Receiver->XAddr, "%s", n.getText(0));
  919. }
  920. {
  921. XMLNode n = c.getChildNode("RTP_Multicast", 0);
  922. m_sCapabilities.Extension->Receiver->RTP_Multicast = checkBool(n.getText(0));
  923. }
  924. {
  925. XMLNode n = c.getChildNode("RTP_TCP", 0);
  926. m_sCapabilities.Extension->Receiver->RTP_TCP = checkBool(n.getText(0));
  927. }
  928. {
  929. XMLNode n = c.getChildNode("RTP_RTSP_TCP", 0);
  930. m_sCapabilities.Extension->Receiver->RTP_RTSP_TCP = checkBool(n.getText(0));
  931. }
  932. {
  933. XMLNode n = c.getChildNode("SupportedReceivers", 0);
  934. m_sCapabilities.Extension->Receiver->SupportedReceivers = atoi(n.getText(0));
  935. }
  936. {
  937. XMLNode n = c.getChildNode("MaximumRTSPURILength", 0);
  938. m_sCapabilities.Extension->Receiver->MaximumRTSPURILength = atoi(n.getText(0));
  939. }
  940. };
  941. };
  942. }
  943. {
  944. XMLNode c = t.getChildNode("AnalyticsDevice", 0);
  945. if( !c.isEmpty() ) {
  946. m_sCapabilities.Extension->AnalyticsDevice = (onvifAnalyticsDeviceCapabilities*) malloc(sizeof(onvifAnalyticsDeviceCapabilities));
  947. if(m_sCapabilities.Extension->AnalyticsDevice!=NULL) {
  948. memset(m_sCapabilities.Extension->AnalyticsDevice, 0, sizeof(onvifAnalyticsDeviceCapabilities));
  949. {
  950. XMLNode n = c.getChildNode("XAddr", 0);
  951. sprintf(m_sCapabilities.Extension->AnalyticsDevice->XAddr, "%s", n.getText(0));
  952. }
  953. {
  954. XMLNode n = c.getChildNode("RuleSupport", 0);
  955. m_sCapabilities.Extension->AnalyticsDevice->RuleSupport = checkBool(n.getText(0));
  956. }
  957. };
  958. };
  959. }
  960. };
  961. };
  962. }
  963. return true;
  964. } else {
  965. LOG("Capabilities is Empty!");
  966. };
  967. } else {
  968. LOG("GetCapabilitiesResponse is Empty!");
  969. };
  970. };
  971. }
  972. return false;
  973. };
  974. // based on https://www.onvif.org/ver20/imaging/wsdl/imaging.wsdl
  975. bool pOnvif::media_GetVideoSources( void ){
  976. if( m_pMediaURI==NULL ) return false;
  977. char tBuffer[DEFAULT_BUFFER_SIZE];
  978. accessToken tTOKEN;
  979. tTOKEN = _makeToken();
  980. sprintf( tBuffer, PONVIF_PACK_GET_VIDEO_SOURCES, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP );
  981. if( _send_request( m_pMediaURI, tBuffer ) ){
  982. XMLResults tParseResults;
  983. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  984. #ifdef DEBUG_ONVIF_PRINTOUT_MESSAGES
  985. LOG("RCPT:");
  986. printf(m_pLastResponse);
  987. #endif
  988. if( tParseResults.error ){
  989. char tBuf[CTEXT];
  990. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  991. LOG_ERROR( tBuf );
  992. } else {
  993. XMLNode zNode = response.getChildNode("Body", 0);
  994. if( zNode.isEmpty() ) return false;
  995. XMLNode tNode = zNode.getChildNode("GetVideoSourcesResponse", 0);
  996. if( !tNode.isEmpty() ) {
  997. for( int index = 0; index < tNode.nChildNode(); index++ ){
  998. XMLNode cNode = tNode.getChildNode("VideoSources", index );
  999. if(!cNode.isEmpty()) {
  1000. videoSource *tPtr;
  1001. tPtr = (videoSource*) malloc(sizeof(videoSource));
  1002. if( tPtr != NULL ) {
  1003. sprintf( tPtr->token, "%s", cNode.getAttribute("token",0));
  1004. {
  1005. XMLNode nNode = cNode.getChildNode("Framerate", 0 );
  1006. tPtr->Framerate = (float)atof( nNode.getText(0));
  1007. }
  1008. {
  1009. XMLNode nNode = cNode.getChildNode("Resolution", 0 );
  1010. if( !nNode.isEmpty() ) {
  1011. {
  1012. XMLNode xNode = nNode.getChildNode("Width", 0 );
  1013. tPtr->Resolution.Width = atoi(xNode.getText(0));
  1014. }
  1015. {
  1016. XMLNode xNode = nNode.getChildNode("Height", 0 );
  1017. tPtr->Resolution.Height = atoi(xNode.getText(0));
  1018. }
  1019. };
  1020. }
  1021. {
  1022. XMLNode nNode = cNode.getChildNode("Imaging", 0 );
  1023. if( !nNode.isEmpty() ) {
  1024. tPtr->Imaging = (onvifImagingSettings*) malloc(sizeof(onvifImagingSettings));
  1025. if( tPtr->Imaging != NULL) {
  1026. memset(tPtr->Imaging, 0, sizeof(onvifImagingSettings));
  1027. {
  1028. XMLNode xNode = nNode.getChildNode("BacklightCompensation", 0 );
  1029. if(!xNode.isEmpty()) {
  1030. tPtr->Imaging->BacklightCompensation = (onvifBacklightCompensation*)malloc(sizeof(onvifBacklightCompensation));
  1031. if(tPtr->Imaging->BacklightCompensation!=NULL) {
  1032. memset(tPtr->Imaging->BacklightCompensation, 0, sizeof(onvifBacklightCompensation));
  1033. {
  1034. XMLNode rNode = xNode.getChildNode("Mode", 0 );
  1035. tPtr->Imaging->BacklightCompensation->Mode = checkOnOff(rNode.getText(0));
  1036. }
  1037. {
  1038. XMLNode rNode = xNode.getChildNode("Level", 0 );
  1039. tPtr->Imaging->BacklightCompensation->Level = (float)atof(rNode.getText(0));
  1040. }
  1041. };
  1042. };
  1043. }
  1044. {
  1045. XMLNode xNode = nNode.getChildNode("Brightness", 0 );
  1046. tPtr->Imaging->Brightness = (float)atoi(xNode.getText(0));
  1047. }
  1048. {
  1049. XMLNode xNode = nNode.getChildNode("ColorSaturation", 0 );
  1050. tPtr->Imaging->ColorSaturation = (float)atoi(xNode.getText(0));
  1051. }
  1052. {
  1053. XMLNode xNode = nNode.getChildNode("Contrast", 0 );
  1054. tPtr->Imaging->Contrast = (float)atoi(xNode.getText(0));
  1055. }
  1056. {
  1057. XMLNode xNode = nNode.getChildNode("Sharpness", 0 );
  1058. tPtr->Imaging->Sharpness = (float)atoi(xNode.getText(0));
  1059. }
  1060. {
  1061. XMLNode xNode = nNode.getChildNode("IrCutFilter", 0 );
  1062. tPtr->Imaging->IrCutFilter = checkOnOffAuto(xNode.getText(0));
  1063. }
  1064. };
  1065. };
  1066. }
  1067. m_vVideoSources.push_back( tPtr );
  1068. };
  1069. };
  1070. };
  1071. return true;
  1072. } else {
  1073. LOG_ERROR("GetVideoSourcesResponse EMPTY!");
  1074. };
  1075. };
  1076. } else {
  1077. LOG_ERROR( "_send_request Failure!" );
  1078. };
  1079. return false;
  1080. };
  1081. bool pOnvif::media_GetProfiles( void ){
  1082. char tBuffer[DEFAULT_BUFFER_SIZE];
  1083. accessToken tTOKEN;
  1084. tTOKEN = _makeToken();
  1085. sprintf( tBuffer, PONVIF_PACK_GET_PROFILES, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP );
  1086. if( _send_request( m_pMediaURI, tBuffer ) ){
  1087. XMLResults tParseResults;
  1088. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1089. #ifdef DEBUG_ONVIF_PRINTOUT_MESSAGES
  1090. LOG("RCPT:");
  1091. printf(m_pLastResponse);
  1092. #endif
  1093. if( tParseResults.error ){
  1094. char tBuf[CTEXT];
  1095. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1096. LOG_ERROR( tBuf );
  1097. } else {
  1098. XMLNode zNode = response.getChildNode("Body", 0);
  1099. if( zNode.isEmpty() ) return false;
  1100. XMLNode tNode = zNode.getChildNode("GetProfilesResponse", 0);
  1101. if( !tNode.isEmpty() ) {
  1102. for( int index = 0; index < tNode.nChildNode(); index++ ){
  1103. XMLNode cNode = tNode.getChildNode("Profiles", index );
  1104. if(!cNode.isEmpty()) {
  1105. videoSourceProfile *tPtr;
  1106. tPtr = (videoSourceProfile*) malloc(sizeof(videoSourceProfile));
  1107. if( tPtr != NULL ) {
  1108. memset(tPtr, 0, sizeof(videoSourceProfile));
  1109. sprintf(tPtr->profiletoken, "%s", cNode.getAttribute("token",0));
  1110. {
  1111. XMLNode nNode = cNode.getChildNode("Name", 0 );
  1112. sprintf(tPtr->profilename, "%s", nNode.getText(0));
  1113. }
  1114. {
  1115. XMLNode nNode = cNode.getChildNode("VideoSourceConfiguration", 0 );
  1116. if(!nNode.isEmpty()) {
  1117. XMLNode zNode = nNode.getChildNode("SourceToken", 0 );
  1118. sprintf(tPtr->sourcetoken, "%s", zNode.getText(0));
  1119. };
  1120. }
  1121. {
  1122. XMLNode nNode = cNode.getChildNode("VideoEncoderConfiguration", 0 );
  1123. if(!nNode.isEmpty()) {
  1124. {
  1125. XMLNode zNode = nNode.getChildNode("Encoding", 0 );
  1126. sprintf(tPtr->encoding, "%s", zNode.getText(0));
  1127. }
  1128. {
  1129. XMLNode zNode = nNode.getChildNode("Resolution", 0 );
  1130. {
  1131. XMLNode jNode = zNode.getChildNode("Width", 0 );
  1132. tPtr->width = atoi(jNode.getText(0));
  1133. }
  1134. {
  1135. XMLNode jNode = zNode.getChildNode("Height", 0 );
  1136. tPtr->height = atoi(jNode.getText(0));
  1137. }
  1138. }
  1139. {
  1140. XMLNode zNode = nNode.getChildNode("RateControl", 0 );
  1141. {
  1142. XMLNode jNode = zNode.getChildNode("FrameRateLimit", 0 );
  1143. tPtr->fps = atoi(jNode.getText(0));
  1144. }
  1145. {
  1146. XMLNode jNode = zNode.getChildNode("BitrateLimit", 0 );
  1147. tPtr->bitrate = atoi(jNode.getText(0));
  1148. }
  1149. }
  1150. };
  1151. }
  1152. m_vVideoProfiles.push_back(tPtr);
  1153. };
  1154. };
  1155. };
  1156. return true;
  1157. };
  1158. };
  1159. };
  1160. return false;
  1161. };
  1162. bool pOnvif::media_GetServices( void ){
  1163. char tBuffer[DEFAULT_BUFFER_SIZE];
  1164. accessToken tTOKEN;
  1165. tTOKEN = _makeToken();
  1166. sprintf( tBuffer, PONVIF_PACK_GET_SERVICES, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP );
  1167. if( _send_request( m_pMediaURI, tBuffer ) ){
  1168. XMLResults tParseResults;
  1169. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1170. LOG("RCPT:");
  1171. printf(m_pLastResponse);
  1172. if( tParseResults.error ){
  1173. char tBuf[CTEXT];
  1174. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1175. LOG_ERROR( tBuf );
  1176. } else {
  1177. };
  1178. };
  1179. return false;
  1180. };
  1181. bool pOnvif::core_GetDeviceInformation() {
  1182. char tBuffer[DEFAULT_BUFFER_SIZE];
  1183. accessToken tTOKEN;
  1184. tTOKEN = _makeToken();
  1185. sprintf( tBuffer, PONVIF_PACK_GET_DEV_INFO, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP );
  1186. if( _send_request( m_pMediaURI, tBuffer ) ){
  1187. XMLResults tParseResults;
  1188. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1189. LOG("RCPT:");
  1190. printf(m_pLastResponse);
  1191. if( tParseResults.error ){
  1192. char tBuf[CTEXT];
  1193. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1194. LOG_ERROR( tBuf );
  1195. } else {
  1196. //return $response['Envelope']['Body']['GetDeviceInformationResponse'];
  1197. };
  1198. };
  1199. return false;
  1200. };
  1201. CSTR pOnvif::media_GetStreamUri( CSTR profileToken, CSTR stream, CSTR protocol ){
  1202. char tBuffer[DEFAULT_BUFFER_SIZE];
  1203. accessToken tTOKEN;
  1204. tTOKEN = _makeToken();
  1205. sprintf( tBuffer, PONVIF_PACK_GET_STREAM_URI, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, stream, protocol );
  1206. if( _send_request( m_pMediaURI, tBuffer ) ){
  1207. XMLResults tParseResults;
  1208. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1209. LOG("RCPT:");
  1210. printf(m_pLastResponse);
  1211. if( tParseResults.error ){
  1212. char tBuf[CTEXT];
  1213. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1214. LOG_ERROR( tBuf );
  1215. } else {
  1216. // Parse
  1217. //return $response['Envelope']['Body']['GetStreamUriResponse']['MediaUri']['Uri'];
  1218. };
  1219. };
  1220. return NULL;
  1221. };
  1222. CSTR pOnvif::media_GetSnapshotUri( CSTR profileToken ){
  1223. char tBuffer[DEFAULT_BUFFER_SIZE];
  1224. accessToken tTOKEN;
  1225. tTOKEN = _makeToken();
  1226. sprintf( tBuffer, PONVIF_PACK_GET_PICTURE_URI, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken );
  1227. if( _send_request( m_pMediaURI, tBuffer ) ){
  1228. XMLResults tParseResults;
  1229. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1230. LOG("RCPT:");
  1231. printf(m_pLastResponse);
  1232. if( tParseResults.error ){
  1233. char tBuf[CTEXT];
  1234. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1235. LOG_ERROR( tBuf );
  1236. } else {
  1237. //Parse
  1238. //return $response['Envelope']['Body']['GetSnapshotUriResponse']['MediaUri']['Uri'];
  1239. };
  1240. };
  1241. return NULL;
  1242. };
  1243. bool pOnvif::ptz_GetStatus( CSTR profileToken ){
  1244. if( m_pPTZURI==NULL ) return false;
  1245. char tBuffer[DEFAULT_BUFFER_SIZE];
  1246. accessToken tTOKEN;
  1247. tTOKEN = _makeToken();
  1248. sprintf( tBuffer, PONVIF_PACK_GET_PTZ_STATUS, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken );
  1249. if( _send_request( m_pPTZURI, tBuffer ) ){
  1250. XMLResults tParseResults;
  1251. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1252. LOG("RCPT:");
  1253. printf(m_pLastResponse);
  1254. if( tParseResults.error ){
  1255. char tBuf[CTEXT];
  1256. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1257. LOG_ERROR( tBuf );
  1258. } else {
  1259. XMLNode zNode = response.getChildNode("Body", 0);
  1260. if( zNode.isEmpty() ) return false;
  1261. XMLNode tNode = zNode.getChildNode("GetStatusResponse", 0);
  1262. if( !tNode.isEmpty() ) {
  1263. XMLNode cNode = tNode.getChildNode("PTZStatus", 0 );
  1264. if(!cNode.isEmpty()) {
  1265. videoSourceProfile *tPtr;
  1266. tPtr = (videoSourceProfile*) malloc(sizeof(videoSourceProfile));
  1267. if( tPtr != NULL ) {
  1268. };
  1269. };
  1270. };
  1271. };
  1272. };
  1273. return false;
  1274. };
  1275. bool pOnvif::ptz_GetPresets( CSTR profileToken ){
  1276. if( m_pPTZURI==NULL ) return false;
  1277. char tBuffer[DEFAULT_BUFFER_SIZE];
  1278. accessToken tTOKEN;
  1279. tTOKEN = _makeToken();
  1280. sprintf( tBuffer, PONVIF_PACK_GET_PRESETS, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken );
  1281. if( _send_request( m_pPTZURI, tBuffer ) ){
  1282. XMLResults tParseResults;
  1283. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1284. LOG("RCPT:");
  1285. printf(m_pLastResponse);
  1286. if( tParseResults.error ){
  1287. char tBuf[CTEXT];
  1288. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1289. LOG_ERROR( tBuf );
  1290. } else {
  1291. //$getpresetsresponse=$response['Envelope']['Body']['GetPresetsResponse']['Preset'];
  1292. //$presets=array();
  1293. //foreach ($getpresetsresponse as $preset) {
  1294. // $presets[]=array('Token'=>$preset['@attributes']['token'],
  1295. // 'Name'=>$preset['Name'],
  1296. // 'PTZPosition'=>$preset['PTZPosition']);
  1297. //}
  1298. //return $presets;
  1299. };
  1300. };
  1301. return false;
  1302. };
  1303. bool pOnvif::ptz_GetNode( CSTR ptzNodeToken ) {
  1304. if( m_pPTZURI == NULL ) return false;
  1305. char tBuffer[DEFAULT_BUFFER_SIZE];
  1306. accessToken tTOKEN;
  1307. tTOKEN = _makeToken();
  1308. sprintf( tBuffer, PONVIF_PACK_GET_PTZ_NODE, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, ptzNodeToken );
  1309. if( _send_request( m_pPTZURI, tBuffer ) ){
  1310. XMLResults tParseResults;
  1311. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1312. LOG("RCPT:");
  1313. printf(m_pLastResponse);
  1314. if( tParseResults.error ){
  1315. char tBuf[CTEXT];
  1316. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1317. LOG_ERROR( tBuf );
  1318. } else {
  1319. //return $response['Envelope']['Body']['GetNodeResponse'];
  1320. };
  1321. };
  1322. return false;
  1323. };
  1324. bool pOnvif::ptz_GotoPreset( CSTR profileToken, CSTR presetToken, float speed_pantilt_x, float speed_pantilt_y, float speed_zoom_x ){
  1325. if( m_pPTZURI == NULL ) return false;
  1326. char tBuffer[DEFAULT_BUFFER_SIZE];
  1327. accessToken tTOKEN;
  1328. tTOKEN = _makeToken();
  1329. 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 );
  1330. if( _send_request( m_pPTZURI, tBuffer ) ){
  1331. XMLResults tParseResults;
  1332. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1333. LOG("RCPT:");
  1334. printf(m_pLastResponse);
  1335. if( tParseResults.error ){
  1336. char tBuf[CTEXT];
  1337. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1338. LOG_ERROR( tBuf );
  1339. } else return true;
  1340. };
  1341. return false;
  1342. };
  1343. bool pOnvif::ptz_RemovePreset( CSTR profileToken, CSTR presetToken ){
  1344. if( m_pPTZURI == NULL ) return false;
  1345. char tBuffer[DEFAULT_BUFFER_SIZE];
  1346. accessToken tTOKEN;
  1347. tTOKEN = _makeToken();
  1348. sprintf( tBuffer, PONVIF_PACK_REMOVE_PRESET, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, presetToken );
  1349. if( _send_request( m_pPTZURI, tBuffer ) ){
  1350. XMLResults tParseResults;
  1351. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1352. LOG("RCPT:");
  1353. printf(m_pLastResponse);
  1354. if( tParseResults.error ){
  1355. char tBuf[CTEXT];
  1356. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1357. LOG_ERROR( tBuf );
  1358. } else return true;
  1359. };
  1360. return false;
  1361. };
  1362. bool pOnvif::ptz_SetPreset( CSTR profileToken, CSTR presetName ){
  1363. if( m_pPTZURI == NULL ) return false;
  1364. char tBuffer[DEFAULT_BUFFER_SIZE];
  1365. accessToken tTOKEN;
  1366. tTOKEN = _makeToken();
  1367. sprintf( tBuffer, PONVIF_PACK_SET_PRESET, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, presetName );
  1368. if( _send_request( m_pPTZURI, tBuffer ) ){
  1369. XMLResults tParseResults;
  1370. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1371. LOG("RCPT:");
  1372. printf(m_pLastResponse);
  1373. if( tParseResults.error ){
  1374. char tBuf[CTEXT];
  1375. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1376. LOG_ERROR( tBuf );
  1377. } else return true;
  1378. };
  1379. return false;
  1380. };
  1381. bool pOnvif::ptz_RelativeMove( CSTR profileToken, float translation_pantilt_x, float translation_pantilt_y, float speed_pantilt_x, float speed_pantilt_y ){
  1382. if( m_pPTZURI == NULL ) return false;
  1383. char tBuffer[DEFAULT_BUFFER_SIZE];
  1384. accessToken tTOKEN;
  1385. tTOKEN = _makeToken();
  1386. 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 );
  1387. if( _send_request( m_pPTZURI, tBuffer ) ){
  1388. XMLResults tParseResults;
  1389. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1390. LOG("RCPT:");
  1391. printf(m_pLastResponse);
  1392. if( tParseResults.error ){
  1393. char tBuf[CTEXT];
  1394. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1395. LOG_ERROR( tBuf );
  1396. } else return true;
  1397. };
  1398. return false;
  1399. };
  1400. bool pOnvif::ptz_RelativeMoveZoom( CSTR profileToken, float zoom, float speedZoom ){
  1401. if( m_pPTZURI == NULL ) return false;
  1402. char tBuffer[DEFAULT_BUFFER_SIZE];
  1403. accessToken tTOKEN;
  1404. tTOKEN = _makeToken();
  1405. sprintf( tBuffer, PONVIF_PACK_RELATIVE_ZOOM, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, zoom, speedZoom );
  1406. if( _send_request( m_pPTZURI, tBuffer ) ){
  1407. XMLResults tParseResults;
  1408. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1409. LOG("RCPT:");
  1410. LOG( m_pLastResponse );
  1411. if( tParseResults.error ){
  1412. char tBuf[CTEXT];
  1413. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1414. LOG_ERROR( tBuf );
  1415. } else return true;
  1416. };
  1417. return false;
  1418. };
  1419. bool pOnvif::ptz_AbsoluteMove( CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom ){
  1420. if( m_pPTZURI == NULL ) return false;
  1421. char tBuffer[DEFAULT_BUFFER_SIZE];
  1422. accessToken tTOKEN;
  1423. tTOKEN = _makeToken();
  1424. sprintf( tBuffer, PONVIF_PACK_ABSOLUTE_MOVE, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, position_pantilt_x, position_pantilt_y, zoom );
  1425. #ifdef DEBUG_ONVIF_TRAFFIC
  1426. FILE *tf;
  1427. tf = fopen("Traffic.txt", "a+");
  1428. fprintf( tf, "%s\n", tBuffer );
  1429. #endif
  1430. if( _send_request( m_pPTZURI, tBuffer ) ){
  1431. XMLResults tParseResults;
  1432. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1433. #ifdef DEBUG_ONVIF_TRAFFIC
  1434. fprintf( tf, "%s\n", m_pLastResponse );
  1435. #endif
  1436. if( tParseResults.error ){
  1437. char tBuf[CTEXT];
  1438. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1439. LOG_ERROR( tBuf );
  1440. } else {
  1441. #ifdef DEBUG_ONVIF_TRAFFIC
  1442. fclose( tf );
  1443. #endif
  1444. return true;
  1445. };
  1446. };
  1447. #ifdef DEBUG_ONVIF_TRAFFIC
  1448. fclose(tf);
  1449. #endif
  1450. return false;
  1451. };
  1452. bool pOnvif::ptz_ContinuousMove( CSTR profileToken, float velocity_pantilt_x, float velocity_pantilt_y ){
  1453. if( m_pPTZURI == NULL ) return false;
  1454. char tBuffer[DEFAULT_BUFFER_SIZE];
  1455. accessToken tTOKEN;
  1456. tTOKEN = _makeToken();
  1457. sprintf( tBuffer, PONVIF_PACK_CONTINUOUS_MOVE, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, velocity_pantilt_x, velocity_pantilt_y );
  1458. if( _send_request( m_pMediaURI, tBuffer ) ){
  1459. XMLResults tParseResults;
  1460. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1461. LOG("RCPT:");
  1462. printf(m_pLastResponse);
  1463. if( tParseResults.error ){
  1464. char tBuf[CTEXT];
  1465. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1466. LOG_ERROR( tBuf );
  1467. } else return true;
  1468. };
  1469. return false;
  1470. };
  1471. bool pOnvif::ptz_ContinuousMoveZoom( CSTR profileToken, float zoom ){
  1472. if( m_pPTZURI == NULL ) return false;
  1473. char tBuffer[DEFAULT_BUFFER_SIZE];
  1474. accessToken tTOKEN;
  1475. tTOKEN = _makeToken();
  1476. sprintf( tBuffer, PONVIF_PACK_CONTINUOUS_ZOOM, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, zoom );
  1477. if( _send_request( m_pMediaURI, tBuffer ) ){
  1478. XMLResults tParseResults;
  1479. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1480. LOG("RCPT:");
  1481. printf(m_pLastResponse);
  1482. if( tParseResults.error ){
  1483. char tBuf[CTEXT];
  1484. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1485. LOG_ERROR( tBuf );
  1486. } else return true;
  1487. };
  1488. return false;
  1489. };
  1490. bool pOnvif::ptz_Stop( CSTR profileToken, bool pantilt, bool zoom ){
  1491. if( m_pPTZURI == NULL ) return false;
  1492. char tBuffer[DEFAULT_BUFFER_SIZE];
  1493. accessToken tTOKEN;
  1494. tTOKEN = _makeToken();
  1495. sprintf( tBuffer, PONVIF_PACK_PTZ_STOP, tTOKEN.USERNAME, tTOKEN.PASSDIGEST, tTOKEN.NONCE, tTOKEN.TIMESTAMP, profileToken, pantilt, zoom );
  1496. if( _send_request( m_pMediaURI, tBuffer ) ){
  1497. XMLResults tParseResults;
  1498. XMLNode response = XMLNode::parseString( m_pLastResponse, "root", &tParseResults );
  1499. LOG("RCPT:");
  1500. printf(m_pLastResponse);
  1501. if( tParseResults.error ){
  1502. char tBuf[CTEXT];
  1503. sprintf( tBuf, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  1504. LOG_ERROR( tBuf );
  1505. } else return true;
  1506. };
  1507. return false;
  1508. };
  1509. /*
  1510. Internal functions
  1511. */
  1512. accessToken pOnvif::_makeToken( void ){
  1513. time_t tTS = time( NULL ) - m_nDeltaTime;
  1514. return _passwordDigest( m_pUsername, m_pPassword, tTS );
  1515. };
  1516. void pOnvif::_getOnvifVersion( nodeCapability &caps ){
  1517. if( caps.Device != NULL ) {
  1518. if( caps.Device->System != NULL ) {
  1519. if( caps.Device->System->SupportedVersions != NULL ) {
  1520. m_sOnvifVersion.Major = caps.Device->System->SupportedVersions->Major;
  1521. m_sOnvifVersion.Minor = caps.Device->System->SupportedVersions->Minor;
  1522. };
  1523. };
  1524. };
  1525. if( caps.PTZ != NULL ) {
  1526. m_pPTZURI = caps.PTZ->XAddr;
  1527. };
  1528. if( caps.Media != NULL ) {
  1529. m_pMediaURI = caps.Media->XAddr;
  1530. };
  1531. if( caps.Device != NULL ) {
  1532. m_pDeviceURI = caps.Device->XAddr;
  1533. };
  1534. };
  1535. /*
  1536. protected function _getActiveSources($videoSources,$profiles) {
  1537. $sources=array();
  1538. if (isset($videoSources['@attributes'])) {
  1539. // NVT is a camera
  1540. $sources[0]['sourcetoken']=$videoSources['@attributes']['token'];
  1541. $this->_getProfileData($sources,0,$profiles);
  1542. }
  1543. else {
  1544. // NVT is an encoder
  1545. for ($i=0;$i<count($videoSources);$i++) {
  1546. if (strtolower($videoSources[$i]['@attributes']['SignalActive'])=='true') {
  1547. $sources[$i]['sourcetoken']=$videoSources[$i]['@attributes']['token'];
  1548. $this->_getProfileData($sources,$i,$profiles);
  1549. }
  1550. } // for
  1551. }
  1552. return $sources;
  1553. }
  1554. void pOnvif::_getProfileData( sources,$i, XMLNode profiles ){
  1555. //$inprofile=0;
  1556. videoSourceProfile *tPtr;
  1557. for( $y=0; $y < count($profiles); $y++ ){
  1558. if ($profiles[$y]['VideoSourceConfiguration']['SourceToken']==$sources[$i]['sourcetoken']) {
  1559. $sources[$i][$inprofile]['profilename']=$profiles[$y]['Name'];
  1560. $sources[$i][$inprofile]['profiletoken']=$profiles[$y]['@attributes']['token'];
  1561. if ( isset($profiles[$y]['VideoEncoderConfiguration'])) {
  1562. $sources[$i][$inprofile]['encoding']=$profiles[$y]['VideoEncoderConfiguration']['Encoding'];
  1563. $sources[$i][$inprofile]['width']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Width'];
  1564. $sources[$i][$inprofile]['height']=$profiles[$y]['VideoEncoderConfiguration']['Resolution']['Height'];
  1565. $sources[$i][$inprofile]['fps']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['FrameRateLimit'];
  1566. $sources[$i][$inprofile]['bitrate']=$profiles[$y]['VideoEncoderConfiguration']['RateControl']['BitrateLimit'];
  1567. }
  1568. if ( isset($profiles[$y]['PTZConfiguration'])) {
  1569. $sources[$i][$inprofile]['ptz']['name']=$profiles[$y]['PTZConfiguration']['Name'];
  1570. $sources[$i][$inprofile]['ptz']['nodetoken']=$profiles[$y]['PTZConfiguration']['NodeToken'];
  1571. }
  1572. $inprofile++;
  1573. }
  1574. }
  1575. };
  1576. */
  1577. /*
  1578. protected function _xml2array($response) {
  1579. $sxe = new SimpleXMLElement($response);
  1580. $dom_sxe = dom_import_simplexml($sxe);
  1581. $dom = new DOMDocument('1.0');
  1582. $dom_sxe = $dom->importNode($dom_sxe, true);
  1583. $dom_sxe = $dom->appendChild($dom_sxe);
  1584. $element = $dom->childNodes->item(0);
  1585. foreach ($sxe->getDocNamespaces() as $name => $uri) {
  1586. $element->removeAttributeNS($uri, $name);
  1587. }
  1588. $xmldata=$dom->saveXML();
  1589. $xmldata=substr($xmldata,strpos($xmldata,"<Envelope>"));
  1590. $xmldata=substr($xmldata,0,strpos($xmldata,"</Envelope>")+strlen("</Envelope>"));
  1591. $xml=simplexml_load_string($xmldata);
  1592. $data=json_decode(json_encode((array)$xml),1);
  1593. $data=array($xml->getName()=>$data);
  1594. return $data;
  1595. }
  1596. */
  1597. accessToken pOnvif::_passwordDigest( CSTR username, CSTR password, time_t timestamp, uint32_t nonce ) {
  1598. accessToken RetVal;
  1599. char tTS[CTEXT];
  1600. unsigned char * tPDIGEST;
  1601. if( timestamp == 0 || 1 ){
  1602. time_t t;
  1603. struct tm * tmp;
  1604. t = time( NULL );
  1605. tmp = gmtime( &t );
  1606. if( tmp == NULL ){
  1607. LOG_ERROR("gmtime Error!");
  1608. };
  1609. if( strftime( tTS, 200, "%FT%T.000Z", tmp )==0 ){
  1610. LOG_ERROR("strftime returned 0!");
  1611. };
  1612. } else {
  1613. struct tm * tmp;
  1614. tmp = gmtime( &timestamp );
  1615. if( tmp == NULL ){
  1616. LOG_ERROR("gmtime Error!");
  1617. };
  1618. if( strftime( tTS, 200, "%FT%T.000Z", tmp )==0 ){
  1619. LOG_ERROR("strftime returned 0!");
  1620. };
  1621. };
  1622. if( nonce == 0 || 1 ){
  1623. nonce = (uint32_t) rand();
  1624. };
  1625. unsigned char tBuff[CTEXT];
  1626. int cp = 0;
  1627. int index = 0;
  1628. for( ; index < 4; index++ ) {
  1629. tBuff[cp++] = ((unsigned char *)(&nonce))[index];
  1630. };
  1631. index = 0;
  1632. while( tTS[index] != '\0' ) {
  1633. tBuff[cp++] = (unsigned char) tTS[index];
  1634. index++;
  1635. };
  1636. index = 0;
  1637. while( password[index] != '\0' ) {
  1638. tBuff[cp++] = (unsigned char) password[index];
  1639. index++;
  1640. };
  1641. size_t baseOutLen;
  1642. unsigned char tSHA[SHA_DIGEST_LENGTH];
  1643. SHA1( tBuff, cp, tSHA );
  1644. //tPDIGEST = base64_encode(pack('H*', sha1(pack('H*', $nonce) . pack('a*',$timestamp).pack('a*',$password))));
  1645. tPDIGEST = base64_encode( tSHA, SHA_DIGEST_LENGTH, &baseOutLen );
  1646. //free( tSHA );
  1647. //$passdigest=base64_encode(sha1($nonce.$timestamp.$password,true)); // alternative
  1648. strncpy( RetVal.USERNAME, username, CTEXT );
  1649. strncpy( RetVal.TIMESTAMP, tTS, CTEXT );
  1650. strncpy( RetVal.PASSDIGEST, (const char*)tPDIGEST, CTEXT );
  1651. free( tPDIGEST );
  1652. tPDIGEST = base64_encode( (unsigned char *)&nonce, 4 , &baseOutLen );
  1653. strncpy( RetVal.NONCE, (const char*)tPDIGEST, baseOutLen );
  1654. RetVal.NONCE[baseOutLen] = '\0';
  1655. free( tPDIGEST );
  1656. //$REQ['NONCE']=base64_encode($nonce); // alternative
  1657. return RetVal;
  1658. }
  1659. bool pOnvif::_send_request( CSTR url, CSTR post_string ){
  1660. char tBuffer[CTEXT];
  1661. if( m_pCURL == NULL ) {
  1662. if( m_pLastResponse == NULL ){
  1663. m_pLastResponse = (CSTR) malloc(DEFAULT_BUFFER_SIZE);
  1664. };
  1665. m_pCURL = curl_easy_init();
  1666. if( m_pProxyHost!= NULL && m_nProxyPort!= 0 ){
  1667. curl_easy_setopt( m_pCURL, CURLOPT_PROXY, m_pProxyHost );
  1668. curl_easy_setopt( m_pCURL, CURLOPT_PROXYPORT, m_nProxyPort );
  1669. if( m_pProxyUsername != NULL && m_pProxyPassword != NULL ){
  1670. sprintf( tBuffer,"%s:%s", m_pProxyUsername, m_pProxyPassword );
  1671. curl_easy_setopt( m_pCURL, CURLOPT_PROXYUSERPWD, tBuffer );
  1672. };
  1673. };
  1674. curl_easy_setopt( m_pCURL, CURLOPT_CONNECTTIMEOUT, 10);
  1675. curl_easy_setopt( m_pCURL, CURLOPT_TIMEOUT, 10);
  1676. curl_easy_setopt( m_pCURL, CURLOPT_SSL_VERIFYPEER, false );
  1677. curl_easy_setopt( m_pCURL, CURLOPT_SSL_VERIFYHOST, false );
  1678. curl_easy_setopt( m_pCURL, CURLOPT_POST, true );
  1679. curl_easy_setopt( m_pCURL, CURLOPT_WRITEFUNCTION, pOnvif::_writer );
  1680. curl_easy_setopt( m_pCURL, CURLOPT_WRITEDATA, this );
  1681. };
  1682. if( m_pCURL != NULL ){
  1683. curl_easy_setopt( m_pCURL, CURLOPT_URL, url );
  1684. struct curl_slist *sList = NULL;
  1685. sList = curl_slist_append( sList, "Content-Type: text/xml; charset=utf-8" );
  1686. sprintf( tBuffer, "Content-Length: %d", strlen(post_string) );
  1687. sList = curl_slist_append( sList, tBuffer );
  1688. curl_easy_setopt( m_pCURL, CURLOPT_HTTPHEADER, sList );
  1689. curl_easy_setopt( m_pCURL, CURLOPT_POSTFIELDS, post_string);
  1690. sprintf( tBuffer,"%s:%s", m_pUsername, m_pPassword );
  1691. curl_easy_setopt( m_pCURL, CURLOPT_USERPWD, tBuffer );
  1692. m_pLastIndex = 0;
  1693. if( curl_easy_perform( m_pCURL ) ) {
  1694. LOG_ERROR("CURL Failure!");
  1695. } else {
  1696. m_pLastResponse[m_pLastIndex] = (char)0;
  1697. return true;
  1698. };
  1699. m_pLastIndex = 0;
  1700. };
  1701. return false;
  1702. };
  1703. int pOnvif::_writer( char *data, size_t size, size_t nmemb, pOnvif *Ptr ){
  1704. if( Ptr == NULL ) return 0;
  1705. memcpy( (Ptr->m_pLastResponse + Ptr->m_pLastIndex), data, size*nmemb );
  1706. Ptr->m_pLastIndex += size*nmemb;
  1707. return size*nmemb;
  1708. };
  1709. #undef LOG
  1710. #undef TLOG
  1711. #undef LOG_ERROR