Coverage Report

Created: 2026-01-09 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/resiprocate/resip/stack/CSeqCategory.cxx
Line
Count
Source
1
#if defined(HAVE_CONFIG_H)
2
#include "config.h"
3
#endif
4
5
#include "resip/stack/CSeqCategory.hxx"
6
#include "resip/stack/UnknownParameter.hxx"
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
13
using namespace resip;
14
using namespace std;
15
16
17
#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
18
19
//====================
20
// CSeqCategory:
21
//====================
22
CSeqCategory::CSeqCategory(const HeaderFieldValue& hfv, 
23
                           Headers::Type type,
24
                           PoolBase* pool)
25
6.11k
   : ParserCategory(hfv, type, pool), mMethod(UNKNOWN), mSequence(0) 
26
6.11k
{}
27
28
CSeqCategory::CSeqCategory() 
29
0
   : ParserCategory(), 
30
0
     mMethod(UNKNOWN), 
31
0
     mUnknownMethodName(getMethodName(UNKNOWN)),
32
0
     mSequence(0) 
33
0
{}
34
35
CSeqCategory::CSeqCategory(const CSeqCategory& rhs, PoolBase* pool)
36
0
   : ParserCategory(rhs, pool),
37
0
     mMethod(rhs.mMethod),
38
0
     mUnknownMethodName(rhs.mUnknownMethodName),
39
0
     mSequence(rhs.mSequence)
40
0
{}
41
42
CSeqCategory&
43
CSeqCategory::operator=(const CSeqCategory& rhs)
44
0
{
45
0
   if (this != &rhs)
46
0
   {
47
0
      ParserCategory::operator=(rhs);
48
0
      mMethod = rhs.mMethod;
49
0
      mUnknownMethodName = rhs.mUnknownMethodName;
50
0
      mSequence = rhs.mSequence;
51
0
   }
52
0
   return *this;
53
0
}
54
55
bool
56
CSeqCategory::operator==(const CSeqCategory& rhs) const
57
0
{
58
0
   return (mMethod == rhs.mMethod &&
59
0
           (mMethod != UNKNOWN || mUnknownMethodName == rhs.mUnknownMethodName) &&
60
0
           mSequence == rhs.mSequence);
61
0
}
62
63
bool
64
CSeqCategory::operator<(const CSeqCategory& rhs) const
65
0
{
66
0
   if (mUnknownMethodName < rhs.mUnknownMethodName) 
67
0
   {
68
0
      return true;
69
0
   }
70
0
   else if (mUnknownMethodName > rhs.mUnknownMethodName) 
71
0
   {
72
0
      return false;
73
0
   }
74
   
75
0
   return mSequence < rhs.mSequence;
76
0
}
77
78
79
ParserCategory* 
80
CSeqCategory::clone() const
81
0
{
82
0
   return new CSeqCategory(*this);
83
0
}
84
85
ParserCategory* 
86
CSeqCategory::clone(void* location) const
87
0
{
88
0
   return new (location) CSeqCategory(*this);
89
0
}
90
91
ParserCategory* 
92
CSeqCategory::clone(PoolBase* pool) const
93
0
{
94
0
   return new (pool) CSeqCategory(*this, pool);
95
0
}
96
97
MethodTypes& 
98
CSeqCategory::method()
99
0
{
100
0
   checkParsed(); 
101
0
   return mMethod;
102
0
}
103
104
MethodTypes 
105
CSeqCategory::method() const 
106
0
{
107
0
   checkParsed(); return mMethod;
108
0
}
109
110
Data&
111
CSeqCategory::unknownMethodName()
112
0
{
113
0
   checkParsed(); 
114
0
   return mUnknownMethodName;
115
0
}
116
117
const Data& 
118
CSeqCategory::unknownMethodName() const 
119
0
{
120
0
   checkParsed(); 
121
0
   return mUnknownMethodName;
122
0
}
123
124
unsigned int& 
125
CSeqCategory::sequence()
126
0
{
127
0
   checkParsed(); 
128
0
   return mSequence;
129
0
}
130
131
unsigned int 
132
CSeqCategory::sequence() const
133
0
{
134
0
   checkParsed(); 
135
0
   return mSequence;
136
0
}
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
150
void
151
CSeqCategory::parse(ParseBuffer& pb)
152
6.11k
{
153
6.11k
   pb.skipWhitespace();
154
6.11k
   mSequence = pb.uInt32();
155
156
6.11k
   const char* anchorPtr = pb.skipWhitespace();
157
6.11k
   pb.skipNonWhitespace(); // .dcm. maybe pass an arg that says throw if you
158
                           // don't move
159
6.11k
   mMethod = getMethodType(anchorPtr, int(pb.position() - anchorPtr));
160
   // for backward compatibility, set the method name even if the method is known
161
6.11k
   pb.data(mUnknownMethodName, anchorPtr);
162
6.11k
}
163
164
EncodeStream& 
165
CSeqCategory::encodeParsed(EncodeStream& str) const
166
0
{
167
0
   str << mSequence 
168
0
       << Symbols::SPACE 
169
0
       << (mMethod != UNKNOWN ? getMethodName(mMethod) : mUnknownMethodName);
170
0
   return str;
171
0
}
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
 */