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...
| 38 | // syntax for remap vs global plugin initialization, and the global BG fetch state :-/. Clean up |
| 39 | // later... |
| 40 | bool |
| 41 | BgFetchConfig::parseOptions(int argc, const char *argv[]) |
| 42 | { |
| 43 | static const struct option longopt[] = { |
| 44 | {const_cast<char *>("log"), required_argument, nullptr, 'l' }, |
| 45 | {const_cast<char *>("config"), required_argument, nullptr, 'c' }, |
| 46 | {const_cast<char *>("allow-304"), no_argument, nullptr, 'a' }, |
| 47 | {nullptr, no_argument, nullptr, '\0'} |
| 48 | }; |
| 49 | |
| 50 | while (true) { |
| 51 | int opt = getopt_long(argc, const_cast<char *const *>(argv), "lc", longopt, nullptr); |
| 52 | |
| 53 | if (opt == -1) { |
| 54 | break; |
| 55 | } |
| 56 | |
| 57 | switch (opt) { |
| 58 | case 'l': |
| 59 | Dbg(Bg_dbg_ctl, "option: log file specified: %s", optarg); |
| 60 | _log_file = optarg; |
| 61 | break; |
| 62 | case 'c': |
| 63 | Dbg(Bg_dbg_ctl, "option: config file '%s'", optarg); |
| 64 | if (!readConfig(optarg)) { |
| 65 | // Error messages are written in the parser |
| 66 | return false; |
| 67 | } |
| 68 | break; |
| 69 | case 'a': |
| 70 | Dbg(Bg_dbg_ctl, "option: --allow-304 set"); |
| 71 | _allow_304 = true; |
| 72 | break; |
| 73 | default: |
| 74 | TSError("[%s] invalid plugin option: %c", PLUGIN_NAME, opt); |
| 75 | return false; |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return true; |
| 81 | } |
| 82 | |
| 83 | // Read a config file, populate the linked list (chain the BgFetchRule's) |
| 84 | bool |
no test coverage detected