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.

603 lines
24 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "kernelModuleOnvifObserver.h"
  2. #include "hardwareManager.h"
  3. #include "hardwareResourceNetworkProvider.h"
  4. #define SEARCH_REQUEST_STRING "<?xml version=\"1.0\" encoding=\"UTF-8\"?><e:Envelope xmlns:e=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:w=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:d=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:dn=\"http://www.onvif.org/ver10/network/wsdl\"><e:Header><w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID><w:To e:mustUnderstand=\"true\">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To><w:Action a:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action></e:Header><e:Body><d:Probe><d:Types>dn:NetworkVideoTransmitter</d:Types></d:Probe></e:Body></e:Envelope>"
  5. #define SEARCH_REQUEST_STRING2323 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" \
  6. "<SOAP:Envelope xmlns:SOAP=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:DISCOVERY=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:ssdp=\"http://example.com/wsdp/sample/print\">\n" \
  7. "<SOAP:Header>\n" \
  8. "<wsa:MessageID>urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7</wsa:MessageID>\n" \
  9. "<wsa:Action>\n" \
  10. "http ://schemas.xmlsoap.org/ws/2005/04/discovery/Probe\n" \
  11. "</wsa:Action>\n" \
  12. "<wsa:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</wsa:To>\n" \
  13. "</SOAP:Header>\n" \
  14. "<SOAP:Body>\n" \
  15. "<DISCOVERY:Probe>\n" \
  16. "<DISCOVERY:Types>ssdp:any</DISCOVERY:Types>\n" \
  17. "</DISCOVERY:Probe>\n" \
  18. "</SOAP:Body>\n" \
  19. "</SOAP:Envelope>\r\n\r\n"
  20. #define HTTP_OK "200 OK"
  21. /******************************************************************
  22. ** Action Defines *
  23. *******************************************************************/
  24. #define HTTP_HEADER_ACTION "POST %s HTTP/1.1\r\n" \
  25. "HOST: %s:%u\r\n" \
  26. "SOAPACTION:\"%s#%s\"\r\n" \
  27. "CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n"\
  28. "Content-Length: %d \r\n\r\n"
  29. #define SOAP_ACTION "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" \
  30. "<s:Envelope xmlns:s=" \
  31. "\"http://schemas.xmlsoap.org/soap/envelope/\" " \
  32. "s:encodingStyle=" \
  33. "\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" \
  34. "<s:Body>\r\n" \
  35. "<u:%s xmlns:u=\"%s\">\r\n%s" \
  36. "</u:%s>\r\n" \
  37. "</s:Body>\r\n" \
  38. "</s:Envelope>\r\n"
  39. #define PORT_MAPPING_LEASE_TIME "63072000" //two year
  40. #define ADD_PORT_MAPPING_PARAMS "<NewRemoteHost></NewRemoteHost>\r\n" \
  41. "<NewExternalPort>%u</NewExternalPort>\r\n"\
  42. "<NewProtocol>%s</NewProtocol>\r\n" \
  43. "<NewInternalPort>%u</NewInternalPort>\r\n"\
  44. "<NewInternalClient>%s</NewInternalClient>\r\n" \
  45. "<NewEnabled>1</NewEnabled>\r\n" \
  46. "<NewPortMappingDescription>%s</NewPortMappingDescription>\r\n" \
  47. "<NewLeaseDuration>" \
  48. PORT_MAPPING_LEASE_TIME \
  49. "</NewLeaseDuration>\r\n"
  50. #define LOG( X ) kernelModule::m_pLog->Log( "MOD_ONVIF", this, X )
  51. #ifdef DEBUG
  52. #define LOG_ERROR( X ) {\
  53. char _tBfrErrMSG2w34[256];\
  54. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  55. kernelModule::m_pLog->Log( "MOD_ONVIF", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  56. }
  57. #else
  58. #define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_ONVIF", this, _LOG_ERROR, X );
  59. #endif
  60. kernelModuleOnvifObserver::kernelModuleOnvifObserver( uint32_t ModuleID ): kernelModule( ModuleID, KERNEL_MODULE_ONVIF_OBSERVER ), basicThread(){
  61. m_bEnabled = false;
  62. m_pEventHeap = basicEventHeap::getInstance();
  63. m_bCurrentNIF = 0;
  64. m_bProbeIsActive = false;
  65. m_bDetached = false;
  66. #ifdef __linux__
  67. m_bWSAOK = true;
  68. #else
  69. m_bWSAOK = false;
  70. WORD wVersionRequested;
  71. WSADATA wsaData;
  72. int err;
  73. wVersionRequested = MAKEWORD(2, 2);
  74. err = WSAStartup(wVersionRequested, &wsaData);
  75. if (err != 0){
  76. LOG_ERROR("WSAStartup failed with error");
  77. } else m_bWSAOK = true;
  78. #endif
  79. };
  80. kernelModuleOnvifObserver::~kernelModuleOnvifObserver(){
  81. if( !m_bDetached ) stopService( true );
  82. };
  83. bool kernelModuleOnvifObserver::startService(){
  84. LOG("Starting Service!");
  85. if( !m_bWSAOK ) return false;
  86. m_bEnabled = reloadSettings();
  87. return init();
  88. };
  89. bool kernelModuleOnvifObserver::stopService( bool force ){
  90. m_bEnabled = false;
  91. if( !m_bDetached ) m_bDetached = uninit();
  92. if( m_bDetached ) {
  93. //Clear Results
  94. m_mResultProtector.lock();
  95. if (m_vResultPool.size()){ // Clear structures
  96. for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){
  97. free(*index);
  98. };
  99. m_vResultPool.clear();
  100. };
  101. m_mResultProtector.unlock();
  102. };
  103. return m_bDetached;
  104. };
  105. /*
  106. #include <stdio.h>
  107. #include <stdint.h>
  108. #include <string.h>
  109. #include <sys/types.h>
  110. #include <sys/socket.h>
  111. #include <linux/in.h>
  112. #include <linux/if_ether.h>
  113. #include <net/if.h>
  114. #include <errno.h>
  115. // Join multicast group, support both IPv4 and IPv6. * @param sockfd socket descripter * @param grp sockaddr * @param grplen sockaddr length * @return 0:on success; non-zero:on failed
  116. static int mcast_join(int sockfd, const struct sockaddr *grp, socklen_t grplen){
  117. #if MCAST_JOIN_GROUP
  118. struct group_req req;
  119. req.gr_interface = 0;
  120. if (grplen > sizeof(req.gr_group)) {
  121. errno = EINVAL;
  122. return -1;
  123. }
  124. memcpy(&req.gr_group, grp, grplen);
  125. return (setsockopt(sockfd, IPPROTO_IP, MCAST_JOIN_GROUP, &req, sizeof(req)));
  126. #else
  127. switch (grp->sa_family) {
  128. case AF_INET: {
  129. struct ip_mreq mreq;
  130. struct ifreq ifreq;
  131. memcpy(&mreq.imr_multiaddr, &((const struct sockaddr_in *) grp)->sin_addr, sizeof(struct in_addr));
  132. mreq.imr_interface.s_addr = htonl(INADDR_ANY);
  133. return (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
  134. &mreq, sizeof(mreq)));
  135. }
  136. #ifdef IPV6
  137. #ifndef IPV6_JOIN_GROUP // APIv0 compatibility
  138. #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
  139. #endif
  140. case AF_INET6: {
  141. struct ipv6_mreq mreq6;
  142. memcpy(&mreq6.ipv6mr_multiaddr, &((const struct sockaddr_in6 *) grp)->sin6_addr, sizeof(struct in6_addr));
  143. mreq6.ipv6mr_interface = 0;
  144. return (setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq6)));
  145. }
  146. #endif
  147. default:
  148. errno = EAFNOSUPPORT;
  149. return -1;
  150. }
  151. #endif
  152. };
  153. int main(int argc, char **argv){
  154. int fd = socket(AF_INET, SOCK_DGRAM, 0);
  155. struct sockaddr_in grp;
  156. bzero(&grp, sizeof(grp));
  157. grp.sin_family = AF_INET;
  158. grp.sin_addr.s_addr = inet_addr("224.0.0.1");;
  159. if (mcast_join(fd, (struct sockaddr*)(&grp), sizeof(grp)))
  160. perror("Join multicast group failed");
  161. }
  162. */
  163. void kernelModuleOnvifObserver::m_fThreadProc(){
  164. int socketFD;
  165. int RetVal;
  166. struct sockaddr_in r_address;
  167. bool bOptVal;
  168. int bOptLen;
  169. int iOptLen;
  170. uint16_t bCounterTO = 600; // 3 second
  171. char rBuffer[MAX_BUFF_SIZE];
  172. #ifdef DEBUG
  173. char tB[128];
  174. LOG("Module Started!");
  175. #endif
  176. m_bDetached = false;
  177. m_bThreadStatus = TH_WORKING;
  178. while( m_bThreadStatus < TH_ENDED ) {
  179. if ( m_bEnabled ) {
  180. if ( m_bProbeIsActive ) {
  181. if( socketFD > -1 ){
  182. if( bCounterTO-- ){
  183. memset( rBuffer, 0, MAX_BUFF_SIZE );
  184. #ifdef DEBUG
  185. struct sockaddr src_addr;
  186. socklen_t addrlen = sizeof( src_addr );
  187. RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, &src_addr, &addrlen );
  188. if ( RetVal > -1 ) {
  189. sprintf(tB, "(%d){%d}MSG[%d] from %s", bCounterTO, socketFD, RetVal, inet_ntoa(((struct sockaddr_in *)&src_addr)->sin_addr));
  190. LOG( tB );
  191. };
  192. #else //http://192.168.200.127/axis-cgi/com/ptz.cgi?info=1&camera=1
  193. RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, NULL, NULL );
  194. #endif
  195. if ((RetVal == -1) && /*(errno != EAGAIN) &&*/ (errno != EINTR) && (errno != EWOULDBLOCK)) {
  196. LOG_ERROR("Error acures while reading UDP package");
  197. close( socketFD );
  198. m_bProbeIsActive = false;
  199. continue; // Error ocured but continue to next address
  200. };
  201. if( RetVal < 1 ){
  202. //LOG("SLEEP");
  203. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  204. continue; // No Data - wait to next time
  205. };
  206. OBSERVER_RESULT *tResult = parseXML( rBuffer );
  207. if ( tResult ) {
  208. m_mResultProtector.lock();
  209. m_vResultPool.push_back( tResult );
  210. m_mResultProtector.unlock();
  211. #ifdef DEBUG
  212. LOG("Probe Finished!");
  213. #endif
  214. } else {
  215. #ifdef DEBUG
  216. LOG("Probe Finished with unrecognized data!");
  217. #endif
  218. };
  219. continue; //To Fetch Another responces
  220. } else {
  221. #ifdef DEBUG
  222. LOG("Probe Finished By Timeout!");
  223. #endif
  224. };
  225. #ifdef __linux__
  226. close(socketFD);
  227. #else
  228. closesocket(socketFD);
  229. #endif
  230. };
  231. m_bProbeIsActive = false;
  232. //Sleep 5 minutes if done all scans
  233. if ( m_bCurrentNIF == 0 ){
  234. for( int i=12000; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  235. };
  236. } else {
  237. // start new probe;
  238. m_mNIFMUTEX.lock();
  239. if ( m_vNIFIPS.size() ) {
  240. #ifdef DEBUG
  241. sprintf( tB, "Starting probe on %s address", m_vNIFIPS.at(m_bCurrentNIF) );
  242. LOG( tB );
  243. #endif
  244. socketFD = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
  245. if( socketFD > -1 ){
  246. CSTR send_buff = (CSTR)SEARCH_REQUEST_STRING;
  247. r_address.sin_family = AF_INET;
  248. r_address.sin_port = htons(HTTPMU_HOST_PORT);
  249. r_address.sin_addr.s_addr = inet_addr(m_vNIFIPS.at(m_bCurrentNIF));
  250. bOptVal = true;
  251. #ifdef DEBUG
  252. LOG("Set Broadcast Flag");
  253. #endif
  254. RetVal = setsockopt( socketFD, SOL_SOCKET, SO_BROADCAST, (char*)&bOptVal, bOptLen );
  255. struct group_req req;
  256. req.gr_interface = 0;
  257. memcpy( &req.gr_group, &r_address, sizeof(r_address));
  258. #ifdef DEBUG
  259. LOG("Join Broadcast Group");
  260. #endif
  261. RetVal = setsockopt( socketFD, IPPROTO_IP, MCAST_JOIN_GROUP, (char*)&req, sizeof(req) );
  262. //The broadcast address to be used may be determined by issuing an ioctl() with the SIOCGIFBRDADDR request.
  263. if ( RetVal > -1 ) {
  264. LOG_ERROR("Setting Socked as Broadcasted Error!");
  265. };
  266. //
  267. struct sockaddr_in tServerAddr;
  268. memset( &tServerAddr, 0, sizeof(tServerAddr) );
  269. tServerAddr.sin_family = AF_INET; // IPv4
  270. tServerAddr.sin_addr.s_addr = inet_addr( "0.0.0.0" ); //INADDR_ANY;
  271. tServerAddr.sin_port = htons(rand( 20000, 40000));
  272. // Bind the socket with the server address
  273. RetVal = bind( socketFD, (const struct sockaddr *)&tServerAddr, sizeof(tServerAddr));
  274. if ( RetVal > -1 ) {
  275. LOG_ERROR("Bind Socked Error!");
  276. };
  277. #ifdef DEBUG
  278. LOG("Sending Probe Request");
  279. #endif
  280. RetVal = sendto( socketFD, send_buff, strlen(send_buff), 0, (struct sockaddr*)&r_address, sizeof(struct sockaddr_in));
  281. if ( RetVal > -1 ) {
  282. #ifdef DEBUG
  283. sprintf( tB, "Sent %d Bytes of %d", RetVal, strlen(send_buff) );
  284. LOG( tB );
  285. #endif
  286. #ifdef __linux__
  287. fcntl( socketFD, F_SETFL, fcntl( socketFD, F_GETFL, 0) | O_NONBLOCK );
  288. #else
  289. u_long val = 1;
  290. ioctlsocket( socketFD, FIONBIO, &val );//none block
  291. #endif
  292. bCounterTO = 600;
  293. m_bProbeIsActive = true;
  294. } else {
  295. #ifdef DEBUG
  296. // Failure to send probe package
  297. LOG_ERROR("Error in sending Probe Request");
  298. #endif
  299. #ifdef __linux__
  300. close(socketFD);
  301. #else
  302. closesocket(socketFD);
  303. #endif
  304. };
  305. };
  306. m_bCurrentNIF++;
  307. if ( m_bCurrentNIF == m_vNIFIPS.size() ) m_bCurrentNIF = 0;
  308. };
  309. m_mNIFMUTEX.unlock();
  310. };
  311. } else {
  312. //Sleep 3 Sec.
  313. for( int i=300; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
  314. };
  315. };
  316. m_bDetached = true;
  317. };
  318. void kernelModuleOnvifObserver::dispatchEvent(EVENT_CONTAINER *Evt){
  319. if(!m_bEnabled) {
  320. #ifdef DEBUG
  321. LOG("Module Disabled!");
  322. #endif
  323. return;
  324. }
  325. if( Evt == NULL ) return;
  326. };
  327. bool kernelModuleOnvifObserver::reloadSettings(){
  328. m_mNIFMUTEX.lock();
  329. if( m_vNIFIPS.size() ) {
  330. for ( vectorCSTR::iterator idx=m_vNIFIPS.begin(); idx < m_vNIFIPS.end(); idx++ ) free(*idx);
  331. m_vNIFIPS.clear();
  332. };
  333. m_mNIFMUTEX.unlock();
  334. #ifdef DEBUG
  335. LOG("Check IPS");
  336. #endif
  337. hardwareManager *tHWM = hardwareManager::getInstance();
  338. if( tHWM != NULL ) {
  339. #ifdef DEBUG
  340. LOG("Check IPS 11");
  341. #endif
  342. DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( HARDWARE_PROVIDER_NETWORK );
  343. if( rIDS != NULL ) {
  344. #ifdef DEBUG
  345. LOG("Check IPS 22");
  346. #endif
  347. for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){
  348. #ifdef DEBUG
  349. LOG("Check IPS 33");
  350. #endif
  351. hardwareResourceNetwork *tRES = ( hardwareResourceNetwork *) tHWM->requestResource( HARDWARE_PROVIDER_NETWORK, *idx );
  352. if( tRES != NULL ) {
  353. #ifdef DEBUG
  354. LOG("Have NIF Resource");
  355. #endif
  356. CSTR BC = tRES->getBroadcast();
  357. if( BC!= NULL ) {
  358. #ifdef DEBUG
  359. LOG("Have BC Address");
  360. LOG(BC);
  361. #endif
  362. m_mNIFMUTEX.lock();
  363. m_vNIFIPS.push_back( BC );
  364. m_mNIFMUTEX.unlock();
  365. #ifdef DEBUG
  366. LOG("NIF defined");
  367. #endif
  368. }
  369. #ifdef DEBUG
  370. else {
  371. LOG("NO BC Address");
  372. }
  373. #endif
  374. ;
  375. } else {
  376. LOG_ERROR("Cannot Get Resource!");
  377. };
  378. };
  379. delete( rIDS );
  380. } else {
  381. LOG("No Networks Detected!");
  382. m_bEnabled = false;
  383. };
  384. } else {
  385. LOG_ERROR("No HW Manager");
  386. };
  387. #ifdef DEBUG
  388. LOG("Default Probe");
  389. LOG( HTTPMU_HOST_ADDRESS );
  390. #endif
  391. CSTR tBC = (CSTR) malloc(16);
  392. if ( tBC ) {
  393. sprintf(tBC, HTTPMU_HOST_ADDRESS );
  394. m_mNIFMUTEX.lock();
  395. m_vNIFIPS.push_back( tBC );
  396. m_mNIFMUTEX.unlock();
  397. } else {
  398. LOG_ERROR("Malloc Error!");
  399. };
  400. return true;
  401. };
  402. OBSERVER_RESULT *kernelModuleOnvifObserver::parseXML( CSTR data ){
  403. OBSERVER_RESULT *retVal = NULL;
  404. if( data!=NULL ){
  405. XMLResults tParseResults;
  406. XMLNode response = XMLNode::parseString( data, "root", &tParseResults );
  407. if( tParseResults.error ){
  408. char tBuffer[CTEXT];
  409. sprintf( tBuffer, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  410. LOG_ERROR( tBuffer );
  411. } else {
  412. if( response.isEmpty() ){
  413. LOG_ERROR("The device descripe XML file is not a valid XML file. Cann't find root element.");
  414. } else {
  415. #ifdef DEBUG
  416. LOG("Probe XML parsed");
  417. #endif
  418. XMLNode Body = response.getChildNode( "Body", 0 );
  419. if(!Body.isEmpty()){
  420. LOG("Have Body elm");
  421. XMLNode ProbeMatches = Body.getChildNode("ProbeMatches", 0);//EndpointReference
  422. if(!ProbeMatches.isEmpty()) {
  423. LOG("Have ProbeMathes elm");
  424. int matches = ProbeMatches.nChildNode();
  425. for(int index=0;index<matches;index++){
  426. XMLNode ProbeMatch = ProbeMatches.getChildNode("ProbeMatch", index);
  427. retVal = (OBSERVER_RESULT *)malloc(sizeof(OBSERVER_RESULT));
  428. if( retVal != NULL ){
  429. memset( retVal, 0, sizeof(OBSERVER_RESULT));
  430. if(!ProbeMatch.isEmpty()) {
  431. LOG("Have ProbeMatch elm");
  432. {
  433. XMLNode node = ProbeMatch.getChildNode("EndpointReference", 0);
  434. if(!node.isEmpty()) {
  435. LOG("Have ProbeMatch EndpointReference");
  436. XMLNode nod = node.getChildNode("Address", 0);
  437. if(!nod.isEmpty()){
  438. char tBuf[CLOG];
  439. sprintf(tBuf,"%s", nod.getText(0));
  440. CArray *tArr;
  441. LOG("Before Explode");
  442. tArr = explode(':',tBuf);
  443. LOG("After Explode");
  444. for(int j=0; j<tArr->size(); j++) {
  445. if( strlen(tArr->at(j)) > 10 ) {
  446. sprintf(retVal->RefID,"%s",tArr->at(j));
  447. break;
  448. };
  449. };
  450. tArr->clear();
  451. delete(tArr);
  452. };
  453. };
  454. }
  455. {
  456. XMLNode node = ProbeMatch.getChildNode("Types", 0);
  457. if( !node.isEmpty() ){
  458. char tBuf[CLOG];
  459. sprintf(tBuf,"%s", node.getText(0));
  460. CArray *tArr;
  461. tArr = explode(' ',tBuf);
  462. sprintf(retVal->Type,"%s",tArr->at(0));
  463. tArr->clear();
  464. delete(tArr);
  465. }
  466. }
  467. {
  468. XMLNode node = ProbeMatch.getChildNode("Scopes", 0);
  469. char tBuf[CLOG];
  470. sprintf( tBuf,"%s", node.getText(0) );
  471. CArray *tArr = explode(' ',tBuf);
  472. if( tArr->size() > 0 ) {
  473. for( int index = 0; index < tArr->size(); index++){
  474. char *tPtr;
  475. if( tPtr = strstr( tArr->at(index), "mac/" ) ){
  476. sprintf(retVal->MAC,"%s",tPtr+4);
  477. };
  478. if( tPtr = strstr( tArr->at(index), "hardware/" ) ){
  479. sprintf(retVal->Hardware,"%s",tPtr+9);
  480. };
  481. if( tPtr = strstr( tArr->at(index), "name/" ) ){
  482. sprintf(retVal->Name,"%s",tPtr+5);
  483. };
  484. if (tPtr = strstr(tArr->at(index), "MAC/")) {
  485. sprintf(retVal->MAC, "%s", tPtr + 4);
  486. };
  487. if (tPtr = strstr(tArr->at(index), "HARDWARE/")) {
  488. sprintf(retVal->Hardware, "%s", tPtr + 9);
  489. };
  490. if (tPtr = strstr(tArr->at(index), "NAME/")) {
  491. sprintf(retVal->Name, "%s", tPtr + 5);
  492. };
  493. };
  494. tArr->clear();
  495. };
  496. delete(tArr);
  497. }
  498. {
  499. XMLNode node = ProbeMatch.getChildNode("XAddrs", 0);
  500. char tBuf[CLOG];
  501. sprintf(tBuf,"%s", node.getText(0));
  502. CArray *tArr;
  503. tArr = explode(' ',tBuf);
  504. if( tArr->size() > 0 ) {
  505. for(int index=0; index < tArr->size(); index++) {
  506. if( strstr( tArr->at(index), "[" ) != NULL ){
  507. // IPv6
  508. } else{
  509. // IPv4
  510. sprintf(retVal->XAddrs,"%s",tArr->at(0));
  511. };
  512. };
  513. tArr->clear();
  514. };
  515. delete(tArr);
  516. }
  517. };
  518. };
  519. };
  520. };
  521. };
  522. };
  523. };
  524. };
  525. return retVal;
  526. };
  527. bool kernelModuleOnvifObserver::validate(){
  528. m_mResultProtector.lock();
  529. if( m_vResultPool.size() ){ // Clear structures
  530. for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){
  531. #ifdef DEBUG
  532. char tBuffer[256];
  533. sprintf( tBuffer, "Found Camwera [%s] %s", (*index)->XAddrs, (*index)->RefID );
  534. LOG( tBuffer );
  535. #endif
  536. uint32_t cid = m_pDBC->getCamId( (*index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
  537. if( cid ) {
  538. #ifdef DEBUG
  539. sprintf( tBuffer, "Camera is Listed as %d", cid );
  540. LOG( tBuffer );
  541. #endif
  542. m_pDBC->updateIPCam( cid, (*index)->XAddrs );// DiscoverResults->at(index));
  543. } else {
  544. // Uncknown camera - no checking
  545. #ifdef DEBUG
  546. LOG("Camera is Not Listed");
  547. #endif
  548. m_pDBC->addIPCam( (*index) );
  549. };
  550. free(*index);
  551. }
  552. m_vResultPool.clear();
  553. #ifdef DEBUG_EXTRA
  554. LOG("Clear Structs Done!");
  555. #endif
  556. } else {
  557. #ifdef DEBUG_EXTRA
  558. LOG("No Online IP Cameras in Network");
  559. #endif
  560. };
  561. m_mResultProtector.unlock();
  562. return true;
  563. };
  564. #undef LOG
  565. #undef LOG_ERROR