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