/src/resiprocate/resip/stack/Headers.hxx
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | #if !defined(RESIP_HEADERS_HXX)  | 
2  |  | #define RESIP_HEADERS_HXX   | 
3  |  |  | 
4  |  | #include "resip/stack/ParserCategories.hxx"  | 
5  |  | #include "resip/stack/HeaderTypes.hxx"  | 
6  |  | #include "resip/stack/Symbols.hxx"  | 
7  |  | #include "rutil/Data.hxx"  | 
8  |  | #include "rutil/HeapInstanceCounter.hxx"  | 
9  |  |  | 
10  |  | namespace resip  | 
11  |  | { | 
12  |  | class SipMessage;  | 
13  |  | class HeaderFieldValueList;  | 
14  |  |  | 
15  |  | //#define PARTIAL_TEMPLATE_SPECIALIZATION  | 
16  |  | #ifdef PARTIAL_TEMPLATE_SPECIALIZATION  | 
17  |  | template<bool>  | 
18  |  | class TypeIf  | 
19  |  | { | 
20  |  |    public:  | 
21  |  |       template <class T>  | 
22  |  |       class Resolve  | 
23  |  |       { | 
24  |  |          public:  | 
25  |  |             typedef T Type;  | 
26  |  |       };  | 
27  |  | };  | 
28  |  |  | 
29  |  | class UnusedHeader  | 
30  |  | { | 
31  |  | };  | 
32  |  |  | 
33  |  | class TypeIf<false>  | 
34  |  | { | 
35  |  |    public:  | 
36  |  |       template <class T>  | 
37  |  |       class Resolve  | 
38  |  |       { | 
39  |  |          public:  | 
40  |  |             typedef UnusedHeader Type;  | 
41  |  |       };  | 
42  |  | };  | 
43  |  |  | 
44  |  | #define UnusedChecking(_enum)                                           \  | 
45  |  |       typedef TypeIf<Headers::_enum != Headers::UNKNOWN> TypeIfT;       \  | 
46  |  |       typedef TypeIfT::Resolve<Type> Resolver;                          \  | 
47  |  |       typedef Resolver::Type UnknownReturn  | 
48  |  |  | 
49  |  | #define MultiUnusedChecking(_enum)                                              \  | 
50  |  |       typedef TypeIf<Headers::_enum != Headers::UNKNOWN> TypeIfT;               \  | 
51  |  |       typedef TypeIfT::Resolve< ParserContainer<Type> > Resolver;               \  | 
52  |  |       typedef Resolver::Type UnknownReturn  | 
53  |  |  | 
54  |  | #else  | 
55  |  |  | 
56  |  | #define UnusedChecking(_enum) typedef int _dummy  | 
57  |  | #define MultiUnusedChecking(_enum) typedef int _dummy  | 
58  |  |  | 
59  |  | #endif  | 
60  |  |  | 
61  |  | class HeaderBase  | 
62  |  | { | 
63  |  |    public:  | 
64  | 0  |       virtual ~HeaderBase() {} | 
65  |  |       virtual Headers::Type getTypeNum() const = 0;  | 
66  |  |       virtual void merge(SipMessage&, const SipMessage&)=0;  | 
67  |  |         | 
68  |  |       static HeaderBase* getInstance(Headers::Type typenum)  | 
69  | 0  |       { | 
70  | 0  |          return theHeaderInstances[typenum+1];  | 
71  | 0  |       }  | 
72  |  |         | 
73  |  |       virtual ParserContainerBase* makeContainer(HeaderFieldValueList* hfvs) const=0;  | 
74  |  |    protected:  | 
75  |  |       static HeaderBase* theHeaderInstances[Headers::MAX_HEADERS+1];  | 
76  |  | };  | 
77  |  |  | 
78  |  | #define defineHeader(_enum, _name, _type, _rfc)                 \  | 
79  |  | class H_##_enum : public HeaderBase                             \  | 
80  |  | {                                                               \ | 
81  |  |    public:                                                      \  | 
82  |  |       RESIP_HeapCount(H_##_enum);                               \  | 
83  |  |       enum {Single = true};                                     \ | 
84  |  |       typedef _type Type;                                       \  | 
85  |  |       UnusedChecking(_enum);                                    \  | 
86  |  |       static Type& knownReturn(ParserContainerBase* container); \  | 
87  |  |       virtual ParserContainerBase* makeContainer(HeaderFieldValueList* hfvs) const;       \  | 
88  |  |       virtual Headers::Type getTypeNum() const;                 \  | 
89  |  |       virtual void merge(SipMessage&, const SipMessage&);       \  | 
90  |  |       H_##_enum();                                              \  | 
91  |  | };                                                              \  | 
92  |  | extern H_##_enum h_##_enum  | 
93  |  |  | 
94  |  | #define defineMultiHeader(_enum, _name, _type, _rfc)            \  | 
95  |  | class H_##_enum##s : public HeaderBase                          \  | 
96  |  | {                                                               \ | 
97  |  |    public:                                                      \  | 
98  |  |       RESIP_HeapCount(H_##_enum##s);                            \  | 
99  |  |       enum {Single = false};                                    \ | 
100  |  |       typedef ParserContainer<_type> Type;                      \  | 
101  |  |       typedef _type ContainedType;                      \  | 
102  |  |       MultiUnusedChecking(_enum);                               \  | 
103  |  |       static Type& knownReturn(ParserContainerBase* container); \  | 
104  |  |       virtual ParserContainerBase* makeContainer(HeaderFieldValueList* hfvs) const;       \  | 
105  |  |       virtual Headers::Type getTypeNum() const;                 \  | 
106  |  |       virtual void merge(SipMessage&, const SipMessage&);       \  | 
107  |  |       H_##_enum##s();                                           \  | 
108  |  | };                                                              \  | 
109  |  | extern H_##_enum##s h_##_enum##s  | 
110  |  |  | 
111  |  | //====================  | 
112  |  | // Token:  | 
113  |  | //====================  | 
114  |  | typedef ParserContainer<Token> Tokens;  | 
115  |  |  | 
116  |  | defineHeader(ContentDisposition, "Content-Disposition", Token, "RFC 3261");  | 
117  |  | defineHeader(ContentEncoding, "Content-Encoding", Token, "RFC 3261");  | 
118  |  | defineHeader(MIMEVersion, "Mime-Version", Token, "RFC 3261");  | 
119  |  | defineHeader(Priority, "Priority", Token, "RFC 3261");  | 
120  |  | defineHeader(Event, "Event", Token, "RFC 3265");  | 
121  |  | defineHeader(SubscriptionState, "Subscription-State", Token, "RFC 3265");  | 
122  |  |  | 
123  |  | defineHeader(SIPETag, "SIP-ETag", Token, "RFC 3903");  | 
124  |  | defineHeader(SIPIfMatch, "SIP-If-Match", Token, "RFC 3903");  | 
125  |  | defineHeader(ContentId, "Content-ID", Token, "RFC 2045");  | 
126  |  |  | 
127  |  | defineMultiHeader(Identity, "Identity", StringCategory, "RFC 8224");  // Originally defined in RFC 4474 as a single header, but later modified by RFC8224 to be a multiheader  | 
128  |  | // explicitly declare to avoid h_Identitys  | 
129  |  | extern H_Identitys h_Identities;  | 
130  |  |  | 
131  |  | defineMultiHeader(AllowEvents, "Allow-Events", Token, "RFC 3265");  | 
132  |  | // explicitly declare to avoid h_AllowEventss, ugh  | 
133  |  | extern H_AllowEventss h_AllowEvents;  | 
134  |  |  | 
135  |  | defineMultiHeader(AcceptEncoding, "Accept-Encoding", Token, "RFC 3261");  | 
136  |  | defineMultiHeader(AcceptLanguage, "Accept-Language", Token, "RFC 3261");  | 
137  |  | defineMultiHeader(Allow, "Allow", Token, "RFC 3261");  | 
138  |  | defineMultiHeader(ContentLanguage, "Content-Language", Token, "RFC 3261");  | 
139  |  | defineMultiHeader(ProxyRequire, "Proxy-Require", Token, "RFC 3261");  | 
140  |  | defineMultiHeader(Require, "Require", Token, "RFC 3261");  | 
141  |  | defineMultiHeader(Supported, "Supported", Token, "RFC 3261");  | 
142  |  | defineMultiHeader(Unsupported, "Unsupported", Token, "RFC 3261");  | 
143  |  | defineMultiHeader(SecurityClient, "Security-Client", Token, "RFC 3329");  | 
144  |  | defineMultiHeader(SecurityServer, "Security-Server", Token, "RFC 3329");  | 
145  |  | defineMultiHeader(SecurityVerify, "Security-Verify", Token, "RFC 3329");  | 
146  |  | // explicitly declare to avoid h_SecurityVerifys, ugh  | 
147  |  | extern H_SecurityVerifys h_SecurityVerifies;  | 
148  |  |  | 
149  |  | defineMultiHeader(RequestDisposition, "Request-Disposition", Token, "RFC 3841");  | 
150  |  | defineMultiHeader(Reason, "Reason", Token, "RFC 3326");  | 
151  |  | defineMultiHeader(Privacy, "Privacy", PrivacyCategory, "RFC 3323");  | 
152  |  | // explicitly declare to avoid h_Privacys  | 
153  |  | extern H_Privacys h_Privacies;  | 
154  |  |  | 
155  |  | defineMultiHeader(PMediaAuthorization, "P-Media-Authorization", Token, "RFC 3313");  | 
156  |  |  | 
157  |  | defineHeader(ReferSub, "Refer-Sub", Token, "RFC 4488");  | 
158  |  | defineHeader(AnswerMode, "Answer-Mode", Token, "draft-ietf-answermode-01");  | 
159  |  | defineHeader(PrivAnswerMode, "Priv-Answer-Mode", Token, "draft-ietf-answermode-01");  | 
160  |  |  | 
161  |  | defineMultiHeader(PAccessNetworkInfo, "P-Access-Network-Info", Token, "RFC 7315"); // section 5.4.  | 
162  |  | defineHeader(PChargingVector, "P-Charging-Vector", Token, "RFC 3455");  | 
163  |  | defineHeader(PChargingFunctionAddresses, "P-Charging-Function-Addresses", Token, "RFC 3455");  | 
164  |  |  | 
165  |  | //====================  | 
166  |  | // Mime  | 
167  |  | //====================  | 
168  |  | typedef ParserContainer<Mime> Mimes;  | 
169  |  |  | 
170  |  | defineMultiHeader(Accept, "Accept", Mime, "RFC 3261");  | 
171  |  | defineHeader(ContentType, "Content-Type", Mime, "RFC 3261");  | 
172  |  |  | 
173  |  | //====================  | 
174  |  | // GenericUris:  | 
175  |  | //====================  | 
176  |  | typedef ParserContainer<GenericUri> GenericUris;  | 
177  |  | defineMultiHeader(CallInfo, "Call-Info", GenericUri, "RFC 3261");  | 
178  |  | defineMultiHeader(AlertInfo, "Alert-Info", GenericUri, "RFC 3261");  | 
179  |  | defineMultiHeader(ErrorInfo, "Error-Info", GenericUri, "RFC 3261");  | 
180  |  | defineHeader(IdentityInfo, "Identity-Info", GenericUri, "RFC 4474");      // deprecated by RFC8224  | 
181  |  |  | 
182  |  | //====================  | 
183  |  | // NameAddr:  | 
184  |  | //====================  | 
185  |  | typedef ParserContainer<NameAddr> NameAddrs;  | 
186  |  |  | 
187  |  | defineMultiHeader(RecordRoute, "Record-Route", NameAddr, "RFC 3261");  | 
188  |  | defineMultiHeader(Route, "Route", NameAddr, "RFC 3261");  | 
189  |  | defineMultiHeader(Contact, "Contact", NameAddr, "RFC 3261");  | 
190  |  | defineHeader(From, "From", NameAddr, "RFC 3261");  | 
191  |  | defineHeader(To, "To", NameAddr, "RFC 3261");  | 
192  |  | defineHeader(ReplyTo, "Reply-To", NameAddr, "RFC 3261");  | 
193  |  | defineHeader(ReferTo, "Refer-To", NameAddr, "RFC 3515");  | 
194  |  | defineHeader(ReferredBy, "Referred-By", NameAddr, "RFC 3892");  | 
195  |  |  | 
196  |  | defineMultiHeader(Path, "Path", NameAddr, "RFC 3327");  | 
197  |  | defineMultiHeader(AcceptContact, "Accept-Contact", NameAddr, "RFC 3841");  | 
198  |  | defineMultiHeader(RejectContact, "Reject-Contact", NameAddr, "RFC 3841");  | 
199  |  | defineMultiHeader(PPreferredIdentity, "P-Preferred-Identity", NameAddr, "RFC 3325");  | 
200  |  | // explicitly declare to avoid h_PAssertedIdentitys  | 
201  |  | extern H_PPreferredIdentitys h_PPreferredIdentities;  | 
202  |  |  | 
203  |  | defineMultiHeader(PAssertedIdentity, "P-Asserted-Identity", NameAddr, "RFC 3325");  | 
204  |  | // explicitly declare to avoid h_PAssertedIdentitys  | 
205  |  | extern H_PAssertedIdentitys h_PAssertedIdentities;  | 
206  |  |  | 
207  |  | defineHeader(PCalledPartyId, "P-Called-Party-ID", NameAddr, "RFC 3455");  | 
208  |  | defineMultiHeader(PAssociatedUri, "P-Associated-URI", NameAddr, "RFC 3455");  | 
209  |  | defineMultiHeader(ServiceRoute, "Service-Route", NameAddr, "RFC 3608");  | 
210  |  | defineMultiHeader(RemotePartyId, "Remote-Party-ID", NameAddr, "draft-ietf-sip-privacy-04"); // ?bwc? Not in 3323, should we keep?  | 
211  |  | defineMultiHeader(HistoryInfo, "History-Info", NameAddr, "RFC 4244");  | 
212  |  |  | 
213  |  | //====================  | 
214  |  | // StringCategory:  | 
215  |  | //====================  | 
216  |  | typedef ParserContainer<StringCategory> StringCategories;  | 
217  |  |  | 
218  |  | defineHeader(ContentTransferEncoding, "Content-Transfer-Encoding", StringCategory, "RFC ?");  | 
219  |  | defineHeader(Organization, "Organization", StringCategory, "RFC 3261");  | 
220  |  | defineHeader(SecWebSocketKey, "Sec-WebSocket-Key", StringCategory, "RFC 6455");  | 
221  |  | defineHeader(SecWebSocketKey1, "Sec-WebSocket-Key1", StringCategory, "draft-hixie- thewebsocketprotocol-76");  | 
222  |  | defineHeader(SecWebSocketKey2, "Sec-WebSocket-Key2", StringCategory, "draft-hixie- thewebsocketprotocol-76");  | 
223  |  | defineHeader(Origin, "Origin", StringCategory, "draft-hixie- thewebsocketprotocol-76");  | 
224  |  | defineHeader(Host, "Host", StringCategory, "draft-hixie- thewebsocketprotocol-76");  | 
225  |  | defineHeader(SecWebSocketAccept, "Sec-WebSocket-Accept", StringCategory, "RFC 6455");  | 
226  |  | defineMultiHeader(Cookie, "Cookie", StringCategory, "RFC 6265");  | 
227  |  | defineHeader(Server, "Server", StringCategory, "RFC 3261");  | 
228  |  | defineHeader(Subject, "Subject", StringCategory, "RFC 3261");  | 
229  |  | defineHeader(UserAgent, "User-Agent", StringCategory, "RFC 3261");  | 
230  |  | defineHeader(Timestamp, "Timestamp", StringCategory, "RFC 3261");  | 
231  |  |  | 
232  |  | //====================  | 
233  |  | // ExpiresCategory:  | 
234  |  | //====================  | 
235  |  |  | 
236  |  | defineHeader(Expires, "Expires", ExpiresCategory, "RFC 3261");  | 
237  |  | defineHeader(SessionExpires, "Session-Expires", ExpiresCategory, "RFC 4028");  | 
238  |  | defineHeader(MinSE, "Min-SE", ExpiresCategory, "RFC 4028");  | 
239  |  |  | 
240  |  | //====================  | 
241  |  | // UInt32Category:  | 
242  |  | //====================  | 
243  |  | typedef ParserContainer<UInt32Category> UInt32Categories;  | 
244  |  | defineHeader(MaxForwards, "Max-Forwards", UInt32Category, "RFC 3261");  | 
245  |  | // !dlb! not clear this needs to be exposed  | 
246  |  | defineHeader(ContentLength, "Content-Length", UInt32Category, "RFC 3261");  | 
247  |  | defineHeader(MinExpires, "Min-Expires", UInt32Category, "RFC 3261");  | 
248  |  | defineHeader(RSeq, "RSeq", UInt32Category, "RFC 3261");  | 
249  |  |  | 
250  |  | // !dlb! this one is not quite right -- can have (comment) after field value  | 
251  |  | defineHeader(RetryAfter, "Retry-After", UInt32Category, "RFC 3261");  | 
252  |  | defineHeader(FlowTimer, "Flow-Timer", UInt32Category, "RFC 5626");  | 
253  |  |  | 
254  |  | //====================  | 
255  |  | // CallId:  | 
256  |  | //====================  | 
257  |  | defineHeader(CallID, "Call-ID", CallID, "RFC 3261");  | 
258  |  | defineHeader(Replaces, "Replaces", CallID, "RFC 3891");  | 
259  |  | defineHeader(InReplyTo, "In-Reply-To", CallID, "RFC 3261");  | 
260  |  |  | 
261  |  | typedef H_CallID H_CallId; // code convention compatible  | 
262  |  | extern H_CallId h_CallId; // code convention compatible  | 
263  |  |  | 
264  |  | defineHeader(Join, "Join", CallId, "RFC 3911");  | 
265  |  | defineHeader(TargetDialog, "Target-Dialog", CallId, "RFC 4538");  | 
266  |  |  | 
267  |  |  | 
268  |  | //====================  | 
269  |  | // Auth:  | 
270  |  | //====================  | 
271  |  | typedef ParserContainer<Auth> Auths;  | 
272  |  | defineHeader(AuthenticationInfo, "Authentication-Info", Auth, "RFC 3261");  | 
273  |  | defineMultiHeader(Authorization, "Authorization", Auth, "RFC 3261");  | 
274  |  | defineMultiHeader(ProxyAuthenticate, "Proxy-Authenticate", Auth, "RFC 3261");  | 
275  |  | defineMultiHeader(ProxyAuthorization, "Proxy-Authorization", Auth, "RFC 3261");  | 
276  |  | defineMultiHeader(WWWAuthenticate, "Www-Authenticate", Auth, "RFC 3261");  | 
277  |  |  | 
278  |  | //====================  | 
279  |  | // CSeqCategory:  | 
280  |  | //====================  | 
281  |  | defineHeader(CSeq, "CSeq", CSeqCategory, "RFC 3261");  | 
282  |  |  | 
283  |  | //====================  | 
284  |  | // DateCategory:  | 
285  |  | //====================  | 
286  |  | defineHeader(Date, "Date", DateCategory, "RFC 3261");  | 
287  |  |  | 
288  |  | //====================  | 
289  |  | // WarningCategory:  | 
290  |  | //====================  | 
291  |  | defineMultiHeader(Warning, "Warning", WarningCategory, "RFC 3261");  | 
292  |  |  | 
293  |  | //Enforces string encoding of extension headers  | 
294  |  | defineMultiHeader(RESIP_DO_NOT_USE, "If you see this things are seriously awry", StringCategory, "NA");  | 
295  |  |  | 
296  |  | //====================  | 
297  |  | // Via  | 
298  |  | //====================  | 
299  |  | typedef ParserContainer<Via> Vias;  | 
300  |  | defineMultiHeader(Via, "Via", Via, "RFC 3261");  | 
301  |  |  | 
302  |  | //====================  | 
303  |  | // RAckCategory  | 
304  |  | //====================  | 
305  |  | defineHeader(RAck, "RAck", RAckCategory, "RFC 3262");  | 
306  |  |  | 
307  |  | //============================  | 
308  |  | // TokenOrQuotedStringCategory  | 
309  |  | //============================  | 
310  |  | defineMultiHeader(PVisitedNetworkID, "P-Visited-Network-ID", TokenOrQuotedStringCategory, "RFC 3455");  | 
311  |  | defineMultiHeader(UserToUser, "User-to-User", TokenOrQuotedStringCategory, "draft-ietf-cuss-sip-uui-17");  | 
312  |  |  | 
313  |  | //====================  | 
314  |  | // special first line accessors  | 
315  |  | //====================  | 
316  |  | class RequestLineType {}; | 
317  |  | extern RequestLineType h_RequestLine;  | 
318  |  |  | 
319  |  | class StatusLineType {}; | 
320  |  | extern StatusLineType h_StatusLine;  | 
321  |  |  | 
322  |  | }  | 
323  |  |  | 
324  |  | #undef defineHeader  | 
325  |  | #undef defineMultiHeader  | 
326  |  |  | 
327  |  | #endif  | 
328  |  |  | 
329  |  | /* ====================================================================  | 
330  |  |  * The Vovida Software License, Version 1.0   | 
331  |  |  *   | 
332  |  |  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.  | 
333  |  |  *   | 
334  |  |  * Redistribution and use in source and binary forms, with or without  | 
335  |  |  * modification, are permitted provided that the following conditions  | 
336  |  |  * are met:  | 
337  |  |  *   | 
338  |  |  * 1. Redistributions of source code must retain the above copyright  | 
339  |  |  *    notice, this list of conditions and the following disclaimer.  | 
340  |  |  *   | 
341  |  |  * 2. Redistributions in binary form must reproduce the above copyright  | 
342  |  |  *    notice, this list of conditions and the following disclaimer in  | 
343  |  |  *    the documentation and/or other materials provided with the  | 
344  |  |  *    distribution.  | 
345  |  |  *   | 
346  |  |  * 3. The names "VOCAL", "Vovida Open Communication Application Library",  | 
347  |  |  *    and "Vovida Open Communication Application Library (VOCAL)" must  | 
348  |  |  *    not be used to endorse or promote products derived from this  | 
349  |  |  *    software without prior written permission. For written  | 
350  |  |  *    permission, please contact vocal@vovida.org.  | 
351  |  |  *  | 
352  |  |  * 4. Products derived from this software may not be called "VOCAL", nor  | 
353  |  |  *    may "VOCAL" appear in their name, without prior written  | 
354  |  |  *    permission of Vovida Networks, Inc.  | 
355  |  |  *   | 
356  |  |  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED  | 
357  |  |  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES  | 
358  |  |  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND  | 
359  |  |  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA  | 
360  |  |  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES  | 
361  |  |  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,  | 
362  |  |  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  | 
363  |  |  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR  | 
364  |  |  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY  | 
365  |  |  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  | 
366  |  |  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  | 
367  |  |  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH  | 
368  |  |  * DAMAGE.  | 
369  |  |  *   | 
370  |  |  * ====================================================================  | 
371  |  |  *   | 
372  |  |  * This software consists of voluntary contributions made by Vovida  | 
373  |  |  * Networks, Inc. and many individuals on behalf of Vovida Networks,  | 
374  |  |  * Inc.  For more information on Vovida Networks, Inc., please see  | 
375  |  |  * <http://www.vovida.org/>.  | 
376  |  |  *  | 
377  |  |  */  |