]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/SourceDomain.cc
Major ACL handling update, including the following changes:
[thirdparty/squid.git] / src / acl / SourceDomain.cc
CommitLineData
3841dd46 1/*
3841dd46 2 * DEBUG: section 28 Access Control
3 * AUTHOR: Duane Wessels
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
26ac0430 21 *
3841dd46 22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26ac0430 26 *
3841dd46 27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 *
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
33 */
34
582c2af2 35#include "squid.h"
c0941a6a
AR
36#include "acl/SourceDomain.h"
37#include "acl/Checklist.h"
38#include "acl/RegexData.h"
39#include "acl/DomainData.h"
95e6d864 40#include "fqdncache.h"
3ff65596 41#include "HttpRequest.h"
3841dd46 42
3841dd46 43SourceDomainLookup SourceDomainLookup::instance_;
44
45SourceDomainLookup *
46SourceDomainLookup::Instance()
47{
48 return &instance_;
49}
50
51void
077fe581 52SourceDomainLookup::checkForAsync(ACLChecklist *checklist) const
3841dd46 53{
c0941a6a 54 fqdncache_nbgethostbyaddr(Filled(checklist)->src_addr, LookupDone, checklist);
3841dd46 55}
56
57void
3ff65596 58SourceDomainLookup::LookupDone(const char *fqdn, const DnsLookupDetails &details, void *data)
3841dd46 59{
3ff65596 60 ACLFilledChecklist *checklist = Filled((ACLChecklist*)data);
3ff65596
AR
61 checklist->markSourceDomainChecked();
62 checklist->request->recordLookup(details);
6f58d7d7 63 checklist->resumeNonBlockingCheck(SourceDomainLookup::Instance());
3841dd46 64}
65
5dee515e 66int
33810b1d 67ACLSourceDomainStrategy::match (ACLData<MatchType> * &data, ACLFilledChecklist *checklist, ACLFlags &)
3841dd46 68{
5dee515e 69 const char *fqdn = NULL;
70 fqdn = fqdncache_gethostbyaddr(checklist->src_addr, FQDN_LOOKUP_IF_MISS);
62e76326 71
5dee515e 72 if (fqdn) {
62e76326 73 return data->match(fqdn);
5dee515e 74 } else if (!checklist->sourceDomainChecked()) {
7660b45d 75 /* FIXME: Using AclMatchedName here is not OO correct. Should find a way to the current acl */
cc192b50 76 debugs(28, 3, "aclMatchAcl: Can't yet compare '" << AclMatchedName << "' ACL for '" << checklist->src_addr << "'");
6f58d7d7
AR
77 if (checklist->goAsync(SourceDomainLookup::Instance()))
78 return -1;
79 // else fall through to "none" match, hiding the lookup failure (XXX)
5dee515e 80 }
62e76326 81
5dee515e 82 return data->match("none");
3841dd46 83}
5dee515e 84
85ACLSourceDomainStrategy *
86ACLSourceDomainStrategy::Instance()
87{
88 return &Instance_;
89}
90
91ACLSourceDomainStrategy ACLSourceDomainStrategy::Instance_;