]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/NoteData.cc
Merged from trunk r12948.
[thirdparty/squid.git] / src / acl / NoteData.cc
1 #include "squid.h"
2 #include "acl/Acl.h"
3 #include "acl/Checklist.h"
4 #include "acl/NoteData.h"
5 #include "acl/StringData.h"
6 #include "cache_cf.h"
7 #include "ConfigParser.h"
8 #include "Debug.h"
9 #include "HttpRequest.h"
10 #include "Notes.h"
11 #include "wordlist.h"
12
13 ACLNoteData::ACLNoteData() : values(new ACLStringData)
14 {}
15
16 ACLNoteData::~ACLNoteData()
17 {
18 delete values;
19 }
20
21 bool
22 ACLNoteData::matchNotes(NotePairs *note)
23 {
24 if (note == NULL)
25 return false;
26
27 debugs(28, 3, "Checking " << name);
28
29 if (values->empty())
30 return (note->findFirst(name.termedBuf()) != NULL);
31
32 for (Vector<NotePairs::Entry *>::iterator i = note->entries.begin(); i!= note->entries.end(); ++i) {
33 if ((*i)->name.cmp(name.termedBuf()) == 0) {
34 if (values->match((*i)->value.termedBuf()))
35 return true;
36 }
37 }
38 return false;
39 }
40
41 bool
42 ACLNoteData::match(HttpRequest *request)
43 {
44 if (request->notes != NULL && matchNotes(request->notes.getRaw()))
45 return true;
46 #if USE_ADAPTATION
47 const Adaptation::History::Pointer ah = request->adaptLogHistory();
48 if (ah != NULL && ah->metaHeaders != NULL && matchNotes(ah->metaHeaders.getRaw()))
49 return true;
50 #endif
51 return false;
52 }
53
54 wordlist *
55 ACLNoteData::dump()
56 {
57 wordlist *W = NULL;
58 wordlistAdd(&W, name.termedBuf());
59 wordlist * dumpR = values->dump();
60 wordlistAddWl(&W, dumpR);
61 wordlistDestroy(&dumpR);
62 return W;
63 }
64
65 void
66 ACLNoteData::parse()
67 {
68 char* t = strtokFile();
69 assert (t != NULL);
70 name = t;
71 values->parse();
72 }
73
74 bool
75 ACLNoteData::empty() const
76 {
77 return name.undefined();
78 }
79
80 ACLData<HttpRequest *> *
81 ACLNoteData::clone() const
82 {
83 ACLNoteData * result = new ACLNoteData;
84 result->values = values->clone();
85 result->name = name;
86 return result;
87 }