/[resiprocate]/branches/b-identity-0505/Contents.hxx
ViewVC logotype

Contents of /branches/b-identity-0505/Contents.hxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4598 - (show annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 6 months ago) by derek
File size: 6984 byte(s)
set svn:eol-style to LF
1 #if !defined(RESIP_CONTENTS_HXX)
2 #define RESIP_CONTENTS_HXX
3
4 #include <iosfwd>
5
6 #include "resiprocate/LazyParser.hxx"
7 #include "resiprocate/Mime.hxx"
8 #include "resiprocate/Token.hxx"
9 #include "resiprocate/StringCategory.hxx"
10 #include "resiprocate/Headers.hxx"
11 #include "resiprocate/HeaderFieldValue.hxx"
12 #include "resiprocate/os/Data.hxx"
13 #include "resiprocate/os/HashMap.hxx"
14
15 namespace resip
16 {
17
18 class Contents;
19 class HeaderFieldValue;
20 class ParseBuffer;
21
22 class ContentsFactoryBase
23 {
24 public:
25 virtual Contents* create(HeaderFieldValue* hfv,
26 const Mime& contentType) const = 0;
27 virtual Contents* convert(Contents* c) const = 0;
28 };
29
30 // MIME header types
31 class MIME_Header
32 {
33 };
34
35 class H_ContentID : public MIME_Header
36 {
37 public:
38 typedef Token Type;
39 };
40 extern H_ContentID h_ContentID;
41
42 class H_ContentDescription : public MIME_Header
43 {
44 public:
45 typedef StringCategory Type;
46 };
47 extern H_ContentDescription h_ContentDescription;
48
49 // Common type for all body contents
50 class Contents : public LazyParser
51 {
52 public:
53 // pass Mime instance for parameters
54
55 Contents(HeaderFieldValue* headerFieldValue, const Mime& contentsType);
56 Contents(const Mime& contentsType);
57 Contents(const Contents& rhs);
58 virtual ~Contents();
59 Contents& operator=(const Contents& rhs);
60
61 void preParseHeaders(ParseBuffer& pb);
62 std::ostream& encodeHeaders(std::ostream& str) const;
63
64 // access to wrapped contents (signed, encrypted)
65 virtual Contents* getContents() {return this;}
66
67 Contents* getContents(const Mime&);
68
69 virtual Data getBodyData() const;
70
71 virtual Contents* clone() const = 0;
72 const Mime& getType() const {return mType;}
73
74 static Contents* createContents(const Mime& contentType,
75 const Data& contents);
76
77 bool exists(const HeaderBase& headerType) const;
78 void remove(const HeaderBase& headerType);
79
80 bool exists(const MIME_Header& headerType) const;
81 void remove(const MIME_Header& headerType);
82
83 // !dlb! break into const and non-const -- throw on const if not exists
84 // !dlb! requires a nested exception...
85
86 // shared header types
87 H_ContentType::Type& header(const H_ContentType& headerType) const;
88 H_ContentDisposition::Type& header(const H_ContentDisposition& headerType) const;
89 H_ContentTransferEncoding::Type& header(const H_ContentTransferEncoding& headerType) const;
90 H_ContentLanguages::Type& header(const H_ContentLanguages& headerType) const;
91
92 // MIME specific header types
93 H_ContentID::Type& header(const H_ContentID& headerType) const;
94 H_ContentDescription::Type& header(const H_ContentDescription& headerType) const;
95
96 int& verion() {return mVersion;}
97 int& minorVersion() {return mMinorVersion;}
98
99 static HashMap<Mime, ContentsFactoryBase*>& getFactoryMap();
100
101 protected:
102 void clear();
103 virtual const Data& errorContext() const;
104
105 mutable Mime mType;
106 mutable H_ContentDisposition::Type *mDisposition;
107 mutable H_ContentTransferEncoding::Type *mTransferEncoding;
108 mutable H_ContentLanguages::Type *mLanguages;
109 mutable Token *mId;
110 mutable H_ContentDescription::Type *mDescription;
111 mutable StringCategory *mLength;
112
113 mutable int mVersion;
114 mutable int mMinorVersion;
115
116 private:
117 static HashMap<Mime, ContentsFactoryBase*>* FactoryMap;
118 };
119
120 template<class T>
121 class ContentsFactory : public ContentsFactoryBase
122 {
123 public:
124 ContentsFactory()
125 {
126 HeaderFieldValue hfv;
127 assert(Contents::getFactoryMap().count(T::getStaticType()) == 0);
128 Contents::getFactoryMap()[T::getStaticType()] = this;
129 }
130
131 explicit ContentsFactory(const Mime& nonStandardType)
132 {
133 HeaderFieldValue hfv;
134 Contents::getFactoryMap()[nonStandardType] = this;
135 }
136
137 virtual ~ContentsFactory()
138 {
139 HashMap<Mime, ContentsFactoryBase*>::iterator i;
140 i = Contents::getFactoryMap().find(T::getStaticType());
141 Contents::getFactoryMap().erase(i);
142 if (Contents::getFactoryMap().size() == 0)
143 {
144 delete &Contents::getFactoryMap();
145 }
146 }
147
148 // pass Mime instance for parameters
149 virtual Contents* create(HeaderFieldValue* hfv, const Mime& contentType) const
150 {
151 return new T(hfv, contentType);
152 }
153
154 virtual Contents* convert(Contents* c) const
155 {
156 return dynamic_cast<T*>(c);
157 }
158 };
159
160 }
161
162 #endif
163
164 /* ====================================================================
165 * The Vovida Software License, Version 1.0
166 *
167 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
168 *
169 * Redistribution and use in source and binary forms, with or without
170 * modification, are permitted provided that the following conditions
171 * are met:
172 *
173 * 1. Redistributions of source code must retain the above copyright
174 * notice, this std::list of conditions and the following disclaimer.
175 *
176 * 2. Redistributions in binary form must reproduce the above copyright
177 * notice, this std::list of conditions and the following disclaimer in
178 * the documentation and/or other materials provided with the
179 * distribution.
180 *
181 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
182 * and "Vovida Open Communication Application Library (VOCAL)" must
183 * not be used to endorse or promote products derived from this
184 * software without prior written permission. For written
185 * permission, please contact vocal@vovida.org.
186 *
187 * 4. Products derived from this software may not be called "VOCAL", nor
188 * may "VOCAL" appear in their name, without prior written
189 * permission of Vovida Networks, Inc.
190 *
191 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
192 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
193 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
194 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
195 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
196 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
197 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
198 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
199 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
200 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
201 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
202 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
203 * DAMAGE.
204 *
205 * ====================================================================
206 *
207 * This software consists of voluntary contributions made by Vovida
208 * Networks, Inc. and many individuals on behalf of Vovida Networks,
209 * Inc. For more information on Vovida Networks, Inc., please see
210 * <http://www.vovida.org/>.
211 *
212 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27