Commit 4d562b77 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Convert LogFragmentType to enum class

parent e6225871
...@@ -44,4 +44,4 @@ HEADERS = [ ...@@ -44,4 +44,4 @@ HEADERS = [
] ]
if __name__ == '__main__': if __name__ == '__main__':
gentokenlookup(HEADERS, 'HD') gentokenlookup(HEADERS, 'HD_')
...@@ -50,4 +50,4 @@ if __name__ == '__main__': ...@@ -50,4 +50,4 @@ if __name__ == '__main__':
continue continue
_, m, _ = line.split(',', 2) _, m, _ = line.split(',', 2)
methods.append(m.strip()) methods.append(m.strip())
gentokenlookup(methods, 'HTTP') gentokenlookup(methods, 'HTTP_')
...@@ -208,5 +208,5 @@ LOGVARS = [ ...@@ -208,5 +208,5 @@ LOGVARS = [
] ]
if __name__ == '__main__': if __name__ == '__main__':
gentokenlookup(OPTIONS, 'SHRPX_OPTID', value_type='char', comp_fun='util::strieq_l') gentokenlookup(OPTIONS, 'SHRPX_OPTID_', value_type='char', comp_fun='util::strieq_l')
gentokenlookup(LOGVARS, 'SHRPX_LOGF', value_type='char', comp_fun='util::strieq_l', return_type='LogFragmentType', fail_value='SHRPX_LOGF_NONE') gentokenlookup(LOGVARS, 'LogFragmentType::', value_type='char', comp_fun='util::strieq_l', return_type='LogFragmentType', fail_value='LogFragmentType::NONE')
#!/usr/bin/env python #!/usr/bin/env python
def to_enum_hd(k, prefix): def to_enum_hd(k, prefix):
res = prefix + '_' res = prefix
for c in k.upper(): for c in k.upper():
if c == ':' or c == '-': if c == ':' or c == '-':
res += '_' res += '_'
...@@ -30,7 +30,7 @@ enum {''' ...@@ -30,7 +30,7 @@ enum {'''
print '''\ print '''\
{},'''.format(to_enum_hd(k, prefix)) {},'''.format(to_enum_hd(k, prefix))
print '''\ print '''\
{}_MAXIDX, {}MAXIDX,
}};'''.format(prefix) }};'''.format(prefix)
def gen_index_header(tokens, prefix, value_type, comp_fun, return_type, fail_value): def gen_index_header(tokens, prefix, value_type, comp_fun, return_type, fail_value):
......
...@@ -379,7 +379,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -379,7 +379,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[2]) { switch (name[2]) {
case 'd': case 'd':
if (util::strieq_l("pi", name, 2)) { if (util::strieq_l("pi", name, 2)) {
return SHRPX_LOGF_PID; return LogFragmentType::PID;
} }
break; break;
} }
...@@ -388,7 +388,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -388,7 +388,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[3]) { switch (name[3]) {
case 'n': case 'n':
if (util::strieq_l("alp", name, 3)) { if (util::strieq_l("alp", name, 3)) {
return SHRPX_LOGF_ALPN; return LogFragmentType::ALPN;
} }
break; break;
} }
...@@ -397,7 +397,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -397,7 +397,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[5]) { switch (name[5]) {
case 's': case 's':
if (util::strieq_l("statu", name, 5)) { if (util::strieq_l("statu", name, 5)) {
return SHRPX_LOGF_STATUS; return LogFragmentType::STATUS;
} }
break; break;
} }
...@@ -406,12 +406,12 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -406,12 +406,12 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[6]) { switch (name[6]) {
case 'i': case 'i':
if (util::strieq_l("tls_sn", name, 6)) { if (util::strieq_l("tls_sn", name, 6)) {
return SHRPX_LOGF_TLS_SNI; return LogFragmentType::TLS_SNI;
} }
break; break;
case 't': case 't':
if (util::strieq_l("reques", name, 6)) { if (util::strieq_l("reques", name, 6)) {
return SHRPX_LOGF_REQUEST; return LogFragmentType::REQUEST;
} }
break; break;
} }
...@@ -420,15 +420,15 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -420,15 +420,15 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[9]) { switch (name[9]) {
case 'l': case 'l':
if (util::strieq_l("time_loca", name, 9)) { if (util::strieq_l("time_loca", name, 9)) {
return SHRPX_LOGF_TIME_LOCAL; return LogFragmentType::TIME_LOCAL;
} }
break; break;
case 'r': case 'r':
if (util::strieq_l("ssl_ciphe", name, 9)) { if (util::strieq_l("ssl_ciphe", name, 9)) {
return SHRPX_LOGF_SSL_CIPHER; return LogFragmentType::SSL_CIPHER;
} }
if (util::strieq_l("tls_ciphe", name, 9)) { if (util::strieq_l("tls_ciphe", name, 9)) {
return SHRPX_LOGF_TLS_CIPHER; return LogFragmentType::TLS_CIPHER;
} }
break; break;
} }
...@@ -437,15 +437,15 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -437,15 +437,15 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[10]) { switch (name[10]) {
case 'r': case 'r':
if (util::strieq_l("remote_add", name, 10)) { if (util::strieq_l("remote_add", name, 10)) {
return SHRPX_LOGF_REMOTE_ADDR; return LogFragmentType::REMOTE_ADDR;
} }
break; break;
case 't': case 't':
if (util::strieq_l("remote_por", name, 10)) { if (util::strieq_l("remote_por", name, 10)) {
return SHRPX_LOGF_REMOTE_PORT; return LogFragmentType::REMOTE_PORT;
} }
if (util::strieq_l("server_por", name, 10)) { if (util::strieq_l("server_por", name, 10)) {
return SHRPX_LOGF_SERVER_PORT; return LogFragmentType::SERVER_PORT;
} }
break; break;
} }
...@@ -454,28 +454,28 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -454,28 +454,28 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[11]) { switch (name[11]) {
case '1': case '1':
if (util::strieq_l("time_iso860", name, 11)) { if (util::strieq_l("time_iso860", name, 11)) {
return SHRPX_LOGF_TIME_ISO8601; return LogFragmentType::TIME_ISO8601;
} }
break; break;
case 'e': case 'e':
if (util::strieq_l("request_tim", name, 11)) { if (util::strieq_l("request_tim", name, 11)) {
return SHRPX_LOGF_REQUEST_TIME; return LogFragmentType::REQUEST_TIME;
} }
break; break;
case 'l': case 'l':
if (util::strieq_l("ssl_protoco", name, 11)) { if (util::strieq_l("ssl_protoco", name, 11)) {
return SHRPX_LOGF_SSL_PROTOCOL; return LogFragmentType::SSL_PROTOCOL;
} }
if (util::strieq_l("tls_protoco", name, 11)) { if (util::strieq_l("tls_protoco", name, 11)) {
return SHRPX_LOGF_TLS_PROTOCOL; return LogFragmentType::TLS_PROTOCOL;
} }
break; break;
case 't': case 't':
if (util::strieq_l("backend_hos", name, 11)) { if (util::strieq_l("backend_hos", name, 11)) {
return SHRPX_LOGF_BACKEND_HOST; return LogFragmentType::BACKEND_HOST;
} }
if (util::strieq_l("backend_por", name, 11)) { if (util::strieq_l("backend_por", name, 11)) {
return SHRPX_LOGF_BACKEND_PORT; return LogFragmentType::BACKEND_PORT;
} }
break; break;
} }
...@@ -484,10 +484,10 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -484,10 +484,10 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[13]) { switch (name[13]) {
case 'd': case 'd':
if (util::strieq_l("ssl_session_i", name, 13)) { if (util::strieq_l("ssl_session_i", name, 13)) {
return SHRPX_LOGF_SSL_SESSION_ID; return LogFragmentType::SSL_SESSION_ID;
} }
if (util::strieq_l("tls_session_i", name, 13)) { if (util::strieq_l("tls_session_i", name, 13)) {
return SHRPX_LOGF_TLS_SESSION_ID; return LogFragmentType::TLS_SESSION_ID;
} }
break; break;
} }
...@@ -496,7 +496,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -496,7 +496,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[14]) { switch (name[14]) {
case 't': case 't':
if (util::strieq_l("body_bytes_sen", name, 14)) { if (util::strieq_l("body_bytes_sen", name, 14)) {
return SHRPX_LOGF_BODY_BYTES_SENT; return LogFragmentType::BODY_BYTES_SENT;
} }
break; break;
} }
...@@ -505,7 +505,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -505,7 +505,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[16]) { switch (name[16]) {
case 'l': case 'l':
if (util::strieq_l("tls_client_seria", name, 16)) { if (util::strieq_l("tls_client_seria", name, 16)) {
return SHRPX_LOGF_TLS_CLIENT_SERIAL; return LogFragmentType::TLS_CLIENT_SERIAL;
} }
break; break;
} }
...@@ -514,10 +514,10 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -514,10 +514,10 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[17]) { switch (name[17]) {
case 'd': case 'd':
if (util::strieq_l("ssl_session_reuse", name, 17)) { if (util::strieq_l("ssl_session_reuse", name, 17)) {
return SHRPX_LOGF_SSL_SESSION_REUSED; return LogFragmentType::SSL_SESSION_REUSED;
} }
if (util::strieq_l("tls_session_reuse", name, 17)) { if (util::strieq_l("tls_session_reuse", name, 17)) {
return SHRPX_LOGF_TLS_SESSION_REUSED; return LogFragmentType::TLS_SESSION_REUSED;
} }
break; break;
} }
...@@ -526,7 +526,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -526,7 +526,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[21]) { switch (name[21]) {
case 'e': case 'e':
if (util::strieq_l("tls_client_issuer_nam", name, 21)) { if (util::strieq_l("tls_client_issuer_nam", name, 21)) {
return SHRPX_LOGF_TLS_CLIENT_ISSUER_NAME; return LogFragmentType::TLS_CLIENT_ISSUER_NAME;
} }
break; break;
} }
...@@ -535,7 +535,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -535,7 +535,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[22]) { switch (name[22]) {
case 'e': case 'e':
if (util::strieq_l("tls_client_subject_nam", name, 22)) { if (util::strieq_l("tls_client_subject_nam", name, 22)) {
return SHRPX_LOGF_TLS_CLIENT_SUBJECT_NAME; return LogFragmentType::TLS_CLIENT_SUBJECT_NAME;
} }
break; break;
} }
...@@ -544,7 +544,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -544,7 +544,7 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[26]) { switch (name[26]) {
case '1': case '1':
if (util::strieq_l("tls_client_fingerprint_sha", name, 26)) { if (util::strieq_l("tls_client_fingerprint_sha", name, 26)) {
return SHRPX_LOGF_TLS_CLIENT_FINGERPRINT_SHA1; return LogFragmentType::TLS_CLIENT_FINGERPRINT_SHA1;
} }
break; break;
} }
...@@ -553,13 +553,13 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) { ...@@ -553,13 +553,13 @@ LogFragmentType log_var_lookup_token(const char *name, size_t namelen) {
switch (name[28]) { switch (name[28]) {
case '6': case '6':
if (util::strieq_l("tls_client_fingerprint_sha25", name, 28)) { if (util::strieq_l("tls_client_fingerprint_sha25", name, 28)) {
return SHRPX_LOGF_TLS_CLIENT_FINGERPRINT_SHA256; return LogFragmentType::TLS_CLIENT_FINGERPRINT_SHA256;
} }
break; break;
} }
break; break;
} }
return SHRPX_LOGF_NONE; return LogFragmentType::NONE;
} }
} // namespace } // namespace
...@@ -613,16 +613,16 @@ std::vector<LogFragment> parse_log_format(BlockAllocator &balloc, ...@@ -613,16 +613,16 @@ std::vector<LogFragment> parse_log_format(BlockAllocator &balloc,
auto type = log_var_lookup_token(var_name, var_namelen); auto type = log_var_lookup_token(var_name, var_namelen);
if (type == SHRPX_LOGF_NONE) { if (type == LogFragmentType::NONE) {
if (util::istarts_with_l(StringRef{var_name, var_namelen}, "http_")) { if (util::istarts_with_l(StringRef{var_name, var_namelen}, "http_")) {
if (util::streq_l("host", StringRef{var_name + str_size("http_"), if (util::streq_l("host", StringRef{var_name + str_size("http_"),
var_namelen - str_size("http_")})) { var_namelen - str_size("http_")})) {
// Special handling of host header field. We will use // Special handling of host header field. We will use
// :authority header field if host header is missing. This // :authority header field if host header is missing. This
// is a typical case in HTTP/2. // is a typical case in HTTP/2.
type = SHRPX_LOGF_AUTHORITY; type = LogFragmentType::AUTHORITY;
} else { } else {
type = SHRPX_LOGF_HTTP; type = LogFragmentType::HTTP;
value = var_name + str_size("http_"); value = var_name + str_size("http_");
} }
} else { } else {
...@@ -634,7 +634,7 @@ std::vector<LogFragment> parse_log_format(BlockAllocator &balloc, ...@@ -634,7 +634,7 @@ std::vector<LogFragment> parse_log_format(BlockAllocator &balloc,
if (literal_start < var_start) { if (literal_start < var_start) {
res.emplace_back( res.emplace_back(
SHRPX_LOGF_LITERAL, LogFragmentType::LITERAL,
make_string_ref(balloc, StringRef{literal_start, var_start})); make_string_ref(balloc, StringRef{literal_start, var_start}));
} }
...@@ -661,7 +661,7 @@ std::vector<LogFragment> parse_log_format(BlockAllocator &balloc, ...@@ -661,7 +661,7 @@ std::vector<LogFragment> parse_log_format(BlockAllocator &balloc,
} }
if (literal_start != eop) { if (literal_start != eop) {
res.emplace_back(SHRPX_LOGF_LITERAL, res.emplace_back(LogFragmentType::LITERAL,
make_string_ref(balloc, StringRef{literal_start, eop})); make_string_ref(balloc, StringRef{literal_start, eop}));
} }
......
...@@ -79,84 +79,84 @@ void test_shrpx_config_parse_log_format(void) { ...@@ -79,84 +79,84 @@ void test_shrpx_config_parse_log_format(void) {
R"("${http_referer}" $http_host "$http_user_agent")")); R"("${http_referer}" $http_host "$http_user_agent")"));
CU_ASSERT(16 == res.size()); CU_ASSERT(16 == res.size());
CU_ASSERT(SHRPX_LOGF_REMOTE_ADDR == res[0].type); CU_ASSERT(LogFragmentType::REMOTE_ADDR == res[0].type);
CU_ASSERT(SHRPX_LOGF_LITERAL == res[1].type); CU_ASSERT(LogFragmentType::LITERAL == res[1].type);
CU_ASSERT(" - $remote_user [" == res[1].value); CU_ASSERT(" - $remote_user [" == res[1].value);
CU_ASSERT(SHRPX_LOGF_TIME_LOCAL == res[2].type); CU_ASSERT(LogFragmentType::TIME_LOCAL == res[2].type);
CU_ASSERT(SHRPX_LOGF_LITERAL == res[3].type); CU_ASSERT(LogFragmentType::LITERAL == res[3].type);
CU_ASSERT("] \"" == res[3].value); CU_ASSERT("] \"" == res[3].value);
CU_ASSERT(SHRPX_LOGF_REQUEST == res[4].type); CU_ASSERT(LogFragmentType::REQUEST == res[4].type);
CU_ASSERT(SHRPX_LOGF_LITERAL == res[5].type); CU_ASSERT(LogFragmentType::LITERAL == res[5].type);
CU_ASSERT("\" " == res[5].value); CU_ASSERT("\" " == res[5].value);
CU_ASSERT(SHRPX_LOGF_STATUS == res[6].type); CU_ASSERT(LogFragmentType::STATUS == res[6].type);
CU_ASSERT(SHRPX_LOGF_LITERAL == res[7].type); CU_ASSERT(LogFragmentType::LITERAL == res[7].type);
CU_ASSERT(" " == res[7].value); CU_ASSERT(" " == res[7].value);
CU_ASSERT(SHRPX_LOGF_BODY_BYTES_SENT == res[8].type); CU_ASSERT(LogFragmentType::BODY_BYTES_SENT == res[8].type);
CU_ASSERT(SHRPX_LOGF_LITERAL == res[9].type); CU_ASSERT(LogFragmentType::LITERAL == res[9].type);
CU_ASSERT(" \"" == res[9].value); CU_ASSERT(" \"" == res[9].value);
CU_ASSERT(SHRPX_LOGF_HTTP == res[10].type); CU_ASSERT(LogFragmentType::HTTP == res[10].type);
CU_ASSERT("referer" == res[10].value); CU_ASSERT("referer" == res[10].value);
CU_ASSERT(SHRPX_LOGF_LITERAL == res[11].type); CU_ASSERT(LogFragmentType::LITERAL == res[11].type);
CU_ASSERT("\" " == res[11].value); CU_ASSERT("\" " == res[11].value);
CU_ASSERT(SHRPX_LOGF_AUTHORITY == res[12].type); CU_ASSERT(LogFragmentType::AUTHORITY == res[12].type);
CU_ASSERT(SHRPX_LOGF_LITERAL == res[13].type); CU_ASSERT(LogFragmentType::LITERAL == res[13].type);
CU_ASSERT(" \"" == res[13].value); CU_ASSERT(" \"" == res[13].value);
CU_ASSERT(SHRPX_LOGF_HTTP == res[14].type); CU_ASSERT(LogFragmentType::HTTP == res[14].type);
CU_ASSERT("user-agent" == res[14].value); CU_ASSERT("user-agent" == res[14].value);
CU_ASSERT(SHRPX_LOGF_LITERAL == res[15].type); CU_ASSERT(LogFragmentType::LITERAL == res[15].type);
CU_ASSERT("\"" == res[15].value); CU_ASSERT("\"" == res[15].value);
res = parse_log_format(balloc, StringRef::from_lit("$")); res = parse_log_format(balloc, StringRef::from_lit("$"));
CU_ASSERT(1 == res.size()); CU_ASSERT(1 == res.size());
CU_ASSERT(SHRPX_LOGF_LITERAL == res[0].type); CU_ASSERT(LogFragmentType::LITERAL == res[0].type);
CU_ASSERT("$" == res[0].value); CU_ASSERT("$" == res[0].value);
res = parse_log_format(balloc, StringRef::from_lit("${")); res = parse_log_format(balloc, StringRef::from_lit("${"));
CU_ASSERT(1 == res.size()); CU_ASSERT(1 == res.size());
CU_ASSERT(SHRPX_LOGF_LITERAL == res[0].type); CU_ASSERT(LogFragmentType::LITERAL == res[0].type);
CU_ASSERT("${" == res[0].value); CU_ASSERT("${" == res[0].value);
res = parse_log_format(balloc, StringRef::from_lit("${a")); res = parse_log_format(balloc, StringRef::from_lit("${a"));
CU_ASSERT(1 == res.size()); CU_ASSERT(1 == res.size());
CU_ASSERT(SHRPX_LOGF_LITERAL == res[0].type); CU_ASSERT(LogFragmentType::LITERAL == res[0].type);
CU_ASSERT("${a" == res[0].value); CU_ASSERT("${a" == res[0].value);
res = parse_log_format(balloc, StringRef::from_lit("${a ")); res = parse_log_format(balloc, StringRef::from_lit("${a "));
CU_ASSERT(1 == res.size()); CU_ASSERT(1 == res.size());
CU_ASSERT(SHRPX_LOGF_LITERAL == res[0].type); CU_ASSERT(LogFragmentType::LITERAL == res[0].type);
CU_ASSERT("${a " == res[0].value); CU_ASSERT("${a " == res[0].value);
res = parse_log_format(balloc, StringRef::from_lit("$$remote_addr")); res = parse_log_format(balloc, StringRef::from_lit("$$remote_addr"));
CU_ASSERT(2 == res.size()); CU_ASSERT(2 == res.size());
CU_ASSERT(SHRPX_LOGF_LITERAL == res[0].type); CU_ASSERT(LogFragmentType::LITERAL == res[0].type);
CU_ASSERT("$" == res[0].value); CU_ASSERT("$" == res[0].value);
CU_ASSERT(SHRPX_LOGF_REMOTE_ADDR == res[1].type); CU_ASSERT(LogFragmentType::REMOTE_ADDR == res[1].type);
CU_ASSERT("" == res[1].value); CU_ASSERT("" == res[1].value);
} }
......
...@@ -609,19 +609,19 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -609,19 +609,19 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
for (auto &lf : lfv) { for (auto &lf : lfv) {
switch (lf.type) { switch (lf.type) {
case SHRPX_LOGF_LITERAL: case LogFragmentType::LITERAL:
std::tie(p, last) = copy(lf.value, p, last); std::tie(p, last) = copy(lf.value, p, last);
break; break;
case SHRPX_LOGF_REMOTE_ADDR: case LogFragmentType::REMOTE_ADDR:
std::tie(p, last) = copy(lgsp.remote_addr, p, last); std::tie(p, last) = copy(lgsp.remote_addr, p, last);
break; break;
case SHRPX_LOGF_TIME_LOCAL: case LogFragmentType::TIME_LOCAL:
std::tie(p, last) = copy(tstamp->time_local, p, last); std::tie(p, last) = copy(tstamp->time_local, p, last);
break; break;
case SHRPX_LOGF_TIME_ISO8601: case LogFragmentType::TIME_ISO8601:
std::tie(p, last) = copy(tstamp->time_iso8601, p, last); std::tie(p, last) = copy(tstamp->time_iso8601, p, last);
break; break;
case SHRPX_LOGF_REQUEST: case LogFragmentType::REQUEST:
std::tie(p, last) = copy(method, p, last); std::tie(p, last) = copy(method, p, last);
std::tie(p, last) = copy(' ', p, last); std::tie(p, last) = copy(' ', p, last);
std::tie(p, last) = copy_escape(path, p, last); std::tie(p, last) = copy_escape(path, p, last);
...@@ -632,13 +632,13 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -632,13 +632,13 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = copy(req.http_minor, p, last); std::tie(p, last) = copy(req.http_minor, p, last);
} }
break; break;
case SHRPX_LOGF_STATUS: case LogFragmentType::STATUS:
std::tie(p, last) = copy(resp.http_status, p, last); std::tie(p, last) = copy(resp.http_status, p, last);
break; break;
case SHRPX_LOGF_BODY_BYTES_SENT: case LogFragmentType::BODY_BYTES_SENT:
std::tie(p, last) = copy(downstream->response_sent_body_length, p, last); std::tie(p, last) = copy(downstream->response_sent_body_length, p, last);
break; break;
case SHRPX_LOGF_HTTP: { case LogFragmentType::HTTP: {
auto hd = req.fs.header(lf.value); auto hd = req.fs.header(lf.value);
if (hd) { if (hd) {
std::tie(p, last) = copy_escape((*hd).value, p, last); std::tie(p, last) = copy_escape((*hd).value, p, last);
...@@ -649,7 +649,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -649,7 +649,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
break; break;
} }
case SHRPX_LOGF_AUTHORITY: case LogFragmentType::AUTHORITY:
if (!req.authority.empty()) { if (!req.authority.empty()) {
std::tie(p, last) = copy(req.authority, p, last); std::tie(p, last) = copy(req.authority, p, last);
break; break;
...@@ -658,13 +658,13 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -658,13 +658,13 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
case SHRPX_LOGF_REMOTE_PORT: case LogFragmentType::REMOTE_PORT:
std::tie(p, last) = copy(lgsp.remote_port, p, last); std::tie(p, last) = copy(lgsp.remote_port, p, last);
break; break;
case SHRPX_LOGF_SERVER_PORT: case LogFragmentType::SERVER_PORT:
std::tie(p, last) = copy(lgsp.server_port, p, last); std::tie(p, last) = copy(lgsp.server_port, p, last);
break; break;
case SHRPX_LOGF_REQUEST_TIME: { case LogFragmentType::REQUEST_TIME: {
auto t = std::chrono::duration_cast<std::chrono::milliseconds>( auto t = std::chrono::duration_cast<std::chrono::milliseconds>(
lgsp.request_end_time - downstream->get_request_start_time()) lgsp.request_end_time - downstream->get_request_start_time())
.count(); .count();
...@@ -678,20 +678,20 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -678,20 +678,20 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = copy(frac, p, last); std::tie(p, last) = copy(frac, p, last);
break; break;
} }
case SHRPX_LOGF_PID: case LogFragmentType::PID:
std::tie(p, last) = copy(lgsp.pid, p, last); std::tie(p, last) = copy(lgsp.pid, p, last);
break; break;
case SHRPX_LOGF_ALPN: case LogFragmentType::ALPN:
std::tie(p, last) = copy_escape(lgsp.alpn, p, last); std::tie(p, last) = copy_escape(lgsp.alpn, p, last);
break; break;
case SHRPX_LOGF_TLS_CIPHER: case LogFragmentType::TLS_CIPHER:
if (!lgsp.ssl) { if (!lgsp.ssl) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
} }
std::tie(p, last) = copy(SSL_get_cipher_name(lgsp.ssl), p, last); std::tie(p, last) = copy(SSL_get_cipher_name(lgsp.ssl), p, last);
break; break;
case SHRPX_LOGF_TLS_PROTOCOL: case LogFragmentType::TLS_PROTOCOL:
if (!lgsp.ssl) { if (!lgsp.ssl) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
...@@ -699,7 +699,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -699,7 +699,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = std::tie(p, last) =
copy(nghttp2::tls::get_tls_protocol(lgsp.ssl), p, last); copy(nghttp2::tls::get_tls_protocol(lgsp.ssl), p, last);
break; break;
case SHRPX_LOGF_TLS_SESSION_ID: { case LogFragmentType::TLS_SESSION_ID: {
auto session = SSL_get_session(lgsp.ssl); auto session = SSL_get_session(lgsp.ssl);
if (!session) { if (!session) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
...@@ -714,7 +714,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -714,7 +714,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = copy_hex_low(session_id, session_id_length, p, last); std::tie(p, last) = copy_hex_low(session_id, session_id_length, p, last);
break; break;
} }
case SHRPX_LOGF_TLS_SESSION_REUSED: case LogFragmentType::TLS_SESSION_REUSED:
if (!lgsp.ssl) { if (!lgsp.ssl) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
...@@ -722,15 +722,15 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -722,15 +722,15 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = std::tie(p, last) =
copy(SSL_session_reused(lgsp.ssl) ? 'r' : '.', p, last); copy(SSL_session_reused(lgsp.ssl) ? 'r' : '.', p, last);
break; break;
case SHRPX_LOGF_TLS_SNI: case LogFragmentType::TLS_SNI:
if (lgsp.sni.empty()) { if (lgsp.sni.empty()) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
} }
std::tie(p, last) = copy_escape(lgsp.sni, p, last); std::tie(p, last) = copy_escape(lgsp.sni, p, last);
break; break;
case SHRPX_LOGF_TLS_CLIENT_FINGERPRINT_SHA1: case LogFragmentType::TLS_CLIENT_FINGERPRINT_SHA1:
case SHRPX_LOGF_TLS_CLIENT_FINGERPRINT_SHA256: { case LogFragmentType::TLS_CLIENT_FINGERPRINT_SHA256: {
if (!lgsp.ssl) { if (!lgsp.ssl) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
...@@ -743,8 +743,9 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -743,8 +743,9 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::array<uint8_t, 32> buf; std::array<uint8_t, 32> buf;
auto len = tls::get_x509_fingerprint( auto len = tls::get_x509_fingerprint(
buf.data(), buf.size(), x, buf.data(), buf.size(), x,
lf.type == SHRPX_LOGF_TLS_CLIENT_FINGERPRINT_SHA256 ? EVP_sha256() lf.type == LogFragmentType::TLS_CLIENT_FINGERPRINT_SHA256
: EVP_sha1()); ? EVP_sha256()
: EVP_sha1());
X509_free(x); X509_free(x);
if (len <= 0) { if (len <= 0) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
...@@ -753,8 +754,8 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -753,8 +754,8 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = copy_hex_low(buf.data(), len, p, last); std::tie(p, last) = copy_hex_low(buf.data(), len, p, last);
break; break;
} }
case SHRPX_LOGF_TLS_CLIENT_ISSUER_NAME: case LogFragmentType::TLS_CLIENT_ISSUER_NAME:
case SHRPX_LOGF_TLS_CLIENT_SUBJECT_NAME: { case LogFragmentType::TLS_CLIENT_SUBJECT_NAME: {
if (!lgsp.ssl) { if (!lgsp.ssl) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
...@@ -764,7 +765,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -764,7 +765,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
} }
auto name = lf.type == SHRPX_LOGF_TLS_CLIENT_ISSUER_NAME auto name = lf.type == LogFragmentType::TLS_CLIENT_ISSUER_NAME
? tls::get_x509_issuer_name(balloc, x) ? tls::get_x509_issuer_name(balloc, x)
: tls::get_x509_subject_name(balloc, x); : tls::get_x509_subject_name(balloc, x);
X509_free(x); X509_free(x);
...@@ -775,7 +776,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -775,7 +776,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = copy(name, p, last); std::tie(p, last) = copy(name, p, last);
break; break;
} }
case SHRPX_LOGF_TLS_CLIENT_SERIAL: { case LogFragmentType::TLS_CLIENT_SERIAL: {
if (!lgsp.ssl) { if (!lgsp.ssl) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
...@@ -794,21 +795,21 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, ...@@ -794,21 +795,21 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
std::tie(p, last) = copy(sn, p, last); std::tie(p, last) = copy(sn, p, last);
break; break;
} }
case SHRPX_LOGF_BACKEND_HOST: case LogFragmentType::BACKEND_HOST:
if (!downstream_addr) { if (!downstream_addr) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
} }
std::tie(p, last) = copy(downstream_addr->host, p, last); std::tie(p, last) = copy(downstream_addr->host, p, last);
break; break;
case SHRPX_LOGF_BACKEND_PORT: case LogFragmentType::BACKEND_PORT:
if (!downstream_addr) { if (!downstream_addr) {
std::tie(p, last) = copy('-', p, last); std::tie(p, last) = copy('-', p, last);
break; break;
} }
std::tie(p, last) = copy(downstream_addr->port, p, last); std::tie(p, last) = copy(downstream_addr->port, p, last);
break; break;
case SHRPX_LOGF_NONE: case LogFragmentType::NONE:
break; break;
default: default:
break; break;
......
...@@ -215,38 +215,38 @@ void dec(Log &log); ...@@ -215,38 +215,38 @@ void dec(Log &log);
#define TTY_HTTP_HD (log_config()->errorlog_tty ? "\033[1;34m" : "") #define TTY_HTTP_HD (log_config()->errorlog_tty ? "\033[1;34m" : "")
#define TTY_RST (log_config()->errorlog_tty ? "\033[0m" : "") #define TTY_RST (log_config()->errorlog_tty ? "\033[0m" : "")
enum LogFragmentType { enum class LogFragmentType {
SHRPX_LOGF_NONE, NONE,
SHRPX_LOGF_LITERAL, LITERAL,
SHRPX_LOGF_REMOTE_ADDR, REMOTE_ADDR,
SHRPX_LOGF_TIME_LOCAL, TIME_LOCAL,
SHRPX_LOGF_TIME_ISO8601, TIME_ISO8601,
SHRPX_LOGF_REQUEST, REQUEST,
SHRPX_LOGF_STATUS, STATUS,
SHRPX_LOGF_BODY_BYTES_SENT, BODY_BYTES_SENT,
SHRPX_LOGF_HTTP, HTTP,
SHRPX_LOGF_AUTHORITY, AUTHORITY,
SHRPX_LOGF_REMOTE_PORT, REMOTE_PORT,
SHRPX_LOGF_SERVER_PORT, SERVER_PORT,
SHRPX_LOGF_REQUEST_TIME, REQUEST_TIME,
SHRPX_LOGF_PID, PID,
SHRPX_LOGF_ALPN, ALPN,
SHRPX_LOGF_TLS_CIPHER, TLS_CIPHER,
SHRPX_LOGF_SSL_CIPHER = SHRPX_LOGF_TLS_CIPHER, SSL_CIPHER = TLS_CIPHER,
SHRPX_LOGF_TLS_PROTOCOL, TLS_PROTOCOL,
SHRPX_LOGF_SSL_PROTOCOL = SHRPX_LOGF_TLS_PROTOCOL, SSL_PROTOCOL = TLS_PROTOCOL,
SHRPX_LOGF_TLS_SESSION_ID, TLS_SESSION_ID,
SHRPX_LOGF_SSL_SESSION_ID = SHRPX_LOGF_TLS_SESSION_ID, SSL_SESSION_ID = TLS_SESSION_ID,
SHRPX_LOGF_TLS_SESSION_REUSED, TLS_SESSION_REUSED,
SHRPX_LOGF_SSL_SESSION_REUSED = SHRPX_LOGF_TLS_SESSION_REUSED, SSL_SESSION_REUSED = TLS_SESSION_REUSED,
SHRPX_LOGF_TLS_SNI, TLS_SNI,
SHRPX_LOGF_TLS_CLIENT_FINGERPRINT_SHA1, TLS_CLIENT_FINGERPRINT_SHA1,
SHRPX_LOGF_TLS_CLIENT_FINGERPRINT_SHA256, TLS_CLIENT_FINGERPRINT_SHA256,
SHRPX_LOGF_TLS_CLIENT_ISSUER_NAME, TLS_CLIENT_ISSUER_NAME,
SHRPX_LOGF_TLS_CLIENT_SERIAL, TLS_CLIENT_SERIAL,
SHRPX_LOGF_TLS_CLIENT_SUBJECT_NAME, TLS_CLIENT_SUBJECT_NAME,
SHRPX_LOGF_BACKEND_HOST, BACKEND_HOST,
SHRPX_LOGF_BACKEND_PORT, BACKEND_PORT,
}; };
struct LogFragment { struct LogFragment {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment