source: trunk/FACT++/src/DimState.cc@ 15470

Last change on this file since 15470 was 14876, checked in by tbretz, 12 years ago
Added a fix for the +services. No easy way to test that... needs testing in real conditions.
File size: 3.0 KB
Line 
1#include "DimState.h"
2
3using namespace std;
4using namespace boost;
5
6void DimDnsServerList::HandlerServerImp(const EventImp &evt)
7{
8 if (evt.GetSize()==0)
9 return;
10
11 time = evt.GetTime();
12 msg = evt.GetString();
13
14 typedef char_separator<char> separator;
15 const tokenizer<separator> tok(msg, separator("|"));
16
17 for (auto it=tok.begin(); it!=tok.end(); it++)
18 {
19 const size_t p = it->find_first_of('@');
20 if (p==string::npos)
21 continue;
22
23 // The first part before the first @ is the server name
24 string server = it->substr(0, p);
25 if (server.empty())
26 continue;
27
28 // If it starts with a - we have to remove an entry
29 if (server[0]=='-')
30 {
31 fServerList.erase(server.substr(1));
32 CallbackServerRemove(server.substr(1));
33 continue;
34 }
35
36 // If it starts with a + we have to add an entry
37 if (server[0]=='+')
38 server = server.substr(1);
39
40 // Check if this server is already in the list.
41 // This should never happen if Dim works reliable
42 if (fServerList.insert(server).second)
43 CallbackServerAdd(server);
44 }
45}
46
47void DimDnsServiceList::HandlerServiceListImp(const EventImp &evt)
48{
49 if (evt.GetSize()==0)
50 return;
51
52 // Get the name of the service
53 //const string svc = getInfo()->getName();
54
55 // Get the server name from the service name
56 //const string server = svc.substr(0, svc.find_first_of('/'));
57 //const string service = svc.substr(svc.find_first_of('/')+1);
58
59 msg = evt.GetString();
60 time = evt.GetTime();
61
62 // Initialize the entry with an empty list
63 //if (msg[0]!='+' && msg[0]!='-')
64 // return;
65
66 typedef char_separator<char> separator;
67 const tokenizer<separator> tok(msg, separator("\n"));
68
69 for (auto it=tok.begin(); it!=tok.end(); it++)
70 {
71 string str = *it;
72
73 if (str[0]=='-')
74 continue;
75
76 if (str[0]=='+')
77 str = str.substr(1);
78
79 const size_t last_pipe = str.find_last_of('|');
80
81 // Get the type and compare it with fType
82 const string type = str.substr(last_pipe+1);
83 if (type=="RPC")
84 continue;
85
86 //const bool iscmd = type=="CMD";
87 //if (type!=fType && fType!="*")
88 // continue;
89
90 const size_t first_pipe = str.find_first_of('|');
91 const size_t first_slash = str.find_first_of('/');
92
93 // Get format, name and command name
94 Service service;
95 service.server = str.substr(0, first_slash);
96 service.name = str.substr(0, first_pipe);
97 service.service = str.substr(first_slash+1, first_pipe-first_slash-1);
98 service.format = str.substr(first_pipe +1, last_pipe -first_pipe -1);
99 service.iscmd = type=="CMD";
100
101 const auto v = find(fServiceList.begin(), fServiceList.end(), service.name);
102 if (v!=fServiceList.end())
103 continue;
104
105 CallbackServiceAdd(service);
106 }
107}
Note: See TracBrowser for help on using the repository browser.