Coverage Report

Created: 2024-07-23 06:39

/src/resiprocate/resip/stack/HeaderFieldValueList.hxx
Line
Count
Source (jump to first uncovered line)
1
#if !defined(RESIP_HEADERFIELDVALUELIST_HXX)
2
#define RESIP_HEADERFIELDVALUELIST_HXX 
3
4
#include <iosfwd>
5
#include <vector>
6
7
#include "rutil/StlPoolAllocator.hxx"
8
#include "rutil/PoolBase.hxx"
9
10
namespace resip
11
{
12
13
class Data;
14
class ParserContainerBase;
15
class HeaderFieldValue;
16
17
/**
18
   @internal
19
20
   A HeaderFieldValueList contains a ParserContainer (after parsing occurs) or may only contain
21
   a vector of unparsed headers (if parsing hasn't occurred).  Depending on how the SipMessage was
22
   constructured, it's possible a HeaderFieldValueList doesn't contain any information in the 
23
   mHeaders vector, and all the data is stored solely in the ParserContainer.  If a ParserContainer
24
   is set, then it must be used for all future encoding.  Looking for null (or not) from 
25
   getParserContainer can be used to see which storage mechanism is being used.
26
27
   Most methods on this class deal with manipulation of the header vector (ie: empty, size, clear,
28
   push_back, pop_back, iterator, etc.).
29
30
   The encode method will either use the ParserContainer to encode (if set), or will encode from the
31
   header vector otherwise.
32
33
   In order to query all the raw header values regardless of their storage format use the 
34
   getNumHeaderValues and getHeaderValueByIndex methods as follows:
35
36
   for(size_t i = 0; i < hfvl->getNumHeaderValues(); i++)
37
   {
38
      Data headerValue;
39
      hfvl->getHeaderValueByIndex(i, headerValue);
40
      ....
41
   }
42
*/
43
class HeaderFieldValueList
44
{
45
   public:
46
      static const HeaderFieldValueList Empty;
47
48
      HeaderFieldValueList()
49
         : mHeaders(), 
50
           mPool(0),
51
           mParserContainer(0)
52
2
      {}
53
54
      HeaderFieldValueList(PoolBase& pool)
55
         : mHeaders(StlPoolAllocator<HeaderFieldValue, PoolBase>(&pool)),
56
           mPool(&pool),
57
           mParserContainer(0)
58
21.9k
      {}
59
60
      ~HeaderFieldValueList();
61
      HeaderFieldValueList(const HeaderFieldValueList& rhs);
62
      HeaderFieldValueList(const HeaderFieldValueList& rhs, PoolBase& pool);
63
      HeaderFieldValueList& operator=(const HeaderFieldValueList& rhs);
64
      
65
219
      inline void setParserContainer(ParserContainerBase* parser) {mParserContainer = parser;}
66
45.4k
      inline ParserContainerBase* getParserContainer() const {return mParserContainer;}
67
68
      EncodeStream& encode(int headerEnum, EncodeStream& str) const;
69
      EncodeStream& encode(const Data& headerName, EncodeStream& str) const;
70
      EncodeStream& encodeEmbedded(const Data& headerName, EncodeStream& str) const;
71
72
169k
      bool empty() const {return mHeaders.empty();}
73
219
      size_t size() const {return mHeaders.size();}
74
      void clear();
75
      //void push_front(HeaderFieldValue* header) {mHeaders.push_front(header);}
76
77
      /**
78
         READ THIS CAREFULLY BEFORE USING THIS FUNCTION
79
         @param own Specifies whether the created HeaderFieldValue will take 
80
            ownership of the buffer passed. This will never make a copy 
81
            of the buffer; if own==false, the HeaderFieldValue will retain the 
82
            same reference that it would if own==true. The only difference is 
83
            that if own==false, the buffer will not be deleted when the 
84
            HeaderFieldValue goes away/releases its reference, while if 
85
            own==true the buffer will be deleted. This means that no matter what 
86
            you pass for this param, you must ensure that the buffer is not 
87
            deleted during the lifetime of this HeaderFieldValueList.
88
      */
89
      void push_back(const char* buffer, size_t length, bool own) 
90
944k
      {
91
944k
         mHeaders.push_back(HeaderFieldValue::Empty); 
92
944k
         mHeaders.back().init(buffer,length,own);
93
944k
      }
94
95
      //void pop_front() {mHeaders.pop_front();}
96
0
      void pop_back() {mHeaders.pop_back();};
97
0
      HeaderFieldValue* front() {return &mHeaders.front();}
98
0
      HeaderFieldValue* back() {return &mHeaders.back();}
99
0
      const HeaderFieldValue* front() const {return &mHeaders.front();}
100
0
      const HeaderFieldValue* back() const {return &mHeaders.back();}
101
102
      inline void reserve(size_t size)
103
0
      {
104
0
         mHeaders.reserve(size);
105
0
      }
106
107
      bool parsedEmpty() const;
108
109
      size_t getNumHeaderValues() const;
110
      bool getHeaderValueByIndex(size_t index, Data& headerValue) const;
111
112
   private:
113
      typedef std::vector<HeaderFieldValue, StlPoolAllocator<HeaderFieldValue, PoolBase > >  ListImpl;
114
   public:
115
      typedef ListImpl::iterator iterator;
116
      typedef ListImpl::const_iterator const_iterator;
117
118
219
      iterator begin() {return mHeaders.begin();}
119
438
      iterator end() {return mHeaders.end();}
120
0
      const_iterator begin() const {return mHeaders.begin();}
121
0
      const_iterator end() const {return mHeaders.end();}
122
123
   private:
124
      ListImpl mHeaders;
125
      PoolBase* mPool;
126
      ParserContainerBase* mParserContainer;
127
128
      void freeParserContainer();
129
};
130
131
}
132
133
#endif
134
135
/* ====================================================================
136
 * The Vovida Software License, Version 1.0 
137
 * 
138
 * Copyright (c) 2023 SIP Spectrum, Inc. www.sipspectrum.com
139
 * Copyright (c) 2000 Vovida Networks, Inc.  
140
 * All rights reserved.
141
 * 
142
 * Redistribution and use in source and binary forms, with or without
143
 * modification, are permitted provided that the following conditions
144
 * are met:
145
 * 
146
 * 1. Redistributions of source code must retain the above copyright
147
 *    notice, this list of conditions and the following disclaimer.
148
 * 
149
 * 2. Redistributions in binary form must reproduce the above copyright
150
 *    notice, this list of conditions and the following disclaimer in
151
 *    the documentation and/or other materials provided with the
152
 *    distribution.
153
 * 
154
 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
155
 *    and "Vovida Open Communication Application Library (VOCAL)" must
156
 *    not be used to endorse or promote products derived from this
157
 *    software without prior written permission. For written
158
 *    permission, please contact vocal@vovida.org.
159
 *
160
 * 4. Products derived from this software may not be called "VOCAL", nor
161
 *    may "VOCAL" appear in their name, without prior written
162
 *    permission of Vovida Networks, Inc.
163
 * 
164
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
165
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
166
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
167
 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
168
 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
169
 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
170
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
171
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
172
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
173
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
174
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
175
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
176
 * DAMAGE.
177
 * 
178
 * ====================================================================
179
 * 
180
 * This software consists of voluntary contributions made by Vovida
181
 * Networks, Inc. and many individuals on behalf of Vovida Networks,
182
 * Inc.  For more information on Vovida Networks, Inc., please see
183
 * <http://www.vovida.org/>.
184
 *
185
 */