| 724 | } |
| 725 | |
| 726 | static AuthOptions * |
| 727 | AuthParseOptions(int argc, const char **argv) |
| 728 | { |
| 729 | // The const_cast<> here is magic to work around a flaw in the definition of struct option |
| 730 | // on some platform. On sane platforms (e.g. linux), it'll get automatically casted back |
| 731 | // to the const char*, as the struct is defined in <getopt.h>. |
| 732 | static const struct option longopt[] = { |
| 733 | {const_cast<char *>("auth-host"), required_argument, nullptr, 'h'}, |
| 734 | {const_cast<char *>("auth-port"), required_argument, nullptr, 'p'}, |
| 735 | {const_cast<char *>("auth-transform"), required_argument, nullptr, 't'}, |
| 736 | {const_cast<char *>("force-cacheability"), no_argument, nullptr, 'c'}, |
| 737 | {const_cast<char *>("cache-internal"), no_argument, nullptr, 'i'}, |
| 738 | {const_cast<char *>("forward-header-prefix"), required_argument, nullptr, 'f'}, |
| 739 | {nullptr, 0, nullptr, 0 }, |
| 740 | }; |
| 741 | |
| 742 | AuthOptions *options = AuthNew<AuthOptions>(); |
| 743 | |
| 744 | options->transform = AuthWriteRedirectedRequest; |
| 745 | |
| 746 | for (;;) { |
| 747 | int opt; |
| 748 | |
| 749 | opt = getopt_long(argc, const_cast<char *const *>(argv), "", longopt, nullptr); |
| 750 | switch (opt) { |
| 751 | case 'h': |
| 752 | options->hostname = optarg; |
| 753 | break; |
| 754 | case 'p': |
| 755 | options->hostport = std::atoi(optarg); |
| 756 | break; |
| 757 | case 'c': |
| 758 | options->force = true; |
| 759 | break; |
| 760 | case 'i': |
| 761 | options->cache_internal_requests = true; |
| 762 | break; |
| 763 | case 'f': |
| 764 | options->forward_header_prefix = optarg; |
| 765 | break; |
| 766 | case 't': |
| 767 | if (strcasecmp(optarg, "redirect") == 0) { |
| 768 | options->transform = AuthWriteRedirectedRequest; |
| 769 | } else if (strcasecmp(optarg, "head") == 0) { |
| 770 | options->transform = AuthWriteHeadRequest; |
| 771 | } else if (strcasecmp(optarg, "range") == 0) { |
| 772 | options->transform = AuthWriteRangeRequest; |
| 773 | } else { |
| 774 | AuthLogError("invalid authorization transform '%s'", optarg); |
| 775 | // XXX make this a fatal error? |
| 776 | } |
| 777 | break; |
| 778 | } |
| 779 | |
| 780 | if (opt == -1) { |
| 781 | break; |
| 782 | } |
| 783 | } |
no test coverage detected