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.

525 lines
19 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. #define TLOG( X ) basicLogCollection::getInstance()->Log( "MOD_ONVIF_T", me, X )
  61. #define TLOG_ERROR( X ) basicLogCollection::getInstance()->Log( "MOD_ONVIF_T", me, _LOG_ERROR, X )
  62. argusModuleOnvifObserver::argusModuleOnvifObserver( uint32_t ModuleID ): argusKernelModule( ModuleID, ARGUS_MODULE_ONVIF_OBSERVER ), basicThread(){
  63. m_bEnabled = false;
  64. m_pEventHeap = basicEventHeap::getInstance();
  65. m_pIpAddresses = NULL;
  66. m_nStatus = 0;
  67. #ifdef __linux__
  68. m_bWSAOK = true;
  69. #else
  70. m_bWSAOK = false;
  71. WORD wVersionRequested;
  72. WSADATA wsaData;
  73. int err;
  74. wVersionRequested = MAKEWORD(2, 2);
  75. err = WSAStartup(wVersionRequested, &wsaData);
  76. if (err != 0){
  77. LOG_ERROR("WSAStartup failed with error");
  78. } else m_bWSAOK = true;
  79. #endif
  80. };
  81. argusModuleOnvifObserver::~argusModuleOnvifObserver(){
  82. if( !m_bDetached ) stopService( true );
  83. };
  84. bool argusModuleOnvifObserver::startService(){
  85. LOG("Starting Service!");
  86. if( !m_bWSAOK ) return false;
  87. m_bEnabled = init();
  88. return m_bEnabled;
  89. };
  90. bool argusModuleOnvifObserver::stopService( bool force ){
  91. m_bEnabled = false;
  92. waitThreadEnd( true );
  93. if( m_vThreads.size() ) { // Kill-Wait Started Probes
  94. #ifdef DEBUG
  95. char tB[128];
  96. sprintf( tB, "Have to Wait %d Probe(s)!", m_vThreads.size() );
  97. LOG( tB );
  98. #endif
  99. for( vectorOBSERVER_CTX::iterator index = m_vThreads.begin(); index < m_vThreads.end(); index++ ) {
  100. if( force ){
  101. #ifdef DEBUG
  102. LOG("Force Cancel Probe!");
  103. #endif
  104. pthread_cancel( (*index)->m_hThreadHandle );
  105. } else{
  106. #ifdef DEBUG
  107. LOG("Wait Probe Exits!");
  108. #endif
  109. pthread_join( (*index)->m_hThreadHandle, NULL );
  110. };
  111. free((*index)->context);
  112. free((*index));
  113. };
  114. m_vThreads.clear();
  115. };
  116. #ifdef DEBUG
  117. LOG("No More Probes!");
  118. #endif
  119. if (m_vResultPool.size()){ // Clear structures
  120. for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){
  121. free(*index);
  122. };
  123. m_vResultPool.clear();
  124. };
  125. #ifdef DEBUG
  126. LOG("Data is Cleared!");
  127. #endif
  128. m_bDetached = true;
  129. return m_bDetached;
  130. };
  131. void argusModuleOnvifObserver::m_fThreadProc(){
  132. double dStatus = 0, dStep = 30.0;
  133. int id = 0;
  134. dStatus = 0;
  135. m_bThreadStatus = TH_WORKING;
  136. if( !m_bEnabled ) {
  137. m_bThreadStatus = TH_ENDED;
  138. #ifdef DEBUG
  139. LOG("Module is Disabled!");
  140. #endif
  141. };
  142. #ifdef DEBUG
  143. LOG("Module Started!");
  144. #endif
  145. while( m_bThreadStatus < TH_ENDED ) {
  146. id = 0;
  147. if( m_pKernel != NULL ){
  148. #ifdef DEBUG_EXTRA
  149. LOG("Check IPS");
  150. #endif
  151. argusHardwareManager *tHWM = m_pKernel->getHardwareManager();
  152. if( tHWM != NULL ) {
  153. DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( ARGUS_HARDWARE_PROVIDER_NETWORK );
  154. if( rIDS != NULL ) {
  155. dStep = 30.0 / (rIDS->size() + 1);
  156. for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){
  157. argusHardwareResourceNetwork *tRES = (argusHardwareResourceNetwork *) tHWM->requestResource( ARGUS_HARDWARE_PROVIDER_NETWORK, *idx );
  158. if( tRES != NULL ) {
  159. CSTR BC = tRES->getBroadcast();
  160. if( BC!= NULL ) {
  161. #ifdef DEBUG_EXTRA
  162. LOG("Have BC Address");
  163. #endif
  164. startProbe( BC, id, (int) dStep );
  165. #ifdef DEBUG_EXTRA
  166. LOG("Probe Started");
  167. #endif
  168. dStatus += dStep;
  169. m_nStatus = (int)dStatus;
  170. id++;
  171. free( BC );
  172. }
  173. #ifdef DEBUG_EXTRA
  174. else {
  175. LOG("NO BC Address");
  176. }
  177. #endif
  178. ;
  179. } else {
  180. LOG_ERROR("Cannot Get Resource!");
  181. };
  182. };
  183. delete( rIDS );
  184. }
  185. #ifdef DEBUG_EXTRA
  186. else {
  187. LOG("No Networks Detected!");
  188. }
  189. #endif
  190. ;
  191. } else {
  192. LOG_ERROR("No HW Manager");
  193. };
  194. } else {
  195. LOG_ERROR("Kernel Not Assigned!" );
  196. };
  197. #ifdef DEBUG_EXTRA
  198. LOG("Start Default Probe");
  199. #endif
  200. startProbe(HTTPMU_HOST_ADDRESS, id, (int)dStep);
  201. dStatus += dStep;
  202. m_nStatus = (int)dStatus;
  203. // Check Finished Threads;
  204. for( vectorOBSERVER_CTX::iterator index = m_vThreads.begin(); index < m_vThreads.end(); index++ ) {
  205. if( (*index)->context->isFinished ){
  206. #ifdef DEBUG_EXTRA
  207. LOG("Probe Exits!");
  208. #endif
  209. pthread_join( (*index)->m_hThreadHandle, NULL );
  210. };
  211. free((*index)->context);
  212. free((*index));
  213. m_vThreads.erase( index );
  214. };
  215. for( int i=300; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( 100 );
  216. };
  217. };
  218. void argusModuleOnvifObserver::dispatchEvent(EVENT_CONTAINER *Evt){
  219. if(!m_bEnabled) {
  220. LOG("Module Disabled!");
  221. return;
  222. }
  223. if( Evt == NULL ) return;
  224. };
  225. bool argusModuleOnvifObserver::reloadSettings(){
  226. return true;
  227. };
  228. PROBE_CTX *argusModuleOnvifObserver::init_PROBE_CTX(CSTR ADR, int ID, int stp){
  229. PROBE_CTX *RetVal;
  230. RetVal = (PROBE_CTX*)malloc(sizeof(PROBE_CTX));
  231. if (RetVal == NULL) return NULL;
  232. sprintf(RetVal->IpAddress, "%s", ADR);
  233. RetVal->Port = HTTPMU_HOST_PORT;
  234. RetVal->socketFD = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  235. RetVal->send_buff = (CSTR) SEARCH_REQUEST_STRING;
  236. RetVal->r_address.sin_family = AF_INET;
  237. RetVal->r_address.sin_port = htons(RetVal->Port);
  238. RetVal->r_address.sin_addr.s_addr = inet_addr(RetVal->IpAddress);
  239. RetVal->bOptVal = true;
  240. RetVal->bOptLen = sizeof(bool);
  241. RetVal->iOptLen = sizeof(int);
  242. RetVal->AddressID = ID;
  243. RetVal->step = stp;
  244. RetVal->isFinished = false;
  245. RetVal->observer = this;
  246. return RetVal;
  247. };
  248. void *argusModuleOnvifObserver::probeThreadProc( void *ptr ){
  249. PROBE_CTX *me;
  250. if (ptr == NULL) return NULL;
  251. me = (PROBE_CTX *)ptr;
  252. //Detach Self!
  253. //pthread_detach( pthread_self() );
  254. #ifdef DEBUG
  255. //TLOG("Probe Request Sent");
  256. #endif
  257. me->RetVal = setsockopt(me->socketFD, SOL_SOCKET, SO_BROADCAST, (char*)&me->bOptVal, me->bOptLen);
  258. me->RetVal = sendto(me->socketFD, me->send_buff, strlen(me->send_buff), 0, (struct sockaddr*)&me->r_address, sizeof(struct sockaddr_in));
  259. #ifdef DEBUG
  260. //sprintf(me->buff, "Sent %d Bytes", me->RetVal );
  261. //TLOG(me->buff);
  262. #endif
  263. #ifdef __linux__
  264. fcntl( me->socketFD, F_SETFL, fcntl(me->socketFD, F_GETFL, 0) | O_NONBLOCK );
  265. #else
  266. u_long val = 1;
  267. ioctlsocket(me->socketFD, FIONBIO, &val);//none block
  268. #endif
  269. for( me->index = 1; me->index <= 10; me->index++ ){
  270. memset(me->buff, 0, sizeof(me->buff));
  271. me->RetVal = recvfrom(me->socketFD, me->buff, MAX_BUFF_SIZE, 0, NULL, NULL);
  272. if( me->RetVal < 0 ){//SOCKET_ERROR){
  273. SLEEP(1000);
  274. continue;
  275. };
  276. if( me->RetVal == 0 ) continue; // No Data
  277. me->recv_buff = me->buff;
  278. XMLResults tParseResults;
  279. XMLNode response = XMLNode::parseString( me->buff, "root", &tParseResults );
  280. #ifdef DEBUG_ONVIF_PRINTOUT_MESSAGES
  281. FILE *fd;
  282. fd = fopen("ONVIF_MSGS.txt","a+");
  283. fprintf(fd,"++++++++++++++++++++\r\n");
  284. fprintf(fd,me->buff);
  285. fprintf(fd,"--------------------\r\n");
  286. fclose(fd);
  287. #endif
  288. if( tParseResults.error ){
  289. char tBuffer[CTEXT];
  290. sprintf( tBuffer, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn );
  291. TLOG_ERROR( tBuffer );
  292. } else {
  293. if( response.isEmpty() ){
  294. TLOG_ERROR("The device descripe XML file is not a valid XML file. Cann't find root element.");
  295. continue;
  296. } else {
  297. TLOG_ERROR("XML PARSED OK");
  298. XMLNode Body = response.getChildNode( "Body", 0 );
  299. if(!Body.isEmpty()){
  300. XMLNode ProbeMatches = Body.getChildNode("ProbeMatches", 0);//EndpointReference
  301. if(!ProbeMatches.isEmpty()) {
  302. int matches = ProbeMatches.nChildNode();
  303. OBSERVER_RESULT *tRecord;
  304. for(int index=0;index<matches;index++){
  305. XMLNode ProbeMatch = ProbeMatches.getChildNode("ProbeMatch", index);
  306. tRecord = (OBSERVER_RESULT *)malloc(sizeof(OBSERVER_RESULT));
  307. if (tRecord != NULL){
  308. memset(tRecord, 0, sizeof(OBSERVER_RESULT));
  309. tRecord->resultID = me->AddressID;
  310. if(!ProbeMatch.isEmpty()) {
  311. {
  312. XMLNode node = ProbeMatch.getChildNode("EndpointReference", 0);
  313. if(!node.isEmpty()) {
  314. XMLNode nod = node.getChildNode("Address", 0);
  315. char tBuf[CLOG];
  316. sprintf(tBuf,"%s", nod.getText(0));
  317. CArray *tArr;
  318. tArr = explode(':',tBuf);
  319. for(int j=0; j<tArr->size(); j++) {
  320. if( strlen(tArr->at(j)) > 10 ) {
  321. sprintf(tRecord->RefID,"%s",tArr->at(j));
  322. break;
  323. };
  324. };
  325. tArr->clear();
  326. delete(tArr);
  327. };
  328. }
  329. {
  330. XMLNode node = ProbeMatch.getChildNode("Types", 0);
  331. char tBuf[CLOG];
  332. sprintf(tBuf,"%s", node.getText(0));
  333. CArray *tArr;
  334. tArr = explode(' ',tBuf);
  335. sprintf(tRecord->Type,"%s",tArr->at(0));
  336. tArr->clear();
  337. delete(tArr);
  338. }
  339. {
  340. XMLNode node = ProbeMatch.getChildNode("Scopes", 0);
  341. char tBuf[CLOG];
  342. sprintf(tBuf,"%s", node.getText(0));
  343. CArray *tArr;
  344. tArr = explode(' ',tBuf);
  345. if( tArr->size() > 0 ) {
  346. for( int index = 0; index < tArr->size(); index++){
  347. char *tPtr;
  348. if( tPtr = strstr( tArr->at(index), "mac/" ) ){
  349. sprintf(tRecord->MAC,"%s",tPtr+4);
  350. };
  351. if( tPtr = strstr( tArr->at(index), "hardware/" ) ){
  352. sprintf(tRecord->Hardware,"%s",tPtr+9);
  353. };
  354. if( tPtr = strstr( tArr->at(index), "name/" ) ){
  355. sprintf(tRecord->Name,"%s",tPtr+5);
  356. };
  357. if (tPtr = strstr(tArr->at(index), "MAC/")) {
  358. sprintf(tRecord->MAC, "%s", tPtr + 4);
  359. };
  360. if (tPtr = strstr(tArr->at(index), "HARDWARE/")) {
  361. sprintf(tRecord->Hardware, "%s", tPtr + 9);
  362. };
  363. if (tPtr = strstr(tArr->at(index), "NAME/")) {
  364. sprintf(tRecord->Name, "%s", tPtr + 5);
  365. };
  366. };
  367. tArr->clear();
  368. };
  369. delete(tArr);
  370. }
  371. {
  372. XMLNode node = ProbeMatch.getChildNode("XAddrs", 0);
  373. char tBuf[CLOG];
  374. sprintf(tBuf,"%s", node.getText(0));
  375. CArray *tArr;
  376. tArr = explode(' ',tBuf);
  377. if( tArr->size() > 0 ) {
  378. for(int index=0; index < tArr->size(); index++) {
  379. if( strstr( tArr->at(index), "[" ) != NULL ){
  380. // IPv6
  381. } else{
  382. // IPv4
  383. sprintf(tRecord->XAddrs,"%s",tArr->at(0));
  384. };
  385. };
  386. tArr->clear();
  387. };
  388. delete(tArr);
  389. }
  390. };
  391. me->observer->m_vResultPool.push_back(tRecord);
  392. };
  393. };
  394. };
  395. };
  396. };
  397. };
  398. };
  399. me->observer->m_nStatus += me->step;
  400. #ifdef __linux__
  401. close(me->socketFD);
  402. #else
  403. closesocket(me->socketFD);
  404. #endif
  405. #ifdef DEBUG_EXTRA
  406. TLOG("Probe Finished");
  407. #endif
  408. me->isFinished = true;
  409. return NULL;
  410. };
  411. bool argusModuleOnvifObserver::startProbe(CSTR IP, int ID, int stp){
  412. #ifdef DEBUG_EXTRA
  413. LOG("Starting Probe!");
  414. LOG( IP );
  415. #endif
  416. PROBE_CTX *tVal = init_PROBE_CTX(IP, ID, stp);
  417. if( tVal == NULL ) return false;
  418. OBSERVER_CTX *tThread;
  419. tThread = (OBSERVER_CTX *) malloc(sizeof(OBSERVER_CTX));
  420. if( tThread != NULL ){
  421. memset( tThread, 0, sizeof(OBSERVER_CTX));
  422. #ifdef __linux__
  423. int RetVal = pthread_create( &tThread->m_hThreadHandle, NULL, probeThreadProc, ( void * ) tVal );
  424. if( RetVal == -1 ) {
  425. LOG_ERROR("Thread Creation Faled.");
  426. free(tVal);
  427. free(tThread);
  428. return false;
  429. };
  430. #else
  431. tThread->m_hThreadHandle = CreateThread(
  432. NULL,
  433. 0,
  434. (LPTHREAD_START_ROUTINE)probeThreadProc,
  435. (LPVOID)tVal,
  436. 0,
  437. &tThread->m_dwThreadID);
  438. if( tThread->m_hThreadHandle==NULL ){
  439. LOG_ERROR("Thread Creation Faled.");
  440. free(tVal);
  441. free(tThread);
  442. return false;
  443. };
  444. #endif
  445. tThread->context = tVal;
  446. m_vThreads.push_back(tThread);
  447. #ifdef DEBUG_EXTRA
  448. LOG("Probe Created");
  449. #endif
  450. return true;
  451. } else {
  452. LOG_ERROR("Can not allocate Memory for Probe CTX");
  453. free(tVal);
  454. };
  455. return false;
  456. };
  457. bool argusModuleOnvifObserver::validate(){
  458. if( m_vResultPool.size() ){ // Clear structures
  459. for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){
  460. #ifdef DEBUG_EXTRA
  461. char tBuffer[256];
  462. sprintf( tBuffer, "Found Camwera [%s] %s", (*index)->XAddrs, (*index)->RefID );
  463. LOG( tBuffer );
  464. #endif
  465. uint32_t cid = m_pDBC->getCamId( (*index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
  466. if( cid ) {
  467. #ifdef DEBUG_EXTRA
  468. sprintf( tBuffer, "Camera is Listed as %d", cid );
  469. LOG( tBuffer );
  470. #endif
  471. m_pDBC->updateIPCam( m_pKernel->getSiteId(), cid, (*index)->XAddrs );// DiscoverResults->at(index));
  472. } else {
  473. // Uncknown camera - no checking
  474. #ifdef DEBUG_EXTRA
  475. LOG("Camera is Not Listed");
  476. #endif
  477. m_pDBC->addIPCam( m_pKernel->getSiteId(), (*index) );
  478. };
  479. free(*index);
  480. }
  481. m_vResultPool.clear();
  482. #ifdef DEBUG_EXTRA
  483. LOG("Clear Structs Done!");
  484. #endif
  485. } else {
  486. #ifdef DEBUG_EXTRA
  487. LOG("No Online IP Cameras in Network");
  488. #endif
  489. };
  490. return true;
  491. };
  492. #undef LOG
  493. #undef LOG_ERROR
  494. #undef TLOG
  495. #undef TLOG_ERROR