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.

602 lines
25 KiB

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