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

Method parseOptions

plugins/experimental/cache_fill/configs.cc:41–91  ·  view source on GitHub ↗

Parse the command line options. This got a little wonky, since we decided to have different syntax for remap vs global plugin initialization, and the global BG fetch state :-/. Clean up later...

Source from the content-addressed store, hash-verified

39// syntax for remap vs global plugin initialization, and the global BG fetch state :-/. Clean up
40// later...
41bool
42BgFetchConfig::parseOptions(int argc, const char *argv[])
43{
44 static const struct option longopt[] = {
45 {const_cast<char *>("log"), required_argument, nullptr, 'l' },
46 {const_cast<char *>("config"), required_argument, nullptr, 'c' },
47 {const_cast<char *>("range-req-only"), optional_argument, nullptr, 'r' },
48 {const_cast<char *>("cache-range-req"), optional_argument, nullptr, 'a' },
49 {nullptr, no_argument, nullptr, '\0'},
50 };
51
52 while (true) {
53 int opt = getopt_long(argc, const_cast<char *const *>(argv), "", longopt, nullptr);
54
55 if (opt == -1) {
56 break;
57 }
58 switch (opt) {
59 case 'l':
60 Dbg(dbg_ctl, "option: log file specified: %s", optarg);
61 _log_file = optarg;
62 break;
63 case 'c':
64 Dbg(dbg_ctl, "option: config file '%s'", optarg);
65 if (!readConfig(optarg)) {
66 // Error messages are written in the parser
67 return false;
68 }
69 break;
70 case 'r':
71 Dbg(dbg_ctl, "option: --range-req-only set");
72 _range_req_only = isTrue(optarg);
73 break;
74 case 'a':
75 Dbg(dbg_ctl, "option: --cache-range-req set");
76 _cache_range_req = isTrue(optarg);
77 break;
78 default:
79 TSError("[%s] invalid plugin option: %c", PLUGIN_NAME, opt);
80 return false;
81 break;
82 }
83 }
84
85 if (_range_req_only && !_cache_range_req) {
86 TSError("[%s] Cannot define _range_req_only=true and _cache_range_req=false", PLUGIN_NAME);
87 return false;
88 }
89
90 return true;
91}
92
93// Read a config file, populate the linked list (chain the BgFetchRule's)
94bool

Callers 2

TSPluginInitFunction · 0.45
TSRemapNewInstanceFunction · 0.45

Calls 2

isTrueFunction · 0.50
TSErrorFunction · 0.50

Tested by

no test coverage detected