2012-06-04 16:48:31 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-06-04 16:48:31 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "shrpx_config.h"
|
|
|
|
|
2015-05-13 15:30:35 +02:00
|
|
|
#ifdef HAVE_PWD_H
|
2012-08-01 17:06:41 +02:00
|
|
|
#include <pwd.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_PWD_H
|
|
|
|
#ifdef HAVE_NETDB_H
|
2012-08-01 17:06:41 +02:00
|
|
|
#include <netdb.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_NETDB_H
|
|
|
|
#ifdef HAVE_SYSLOG_H
|
2012-08-01 18:20:18 +02:00
|
|
|
#include <syslog.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_SYSLOG_H
|
2012-12-03 07:33:04 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#ifdef HAVE_FCNTL_H
|
2015-01-06 16:25:10 +01:00
|
|
|
#include <fcntl.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_FCNTL_H
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2012-12-03 07:33:04 +01:00
|
|
|
#include <unistd.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_UNISTD_H
|
2012-08-01 17:06:41 +02:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <cerrno>
|
|
|
|
#include <limits>
|
|
|
|
#include <fstream>
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#include <nghttp2/nghttp2.h>
|
2013-02-22 13:54:07 +01:00
|
|
|
|
2013-08-27 19:47:22 +02:00
|
|
|
#include "http-parser/http_parser.h"
|
|
|
|
|
2012-08-01 17:26:24 +02:00
|
|
|
#include "shrpx_log.h"
|
2013-02-06 15:27:05 +01:00
|
|
|
#include "shrpx_ssl.h"
|
2013-02-09 08:42:01 +01:00
|
|
|
#include "shrpx_http.h"
|
2013-08-27 19:47:22 +02:00
|
|
|
#include "http2.h"
|
2012-08-01 17:06:41 +02:00
|
|
|
#include "util.h"
|
2015-02-05 15:21:53 +01:00
|
|
|
#include "template.h"
|
2012-08-01 17:06:41 +02:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
using namespace nghttp2;
|
2012-08-01 17:06:41 +02:00
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
namespace shrpx {
|
|
|
|
|
|
|
|
namespace {
|
2013-10-02 16:13:25 +02:00
|
|
|
Config *config = nullptr;
|
2012-06-04 16:48:31 +02:00
|
|
|
} // namespace
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
const Config *get_config() { return config; }
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
Config *mod_config() { return config; }
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void create_config() { config = new Config(); }
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2015-01-07 16:01:09 +01:00
|
|
|
TicketKeys::~TicketKeys() {
|
|
|
|
/* Erase keys from memory */
|
|
|
|
for (auto &key : keys) {
|
|
|
|
memset(&key, 0, sizeof(key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 17:06:41 +02:00
|
|
|
namespace {
|
|
|
|
int split_host_port(char *host, size_t hostlen, uint16_t *port_ptr,
|
2014-11-27 15:39:04 +01:00
|
|
|
const char *hostport) {
|
2012-08-01 17:06:41 +02:00
|
|
|
// host and port in |hostport| is separated by single ','.
|
|
|
|
const char *p = strchr(hostport, ',');
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!p) {
|
2012-08-01 17:26:24 +02:00
|
|
|
LOG(ERROR) << "Invalid host, port: " << hostport;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
size_t len = p - hostport;
|
|
|
|
if (hostlen < len + 1) {
|
2012-08-01 17:26:24 +02:00
|
|
|
LOG(ERROR) << "Hostname too long: " << hostport;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy(host, hostport, len);
|
|
|
|
host[len] = '\0';
|
|
|
|
|
|
|
|
errno = 0;
|
2014-11-27 15:39:04 +01:00
|
|
|
unsigned long d = strtoul(p + 1, nullptr, 10);
|
|
|
|
if (errno == 0 && 1 <= d && d <= std::numeric_limits<uint16_t>::max()) {
|
2012-08-01 17:06:41 +02:00
|
|
|
*port_ptr = d;
|
|
|
|
return 0;
|
|
|
|
} else {
|
2014-11-27 15:39:04 +01:00
|
|
|
LOG(ERROR) << "Port is invalid: " << p + 1;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-12-07 15:14:20 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
bool is_secure(const char *filename) {
|
2012-12-03 07:33:04 +01:00
|
|
|
struct stat buf;
|
|
|
|
int rv = stat(filename, &buf);
|
|
|
|
if (rv == 0) {
|
2014-11-27 15:39:04 +01:00
|
|
|
if ((buf.st_mode & S_IRWXU) && !(buf.st_mode & S_IRWXG) &&
|
2012-12-03 07:33:04 +01:00
|
|
|
!(buf.st_mode & S_IRWXO)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-07 15:14:20 +01:00
|
|
|
} // namespace
|
2012-12-03 07:33:04 +01:00
|
|
|
|
2015-01-07 17:26:30 +01:00
|
|
|
std::unique_ptr<TicketKeys>
|
|
|
|
read_tls_ticket_key_file(const std::vector<std::string> &files) {
|
2015-02-05 15:21:53 +01:00
|
|
|
auto ticket_keys = make_unique<TicketKeys>();
|
2015-01-07 17:26:30 +01:00
|
|
|
auto &keys = ticket_keys->keys;
|
|
|
|
keys.resize(files.size());
|
|
|
|
size_t i = 0;
|
|
|
|
for (auto &file : files) {
|
|
|
|
std::ifstream f(file.c_str());
|
|
|
|
if (!f) {
|
|
|
|
LOG(ERROR) << "tls-ticket-key-file: could not open file " << file;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
char buf[48];
|
|
|
|
f.read(buf, sizeof(buf));
|
|
|
|
if (f.gcount() != sizeof(buf)) {
|
|
|
|
LOG(ERROR) << "tls-ticket-key-file: want to read 48 bytes but read "
|
|
|
|
<< f.gcount() << " bytes from " << file;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &key = keys[i++];
|
|
|
|
auto p = buf;
|
|
|
|
memcpy(key.name, p, sizeof(key.name));
|
|
|
|
p += sizeof(key.name);
|
|
|
|
memcpy(key.aes_key, p, sizeof(key.aes_key));
|
|
|
|
p += sizeof(key.aes_key);
|
|
|
|
memcpy(key.hmac_key, p, sizeof(key.hmac_key));
|
|
|
|
|
|
|
|
if (LOG_ENABLED(INFO)) {
|
|
|
|
LOG(INFO) << "session ticket key: " << util::format_hex(key.name,
|
|
|
|
sizeof(key.name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ticket_keys;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
FILE *open_file_for_write(const char *filename) {
|
2015-01-22 15:20:16 +01:00
|
|
|
#if defined O_CLOEXEC
|
2015-01-06 16:25:10 +01:00
|
|
|
auto fd = open(filename, O_WRONLY | O_CLOEXEC | O_CREAT | O_TRUNC,
|
|
|
|
S_IRUSR | S_IWUSR);
|
2015-01-22 15:20:16 +01:00
|
|
|
#else
|
|
|
|
auto fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
|
|
|
|
|
|
|
// We get race condition if execve is called at the same time.
|
|
|
|
if (fd != -1) {
|
2015-03-02 21:14:09 +01:00
|
|
|
util::make_socket_closeonexec(fd);
|
2015-01-22 15:20:16 +01:00
|
|
|
}
|
|
|
|
#endif
|
2015-01-06 16:25:10 +01:00
|
|
|
if (fd == -1) {
|
|
|
|
LOG(ERROR) << "Failed to open " << filename
|
|
|
|
<< " for writing. Cause: " << strerror(errno);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto f = fdopen(fd, "wb");
|
2014-11-27 15:39:04 +01:00
|
|
|
if (f == nullptr) {
|
|
|
|
LOG(ERROR) << "Failed to open " << filename
|
|
|
|
<< " for writing. Cause: " << strerror(errno);
|
2014-08-19 17:17:50 +02:00
|
|
|
return nullptr;
|
2013-11-17 15:52:19 +01:00
|
|
|
}
|
2014-08-12 15:22:02 +02:00
|
|
|
|
2013-11-17 15:52:19 +01:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
std::string read_passwd_from_file(const char *filename) {
|
2012-12-03 07:33:04 +01:00
|
|
|
std::string line;
|
|
|
|
|
|
|
|
if (!is_secure(filename)) {
|
|
|
|
LOG(ERROR) << "Private key passwd file " << filename
|
|
|
|
<< " has insecure mode.";
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ifstream in(filename, std::ios::binary);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!in) {
|
2012-12-03 07:33:04 +01:00
|
|
|
LOG(ERROR) << "Could not open key passwd file " << filename;
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::getline(in, line);
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
std::unique_ptr<char[]> strcopy(const char *val) {
|
2014-11-18 16:56:44 +01:00
|
|
|
return strcopy(val, strlen(val));
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
std::unique_ptr<char[]> strcopy(const char *val, size_t len) {
|
2015-02-05 15:21:53 +01:00
|
|
|
auto res = make_unique<char[]>(len + 1);
|
2014-11-18 16:56:44 +01:00
|
|
|
memcpy(res.get(), val, len);
|
|
|
|
res[len] = '\0';
|
2014-06-08 14:02:40 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
std::unique_ptr<char[]> strcopy(const std::string &val) {
|
2014-11-18 16:56:44 +01:00
|
|
|
return strcopy(val.c_str(), val.size());
|
2012-08-01 17:06:41 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
std::vector<char *> parse_config_str_list(const char *s) {
|
2013-09-23 13:55:39 +02:00
|
|
|
size_t len = 1;
|
2014-11-27 15:39:04 +01:00
|
|
|
for (const char *first = s, *p = nullptr; (p = strchr(first, ','));
|
|
|
|
++len, first = p + 1)
|
|
|
|
;
|
|
|
|
auto list = std::vector<char *>(len);
|
2014-01-02 03:13:07 +01:00
|
|
|
auto first = strdup(s);
|
2013-09-23 13:55:39 +02:00
|
|
|
len = 0;
|
2014-11-27 15:39:04 +01:00
|
|
|
for (;;) {
|
2013-09-23 13:55:39 +02:00
|
|
|
auto p = strchr(first, ',');
|
2014-11-27 15:39:04 +01:00
|
|
|
if (p == nullptr) {
|
2013-09-23 13:55:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
list[len++] = first;
|
|
|
|
*p = '\0';
|
|
|
|
first = p + 1;
|
|
|
|
}
|
|
|
|
list[len++] = first;
|
2014-06-08 15:52:27 +02:00
|
|
|
|
2014-01-02 03:13:07 +01:00
|
|
|
return list;
|
2013-09-23 13:55:39 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void clear_config_str_list(std::vector<char *> &list) {
|
|
|
|
if (list.empty()) {
|
2014-06-08 15:52:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(list[0]);
|
|
|
|
list.clear();
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
std::pair<std::string, std::string> parse_header(const char *optarg) {
|
2014-04-26 07:56:08 +02:00
|
|
|
// We skip possible ":" at the start of optarg.
|
|
|
|
const auto *colon = strchr(optarg + 1, ':');
|
|
|
|
|
|
|
|
// name = ":" is not allowed
|
2014-11-27 15:39:04 +01:00
|
|
|
if (colon == nullptr || (optarg[0] == ':' && colon == optarg + 1)) {
|
2014-04-26 07:56:08 +02:00
|
|
|
return {"", ""};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto value = colon + 1;
|
2014-11-27 15:39:04 +01:00
|
|
|
for (; *value == '\t' || *value == ' '; ++value)
|
|
|
|
;
|
2014-04-26 07:56:08 +02:00
|
|
|
|
|
|
|
return {std::string(optarg, colon), std::string(value, strlen(value))};
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
template <typename T>
|
|
|
|
int parse_uint(T *dest, const char *opt, const char *optarg) {
|
2014-08-27 16:36:36 +02:00
|
|
|
char *end = nullptr;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
auto val = strtol(optarg, &end, 10);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!optarg[0] || errno != 0 || *end || val < 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": bad value. Specify an integer >= 0.";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest = val;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:54:53 +01:00
|
|
|
namespace {
|
|
|
|
template <typename T>
|
|
|
|
int parse_uint_with_unit(T *dest, const char *opt, const char *optarg) {
|
|
|
|
auto n = util::parse_uint_with_unit(optarg);
|
|
|
|
if (n == -1) {
|
|
|
|
LOG(ERROR) << opt << ": bad value: '" << optarg << "'";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest = n;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
template <typename T>
|
|
|
|
int parse_int(T *dest, const char *opt, const char *optarg) {
|
2014-08-27 16:36:36 +02:00
|
|
|
char *end = nullptr;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
auto val = strtol(optarg, &end, 10);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!optarg[0] || errno != 0 || *end) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": bad value. Specify an integer.";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest = val;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-18 16:56:44 +01:00
|
|
|
namespace {
|
|
|
|
LogFragment make_log_fragment(LogFragmentType type,
|
2014-11-27 15:39:04 +01:00
|
|
|
std::unique_ptr<char[]> value = nullptr) {
|
2014-11-18 16:56:44 +01:00
|
|
|
return LogFragment{type, std::move(value)};
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
bool var_token(char c) {
|
2014-11-18 16:56:44 +01:00
|
|
|
return util::isAlpha(c) || util::isDigit(c) || c == '_';
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
std::vector<LogFragment> parse_log_format(const char *optarg) {
|
2014-11-18 16:56:44 +01:00
|
|
|
auto literal_start = optarg;
|
|
|
|
auto p = optarg;
|
|
|
|
auto eop = p + strlen(optarg);
|
|
|
|
|
|
|
|
auto res = std::vector<LogFragment>();
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (; p != eop;) {
|
|
|
|
if (*p != '$') {
|
2014-11-18 16:56:44 +01:00
|
|
|
++p;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto var_start = p;
|
|
|
|
|
|
|
|
++p;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (; p != eop && var_token(*p); ++p)
|
|
|
|
;
|
2014-11-18 16:56:44 +01:00
|
|
|
|
|
|
|
auto varlen = p - var_start;
|
|
|
|
|
|
|
|
auto type = SHRPX_LOGF_NONE;
|
|
|
|
const char *value = nullptr;
|
|
|
|
size_t valuelen = 0;
|
|
|
|
|
2015-02-22 07:32:48 +01:00
|
|
|
if (util::strieq_l("$remote_addr", var_start, varlen)) {
|
2014-11-18 16:56:44 +01:00
|
|
|
type = SHRPX_LOGF_REMOTE_ADDR;
|
2015-02-22 07:32:48 +01:00
|
|
|
} else if (util::strieq_l("$time_local", var_start, varlen)) {
|
2014-11-18 16:56:44 +01:00
|
|
|
type = SHRPX_LOGF_TIME_LOCAL;
|
2015-02-22 07:32:48 +01:00
|
|
|
} else if (util::strieq_l("$time_iso8601", var_start, varlen)) {
|
2014-11-19 17:53:30 +01:00
|
|
|
type = SHRPX_LOGF_TIME_ISO8601;
|
2015-02-22 07:32:48 +01:00
|
|
|
} else if (util::strieq_l("$request", var_start, varlen)) {
|
2014-11-18 16:56:44 +01:00
|
|
|
type = SHRPX_LOGF_REQUEST;
|
2015-02-22 07:32:48 +01:00
|
|
|
} else if (util::strieq_l("$status", var_start, varlen)) {
|
2014-11-18 16:56:44 +01:00
|
|
|
type = SHRPX_LOGF_STATUS;
|
2015-02-22 07:32:48 +01:00
|
|
|
} else if (util::strieq_l("$body_bytes_sent", var_start, varlen)) {
|
2014-11-18 16:56:44 +01:00
|
|
|
type = SHRPX_LOGF_BODY_BYTES_SENT;
|
2014-11-27 15:39:04 +01:00
|
|
|
} else if (util::istartsWith(var_start, varlen, "$http_")) {
|
2014-11-18 16:56:44 +01:00
|
|
|
type = SHRPX_LOGF_HTTP;
|
|
|
|
value = var_start + sizeof("$http_") - 1;
|
|
|
|
valuelen = varlen - (sizeof("$http_") - 1);
|
2015-02-22 07:32:48 +01:00
|
|
|
} else if (util::strieq_l("$remote_port", var_start, varlen)) {
|
2014-11-19 17:53:30 +01:00
|
|
|
type = SHRPX_LOGF_REMOTE_PORT;
|
2015-02-22 07:32:48 +01:00
|
|
|
} else if (util::strieq_l("$server_port", var_start, varlen)) {
|
2014-11-19 17:53:30 +01:00
|
|
|
type = SHRPX_LOGF_SERVER_PORT;
|
2015-02-22 07:32:48 +01:00
|
|
|
} else if (util::strieq_l("$request_time", var_start, varlen)) {
|
2014-11-19 17:53:30 +01:00
|
|
|
type = SHRPX_LOGF_REQUEST_TIME;
|
2015-02-22 07:32:48 +01:00
|
|
|
} else if (util::strieq_l("$pid", var_start, varlen)) {
|
2014-11-24 06:34:43 +01:00
|
|
|
type = SHRPX_LOGF_PID;
|
2015-02-22 07:32:48 +01:00
|
|
|
} else if (util::strieq_l("$alpn", var_start, varlen)) {
|
2014-11-24 07:22:10 +01:00
|
|
|
type = SHRPX_LOGF_ALPN;
|
2014-11-18 16:56:44 +01:00
|
|
|
} else {
|
|
|
|
LOG(WARN) << "Unrecognized log format variable: "
|
|
|
|
<< std::string(var_start, varlen);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (literal_start < var_start) {
|
|
|
|
res.push_back(
|
|
|
|
make_log_fragment(SHRPX_LOGF_LITERAL,
|
|
|
|
strcopy(literal_start, var_start - literal_start)));
|
2014-11-18 16:56:44 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (value == nullptr) {
|
2014-11-18 16:56:44 +01:00
|
|
|
res.push_back(make_log_fragment(type));
|
|
|
|
} else {
|
|
|
|
res.push_back(make_log_fragment(type, strcopy(value, valuelen)));
|
2014-11-27 15:39:04 +01:00
|
|
|
auto &v = res.back().value;
|
|
|
|
for (size_t i = 0; v[i]; ++i) {
|
|
|
|
if (v[i] == '_') {
|
2014-11-18 16:56:44 +01:00
|
|
|
v[i] = '-';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
literal_start = var_start + varlen;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (literal_start != eop) {
|
|
|
|
res.push_back(make_log_fragment(
|
|
|
|
SHRPX_LOGF_LITERAL, strcopy(literal_start, eop - literal_start)));
|
2014-11-18 16:56:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-08-27 16:36:36 +02:00
|
|
|
namespace {
|
2015-01-27 16:36:44 +01:00
|
|
|
int parse_duration(ev_tstamp *dest, const char *opt, const char *optarg) {
|
2015-01-29 15:28:47 +01:00
|
|
|
auto t = util::parse_duration_with_unit(optarg);
|
2015-01-27 16:36:44 +01:00
|
|
|
if (t == std::numeric_limits<double>::infinity()) {
|
|
|
|
LOG(ERROR) << opt << ": bad value: '" << optarg << "'";
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-27 16:36:44 +01:00
|
|
|
*dest = t;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int parse_config(const char *opt, const char *optarg) {
|
2012-08-01 17:06:41 +02:00
|
|
|
char host[NI_MAXHOST];
|
|
|
|
uint16_t port;
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND)) {
|
2015-02-22 04:27:51 +01:00
|
|
|
if (util::istartsWith(optarg, SHRPX_UNIX_PATH_PREFIX)) {
|
|
|
|
DownstreamAddr addr;
|
2015-02-22 09:12:00 +01:00
|
|
|
auto path = optarg + str_size(SHRPX_UNIX_PATH_PREFIX);
|
|
|
|
addr.host = strcopy(path);
|
|
|
|
addr.host_unix = true;
|
2015-02-22 04:27:51 +01:00
|
|
|
|
|
|
|
mod_config()->downstream_addrs.push_back(std::move(addr));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (split_host_port(host, sizeof(host), &port, optarg) == -1) {
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 14:02:40 +02:00
|
|
|
|
2014-12-06 10:31:46 +01:00
|
|
|
DownstreamAddr addr;
|
|
|
|
addr.host = strcopy(host);
|
|
|
|
addr.port = port;
|
|
|
|
|
|
|
|
mod_config()->downstream_addrs.push_back(std::move(addr));
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND)) {
|
2015-02-22 09:01:19 +01:00
|
|
|
if (util::istartsWith(optarg, SHRPX_UNIX_PATH_PREFIX)) {
|
|
|
|
auto path = optarg + str_size(SHRPX_UNIX_PATH_PREFIX);
|
|
|
|
mod_config()->host = strcopy(path);
|
|
|
|
mod_config()->port = 0;
|
|
|
|
mod_config()->host_unix = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (split_host_port(host, sizeof(host), &port, optarg) == -1) {
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 14:02:40 +02:00
|
|
|
|
|
|
|
mod_config()->host = strcopy(host);
|
|
|
|
mod_config()->port = port;
|
2015-02-22 09:01:19 +01:00
|
|
|
mod_config()->host_unix = false;
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_WORKERS)) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return parse_uint(&mod_config()->num_worker, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_HTTP2_MAX_CONCURRENT_STREAMS)) {
|
|
|
|
return parse_uint(&mod_config()->http2_max_concurrent_streams, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_LOG_LEVEL)) {
|
|
|
|
if (Log::set_severity_level_by_name(optarg) == -1) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": Invalid severity level: " << optarg;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_DAEMON)) {
|
2012-08-01 17:06:41 +02:00
|
|
|
mod_config()->daemon = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_HTTP2_PROXY)) {
|
2013-11-04 10:14:05 +01:00
|
|
|
mod_config()->http2_proxy = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_HTTP2_BRIDGE)) {
|
2013-11-04 10:14:05 +01:00
|
|
|
mod_config()->http2_bridge = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_CLIENT_PROXY)) {
|
2012-11-21 14:10:35 +01:00
|
|
|
mod_config()->client_proxy = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_ADD_X_FORWARDED_FOR)) {
|
2012-08-01 17:06:41 +02:00
|
|
|
mod_config()->add_x_forwarded_for = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_STRIP_INCOMING_X_FORWARDED_FOR)) {
|
2014-10-24 15:24:17 +02:00
|
|
|
mod_config()->strip_incoming_x_forwarded_for = util::strieq(optarg, "yes");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_NO_VIA)) {
|
2013-01-09 14:01:25 +01:00
|
|
|
mod_config()->no_via = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_HTTP2_READ_TIMEOUT)) {
|
2015-01-27 16:36:44 +01:00
|
|
|
return parse_duration(&mod_config()->http2_upstream_read_timeout, opt,
|
|
|
|
optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_READ_TIMEOUT)) {
|
2015-01-27 16:36:44 +01:00
|
|
|
return parse_duration(&mod_config()->upstream_read_timeout, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_WRITE_TIMEOUT)) {
|
2015-01-27 16:36:44 +01:00
|
|
|
return parse_duration(&mod_config()->upstream_write_timeout, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_READ_TIMEOUT)) {
|
2015-01-27 16:36:44 +01:00
|
|
|
return parse_duration(&mod_config()->downstream_read_timeout, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_WRITE_TIMEOUT)) {
|
2015-01-27 16:36:44 +01:00
|
|
|
return parse_duration(&mod_config()->downstream_write_timeout, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_STREAM_READ_TIMEOUT)) {
|
2015-01-27 16:36:44 +01:00
|
|
|
return parse_duration(&mod_config()->stream_read_timeout, opt, optarg);
|
2014-08-09 11:47:45 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_STREAM_WRITE_TIMEOUT)) {
|
2015-01-27 16:36:44 +01:00
|
|
|
return parse_duration(&mod_config()->stream_write_timeout, opt, optarg);
|
2014-08-09 11:47:45 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_ACCESSLOG_FILE)) {
|
2014-07-05 11:22:40 +02:00
|
|
|
mod_config()->accesslog_file = strcopy(optarg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_ACCESSLOG_SYSLOG)) {
|
2014-07-05 11:22:40 +02:00
|
|
|
mod_config()->accesslog_syslog = util::strieq(optarg, "yes");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_ACCESSLOG_FORMAT)) {
|
2014-11-18 16:56:44 +01:00
|
|
|
mod_config()->accesslog_format = parse_log_format(optarg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_ERRORLOG_FILE)) {
|
2014-07-05 11:22:40 +02:00
|
|
|
mod_config()->errorlog_file = strcopy(optarg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_ERRORLOG_SYSLOG)) {
|
2014-07-05 11:22:40 +02:00
|
|
|
mod_config()->errorlog_syslog = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT)) {
|
2015-01-27 16:36:44 +01:00
|
|
|
return parse_duration(&mod_config()->downstream_idle_read_timeout, opt,
|
|
|
|
optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS) ||
|
|
|
|
util::strieq(opt, SHRPX_OPT_BACKEND_HTTP2_WINDOW_BITS)) {
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2012-11-21 15:47:48 +01:00
|
|
|
size_t *resp;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS)) {
|
2013-11-04 10:14:05 +01:00
|
|
|
resp = &mod_config()->http2_upstream_window_bits;
|
2012-11-21 15:47:48 +01:00
|
|
|
} else {
|
2013-11-04 10:14:05 +01:00
|
|
|
resp = &mod_config()->http2_downstream_window_bits;
|
2012-11-21 15:47:48 +01:00
|
|
|
}
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2012-08-01 17:06:41 +02:00
|
|
|
errno = 0;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
|
|
|
int n;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (parse_uint(&n, opt, optarg) != 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (n >= 31) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt
|
|
|
|
<< ": specify the integer in the range [0, 30], inclusive";
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
2014-08-27 16:36:36 +02:00
|
|
|
*resp = n;
|
|
|
|
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS) ||
|
|
|
|
util::strieq(opt, SHRPX_OPT_BACKEND_HTTP2_CONNECTION_WINDOW_BITS)) {
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2013-11-20 16:15:17 +01:00
|
|
|
size_t *resp;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS)) {
|
2013-11-20 16:15:17 +01:00
|
|
|
resp = &mod_config()->http2_upstream_connection_window_bits;
|
|
|
|
} else {
|
|
|
|
resp = &mod_config()->http2_downstream_connection_window_bits;
|
|
|
|
}
|
2014-08-27 16:36:36 +02:00
|
|
|
|
2013-11-20 16:15:17 +01:00
|
|
|
errno = 0;
|
2014-08-27 16:36:36 +02:00
|
|
|
|
|
|
|
int n;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (parse_uint(&n, opt, optarg) != 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (n < 16 || n >= 31) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt
|
|
|
|
<< ": specify the integer in the range [16, 30], inclusive";
|
2013-11-20 16:15:17 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
2014-08-27 16:36:36 +02:00
|
|
|
*resp = n;
|
|
|
|
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_NO_TLS)) {
|
2013-08-03 12:01:57 +02:00
|
|
|
mod_config()->upstream_no_tls = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_NO_TLS)) {
|
2013-08-03 12:01:57 +02:00
|
|
|
mod_config()->downstream_no_tls = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_TLS_SNI_FIELD)) {
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->backend_tls_sni_name = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_PID_FILE)) {
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->pid_file = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_USER)) {
|
2013-10-02 16:13:25 +02:00
|
|
|
auto pwd = getpwnam(optarg);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!pwd) {
|
|
|
|
LOG(ERROR) << opt << ": failed to get uid from " << optarg << ": "
|
|
|
|
<< strerror(errno);
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2015-01-26 15:41:38 +01:00
|
|
|
mod_config()->user = strcopy(pwd->pw_name);
|
2012-08-01 17:06:41 +02:00
|
|
|
mod_config()->uid = pwd->pw_uid;
|
|
|
|
mod_config()->gid = pwd->pw_gid;
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_PRIVATE_KEY_FILE)) {
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->private_key_file = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE)) {
|
2013-10-02 16:13:25 +02:00
|
|
|
auto passwd = read_passwd_from_file(optarg);
|
2012-12-03 07:33:04 +01:00
|
|
|
if (passwd.empty()) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": Couldn't read key file's passwd from " << optarg;
|
2012-12-03 07:33:04 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->private_key_passwd = strcopy(passwd);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_CERTIFICATE_FILE)) {
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->cert_file = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_DH_PARAM_FILE)) {
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->dh_param_file = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_SUBCERT)) {
|
2013-02-06 15:27:05 +01:00
|
|
|
// Private Key file and certificate file separated by ':'.
|
|
|
|
const char *sp = strchr(optarg, ':');
|
2014-11-27 15:39:04 +01:00
|
|
|
if (sp) {
|
2013-02-06 15:27:05 +01:00
|
|
|
std::string keyfile(optarg, sp);
|
|
|
|
// TODO Do we need private key for subcert?
|
2014-11-27 15:39:04 +01:00
|
|
|
mod_config()->subcerts.emplace_back(keyfile, sp + 1);
|
2013-02-06 15:27:05 +01:00
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_SYSLOG_FACILITY)) {
|
2012-08-01 18:20:18 +02:00
|
|
|
int facility = int_syslog_facility(optarg);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (facility == -1) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": Unknown syslog facility: " << optarg;
|
2012-08-01 18:20:18 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
mod_config()->syslog_facility = facility;
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKLOG)) {
|
2014-08-27 16:36:36 +02:00
|
|
|
int n;
|
2014-11-27 15:39:04 +01:00
|
|
|
if (parse_int(&n, opt, optarg) != 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (n < -1) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": " << optarg << " is not allowed";
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_config()->backlog = n;
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_CIPHERS)) {
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->ciphers = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_CLIENT)) {
|
2012-11-21 14:10:35 +01:00
|
|
|
mod_config()->client = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_INSECURE)) {
|
2012-11-22 13:46:15 +01:00
|
|
|
mod_config()->insecure = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_CACERT)) {
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->cacert = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_IPV4)) {
|
2012-11-23 13:11:01 +01:00
|
|
|
mod_config()->backend_ipv4 = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_IPV6)) {
|
2012-11-23 13:11:01 +01:00
|
|
|
mod_config()->backend_ipv6 = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_HTTP_PROXY_URI)) {
|
2013-02-09 08:42:01 +01:00
|
|
|
// parse URI and get hostname, port and optionally userinfo.
|
|
|
|
http_parser_url u;
|
|
|
|
memset(&u, 0, sizeof(u));
|
|
|
|
int rv = http_parser_parse_url(optarg, strlen(optarg), 0, &u);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv == 0) {
|
2013-02-09 08:42:01 +01:00
|
|
|
std::string val;
|
2014-11-27 15:39:04 +01:00
|
|
|
if (u.field_set & UF_USERINFO) {
|
2013-08-27 19:47:22 +02:00
|
|
|
http2::copy_url_component(val, &u, UF_USERINFO, optarg);
|
2013-02-22 13:23:59 +01:00
|
|
|
// Surprisingly, u.field_set & UF_USERINFO is nonzero even if
|
|
|
|
// userinfo component is empty string.
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!val.empty()) {
|
2013-02-22 13:23:59 +01:00
|
|
|
val = util::percentDecode(val.begin(), val.end());
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->downstream_http_proxy_userinfo = strcopy(val);
|
2013-02-22 13:23:59 +01:00
|
|
|
}
|
2013-02-09 08:42:01 +01:00
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (u.field_set & UF_HOST) {
|
2013-08-27 19:47:22 +02:00
|
|
|
http2::copy_url_component(val, &u, UF_HOST, optarg);
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->downstream_http_proxy_host = strcopy(val);
|
2013-02-09 08:42:01 +01:00
|
|
|
} else {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": no hostname specified";
|
2013-02-09 08:42:01 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (u.field_set & UF_PORT) {
|
2013-02-09 08:42:01 +01:00
|
|
|
mod_config()->downstream_http_proxy_port = u.port;
|
|
|
|
} else {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": no port specified";
|
2013-02-09 08:42:01 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": parse error";
|
|
|
|
return -1;
|
2013-02-09 08:42:01 +01:00
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_READ_RATE)) {
|
2015-01-13 13:54:53 +01:00
|
|
|
return parse_uint_with_unit(&mod_config()->read_rate, opt, optarg);
|
2014-08-17 09:17:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_READ_BURST)) {
|
2015-01-13 13:54:53 +01:00
|
|
|
return parse_uint_with_unit(&mod_config()->read_burst, opt, optarg);
|
2014-08-17 09:17:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_WRITE_RATE)) {
|
2015-01-13 13:54:53 +01:00
|
|
|
return parse_uint_with_unit(&mod_config()->write_rate, opt, optarg);
|
2014-08-17 09:17:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_WRITE_BURST)) {
|
2015-01-13 13:54:53 +01:00
|
|
|
return parse_uint_with_unit(&mod_config()->write_burst, opt, optarg);
|
2014-08-17 09:17:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_WORKER_READ_RATE)) {
|
2015-01-02 03:22:39 +01:00
|
|
|
LOG(WARN) << opt << ": not implemented yet";
|
2015-01-13 13:54:53 +01:00
|
|
|
return parse_uint_with_unit(&mod_config()->worker_read_rate, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_WORKER_READ_BURST)) {
|
2015-01-02 03:22:39 +01:00
|
|
|
LOG(WARN) << opt << ": not implemented yet";
|
2015-01-13 13:54:53 +01:00
|
|
|
return parse_uint_with_unit(&mod_config()->worker_read_burst, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_WORKER_WRITE_RATE)) {
|
2015-01-02 03:22:39 +01:00
|
|
|
LOG(WARN) << opt << ": not implemented yet";
|
2015-01-13 13:54:53 +01:00
|
|
|
return parse_uint_with_unit(&mod_config()->worker_write_rate, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_WORKER_WRITE_BURST)) {
|
2015-01-02 03:22:39 +01:00
|
|
|
LOG(WARN) << opt << ": not implemented yet";
|
2015-01-13 13:54:53 +01:00
|
|
|
return parse_uint_with_unit(&mod_config()->worker_write_burst, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_NPN_LIST)) {
|
2014-06-08 15:52:27 +02:00
|
|
|
clear_config_str_list(mod_config()->npn_list);
|
|
|
|
|
|
|
|
mod_config()->npn_list = parse_config_str_list(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_TLS_PROTO_LIST)) {
|
2014-06-08 15:52:27 +02:00
|
|
|
clear_config_str_list(mod_config()->tls_proto_list);
|
|
|
|
|
|
|
|
mod_config()->tls_proto_list = parse_config_str_list(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_VERIFY_CLIENT)) {
|
2013-11-01 17:10:18 +01:00
|
|
|
mod_config()->verify_client = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_VERIFY_CLIENT_CACERT)) {
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->verify_client_cacert = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_CLIENT_PRIVATE_KEY_FILE)) {
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->client_private_key_file = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_CLIENT_CERT_FILE)) {
|
2014-06-08 14:02:40 +02:00
|
|
|
mod_config()->client_cert_file = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_HTTP2_DUMP_REQUEST_HEADER)) {
|
2014-08-12 18:53:44 +02:00
|
|
|
mod_config()->http2_upstream_dump_request_header_file = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER)) {
|
2014-08-12 18:53:44 +02:00
|
|
|
mod_config()->http2_upstream_dump_response_header_file = strcopy(optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_HTTP2_NO_COOKIE_CRUMBLING)) {
|
2013-11-17 16:03:55 +01:00
|
|
|
mod_config()->http2_no_cookie_crumbling = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FRONTEND_FRAME_DEBUG)) {
|
2014-02-09 10:47:26 +01:00
|
|
|
mod_config()->upstream_frame_debug = util::strieq(optarg, "yes");
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_PADDING)) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return parse_uint(&mod_config()->padding, opt, optarg);
|
2014-06-08 16:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_ALTSVC)) {
|
2014-06-08 15:52:27 +02:00
|
|
|
auto tokens = parse_config_str_list(optarg);
|
2014-04-03 06:20:50 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (tokens.size() < 2) {
|
2014-04-08 15:28:50 +02:00
|
|
|
// Requires at least protocol_id and port
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": too few parameters: " << optarg;
|
2014-04-08 15:28:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-04-03 06:20:50 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (tokens.size() > 4) {
|
2014-04-08 15:28:50 +02:00
|
|
|
// We only need protocol_id, port, host and origin
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": too many parameters: " << optarg;
|
2014-04-03 06:20:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-08-27 16:36:36 +02:00
|
|
|
int port;
|
2014-04-08 15:28:50 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (parse_uint(&port, opt, tokens[1]) != 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (port < 1 ||
|
|
|
|
port > static_cast<int>(std::numeric_limits<uint16_t>::max())) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": port is invalid: " << tokens[1];
|
2014-04-08 15:28:50 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
AltSvc altsvc;
|
|
|
|
|
|
|
|
altsvc.port = port;
|
|
|
|
|
|
|
|
altsvc.protocol_id = tokens[0];
|
|
|
|
altsvc.protocol_id_len = strlen(altsvc.protocol_id);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (tokens.size() > 2) {
|
2014-04-08 15:28:50 +02:00
|
|
|
altsvc.host = tokens[2];
|
|
|
|
altsvc.host_len = strlen(altsvc.host);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (tokens.size() > 3) {
|
2014-04-08 15:28:50 +02:00
|
|
|
altsvc.origin = tokens[3];
|
|
|
|
altsvc.origin_len = strlen(altsvc.origin);
|
|
|
|
}
|
|
|
|
}
|
2014-04-03 06:20:50 +02:00
|
|
|
|
2014-04-08 15:28:50 +02:00
|
|
|
mod_config()->altsvcs.push_back(std::move(altsvc));
|
2014-04-03 06:20:50 +02:00
|
|
|
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-05 16:04:20 +02:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_ADD_REQUEST_HEADER) ||
|
|
|
|
util::strieq(opt, SHRPX_OPT_ADD_RESPONSE_HEADER)) {
|
2014-04-26 07:56:08 +02:00
|
|
|
auto p = parse_header(optarg);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (p.first.empty()) {
|
2014-08-27 16:36:36 +02:00
|
|
|
LOG(ERROR) << opt << ": header field name is empty: " << optarg;
|
2014-04-26 07:56:08 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2015-06-05 16:04:20 +02:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_ADD_REQUEST_HEADER)) {
|
|
|
|
mod_config()->add_request_headers.push_back(std::move(p));
|
|
|
|
} else {
|
|
|
|
mod_config()->add_response_headers.push_back(std::move(p));
|
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS)) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return parse_uint(&mod_config()->worker_frontend_connections, opt, optarg);
|
2014-06-26 15:55:22 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_NO_LOCATION_REWRITE)) {
|
2014-08-10 05:39:27 +02:00
|
|
|
mod_config()->no_location_rewrite = util::strieq(optarg, "yes");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-03 17:41:20 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_NO_HOST_REWRITE)) {
|
|
|
|
mod_config()->no_host_rewrite = util::strieq(optarg, "yes");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-04 17:07:00 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_HOST)) {
|
2014-08-27 16:36:36 +02:00
|
|
|
int n;
|
2014-08-16 14:29:20 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (parse_uint(&n, opt, optarg) != 0) {
|
2014-08-27 16:36:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-13 15:23:35 +01:00
|
|
|
if (n == 0) {
|
|
|
|
LOG(ERROR) << opt << ": specify an integer strictly more than 0";
|
2014-08-16 14:29:20 +02:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-12-04 17:07:00 +01:00
|
|
|
mod_config()->downstream_connections_per_host = n;
|
2014-08-16 14:29:20 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-02 04:53:27 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_FRONTEND)) {
|
2015-01-13 15:23:35 +01:00
|
|
|
return parse_uint(&mod_config()->downstream_connections_per_frontend, opt,
|
|
|
|
optarg);
|
2015-01-02 04:53:27 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_LISTENER_DISABLE_TIMEOUT)) {
|
2015-01-27 16:36:44 +01:00
|
|
|
return parse_duration(&mod_config()->listener_disable_timeout, opt, optarg);
|
2014-08-27 15:34:00 +02:00
|
|
|
}
|
|
|
|
|
2015-01-07 17:26:30 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_TLS_TICKET_KEY_FILE)) {
|
|
|
|
mod_config()->tls_ticket_key_files.push_back(optarg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-10 15:17:48 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_RLIMIT_NOFILE)) {
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (parse_uint(&n, opt, optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
LOG(ERROR) << opt << ": specify the integer more than or equal to 0";
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_config()->rlimit_nofile = n;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-13 15:30:28 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_REQUEST_BUFFER) ||
|
|
|
|
util::strieq(opt, SHRPX_OPT_BACKEND_RESPONSE_BUFFER)) {
|
2015-01-13 15:20:06 +01:00
|
|
|
size_t n;
|
|
|
|
if (parse_uint_with_unit(&n, opt, optarg) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == 0) {
|
|
|
|
LOG(ERROR) << opt << ": specify an integer strictly more than 0";
|
2015-01-13 15:23:35 +01:00
|
|
|
|
2015-01-13 15:20:06 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-13 15:30:28 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_REQUEST_BUFFER)) {
|
|
|
|
mod_config()->downstream_request_buffer_size = n;
|
|
|
|
} else {
|
|
|
|
mod_config()->downstream_response_buffer_size = n;
|
|
|
|
}
|
2015-01-13 15:20:06 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-08 08:19:12 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_NO_SERVER_PUSH)) {
|
|
|
|
mod_config()->no_server_push = util::strieq(optarg, "yes");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-10 15:43:25 +01:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_BACKEND_HTTP2_CONNECTIONS_PER_WORKER)) {
|
|
|
|
return parse_uint(&mod_config()->http2_downstream_connections_per_worker,
|
|
|
|
opt, optarg);
|
|
|
|
}
|
|
|
|
|
2015-03-30 16:20:40 +02:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_FETCH_OCSP_RESPONSE_FILE)) {
|
|
|
|
mod_config()->fetch_ocsp_response_file = strcopy(optarg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (util::strieq(opt, SHRPX_OPT_OCSP_UPDATE_INTERVAL)) {
|
|
|
|
return parse_duration(&mod_config()->ocsp_update_interval, opt, optarg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (util::strieq(opt, SHRPX_OPT_NO_OCSP)) {
|
|
|
|
mod_config()->no_ocsp = util::strieq(optarg, "yes");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-29 14:10:59 +02:00
|
|
|
if (util::strieq(opt, SHRPX_OPT_HEADER_FIELD_BUFFER)) {
|
|
|
|
return parse_uint_with_unit(&mod_config()->header_field_buffer, opt,
|
|
|
|
optarg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (util::strieq(opt, SHRPX_OPT_MAX_HEADER_FIELDS)) {
|
|
|
|
return parse_uint(&mod_config()->max_header_fields, opt, optarg);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(opt, "conf")) {
|
2014-11-08 02:51:56 +01:00
|
|
|
LOG(WARN) << "conf: ignored";
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
return 0;
|
2012-08-01 17:06:41 +02:00
|
|
|
}
|
2014-06-08 16:01:48 +02:00
|
|
|
|
|
|
|
LOG(ERROR) << "Unknown option: " << opt;
|
|
|
|
|
|
|
|
return -1;
|
2012-08-01 17:06:41 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int load_config(const char *filename) {
|
2012-08-01 17:06:41 +02:00
|
|
|
std::ifstream in(filename, std::ios::binary);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!in) {
|
2012-08-01 17:26:24 +02:00
|
|
|
LOG(ERROR) << "Could not open config file " << filename;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
std::string line;
|
|
|
|
int linenum = 0;
|
2014-11-27 15:39:04 +01:00
|
|
|
while (std::getline(in, line)) {
|
2012-08-01 17:06:41 +02:00
|
|
|
++linenum;
|
2014-11-27 15:39:04 +01:00
|
|
|
if (line.empty() || line[0] == '#') {
|
2012-08-01 17:06:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
size_t i;
|
|
|
|
size_t size = line.size();
|
2014-11-27 15:39:04 +01:00
|
|
|
for (i = 0; i < size && line[i] != '='; ++i)
|
|
|
|
;
|
|
|
|
if (i == size) {
|
2012-08-01 17:26:24 +02:00
|
|
|
LOG(ERROR) << "Bad configuration format at line " << linenum;
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
line[i] = '\0';
|
2013-10-02 16:13:25 +02:00
|
|
|
auto s = line.c_str();
|
2014-11-27 15:39:04 +01:00
|
|
|
if (parse_config(s, s + i + 1) == -1) {
|
2012-08-01 17:06:41 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
const char *str_syslog_facility(int facility) {
|
|
|
|
switch (facility) {
|
|
|
|
case (LOG_AUTH):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "auth";
|
2015-06-27 10:51:07 +02:00
|
|
|
#ifdef LOG_AUTHPRIV
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_AUTHPRIV):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "authpriv";
|
2015-06-27 10:51:07 +02:00
|
|
|
#endif // LOG_AUTHPRIV
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_CRON):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "cron";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_DAEMON):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "daemon";
|
2015-06-27 10:51:07 +02:00
|
|
|
#ifdef LOG_FTP
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_FTP):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "ftp";
|
2015-06-27 10:51:07 +02:00
|
|
|
#endif // LOG_FTP
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_KERN):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "kern";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL0):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "local0";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL1):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "local1";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL2):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "local2";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL3):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "local3";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL4):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "local4";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL5):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "local5";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL6):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "local6";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LOCAL7):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "local7";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_LPR):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "lpr";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_MAIL):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "mail";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_SYSLOG):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "syslog";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_USER):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "user";
|
2014-11-27 15:39:04 +01:00
|
|
|
case (LOG_UUCP):
|
2012-08-01 18:20:18 +02:00
|
|
|
return "uucp";
|
|
|
|
default:
|
|
|
|
return "(unknown)";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int int_syslog_facility(const char *strfacility) {
|
|
|
|
if (util::strieq(strfacility, "auth")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_AUTH;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2015-06-27 10:51:07 +02:00
|
|
|
#ifdef LOG_AUTHPRIV
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "authpriv")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_AUTHPRIV;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
2015-06-27 10:51:07 +02:00
|
|
|
#endif // LOG_AUTHPRIV
|
2014-06-08 16:03:26 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "cron")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_CRON;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "daemon")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_DAEMON;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2015-06-27 10:51:07 +02:00
|
|
|
#ifdef LOG_FTP
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "ftp")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_FTP;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
2015-06-27 10:51:07 +02:00
|
|
|
#endif // LOG_FTP
|
2014-06-08 16:03:26 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "kern")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_KERN;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "local0")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL0;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "local1")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL1;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "local2")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL2;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "local3")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL3;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "local4")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL4;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "local5")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL5;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "local6")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL6;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "local7")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LOCAL7;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "lpr")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_LPR;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "mail")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_MAIL;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "news")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_NEWS;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "syslog")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_SYSLOG;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "user")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_USER;
|
2014-06-08 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::strieq(strfacility, "uucp")) {
|
2012-08-01 18:20:18 +02:00
|
|
|
return LOG_UUCP;
|
|
|
|
}
|
2014-06-08 16:03:26 +02:00
|
|
|
|
|
|
|
return -1;
|
2012-08-01 18:20:18 +02:00
|
|
|
}
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
} // namespace shrpx
|