]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/headermap.h
Security-164.1.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / headermap.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // headermap - represent Internet-standard headers
21 //
22 //@@@ Handle duplicate entries.
23 //@@@ Be flexible: think HTTP (append with commas) vs. RFC822 (multiple Received: headers etc.)
24 //
25 #ifndef _H_HEADERMAP
26 #define _H_HEADERMAP
27
28 #include <string>
29 #include <map>
30
31
32 namespace Security {
33
34
35 //
36 // Header-maps
37 //
38 class HeaderMap {
39 static const int maxKeyLength = 80;
40 typedef std::map<std::string, std::string> Map;
41 public:
42 HeaderMap() { }
43 virtual ~HeaderMap() { }
44
45 virtual void merge(std::string key, std::string &old, std::string newValue);
46
47 void add(const char *key, const char *value);
48 void add(const char *line); // Key: value
49 void remove(const char *key);
50
51 const char *find(const char *key, const char *def = NULL) const;
52 std::string &operator [] (const char *key);
53
54 typedef Map::const_iterator ConstIterator;
55 ConstIterator begin() const { return mMap.begin(); }
56 ConstIterator end() const { return mMap.end(); }
57
58 typedef Map::const_iterator Iterator;
59 Iterator begin() { return mMap.begin(); }
60 Iterator end() { return mMap.end(); }
61
62 std::string collect(const char *lineEnding = "\r\n") const;
63 size_t collectLength(const char *lineEnding = "\r\n") const;
64
65 private:
66 //
67 // In-place case canonicalization of header keys
68 //
69 struct CanonicalKey {
70 CanonicalKey(const char *key, char end = '\0');
71 operator const char *() const { return mValue; }
72 operator std::string () const { return mValue; }
73 private:
74 char mValue[maxKeyLength];
75 };
76
77 void add(const CanonicalKey &key, const char *value);
78
79 private:
80 Map mMap; // map of key: value pairs
81 };
82
83
84 } // end namespace Security
85
86
87 #endif /* _H_HEADERMAP */