From: Amos Jeffries Date: Mon, 29 Sep 2014 09:24:20 +0000 (-0700) Subject: Cleanup: convert AuthUserIP from CBDATA to MEMPROXY class X-Git-Tag: SQUID_3_5_0_1~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a98f21acbde858b3d2b1f0ed81f0bf44209b0922;p=thirdparty%2Fsquid.git Cleanup: convert AuthUserIP from CBDATA to MEMPROXY class This object was not needing to be passed as callback arguments but was using CBDATA type to gain memory pooling. Converting to the correct pooling mechanism removes some more uses of cbdataFree() and ensures the object and its members destructors are called properly. --- diff --git a/src/auth/User.cc b/src/auth/User.cc index 8ad57607d8..f07dbe57a8 100644 --- a/src/auth/User.cc +++ b/src/auth/User.cc @@ -21,9 +21,6 @@ #include "SquidTime.h" #include "Store.h" -// This should be converted into a pooled type. Does not need to be cbdata -CBDATA_TYPE(AuthUserIP); - time_t Auth::User::last_discard = 0; Auth::User::User(Auth::Config *aConfig, const char *aRequestRealm) : @@ -84,7 +81,7 @@ Auth::User::absorb(Auth::User::Pointer from) if (new_ipdata->ip_expiretime <= squid_curtime) { /* This IP has expired - remove from the source list */ dlinkDelete(&new_ipdata->node, &(from->ip_list)); - cbdataFree(new_ipdata); + delete new_ipdata; /* catch incipient underflow */ -- from->ipcount; } else { @@ -103,7 +100,7 @@ Auth::User::absorb(Auth::User::Pointer from) } else if (ipdata->ip_expiretime <= squid_curtime) { /* This IP has expired - cleanup the destination list */ dlinkDelete(&ipdata->node, &ip_list); - cbdataFree(ipdata); + delete ipdata; /* catch incipient underflow */ assert(ipcount); -- ipcount; @@ -229,7 +226,7 @@ Auth::User::clearIp() tempnode = (AuthUserIP *) ipdata->node.next; /* walk the ip list */ dlinkDelete(&ipdata->node, &ip_list); - cbdataFree(ipdata); + delete ipdata; /* catch incipient underflow */ assert(ipcount); -- ipcount; @@ -251,7 +248,7 @@ Auth::User::removeIp(Ip::Address ipaddr) if (ipdata->ipaddr == ipaddr) { /* remove the node */ dlinkDelete(&ipdata->node, &ip_list); - cbdataFree(ipdata); + delete ipdata; /* catch incipient underflow */ assert(ipcount); -- ipcount; @@ -269,8 +266,6 @@ Auth::User::addIp(Ip::Address ipaddr) AuthUserIP *ipdata = (AuthUserIP *) ip_list.head; int found = 0; - CBDATA_INIT_TYPE(AuthUserIP); - /* * we walk the entire list to prevent the first item in the list * preventing old entries being flushed and locking a user out after @@ -288,7 +283,7 @@ Auth::User::addIp(Ip::Address ipaddr) } else if (ipdata->ip_expiretime <= squid_curtime) { /* This IP has expired - remove from the seen list */ dlinkDelete(&ipdata->node, &ip_list); - cbdataFree(ipdata); + delete ipdata; /* catch incipient underflow */ assert(ipcount); -- ipcount; @@ -301,11 +296,7 @@ Auth::User::addIp(Ip::Address ipaddr) return; /* This ip is not in the seen list */ - ipdata = cbdataAlloc(AuthUserIP); - - ipdata->ip_expiretime = squid_curtime + ::Config.authenticateIpTTL; - - ipdata->ipaddr = ipaddr; + ipdata = new AuthUserIP(ipaddr, squid_curtime + ::Config.authenticateIpTTL); dlinkAddTail(ipdata, &ipdata->node, &ip_list); diff --git a/src/auth/UserRequest.h b/src/auth/UserRequest.h index 74f59b9ca7..ab54933144 100644 --- a/src/auth/UserRequest.h +++ b/src/auth/UserRequest.h @@ -33,12 +33,12 @@ class HttpRequest; /** * Node used to link an IP address to some user credentials * for the max_user_ip ACL feature. - * - * \ingroup AuthAPI */ class AuthUserIP { public: + AuthUserIP(const Ip::Address &ip, time_t t) : ipaddr(ip), ip_expiretime(t) {} + dlink_node node; /// IP address this user authenticated from @@ -49,8 +49,12 @@ public: * (user,IP) pair plus authenticate_ip_ttl seconds */ time_t ip_expiretime; + + MEMPROXY_CLASS(AuthUserIP); }; +MEMPROXY_CLASS_INLINE(AuthUserIP); + // TODO: make auth schedule AsyncCalls? typedef void AUTHCB(void*);