int ControlMatcher::BuildTable() { Reads the cache.config file and build the records array from it
| 251 | // from it |
| 252 | // |
| 253 | int |
| 254 | CacheHostTable::BuildTableFromString(const char *config_file_path, char *file_buf) |
| 255 | { |
| 256 | Note("%s loading ...", ts::filename::HOSTING); |
| 257 | |
| 258 | // Table build locals |
| 259 | Tokenizer bufTok("\n"); |
| 260 | tok_iter_state i_state; |
| 261 | const char *tmp = nullptr; |
| 262 | matcher_line *first = nullptr; |
| 263 | matcher_line *current = nullptr; |
| 264 | matcher_line *last = nullptr; |
| 265 | int line_num = 0; |
| 266 | int second_pass = 0; |
| 267 | int numEntries = 0; |
| 268 | const char *errPtr = nullptr; |
| 269 | |
| 270 | // type counts |
| 271 | int hostDomain = 0; |
| 272 | |
| 273 | if (bufTok.Initialize(file_buf, SHARE_TOKS | ALLOW_EMPTY_TOKS) == 0) { |
| 274 | // We have an empty file |
| 275 | /* no hosting customers -- put all the volumes in the |
| 276 | generic table */ |
| 277 | if (gen_host_rec.Init(type)) { |
| 278 | Warning("Problems encountered while initializing the Generic Volume"); |
| 279 | } |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | // First get the number of entries |
| 284 | tmp = bufTok.iterFirst(&i_state); |
| 285 | while (tmp != nullptr) { |
| 286 | line_num++; |
| 287 | |
| 288 | // skip all blank spaces at beginning of line |
| 289 | while (*tmp && isspace(*tmp)) { |
| 290 | tmp++; |
| 291 | } |
| 292 | |
| 293 | if (*tmp != '#' && *tmp != '\0') { |
| 294 | current = static_cast<matcher_line *>(ats_malloc(sizeof(matcher_line))); |
| 295 | errPtr = parseConfigLine(const_cast<char *>(tmp), current, &config_tags); |
| 296 | |
| 297 | if (errPtr != nullptr) { |
| 298 | Warning("%s discarding %s entry at line %d : %s", matcher_name, config_file_path, line_num, errPtr); |
| 299 | ats_free(current); |
| 300 | } else { |
| 301 | // Line parsed ok. Figure out what the destination |
| 302 | // type is and link it into our list |
| 303 | numEntries++; |
| 304 | current->line_num = line_num; |
| 305 | |
| 306 | switch (current->type) { |
| 307 | case MATCH_HOST: |
| 308 | case MATCH_DOMAIN: |
| 309 | hostDomain++; |
| 310 | break; |
nothing calls this directly
no test coverage detected