1
#ifndef RESIP_Contents_hxx
2
#define RESIP_Contents_hxx
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"
20
class HeaderFieldValue;
23
/** @brief MIME header identifier base class */
28
/** @brief Content-ID MIME header identifier class */
29
class H_ContentID : public MIME_Header
34
extern H_ContentID h_ContentID;
36
/** @brief Content-ID MIME header identifier class */
37
class H_ContentDescription : public MIME_Header
40
typedef StringCategory Type;
42
extern H_ContentDescription h_ContentDescription;
48
@brief Base class for all SIP body types. Lazily-parsed.
50
class Contents : public LazyParser
53
/// pass Mime instance for parameters
54
Contents(const HeaderFieldValue& headerFieldValue, const Mime& contentsType);
56
@brief Create a contents with a given mime type
57
@param contentsType the mime type of the contents
59
Contents(const Mime& contentsType);
61
@brief Copy constructor
62
@param rhs the Contents to be copied
64
Contents(const Contents& rhs);
67
@todo internal documentation
69
Contents(const Contents& rhs,HeaderFieldValue::CopyPaddingEnum e);
72
@todo internal documentation
74
Contents(const HeaderFieldValue& headerFieldValue,
75
HeaderFieldValue::CopyPaddingEnum e,
76
const Mime& contentsType);
79
@brief Assignment operator
80
@param rhs Contents object to be copied
81
@return a reference to a copy of rhs
83
Contents& operator=(const Contents& rhs);
85
@brief Preforms preparsing on the headers stored in the ParseBuffer pb
86
@param pb a ParseBuffer containing the headers to preparse
88
void preParseHeaders(ParseBuffer& pb);
90
@brief encodes headers to an output stream
91
@param str output stream destination for encoded headers
92
@return a reference to str
94
EncodeStream& encodeHeaders(EncodeStream& str) const;
97
@brief access to wrapped contents (signed, encrypted)
98
@return a pointer to self
100
virtual Contents* getContents() {return this;}
104
@todo - unimplemented - decide fate
106
Contents* getContents(const Mime&);
108
virtual Data getBodyData() const;
111
@brief returns a copy of a Contents object
113
virtual Contents* clone() const = 0;
115
@brief getter for mime type of message
116
@return the mime type of the message
118
const Mime& getType() const {return mType;}
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.
127
@sa ContentsFactoryBase
129
static Contents* createContents(const Mime& contentType,
130
const Data& contents);
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
136
bool exists(const HeaderBase& headerType) const;
138
@brief removes a header if it is present
139
@param headerType the header to remove
141
void remove(const HeaderBase& headerType);
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
147
bool exists(const MIME_Header& headerType) const;
149
@brief removes a MIME header if it is present
150
@param headerType the MIME header to remove
152
void remove(const MIME_Header& headerType);
154
// !dlb! break into const and non-const -- throw on const if not exists
155
// !dlb! requires a nested exception...
157
// shared header types
159
@brief returns the value of the Content-Type header
160
Throws an Contents::Exception if the header doesn't exist.
163
retval = contents.header(Headers::ContentType);
166
@return the Content-Type header value
168
const H_ContentType::Type& header(const H_ContentType& headerType) const;
170
@brief returns the value of the Content-Type header
173
retval = contents.header(Headers::ContentType);
176
@return the Content-Type header value
178
H_ContentType::Type& header(const H_ContentType& headerType);
181
@brief returns the value of the Content-Disposition header
182
Throws an Contents::Exception if the header doesn't exist.
184
retval = contents.header(Headers::ContentDisposition);
186
@return the Content-Disposition header value
188
const H_ContentDisposition::Type& header(const H_ContentDisposition& headerType) const;
190
@brief returns the value of the Content-Disposition header
192
retval = contents.header(Headers::ContentDisposition);
194
@return the Content-Disposition header value
196
H_ContentDisposition::Type& header(const H_ContentDisposition& headerType);
199
@brief returns the value of the Content-Transfer-Encoding header
200
Throws an Contents::Exception if the header doesn't exist.
202
retval = contents.header(Headers::ContentTransferEncoding);
204
@return the Content-Transfer-Encoding header value
206
const H_ContentTransferEncoding::Type& header(const H_ContentTransferEncoding& headerType) const;
208
@brief returns the value of the Content-Transfer-Encoding header
210
retval = contents.header(Headers::ContentTransferEncoding);
212
@return the Content-Transfer-Encoding header value
214
H_ContentTransferEncoding::Type& header(const H_ContentTransferEncoding& headerType);
217
@brief returns the value of the Content-Languages header
218
Throws an Contents::Exception if the header doesn't exist.
220
retval = contents.header(Headers::ContentLanguages);
222
@return the Content-Languages header value
224
const H_ContentLanguages::Type& header(const H_ContentLanguages& headerType) const;
226
@brief returns the value of the Content-Languages header
228
retval = contents.header(Headers::ContentLanguages);
230
@return the Content-Languages header value
232
H_ContentLanguages::Type& header(const H_ContentLanguages& headerType);
234
// MIME specific header types
236
@brief returns the value of the Content-ID MIME header
237
Throws an Contents::Exception if the header doesn't exist.
239
retval = contents.header(Headers::ContentId);
241
@return the Content-Id MIME header value
243
const H_ContentID::Type& header(const H_ContentID& headerType) const;
245
@brief returns the value of the Content-ID MIME header
247
retval = contents.header(Headers::ContentId);
249
@return the Content-Id MIME header value
251
H_ContentID::Type& header(const H_ContentID& headerType);
254
@brief returns the Content-Description MIME header
255
Throws an Contents::Exception if the header doesn't exist.
257
retval = contents.header(Headers::ContentDescription)
259
@return the Content-Description MIME header
261
const H_ContentDescription::Type& header(const H_ContentDescription& headerType) const;
263
@brief returns the Content-Description MIME header
265
retval = contents.header(Headers::ContentDescription)
267
@return the Content-Description MIME header
269
H_ContentDescription::Type& header(const H_ContentDescription& headerType);
272
@brief returns the major version of MIME used by the contents
273
@return MIME major version
275
int& version() {return mVersion;}
277
@brief returns the minor version of MIME used by the contents
278
@return MIME minor version
280
int& minorVersion() {return mMinorVersion;}
283
@todo - is this being used? -- is the buffer list being used as a list?
285
void addBuffer(char* buf);
291
@todo !bwc! Calls freeMem(), then reverts members to a default state
292
(including setting pointers to 0)
305
mTransferEncoding = 0;
314
void init(const Contents& orig);
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()
322
inline void freeMem()
325
delete mTransferEncoding;
331
for (std::vector<char*>::iterator i = mBufferList.begin();
332
i != mBufferList.end(); i++)
339
virtual const Data& errorContext() const;
344
H_ContentDisposition::Type *mDisposition;
346
H_ContentTransferEncoding::Type *mTransferEncoding;
348
H_ContentLanguages::Type *mLanguages;
352
H_ContentDescription::Type *mDescription;
354
StringCategory *mLength;
361
std::vector<char*> mBufferList;
368
/* ====================================================================
369
* The Vovida Software License, Version 1.0
371
* Copyright (c) 2000-2005
373
* Redistribution and use in source and binary forms, with or without
374
* modification, are permitted provided that the following conditions
377
* 1. Redistributions of source code must retain the above copyright
378
* notice, this list of conditions and the following disclaimer.
380
* 2. Redistributions in binary form must reproduce the above copyright
381
* notice, this list of conditions and the following disclaimer in
382
* the documentation and/or other materials provided with the
385
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
386
* and "Vovida Open Communication Application Library (VOCAL)" must
387
* not be used to endorse or promote products derived from this
388
* software without prior written permission. For written
389
* permission, please contact vocal@vovida.org.
391
* 4. Products derived from this software may not be called "VOCAL", nor
392
* may "VOCAL" appear in their name, without prior written
393
* permission of Vovida Networks, Inc.
395
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
396
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
397
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
398
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
399
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
400
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
401
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
402
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
403
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
404
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
405
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
406
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
409
* ====================================================================
411
* This software consists of voluntary contributions made by Vovida
412
* Networks, Inc. and many individuals on behalf of Vovida Networks,
413
* Inc. For more information on Vovida Networks, Inc., please see
414
* <http://www.vovida.org/>.