/[resiprocate]/branches/b-identity-0505/CSeqCategory.cxx
ViewVC logotype

Contents of /branches/b-identity-0505/CSeqCategory.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4598 - (show annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 6 months ago) by derek
File size: 5789 byte(s)
set svn:eol-style to LF
1 #if defined(HAVE_CONFIG_H)
2 #include "resiprocate/config.hxx"
3 #endif
4
5 #include "resiprocate/CSeqCategory.hxx"
6 #include "resiprocate/UnknownParameter.hxx"
7 #include "resiprocate/os/Data.hxx"
8 #include "resiprocate/os/DnsUtil.hxx"
9 #include "resiprocate/os/Logger.hxx"
10 #include "resiprocate/os/ParseBuffer.hxx"
11 #include "resiprocate/os/WinLeakCheck.hxx"
12
13 using namespace resip;
14 using namespace std;
15
16
17 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
18
19 //====================
20 // CSeqCategory:
21 //====================
22 CSeqCategory::CSeqCategory(HeaderFieldValue* hfv, Headers::Type type)
23 : ParserCategory(hfv, type), mMethod(UNKNOWN), mSequence(-1)
24 {}
25
26 CSeqCategory::CSeqCategory()
27 : ParserCategory(),
28 mMethod(UNKNOWN),
29 mUnknownMethodName(getMethodName(UNKNOWN)),
30 mSequence(-1)
31 {}
32
33 CSeqCategory::CSeqCategory(const CSeqCategory& rhs)
34 : ParserCategory(rhs),
35 mMethod(rhs.mMethod),
36 mUnknownMethodName(rhs.mUnknownMethodName),
37 mSequence(rhs.mSequence)
38 {}
39
40 CSeqCategory&
41 CSeqCategory::operator=(const CSeqCategory& rhs)
42 {
43 if (this != &rhs)
44 {
45 ParserCategory::operator=(rhs);
46 mMethod = rhs.mMethod;
47 mUnknownMethodName = rhs.mUnknownMethodName;
48 mSequence = rhs.mSequence;
49 }
50 return *this;
51 }
52
53 bool
54 CSeqCategory::operator==(const CSeqCategory& rhs) const
55 {
56 return (mMethod == rhs.mMethod &&
57 (mMethod != UNKNOWN || mUnknownMethodName == rhs.mUnknownMethodName) &&
58 mSequence == rhs.mSequence);
59 }
60
61 bool
62 CSeqCategory::operator<(const CSeqCategory& rhs) const
63 {
64 if (mUnknownMethodName < rhs.mUnknownMethodName)
65 {
66 return true;
67 }
68 else if (mUnknownMethodName > rhs.mUnknownMethodName)
69 {
70 return false;
71 }
72
73 return mSequence < rhs.mSequence;
74 }
75
76
77 ParserCategory*
78 CSeqCategory::clone() const
79 {
80 return new CSeqCategory(*this);
81 }
82
83 MethodTypes&
84 CSeqCategory::method()
85 {
86 checkParsed();
87 return mMethod;
88 }
89
90 MethodTypes
91 CSeqCategory::method() const
92 {
93 checkParsed(); return mMethod;
94 }
95
96 Data&
97 CSeqCategory::unknownMethodName()
98 {
99 checkParsed();
100 return mUnknownMethodName;
101 }
102
103 const Data&
104 CSeqCategory::unknownMethodName() const
105 {
106 checkParsed();
107 return mUnknownMethodName;
108 }
109
110 int&
111 CSeqCategory::sequence()
112 {
113 checkParsed();
114 return mSequence;
115 }
116
117 int
118 CSeqCategory::sequence() const
119 {
120 checkParsed();
121 return mSequence;
122 }
123
124 // examples to test:
125 // "CSeq:15 ACK" // ok
126 // "CSeq:ACK" // bad
127 // "CSeq:JOE" // ok
128 // "CSeq:1 JOE" // ok
129 // "CSeq:1323333 INVITE" // ok
130 // "CSeq:1323333 Invite" // ok - not invite
131 // "CSeq:1323333 InviTe" // ok - not invite
132 // "CSeq:\t\t \t15\t\t\t \t ACK" // ok
133 // "CSeq:\t\t \t15\t\t\t \t" // bad
134 // "CSeq:1xihzihsihtqnognsd INVITE" // not ok, but parses (?)
135
136 void
137 CSeqCategory::parse(ParseBuffer& pb)
138 {
139 pb.skipWhitespace();
140 mSequence = pb.integer();
141
142 const char* anchorPtr = pb.skipWhitespace();
143 pb.skipNonWhitespace(); // .dcm. maybe pass an arg that says throw if you
144 // don't move
145 mMethod = getMethodType(anchorPtr, pb.position() - anchorPtr);
146 // for backward compatibility, set the method name even if the method is known
147 pb.data(mUnknownMethodName, anchorPtr);
148 }
149
150 std::ostream&
151 CSeqCategory::encodeParsed(std::ostream& str) const
152 {
153 str << mSequence
154 << Symbols::SPACE
155 << (mMethod != UNKNOWN ? getMethodName(mMethod) : mUnknownMethodName);
156 return str;
157 }
158
159
160 /* ====================================================================
161 * The Vovida Software License, Version 1.0
162 *
163 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
164 *
165 * Redistribution and use in source and binary forms, with or without
166 * modification, are permitted provided that the following conditions
167 * are met:
168 *
169 * 1. Redistributions of source code must retain the above copyright
170 * notice, this list of conditions and the following disclaimer.
171 *
172 * 2. Redistributions in binary form must reproduce the above copyright
173 * notice, this list of conditions and the following disclaimer in
174 * the documentation and/or other materials provided with the
175 * distribution.
176 *
177 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
178 * and "Vovida Open Communication Application Library (VOCAL)" must
179 * not be used to endorse or promote products derived from this
180 * software without prior written permission. For written
181 * permission, please contact vocal@vovida.org.
182 *
183 * 4. Products derived from this software may not be called "VOCAL", nor
184 * may "VOCAL" appear in their name, without prior written
185 * permission of Vovida Networks, Inc.
186 *
187 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
188 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
189 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
190 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
191 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
192 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
193 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
194 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
195 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
196 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
197 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
198 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
199 * DAMAGE.
200 *
201 * ====================================================================
202 *
203 * This software consists of voluntary contributions made by Vovida
204 * Networks, Inc. and many individuals on behalf of Vovida Networks,
205 * Inc. For more information on Vovida Networks, Inc., please see
206 * <http://www.vovida.org/>.
207 *
208 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27