reSIProcate/stack  9694
GenericUri.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 
00005 #include "resip/stack/GenericUri.hxx"
00006 #include "rutil/Logger.hxx"
00007 #include "rutil/ParseBuffer.hxx"
00008 //#include "rutil/WinLeakCheck.hxx"  // not compatible with placement new used below
00009 
00010 using namespace resip;
00011 using namespace std;
00012 
00013 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
00014 
00015 
00016 //====================
00017 // GenericUri
00018 //====================
00019 GenericUri::GenericUri(const GenericUri& rhs,
00020                         PoolBase* pool)
00021    : ParserCategory(rhs, pool),
00022      mUri(rhs.mUri)
00023 {}
00024 
00025 GenericUri::GenericUri(const HeaderFieldValue& hfv, 
00026                         Headers::Type type,
00027                         PoolBase* pool) 
00028    : ParserCategory(hfv, type, pool) 
00029 {}
00030 
00031 GenericUri&
00032 GenericUri::operator=(const GenericUri& rhs)
00033 {
00034    if (this != &rhs)
00035    {
00036       ParserCategory::operator=(rhs);
00037       mUri = rhs.mUri;
00038    }
00039    return *this;
00040 }
00041 
00042 Data& 
00043 GenericUri::uri()
00044 {
00045    checkParsed();
00046    return mUri;
00047 }
00048 
00049 const Data& 
00050 GenericUri::uri() const
00051 {
00052    checkParsed();
00053    return mUri;
00054 }
00055 
00056 void
00057 GenericUri::parse(ParseBuffer& pb)
00058 {
00059    pb.skipWhitespace();
00060    const char* anchor = pb.skipChar(Symbols::LA_QUOTE[0]);
00061 
00062    pb.skipToChar(Symbols::RA_QUOTE[0]);
00063    pb.data(mUri, anchor);
00064    pb.skipChar(Symbols::RA_QUOTE[0]);
00065 
00066    pb.skipWhitespace();
00067 
00068    parseParameters(pb);
00069 }
00070 
00071 ParserCategory* 
00072 GenericUri::clone() const
00073 {
00074    return new GenericUri(*this);
00075 }
00076 
00077 ParserCategory* 
00078 GenericUri::clone(void* location) const
00079 {
00080    return new (location) GenericUri(*this);
00081 }
00082 
00083 ParserCategory* 
00084 GenericUri::clone(PoolBase* pool) const
00085 {
00086    return new (pool) GenericUri(*this, pool);
00087 }
00088 
00089 EncodeStream& 
00090 GenericUri::encodeParsed(EncodeStream& str) const
00091 {
00092    str << Symbols::LA_QUOTE[0]
00093        << mUri
00094        << Symbols::RA_QUOTE[0];
00095 
00096    encodeParameters(str);
00097 
00098    return str;
00099 }
00100 
00101 ParameterTypes::Factory GenericUri::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0};
00102 
00103 Parameter* 
00104 GenericUri::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool)
00105 {
00106    if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type])
00107    {
00108       return ParameterFactories[type](type, pb, terminators, pool);
00109    }
00110    return 0;
00111 }
00112 
00113 bool 
00114 GenericUri::exists(const Param<GenericUri>& paramType) const
00115 {
00116     checkParsed();
00117     bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL;
00118     return ret;
00119 }
00120 
00121 void 
00122 GenericUri::remove(const Param<GenericUri>& paramType)
00123 {
00124     checkParsed();
00125     removeParameterByEnum(paramType.getTypeNum());
00126 }
00127 
00128 #define defineParam(_enum, _name, _type, _RFC_ref_ignored)                                                      \
00129 _enum##_Param::DType&                                                                                           \
00130 GenericUri::param(const _enum##_Param& paramType)                                                           \
00131 {                                                                                                               \
00132    checkParsed();                                                                                               \
00133    _enum##_Param::Type* p =                                                                                     \
00134       static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));                            \
00135    if (!p)                                                                                                      \
00136    {                                                                                                            \
00137       p = new _enum##_Param::Type(paramType.getTypeNum());                                                      \
00138       mParameters.push_back(p);                                                                                 \
00139    }                                                                                                            \
00140    return p->value();                                                                                           \
00141 }                                                                                                               \
00142                                                                                                                 \
00143 const _enum##_Param::DType&                                                                                     \
00144 GenericUri::param(const _enum##_Param& paramType) const                                                     \
00145 {                                                                                                               \
00146    checkParsed();                                                                                               \
00147    _enum##_Param::Type* p =                                                                                     \
00148       static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));                            \
00149    if (!p)                                                                                                      \
00150    {                                                                                                            \
00151       InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]);     \
00152       DebugLog(<< *this);                                                                                       \
00153       throw Exception("Missing parameter " _name, __FILE__, __LINE__);                                          \
00154    }                                                                                                            \
00155    return p->value();                                                                                           \
00156 }
00157 
00158 defineParam(purpose, "purpose", DataParameter, "RFC 3261");
00159 
00160 #undef defineParam
00161 
00162 /* ====================================================================
00163  * The Vovida Software License, Version 1.0 
00164  * 
00165  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00166  * 
00167  * Redistribution and use in source and binary forms, with or without
00168  * modification, are permitted provided that the following conditions
00169  * are met:
00170  * 
00171  * 1. Redistributions of source code must retain the above copyright
00172  *    notice, this list of conditions and the following disclaimer.
00173  * 
00174  * 2. Redistributions in binary form must reproduce the above copyright
00175  *    notice, this list of conditions and the following disclaimer in
00176  *    the documentation and/or other materials provided with the
00177  *    distribution.
00178  * 
00179  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00180  *    and "Vovida Open Communication Application Library (VOCAL)" must
00181  *    not be used to endorse or promote products derived from this
00182  *    software without prior written permission. For written
00183  *    permission, please contact vocal@vovida.org.
00184  *
00185  * 4. Products derived from this software may not be called "VOCAL", nor
00186  *    may "VOCAL" appear in their name, without prior written
00187  *    permission of Vovida Networks, Inc.
00188  * 
00189  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00190  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00191  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00192  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00193  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00194  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00195  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00196  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00197  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00198  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00199  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00200  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00201  * DAMAGE.
00202  * 
00203  * ====================================================================
00204  * 
00205  * This software consists of voluntary contributions made by Vovida
00206  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00207  * Inc.  For more information on Vovida Networks, Inc., please see
00208  * <http://www.vovida.org/>.
00209  *
00210  */