Coverage Report

Created: 2024-04-23 06:04

/src/resiprocate/resip/stack/ExpiresCategory.cxx
Line
Count
Source (jump to first uncovered line)
1
#if defined(HAVE_CONFIG_H)
2
#include "config.h"
3
#endif
4
5
#include "resip/stack/ExpiresCategory.hxx"
6
#include "rutil/Logger.hxx"
7
#include "rutil/ParseBuffer.hxx"
8
//#include "rutil/WinLeakCheck.hxx"  // not compatible with placement new used below
9
10
using namespace resip;
11
using namespace std;
12
13
#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
14
15
//====================
16
// Expires:
17
//====================
18
ExpiresCategory:: ExpiresCategory()
19
   : ParserCategory(), 
20
     mValue(0) 
21
0
{}
22
23
ExpiresCategory::ExpiresCategory(const HeaderFieldValue& hfv, 
24
                                 Headers::Type type,
25
                                 PoolBase* pool)
26
   : ParserCategory(hfv, type, pool), mValue(0)
27
6.45k
{}
28
29
ExpiresCategory::ExpiresCategory(const ExpiresCategory& rhs,
30
                                 PoolBase* pool)
31
   : ParserCategory(rhs, pool),
32
     mValue(rhs.mValue)
33
0
{}
34
35
ExpiresCategory&
36
ExpiresCategory::operator=(const ExpiresCategory& rhs)
37
0
{
38
0
   if (this != &rhs)
39
0
   {
40
0
      ParserCategory::operator=(rhs);
41
0
      mValue = rhs.mValue;
42
0
   }
43
0
   return *this;
44
0
}
45
46
ParserCategory* ExpiresCategory::clone() const
47
0
{
48
0
   return new ExpiresCategory(*this);
49
0
}
50
51
ParserCategory* ExpiresCategory::clone(void* location) const
52
0
{
53
0
   return new (location) ExpiresCategory(*this);
54
0
}
55
56
ParserCategory* 
57
ExpiresCategory::clone(PoolBase* pool) const
58
0
{
59
0
   return new (pool) ExpiresCategory(*this, pool);
60
0
}
61
62
uint32_t& 
63
ExpiresCategory::value() 
64
0
{
65
0
   checkParsed(); 
66
0
   return mValue;
67
0
}
68
69
uint32_t
70
ExpiresCategory::value() const 
71
0
{
72
0
   checkParsed(); 
73
0
   return mValue;
74
0
}
75
76
void
77
ExpiresCategory::parse(ParseBuffer& pb)
78
6.45k
{
79
6.45k
   pb.skipWhitespace();
80
6.45k
   const char *p = pb.position();
81
6.45k
   if (!pb.eof() && isdigit(*p))
82
460
   {
83
460
     mValue = pb.uInt32();
84
460
   }
85
5.99k
   else
86
5.99k
   {
87
5.99k
      mValue = 3600;
88
5.99k
   }
89
6.45k
   pb.skipToChar(Symbols::SEMI_COLON[0]);
90
6.45k
   parseParameters(pb);
91
6.45k
}
92
93
EncodeStream& 
94
ExpiresCategory::encodeParsed(EncodeStream& str) const
95
0
{
96
0
   str << mValue;
97
0
   encodeParameters(str);
98
0
   return str;
99
0
}
100
101
ParameterTypes::Factory ExpiresCategory::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0};
102
103
Parameter* 
104
ExpiresCategory::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool)
105
598k
{
106
598k
   if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type])
107
0
   {
108
0
      return ParameterFactories[type](type, pb, terminators, pool);
109
0
   }
110
598k
   return 0;
111
598k
}
112
113
bool 
114
ExpiresCategory::exists(const Param<ExpiresCategory>& paramType) const
115
0
{
116
0
    checkParsed();
117
0
    bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL;
118
0
    return ret;
119
0
}
120
121
void 
122
ExpiresCategory::remove(const Param<ExpiresCategory>& paramType)
123
0
{
124
0
    checkParsed();
125
0
    removeParameterByEnum(paramType.getTypeNum());
126
0
}
127
128
#define defineParam(_enum, _name, _type, _RFC_ref_ignored)                                                      \
129
_enum##_Param::DType&                                                                                           \
130
0
ExpiresCategory::param(const _enum##_Param& paramType)                                                           \
131
0
{                                                                                                               \
132
0
   checkParsed();                                                                                               \
133
0
   _enum##_Param::Type* p =                                                                                     \
134
0
      static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));                            \
135
0
   if (!p)                                                                                                      \
136
0
   {                                                                                                            \
137
0
      p = new _enum##_Param::Type(paramType.getTypeNum());                                                      \
138
0
      mParameters.push_back(p);                                                                                 \
139
0
   }                                                                                                            \
140
0
   return p->value();                                                                                           \
141
0
}                                                                                                               \
142
                                                                                                                \
143
const _enum##_Param::DType&                                                                                     \
144
0
ExpiresCategory::param(const _enum##_Param& paramType) const                                                     \
145
0
{                                                                                                               \
146
0
   checkParsed();                                                                                               \
147
0
   _enum##_Param::Type* p =                                                                                     \
148
0
      static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));                            \
149
0
   if (!p)                                                                                                      \
150
0
   {                                                                                                            \
151
0
      InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]);     \
152
0
      DebugLog(<< *this);                                                                                       \
153
0
      throw Exception("Missing parameter " _name, __FILE__, __LINE__);                                          \
154
0
   }                                                                                                            \
155
0
   return p->value();                                                                                           \
156
0
}
157
158
defineParam(refresher, "refresher", DataParameter, "RFC 4028");
159
160
#undef defineParam
161
162
/* ====================================================================
163
 * The Vovida Software License, Version 1.0 
164
 * 
165
 * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
166
 * 
167
 * Redistribution and use in source and binary forms, with or without
168
 * modification, are permitted provided that the following conditions
169
 * are met:
170
 * 
171
 * 1. Redistributions of source code must retain the above copyright
172
 *    notice, this list of conditions and the following disclaimer.
173
 * 
174
 * 2. Redistributions in binary form must reproduce the above copyright
175
 *    notice, this list of conditions and the following disclaimer in
176
 *    the documentation and/or other materials provided with the
177
 *    distribution.
178
 * 
179
 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
180
 *    and "Vovida Open Communication Application Library (VOCAL)" must
181
 *    not be used to endorse or promote products derived from this
182
 *    software without prior written permission. For written
183
 *    permission, please contact vocal@vovida.org.
184
 *
185
 * 4. Products derived from this software may not be called "VOCAL", nor
186
 *    may "VOCAL" appear in their name, without prior written
187
 *    permission of Vovida Networks, Inc.
188
 * 
189
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
190
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
191
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
192
 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
193
 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
194
 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
195
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
196
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
197
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
198
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
199
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
200
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
201
 * DAMAGE.
202
 * 
203
 * ====================================================================
204
 * 
205
 * This software consists of voluntary contributions made by Vovida
206
 * Networks, Inc. and many individuals on behalf of Vovida Networks,
207
 * Inc.  For more information on Vovida Networks, Inc., please see
208
 * <http://www.vovida.org/>.
209
 *
210
 */