1 | #include "DimState.h"
|
---|
2 |
|
---|
3 | using namespace std;
|
---|
4 | using namespace boost;
|
---|
5 |
|
---|
6 | void 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 |
|
---|
47 | void 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 | if (it->at(0)=='-')
|
---|
72 | continue;
|
---|
73 |
|
---|
74 | // Get the type and compare it with fType
|
---|
75 | const string type = it->substr(it->find_last_of('|')+1);
|
---|
76 | if (type=="RPC")
|
---|
77 | continue;
|
---|
78 |
|
---|
79 | //const bool iscmd = type=="CMD";
|
---|
80 | //if (type!=fType && fType!="*")
|
---|
81 | // continue;
|
---|
82 |
|
---|
83 | const size_t first_pipe = it->find_first_of('|');
|
---|
84 | const size_t first_slash = it->find_first_of('/');
|
---|
85 | const size_t last_pipe = it->find_last_of('|');
|
---|
86 |
|
---|
87 | // Get format, name and command name
|
---|
88 | Service service;
|
---|
89 | service.server = it->substr(0, first_slash);
|
---|
90 | service.name = it->substr(0, first_pipe);
|
---|
91 | service.service = it->substr(first_slash+1, first_pipe-first_slash-1);
|
---|
92 | service.format = it->substr(first_pipe +1, last_pipe -first_pipe -1);
|
---|
93 | service.iscmd = type=="CMD";
|
---|
94 |
|
---|
95 | //if (it->at(0)=='+')
|
---|
96 | //{
|
---|
97 | // // Check if this server is not found in the list.
|
---|
98 | // // This should never happen if Dim works reliable
|
---|
99 | // const TypeList::iterator v = list.find(name);
|
---|
100 | // if (v!=list.end())
|
---|
101 | // {
|
---|
102 | // stringstream err;
|
---|
103 | // err << "DimServiceInfoList: Service '" << server << "/" << name << "' already in list not as it ought to be.";
|
---|
104 | // throw runtime_error(err.str());
|
---|
105 | // }
|
---|
106 | //
|
---|
107 | // list[name] = make_pair(fmt, iscmd);
|
---|
108 | // fList->AddService(server, name, fmt, iscmd);
|
---|
109 | //}
|
---|
110 |
|
---|
111 | const auto v = find(fServiceList.begin(), fServiceList.end(), service.name);
|
---|
112 | if (v!=fServiceList.end())
|
---|
113 | continue;
|
---|
114 |
|
---|
115 | CallbackServiceAdd(service);
|
---|
116 | }
|
---|
117 | }
|
---|