Coverage Report

Created: 2023-06-07 06:03

/src/resiprocate/rutil/DataStream.cxx
Line
Count
Source (jump to first uncovered line)
1
#ifdef HAVE_CONFIG_H
2
#include "config.h"
3
#endif
4
5
#include "rutil/ResipAssert.h"
6
#include "rutil/DataStream.hxx"
7
#include "rutil/Data.hxx"
8
9
// Remove warning about 'this' use in initiator list - pointer is only stored
10
#if defined(WIN32) && !defined(__GNUC__)
11
#pragma warning( disable : 4355 ) // using this in base member initializer list 
12
#endif
13
14
using namespace resip;
15
16
DataBuffer::DataBuffer(Data& str)
17
   : mStr(str)
18
85.7k
{
19
85.7k
#ifdef RESIP_USE_STL_STREAMS
20
85.7k
   char* gbuf = const_cast<char*>(mStr.mBuf);
21
85.7k
   setg(gbuf, gbuf, gbuf+mStr.size());
22
   // expose the excess capacity as the put buffer
23
85.7k
   setp(gbuf+mStr.mSize, gbuf+mStr.mCapacity);
24
85.7k
#endif
25
85.7k
}
26
27
DataBuffer::~DataBuffer()
28
85.7k
{}
29
30
#ifndef RESIP_USE_STL_STREAMS
31
uint64_t DataBuffer::tellpbuf(void)
32
{ 
33
   return mStr.size(); 
34
}
35
36
size_t DataBuffer::readbuf(char *buf, size_t count)
37
{
38
   if (count <= 0)
39
   {
40
      return 0;
41
   }
42
43
   if (!buf)
44
   {
45
      resip_assert(0);
46
      return 0;
47
   }
48
49
   size_t cursize = mStr.size();
50
51
   size_t toread = (cursize < count) ? (cursize) : (count);
52
53
   memcpy(buf,mStr.begin(),toread);
54
55
   //wow, not efficient.  Just added this function for repro, need to revisit. @TODO.
56
   mStr = mStr.substr(toread);
57
58
   return toread;
59
}
60
61
size_t DataBuffer::writebuf(const char *str, size_t count)
62
{
63
   if( count <= 0 )
64
   {
65
      return 0;
66
   }
67
68
   mStr.append(str,count);
69
   return count;
70
}
71
size_t DataBuffer::putbuf(char ch)
72
{
73
   mStr += ch;
74
75
   return 1;
76
}
77
#else
78
int
79
DataBuffer::sync()
80
255k
{
81
255k
   size_t len = pptr() - pbase();
82
255k
   if (len > 0)
83
170k
   {
84
170k
      size_t pos = gptr() - eback();  // remember the get position
85
170k
      mStr.mSize += len;
86
170k
      char* gbuf = const_cast<char*>(mStr.data());
87
      // reset the get buffer
88
170k
      setg(gbuf, gbuf+pos, gbuf+mStr.size());
89
      // reset the put buffer
90
170k
      setp(gbuf + mStr.mSize, gbuf + mStr.mCapacity);
91
170k
   }
92
255k
   return 0;
93
255k
}
94
95
int
96
DataBuffer::overflow(int c)
97
422k
{
98
   // sync, but reallocate
99
422k
   size_t len = pptr() - pbase();
100
   // .kw. test below is always true. Checked with David Butcher
101
   // and he says this is safe but perhaps performs unrequired
102
   // re-allocs.
103
422k
   if (len >= 0)
104
422k
   {
105
422k
      size_t pos = gptr() - eback();  // remember the get position
106
107
      // update the length
108
422k
      mStr.mSize += len;
109
110
      // resize the underlying Data and reset the input buffer
111
422k
      mStr.resize(((mStr.mCapacity+16)*3)/2, true);
112
113
422k
      char* gbuf = const_cast<char*>(mStr.mBuf);
114
      // reset the get buffer
115
422k
      setg(gbuf, gbuf+pos, gbuf+mStr.mSize);
116
      // reset the put buffer
117
422k
      setp(gbuf + mStr.mSize, gbuf + mStr.mCapacity);
118
422k
   }
119
422k
   if (c != -1)
120
422k
   {
121
422k
      mStr.mBuf[mStr.mSize] = c;
122
422k
      pbump(1);
123
422k
      return c;
124
422k
   }
125
0
   return 0;
126
422k
}
127
#endif
128
129
iDataStream::iDataStream(Data& str)
130
   : DataBuffer(str), 
131
     DecodeStream(this)
132
0
{
133
0
}
Unexecuted instantiation: resip::iDataStream::iDataStream(resip::Data&)
Unexecuted instantiation: resip::iDataStream::iDataStream(resip::Data&)
134
135
iDataStream::~iDataStream()
136
0
{}
137
138
oDataStream::oDataStream(Data& str)
139
   : DataBuffer(str), 
140
   EncodeStream(this)
141
716
{
142
   // don't call this with a read-only buffer!
143
716
   resip_assert(str.mShareEnum != Data::Share);
144
716
}
Unexecuted instantiation: resip::oDataStream::oDataStream(resip::Data&)
resip::oDataStream::oDataStream(resip::Data&)
Line
Count
Source
141
716
{
142
   // don't call this with a read-only buffer!
143
716
   resip_assert(str.mShareEnum != Data::Share);
144
716
}
145
146
oDataStream::~oDataStream()
147
716
{
148
716
   flush();
149
716
}
150
151
void
152
oDataStream::reset()
153
0
{
154
0
   flush();
155
0
   mStr.clear();
156
0
#ifdef RESIP_USE_STL_STREAMS
157
   // reset the underlying buffer state
158
0
   char* gbuf = const_cast<char*>(mStr.mBuf);
159
0
   setg(gbuf, gbuf, gbuf+mStr.size());
160
0
   setp(gbuf+mStr.mSize, gbuf+mStr.mCapacity);
161
0
#endif
162
0
}
163
164
DataStream::DataStream(Data& str)
165
   : DataBuffer(str), 
166
#ifdef  RESIP_USE_STL_STREAMS
167
     std::iostream(this)
168
#else
169
   ResipFastOStream(this)
170
#endif
171
85.0k
{
172
   // don't call this with a read-only buffer!
173
85.0k
   resip_assert(str.mShareEnum != Data::Share);
174
85.0k
}
Unexecuted instantiation: resip::DataStream::DataStream(resip::Data&)
resip::DataStream::DataStream(resip::Data&)
Line
Count
Source
171
85.0k
{
172
   // don't call this with a read-only buffer!
173
85.0k
   resip_assert(str.mShareEnum != Data::Share);
174
85.0k
}
175
176
DataStream::~DataStream()
177
85.0k
{
178
85.0k
   flush();
179
85.0k
}
180
181
/* ====================================================================
182
 * The Vovida Software License, Version 1.0
183
 *
184
 * Copyright 2000-2005
185
 *
186
 * Redistribution and use in source and binary forms, with or without
187
 * modification, are permitted provided that the following conditions
188
 * are met:
189
 *
190
 * 1. Redistributions of source code must retain the above copyright
191
 *    notice, this list of conditions and the following disclaimer.
192
 *
193
 * 2. Redistributions in binary form must reproduce the above copyright
194
 *    notice, this list of conditions and the following disclaimer in
195
 *    the documentation and/or other materials provided with the
196
 *    distribution.
197
 *
198
 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
199
 *    and "Vovida Open Communication Application Library (VOCAL)" must
200
 *    not be used to endorse or promote products derived from this
201
 *    software without prior written permission. For written
202
 *    permission, please contact vocal@vovida.org.
203
 *
204
 * 4. Products derived from this software may not be called "VOCAL", nor
205
 *    may "VOCAL" appear in their name, without prior written
206
 *    permission of Vovida Networks, Inc.
207
 * 
208
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
209
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
210
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
211
 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
212
 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
213
 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
214
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
215
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
216
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
217
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
218
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
219
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
220
 * DAMAGE.
221
 * 
222
 * ====================================================================
223
 * 
224
 * This software consists of voluntary contributions made by Vovida
225
 * Networks, Inc. and many individuals on behalf of Vovida Networks,
226
 * Inc.  For more information on Vovida Networks, Inc., please see
227
 * <http://www.vovida.org/>.
228
 *
229
 */