reSIProcate/stack  9694
RequestLine.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/RequestLine.hxx"
00006 #include "resip/stack/UnknownParameter.hxx"
00007 #include "rutil/Data.hxx"
00008 #include "rutil/DnsUtil.hxx"
00009 #include "rutil/Logger.hxx"
00010 #include "rutil/ParseBuffer.hxx"
00011 //#include "rutil/WinLeakCheck.hxx"  // not compatible with placement new used below
00012 
00013 using namespace resip;
00014 using namespace std;
00015 
00016 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
00017 
00018 //====================
00019 // RequestLine:
00020 //====================
00021 RequestLine::RequestLine()
00022    : StartLine(),
00023      mMethod(UNKNOWN),
00024      mUnknownMethodName(Data::Share,getMethodName(UNKNOWN)),
00025      mSipVersion(Data::Share,Symbols::DefaultSipVersion)
00026 {}
00027 
00028 RequestLine::RequestLine(MethodTypes method, 
00029                          const Data& sipVersion)
00030    : mMethod(method),
00031      mUnknownMethodName(),
00032      mSipVersion(sipVersion)
00033 {}
00034 
00035 RequestLine::RequestLine(const HeaderFieldValue& hfv) 
00036    : StartLine(hfv),
00037      mMethod(UNKNOWN),
00038      mUnknownMethodName(Data::Share,getMethodName(UNKNOWN)),
00039      mSipVersion(Data::Share,Symbols::DefaultSipVersion)
00040 {}
00041 
00042 RequestLine::RequestLine(const char* buf, int len) :
00043    StartLine(buf, len),
00044    mMethod(UNKNOWN),
00045    mUnknownMethodName(Data::Share,getMethodName(UNKNOWN)),
00046    mSipVersion(Data::Share,Symbols::DefaultSipVersion)
00047 {}
00048 
00049 RequestLine::RequestLine(const RequestLine& rhs)
00050    : StartLine(rhs),
00051      mUri(rhs.mUri),
00052      mMethod(rhs.mMethod),
00053      mUnknownMethodName(rhs.mUnknownMethodName),
00054      mSipVersion(rhs.mSipVersion)
00055 {}
00056 
00057 RequestLine&
00058 RequestLine::operator=(const RequestLine& rhs)
00059 {
00060    if (this != &rhs)
00061    {
00062       StartLine::operator=(rhs);
00063       mUri = rhs.mUri;
00064       mMethod = rhs.mMethod;
00065       mUnknownMethodName = rhs.mUnknownMethodName;
00066       mSipVersion = rhs.mSipVersion;
00067    }
00068    return *this;
00069 }
00070 
00071 RequestLine::~RequestLine()
00072 {}
00073 
00074 StartLine *
00075 RequestLine::clone() const
00076 {
00077    return new RequestLine(*this);
00078 }
00079 
00080 StartLine *
00081 RequestLine::clone(void* location) const
00082 {
00083    return new (location) RequestLine(*this);
00084 }
00085 
00086 const Uri&
00087 RequestLine::uri() const 
00088 {
00089    checkParsed(); 
00090    return mUri;
00091 }
00092 
00093 Uri&
00094 RequestLine::uri()
00095 {
00096    checkParsed(); 
00097    return mUri;
00098 }
00099 
00100 MethodTypes
00101 RequestLine::getMethod() const 
00102 {
00103    checkParsed(); 
00104    return mMethod;
00105 }
00106 
00107 MethodTypes& 
00108 RequestLine::method() 
00109 {
00110    checkParsed(); 
00111    return mMethod;
00112 }
00113 
00114 MethodTypes 
00115 RequestLine::method() const 
00116 {
00117    checkParsed(); 
00118    return mMethod;
00119 }
00120 
00121 Data& 
00122 RequestLine::unknownMethodName()
00123 {
00124    checkParsed(); 
00125    return mUnknownMethodName;
00126 }
00127 
00128 const Data& 
00129 RequestLine::unknownMethodName() const 
00130 {
00131    checkParsed(); 
00132    return mUnknownMethodName;
00133 }
00134 
00135 const Data& 
00136 RequestLine::getSipVersion() const 
00137 {
00138    checkParsed(); 
00139    return mSipVersion;
00140 }
00141 
00142 void 
00143 RequestLine::parse(ParseBuffer& pb)
00144 {
00145    const char* start;
00146    start = pb.skipWhitespace();
00147    pb.skipNonWhitespace();
00148    mMethod = getMethodType(start, int(pb.position() - start));
00149    // for backward compatibility, set the method name even if the method is known
00150    pb.data(mUnknownMethodName, start);
00151    pb.skipWhitespace();
00152    mUri.parse(pb);
00153    start = pb.skipWhitespace();
00154    pb.skipNonWhitespace();
00155    pb.data(mSipVersion, start);
00156 }
00157 
00158 EncodeStream&
00159 RequestLine::encodeParsed(EncodeStream& str) const
00160 {
00161    str << (mMethod != UNKNOWN ? getMethodName(mMethod) : mUnknownMethodName) << Symbols::SPACE;
00162    mUri.encodeParsed(str);
00163    str << Symbols::SPACE << mSipVersion;
00164    return str;
00165 }
00166 
00167 const Data& 
00168 RequestLine::errorContext() const
00169 {
00170    static const Data reqLine("Request Line");
00171    return reqLine;
00172 }
00173 
00174 /* ====================================================================
00175  * The Vovida Software License, Version 1.0 
00176  * 
00177  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00178  * 
00179  * Redistribution and use in source and binary forms, with or without
00180  * modification, are permitted provided that the following conditions
00181  * are met:
00182  * 
00183  * 1. Redistributions of source code must retain the above copyright
00184  *    notice, this list of conditions and the following disclaimer.
00185  * 
00186  * 2. Redistributions in binary form must reproduce the above copyright
00187  *    notice, this list of conditions and the following disclaimer in
00188  *    the documentation and/or other materials provided with the
00189  *    distribution.
00190  * 
00191  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00192  *    and "Vovida Open Communication Application Library (VOCAL)" must
00193  *    not be used to endorse or promote products derived from this
00194  *    software without prior written permission. For written
00195  *    permission, please contact vocal@vovida.org.
00196  *
00197  * 4. Products derived from this software may not be called "VOCAL", nor
00198  *    may "VOCAL" appear in their name, without prior written
00199  *    permission of Vovida Networks, Inc.
00200  * 
00201  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00202  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00203  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00204  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00205  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00206  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00207  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00208  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00209  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00210  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00211  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00212  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00213  * DAMAGE.
00214  * 
00215  * ====================================================================
00216  * 
00217  * This software consists of voluntary contributions made by Vovida
00218  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00219  * Inc.  For more information on Vovida Networks, Inc., please see
00220  * <http://www.vovida.org/>.
00221  *
00222  */