MEDIUM: log-format: make the format parser more robust and more extensible
The log-format parser reached a limit making it hard to add new features.
It also suffers from a weak handling of certain incorrect corner cases,
for example "%{foo}" is emitted as a litteral while syntactically it's an
argument to no variable. Also the argument parser had to redo some of the
job with some cases causing minor memory leaks (eg: ignored args).
This work aims at improving the situation so that slightly better reporting
is possible and that it becomes possible to extend the log format. The code
has a few more states but looks significantly simpler. The parser is now
capable of reporting ignored arguments and truncated lines.
diff --git a/include/proto/log.h b/include/proto/log.h
index a6c59ff..5d1215a 100644
--- a/include/proto/log.h
+++ b/include/proto/log.h
@@ -55,10 +55,10 @@
int parse_logformat_var_args(char *args, struct logformat_node *node);
/*
- * Parse a variable '%varname' or '%{args}varname' in logformat
+ * Parse a variable '%varname' or '%{args}varname' in log-format
*
*/
-int parse_logformat_var(char *str, size_t len, struct proxy *curproxy, struct list *list_format, int *defoptions);
+int parse_logformat_var(char *arg, int arg_len, char *var, int var_len, struct proxy *curproxy, struct list *list_format, int *defoptions);
/*
* add to the logformat linked list
diff --git a/include/types/log.h b/include/types/log.h
index c81ab0d..0ed79d4 100644
--- a/include/types/log.h
+++ b/include/types/log.h
@@ -97,15 +97,16 @@
LOG_FMT_SSL_VERSION,
};
-/* enum for parse_logformat */
+/* enum for parse_logformat_string */
enum {
- LF_TEXT = 0,
- LF_SEPARATOR,
- LF_VAR, // after %
-
- LF_STARTVAR, // %
- LF_STARG, // { and within { }
- LF_EDARG, // end arg }
+ LF_INIT = 0, // before first character
+ LF_TEXT, // normal text
+ LF_SEPARATOR, // a single separator
+ LF_VAR, // variable name, after '%' or '%{..}'
+ LF_STARTVAR, // % in text
+ LF_STARG, // after '%{' and berore '}'
+ LF_EDARG, // '}' after '%{'
+ LF_END, // \0 found
};