-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 $
jb_err err = JB_ERR_OK;
char *client_tag_status;
char buf[1000];
+ time_t refresh_delay;
assert(csp);
assert(rsp);
}
if (!err) err = string_append(&client_tag_status, "</table>\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))
{
}
+/*********************************************************************
+ *
+ * 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
#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 $
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,
<meta name="robots" content="noindex,nofollow">
<link rel="stylesheet" type="text/css" href="@default-cgi@send-stylesheet">
<link rel="shortcut icon" href="@default-cgi@favicon.ico" type="image/x-icon">
+<!-- @if-tags-expire-start -->
+ <meta http-equiv="refresh" content="@refresh-delay@">
+<!-- if-tags-expire-end@ -->
</head>
<body>