reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
CSeqCategory.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
7#include "rutil/Data.hxx"
8#include "rutil/DnsUtil.hxx"
9#include "rutil/Logger.hxx"
10#include "rutil/ParseBuffer.hxx"
11//#include "rutil/WinLeakCheck.hxx" // not compatible with placement new used below
12
13using namespace resip;
14using namespace std;
15
16
17#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
18
19//====================
20// CSeqCategory:
21//====================
23 Headers::Type type,
24 PoolBase* pool)
25 : ParserCategory(hfv, type, pool), mMethod(UNKNOWN), mSequence(0)
26{}
27
29 : ParserCategory(),
30 mMethod(UNKNOWN),
31 mUnknownMethodName(getMethodName(UNKNOWN)),
32 mSequence(0)
33{}
34
36 : ParserCategory(rhs, pool),
37 mMethod(rhs.mMethod),
38 mUnknownMethodName(rhs.mUnknownMethodName),
39 mSequence(rhs.mSequence)
40{}
41
44{
45 if (this != &rhs)
46 {
48 mMethod = rhs.mMethod;
49 mUnknownMethodName = rhs.mUnknownMethodName;
50 mSequence = rhs.mSequence;
51 }
52 return *this;
53}
54
55bool
57{
58 return (mMethod == rhs.mMethod &&
59 (mMethod != UNKNOWN || mUnknownMethodName == rhs.mUnknownMethodName) &&
60 mSequence == rhs.mSequence);
61}
62
63bool
65{
66 if (mUnknownMethodName < rhs.mUnknownMethodName)
67 {
68 return true;
69 }
70 else if (mUnknownMethodName > rhs.mUnknownMethodName)
71 {
72 return false;
73 }
74
75 return mSequence < rhs.mSequence;
76}
77
78
81{
82 return new CSeqCategory(*this);
83}
84
86CSeqCategory::clone(void* location) const
87{
88 return new (location) CSeqCategory(*this);
89}
90
93{
94 return new (pool) CSeqCategory(*this, pool);
95}
96
99{
100 checkParsed();
101 return mMethod;
102}
103
106{
107 checkParsed(); return mMethod;
108}
109
110Data&
112{
113 checkParsed();
114 return mUnknownMethodName;
115}
116
117const Data&
119{
120 checkParsed();
121 return mUnknownMethodName;
122}
123
124unsigned int&
126{
127 checkParsed();
128 return mSequence;
129}
130
131unsigned int
133{
134 checkParsed();
135 return mSequence;
136}
137
138// examples to test:
139// "CSeq:15 ACK" // ok
140// "CSeq:ACK" // bad
141// "CSeq:JOE" // ok
142// "CSeq:1 JOE" // ok
143// "CSeq:1323333 INVITE" // ok
144// "CSeq:1323333 Invite" // ok - not invite
145// "CSeq:1323333 InviTe" // ok - not invite
146// "CSeq:\t\t \t15\t\t\t \t ACK" // ok
147// "CSeq:\t\t \t15\t\t\t \t" // bad
148// "CSeq:1xihzihsihtqnognsd INVITE" // not ok, but parses (?)
149
150void
152{
153 pb.skipWhitespace();
154 mSequence = pb.uInt32();
155
156 const char* anchorPtr = pb.skipWhitespace();
157 pb.skipNonWhitespace(); // .dcm. maybe pass an arg that says throw if you
158 // don't move
159 mMethod = getMethodType(anchorPtr, int(pb.position() - anchorPtr));
160 // for backward compatibility, set the method name even if the method is known
161 pb.data(mUnknownMethodName, anchorPtr);
162}
163
165CSeqCategory::encodeParsed(EncodeStream& str) const
166{
167 str << mSequence
169 << (mMethod != UNKNOWN ? getMethodName(mMethod) : mUnknownMethodName);
170 return str;
171}
172
173
174/* ====================================================================
175 * The Vovida Software License, Version 1.0
176 *
177 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
178 *
179 * Redistribution and use in source and binary forms, with or without
180 * modification, are permitted provided that the following conditions
181 * are met:
182 *
183 * 1. Redistributions of source code must retain the above copyright
184 * notice, this list of conditions and the following disclaimer.
185 *
186 * 2. Redistributions in binary form must reproduce the above copyright
187 * notice, this list of conditions and the following disclaimer in
188 * the documentation and/or other materials provided with the
189 * distribution.
190 *
191 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
192 * and "Vovida Open Communication Application Library (VOCAL)" must
193 * not be used to endorse or promote products derived from this
194 * software without prior written permission. For written
195 * permission, please contact vocal@vovida.org.
196 *
197 * 4. Products derived from this software may not be called "VOCAL", nor
198 * may "VOCAL" appear in their name, without prior written
199 * permission of Vovida Networks, Inc.
200 *
201 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
202 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
203 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
204 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
205 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
206 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
207 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
208 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
209 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
210 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
211 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
212 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
213 * DAMAGE.
214 *
215 * ====================================================================
216 *
217 * This software consists of voluntary contributions made by Vovida
218 * Networks, Inc. and many individuals on behalf of Vovida Networks,
219 * Inc. For more information on Vovida Networks, Inc., please see
220 * <http://www.vovida.org/>.
221 *
222 */
Represents a CSeq header field value (this doesn't have an official name in the RFC 3261 grammar).
unsigned int & sequence()
CSeqCategory & operator=(const CSeqCategory &)
virtual EncodeStream & encodeParsed(EncodeStream &str) const
virtual void parse(ParseBuffer &pb)
bool operator==(const CSeqCategory &rhs) const
bool operator<(const CSeqCategory &rhs) const
virtual ParserCategory * clone() const
MethodTypes & method()
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
void checkParsed() const
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipNonWhitespace()
uint32_t uInt32()
dcm! – merge these, ask about length checks
CurrentPosition skipWhitespace()
CurrentPosition position() const
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
Base class for all SIP grammar elements that can have parameters.
ParserCategory & operator=(const ParserCategory &rhs)
static const char * SPACE
Definition Symbols.hxx:34
dcm! – add UnusedChecking(_enum) below;
const Data & getMethodName(MethodTypes t)
MethodTypes getMethodType(const Data &name)
#define EncodeStream