FACT++  1.0
void DimServerList::infoHandler ( )
protectedvirtual

A DimInfo to retrieve the SERVER_LIST from teh DNS server.

Whenever the service with the server list is updated this functions changes the contents of the list and calls RemoveAllServers(), RemoveServer() and AddServer() where appropriate.

Implements DimInfoHandler.

Reimplemented in DimServiceInfoList.

Definition at line 54 of file DimServerList.cc.

References DimServerListImp::AddServer(), buffer, fDimServers, fList, fServerList, DimInfoHandler::getInfo(), DimInfo::getString(), DimServerListImp::RemoveAllServers(), DimServerListImp::RemoveServer(), and str.

55 {
56  if (getInfo()!=&fDimServers)
57  return;
58 
59  // Get the received string from the handler
60  const string str = fDimServers.getString();
61 
62  // Check if it starts with + or -
63  if (str[0]!='-' && str[0]!='+')
64  {
66  fServerList.clear();
67  }
68 
69  // Create a stringstream to tokenize the received string
70  stringstream stream(str);
71 
72  // Loop over the seperating tokens
73  string buffer;
74  while (getline(stream, buffer, '|'))
75  {
76  // The first part before the first @ is the server name
77  const string server = buffer.substr(0, buffer.find_first_of('@'));
78  if (server.empty())
79  continue;
80 
81  // If it starts with a - we have to remove an entry
82  if (server[0]=='-')
83  {
84  const string trunc = server.substr(1);
85 
86  // Check if this server is not found in the list.
87  // This should never happen if Dim works reliable
88  const ServerList::iterator v = find(fServerList.begin(), fServerList.end(), trunc);
89  if (v==fServerList.end())
90  {
91  //stringstream err;
92  //err << "DimServerList: Server '" << trunc << "' not in list as it ought to be.";
93  //throw runtime_error(err.str());
94  }
95 
96  fList->RemoveServer(trunc);
97  fServerList.erase(v);
98 
99  continue;
100  }
101 
102  // If it starts with a + we have to add an entry
103  if (server[0]=='+')
104  {
105  const string trunc = server.substr(1);
106 
107  // Check if this server is already in the list.
108  // This should never happen if Dim works reliable
109  const ServerList::iterator v = find(fServerList.begin(), fServerList.end(), trunc);
110  if (v!=fServerList.end())
111  {
112  fList->RemoveServer(trunc);
113  fServerList.erase(v);
114 
115  //stringstream err;
116  //err << "DimServerList: Server '" << trunc << "' in list not as it ought to be.";
117  //throw runtime_error(err.str());
118  }
119 
120  fServerList.push_back(trunc);
121  fList->AddServer(trunc);
122 
123  continue;
124  }
125 
126  // In any other case we just add the entry to the list
127  fServerList.push_back(server);
128  fList->AddServer(server);
129  }
130 }
char * getString()
Definition: dic.hxx:108
virtual void RemoveAllServers()
Definition: DimServerList.h:45
char str[80]
Definition: test_client.c:7
virtual void AddServer(const std::string &)
Definition: DimServerList.h:43
DimServerListImp * fList
Definition: DimServerList.h:17
virtual void RemoveServer(std::string)
Definition: DimServerList.h:44
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
DimInfo * getInfo()
Definition: dic.hxx:26
DimInfo fDimServers
A list with the available servers.
Definition: DimServerList.h:19
ServerList fServerList
Definition: DimServerList.h:18

+ Here is the call graph for this function: