MCPcopy Create free account
hub / github.com/apache/trafficserver / load_config

Function load_config

plugins/regex_revalidate/regex_revalidate.cc:366–497  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364}
365
366static bool
367load_config(plugin_state_t *pstate, invalidate_t **ilist)
368{
369 size_t path_len;
370 char *path;
371
372 if (pstate->config_path[0] != '/') {
373 path_len = strlen(TSConfigDirGet()) + strlen(pstate->config_path) + 2;
374 path = static_cast<char *>(alloca(path_len));
375 snprintf(path, path_len, "%s/%s", TSConfigDirGet(), pstate->config_path);
376 } else {
377 path = pstate->config_path;
378 }
379
380 int const fd = open(path, O_RDONLY);
381 if (fd < 0) {
382 Dbg(dbg_ctl, "Could not open %s for reading", path);
383 return false;
384 }
385
386 struct stat s;
387 if (fstat(fd, &s) < 0) {
388 Dbg(dbg_ctl, "Could not stat %s", path);
389 close(fd);
390 return false;
391 }
392
393 // Don't load if mod time is older than our copy
394 if (pstate->last_load < s.st_mtime) {
395 time_t const now = time(nullptr);
396
397 FILE *const fs = fdopen(fd, "r");
398 if (NULL == fs) {
399 Dbg(dbg_ctl, "Could not open %s for reading", path);
400 close(fd);
401 return false;
402 }
403
404 Dbg(dbg_ctl, "Attempting to load rules from: '%s'", path);
405 const char *errptr;
406 int erroffset;
407 int ovector[OVECTOR_SIZE];
408 pcre *const config_re = pcre_compile("^([^#].+?)\\s+(\\d+)(\\s+(\\w+))?\\s*$", 0, &errptr, &erroffset, nullptr);
409 TSReleaseAssert(nullptr != config_re);
410
411 char line[LINE_MAX];
412 int ln = 0;
413 invalidate_t *iptr, *i;
414
415 while (fgets(line, LINE_MAX, fs) != nullptr) {
416 Dbg(dbg_ctl, "Processing: %d %s", ln, line);
417 ++ln;
418 int const rc = pcre_exec(config_re, nullptr, line, strlen(line), 0, 0, ovector, OVECTOR_SIZE);
419
420 if (3 <= rc) {
421 i = (invalidate_t *)TSmalloc(sizeof(invalidate_t));
422 init_invalidate_t(i);
423 pcre_get_substring(line, ovector, rc, 1, &i->regex_text);

Callers 2

config_handlerFunction · 0.85
TSPluginInitFunction · 0.85

Calls 7

TSConfigDirGetFunction · 0.85
pcre_execFunction · 0.85
TSmallocFunction · 0.85
init_invalidate_tFunction · 0.85
free_invalidate_tFunction · 0.85
strForResultFunction · 0.85
strcmpFunction · 0.85

Tested by

no test coverage detected