} \
} while(0)
-/* start quoting the upcoming text if quoting is enabled. The final quote
- * will automatically be added (because quote is set to 1).
+/* indicate that a new variable-length text is starting, sets in_text
+ * variable to indicate that a var text was started and deals with
+ * encoding and options to know if some special treatment is needed.
*/
-#define LOGQUOTE_START() do { \
+#define LOG_VARTEXT_START() do { \
+ in_text = 1; \
+ /* put the text within quotes if quoting is \
+ * enabled \
+ */ \
if (tmp->options & LOG_OPT_QUOTE) { \
LOGCHAR('"'); \
- quote = 1; \
} \
} while (0)
-/* properly finish a quotation that was started using LOGQUOTE_START */
-#define LOGQUOTE_END() do { \
- if (quote) { \
+/* properly finish a variable text that was started using LOG_VARTEXT_START
+ * checks the in_text variable to know if a text was started or not, and
+ * deals with encoding and options to know if some special treatment is
+ * needed.
+ */
+#define LOG_VARTEXT_END() do { \
+ if (!in_text) \
+ break; \
+ in_text = 0; \
+ /* add the ending quote if quoting is enabled \
+ */ \
+ if (tmp->options & LOG_OPT_QUOTE) { \
LOGCHAR('"'); \
- quote = 0; \
} \
} while (0)
const char *src = NULL;
struct sample *key;
const struct buffer empty = { };
- int quote = 0; /* inside quoted string */
+ int in_text = 0; /* inside variable-length text */
switch (tmp->type) {
case LOG_FMT_SEPARATOR:
case LOG_FMT_FRONTEND_XPRT: // %ft
src = fe->id;
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
ret = lf_rawtext(tmplog, src, dst + maxsize - tmplog, tmp);
if (ret == NULL)
goto out;
case LOG_FMT_HDRREQUEST: // %hr
/* request header */
if (fe->nb_req_cap && s && s->req_cap) {
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
LOGCHAR('{');
for (hdr = 0; hdr < fe->nb_req_cap; hdr++) {
if (hdr)
for (hdr = 0; hdr < fe->nb_req_cap; hdr++) {
if (hdr > 0)
LOG_STRARRAY_NEXT();
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
if (s->req_cap[hdr] != NULL) {
ret = lf_encode_string(tmplog, dst + maxsize,
'#', hdr_encode_map, s->req_cap[hdr], tmp);
tmplog = ret;
} else if (!(tmp->options & LOG_OPT_QUOTE))
LOGCHAR('-');
- /* Manually end quotation as we're emitting multiple
- * quoted texts at once
+ /* Manually end variable text as we're emitting multiple
+ * texts at once
*/
- LOGQUOTE_END();
+ LOG_VARTEXT_END();
}
LOG_STRARRAY_END();
}
case LOG_FMT_HDRRESPONS: // %hs
/* response header */
if (fe->nb_rsp_cap && s && s->res_cap) {
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
LOGCHAR('{');
for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) {
if (hdr)
for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) {
if (hdr > 0)
LOG_STRARRAY_NEXT();
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
if (s->res_cap[hdr] != NULL) {
ret = lf_encode_string(tmplog, dst + maxsize,
'#', hdr_encode_map, s->res_cap[hdr], tmp);
tmplog = ret;
} else if (!(tmp->options & LOG_OPT_QUOTE))
LOGCHAR('-');
- /* Manually end quotation as we're emitting multiple
- * quoted texts at once
+ /* Manually end variable text as we're emitting multiple
+ * texts at once
*/
- LOGQUOTE_END();
+ LOG_VARTEXT_END();
}
LOG_STRARRAY_END();
}
case LOG_FMT_REQ: // %r
/* Request */
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
uri = txn && txn->uri ? txn->uri : "<BADREQ>";
ret = lf_encode_string(tmplog, dst + maxsize,
'#', url_encode_map, uri, tmp);
case LOG_FMT_HTTP_PATH: // %HP
uri = txn && txn->uri ? txn->uri : "<BADREQ>";
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
end = uri + strlen(uri);
// look for the first whitespace character
case LOG_FMT_HTTP_PATH_ONLY: // %HPO
uri = txn && txn->uri ? txn->uri : "<BADREQ>";
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
end = uri + strlen(uri);
break;
case LOG_FMT_HTTP_QUERY: // %HQ
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
if (!txn || !txn->uri) {
chunk.area = "<BADREQ>";
case LOG_FMT_HTTP_URI: // %HU
uri = txn && txn->uri ? txn->uri : "<BADREQ>";
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
end = uri + strlen(uri);
// look for the first whitespace character
case LOG_FMT_HTTP_METHOD: // %HM
uri = txn && txn->uri ? txn->uri : "<BADREQ>";
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
end = uri + strlen(uri);
// look for the first whitespace character
case LOG_FMT_HTTP_VERSION: // %HV
uri = txn && txn->uri ? txn->uri : "<BADREQ>";
- LOGQUOTE_START();
+ LOG_VARTEXT_START();
end = uri + strlen(uri);
// look for the first whitespace character
if (tmp->type != LOG_FMT_SEPARATOR)
last_isspace = 0; // not a separator, hence not a space
- /* if quotation was started for the current node data, we need
- * to finish the quote
+ /* if variable text was started for the current node data, we need
+ * to end it
*/
- LOGQUOTE_END();
+ LOG_VARTEXT_END();
}
out: