~ubuntu-branches/ubuntu/saucy/resiprocate/saucy-proposed

« back to all changes in this revision

Viewing changes to resip/stack/Contents.hxx

  • Committer: Package Import Robot
  • Author(s): Daniel Pocock
  • Date: 2012-05-17 19:29:59 UTC
  • Revision ID: package-import@ubuntu.com-20120517192959-vv00m77isztdy64q
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
      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
      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
      int& version() {return mVersion;}
 
276
      /**
 
277
        @brief returns the minor version of MIME used by the contents
 
278
        @return MIME minor version
 
279
      */
 
280
      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
      {
 
296
         freeMem();
 
297
         init();
 
298
      }
 
299
      
 
300
      /** @internal */
 
301
      inline void init()
 
302
      {
 
303
         mBufferList.clear();
 
304
         mDisposition = 0;
 
305
         mTransferEncoding = 0;
 
306
         mLanguages = 0;
 
307
         mId = 0;
 
308
         mDescription = 0;
 
309
         mLength = 0;
 
310
         mVersion = 1;
 
311
         mMinorVersion = 0;
 
312
      }
 
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
      {
 
324
         delete mDisposition;
 
325
         delete mTransferEncoding;
 
326
         delete mLanguages;
 
327
         delete mId;
 
328
         delete mDescription;
 
329
         delete mLength;
 
330
 
 
331
         for (std::vector<char*>::iterator i = mBufferList.begin();
 
332
              i != mBufferList.end(); i++)
 
333
         {
 
334
            delete [] *i;
 
335
         }
 
336
 
 
337
      }
 
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
}
 
365
 
 
366
#endif
 
367
 
 
368
/* ====================================================================
 
369
 * The Vovida Software License, Version 1.0 
 
370
 * 
 
371
 * Copyright (c) 2000-2005
 
372
 * 
 
373
 * Redistribution and use in source and binary forms, with or without
 
374
 * modification, are permitted provided that the following conditions
 
375
 * are met:
 
376
 * 
 
377
 * 1. Redistributions of source code must retain the above copyright
 
378
 *    notice, this list of conditions and the following disclaimer.
 
379
 * 
 
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
 
383
 *    distribution.
 
384
 * 
 
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.
 
390
 *
 
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.
 
394
 * 
 
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
 
407
 * DAMAGE.
 
408
 * 
 
409
 * ====================================================================
 
410
 * 
 
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/>.
 
415
 *
 
416
 */