Elukey has uploaded a new change for review. https://gerrit.wikimedia.org/r/322256
Change subject: Move definitions to header files for a better code readability ...................................................................... Move definitions to header files for a better code readability Split the map struct definition from its declaration and moved some header inclusions in varnishkafka.h Change-Id: I1f7799b2ae6e06ad37eedc287e983a8edeb2a663 --- M varnishkafka.c M varnishkafka.h 2 files changed, 65 insertions(+), 63 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/software/varnish/varnishkafka refs/changes/56/322256/1 diff --git a/varnishkafka.c b/varnishkafka.c index b6d7a62..c395290 100644 --- a/varnishkafka.c +++ b/varnishkafka.c @@ -48,17 +48,6 @@ #include <limits.h> #include <stdbool.h> -#include <vapi/vsm.h> -#include <vapi/vsl.h> -#include <vapi/voptget.h> -#include <vdef.h> - -#include <librdkafka/rdkafka.h> - -#include <yajl/yajl_common.h> -#include <yajl/yajl_gen.h> -#include <yajl/yajl_version.h> - #include "varnishkafka.h" #include "base64.h" @@ -747,59 +736,8 @@ */ static int format_parse (const char *format_orig, char *errstr, size_t errstr_size) { - /** - * Maps a formatter %X to a VSL tag and column id, or parser, or both - */ - struct { - /* A formatter may be backed by multiple tags. - * The first matching tag observed in the log will be used. - * - * Example: - * A formatter declared as following in 'map': - * ['x'] = { { - * { VSL_CLIENTMARKER, SLT_Timestamp, - * .var = "Process", - * .fmtvar = "Varnish:time_firstbyte", .col = 2 }, - * { VSL_CLIENTMARKER, SLT_Begin, - * .fmtvar = "Varnish:xvid", .col = 2 } - * } }, - * - * In this case, the struct below is replicated two - * times to match the 'x' formatter to multiple - * Varnish tags (establishing also a priority). - * Therefore, supposing that 'x' corresponds to 'map[42]', - * the following variables will be accessible: - * - map[42].f[0].var ==> "Process" - * - map[42].f[1].fmtvar ==> "Varnish:xvid" - */ - struct { - /* VSL_CLIENTMARKER or VSL_BACKENDMARKER, or both */ - int spec; - /* The SLT_.. tag id */ - int tag; - /* For "Name: Value" tags (such as SLT_RespHeader), - * this is the "Name" part. */ - const char *var; - /* Special handling for non-name-value vars such as - * %{Varnish:handling}x. fmtvar is "Varnish:handling" */ - const char *fmtvar; - /* Column to extract: - * 0 for entire string, else 1, 2, .. */ - int col; - /* Parser to manually extract and/or convert a - * tag's content. */ - size_t (*parser) (const struct tag *tag, - struct logline *lp, - const char *ptr, size_t len); - /* Optional tag->flags */ - int tag_flags; - } f[5+1]; /* increase size when necessary (max used size + 1) */ - /* Default string if no matching tag was found or all - * parsers failed, defaults to "-". */ - const char *def; - - } map[256] = { + struct VSL_Tag_Formatter map[256] = { /* Indexed by formatter character as * specified by varnishncsa(1). * Each formatter is associated with diff --git a/varnishkafka.h b/varnishkafka.h index 681f875..9d5b68e 100644 --- a/varnishkafka.h +++ b/varnishkafka.h @@ -32,6 +32,17 @@ #include <sys/queue.h> +#include <vapi/vsl.h> +#include <vapi/vsm.h> +#include <vapi/voptget.h> +#include <vdef.h> + +#include <librdkafka/rdkafka.h> + +#include <yajl/yajl_common.h> +#include <yajl/yajl_gen.h> +#include <yajl/yajl_version.h> + #ifndef likely #define likely(x) __builtin_expect((x),1) #endif @@ -229,3 +240,56 @@ void out_stdout (struct logline *lp, const char *buf, size_t len); void out_null (struct logline *lp, const char *buf, size_t len); extern void (*outfunc) (struct logline *lp, const char *buf, size_t len); + +/** +* Maps a formatter %X to a VSL tag and column id, or parser, or both +*/ +struct VSL_Tag_Formatter { + /* A formatter may be backed by multiple tags. + * The first matching tag observed in the log will be used. + * + * Example: + * A formatter declared as following in 'map': + * ['x'] = { { + * { VSL_CLIENTMARKER, SLT_Timestamp, + * .var = "Process", + * .fmtvar = "Varnish:time_firstbyte", .col = 2 }, + * { VSL_CLIENTMARKER, SLT_Begin, + * .fmtvar = "Varnish:xvid", .col = 2 } + * } }, + * + * In this case, the struct below is replicated two + * times to match the 'x' formatter to multiple + * Varnish tags (establishing also a priority). + * Therefore, supposing that 'x' corresponds to 'map[42]', + * the following variables will be accessible: + * - map[42].f[0].var ==> "Process" + * - map[42].f[1].fmtvar ==> "Varnish:xvid" + */ + struct { + /* VSL_CLIENTMARKER or VSL_BACKENDMARKER, or both */ + int spec; + /* The SLT_.. tag id */ + int tag; + /* For "Name: Value" tags (such as SLT_RespHeader), + * this is the "Name" part. */ + const char *var; + /* Special handling for non-name-value vars such as + * %{Varnish:handling}x. fmtvar is "Varnish:handling" */ + const char *fmtvar; + /* Column to extract: + * 0 for entire string, else 1, 2, .. */ + int col; + /* Parser to manually extract and/or convert a + * tag's content. */ + size_t (*parser) (const struct tag *tag, + struct logline *lp, + const char *ptr, size_t len); + /* Optional tag->flags */ + int tag_flags; + } f[5+1]; /* increase size when necessary (max used size + 1) */ + + /* Default string if no matching tag was found or all + * parsers failed, defaults to "-". */ + char *def; +}; \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/322256 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1f7799b2ae6e06ad37eedc287e983a8edeb2a663 Gerrit-PatchSet: 1 Gerrit-Project: operations/software/varnish/varnishkafka Gerrit-Branch: master Gerrit-Owner: Elukey <ltosc...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits