From: Fabian Keil Date: Mon, 20 Feb 2017 13:47:04 +0000 (+0000) Subject: Insert a refresh tag into the /client-tags cgi page X-Git-Tag: v_3_0_27~214 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=3ac2e455b47cce2028e1f8c7de72a77a15491691;hp=668491938efce71fde75a85f3b9dc0cedba50f77 Insert a refresh tag into the /client-tags cgi page ... when serving it while a client-specific tag is temporarily enabled. This makes it less likely that the user ends up looking at tag state that is out of date. --- diff --git a/cgisimple.c b/cgisimple.c index c2983e30..078a0011 100644 --- a/cgisimple.c +++ b/cgisimple.c @@ -1,4 +1,4 @@ -const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.145 2017/01/23 13:05:12 fabiankeil Exp $"; +const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.146 2017/02/20 13:45:14 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $ @@ -345,6 +345,7 @@ jb_err cgi_show_client_tags(struct client_state *csp, jb_err err = JB_ERR_OK; char *client_tag_status; char buf[1000]; + time_t refresh_delay; assert(csp); assert(rsp); @@ -397,6 +398,24 @@ jb_err cgi_show_client_tags(struct client_state *csp, } if (!err) err = string_append(&client_tag_status, "\n"); } + refresh_delay = get_next_tag_timeout_for_client(csp->client_address); + if (refresh_delay != 0) + { + snprintf(buf, sizeof(buf), "%d", csp->config->client_tag_lifetime); + if (map(exports, "refresh-delay", 1, buf, 1)) + { + free_map(exports); + return JB_ERR_MEMORY; + } + } + else + { + err = map_block_killer(exports, "tags-expire"); + if (err != JB_ERR_OK) + { + return err; + } + } if (map(exports, "client-tags", 1, client_tag_status, 0)) { diff --git a/client-tags.c b/client-tags.c index fda1f887..f9b38c9c 100644 --- a/client-tags.c +++ b/client-tags.c @@ -252,6 +252,54 @@ void get_tag_list_for_client(struct list *tag_list, } +/********************************************************************* + * + * Function : get_next_tag_timeout_for_client + * + * Description : Figures out when the next temporarily enabled tag + * for the client will have timed out. + * + * Parameters : + * 1 : client_address = Address of the client + * + * Returns : Lowest timeout in seconds + * + *********************************************************************/ +time_t get_next_tag_timeout_for_client(const char *client_address) +{ + struct client_specific_tag *enabled_tags; + time_t next_timeout = 0; + const time_t now = time(NULL); + + privoxy_mutex_lock(&client_tags_mutex); + + enabled_tags = get_tags_for_client(client_address); + while (enabled_tags != NULL) + { + log_error(LOG_LEVEL_CGI, "Evaluating tag '%s' for client %s. End of life %d", + enabled_tags->name, client_address, enabled_tags->end_of_life); + if (enabled_tags->end_of_life) + { + time_t time_left = enabled_tags->end_of_life - now; + /* Add a second to make sure the tag will have expired */ + time_left++; + log_error(LOG_LEVEL_CGI, "%d > %d?", next_timeout, time_left); + if (next_timeout == 0 || next_timeout > time_left) + { + next_timeout = time_left; + } + } + enabled_tags = enabled_tags->next; + } + + privoxy_mutex_unlock(&client_tags_mutex); + + log_error(LOG_LEVEL_CGI, "Next timeout in %d seconds", next_timeout); + + return next_timeout; + +} + /********************************************************************* * * Function : add_tag_for_client diff --git a/client-tags.h b/client-tags.h index 6f8398c4..24b45c1c 100644 --- a/client-tags.h +++ b/client-tags.h @@ -1,6 +1,6 @@ #ifndef CLIENT_TAGS_H_INCLUDED #define CLIENT_TAGS_H_INCLUDED -#define CLIENT_TAGS_H_VERSION "$Id: client-tags.h,v 1.2 2016/05/03 13:21:42 fabiankeil Exp $" +#define CLIENT_TAGS_H_VERSION "$Id: client-tags.h,v 1.3 2016/05/22 12:43:07 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/client-tags.h,v $ @@ -33,6 +33,7 @@ extern int client_tag_match(const struct pattern_spec *pattern, const struct list *tags); extern void get_tag_list_for_client(struct list *tag_list, const char *client_address); +extern time_t get_next_tag_timeout_for_client(const char *client_address); extern jb_err disable_client_specific_tag(struct client_state *csp, const char *tag_name); extern jb_err enable_client_specific_tag(struct client_state *csp, diff --git a/templates/client-tags b/templates/client-tags index a5291c1d..6520a1a8 100644 --- a/templates/client-tags +++ b/templates/client-tags @@ -80,6 +80,9 @@ + + +