]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Henrik Nordstrom <henrik@henriknordstrom.net>
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 3 Jul 2008 03:04:04 +0000 (15:04 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 3 Jul 2008 03:04:04 +0000 (15:04 +1200)
Port from 2.6: Support for cachemgr sub-actions

see. http://www.squid-cache.org/Versions/v2/2.6/changesets/10659.patch

This brings the Squid-3 cachemgr.cgi up to parity and backwards
compatibility with Squid 2.6 cachemgr.cgi

tools/cachemgr.cc

index 29eb93a99b06e5db4ac3e904864d720d9fb8afc6..c3becac532d34cd977bec0ebcba43063ebf6745b 100644 (file)
@@ -579,6 +579,27 @@ munge_other_line(const char *buf, cachemgr_request * req)
     return html;
 }
 
+static const char *
+munge_action_line(const char *_buf, cachemgr_request * req)
+{
+    static char html[2 * 1024];
+    char *buf = xstrdup(_buf);
+    char *x = buf;
+    const char *action, *description;
+    char *p;
+
+    if ((p = strchr(x, '\n')))
+       *p = '\0';
+    action = xstrtok(&x, '\t');
+    description = xstrtok(&x, '\t');
+    if (!description)
+       description = action;
+    if (!action)
+       return "";
+    snprintf(html, sizeof(html), " <a href=\"%s\">%s</a>", menu_url(req, action), description);
+    return html;
+}
+
 static int
 read_reply(int s, cachemgr_request * req)
 {
@@ -594,7 +615,7 @@ read_reply(int s, cachemgr_request * req)
 #endif
     /* interpretation states */
     enum {
-        isStatusLine, isHeaders, isBodyStart, isBody, isForward, isEof, isForwardEof, isSuccess, isError
+        isStatusLine, isHeaders, isActions, isBodyStart, isBody, isForward, isEof, isForwardEof, isSuccess, isError
     } istate = isStatusLine;
     int parse_menu = 0;
     const char *action = req->action;
@@ -688,6 +709,22 @@ read_reply(int s, cachemgr_request * req)
                 printf("<PRE>\n");
             }
 
+            istate = isActions;
+            /* yes, fall through, we do not want to loose the first line */
+
+        case isActions:
+            if (strncmp(buf, "action:", 7) == 0) {
+                fputs(" ", stdout);
+                fputs(munge_action_line(buf + 7, req), stdout);
+                break;
+            }
+            if (parse_menu) {
+                printf("<UL>\n");
+            } else {
+                printf("<HR noshade size=\"1px\">\n");
+                printf("<PRE>\n");
+            }
+
             istate = isBody;
             /* yes, fall through, we do not want to loose the first line */
 
@@ -708,9 +745,7 @@ read_reply(int s, cachemgr_request * req)
              * 401 to .cgi because web server filters out all auth info. Thus we
              * disable authentication headers for now.
              */
-            if (!strncasecmp(buf, "WWW-Authenticate:", 17) || !strncasecmp(buf, "Proxy-Authenticate:", 19))
-
-                ;      /* skip */
+            if (!strncasecmp(buf, "WWW-Authenticate:", 17) || !strncasecmp(buf, "Proxy-Authenticate:", 19));   /* skip */
             else
                 fputs(buf, stdout);