From: Kinkie Date: Sun, 29 Jun 2008 20:29:02 +0000 (+0200) Subject: More refactoring, moved C-style methods into C++-style declarations X-Git-Tag: SQUID_3_1_0_1~49^2~143^2~53^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00b0115f5201966d65834508aefa74d257ec522c;p=thirdparty%2Fsquid.git More refactoring, moved C-style methods into C++-style declarations --- diff --git a/src/CacheManager.h b/src/CacheManager.h index 9014188584..2a5397233a 100644 --- a/src/CacheManager.h +++ b/src/CacheManager.h @@ -66,6 +66,15 @@ public: }; +/// \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. @@ -88,10 +97,14 @@ public: virtual void registerAction(char const * action, char const * desc, OBJH * handler, int pw_req_flag, int atomic); virtual CacheManagerAction * findAction(char const * action); + virtual void Start(int fd, HttpRequest * request, StoreEntry * entry); + static CacheManager* GetInstance(); protected: CacheManager(); + virtual cachemgrStateData* ParseUrl(const char *url); + virtual void ParseHeaders(cachemgrStateData * mgr, const HttpRequest * request); private: static CacheManager* instance; diff --git a/src/cache_manager.cc b/src/cache_manager.cc index 6273088a4f..d0cc60bf6d 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -50,18 +50,8 @@ /// \ingroup CacheManagerInternal #define MGR_PASSWD_SZ 128 -/// \ingroup CacheManagerInternal -typedef struct -{ - StoreEntry *entry; - char *action; - char *user_name; - char *passwd; -} cachemgrStateData; static CacheManagerAction *cachemgrFindAction(const char *action); -static cachemgrStateData *cachemgrParseUrl(const char *url); -static void cachemgrParseHeaders(cachemgrStateData * mgr, const HttpRequest * request); static int cachemgrCheckPassword(cachemgrStateData *); static void cachemgrStateFree(cachemgrStateData * mgr); static char *cachemgrPasswdGet(cachemgr_passwd *, const char *); @@ -134,8 +124,8 @@ cachemgrFindAction(const char *action) } /// \ingroup CacheManagerInternal -static cachemgrStateData * -cachemgrParseUrl(const char *url) +cachemgrStateData * +CacheManager::ParseUrl(const char *url) { int t; LOCAL_ARRAY(char, host, MAX_URL); @@ -158,13 +148,13 @@ cachemgrParseUrl(const char *url) #endif } else if ((a = cachemgrFindAction(request)) == NULL) { - debugs(16, 1, "cachemgrParseUrl: action '" << request << "' not found"); + debugs(16, 1, "CacheManager::ParseUrl: action '" << request << "' not found"); return NULL; } else { prot = cachemgrActionProtection(a); if (!strcmp(prot, "disabled") || !strcmp(prot, "hidden")) { - debugs(16, 1, "cachemgrParseUrl: action '" << request << "' is " << prot); + debugs(16, 1, "CacheManager::ParseUrl: action '" << request << "' is " << prot); return NULL; } } @@ -182,8 +172,8 @@ cachemgrParseUrl(const char *url) } /// \ingroup CacheManagerInternal -static void -cachemgrParseHeaders(cachemgrStateData * mgr, const HttpRequest * request) +void +CacheManager::ParseHeaders(cachemgrStateData * mgr, const HttpRequest * request) { const char *basic_cookie; /* base 64 _decoded_ user:passwd pair */ const char *passwd_del; @@ -194,7 +184,7 @@ cachemgrParseHeaders(cachemgrStateData * mgr, const HttpRequest * request) return; if (!(passwd_del = strchr(basic_cookie, ':'))) { - debugs(16, 1, "cachemgrParseHeaders: unknown basic_cookie format '" << basic_cookie << "'"); + debugs(16, 1, "CacheManager::ParseHeaders: unknown basic_cookie format '" << basic_cookie << "'"); return; } @@ -210,7 +200,7 @@ cachemgrParseHeaders(cachemgrStateData * mgr, const HttpRequest * request) mgr->passwd = xstrdup(passwd_del + 1); /* warning: this prints decoded password which maybe not what you want to do @?@ @?@ */ - debugs(16, 9, "cachemgrParseHeaders: got user: '" << mgr->user_name << "' passwd: '" << mgr->passwd << "'"); + debugs(16, 9, "CacheManager::ParseHeaders: got user: '" << mgr->user_name << "' passwd: '" << mgr->passwd << "'"); } /** @@ -255,14 +245,14 @@ cachemgrStateFree(cachemgrStateData * mgr) // API void -cachemgrStart(int fd, HttpRequest * request, StoreEntry * entry) +CacheManager::Start(int fd, HttpRequest * request, StoreEntry * entry) { cachemgrStateData *mgr = NULL; ErrorState *err = NULL; CacheManagerAction *a; debugs(16, 3, "objectcacheStart: '" << entry->url() << "'" ); - if ((mgr = cachemgrParseUrl(entry->url())) == NULL) { + if ((mgr = ParseUrl(entry->url())) == NULL) { err = errorCon(ERR_INVALID_URL, HTTP_NOT_FOUND, request); err->url = xstrdup(entry->url()); errorAppendEntry(entry, err); @@ -278,7 +268,7 @@ cachemgrStart(int fd, HttpRequest * request, StoreEntry * entry) debugs(16, 5, "CACHEMGR: " << fd_table[fd].ipaddr << " requesting '" << mgr->action << "'"); /* get additional info from request headers */ - cachemgrParseHeaders(mgr, request); + ParseHeaders(mgr, request); /* Check password */ diff --git a/src/forward.cc b/src/forward.cc index 41875152db..bc94625e7c 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -256,7 +256,7 @@ FwdState::fwdStart(int client_fd, StoreEntry *entry, HttpRequest *request) return; case PROTO_CACHEOBJ: - cachemgrStart(client_fd, request, entry); + CacheManager::GetInstance()->Start(client_fd, request, entry); return; case PROTO_URN: