From: Amos Jeffries Date: Fri, 22 Feb 2013 13:26:12 +0000 (+1300) Subject: SourceLayout: shuffle BasicAuthQueueNode to Auth:: namespace X-Git-Tag: SQUID_3_4_0_1~258 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bf9294334586a86cf68a50cfb25e17baa4cea104;p=thirdparty%2Fsquid.git SourceLayout: shuffle BasicAuthQueueNode to Auth:: namespace ... and document what it is used for by authentication. There is only one logic change in this patch. The QueueNode destructor is added to clear the queued CBDATA entries when the queue is deleted. Previously the pointer was just erased in hopes that the queue was notified prior to deletion. --- diff --git a/src/auth/Makefile.am b/src/auth/Makefile.am index 1abb966dfc..2423048bf2 100644 --- a/src/auth/Makefile.am +++ b/src/auth/Makefile.am @@ -18,6 +18,7 @@ libauth_la_SOURCES = \ CredentialState.h \ Gadgets.cc \ Gadgets.h \ + QueueNode.h \ Scheme.cc \ Scheme.h \ State.h \ diff --git a/src/auth/QueueNode.h b/src/auth/QueueNode.h new file mode 100644 index 0000000000..70bf0b8248 --- /dev/null +++ b/src/auth/QueueNode.h @@ -0,0 +1,49 @@ +#ifndef SQUID_SRC_AUTH_QUEUENODE_H +#define SQUID_SRC_AUTH_QUEUENODE_H + +namespace Auth +{ + +/** + * A queue of auth requests waiting for verification to occur. + * + * Certain authentication schemes such a Basic and Bearer auth + * permit credentials tokens to be repeated from multiple sources + * simultaneously. This queue node allows multiple validation + * queries to be collapsed into one backend helper lookup. + * CBDATA and handlers stored in these queue nodes can be notified + * all at once with a result when the lookup completes. + */ +class QueueNode +{ + +private: + // we store CBDATA here, copy is not safe + QueueNode(const QueueNode &); + QueueNode &operator =(const QueueNode &); + +public: + QueueNode(Auth::UserRequest *aRequest, AUTHCB *aHandler, void *aData) : auth_user_request(aRequest), handler(aHandler), data(cbdataReference(aData)) {} + ~QueueNode() { + cbdataReferenceDone(data); + while (next) { + QueueNode *tmp = next->next; + next->next = NULL; + delete next; + next = tmp; + }; + } + + Auth::QueueNode *next; + Auth::UserRequest::Pointer auth_user_request; + AUTHCB *handler; + void *data; + + MEMPROXY_CLASS(Auth::QueueNode); +}; + +MEMPROXY_CLASS_INLINE(Auth::QueueNode); + +} // namespace Auth + +#endif /* SQUID_SRC_AUTH_QUEUENODE_H */ diff --git a/src/auth/basic/User.cc b/src/auth/basic/User.cc index 0b598f6923..66320d2241 100644 --- a/src/auth/basic/User.cc +++ b/src/auth/basic/User.cc @@ -8,7 +8,7 @@ Auth::Basic::User::User(Auth::Config *aConfig) : Auth::User(aConfig), passwd(NULL), - auth_queue(NULL), + queue(NULL), currentRequest(NULL) {} diff --git a/src/auth/basic/User.h b/src/auth/basic/User.h index c5d5fd2f36..52ed43cfb5 100644 --- a/src/auth/basic/User.h +++ b/src/auth/basic/User.h @@ -4,12 +4,11 @@ #include "auth/User.h" #include "auth/UserRequest.h" -class BasicAuthQueueNode; - namespace Auth { class Config; +class QueueNode; namespace Basic { @@ -31,7 +30,7 @@ public: char *passwd; - BasicAuthQueueNode *auth_queue; + QueueNode *queue; private: Auth::UserRequest::Pointer currentRequest; diff --git a/src/auth/basic/UserRequest.cc b/src/auth/basic/UserRequest.cc index 669c8beb7c..c85830fc3d 100644 --- a/src/auth/basic/UserRequest.cc +++ b/src/auth/basic/UserRequest.cc @@ -2,6 +2,7 @@ #include "auth/basic/auth_basic.h" #include "auth/basic/User.h" #include "auth/basic/UserRequest.h" +#include "auth/QueueNode.h" #include "auth/State.h" #include "charset.h" #include "Debug.h" @@ -96,15 +97,11 @@ Auth::Basic::UserRequest::module_start(AUTHCB * handler, void *data) if (user()->credentials() == Auth::Pending) { /* there is a request with the same credentials already being verified */ - BasicAuthQueueNode *node = static_cast(xcalloc(1, sizeof(BasicAuthQueueNode))); - assert(node); - node->auth_user_request = this; - node->handler = handler; - node->data = cbdataReference(data); + Auth::QueueNode *node = new Auth::QueueNode(this, handler, data); /* queue this validation request to be infored of the pending lookup results */ - node->next = basic_auth->auth_queue; - basic_auth->auth_queue = node; + node->next = basic_auth->queue; + basic_auth->queue = node; return; } // otherwise submit this request to the auth helper(s) for validation @@ -139,7 +136,6 @@ void Auth::Basic::UserRequest::HandleReply(void *data, const HelperReply &reply) { Auth::StateData *r = static_cast(data); - BasicAuthQueueNode *tmpnode; void *cbdata; debugs(29, 5, HERE << "reply=" << reply); @@ -168,15 +164,15 @@ Auth::Basic::UserRequest::HandleReply(void *data, const HelperReply &reply) cbdataReferenceDone(r->data); - while (basic_auth->auth_queue) { - tmpnode = basic_auth->auth_queue->next; + while (basic_auth->queue) { + if (cbdataReferenceValidDone(basic_auth->queue->data, &cbdata)) + basic_auth->queue->handler(cbdata); - if (cbdataReferenceValidDone(basic_auth->auth_queue->data, &cbdata)) - basic_auth->auth_queue->handler(cbdata); + Auth::QueueNode *tmpnode = basic_auth->queue->next; + basic_auth->queue->next = NULL; + delete basic_auth->queue; - xfree(basic_auth->auth_queue); - - basic_auth->auth_queue = tmpnode; + basic_auth->queue = tmpnode; } delete r; diff --git a/src/auth/basic/auth_basic.h b/src/auth/basic/auth_basic.h index e519fab8da..3e10b21f6d 100644 --- a/src/auth/basic/auth_basic.h +++ b/src/auth/basic/auth_basic.h @@ -13,17 +13,6 @@ #define DefaultAuthenticateChildrenMax 32 /* 32 processes */ -/** queue of auth requests waiting for verification to occur */ -class BasicAuthQueueNode -{ - -public: - BasicAuthQueueNode *next; - Auth::UserRequest::Pointer auth_user_request; - AUTHCB *handler; - void *data; -}; - namespace Auth { namespace Basic