1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
* C++ ICAP library
* Copyright (C) 2012 Uditha Atukorala
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef ICAP_HEADER_H
#define ICAP_HEADER_H
#include "common.h"
#include <string>
#include <map>
#include <vector>
#include <functional>
namespace icap {
class Header {
public:
/* headers data type */
typedef std::map<std::string, std::string> headers_t;
/* headers iterator type */
typedef headers_t::iterator headers_index_t;
/* encapsulated header type */
typedef std::map<std::string, int> encapsulated_header_t;
/* encapsulated header iterator type */
typedef encapsulated_header_t::iterator encapsulated_header_index_t;
/* encapsulated header data type */
typedef std::pair<std::string, int> encapsulated_header_data_t;
/**
* Binary compare structure to compare two encapsulated header
* entity (data) values. Used for sorting.
*/
struct encapsulated_header_compare
: std::binary_function<icap::Header::encapsulated_header_data_t, icap::Header::encapsulated_header_data_t, bool> {
inline bool operator()( const icap::Header::encapsulated_header_data_t &lhs, const icap::Header::encapsulated_header_data_t &rhs ) {
return lhs.second < rhs.second;
}
};
Header();
virtual ~Header();
/**
* Return headers
* @return headers
*/
const headers_t &headers() const throw();
/**
* Returns the header value for the given header key or an empty string
* if the header is not found.
*
* @param key header key
* @return header value
*/
const std::string value( const std::string &key ) throw();
/**
* Return Encapsulated header value for the given entity
* or -1 if the given entity is invalid.
*
* @param entity encapsulated header entity
* @return -1 | encapsulated header value
*/
const int encapsulated_header( const std::string &entity ) throw();
/**
* Attach header data into the header
*
* <pre>
* e.g.
* Host: icap-server.net
* Encapsulated: req-hdr=0, null-body=170
* [key]: [value]
* </pre>
*
* @param key header key
* @param value header value
*/
virtual void attach( std::string key, std::string value ) throw();
/**
* Attach Encapsulated header data. This method should only be used
* when reading a raw request / response. Consider using update_encapsulated()
* method for other scenarios.
*
* <pre>
* e.g.
* Encapsulated: req-hdr=0, req-body=412
* Encapsulated: req-hdr=0, res-hdr=822, res-body=1655
* Encapsulated: [header_value]
* </pre>
*
* @param header_value Encapsulated header value
* @return boolean to denote success or failure
*/
virtual bool attach_encapsulated( std::string header_value ) throw();
/**
* Update Encapsulated header data using the passed in (icap::payload_t) payload.
* When the request / response has been populated with the payload, calling this
* method will update the encapsulated header entities with appropriate values.
*
* This methos will always succeed.
*
* @param payload request or response payload
*/
virtual void update_encapsulated( const payload_t &payload ) throw();
/**
* Remove header data from the header instance with the given key
*
* @param key header key
* @return boolean to denote success or failure
*/
virtual bool remove( std::string key ) throw();
/**
* Return Encapsulated header as a std::string value.
* @return encapsulated header value (e.g. res-hdr=0, res-body=213)
*/
virtual const std::string encapsulated_header_str() throw();
/**
* Sort the encapsulated header data and return a std::vector of
* encapsulated_header_data_t. The actual header data won't be changed.
*
* @return sorted encapsulated header
*/
virtual std::vector<encapsulated_header_data_t> sort_encapsulated_header();
protected:
headers_t _headers;
encapsulated_header_t _encapsulated;
private:
};
} /* end of namespace icap */
#endif /* !ICAP_HEADER_H */
|