current cgisimple.c, 1.146, 1.147 client-tags.c, 1.6, 1.7 client-tags.h, 1.3, 1.4

Fabian Keil <[email protected]> Mon, 20 Feb 2017 13:47:06 +0000
Newsgroups gmane.comp.web.privoxy.cvs
Message-ID <[email protected]>
Update of /cvsroot/ijbswa/current
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv15413

Modified Files:
	cgisimple.c client-tags.c client-tags.h 
Log Message:
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.


Index: client-tags.c
===================================================================
RCS file: /cvsroot/ijbswa/current/client-tags.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** client-tags.c	22 May 2016 12:43:07 -0000	1.6
--- client-tags.c	20 Feb 2017 13:47:04 -0000	1.7
***************
*** 255,258 ****
--- 255,306 ----
  /*********************************************************************
   *
+  * 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
   *

Index: client-tags.h
===================================================================
RCS file: /cvsroot/ijbswa/current/client-tags.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** client-tags.h	22 May 2016 12:43:07 -0000	1.3
--- client-tags.h	20 Feb 2017 13:47:04 -0000	1.4
***************
*** 34,37 ****
--- 34,38 ----
  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);

Index: cgisimple.c
===================================================================
RCS file: /cvsroot/ijbswa/current/cgisimple.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -C2 -d -r1.146 -r1.147
*** cgisimple.c	20 Feb 2017 13:45:14 -0000	1.146
--- cgisimple.c	20 Feb 2017 13:47:04 -0000	1.147
***************
*** 346,349 ****
--- 346,350 ----
     char *client_tag_status;
     char buf[1000];
+    time_t refresh_delay;
  
     assert(csp);
***************
*** 398,401 ****
--- 399,420 ----
        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))


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot