reSIProcate/stack  9694
Contents.hxx
Go to the documentation of this file.
00001 #ifndef RESIP_Contents_hxx
00002 #define RESIP_Contents_hxx
00003 
00004 #include <iosfwd>
00005 #include <vector>
00006 
00007 #include "resip/stack/LazyParser.hxx"
00008 #include "resip/stack/Mime.hxx"
00009 #include "resip/stack/StringCategory.hxx"
00010 #include "resip/stack/Headers.hxx"
00011 #include "resip/stack/HeaderFieldValue.hxx"
00012 #include "rutil/Data.hxx"
00013 #include "resip/stack/ContentsFactory.hxx"
00014 
00015 namespace resip
00016 {
00017 
00018 class Token;
00019 class Contents;
00020 class HeaderFieldValue;
00021 class ParseBuffer;
00022 
00024 class MIME_Header
00025 {
00026 };
00027 
00029 class H_ContentID : public MIME_Header
00030 {
00031    public:
00032       typedef Token Type;
00033 };
00034 extern H_ContentID h_ContentID;
00035 
00037 class H_ContentDescription : public MIME_Header
00038 {
00039    public:
00040       typedef StringCategory Type;
00041 };
00042 extern H_ContentDescription h_ContentDescription;
00043       
00044 
00050 class Contents : public LazyParser
00051 {
00052    public:
00054       Contents(const HeaderFieldValue& headerFieldValue, const Mime& contentsType);
00059       Contents(const Mime& contentsType);
00064       Contents(const Contents& rhs);
00069       Contents(const Contents& rhs,HeaderFieldValue::CopyPaddingEnum e);
00074       Contents(const HeaderFieldValue& headerFieldValue,
00075                HeaderFieldValue::CopyPaddingEnum e,
00076                const Mime& contentsType);
00077       virtual ~Contents();
00083       Contents& operator=(const Contents& rhs);
00088       void preParseHeaders(ParseBuffer& pb);
00094       EncodeStream& encodeHeaders(EncodeStream& str) const;
00095 
00100       virtual Contents* getContents() {return this;}
00101 
00106       Contents* getContents(const Mime&);
00107 
00108       virtual Data getBodyData() const;
00109 
00113       virtual Contents* clone() const = 0;
00118       const Mime& getType() const {return mType;}
00129       static Contents* createContents(const Mime& contentType, 
00130                                       const Data& contents);
00136       bool exists(const HeaderBase& headerType) const;
00141       void remove(const HeaderBase& headerType);
00147       bool exists(const MIME_Header& headerType) const;
00152       void remove(const MIME_Header& headerType);
00153 
00154       // !dlb! break into const and non-const -- throw on const if not exists
00155       // !dlb! requires a nested exception...
00156 
00157       // shared header types
00168       const H_ContentType::Type& header(const H_ContentType& headerType) const;
00178       H_ContentType::Type& header(const H_ContentType& headerType);
00179 
00188       const H_ContentDisposition::Type& header(const H_ContentDisposition& headerType) const;
00196       H_ContentDisposition::Type& header(const H_ContentDisposition& headerType);
00197 
00206       const H_ContentTransferEncoding::Type& header(const H_ContentTransferEncoding& headerType) const;
00214       H_ContentTransferEncoding::Type& header(const H_ContentTransferEncoding& headerType);
00215 
00224       const H_ContentLanguages::Type& header(const H_ContentLanguages& headerType) const;
00232       H_ContentLanguages::Type& header(const H_ContentLanguages& headerType);
00233 
00234       // MIME specific header types
00243       const H_ContentID::Type& header(const H_ContentID& headerType) const;
00251       H_ContentID::Type& header(const H_ContentID& headerType);
00252 
00261       const H_ContentDescription::Type& header(const H_ContentDescription& headerType) const;
00269       H_ContentDescription::Type& header(const H_ContentDescription& headerType);
00270 
00275       int& version() {return mVersion;}
00280       int& minorVersion() {return mMinorVersion;}
00285       void addBuffer(char* buf);
00286 
00287    protected:
00288 
00294       inline void clear()
00295       {
00296          freeMem();
00297          init();
00298       }
00299       
00301       inline void init()
00302       {
00303          mBufferList.clear();
00304          mDisposition = 0;
00305          mTransferEncoding = 0;
00306          mLanguages = 0;
00307          mId = 0;
00308          mDescription = 0;
00309          mLength = 0;
00310          mVersion = 1;
00311          mMinorVersion = 0;
00312       }
00314       void init(const Contents& orig);
00315 
00316       // !bwc! Just frees up heap-allocated stuff, doesn't set pointers to 0
00317       // This exists because it is pointless (and inefficient) to revert 
00318       // members to a default state while deleting (they're just going to go
00319       // out of scope anyway) The d'tor is the only thing that uses this by
00320       // itself. Everything else should use clear()
00322       inline void freeMem()
00323       {
00324          delete mDisposition;
00325          delete mTransferEncoding;
00326          delete mLanguages;
00327          delete mId;
00328          delete mDescription;
00329          delete mLength;
00330 
00331          for (std::vector<char*>::iterator i = mBufferList.begin();
00332               i != mBufferList.end(); i++)
00333          {
00334             delete [] *i;
00335          }
00336 
00337       }
00339       virtual const Data& errorContext() const;
00340 
00342       Mime mType;
00344       H_ContentDisposition::Type *mDisposition;
00346       H_ContentTransferEncoding::Type *mTransferEncoding;
00348       H_ContentLanguages::Type *mLanguages;
00350       Token *mId;
00352       H_ContentDescription::Type *mDescription;
00354       StringCategory *mLength;
00355       
00357       int mVersion;
00359       int mMinorVersion;
00360 
00361       std::vector<char*> mBufferList;
00362 };
00363 
00364 }
00365 
00366 #endif
00367 
00368 /* ====================================================================
00369  * The Vovida Software License, Version 1.0 
00370  * 
00371  * Copyright (c) 2000-2005
00372  * 
00373  * Redistribution and use in source and binary forms, with or without
00374  * modification, are permitted provided that the following conditions
00375  * are met:
00376  * 
00377  * 1. Redistributions of source code must retain the above copyright
00378  *    notice, this list of conditions and the following disclaimer.
00379  * 
00380  * 2. Redistributions in binary form must reproduce the above copyright
00381  *    notice, this list of conditions and the following disclaimer in
00382  *    the documentation and/or other materials provided with the
00383  *    distribution.
00384  * 
00385  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00386  *    and "Vovida Open Communication Application Library (VOCAL)" must
00387  *    not be used to endorse or promote products derived from this
00388  *    software without prior written permission. For written
00389  *    permission, please contact vocal@vovida.org.
00390  *
00391  * 4. Products derived from this software may not be called "VOCAL", nor
00392  *    may "VOCAL" appear in their name, without prior written
00393  *    permission of Vovida Networks, Inc.
00394  * 
00395  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00396  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00397  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00398  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00399  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00400  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00401  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00402  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00403  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00404  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00405  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00406  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00407  * DAMAGE.
00408  * 
00409  * ====================================================================
00410  * 
00411  * This software consists of voluntary contributions made by Vovida
00412  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00413  * Inc.  For more information on Vovida Networks, Inc., please see
00414  * <http://www.vovida.org/>.
00415  *
00416  */