reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
DataParameter.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
5#include "rutil/ResipAssert.h"
10#include "rutil/Logger.hxx"
12
13using namespace resip;
14using namespace std;
15
16#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
17
19 ParseBuffer& pb,
20 const std::bitset<256>& terminators)
21 : Parameter(type),
22 mValue(),
23 mQuoted(false)
24{
25 pb.skipWhitespace();
27 pb.skipWhitespace();
28 if(terminators[(unsigned char)(*pb.position())]) // handle cases such as ;tag=
29 {
30 throw ParseException("Empty value in string-type parameter.",
31 "DataParameter",
32 __FILE__,__LINE__);
33 }
34
35 if (*pb.position() == Symbols::DOUBLE_QUOTE[0])
36 {
37 setQuoted(true);
38 pb.skipChar();
39 const char* pos = pb.position();
40 pb.skipToEndQuote();
41 pb.data(mValue, pos);
42 pb.skipChar();
43 }
44 else
45 {
46 const char* pos = pb.position();
47 pb.skipToOneOf(terminators);
48 pb.data(mValue, pos);
49 }
50
51 if(!mQuoted && mValue.empty())
52 {
53 // .bwc. We can't let this happen, because we throw if we try to encode
54 // when we have an empty value. If that behavior stops, this can be
55 // removed.
56 /* throw ParseException("DataParameter c'tor parsed empty param!",
57 "DataParameter",
58 __FILE__,
59 __LINE__); */
60 }
61}
62
64 : Parameter(type),
65 mValue(),
66 mQuoted(false)
67{
68}
69
72{
73 return new DataParameter(*this);
74}
75
77DataParameter::encode(EncodeStream& stream) const
78{
79 if (mQuoted)
80 {
81 return stream << getName() << Symbols::EQUALS
83 }
84 else
85 {
86 // this will assert if you've accessed a parameter that doesn't exist and
87 // then the stack has created an empty parameter with no value. Try
88 // calling exists(p_foo) before calling param(p_foo)
89 if (mValue.empty())
90 {
91 ErrLog(<< "Accessing defaulted DataParameter: '" << getName() << "'");
92 }
93 resip_assert(!mValue.empty()); // !jf! probably should throw here
94 return stream << getName() << Symbols::EQUALS << mValue;
95 }
96}
97
98/* ====================================================================
99 * The Vovida Software License, Version 1.0
100 *
101 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
102 *
103 * Redistribution and use in source and binary forms, with or without
104 * modification, are permitted provided that the following conditions
105 * are met:
106 *
107 * 1. Redistributions of source code must retain the above copyright
108 * notice, this list of conditions and the following disclaimer.
109 *
110 * 2. Redistributions in binary form must reproduce the above copyright
111 * notice, this list of conditions and the following disclaimer in
112 * the documentation and/or other materials provided with the
113 * distribution.
114 *
115 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
116 * and "Vovida Open Communication Application Library (VOCAL)" must
117 * not be used to endorse or promote products derived from this
118 * software without prior written permission. For written
119 * permission, please contact vocal@vovida.org.
120 *
121 * 4. Products derived from this software may not be called "VOCAL", nor
122 * may "VOCAL" appear in their name, without prior written
123 * permission of Vovida Networks, Inc.
124 *
125 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
126 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
127 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
128 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
129 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
130 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
131 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
132 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
133 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
134 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
135 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
136 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
137 * DAMAGE.
138 *
139 * ====================================================================
140 *
141 * This software consists of voluntary contributions made by Vovida
142 * Networks, Inc. and many individuals on behalf of Vovida Networks,
143 * Inc. For more information on Vovida Networks, Inc., please see
144 * <http://www.vovida.org/>.
145 *
146 */
#define ErrLog(args_)
Definition Logger.hxx:137
#define resip_assert(x)
This file needs to work for both C and C++ code.
Generically represents miscellaneous parameter data.
DataParameter(ParameterTypes::Type, ParseBuffer &pb, const std::bitset< 256 > &terminators)
virtual EncodeStream & encode(EncodeStream &stream) const
virtual Parameter * clone() const
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
virtual const Data & getName() const
Definition Parameter.cxx:23
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipWhitespace()
CurrentPosition position() const
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)
const char * skipToEndQuote(char quote='"')
BaseException used to indicate parse failures.
static const char * EQUALS
Definition Symbols.hxx:29
static const char * DOUBLE_QUOTE
Definition Symbols.hxx:26
dcm! – add UnusedChecking(_enum) below;
#define EncodeStream