Coverage Report

Created: 2024-07-23 06:39

/src/resiprocate/resip/stack/GenericUri.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/GenericUri.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
//====================
17
// GenericUri
18
//====================
19
GenericUri::GenericUri(const GenericUri& rhs,
20
                        PoolBase* pool)
21
   : ParserCategory(rhs, pool),
22
     mUri(rhs.mUri)
23
0
{}
24
25
GenericUri::GenericUri(const HeaderFieldValue& hfv, 
26
                        Headers::Type type,
27
                        PoolBase* pool) 
28
   : ParserCategory(hfv, type, pool) 
29
6.46k
{}
30
31
GenericUri&
32
GenericUri::operator=(const GenericUri& rhs)
33
0
{
34
0
   if (this != &rhs)
35
0
   {
36
0
      ParserCategory::operator=(rhs);
37
0
      mUri = rhs.mUri;
38
0
   }
39
0
   return *this;
40
0
}
41
42
Data& 
43
GenericUri::uri()
44
0
{
45
0
   checkParsed();
46
0
   return mUri;
47
0
}
48
49
const Data& 
50
GenericUri::uri() const
51
0
{
52
0
   checkParsed();
53
0
   return mUri;
54
0
}
55
56
void
57
GenericUri::parse(ParseBuffer& pb)
58
6.46k
{
59
6.46k
   pb.skipWhitespace();
60
6.46k
   const char* anchor = pb.skipChar(Symbols::LA_QUOTE[0]);
61
62
6.46k
   pb.skipToChar(Symbols::RA_QUOTE[0]);
63
6.46k
   pb.data(mUri, anchor);
64
6.46k
   pb.skipChar(Symbols::RA_QUOTE[0]);
65
66
6.46k
   pb.skipWhitespace();
67
68
6.46k
   parseParameters(pb);
69
6.46k
}
70
71
ParserCategory* 
72
GenericUri::clone() const
73
0
{
74
0
   return new GenericUri(*this);
75
0
}
76
77
ParserCategory* 
78
GenericUri::clone(void* location) const
79
0
{
80
0
   return new (location) GenericUri(*this);
81
0
}
82
83
ParserCategory* 
84
GenericUri::clone(PoolBase* pool) const
85
0
{
86
0
   return new (pool) GenericUri(*this, pool);
87
0
}
88
89
EncodeStream& 
90
GenericUri::encodeParsed(EncodeStream& str) const
91
0
{
92
0
   str << Symbols::LA_QUOTE[0]
93
0
       << mUri
94
0
       << Symbols::RA_QUOTE[0];
95
96
0
   encodeParameters(str);
97
98
0
   return str;
99
0
}
100
101
ParameterTypes::Factory GenericUri::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0};
102
103
Parameter* 
104
GenericUri::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool)
105
213
{
106
213
   if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type])
107
0
   {
108
0
      return ParameterFactories[type](type, pb, terminators, pool);
109
0
   }
110
213
   return 0;
111
213
}
112
113
bool 
114
GenericUri::exists(const Param<GenericUri>& 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
GenericUri::remove(const Param<GenericUri>& 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
GenericUri::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
GenericUri::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(purpose, "purpose", DataParameter, "RFC 3261");
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
 */