|
reSIProcate/stack
9694
|
00001 #if defined(HAVE_CONFIG_H) 00002 #include "config.h" 00003 #endif 00004 00005 #include "resip/stack/CSeqCategory.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 00017 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP 00018 00019 //==================== 00020 // CSeqCategory: 00021 //==================== 00022 CSeqCategory::CSeqCategory(const HeaderFieldValue& hfv, 00023 Headers::Type type, 00024 PoolBase* pool) 00025 : ParserCategory(hfv, type, pool), mMethod(UNKNOWN), mSequence(0) 00026 {} 00027 00028 CSeqCategory::CSeqCategory() 00029 : ParserCategory(), 00030 mMethod(UNKNOWN), 00031 mUnknownMethodName(getMethodName(UNKNOWN)), 00032 mSequence(0) 00033 {} 00034 00035 CSeqCategory::CSeqCategory(const CSeqCategory& rhs, PoolBase* pool) 00036 : ParserCategory(rhs, pool), 00037 mMethod(rhs.mMethod), 00038 mUnknownMethodName(rhs.mUnknownMethodName), 00039 mSequence(rhs.mSequence) 00040 {} 00041 00042 CSeqCategory& 00043 CSeqCategory::operator=(const CSeqCategory& rhs) 00044 { 00045 if (this != &rhs) 00046 { 00047 ParserCategory::operator=(rhs); 00048 mMethod = rhs.mMethod; 00049 mUnknownMethodName = rhs.mUnknownMethodName; 00050 mSequence = rhs.mSequence; 00051 } 00052 return *this; 00053 } 00054 00055 bool 00056 CSeqCategory::operator==(const CSeqCategory& rhs) const 00057 { 00058 return (mMethod == rhs.mMethod && 00059 (mMethod != UNKNOWN || mUnknownMethodName == rhs.mUnknownMethodName) && 00060 mSequence == rhs.mSequence); 00061 } 00062 00063 bool 00064 CSeqCategory::operator<(const CSeqCategory& rhs) const 00065 { 00066 if (mUnknownMethodName < rhs.mUnknownMethodName) 00067 { 00068 return true; 00069 } 00070 else if (mUnknownMethodName > rhs.mUnknownMethodName) 00071 { 00072 return false; 00073 } 00074 00075 return mSequence < rhs.mSequence; 00076 } 00077 00078 00079 ParserCategory* 00080 CSeqCategory::clone() const 00081 { 00082 return new CSeqCategory(*this); 00083 } 00084 00085 ParserCategory* 00086 CSeqCategory::clone(void* location) const 00087 { 00088 return new (location) CSeqCategory(*this); 00089 } 00090 00091 ParserCategory* 00092 CSeqCategory::clone(PoolBase* pool) const 00093 { 00094 return new (pool) CSeqCategory(*this, pool); 00095 } 00096 00097 MethodTypes& 00098 CSeqCategory::method() 00099 { 00100 checkParsed(); 00101 return mMethod; 00102 } 00103 00104 MethodTypes 00105 CSeqCategory::method() const 00106 { 00107 checkParsed(); return mMethod; 00108 } 00109 00110 Data& 00111 CSeqCategory::unknownMethodName() 00112 { 00113 checkParsed(); 00114 return mUnknownMethodName; 00115 } 00116 00117 const Data& 00118 CSeqCategory::unknownMethodName() const 00119 { 00120 checkParsed(); 00121 return mUnknownMethodName; 00122 } 00123 00124 unsigned int& 00125 CSeqCategory::sequence() 00126 { 00127 checkParsed(); 00128 return mSequence; 00129 } 00130 00131 unsigned int 00132 CSeqCategory::sequence() const 00133 { 00134 checkParsed(); 00135 return mSequence; 00136 } 00137 00138 // examples to test: 00139 // "CSeq:15 ACK" // ok 00140 // "CSeq:ACK" // bad 00141 // "CSeq:JOE" // ok 00142 // "CSeq:1 JOE" // ok 00143 // "CSeq:1323333 INVITE" // ok 00144 // "CSeq:1323333 Invite" // ok - not invite 00145 // "CSeq:1323333 InviTe" // ok - not invite 00146 // "CSeq:\t\t \t15\t\t\t \t ACK" // ok 00147 // "CSeq:\t\t \t15\t\t\t \t" // bad 00148 // "CSeq:1xihzihsihtqnognsd INVITE" // not ok, but parses (?) 00149 00150 void 00151 CSeqCategory::parse(ParseBuffer& pb) 00152 { 00153 pb.skipWhitespace(); 00154 mSequence = pb.uInt32(); 00155 00156 const char* anchorPtr = pb.skipWhitespace(); 00157 pb.skipNonWhitespace(); // .dcm. maybe pass an arg that says throw if you 00158 // don't move 00159 mMethod = getMethodType(anchorPtr, int(pb.position() - anchorPtr)); 00160 // for backward compatibility, set the method name even if the method is known 00161 pb.data(mUnknownMethodName, anchorPtr); 00162 } 00163 00164 EncodeStream& 00165 CSeqCategory::encodeParsed(EncodeStream& str) const 00166 { 00167 str << mSequence 00168 << Symbols::SPACE 00169 << (mMethod != UNKNOWN ? getMethodName(mMethod) : mUnknownMethodName); 00170 return str; 00171 } 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 */
1.7.5.1