Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
http access-log API
Browse files Browse the repository at this point in the history
- New API to create a tag-stack of formats which can be used to
  compile and display http logs. Currently the following variables
  are defined:

        $ua    - the user-agent
        $path  - the request path
        $rhost - the remote host
        $meth  - the http method
        $ts    - timestamp
        $proto - HTTP version
        $status - HTTP status
        $ref    - referrer
        $host   - $vhost
Usage:  

```C
void *log = htp_logutil_new("$rhost $host \"$ua\" [$ts] \"$meth $path");

static void
process_request_(evhtp_request_t * req, void * arg)
{
    (void)arg;

    htp_log_request(log, stderr, req);
    evhtp_send_reply(req, EVHTP_RES_OK);
}
```

See: examples/example_basic.c
  • Loading branch information
NathanFrench authored Aug 7, 2018
1 parent 606f3e3 commit a0a8641
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ check_c_compiler_flag(-fstack-protector-strong has_stack_protector)
set(LIBEVHTP_SOURCE_FILES
evhtp.c
numtoa.c
parser.c)
parser.c
logutils.c)

find_package(LibEvent REQUIRED)
list(APPEND LIBEVHTP_EXTERNAL_LIBS ${LIBEVENT_LIBRARIES})
Expand Down
23 changes: 13 additions & 10 deletions uncrustify.cfg → dist/uncrustify.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ nl_enum_colon_type = ignore # ignore/add/remove/force

# Add or remove newline between 'struct and '{'.
### -ellzey
### nl_struct_brace = remove # ignore/add/remove/force
nl_struct_brace = remove # ignore/add/remove/force

# Add or remove newline between 'union' and '{'.
### -ellzey
Expand All @@ -1035,15 +1035,15 @@ nl_brace_else = remove # ignore/add/remove/force

# Add or remove newline between 'else if' and '{'
# If set to ignore, nl_if_brace is used instead.
nl_elseif_brace = ignore # ignore/add/remove/force
nl_elseif_brace = remove # ignore/add/remove/force

# Add or remove newline between 'else' and '{'.
### -ellzey
### nl_else_brace = remove # ignore/add/remove/force
nl_else_brace = remove # ignore/add/remove/force

# Add or remove newline between 'else' and 'if'.
### -ellzey
### nl_else_if = remove # ignore/add/remove/force
nl_else_if = remove # ignore/add/remove/force

# Add or remove newline before 'if'/'else if' closing parenthesis.
nl_before_if_closing_paren = ignore # ignore/add/remove/force
Expand Down Expand Up @@ -1148,6 +1148,7 @@ nl_constr_init_args = ignore # ignore/add/remove/force
nl_enum_own_lines = ignore # ignore/add/remove/force

# Add or remove newline between return type and function name in a function definition.
# -ellzey
nl_func_type_name = add # ignore/add/remove/force

# Add or remove newline between return type and function name inside a class {}
Expand Down Expand Up @@ -1248,6 +1249,7 @@ nl_func_call_end_multi_line = false # false/true
nl_oc_msg_args = false # false/true

# Add or remove newline between function signature and '{'.
# -ellzey
nl_fdef_brace = add # ignore/add/remove/force

# Add or remove newline between C++11 lambda signature and '{'.
Expand Down Expand Up @@ -1313,6 +1315,7 @@ nl_before_if = ignore # ignore/add/remove/force

# Add or remove blank line after 'if' statement.
# Add/Force work only if the next token is not a closing brace.
# -ellzey
nl_after_if = add # ignore/add/remove/force

# Add or remove blank line before 'for'.
Expand Down Expand Up @@ -1698,7 +1701,7 @@ align_right_cmt_gap = 0 # unsigned number
align_right_cmt_at_col = 0 # unsigned number

# The span for aligning function prototypes (0=don't align).
align_func_proto_span = 1 # unsigned number
align_func_proto_span = 0 # unsigned number

# Minimum gap between the return type and the function name.
align_func_proto_gap = 0 # unsigned number
Expand Down Expand Up @@ -1856,22 +1859,22 @@ mod_full_brace_do = add # ignore/add/remove/force
mod_full_brace_for = add # ignore/add/remove/force

# Add or remove braces on single-line function definitions. (Pawn).
mod_full_brace_function = ignore # ignore/add/remove/force
#mod_full_brace_function = add # ignore/add/remove/force

# Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'.
mod_full_brace_if = add # ignore/add/remove/force
mod_full_brace_if = force # ignore/add/remove/force

# Make all if/elseif/else statements in a chain be braced or not. Overrides mod_full_brace_if.
# If any must be braced, they are all braced. If all can be unbraced, then the braces are removed.
mod_full_brace_if_chain = false # false/true
# mod_full_brace_if_chain = false # false/true

# Make all if/elseif/else statements with at least one 'else' or 'else if' fully braced.
# If mod_full_brace_if_chain is used together with this option, all if-else chains will get braces,
# and simple 'if' statements will lose them (if possible).
mod_full_brace_if_chain_only = false # false/true
#mod_full_brace_if_chain_only = false # false/true

# Don't remove braces around statements that span N newlines
mod_full_brace_nl = 3 # unsigned number
# mod_full_brace_nl = 3 # unsigned number

# Blocks removal of braces if the parenthesis of if/for/while/.. span multiple lines.
mod_full_brace_nl_block_rem_mlcond = false # false/true
Expand Down
6 changes: 5 additions & 1 deletion examples/example_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
#include "./eutils.h"
#include "internal.h"
#include "evhtp/evhtp.h"
#include "evhtp/logutils.h"

static void
process_request_(evhtp_request_t * req, void * arg)
{
(void)arg;

htp_log_request(arg, stderr, req);
evhtp_send_reply(req, EVHTP_RES_OK);
}

Expand All @@ -26,11 +28,13 @@ main(int argc, char ** argv)
(void)argv;
struct event_base * evbase;
struct evhtp * htp;
void * log;

evbase = event_base_new();
htp = evhtp_new(evbase, NULL);
log = htp_logutil_new("$rhost $host \"$ua\" [$ts] \"$meth $path HTTP/$proto\" $status");

evhtp_set_cb(htp, "/", process_request_, NULL);
evhtp_set_cb(htp, "/", process_request_, log);
evhtp_enable_flag(htp, EVHTP_FLAG_ENABLE_ALL);

#ifndef EVHTP_DISABLE_EVTHR
Expand Down
8 changes: 8 additions & 0 deletions include/evhtp/logutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __EVHTP_LOGUTILS_H__
#define __EVHTP_LOGUTILS_H__

EVHTP_EXPORT void * htp_logutil_new(const char * format);
EVHTP_EXPORT void htp_log_request(void * logutil, FILE * fp, evhtp_request_t * request);

#endif

Loading

0 comments on commit a0a8641

Please sign in to comment.