]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: convert AuthUserIP from CBDATA to MEMPROXY class
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 29 Sep 2014 09:24:20 +0000 (02:24 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 29 Sep 2014 09:24:20 +0000 (02:24 -0700)
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.

src/auth/User.cc
src/auth/UserRequest.h

index 8ad57607d8faf8f0f63f705bb91ebbf40af6f5a1..f07dbe57a8bc71cf00d670b680f8a43297f800a6 100644 (file)
@@ -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);
 
index 74f59b9ca7f0acbf51cf66741fbebe067ace9fb4..ab54933144f84276a865021d975ee5867a303c2a 100644 (file)
@@ -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*);