reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Mime.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
6#include "rutil/Data.hxx"
7#include "rutil/DnsUtil.hxx"
8#include "rutil/Logger.hxx"
10//#include "rutil/WinLeakCheck.hxx" // not compatible with placement new used below
11
12using namespace resip;
13using namespace std;
14
15#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
16
17//====================
18// MIME
19//====================
21 : ParserCategory(),
22 mType(),
23 mSubType()
24{}
25
26Mime::Mime(const Data& type, const Data& subType)
27 : ParserCategory(),
28 mType(type),
29 mSubType(subType)
30{}
31
33 Headers::Type type,
34 PoolBase* pool)
35 : ParserCategory(hfv, type, pool),
36 mType(),
37 mSubType()
38{}
39
40Mime::Mime(const Mime& rhs,
41 PoolBase* pool)
42 : ParserCategory(rhs, pool),
43 mType(rhs.mType),
44 mSubType(rhs.mSubType)
45{}
46
47Mime&
49{
50 if (this != &rhs)
51 {
53 mType = rhs.mType;
54 mSubType = rhs.mSubType;
55 }
56 return *this;
57}
58
59bool
60Mime::operator<(const Mime& rhs) const
61{
62 if (isLessThanNoCase(type(), rhs.type()))
63 {
64 return true;
65 }
66 else if (isLessThanNoCase(rhs.type(), type()))
67 {
68 return false;
69 }
70 return isLessThanNoCase(subType(), rhs.subType());
71}
72
73bool
74Mime::isEqual(const Mime& rhs) const
75{
76 return (isEqualNoCase(type(), rhs.type()) &&
77 isEqualNoCase(subType(), rhs.subType()));
78}
79
80bool
81Mime::operator==(const Mime& rhs) const
82{
83 return (isEqualNoCase(type(), rhs.type()) &&
84 isEqualNoCase(subType(), rhs.subType()));
85}
86
87bool
88Mime::operator!=(const Mime& rhs) const
89{
90 return !(*this == rhs);
91}
92
93const Data&
94Mime::type() const
95{
96 checkParsed();
97 return mType;
98}
99
100const Data& Mime::subType() const
101{
102 checkParsed();
103 return mSubType;
104}
105
106Data&
108{
109 checkParsed();
110 return mType;
111}
112
114{
115 checkParsed();
116 return mSubType;
117}
118
119void
121{
122 const char* anchor = pb.skipWhitespace();
123 static std::bitset<256> delimiter1=Data::toBitset("\r\n\t /");
124 pb.skipToOneOf(delimiter1);
125 pb.data(mType, anchor);
126
127 pb.skipWhitespace();
129
130 anchor = pb.skipWhitespace();
131 static std::bitset<256> delimiter2=Data::toBitset("\r\n\t ;");
132 pb.skipToOneOf(delimiter2);
133 pb.data(mSubType, anchor);
134
135 pb.skipWhitespace();
136 parseParameters(pb);
137}
138
141{
142 return new Mime(*this);
143}
144
146Mime::clone(void* location) const
147{
148 return new (location) Mime(*this);
149}
150
153{
154 return new (pool) Mime(*this, pool);
155}
156
158Mime::encodeParsed(EncodeStream& str) const
159{
160 str << mType << Symbols::SLASH << mSubType ;
161 encodeParameters(str);
162 return str;
163}
164
165ParameterTypes::Factory Mime::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0};
166
167Parameter*
168Mime::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool)
169{
170 if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type])
171 {
172 return ParameterFactories[type](type, pb, terminators, pool);
173 }
174 return 0;
175}
176
177bool
178Mime::exists(const Param<Mime>& paramType) const
179{
180 checkParsed();
181 bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL;
182 return ret;
183}
184
185void
186Mime::remove(const Param<Mime>& paramType)
187{
188 checkParsed();
190}
191
192#define defineParam(_enum, _name, _type, _RFC_ref_ignored) \
193_enum##_Param::DType& \
194Mime::param(const _enum##_Param& paramType) \
195{ \
196 checkParsed(); \
197 _enum##_Param::Type* p = \
198 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
199 if (!p) \
200 { \
201 p = new _enum##_Param::Type(paramType.getTypeNum()); \
202 mParameters.push_back(p); \
203 } \
204 return p->value(); \
205} \
206 \
207const _enum##_Param::DType& \
208Mime::param(const _enum##_Param& paramType) const \
209{ \
210 checkParsed(); \
211 _enum##_Param::Type* p = \
212 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
213 if (!p) \
214 { \
215 InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]); \
216 DebugLog(<< *this); \
217 throw Exception("Missing parameter " _name, __FILE__, __LINE__); \
218 } \
219 return p->value(); \
220}
221
222defineParam(accessType, "access-type", DataParameter, "RFC 2046");
223defineParam(boundary, "boundary", DataParameter, "RFC 2046");
224defineParam(charset, "charset", DataParameter, "RFC 2045");
225defineParam(directory, "directory", DataParameter, "RFC 2046");
226defineParam(expiration, "expiration", QuotedDataParameter, "RFC 2046");
227defineParam(micalg, "micalg", DataParameter, "RFC 1847");
228defineParam(mode, "mode", DataParameter, "RFC 2046");
229defineParam(name, "name", DataParameter, "RFC 2046");
230defineParam(permission, "permission", DataParameter, "RFC 2046");
231defineParam(protocol, "protocol", QuotedDataParameter, "RFC 1847");
232defineParam(q, "q", QValueParameter, "RFC 3261");
233defineParam(server, "server", DataParameter, "RFC 2046");
234defineParam(site, "site", DataParameter, "RFC 2046");
235defineParam(size, "size", DataParameter, "RFC 2046");
236defineParam(smimeType, "smime-type", DataParameter, "RFC 2633");
237defineParam(url, "url", QuotedDataParameter, "RFC 4483");
238
239#undef defineParam
240
241HashValueImp(resip::Mime, data.type().caseInsensitiveTokenHash() ^ data.subType().caseInsensitiveTokenHash());
242
243/* ====================================================================
244 * The Vovida Software License, Version 1.0
245 *
246 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
247 *
248 * Redistribution and use in source and binary forms, with or without
249 * modification, are permitted provided that the following conditions
250 * are met:
251 *
252 * 1. Redistributions of source code must retain the above copyright
253 * notice, this list of conditions and the following disclaimer.
254 *
255 * 2. Redistributions in binary form must reproduce the above copyright
256 * notice, this list of conditions and the following disclaimer in
257 * the documentation and/or other materials provided with the
258 * distribution.
259 *
260 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
261 * and "Vovida Open Communication Application Library (VOCAL)" must
262 * not be used to endorse or promote products derived from this
263 * software without prior written permission. For written
264 * permission, please contact vocal@vovida.org.
265 *
266 * 4. Products derived from this software may not be called "VOCAL", nor
267 * may "VOCAL" appear in their name, without prior written
268 * permission of Vovida Networks, Inc.
269 *
270 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
271 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
272 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
273 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
274 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
275 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
276 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
277 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
278 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
279 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
280 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
281 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
282 * DAMAGE.
283 *
284 * ====================================================================
285 *
286 * This software consists of voluntary contributions made by Vovida
287 * Networks, Inc. and many individuals on behalf of Vovida Networks,
288 * Inc. For more information on Vovida Networks, Inc., please see
289 * <http://www.vovida.org/>.
290 *
291 */
#define defineParam(_enum, _name, _type, _RFC_ref_ignored)
Definition Auth.cxx:239
#define HashValueImp(type, ret)
Definition HashMap.hxx:24
Generically represents miscellaneous parameter data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
size_t caseInsensitiveTokenHash() const
A faster version of caseInsensitiveHash that has the same collision properties if this Data is made u...
Definition Data.cxx:2367
static std::bitset< 256 > toBitset(const resip::Data &chars)
Creates a bitset reflecting the contents of this data (as a set) ie.
Definition Data.cxx:2477
void checkParsed() const
Represents the "media-type" element in the RFC 3261 grammar.
Definition Mime.hxx:20
virtual void parse(ParseBuffer &pb)
Definition Mime.cxx:120
virtual Parameter * createParam(ParameterTypes::Type type, ParseBuffer &pb, const std::bitset< 256 > &terminators, PoolBase *pool)
Definition Mime.cxx:168
virtual ParserCategory * clone() const
Definition Mime.cxx:140
const Data & subType() const
Definition Mime.cxx:100
bool isEqual(const Mime &rhs) const
Definition Mime.cxx:74
bool exists(const Param< Mime > &paramType) const
Definition Mime.cxx:178
bool operator!=(const Mime &rhs) const
Definition Mime.cxx:88
Mime & operator=(const Mime &)
Definition Mime.cxx:48
bool operator==(const Mime &rhs) const
Definition Mime.cxx:81
bool operator<(const Mime &rhs) const
Definition Mime.cxx:60
void remove(const Param< Mime > &paramType)
Definition Mime.cxx:186
const Data & type() const
Definition Mime.cxx:94
virtual EncodeStream & encodeParsed(EncodeStream &str) const
Definition Mime.cxx:158
virtual ParameterTypes::Type getTypeNum() const =0
Parameter *(* Factory)(ParameterTypes::Type, ParseBuffer &, const std::bitset< 256 > &terminators, PoolBase *pool)
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipWhitespace()
CurrentPosition skipToOneOf(const char *cs)
CurrentPosition skipChar()
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
Base class for all SIP grammar elements that can have parameters.
Parameter * getParameterByEnum(ParameterTypes::Type type) const
ParserCategory & operator=(const ParserCategory &rhs)
void removeParameterByEnum(ParameterTypes::Type type)
void parseParameters(ParseBuffer &pb)
EncodeStream & encodeParameters(EncodeStream &str) const
Encodes parameters as they should appear on the wire.
Represents the "q" parameter value of the RFC 3261 grammar.
Generically represents miscellaneous parameter data that is encoded using double quotes.
static const char * SLASH
Definition Symbols.hxx:32
dcm! – add UnusedChecking(_enum) below;
bool isEqualNoCase(const Data &left, const Data &right)
Definition Data.hxx:1116
bool isLessThanNoCase(const Data &left, const Data &right)
Definition Data.hxx:1127
#define EncodeStream