From 932f6a29501949c99204c8f2ed8ae7d9704e53af Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 27 Jul 2012 17:39:57 +0000 Subject: [PATCH] Add LOG_LEVEL_ACTIONS to log the applying actions Unlike in the "Final results", the effect of tags is taken into account. --- actions.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- actions.h | 3 ++- errlog.c | 5 +++- errlog.h | 3 ++- jcc.c | 32 +++++++++++++++++++++++++- 5 files changed, 106 insertions(+), 5 deletions(-) diff --git a/actions.c b/actions.c index caf62dfb..38ddfc9a 100644 --- a/actions.c +++ b/actions.c @@ -1,4 +1,4 @@ -const char actions_rcs[] = "$Id: actions.c,v 1.82 2012/06/08 15:09:06 fabiankeil Exp $"; +const char actions_rcs[] = "$Id: actions.c,v 1.83 2012/06/08 15:15:11 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/actions.c,v $ @@ -1871,3 +1871,69 @@ char *current_action_to_html(const struct client_state *csp, } return result; } + + +/********************************************************************* + * + * Function : action_to_line_of_text + * + * Description : Converts a action spec to a single text line + * listing the enabled actions. + * + * Parameters : + * 1 : action = Current action spec to be converted + * + * Returns : A string. Caller must free it. + * Out-of-memory errors are fatal. + * + *********************************************************************/ +char *actions_to_line_of_text(const struct current_action_spec *action) +{ + char buffer[200]; + struct list_entry *lst; + char *active; + const unsigned long flags = action->flags; + + active = strdup_or_die(""); + +#define DEFINE_ACTION_BOOL(__name, __bit) \ + if (flags & __bit) \ + { \ + snprintf(buffer, sizeof(buffer), "+%s ", __name); \ + string_append(&active, buffer); \ + } \ + +#define DEFINE_ACTION_STRING(__name, __bit, __index) \ + if (flags & __bit) \ + { \ + snprintf(buffer, sizeof(buffer), "+%s{%s} ", \ + __name, action->string[__index]); \ + string_append(&active, buffer); \ + } \ + +#define DEFINE_ACTION_MULTI(__name, __index) \ + lst = action->multi[__index]->first; \ + while (lst != NULL) \ + { \ + snprintf(buffer, sizeof(buffer), "+%s{%s} ", \ + __name, lst->str); \ + string_append(&active, buffer); \ + lst = lst->next; \ + } \ + +#define DEFINE_ACTION_ALIAS 0 /* No aliases for output */ + +#include "actionlist.h" + +#undef DEFINE_ACTION_MULTI +#undef DEFINE_ACTION_STRING +#undef DEFINE_ACTION_BOOL +#undef DEFINE_ACTION_ALIAS + + if (active == NULL) + { + log_error(LOG_LEVEL_FATAL, "Out of memory in action_to_line_of_text()"); + } + + return active; +} diff --git a/actions.h b/actions.h index b2ab66ce..4e91cc47 100644 --- a/actions.h +++ b/actions.h @@ -1,6 +1,6 @@ #ifndef ACTIONS_H_INCLUDED #define ACTIONS_H_INCLUDED -#define ACTIONS_H_VERSION "$Id: actions.h,v 1.19 2009/05/16 13:27:20 fabiankeil Exp $" +#define ACTIONS_H_VERSION "$Id: actions.h,v 1.20 2011/09/04 11:10:56 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/actions.h,v $ @@ -80,6 +80,7 @@ extern jb_err merge_current_action (struct current_action_spec *dest, const struct action_spec *src); extern char * current_action_to_html(const struct client_state *csp, const struct current_action_spec *action); +extern char * actions_to_line_of_text(const struct current_action_spec *action); extern jb_err get_action_token(char **line, char **name, char **value); extern void unload_actions_file(void *file_data); diff --git a/errlog.c b/errlog.c index e094ddd5..ddcc39b2 100644 --- a/errlog.c +++ b/errlog.c @@ -1,4 +1,4 @@ -const char errlog_rcs[] = "$Id: errlog.c,v 1.114 2012/03/09 17:55:50 fabiankeil Exp $"; +const char errlog_rcs[] = "$Id: errlog.c,v 1.115 2012/07/27 17:27:47 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/errlog.c,v $ @@ -621,6 +621,9 @@ static inline const char *get_log_level_string(int loglevel) case LOG_LEVEL_CGI: log_level_string = "CGI"; break; + case LOG_LEVEL_ACTIONS: + log_level_string = "Actions"; + break; default: log_level_string = "Unknown log level"; break; diff --git a/errlog.h b/errlog.h index 69341371..6ef5bc2f 100644 --- a/errlog.h +++ b/errlog.h @@ -1,6 +1,6 @@ #ifndef ERRLOG_H_INCLUDED #define ERRLOG_H_INCLUDED -#define ERRLOG_H_VERSION "$Id: errlog.h,v 1.27 2011/09/04 11:10:56 fabiankeil Exp $" +#define ERRLOG_H_VERSION "$Id: errlog.h,v 1.28 2012/07/27 17:27:47 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/errlog.h,v $ @@ -58,6 +58,7 @@ extern "C" { #define LOG_LEVEL_CRUNCH 0x0400 #define LOG_LEVEL_CGI 0x0800 /* CGI / templates */ #define LOG_LEVEL_RECEIVED 0x8000 +#define LOG_LEVEL_ACTIONS 0x10000 /* Following are always on: */ #define LOG_LEVEL_INFO 0x1000 diff --git a/jcc.c b/jcc.c index 6757ad26..8f35b329 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.383 2012/07/23 12:55:25 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.384 2012/07/27 17:31:10 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -661,6 +661,34 @@ static const char *crunch_reason(const struct http_response *rsp) } +/********************************************************************* + * + * Function : log_applied_actions + * + * Description : Logs the applied actions if LOG_LEVEL_ACTIONS is + * enabled. + * + * Parameters : + * 1 : actions = Current action spec to log + * + * Returns : Nothing. + * + *********************************************************************/ +static void log_applied_actions(const struct current_action_spec *actions) +{ + /* + * The conversion to text requires lots of memory allocations so + * we only do the conversion if the user is actually interested. + */ + if (debug_level_is_enabled(LOG_LEVEL_ACTIONS)) + { + char *actions_as_text = actions_to_line_of_text(actions); + log_error(LOG_LEVEL_ACTIONS, "%s", actions_as_text); + freez(actions_as_text); + } +} + + /********************************************************************* * * Function : send_crunch_response @@ -705,6 +733,7 @@ static void send_crunch_response(const struct client_state *csp, struct http_res status_code[3] = '\0'; /* Log that the request was crunched and why. */ + log_applied_actions(csp->action); log_error(LOG_LEVEL_CRUNCH, "%s: %s", crunch_reason(rsp), http->url); log_error(LOG_LEVEL_CLF, "%s - - [%T] \"%s\" %s %u", csp->ip_addr_str, http->ocmd, status_code, rsp->content_length); @@ -1602,6 +1631,7 @@ static void chat(struct client_state *csp) return; } + log_applied_actions(csp->action); log_error(LOG_LEVEL_GPC, "%s%s", http->hostport, http->path); if (fwd->forward_host) -- 2.39.2