]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CacheManager.h
Merged from trunk.
[thirdparty/squid.git] / src / CacheManager.h
1
2 /*
3 * $Id: CacheManager.h,v 1.2 2008/02/26 21:49:34 amosjeffries Exp $
4 *
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 */
33
34 #ifndef SQUID_CACHEMANAGER_H
35 #define SQUID_CACHEMANAGER_H
36
37 #include "squid.h"
38 #include "Array.h"
39
40 /**
41 \defgroup CacheManagerAPI Cache Manager API
42 \ingroup Components
43
44 \defgroup CacheManagerInternal Cache Manager intenal API (not for public use)
45 \ingroup CacheManagerAPI
46 */
47
48 /**
49 \ingroup CacheManagerInternal
50 * The basic action handler. Its virtual method run(StoreEntry *) is invoked
51 * to perform the actual action.
52 */
53 class CacheManagerAction {
54 public:
55 virtual void run(StoreEntry *sentry) = 0;
56 char *action;
57 char *desc;
58 struct
59 {
60 unsigned int pw_req:1;
61 unsigned int atomic:1;
62 } flags;
63 virtual ~CacheManagerAction();
64 CacheManagerAction(char const *anAction, char const *aDesc, unsigned int isPwReq, unsigned int isAtomic);
65
66 };
67
68 /**
69 \ingroup CacheManagerInternal
70 * wrapper allowing c-style callbacks to be used. Arguments are supposed to
71 * managed by the caller.
72 * This object is generated by CacheManager::registerAction
73 */
74 class CacheManagerActionLegacy : public CacheManagerAction {
75 public:
76 OBJH *handler;
77 virtual void run (StoreEntry *sentry);
78 CacheManagerActionLegacy(char const *anAction, char const *aDesc, unsigned int isPwReq, unsigned int isAtomic, OBJH *aHandler);
79 };
80
81
82 /**
83 \ingroup CacheManagerAPI
84 * a CacheManager - the menu system for interacting with squid.
85 * This is currently just an adapter to the global cachemgr* routines to
86 * provide looser coupling between modules, but once fully transitioned,
87 * an instance of this class will represent a single independent manager.
88 * TODO: update documentation to reflect the new singleton model.
89 */
90 class CacheManager
91 {
92
93 public:
94 /* the holy trinity - assignment, copy cons, destructor */
95 /* unimplemented - prevents bugs from synthetic */
96 CacheManager & operator = (CacheManager &);
97 /* unimplemented - prevents bugs from synthetic */
98 CacheManager(CacheManager const &);
99 /* inline so that we dont need to link in cachemgr.cc at all in tests */
100 virtual ~CacheManager() {}
101
102 void registerAction(char const * action, char const * desc, OBJH * handler, int pw_req_flag, int atomic);
103 void registerAction(CacheManagerAction *anAction);
104 CacheManagerAction * findAction(char const * action);
105
106 void Start(int fd, HttpRequest * request, StoreEntry * entry);
107
108 static CacheManager* GetInstance();
109 const char *ActionProtection(const CacheManagerAction * at);
110
111 protected:
112 // command classes. They are private to the cachemanager, they
113 // may require access to local data, plus we avoid polluting
114 // the namespace more than needed.
115 class ShutdownAction : public CacheManagerAction {
116 public:
117 virtual void run (StoreEntry *sentry);
118 ShutdownAction();
119 };
120 class ReconfigureAction : public CacheManagerAction {
121 public:
122 virtual void run (StoreEntry *sentry);
123 ReconfigureAction();
124 };
125 class OfflineToggleAction : public CacheManagerAction {
126 public:
127 virtual void run (StoreEntry *sentry);
128 OfflineToggleAction();
129 };
130 class MenuAction : public CacheManagerAction {
131 private:
132 //needs to reference the cachemgr in order to get to ActionsList
133 CacheManager *cmgr;
134 public:
135 virtual void run (StoreEntry *sentry);
136 MenuAction(CacheManager *);
137
138 };
139
140 /// \ingroup CacheManagerInternal
141 typedef struct
142 {
143 StoreEntry *entry;
144 char *action;
145 char *user_name;
146 char *passwd;
147 } cachemgrStateData;
148
149
150 CacheManager();
151 cachemgrStateData* ParseUrl(const char *url);
152 void ParseHeaders(cachemgrStateData * mgr, const HttpRequest * request);
153 int CheckPassword(cachemgrStateData * mgr);
154 char *PasswdGet(cachemgr_passwd *, const char *);
155
156 // \ingroup CacheManagerInternal
157 typedef Vector<CacheManagerAction *> CacheManagerActionList;
158 CacheManagerActionList ActionsList;
159
160
161 private:
162 static CacheManager* instance;
163
164 void StateFree(cachemgrStateData * mgr);
165
166
167 };
168
169 #endif /* SQUID_CACHEMANAGER_H */