Coverage Report

Created: 2023-06-07 06:03

/src/resiprocate/resip/stack/HeaderFieldValue.cxx
Line
Count
Source (jump to first uncovered line)
1
#if defined(HAVE_CONFIG_H)
2
#include "config.h"
3
#endif
4
5
#include <iostream>
6
7
#include "resip/stack/UnknownParameter.hxx"
8
#include "resip/stack/ExistsParameter.hxx"
9
#include "resip/stack/HeaderFieldValue.hxx"
10
#include "resip/stack/MsgHeaderScanner.hxx"
11
#include "resip/stack/ParserCategory.hxx"
12
#include "resip/stack/Symbols.hxx"
13
#include "rutil/ParseBuffer.hxx"
14
#include "rutil/Logger.hxx"
15
#include "rutil/WinLeakCheck.hxx"
16
17
using namespace std;
18
using namespace resip;
19
20
21
#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
22
23
const HeaderFieldValue HeaderFieldValue::Empty;
24
25
HeaderFieldValue::HeaderFieldValue(const char* field, unsigned int fieldLength)
26
   : mField(field),
27
     mFieldLength(fieldLength),
28
     mMine(false)
29
13.6k
{}
30
31
HeaderFieldValue::HeaderFieldValue(const HeaderFieldValue& hfv)
32
   : mField(0),
33
     mFieldLength(hfv.mFieldLength),
34
     mMine(true)
35
2.76M
{
36
2.76M
   if(mFieldLength)
37
1.72M
   {
38
1.72M
      char* newField = new char[mFieldLength];
39
1.72M
      memcpy(newField, hfv.mField, mFieldLength);
40
1.72M
      mField=newField;
41
1.72M
   }
42
2.76M
}
43
44
HeaderFieldValue&
45
HeaderFieldValue::operator=(const HeaderFieldValue& rhs)
46
0
{
47
0
   if(this!=&rhs)
48
0
   {
49
0
      mFieldLength=rhs.mFieldLength;
50
0
      if(mMine) delete [] mField;
51
0
      mMine=true;
52
0
      if(mFieldLength)
53
0
      {
54
0
         char* newField = new char[mFieldLength];
55
0
         memcpy(newField, rhs.mField, mFieldLength);
56
0
         mField=newField;
57
0
      }
58
0
      else
59
0
      {
60
0
         mField=0;
61
0
      }
62
0
   }
63
   
64
0
   return *this;
65
0
}
66
67
HeaderFieldValue& 
68
HeaderFieldValue::copyWithPadding(const HeaderFieldValue& rhs)
69
0
{
70
0
   if(this!=&rhs)
71
0
   {
72
0
      mFieldLength=rhs.mFieldLength;
73
0
      if(mMine) delete [] mField;
74
0
      mMine=true;
75
0
      if(mFieldLength)
76
0
      {
77
0
         char* newField = MsgHeaderScanner::allocateBuffer(mFieldLength);
78
0
         memcpy(newField, rhs.mField, mFieldLength);
79
0
         mField=newField;
80
0
      }
81
0
      else
82
0
      {
83
0
         mField=0;
84
0
      }
85
0
   }
86
   
87
0
   return *this;
88
0
}
89
90
HeaderFieldValue::HeaderFieldValue(const HeaderFieldValue& hfv, CopyPaddingEnum e)
91
   : mField(0),
92
     mFieldLength(hfv.mFieldLength),
93
     mMine(true)
94
0
{
95
0
   char* newField = MsgHeaderScanner::allocateBuffer(mFieldLength);
96
0
   memcpy(newField, hfv.mField, mFieldLength);
97
0
   mField=newField;
98
0
}
99
100
HeaderFieldValue::HeaderFieldValue(const HeaderFieldValue& hfv, NoOwnershipEnum n)
101
   : mField(hfv.mField),
102
     mFieldLength(hfv.mFieldLength),
103
     mMine(false)
104
156k
{
105
   // ?bwc? assert(!hfv.mMine); ?
106
156k
}
107
108
HeaderFieldValue&
109
HeaderFieldValue::swap(HeaderFieldValue& orig)
110
199
{
111
199
   if (this != &orig)
112
199
   {
113
199
      std::swap(mField, orig.mField);
114
199
      std::swap(mFieldLength, orig.mFieldLength);
115
199
      std::swap(mMine, orig.mMine);
116
199
   }
117
199
   return *this;
118
199
}
119
120
HeaderFieldValue::~HeaderFieldValue()
121
2.98M
{
122
2.98M
  if (mMine)
123
1.72M
  {
124
1.72M
     delete[] mField;
125
1.72M
  }
126
2.98M
}
127
128
EncodeStream& 
129
HeaderFieldValue::encode(EncodeStream& str) const
130
0
{
131
0
   str.write(mField, mFieldLength);
132
0
   return str;
133
0
}
134
135
EncodeStream& resip::operator<<(EncodeStream& stream, HeaderFieldValue& hfv)
136
0
{
137
0
   hfv.encode(stream);
138
0
   return stream;
139
0
}
140
141
/* ====================================================================
142
 * The Vovida Software License, Version 1.0 
143
 * 
144
 * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
145
 * 
146
 * Redistribution and use in source and binary forms, with or without
147
 * modification, are permitted provided that the following conditions
148
 * are met:
149
 * 
150
 * 1. Redistributions of source code must retain the above copyright
151
 *    notice, this list of conditions and the following disclaimer.
152
 * 
153
 * 2. Redistributions in binary form must reproduce the above copyright
154
 *    notice, this list of conditions and the following disclaimer in
155
 *    the documentation and/or other materials provided with the
156
 *    distribution.
157
 * 
158
 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
159
 *    and "Vovida Open Communication Application Library (VOCAL)" must
160
 *    not be used to endorse or promote products derived from this
161
 *    software without prior written permission. For written
162
 *    permission, please contact vocal@vovida.org.
163
 *
164
 * 4. Products derived from this software may not be called "VOCAL", nor
165
 *    may "VOCAL" appear in their name, without prior written
166
 *    permission of Vovida Networks, Inc.
167
 * 
168
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
169
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
170
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
171
 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
172
 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
173
 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
174
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
175
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
176
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
177
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
178
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
179
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
180
 * DAMAGE.
181
 * 
182
 * ====================================================================
183
 * 
184
 * This software consists of voluntary contributions made by Vovida
185
 * Networks, Inc. and many individuals on behalf of Vovida Networks,
186
 * Inc.  For more information on Vovida Networks, Inc., please see
187
 * <http://www.vovida.org/>.
188
 *
189
 */