This adds support for multiple output formats in the manager actions.

As discussed earlier it makes use of the file extension concept.

For example:    /action.html

Would pass "html" in the format parameter. If the action is able to produce HTML output, it can test for this format type and do so. The default format is "txt" for backward compatibility.


Amos
--
Please be using
  Current Stable Squid 2.7.STABLE9 or 3.1.14
  Beta testers wanted for 3.2.0.10
=== modified file 'src/cache_manager.cc'
--- src/cache_manager.cc	2011-07-04 01:48:32 +0000
+++ src/cache_manager.cc	2011-07-11 10:50:03 +0000
@@ -56,6 +56,9 @@
 #include "wordlist.h"
 #include <algorithm>
 
+#if HAVE_STRING_H
+#include <string.h>
+#endif
 
 /// \ingroup CacheManagerInternal
 #define MGR_PASSWD_SZ 128
@@ -221,6 +224,15 @@
     }
 #endif
 
+    // determine content type to output.
+    const char *format = strrchr(request,'.');
+    if (format) {
+        request[(format-request)] = '\0';
+        ++format;
+    } else {
+        format = "txt"; // default if none.
+    }
+
     Mgr::ActionProfile::Pointer profile = findAction(request);
     if (!profile) {
         debugs(16, DBG_IMPORTANT, "CacheManager::ParseUrl: action '" << request << "' not found");
@@ -241,6 +253,7 @@
     cmd->params.userName = String();
     cmd->params.password = password;
     cmd->params.actionName = request;
+    cmd->params.format = format;
     return cmd;
 }
 

=== modified file 'src/internal.cc'
--- src/internal.cc	2011-07-04 01:48:32 +0000
+++ src/internal.cc	2011-07-11 11:33:20 +0000
@@ -74,6 +74,7 @@
     } else if (0 == strncmp(upath, "/squid-internal-mgr/", 20)) {
         CacheManager::GetInstance()->Start(clientConn, request, entry);
     } else {
+        debugs(0,0,HERE << "upath[20]=" << upath[20]);
         debugObj(76, 1, "internalStart: unknown request:\n",
                  request, (ObjPackMethod) & httpRequestPack);
         err = errorCon(ERR_INVALID_REQ, HTTP_NOT_FOUND, request);

=== modified file 'src/mgr/Action.h'
--- src/mgr/Action.h	2010-10-29 00:12:28 +0000
+++ src/mgr/Action.h	2011-07-15 03:04:29 +0000
@@ -80,7 +85,7 @@
     virtual void dump(StoreEntry *entry) {}
 
 
-private:
+protected:
     const CommandPointer cmd; ///< the command that caused this action
 
 

=== modified file 'src/mgr/ActionParams.cc'
--- src/mgr/ActionParams.cc	2011-01-24 17:24:59 +0000
+++ src/mgr/ActionParams.cc	2011-07-11 08:14:29 +0000
@@ -25,6 +25,7 @@
     msg.getPod(httpFlags);
 
     msg.getString(actionName);
+    msg.getString(format);
     msg.getString(userName);
     msg.getString(password);
     queryParams.unpack(msg);
@@ -38,6 +39,7 @@
     msg.putPod(httpFlags);
 
     msg.putString(actionName);
+    msg.putString(format);
     msg.putString(userName);
     msg.putString(password);
     queryParams.pack(msg);

=== modified file 'src/mgr/ActionParams.h'
--- src/mgr/ActionParams.h	2011-01-24 17:24:59 +0000
+++ src/mgr/ActionParams.h	2011-07-11 08:13:54 +0000
@@ -32,6 +32,7 @@
 
     /* action parameters extracted from the client HTTP request */
     String actionName; ///< action name (and credentials realm)
+    String format; ///< output format. ie txt or html
     String userName; ///< user login name; currently only used for logging
     String password; ///< user password; used for acceptance check and cleared
     QueryParams queryParams;

Reply via email to