reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
CallId.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
7#include "rutil/Data.hxx"
8#include "rutil/DnsUtil.hxx"
9#include "rutil/Logger.hxx"
10#include "rutil/ParseBuffer.hxx"
11//#include "rutil/WinLeakCheck.hxx" // not compatible with placement new used below
12
13using namespace resip;
14using namespace std;
15
16
17#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
18
19//====================
20// CallID:
21//====================
23 : ParserCategory(),
24 mValue()
25{}
26
28 Headers::Type type,
29 PoolBase* pool)
30 : ParserCategory(hfv, type, pool), mValue()
31{}
32
34 PoolBase* pool)
35 : ParserCategory(rhs, pool),
36 mValue(rhs.mValue)
37{}
38
39CallID&
41{
42 if (this != &rhs)
43 {
45 mValue = rhs.mValue;
46 }
47 return *this;
48}
49
50bool
51CallID::operator==(const CallID& rhs) const
52{
53 return value() == rhs.value();
54}
55
58{
59 return new CallID(*this);
60}
61
63CallID::clone(void* location) const
64{
65 return new (location) CallID(*this);
66}
67
70{
71 return new (pool) CallID(*this, pool);
72}
73
74Data&
76{
77 checkParsed();
78 return mValue;
79}
80
81const Data&
83{
84 checkParsed();
85 return mValue;
86}
87
88void
90{
91 const char* start = pb.skipWhitespace();
92 pb.assertNotEof();
93 static const std::bitset<256> wsOrSemi(Data::toBitset(ParseBuffer::Whitespace).set(Symbols::SEMI_COLON[0]));
94 pb.skipToOneOf(wsOrSemi);
95 pb.data(mValue, start);
96
98}
99
101CallID::encodeParsed(EncodeStream& str) const
102{
103 str << mValue;
104 encodeParameters(str);
105 return str;
106}
107
108ParameterTypes::Factory CallID::ParameterFactories[ParameterTypes::MAX_PARAMETER]={0};
109
110Parameter*
111CallID::createParam(ParameterTypes::Type type, ParseBuffer& pb, const std::bitset<256>& terminators, PoolBase* pool)
112{
113 if(type > ParameterTypes::UNKNOWN && type < ParameterTypes::MAX_PARAMETER && ParameterFactories[type])
114 {
115 return ParameterFactories[type](type, pb, terminators, pool);
116 }
117 return 0;
118}
119
120bool
121CallID::exists(const Param<CallID>& paramType) const
122{
123 checkParsed();
124 bool ret = getParameterByEnum(paramType.getTypeNum()) != NULL;
125 return ret;
126}
127
128void
130{
131 checkParsed();
133}
134
135#define defineParam(_enum, _name, _type, _RFC_ref_ignored) \
136_enum##_Param::DType& \
137CallID::param(const _enum##_Param& paramType) \
138{ \
139 checkParsed(); \
140 _enum##_Param::Type* p = \
141 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
142 if (!p) \
143 { \
144 p = new _enum##_Param::Type(paramType.getTypeNum()); \
145 mParameters.push_back(p); \
146 } \
147 return p->value(); \
148} \
149 \
150const _enum##_Param::DType& \
151CallID::param(const _enum##_Param& paramType) const \
152{ \
153 checkParsed(); \
154 _enum##_Param::Type* p = \
155 static_cast<_enum##_Param::Type*>(getParameterByEnum(paramType.getTypeNum())); \
156 if (!p) \
157 { \
158 InfoLog(<< "Missing parameter " _name " " << ParameterTypes::ParameterNames[paramType.getTypeNum()]); \
159 DebugLog(<< *this); \
160 throw Exception("Missing parameter " _name, __FILE__, __LINE__); \
161 } \
162 return p->value(); \
163}
164
165defineParam(fromTag, "from-tag", DataParameter, "RFC 3891 (not in IANA, apparently)");
166defineParam(toTag, "to-tag", DataParameter, "RFC 3891 (not in IANA, apparently)");
167defineParam(earlyOnly, "early-only", ExistsParameter, "RFC 3891 (not in IANA, apparently)");
168
169#undef defineParam
170
171
172/* ====================================================================
173 * The Vovida Software License, Version 1.0
174 *
175 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
176 *
177 * Redistribution and use in source and binary forms, with or without
178 * modification, are permitted provided that the following conditions
179 * are met:
180 *
181 * 1. Redistributions of source code must retain the above copyright
182 * notice, this list of conditions and the following disclaimer.
183 *
184 * 2. Redistributions in binary form must reproduce the above copyright
185 * notice, this list of conditions and the following disclaimer in
186 * the documentation and/or other materials provided with the
187 * distribution.
188 *
189 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
190 * and "Vovida Open Communication Application Library (VOCAL)" must
191 * not be used to endorse or promote products derived from this
192 * software without prior written permission. For written
193 * permission, please contact vocal@vovida.org.
194 *
195 * 4. Products derived from this software may not be called "VOCAL", nor
196 * may "VOCAL" appear in their name, without prior written
197 * permission of Vovida Networks, Inc.
198 *
199 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
200 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
201 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
202 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
203 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
204 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
205 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
206 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
207 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
208 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
209 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
210 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
211 * DAMAGE.
212 *
213 * ====================================================================
214 *
215 * This software consists of voluntary contributions made by Vovida
216 * Networks, Inc. and many individuals on behalf of Vovida Networks,
217 * Inc. For more information on Vovida Networks, Inc., please see
218 * <http://www.vovida.org/>.
219 *
220 */
#define defineParam(_enum, _name, _type, _RFC_ref_ignored)
Definition Auth.cxx:239
Represents the "callid" element in the SIP grammar.
Definition CallId.hxx:18
void remove(const Param< CallID > &paramType)
Definition CallId.cxx:129
bool operator==(const CallID &) const
Definition CallId.cxx:51
bool exists(const Param< CallID > &paramType) const
Definition CallId.cxx:121
CallID & operator=(const CallID &)
Definition CallId.cxx:40
virtual void parse(ParseBuffer &pb)
Definition CallId.cxx:89
Data & value()
Definition CallId.cxx:75
virtual EncodeStream & encodeParsed(EncodeStream &str) const
Definition CallId.cxx:101
virtual ParserCategory * clone() const
Definition CallId.cxx:57
virtual Parameter * createParam(ParameterTypes::Type type, ParseBuffer &pb, const std::bitset< 256 > &terminators, PoolBase *pool)
Definition CallId.cxx:111
Generically represents miscellaneous parameter data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
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
Represents various parameters that are indicated to be in effect merely by being present,...
void checkParsed() const
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()
void assertNotEof() const
CurrentPosition skipToOneOf(const char *cs)
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
static const char * Whitespace
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.
static const char * SEMI_COLON
Definition Symbols.hxx:30
dcm! – add UnusedChecking(_enum) below;
#define EncodeStream