reSIProcate/stack  9694
Headers.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_HEADERS_HXX)
00002 #define RESIP_HEADERS_HXX 
00003 
00004 #include "resip/stack/ParserCategories.hxx"
00005 #include "resip/stack/HeaderTypes.hxx"
00006 #include "resip/stack/Symbols.hxx"
00007 #include "rutil/Data.hxx"
00008 #include "rutil/HeapInstanceCounter.hxx"
00009 
00010 namespace resip
00011 {
00012 class SipMessage;
00013 class HeaderFieldValueList;
00014 
00015 //#define PARTIAL_TEMPLATE_SPECIALIZATION
00016 #ifdef PARTIAL_TEMPLATE_SPECIALIZATION
00017 template<bool>
00018 class TypeIf
00019 {
00020    public:
00021       template <class T>
00022       class Resolve
00023       {
00024          public:
00025             typedef T Type;
00026       };
00027 };
00028 
00029 class UnusedHeader
00030 {
00031 };
00032 
00033 class TypeIf<false>
00034 {
00035    public:
00036       template <class T>
00037       class Resolve
00038       {
00039          public:
00040             typedef UnusedHeader Type;
00041       };
00042 };
00043 
00044 #define UnusedChecking(_enum)                                           \
00045       typedef TypeIf<Headers::_enum != Headers::UNKNOWN> TypeIfT;       \
00046       typedef TypeIfT::Resolve<Type> Resolver;                          \
00047       typedef Resolver::Type UnknownReturn
00048 
00049 #define MultiUnusedChecking(_enum)                                              \
00050       typedef TypeIf<Headers::_enum != Headers::UNKNOWN> TypeIfT;               \
00051       typedef TypeIfT::Resolve< ParserContainer<Type> > Resolver;               \
00052       typedef Resolver::Type UnknownReturn
00053 
00054 #else
00055 
00056 #define UnusedChecking(_enum) typedef int _dummy
00057 #define MultiUnusedChecking(_enum) typedef int _dummy
00058 
00059 #endif
00060 
00061 class HeaderBase
00062 {
00063    public:
00064       virtual ~HeaderBase() {}
00065       virtual Headers::Type getTypeNum() const = 0;
00066       virtual void merge(SipMessage&, const SipMessage&)=0;
00067       
00068       static HeaderBase* getInstance(Headers::Type typenum)
00069       {
00070          return theHeaderInstances[typenum+1];
00071       }
00072       
00073       virtual ParserContainerBase* makeContainer(HeaderFieldValueList* hfvs) const=0;
00074    protected:
00075       static HeaderBase* theHeaderInstances[Headers::MAX_HEADERS+1];
00076 };
00077 
00078 #define defineHeader(_enum, _name, _type, _rfc)                 \
00079 class H_##_enum : public HeaderBase                             \
00080 {                                                               \
00081    public:                                                      \
00082       RESIP_HeapCount(H_##_enum);                               \
00083       enum {Single = true};                                     \
00084       typedef _type Type;                                       \
00085       UnusedChecking(_enum);                                    \
00086       static Type& knownReturn(ParserContainerBase* container); \
00087       virtual ParserContainerBase* makeContainer(HeaderFieldValueList* hfvs) const;       \
00088       virtual Headers::Type getTypeNum() const;                 \
00089       virtual void merge(SipMessage&, const SipMessage&);       \
00090       H_##_enum();                                              \
00091 };                                                              \
00092 extern H_##_enum h_##_enum
00093 
00094 #define defineMultiHeader(_enum, _name, _type, _rfc)            \
00095 class H_##_enum##s : public HeaderBase                          \
00096 {                                                               \
00097    public:                                                      \
00098       RESIP_HeapCount(H_##_enum##s);                            \
00099       enum {Single = false};                                    \
00100       typedef ParserContainer<_type> Type;                      \
00101       typedef _type ContainedType;                      \
00102       MultiUnusedChecking(_enum);                               \
00103       static Type& knownReturn(ParserContainerBase* container); \
00104       virtual ParserContainerBase* makeContainer(HeaderFieldValueList* hfvs) const;       \
00105       virtual Headers::Type getTypeNum() const;                 \
00106       virtual void merge(SipMessage&, const SipMessage&);       \
00107       H_##_enum##s();                                           \
00108 };                                                              \
00109 extern H_##_enum##s h_##_enum##s
00110 
00111 //====================
00112 // Token:
00113 //====================
00114 typedef ParserContainer<Token> Tokens;
00115 
00116 defineHeader(ContentDisposition, "Content-Disposition", Token, "RFC 3261");
00117 defineHeader(ContentEncoding, "Content-Encoding", Token, "RFC 3261");
00118 defineHeader(MIMEVersion, "Mime-Version", Token, "RFC 3261");
00119 defineHeader(Priority, "Priority", Token, "RFC 3261");
00120 defineHeader(Event, "Event", Token, "RFC 3265");
00121 defineHeader(SubscriptionState, "Subscription-State", Token, "RFC 3265");
00122 
00123 defineHeader(SIPETag, "SIP-ETag", Token, "RFC 3903");
00124 defineHeader(SIPIfMatch, "SIP-If-Match", Token, "RFC 3903");
00125 defineHeader(ContentId, "Content-ID", Token, "RFC 2045");
00126 
00127 defineMultiHeader(AllowEvents, "Allow-Events", Token, "RFC 3265");
00128 
00129 defineHeader(Identity, "Identity", StringCategory, "RFC 4474");
00130 // explicitly declare to avoid h_AllowEventss, ugh
00131 extern H_AllowEventss h_AllowEvents;
00132 
00133 defineMultiHeader(AcceptEncoding, "Accept-Encoding", Token, "RFC 3261");
00134 defineMultiHeader(AcceptLanguage, "Accept-Language", Token, "RFC 3261");
00135 defineMultiHeader(Allow, "Allow", Token, "RFC 3261");
00136 defineMultiHeader(ContentLanguage, "Content-Language", Token, "RFC 3261");
00137 defineMultiHeader(ProxyRequire, "Proxy-Require", Token, "RFC 3261");
00138 defineMultiHeader(Require, "Require", Token, "RFC 3261");
00139 defineMultiHeader(Supported, "Supported", Token, "RFC 3261");
00140 defineMultiHeader(Unsupported, "Unsupported", Token, "RFC 3261");
00141 defineMultiHeader(SecurityClient, "Security-Client", Token, "RFC 3329");
00142 defineMultiHeader(SecurityServer, "Security-Server", Token, "RFC 3329");
00143 defineMultiHeader(SecurityVerify, "Security-Verify", Token, "RFC 3329");
00144 // explicitly declare to avoid h_SecurityVerifys, ugh
00145 extern H_SecurityVerifys h_SecurityVerifies;
00146 
00147 defineMultiHeader(RequestDisposition, "Request-Disposition", Token, "RFC 3841");
00148 defineMultiHeader(Reason, "Reason", Token, "RFC 3326");
00149 defineMultiHeader(Privacy, "Privacy", PrivacyCategory, "RFC 3323");
00150 // explicitly declare to avoid h_Privacys
00151 extern H_Privacys h_Privacies;
00152 
00153 defineMultiHeader(PMediaAuthorization, "P-Media-Authorization", Token, "RFC 3313");
00154 
00155 defineHeader(ReferSub, "Refer-Sub", Token, "RFC 4488");
00156 defineHeader(AnswerMode, "Answer-Mode", Token, "draft-ietf-answermode-01");
00157 defineHeader(PrivAnswerMode, "Priv-Answer-Mode", Token, "draft-ietf-answermode-01");
00158 
00159 //====================
00160 // Mime
00161 //====================
00162 typedef ParserContainer<Mime> Mimes;
00163 
00164 defineMultiHeader(Accept, "Accept", Mime, "RFC 3261");
00165 defineHeader(ContentType, "Content-Type", Mime, "RFC 3261");
00166 
00167 //====================
00168 // GenericUris:
00169 //====================
00170 typedef ParserContainer<GenericUri> GenericUris;
00171 defineMultiHeader(CallInfo, "Call-Info", GenericUri, "RFC 3261");
00172 defineMultiHeader(AlertInfo, "Alert-Info", GenericUri, "RFC 3261");
00173 defineMultiHeader(ErrorInfo, "Error-Info", GenericUri, "RFC 3261");
00174 defineHeader(IdentityInfo, "Identity-Info", GenericUri, "RFC 4474");
00175 
00176 //====================
00177 // NameAddr:
00178 //====================
00179 typedef ParserContainer<NameAddr> NameAddrs;
00180 
00181 defineMultiHeader(RecordRoute, "Record-Route", NameAddr, "RFC 3261");
00182 defineMultiHeader(Route, "Route", NameAddr, "RFC 3261");
00183 defineMultiHeader(Contact, "Contact", NameAddr, "RFC 3261");
00184 defineHeader(From, "From", NameAddr, "RFC 3261");
00185 defineHeader(To, "To", NameAddr, "RFC 3261");
00186 defineHeader(ReplyTo, "Reply-To", NameAddr, "RFC 3261");
00187 defineHeader(ReferTo, "Refer-To", NameAddr, "RFC 3515");
00188 defineHeader(ReferredBy, "Referred-By", NameAddr, "RFC 3892");
00189 
00190 defineMultiHeader(Path, "Path", NameAddr, "RFC 3327");
00191 defineMultiHeader(AcceptContact, "Accept-Contact", NameAddr, "RFC 3841");
00192 defineMultiHeader(RejectContact, "Reject-Contact", NameAddr, "RFC 3841");
00193 defineMultiHeader(PPreferredIdentity, "P-Preferred-Identity", NameAddr, "RFC 3325");
00194 // explicitly declare to avoid h_PAssertedIdentitys
00195 extern H_PPreferredIdentitys h_PPreferredIdentities;
00196 
00197 defineMultiHeader(PAssertedIdentity, "P-Asserted-Identity", NameAddr, "RFC 3325");
00198 // explicitly declare to avoid h_PAssertedIdentitys
00199 extern H_PAssertedIdentitys h_PAssertedIdentities;
00200 
00201 defineHeader(PCalledPartyId, "P-Called-Party-ID", NameAddr, "RFC 3455");
00202 defineMultiHeader(PAssociatedUri, "P-Associated-URI", NameAddr, "RFC 3455");
00203 defineMultiHeader(ServiceRoute, "Service-Route", NameAddr, "RFC 3608");
00204 defineMultiHeader(RemotePartyId, "Remote-Party-ID", NameAddr, "draft-ietf-sip-privacy-04"); // ?bwc? Not in 3323, should we keep?
00205 defineMultiHeader(HistoryInfo, "History-Info", NameAddr, "RFC 4244");
00206 
00207 //====================
00208 // StringCategory:
00209 //====================
00210 typedef ParserContainer<StringCategory> StringCategories;
00211 
00212 defineHeader(ContentTransferEncoding, "Content-Transfer-Encoding", StringCategory, "RFC ?");
00213 defineHeader(Organization, "Organization", StringCategory, "RFC 3261");
00214 defineHeader(Server, "Server", StringCategory, "RFC 3261");
00215 defineHeader(Subject, "Subject", StringCategory, "RFC 3261");
00216 defineHeader(UserAgent, "User-Agent", StringCategory, "RFC 3261");
00217 defineHeader(Timestamp, "Timestamp", StringCategory, "RFC 3261");
00218 
00219 //====================
00220 // ExpiresCategory:
00221 //====================
00222 
00223 defineHeader(Expires, "Expires", ExpiresCategory, "RFC 3261");
00224 defineHeader(SessionExpires, "Session-Expires", ExpiresCategory, "RFC 4028");
00225 defineHeader(MinSE, "Min-SE", ExpiresCategory, "RFC 4028");
00226 
00227 //====================
00228 // UInt32Category:
00229 //====================
00230 typedef ParserContainer<UInt32Category> UInt32Categories;
00231 defineHeader(MaxForwards, "Max-Forwards", UInt32Category, "RFC 3261");
00232 // !dlb! not clear this needs to be exposed
00233 defineHeader(ContentLength, "Content-Length", UInt32Category, "RFC 3261");
00234 defineHeader(MinExpires, "Min-Expires", UInt32Category, "RFC 3261");
00235 defineHeader(RSeq, "RSeq", UInt32Category, "RFC 3261");
00236 
00237 // !dlb! this one is not quite right -- can have (comment) after field value
00238 defineHeader(RetryAfter, "Retry-After", UInt32Category, "RFC 3261");
00239 defineHeader(FlowTimer, "Flow-Timer", UInt32Category, "RFC 5626");
00240 
00241 //====================
00242 // CallId:
00243 //====================
00244 defineHeader(CallID, "Call-ID", CallID, "RFC 3261");
00245 defineHeader(Replaces, "Replaces", CallID, "RFC 3891");
00246 defineHeader(InReplyTo, "In-Reply-To", CallID, "RFC 3261");
00247 
00248 typedef H_CallID H_CallId; // code convention compatible
00249 extern H_CallId h_CallId; // code convention compatible
00250 
00251 defineHeader(Join, "Join", CallId, "RFC 3911");
00252 defineHeader(TargetDialog, "Target-Dialog", CallId, "RFC 4538");
00253 
00254 
00255 //====================
00256 // Auth:
00257 //====================
00258 typedef ParserContainer<Auth> Auths;
00259 defineHeader(AuthenticationInfo, "Authentication-Info", Auth, "RFC 3261");
00260 defineMultiHeader(Authorization, "Authorization", Auth, "RFC 3261");
00261 defineMultiHeader(ProxyAuthenticate, "Proxy-Authenticate", Auth, "RFC 3261");
00262 defineMultiHeader(ProxyAuthorization, "Proxy-Authorization", Auth, "RFC 3261");
00263 defineMultiHeader(WWWAuthenticate, "Www-Authenticate", Auth, "RFC 3261");
00264 
00265 //====================
00266 // CSeqCategory:
00267 //====================
00268 defineHeader(CSeq, "CSeq", CSeqCategory, "RFC 3261");
00269 
00270 //====================
00271 // DateCategory:
00272 //====================
00273 defineHeader(Date, "Date", DateCategory, "RFC 3261");
00274 
00275 //====================
00276 // WarningCategory:
00277 //====================
00278 defineMultiHeader(Warning, "Warning", WarningCategory, "RFC 3261");
00279 
00280 //Enforces string encoding of extension headers
00281 defineMultiHeader(RESIP_DO_NOT_USE, "If you see this things are seriously awry", StringCategory, "NA");
00282 
00283 //====================
00284 // Via
00285 //====================
00286 typedef ParserContainer<Via> Vias;
00287 defineMultiHeader(Via, "Via", Via, "RFC 3261");
00288 
00289 //====================
00290 // RAckCategory
00291 //====================
00292 defineHeader(RAck, "RAck", RAckCategory, "RFC 3262");
00293 
00294 //====================
00295 // special first line accessors
00296 //====================
00297 class RequestLineType {};
00298 extern RequestLineType h_RequestLine;
00299 
00300 class StatusLineType {};
00301 extern StatusLineType h_StatusLine;
00302 
00303 }
00304 
00305 #undef defineHeader
00306 #undef defineMultiHeader
00307 
00308 #endif
00309 
00310 /* ====================================================================
00311  * The Vovida Software License, Version 1.0 
00312  * 
00313  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00314  * 
00315  * Redistribution and use in source and binary forms, with or without
00316  * modification, are permitted provided that the following conditions
00317  * are met:
00318  * 
00319  * 1. Redistributions of source code must retain the above copyright
00320  *    notice, this list of conditions and the following disclaimer.
00321  * 
00322  * 2. Redistributions in binary form must reproduce the above copyright
00323  *    notice, this list of conditions and the following disclaimer in
00324  *    the documentation and/or other materials provided with the
00325  *    distribution.
00326  * 
00327  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00328  *    and "Vovida Open Communication Application Library (VOCAL)" must
00329  *    not be used to endorse or promote products derived from this
00330  *    software without prior written permission. For written
00331  *    permission, please contact vocal@vovida.org.
00332  *
00333  * 4. Products derived from this software may not be called "VOCAL", nor
00334  *    may "VOCAL" appear in their name, without prior written
00335  *    permission of Vovida Networks, Inc.
00336  * 
00337  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00338  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00339  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00340  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00341  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00342  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00343  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00344  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00345  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00346  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00347  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00348  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00349  * DAMAGE.
00350  * 
00351  * ====================================================================
00352  * 
00353  * This software consists of voluntary contributions made by Vovida
00354  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00355  * Inc.  For more information on Vovida Networks, Inc., please see
00356  * <http://www.vovida.org/>.
00357  *
00358  */