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