Coverage Report

Created: 2024-07-23 06:39

/src/resiprocate/resip/stack/TokenOrQuotedStringCategory.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/TokenOrQuotedStringCategory.hxx"
6
#include "rutil/Logger.hxx"
7
#include "rutil/ParseBuffer.hxx"
8
9
using namespace resip;
10
using namespace std;
11
12
#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
13
14
//============================
15
// TokenOrQuotedStringCategory
16
//============================
17
TokenOrQuotedStringCategory::TokenOrQuotedStringCategory()
18
   : ParserCategory(),
19
     mValue(),
20
     mQuoted(false)
21
0
{}
22
23
TokenOrQuotedStringCategory::TokenOrQuotedStringCategory(const Data& value,
24
                                                         bool quoted)
25
   : ParserCategory(),
26
     mValue(value),
27
     mQuoted(quoted)
28
0
{}
29
30
TokenOrQuotedStringCategory::TokenOrQuotedStringCategory(const HeaderFieldValue& hfv,
31
                                                         Headers::Type type,
32
                                                         PoolBase* pool)
33
   : ParserCategory(hfv, type, pool),
34
     mValue(),
35
     mQuoted(false)
36
0
{}
37
38
TokenOrQuotedStringCategory::TokenOrQuotedStringCategory(const TokenOrQuotedStringCategory& rhs,
39
                                                         PoolBase* pool)
40
   : ParserCategory(rhs, pool),
41
     mValue(rhs.mValue),
42
     mQuoted(rhs.mQuoted)
43
0
{}
44
45
TokenOrQuotedStringCategory&
46
TokenOrQuotedStringCategory::operator=(const TokenOrQuotedStringCategory& rhs)
47
0
{
48
0
   if (this != &rhs)
49
0
   {
50
0
      ParserCategory::operator=(rhs);
51
0
      mValue = rhs.mValue;
52
0
      mQuoted = rhs.mQuoted;
53
0
   }
54
0
   return *this;
55
0
}
56
57
ParserCategory*
58
TokenOrQuotedStringCategory::clone() const
59
0
{
60
0
   return new TokenOrQuotedStringCategory(*this);
61
0
}
62
63
ParserCategory*
64
TokenOrQuotedStringCategory::clone(void* location) const
65
0
{
66
0
   return new (location) TokenOrQuotedStringCategory(*this);
67
0
}
68
69
ParserCategory*
70
TokenOrQuotedStringCategory::clone(PoolBase* pool) const
71
0
{
72
0
   return new (pool) TokenOrQuotedStringCategory(*this, pool);
73
0
}
74
75
bool
76
TokenOrQuotedStringCategory::isEqual(const TokenOrQuotedStringCategory& rhs) const
77
0
{
78
0
   return ((value() == rhs.value()) && (isQuoted() == rhs.isQuoted()));
79
0
}
80
81
bool
82
TokenOrQuotedStringCategory::operator==(const TokenOrQuotedStringCategory& rhs) const
83
0
{
84
0
   return ((value() == rhs.value()) && (isQuoted() == rhs.isQuoted()));
85
0
}
86
87
bool
88
TokenOrQuotedStringCategory::operator!=(const TokenOrQuotedStringCategory& rhs) const
89
0
{
90
0
   return ((value() != rhs.value()) || (isQuoted() != rhs.isQuoted()));
91
0
}
92
93
bool
94
TokenOrQuotedStringCategory::operator<(const TokenOrQuotedStringCategory& rhs) const
95
0
{
96
   // don't use mQuoted for operator <
97
0
   return (value() < rhs.value());
98
0
}
99
100
void
101
TokenOrQuotedStringCategory::parse(ParseBuffer& pb)
102
0
{
103
0
   const char* startMark = pb.skipWhitespace();
104
0
   if (*pb.position() == Symbols::DOUBLE_QUOTE[0])
105
0
   {
106
0
      setQuoted(true);
107
0
      pb.skipChar();
108
0
      startMark = pb.position();
109
0
      pb.skipToEndQuote();
110
0
   }
111
0
   else
112
0
   {
113
0
      setQuoted(false);
114
0
      pb.skipToOneOf(ParseBuffer::Whitespace, Symbols::SEMI_COLON);
115
0
   }
116
0
   pb.data(mValue, startMark);
117
0
   pb.skipToChar(Symbols::SEMI_COLON[0]);
118
0
   parseParameters(pb);
119
0
}
120
121
EncodeStream&
122
TokenOrQuotedStringCategory::encodeParsed(EncodeStream& str) const
123
0
{
124
0
   str << quotedValue();
125
0
   encodeParameters(str);
126
0
   return str;
127
0
}
128
129
const Data& TokenOrQuotedStringCategory::value() const
130
0
{
131
0
   checkParsed();
132
0
   return mValue;
133
0
}
134
135
Data& TokenOrQuotedStringCategory::value()
136
0
{
137
0
   checkParsed();
138
0
   return mValue;
139
0
}
140
141
Data TokenOrQuotedStringCategory::quotedValue() const
142
0
{
143
0
   checkParsed();
144
0
   Data tokenValue;
145
0
   if (mQuoted)
146
0
   {
147
0
      tokenValue += Symbols::DOUBLE_QUOTE;
148
0
   }
149
   // mValue does not contain quoted string
150
0
   tokenValue += mValue;
151
0
   if (mQuoted)
152
0
   {
153
0
      tokenValue += Symbols::DOUBLE_QUOTE;
154
0
   }
155
0
   return tokenValue;
156
0
}
157
158
ParameterTypes::Factory TokenOrQuotedStringCategory::ParameterFactories[ParameterTypes::MAX_PARAMETER] = { 0 };
159
160
Parameter*
161
TokenOrQuotedStringCategory::createParam(ParameterTypes::Type type,
162
                                         ParseBuffer& pb,
163
                                         const std::bitset<256>& terminators,
164
                                         PoolBase* pool)
165
0
{
166
0
   if ((type > ParameterTypes::UNKNOWN) && (type < ParameterTypes::MAX_PARAMETER) && ParameterFactories[type])
167
0
   {
168
0
      return ParameterFactories[type](type, pb, terminators, pool);
169
0
   }
170
0
   return 0;
171
0
}
172
173
bool
174
TokenOrQuotedStringCategory::exists(const Param<TokenOrQuotedStringCategory>& paramType) const
175
0
{
176
0
    checkParsed();
177
0
    bool ret = (getParameterByEnum(paramType.getTypeNum()) != NULL);
178
0
    return ret;
179
0
}
180
181
void
182
TokenOrQuotedStringCategory::remove(const Param<TokenOrQuotedStringCategory>& paramType)
183
0
{
184
0
    checkParsed();
185
0
    removeParameterByEnum(paramType.getTypeNum());
186
0
}
187
188
#define defineParam(_enum, _name, _type, _RFC_ref_ignored)                                                      \
189
_enum##_Param::DType&                                                                                           \
190
0
TokenOrQuotedStringCategory::param(const _enum##_Param& paramType)                                              \
191
0
{                                                                                                               \
192
0
   checkParsed();                                                                                               \
193
0
   _enum##_Param::Type* p =                                                                                     \
194
0
      static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));                            \
195
0
   if (!p)                                                                                                      \
196
0
   {                                                                                                            \
197
0
      p = new _enum##_Param::Type(paramType.getTypeNum());                                                      \
198
0
      mParameters.push_back(p);                                                                                 \
199
0
   }                                                                                                            \
200
0
   return p->value();                                                                                           \
201
0
}                                                                                                               \
Unexecuted instantiation: resip::TokenOrQuotedStringCategory::param(resip::purpose_Param const&)
Unexecuted instantiation: resip::TokenOrQuotedStringCategory::param(resip::content_Param const&)
Unexecuted instantiation: resip::TokenOrQuotedStringCategory::param(resip::encoding_Param const&)
202
                                                                                                                \
203
const _enum##_Param::DType&                                                                                     \
204
0
TokenOrQuotedStringCategory::param(const _enum##_Param& paramType) const                                        \
205
0
{                                                                                                               \
206
0
   checkParsed();                                                                                               \
207
0
   _enum##_Param::Type* p =                                                                                     \
208
0
      static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum()));                            \
209
0
   if (!p)                                                                                                      \
210
0
   {                                                                                                            \
211
0
      InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]);     \
212
0
      DebugLog(<< *this);                                                                                       \
213
0
      throw Exception("Missing parameter " _name, __FILE__, __LINE__);                                          \
214
0
   }                                                                                                            \
215
0
   return p->value();                                                                                           \
216
0
}
Unexecuted instantiation: resip::TokenOrQuotedStringCategory::param(resip::purpose_Param const&) const
Unexecuted instantiation: resip::TokenOrQuotedStringCategory::param(resip::content_Param const&) const
Unexecuted instantiation: resip::TokenOrQuotedStringCategory::param(resip::encoding_Param const&) const
217
218
defineParam(purpose, "purpose", DataParameter, "draft-ietf-cuss-sip-uui-17"); // User-to-User
219
defineParam(content, "content", DataParameter, "draft-ietf-cuss-sip-uui-17"); // User-to-User
220
defineParam(encoding, "encoding", DataParameter, "draft-ietf-cuss-sip-uui-17"); // User-to-User
221
222
#undef defineParam
223
224
/* ====================================================================
225
 * The Vovida Software License, Version 1.0 
226
 * 
227
 * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
228
 * 
229
 * Redistribution and use in source and binary forms, with or without
230
 * modification, are permitted provided that the following conditions
231
 * are met:
232
 * 
233
 * 1. Redistributions of source code must retain the above copyright
234
 *    notice, this list of conditions and the following disclaimer.
235
 * 
236
 * 2. Redistributions in binary form must reproduce the above copyright
237
 *    notice, this list of conditions and the following disclaimer in
238
 *    the documentation and/or other materials provided with the
239
 *    distribution.
240
 * 
241
 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
242
 *    and "Vovida Open Communication Application Library (VOCAL)" must
243
 *    not be used to endorse or promote products derived from this
244
 *    software without prior written permission. For written
245
 *    permission, please contact vocal@vovida.org.
246
 *
247
 * 4. Products derived from this software may not be called "VOCAL", nor
248
 *    may "VOCAL" appear in their name, without prior written
249
 *    permission of Vovida Networks, Inc.
250
 * 
251
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
252
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
253
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
254
 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
255
 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
256
 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
257
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
258
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
259
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
260
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
262
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
263
 * DAMAGE.
264
 * 
265
 * ====================================================================
266
 * 
267
 * This software consists of voluntary contributions made by Vovida
268
 * Networks, Inc. and many individuals on behalf of Vovida Networks,
269
 * Inc.  For more information on Vovida Networks, Inc., please see
270
 * <http://www.vovida.org/>.
271
 *
272
 */