]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Refactored menu action.
authorFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 4 Jul 2008 19:14:12 +0000 (21:14 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 4 Jul 2008 19:14:12 +0000 (21:14 +0200)
Changed cachemgrStateData to protected.

src/CacheManager.h
src/cache_manager.cc

index 9394761d029336da004e1cfd60da4b79be523fb6..092d3ad57cf682bd9392900647fcd496b4c902f5 100644 (file)
@@ -73,15 +73,6 @@ public:
 class CacheManagerActionList : public Vector<CacheManagerAction *> {
 };
 
-/// \ingroup CacheManagerInternal
-typedef struct
-{
-    StoreEntry *entry;
-    char *action;
-    char *user_name;
-    char *passwd;
-} cachemgrStateData;
-
 /**
  \ingroup CacheManagerAPI
  * a CacheManager - the menu system for interacting with squid.
@@ -112,12 +103,6 @@ public:
     const char *ActionProtection(const CacheManagerAction * at); //needs to be called from C
 
 protected:
-    CacheManager(); 
-    cachemgrStateData* ParseUrl(const char *url);
-    void ParseHeaders(cachemgrStateData * mgr, const HttpRequest * request);
-    int CheckPassword(cachemgrStateData * mgr);
-    char *PasswdGet(cachemgr_passwd *, const char *);
-
     // command classes. They are private to the cachemanager because they
     // may require access to local data sources, plus we avoid polluting
     // the namespace more than needed.
@@ -136,18 +121,31 @@ protected:
          virtual void run (StoreEntry *sentry);
          OfflineToggleAction();
     };
+    class MenuAction : public CacheManagerAction {
+    public:
+         virtual void run (StoreEntry *sentry);
+         MenuAction();
+    };
 
+/// \ingroup CacheManagerInternal
+typedef struct
+{
+    StoreEntry *entry;
+    char *action;
+    char *user_name;
+    char *passwd;
+} cachemgrStateData;
+
+
+    CacheManager(); 
+    cachemgrStateData* ParseUrl(const char *url);
+    void ParseHeaders(cachemgrStateData * mgr, const HttpRequest * request);
+    int CheckPassword(cachemgrStateData * mgr);
+    char *PasswdGet(cachemgr_passwd *, const char *);
 
 private:
     static CacheManager* instance;
 
-    //commands need to be static to be able to be referenced as C-style
-    //functions. Binding to nonstatic members can be done at runtime
-    //via the singleton, but it's syntactic hackery
-    //TODO: fix so that ActionTable uses a Command pattern and thus
-    //      function calls are properly object-wrapped
-    static void MenuCommand(StoreEntry *sentry);
-
     void StateFree(cachemgrStateData * mgr);
 
 
index 5b7b76778dd31d3760fe121e44fb60ced5cea101..8de91f2d681903af32d5ef8e3b4fa00e288d911d 100644 (file)
@@ -60,11 +60,10 @@ CacheManager::CacheManager()
     if (ActionsList != NULL)
          delete(ActionsList); //TODO: Laaazy. Will be moved to class member
     ActionsList = new CacheManagerActionList;
-    registerAction("menu", "This Cachemanager Menu", MenuCommand, 0, 1);
-    //registerAction("offline_toggle", "Toggle offline_mode setting", OfflineToggleCommand, 1, 1);
     registerAction(new OfflineToggleAction);
     registerAction(new ShutdownAction);
     registerAction(new ReconfigureAction);
+    registerAction(new MenuAction);
 }
 
 void
@@ -99,7 +98,6 @@ CacheManager::findAction(char const * action)
 
     debugs(16, 5, "CacheManager::findAction: looking for action " << action);
     for ( a = ActionsList->begin(); a != ActionsList->end(); a++) {
-       //debugs(16, 6, " checking against '" << (*a)->action << "'");
         if (0 == strcmp((*a)->action, action)) {
             debugs(16, 6, " found");
             return *a;
@@ -111,7 +109,7 @@ CacheManager::findAction(char const * action)
 }
 
 /// \ingroup CacheManagerInternal
-cachemgrStateData *
+CacheManager::cachemgrStateData *
 CacheManager::ParseUrl(const char *url)
 {
     int t;
@@ -384,7 +382,7 @@ CacheManager::ActionProtection(const CacheManagerAction * at)
 
 /// \ingroup CacheManagerInternal
 void
-CacheManager::MenuCommand(StoreEntry * sentry)
+CacheManager::MenuAction::run(StoreEntry * sentry)
 {
     CacheManagerActionList::iterator a;
 
@@ -395,6 +393,7 @@ CacheManager::MenuCommand(StoreEntry * sentry)
             (*a)->action, (*a)->desc, CacheManager::GetInstance()->ActionProtection(*a));
     }
 }
+CacheManager::MenuAction::MenuAction() : CacheManagerAction ("menu", "Cache Manager Menu", 1, 1) { }
 
 /// \ingroup CacheManagerInternal
 char *