reSIProcate/stack  9694
Uri.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_URI_HXX)
00002 #define RESIP_URI_HXX 
00003 
00004 #include <bitset>
00005 #include <cassert>
00006 
00007 #include "resip/stack/ParserCategory.hxx"
00008 #include "resip/stack/Token.hxx"
00009 #include "rutil/TransportType.hxx"
00010 #include "rutil/HeapInstanceCounter.hxx"
00011 
00012 namespace resip
00013 {
00014 class SipMessage;
00015 
00021 class Uri : public ParserCategory
00022 {
00023    public:
00024       RESIP_HeapCount(Uri);
00025       
00026       static const size_t uriEncodingTableSize = 256;
00027 
00028       Uri(PoolBase* pool=0);
00029       Uri(const HeaderFieldValue& hfv, Headers::Type type, PoolBase* pool=0);
00030       Uri(const Uri& orig,
00031          PoolBase* pool=0);
00032       explicit Uri(const Data& data);
00033 
00034       ~Uri();
00035       
00036       // convert from a tel scheme to sip scheme, adds user=phone param
00037       //static Uri fromTel(const Uri&, const Data& host);  // deprecate...
00038       static Uri fromTel(const Uri&, const Uri& hostUri);
00039 
00040       Data& host() {checkParsed(); mHostCanonicalized=false; return mHost;}
00041       const Data& host() const {checkParsed(); return mHost;}
00042       Data& user() {checkParsed(); return mUser;}
00043       const Data& user() const {checkParsed(); return mUser;}
00044       Data& userParameters() {checkParsed(); return mUserParameters;}
00045       const Data& userParameters() const {checkParsed(); return mUserParameters;}
00046       Data& opaque() {checkParsed(); return mHost;}
00047       const Data& opaque() const {checkParsed(); return mHost;}
00048 
00049       // Returns user@host[:port] (no scheme)
00050       Data getAor() const;
00051       // Returns user@host (no scheme or port)
00052       Data getAorNoPort() const;
00053 
00054       // Actually returns the AOR; <scheme>:<user>@<host>
00055       Data getAorNoReally() const
00056       {
00057          return getAOR(false);
00058       }
00059 
00060       // Returns the AOR, optionally adding the port
00061       Data getAOR(bool addPort) const;
00062 
00063       //strips all paramters - if transport type is specified (ie. not UNKNOWN_TRANSPORT),
00064       //and the default port for the transport is on the Aor, then it is removed
00065       Uri getAorAsUri(TransportType transportTypeToRemoveDefaultPort = UNKNOWN_TRANSPORT) const;
00066       
00067 
00076       bool userIsTelephoneSubscriber() const;
00077 
00130       Token getUserAsTelephoneSubscriber() const;
00131 
00138       void setUserAsTelephoneSubscriber(const Token& telephoneSubscriber);
00139 
00140 
00141       Data& scheme() {checkParsed(); return mScheme;}
00142       const Data& scheme() const {checkParsed(); return mScheme;}
00143       int& port() {checkParsed(); return mPort;}
00144       int port() const {checkParsed(); return mPort;}
00145       Data& password() {checkParsed(); return mPassword;}
00146       const Data& password() const {checkParsed(); return mPassword;}
00147 
00148       Data toString() const;
00149 
00152       bool isEnumSearchable() const;
00153 
00155       std::vector<Data> getEnumLookups(const std::vector<Data>& suffixes) const;
00156 
00158       static void setUriUserEncoding(unsigned char c, bool encode);
00159       static void setUriPasswordEncoding(unsigned char c, bool encode);
00160       
00161       bool hasEmbedded() const;
00162       SipMessage& embedded();
00163       const SipMessage& embedded() const;
00164 
00165       void removeEmbedded();
00166 
00167       virtual void parse(ParseBuffer& pb);
00168       virtual ParserCategory* clone() const;
00169       virtual ParserCategory* clone(void* location) const;
00170       virtual ParserCategory* clone(PoolBase* pool) const;
00171       virtual EncodeStream& encodeParsed(EncodeStream& str) const;
00172       
00173       // parse the headers into this as SipMessage
00174       void parseEmbeddedHeaders(ParseBuffer& pb);
00175       EncodeStream& encodeEmbeddedHeaders(EncodeStream& str) const;
00176 
00177       Uri& operator=(const Uri& rhs);
00178       bool operator==(const Uri& other) const;
00179       bool operator!=(const Uri& other) const;
00180       bool operator<(const Uri& other) const;
00181       
00182       bool aorEqual(const Uri& rhs) const;
00183 
00184       typedef std::bitset<Uri::uriEncodingTableSize> EncodingTable;
00185 
00186       static EncodingTable& getUserEncodingTable()
00187       {
00188          static EncodingTable userEncodingTable(
00189                Data::toBitset("abcdefghijklmnopqrstuvwxyz"
00190                               "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00191                               "0123456789"
00192                               "-_.!~*\\()&=+$,;?/").flip());
00193          return userEncodingTable;
00194       }
00195 
00196       static EncodingTable& getPasswordEncodingTable()
00197       {
00198          static EncodingTable passwordEncodingTable(
00199                Data::toBitset("abcdefghijklmnopqrstuvwxyz"
00200                               "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00201                               "0123456789"
00202                               "-_.!~*\\()&=+$").flip());
00203          return passwordEncodingTable;
00204       }
00205 
00206       static EncodingTable& getLocalNumberTable()
00207       {
00208          // ?bwc? 'p' and 'w' are allowed in 2806, but have been removed in 
00209          // 3966. Should we support these or not?
00210          static EncodingTable localNumberTable(
00211                Data::toBitset("*#-.()0123456789ABCDEFpw"));
00212          return localNumberTable;
00213       }
00214 
00215       static EncodingTable& getGlobalNumberTable()
00216       {
00217          static EncodingTable globalNumberTable(
00218                Data::toBitset("-.()0123456789"));
00219          return globalNumberTable;
00220       }
00221 
00222       // Inform the compiler that overloads of these may be found in
00223       // ParserCategory, too.
00224       using ParserCategory::exists;
00225       using ParserCategory::remove;
00226       using ParserCategory::param;
00227 
00228       virtual Parameter* createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool);
00229       bool exists(const Param<Uri>& paramType) const;
00230       void remove(const Param<Uri>& paramType);
00231 
00232 #define defineParam(_enum, _name, _type, _RFC_ref_ignored)                      \
00233       const _enum##_Param::DType& param(const _enum##_Param& paramType) const;  \
00234       _enum##_Param::DType& param(const _enum##_Param& paramType); \
00235       friend class _enum##_Param
00236 
00237       defineParam(ob,"ob",ExistsParameter,"RFC 5626");
00238       defineParam(gr, "gr", ExistsOrDataParameter, "RFC 5627");
00239       defineParam(comp, "comp", DataParameter, "RFC 3486");
00240       defineParam(duration, "duration", UInt32Parameter, "RFC 4240");
00241       defineParam(lr, "lr", ExistsParameter, "RFC 3261");
00242       defineParam(maddr, "maddr", DataParameter, "RFC 3261");
00243       defineParam(method, "method", DataParameter, "RFC 3261");
00244       defineParam(transport, "transport", DataParameter, "RFC 3261");
00245       defineParam(ttl, "ttl", UInt32Parameter, "RFC 3261");
00246       defineParam(user, "user", DataParameter, "RFC 3261, 4967");
00247       defineParam(extension, "ext", DataParameter, "RFC 3966"); // Token is used when ext is a user-parameter
00248       defineParam(sigcompId, "sigcomp-id", QuotedDataParameter, "RFC 5049");
00249       defineParam(rinstance, "rinstance", DataParameter, "proprietary (resip)");
00250       defineParam(addTransport, "addTransport", ExistsParameter, "RESIP INTERNAL");
00251 
00252 #undef defineParam
00253 
00254    protected:
00255       Data mScheme;
00256       // .bwc. I don't like this.
00257       mutable Data mHost;
00258       Data mUser;
00259       Data mUserParameters;
00260       int mPort;
00261       Data mPassword;
00262 
00263       void getAorInternal(bool dropScheme, bool addPort, Data& aor) const;
00264       mutable bool mHostCanonicalized;
00265 
00266    private:
00267       std::auto_ptr<Data> mEmbeddedHeadersText;
00268       std::auto_ptr<SipMessage> mEmbeddedHeaders;
00269 
00270       static ParameterTypes::Factory ParameterFactories[ParameterTypes::MAX_PARAMETER];
00271 
00282       static const bool tablesMightBeInitialized;
00283 
00284 };
00285 
00286 }
00287 
00288 #include "rutil/HashMap.hxx"
00289 
00290 HashValue(resip::Uri);
00291 
00292 #endif
00293 
00294 /* ====================================================================
00295  * The Vovida Software License, Version 1.0 
00296  * 
00297  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00298  * 
00299  * Redistribution and use in source and binary forms, with or without
00300  * modification, are permitted provided that the following conditions
00301  * are met:
00302  * 
00303  * 1. Redistributions of source code must retain the above copyright
00304  *    notice, this list of conditions and the following disclaimer.
00305  * 
00306  * 2. Redistributions in binary form must reproduce the above copyright
00307  *    notice, this list of conditions and the following disclaimer in
00308  *    the documentation and/or other materials provided with the
00309  *    distribution.
00310  * 
00311  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00312  *    and "Vovida Open Communication Application Library (VOCAL)" must
00313  *    not be used to endorse or promote products derived from this
00314  *    software without prior written permission. For written
00315  *    permission, please contact vocal@vovida.org.
00316  *
00317  * 4. Products derived from this software may not be called "VOCAL", nor
00318  *    may "VOCAL" appear in their name, without prior written
00319  *    permission of Vovida Networks, Inc.
00320  * 
00321  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00322  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00323  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00324  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00325  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00326  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00327  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00328  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00329  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00330  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00331  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00332  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00333  * DAMAGE.
00334  * 
00335  * ====================================================================
00336  * 
00337  * This software consists of voluntary contributions made by Vovida
00338  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00339  * Inc.  For more information on Vovida Networks, Inc., please see
00340  * <http://www.vovida.org/>.
00341  *
00342  */