/src/resiprocate/resip/stack/Contents.hxx
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef RESIP_Contents_hxx |
2 | | #define RESIP_Contents_hxx |
3 | | |
4 | | #include <iosfwd> |
5 | | #include <vector> |
6 | | |
7 | | #include "resip/stack/LazyParser.hxx" |
8 | | #include "resip/stack/Mime.hxx" |
9 | | #include "resip/stack/StringCategory.hxx" |
10 | | #include "resip/stack/Headers.hxx" |
11 | | #include "resip/stack/HeaderFieldValue.hxx" |
12 | | #include "rutil/Data.hxx" |
13 | | #include "resip/stack/ContentsFactory.hxx" |
14 | | |
15 | | namespace resip |
16 | | { |
17 | | |
18 | | class Token; |
19 | | class Contents; |
20 | | class HeaderFieldValue; |
21 | | class ParseBuffer; |
22 | | |
23 | | /** @brief MIME header identifier base class */ |
24 | | class MIME_Header |
25 | | { |
26 | | }; |
27 | | |
28 | | /** @brief Content-ID MIME header identifier class */ |
29 | | class H_ContentID : public MIME_Header |
30 | | { |
31 | | public: |
32 | | typedef Token Type; |
33 | | }; |
34 | | extern H_ContentID h_ContentID; |
35 | | |
36 | | /** @brief Content-ID MIME header identifier class */ |
37 | | class H_ContentDescription : public MIME_Header |
38 | | { |
39 | | public: |
40 | | typedef StringCategory Type; |
41 | | }; |
42 | | extern H_ContentDescription h_ContentDescription; |
43 | | |
44 | | |
45 | | /** |
46 | | @ingroup resip_crit |
47 | | @ingroup sip_payload |
48 | | @brief Base class for all SIP body types. Lazily-parsed. |
49 | | */ |
50 | | class Contents : public LazyParser |
51 | | { |
52 | | public: |
53 | | /// pass Mime instance for parameters |
54 | | Contents(const HeaderFieldValue& headerFieldValue, const Mime& contentsType); |
55 | | /** |
56 | | @brief Create a contents with a given mime type |
57 | | @param contentsType the mime type of the contents |
58 | | */ |
59 | | Contents(const Mime& contentsType); |
60 | | /** |
61 | | @brief Copy constructor |
62 | | @param rhs the Contents to be copied |
63 | | */ |
64 | | Contents(const Contents& rhs); |
65 | | /** |
66 | | @internal |
67 | | @todo internal documentation |
68 | | */ |
69 | | Contents(const Contents& rhs,HeaderFieldValue::CopyPaddingEnum e); |
70 | | /** |
71 | | @internal |
72 | | @todo internal documentation |
73 | | */ |
74 | | Contents(const HeaderFieldValue& headerFieldValue, |
75 | | HeaderFieldValue::CopyPaddingEnum e, |
76 | | const Mime& contentsType); |
77 | | virtual ~Contents(); |
78 | | /** |
79 | | @brief Assignment operator |
80 | | @param rhs Contents object to be copied |
81 | | @return a reference to a copy of rhs |
82 | | */ |
83 | | Contents& operator=(const Contents& rhs); |
84 | | /** |
85 | | @brief Preforms preparsing on the headers stored in the ParseBuffer pb |
86 | | @param pb a ParseBuffer containing the headers to preparse |
87 | | */ |
88 | | void preParseHeaders(ParseBuffer& pb); |
89 | | /** |
90 | | @brief encodes headers to an output stream |
91 | | @param str output stream destination for encoded headers |
92 | | @return a reference to str |
93 | | */ |
94 | | EncodeStream& encodeHeaders(EncodeStream& str) const; |
95 | | |
96 | | /** |
97 | | @brief access to wrapped contents (signed, encrypted) |
98 | | @return a pointer to self |
99 | | */ |
100 | 0 | virtual Contents* getContents() {return this;} |
101 | | |
102 | | /** |
103 | | @internal |
104 | | @todo - unimplemented - decide fate |
105 | | */ |
106 | | Contents* getContents(const Mime&); |
107 | | |
108 | | virtual Data getBodyData() const; |
109 | | |
110 | | /** |
111 | | @brief returns a copy of a Contents object |
112 | | */ |
113 | | virtual Contents* clone() const = 0; |
114 | | /** |
115 | | @brief getter for mime type of message |
116 | | @return the mime type of the message |
117 | | */ |
118 | 0 | const Mime& getType() const {return mType;} |
119 | | /** |
120 | | @brief factory method to create a Contents object from a mime type and a payload |
121 | | @param contentType the mime type of the contents |
122 | | @param contents the contents |
123 | | @return a instance of a Contents subclass appropriate to the mime type |
124 | | @note If no registered Contents subclass has been registered with the factory |
125 | | an instance of OctetContents is returned. |
126 | | @sa ContentsFactory |
127 | | @sa ContentsFactoryBase |
128 | | */ |
129 | | static Contents* createContents(const Mime& contentType, |
130 | | const Data& contents); |
131 | | /** |
132 | | @brief checks to see if a header is present |
133 | | @param headerType the header to check for |
134 | | @return true if that header exists and false otherwise |
135 | | */ |
136 | | bool exists(const HeaderBase& headerType) const; |
137 | | /** |
138 | | @brief removes a header if it is present |
139 | | @param headerType the header to remove |
140 | | */ |
141 | | void remove(const HeaderBase& headerType); |
142 | | /** |
143 | | @brief checks to see if a MIME header exists |
144 | | @param headerType the MIME header to check for |
145 | | @return true if the header exists and false otherwise |
146 | | */ |
147 | | bool exists(const MIME_Header& headerType) const; |
148 | | /** |
149 | | @brief removes a MIME header if it is present |
150 | | @param headerType the MIME header to remove |
151 | | */ |
152 | | void remove(const MIME_Header& headerType); |
153 | | |
154 | | // !dlb! break into const and non-const -- throw on const if not exists |
155 | | // !dlb! requires a nested exception... |
156 | | |
157 | | // shared header types |
158 | | /** |
159 | | @brief returns the value of the Content-Type header |
160 | | Throws an Contents::Exception if the header doesn't exist. |
161 | | |
162 | | @code |
163 | | retval = contents.header(Headers::ContentType); |
164 | | @endcode |
165 | | |
166 | | @return the Content-Type header value |
167 | | */ |
168 | | const H_ContentType::Type& header(const H_ContentType& headerType) const; |
169 | | /** |
170 | | @brief returns the value of the Content-Type header |
171 | | |
172 | | @code |
173 | | retval = contents.header(Headers::ContentType); |
174 | | @endcode |
175 | | |
176 | | @return the Content-Type header value |
177 | | */ |
178 | | H_ContentType::Type& header(const H_ContentType& headerType); |
179 | | |
180 | | /** |
181 | | @brief returns the value of the Content-Disposition header |
182 | | Throws an Contents::Exception if the header doesn't exist. |
183 | | @code |
184 | | retval = contents.header(Headers::ContentDisposition); |
185 | | @endcode |
186 | | @return the Content-Disposition header value |
187 | | */ |
188 | | const H_ContentDisposition::Type& header(const H_ContentDisposition& headerType) const; |
189 | | /** |
190 | | @brief returns the value of the Content-Disposition header |
191 | | @code |
192 | | retval = contents.header(Headers::ContentDisposition); |
193 | | @endcode |
194 | | @return the Content-Disposition header value |
195 | | */ |
196 | | H_ContentDisposition::Type& header(const H_ContentDisposition& headerType); |
197 | | |
198 | | /** |
199 | | @brief returns the value of the Content-Transfer-Encoding header |
200 | | Throws an Contents::Exception if the header doesn't exist. |
201 | | @code |
202 | | retval = contents.header(Headers::ContentTransferEncoding); |
203 | | @endcode |
204 | | @return the Content-Transfer-Encoding header value |
205 | | */ |
206 | | const H_ContentTransferEncoding::Type& header(const H_ContentTransferEncoding& headerType) const; |
207 | | /** |
208 | | @brief returns the value of the Content-Transfer-Encoding header |
209 | | @code |
210 | | retval = contents.header(Headers::ContentTransferEncoding); |
211 | | @endcode |
212 | | @return the Content-Transfer-Encoding header value |
213 | | */ |
214 | | H_ContentTransferEncoding::Type& header(const H_ContentTransferEncoding& headerType); |
215 | | |
216 | | /** |
217 | | @brief returns the value of the Content-Languages header |
218 | | Throws an Contents::Exception if the header doesn't exist. |
219 | | @code |
220 | | retval = contents.header(Headers::ContentLanguages); |
221 | | @endcode |
222 | | @return the Content-Languages header value |
223 | | */ |
224 | | const H_ContentLanguages::Type& header(const H_ContentLanguages& headerType) const; |
225 | | /** |
226 | | @brief returns the value of the Content-Languages header |
227 | | @code |
228 | | retval = contents.header(Headers::ContentLanguages); |
229 | | @endcode |
230 | | @return the Content-Languages header value |
231 | | */ |
232 | | H_ContentLanguages::Type& header(const H_ContentLanguages& headerType); |
233 | | |
234 | | // MIME specific header types |
235 | | /** |
236 | | @brief returns the value of the Content-ID MIME header |
237 | | Throws an Contents::Exception if the header doesn't exist. |
238 | | @code |
239 | | retval = contents.header(Headers::ContentId); |
240 | | @endcode |
241 | | @return the Content-Id MIME header value |
242 | | */ |
243 | | const H_ContentID::Type& header(const H_ContentID& headerType) const; |
244 | | /** |
245 | | @brief returns the value of the Content-ID MIME header |
246 | | @code |
247 | | retval = contents.header(Headers::ContentId); |
248 | | @endcode |
249 | | @return the Content-Id MIME header value |
250 | | */ |
251 | | H_ContentID::Type& header(const H_ContentID& headerType); |
252 | | |
253 | | /** |
254 | | @brief returns the Content-Description MIME header |
255 | | Throws an Contents::Exception if the header doesn't exist. |
256 | | @code |
257 | | retval = contents.header(Headers::ContentDescription) |
258 | | @endcode |
259 | | @return the Content-Description MIME header |
260 | | */ |
261 | | const H_ContentDescription::Type& header(const H_ContentDescription& headerType) const; |
262 | | /** |
263 | | @brief returns the Content-Description MIME header |
264 | | @code |
265 | | retval = contents.header(Headers::ContentDescription) |
266 | | @endcode |
267 | | @return the Content-Description MIME header |
268 | | */ |
269 | | H_ContentDescription::Type& header(const H_ContentDescription& headerType); |
270 | | |
271 | | /** |
272 | | @brief returns the major version of MIME used by the contents |
273 | | @return MIME major version |
274 | | */ |
275 | 0 | int& version() {return mVersion;} |
276 | | /** |
277 | | @brief returns the minor version of MIME used by the contents |
278 | | @return MIME minor version |
279 | | */ |
280 | 0 | int& minorVersion() {return mMinorVersion;} |
281 | | /** |
282 | | @internal |
283 | | @todo - is this being used? -- is the buffer list being used as a list? |
284 | | */ |
285 | | void addBuffer(char* buf); |
286 | | |
287 | | protected: |
288 | | |
289 | | /** |
290 | | @internal |
291 | | @todo !bwc! Calls freeMem(), then reverts members to a default state |
292 | | (including setting pointers to 0) |
293 | | */ |
294 | | inline void clear() |
295 | 0 | { |
296 | 0 | freeMem(); |
297 | 0 | init(); |
298 | 0 | } |
299 | | |
300 | | /** @internal */ |
301 | | inline void init() |
302 | 68.6k | { |
303 | 68.6k | mBufferList.clear(); |
304 | 68.6k | mDisposition = 0; |
305 | 68.6k | mTransferEncoding = 0; |
306 | 68.6k | mLanguages = 0; |
307 | 68.6k | mId = 0; |
308 | 68.6k | mDescription = 0; |
309 | 68.6k | mLength = 0; |
310 | 68.6k | mVersion = 1; |
311 | 68.6k | mMinorVersion = 0; |
312 | 68.6k | } |
313 | | /** @internal */ |
314 | | void init(const Contents& orig); |
315 | | |
316 | | // !bwc! Just frees up heap-allocated stuff, doesn't set pointers to 0 |
317 | | // This exists because it is pointless (and inefficient) to revert |
318 | | // members to a default state while deleting (they're just going to go |
319 | | // out of scope anyway) The d'tor is the only thing that uses this by |
320 | | // itself. Everything else should use clear() |
321 | | /** @internal */ |
322 | | inline void freeMem() |
323 | 68.6k | { |
324 | 68.6k | delete mDisposition; |
325 | 68.6k | delete mTransferEncoding; |
326 | 68.6k | delete mLanguages; |
327 | 68.6k | delete mId; |
328 | 68.6k | delete mDescription; |
329 | 68.6k | delete mLength; |
330 | | |
331 | 68.6k | for (std::vector<char*>::iterator i = mBufferList.begin(); |
332 | 68.6k | i != mBufferList.end(); i++) |
333 | 0 | { |
334 | 0 | delete [] *i; |
335 | 0 | } |
336 | | |
337 | 68.6k | } |
338 | | /** @internal */ |
339 | | virtual const Data& errorContext() const; |
340 | | |
341 | | /** @internal */ |
342 | | Mime mType; |
343 | | /** @internal */ |
344 | | H_ContentDisposition::Type *mDisposition; |
345 | | /** @internal */ |
346 | | H_ContentTransferEncoding::Type *mTransferEncoding; |
347 | | /** @internal */ |
348 | | H_ContentLanguages::Type *mLanguages; |
349 | | /** @internal */ |
350 | | Token *mId; |
351 | | /** @internal */ |
352 | | H_ContentDescription::Type *mDescription; |
353 | | /** @internal */ |
354 | | StringCategory *mLength; |
355 | | |
356 | | /** @internal */ |
357 | | int mVersion; |
358 | | /** @internal */ |
359 | | int mMinorVersion; |
360 | | |
361 | | std::vector<char*> mBufferList; |
362 | | }; |
363 | | |
364 | | bool operator==(const Contents& lhs, const Contents& rhs); |
365 | | bool operator!=(const Contents& lhs, const Contents& rhs); |
366 | | |
367 | | } |
368 | | |
369 | | #endif |
370 | | |
371 | | /* ==================================================================== |
372 | | * The Vovida Software License, Version 1.0 |
373 | | * |
374 | | * Copyright (c) 2000-2005 |
375 | | * |
376 | | * Redistribution and use in source and binary forms, with or without |
377 | | * modification, are permitted provided that the following conditions |
378 | | * are met: |
379 | | * |
380 | | * 1. Redistributions of source code must retain the above copyright |
381 | | * notice, this list of conditions and the following disclaimer. |
382 | | * |
383 | | * 2. Redistributions in binary form must reproduce the above copyright |
384 | | * notice, this list of conditions and the following disclaimer in |
385 | | * the documentation and/or other materials provided with the |
386 | | * distribution. |
387 | | * |
388 | | * 3. The names "VOCAL", "Vovida Open Communication Application Library", |
389 | | * and "Vovida Open Communication Application Library (VOCAL)" must |
390 | | * not be used to endorse or promote products derived from this |
391 | | * software without prior written permission. For written |
392 | | * permission, please contact vocal@vovida.org. |
393 | | * |
394 | | * 4. Products derived from this software may not be called "VOCAL", nor |
395 | | * may "VOCAL" appear in their name, without prior written |
396 | | * permission of Vovida Networks, Inc. |
397 | | * |
398 | | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
399 | | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
400 | | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND |
401 | | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA |
402 | | * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES |
403 | | * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, |
404 | | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
405 | | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
406 | | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
407 | | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
408 | | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
409 | | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
410 | | * DAMAGE. |
411 | | * |
412 | | * ==================================================================== |
413 | | * |
414 | | * This software consists of voluntary contributions made by Vovida |
415 | | * Networks, Inc. and many individuals on behalf of Vovida Networks, |
416 | | * Inc. For more information on Vovida Networks, Inc., please see |
417 | | * <http://www.vovida.org/>. |
418 | | * |
419 | | */ |