]> git.ipfire.org Git - thirdparty/squid.git/blame - src/Notes.h
Fix helper reply length detection
[thirdparty/squid.git] / src / Notes.h
CommitLineData
b3404bc5
CT
1#ifndef SQUID_NOTES_H
2#define SQUID_NOTES_H
3
4#include "HttpHeader.h"
5#include "HttpHeaderTools.h"
6#include "typedefs.h"
7
8#if HAVE_STRING
9#include <string>
10#endif
11
b3404bc5
CT
12class HttpRequest;
13class HttpReply;
14
15/**
16 * Used to store notes. The notes are custom key:value pairs
17 * ICAP request headers or ECAP options used to pass
18 * custom transaction-state related meta information to squid
19 * internal subsystems or to addaptation services.
20 */
21class Note: public RefCountable
22{
23public:
24 typedef RefCount<Note> Pointer;
25 /// Stores a value for the note.
26 class Value: public RefCountable
27 {
28 public:
29 typedef RefCount<Value> Pointer;
30 String value; ///< a note value
31 ACLList *aclList; ///< The access list used to determine if this value is valid for a request
32 explicit Value(const String &aVal) : value(aVal), aclList(NULL) {}
33 ~Value();
34 };
35 typedef Vector<Value::Pointer> Values;
36
37 explicit Note(const String &aKey): key(aKey) {}
38
39 /**
40 * Adds a value to the note and returns a pointer to the
41 * related Value object.
42 */
43 Value::Pointer addValue(const String &value);
44
45 /**
46 * Walks through the possible values list of the note and selects
47 * the first value which matches the given HttpRequest and HttpReply
48 * or NULL if none matches.
49 */
50 const char *match(HttpRequest *request, HttpReply *reply);
51 String key; ///< The note key
52 Values values; ///< The possible values list for the note
53};
54
55class ConfigParser;
56/**
57 * Used to store a notes list.
58 */
ffb82151
A
59class Notes
60{
b3404bc5
CT
61public:
62 typedef Vector<Note::Pointer> NotesList;
63 typedef NotesList::iterator iterator; ///< iterates over the notes list
bc600349 64 typedef NotesList::const_iterator const_iterator; ///< iterates over the notes list
b3404bc5
CT
65
66 Notes(const char *aDescr, const char **metasBlacklist): descr(aDescr), blacklisted(metasBlacklist) {}
67 Notes(): descr(NULL), blacklisted(NULL) {}
68 ~Notes() { notes.clean(); }
69 /**
70 * Parse a notes line and returns a pointer to the
71 * parsed Note object.
72 */
73 Note::Pointer parse(ConfigParser &parser);
74 /**
75 * Dump the notes list to the given StoreEntry object.
76 */
77 void dump(StoreEntry *entry, const char *name);
78 void clean(); /// clean the notes list
79
80 /// points to the first argument
81 iterator begin() { return notes.begin(); }
82 /// points to the end of list
83 iterator end() { return notes.end(); }
84 /// return true if the notes list is empty
85 bool empty() { return notes.empty(); }
86
87 NotesList notes; ///< The Note::Pointer objects array list
88 const char *descr; ///< A short description for notes list
89 const char **blacklisted; ///< Null terminated list of blacklisted note keys
90private:
91 /**
92 * Adds a note to the notes list and returns a pointer to the
93 * related Note object. If the note key already exists in list,
94 * returns a pointer to the existing object.
95 */
96 Note::Pointer add(const String &noteKey);
bc600349
AJ
97
98public:
99 /**
100 * Adds a note key and value to the notes list.
101 * If the key name already exists in list, add the given value to its set of values.
102 */
103 void add(const String &noteKey, const String &noteValue);
104
105 /**
106 * Looks up a note by key name and returns a Note::Pointer to it
107 */
108 Note::Pointer findByName(const String &noteKey) const;
b3404bc5
CT
109};
110
ffb82151
A
111class NotePairs : public HttpHeader
112{
b3404bc5
CT
113public:
114 NotePairs() : HttpHeader(hoNote) {}
115};
116
117#endif