reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ParserCategory.hxx
Go to the documentation of this file.
1#if !defined(RESIP_PARSERCATEGORY_HXX)
2#define RESIP_PARSERCATEGORY_HXX
3
4#include <iosfwd>
5#include <vector>
6#include <set>
10#include "rutil/Data.hxx"
13#include "rutil/PoolBase.hxx"
14
16
17#define defineParam(_enum, _name, _type, _RFC_ref_ignored) \
18 const _enum##_Param::DType& param(const _enum##_Param& paramType) const; \
19 _enum##_Param::DType& param(const _enum##_Param& paramType)
20
21namespace resip
22{
23class UnknownParameter;
24class ExtensionParameter;
25class Parameter;
26class ParseBuffer;
27
85{
86 public:
88
89 // NoCommaTokenizing: commas do not indicate a new header value
90 // CommasAllowedOutputMulti: multi headers can be received with commas but
91 // output them on separate lines.
92 // CommasAllowedOutputCommas: multi headers can be received with commas
93 // and will always output with commas when
94 // parsed.
96
102 ParserCategory(const HeaderFieldValue& headerFieldValue,
103 Headers::Type type,
104 PoolBase* pool=0);
105
111 ParserCategory(const char* buf,
112 int length,
113 Headers::Type type,
114 PoolBase* pool=0);
115
121 PoolBase* pool=0);
122
128
129 virtual ~ParserCategory();
130
131 virtual ParserCategory* clone() const = 0;
132 virtual Parameter* createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool);
133
134 // Do a placement new
135 virtual ParserCategory* clone(void* location) const = 0;
136
137 // Do a pool allocated new
138 virtual ParserCategory* clone(PoolBase* pool) const = 0;
139
145 inline bool exists(const ParamBase& paramType) const
146 {
147 checkParsed();
148 return (getParameterByEnum(paramType.getTypeNum()) != NULL);
149 }
150
156 void remove(const ParamBase& paramType);
157
158 // !dlb! causes compiler error in windows -- change template to const T*
165 const Data& param(const ExtensionParameter& param) const;
166
174
180 void remove(const ExtensionParameter& param);
181
187 bool exists(const ExtensionParameter& param) const;
188
189 typedef std::set<ParameterTypes::Type> ParameterTypeSet;
190
192
201
205 class Exception final : public BaseException
206 {
207 public:
208 Exception(const Data& msg, const Data& file, const int line)
209 : BaseException(msg, file, line) {}
210
211 const char* name() const noexcept override { return "ParserCategory::Exception"; }
212 };
213
220
227
228 // used to compare 2 parameter lists for equality in an order independent way
236
242
249
254 void setParameter(const Parameter* parameter);
255
259 int numKnownParams() const {return (int)mParameters.size();};
260
264 int numUnknownParams() const {return (int)mUnknownParameters.size();};
265
266 protected:
267 ParserCategory(PoolBase* pool=0);
268
276
283 bool addParameter(UnknownParameter* unknownParam);
284
285 Parameter* getParameterByData(const Data& data) const;
286 void removeParameterByData(const Data& data);
288 {
289 return mPool;
290 }
291
292 inline void freeParameter(Parameter* p)
293 {
294 if(p)
295 {
296 p->~Parameter();
297 if(mPool)
298 {
299 mPool->deallocate(p);
300 return;
301 }
302 ::operator delete(p);
303 }
304 }
305
306 virtual const Data& errorContext() const;
307
308 typedef std::vector<Parameter*, StlPoolAllocator<Parameter*, PoolBase> > ParameterList;
313 private:
314 void clear();
315 void copyParametersFrom(const ParserCategory& other);
317 friend class NameAddr;
318};
319
321operator<<(EncodeStream&, const ParserCategory& category);
322
323}
324
325#undef defineParam
326
327#endif
328
329/* ====================================================================
330 * The Vovida Software License, Version 1.0
331 *
332 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
333 *
334 * Redistribution and use in source and binary forms, with or without
335 * modification, are permitted provided that the following conditions
336 * are met:
337 *
338 * 1. Redistributions of source code must retain the above copyright
339 * notice, this list of conditions and the following disclaimer.
340 *
341 * 2. Redistributions in binary form must reproduce the above copyright
342 * notice, this list of conditions and the following disclaimer in
343 * the documentation and/or other materials provided with the
344 * distribution.
345 *
346 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
347 * and "Vovida Open Communication Application Library (VOCAL)" must
348 * not be used to endorse or promote products derived from this
349 * software without prior written permission. For written
350 * permission, please contact vocal@vovida.org.
351 *
352 * 4. Products derived from this software may not be called "VOCAL", nor
353 * may "VOCAL" appear in their name, without prior written
354 * permission of Vovida Networks, Inc.
355 *
356 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
357 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
358 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
359 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
360 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
361 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
362 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
363 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
364 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
365 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
366 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
367 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
368 * DAMAGE.
369 *
370 * ====================================================================
371 *
372 * This software consists of voluntary contributions made by Vovida
373 * Networks, Inc. and many individuals on behalf of Vovida Networks,
374 * Inc. For more information on Vovida Networks, Inc., please see
375 * <http://www.vovida.org/>.
376 *
377 */
The abstract base-class for all exceptions thrown by resip code.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
The base-class for all lazily-parsed SIP grammar elements.
void checkParsed() const
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
virtual ParameterTypes::Type getTypeNum() const =0
virtual ~Parameter()
Definition Parameter.hxx:16
Provides string-parsing functionality with protection from buffer overflow.
Exception class used by ParserCategory.
Exception(const Data &msg, const Data &file, const int line)
const char * name() const noexcept override
Base class for all SIP grammar elements that can have parameters.
void removeParameterByData(const Data &data)
void remove(const ParamBase &paramType)
Removes a natively supported parameter, if the parameter is present.
void setParameter(const Parameter *parameter)
Parameter * getParameterByData(const Data &data) const
Parameter * getParameterByEnum(ParameterTypes::Type type) const
Data commutativeParameterHash() const
ParameterList mUnknownParameters
ParserCategory & operator=(const ParserCategory &rhs)
void removeParameterByEnum(ParameterTypes::Type type)
void parseParameters(ParseBuffer &pb)
bool addParameter(Parameter *param)
virtual ParserCategory * clone(PoolBase *pool) const =0
virtual Parameter * createParam(ParameterTypes::Type type, ParseBuffer &pb, const std::bitset< 256 > &terminators, PoolBase *pool)
int numKnownParams() const
Returns the number of known (natively supported) parameters.
static const ParameterTypeSet EmptyParameterTypeSet
EncodeStream & encodeParameters(EncodeStream &str) const
Encodes parameters as they should appear on the wire.
std::vector< Parameter *, StlPoolAllocator< Parameter *, PoolBase > > ParameterList
virtual const Data & errorContext() const
int numUnknownParams() const
Returns the number of unknown parameters.
friend EncodeStream & operator<<(EncodeStream &, const ParserCategory &)
bool exists(const ParamBase &paramType) const
Checks for the existence of a natively supported parameter.
virtual ParserCategory * clone(void *location) const =0
virtual ParserCategory * clone() const =0
std::set< ParameterTypes::Type > ParameterTypeSet
void removeParametersExcept(const ParameterTypeSet &set=EmptyParameterTypeSet)
Removes all known parameters except those that are specified in set.
void freeParameter(Parameter *p)
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
virtual void deallocate(void *ptr)=0
Generically used to represent any parameter that is not known by the implmentation.
dcm! – add UnusedChecking(_enum) below;
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
Replaces STL streams for general encoding purposes.
#define EncodeStream