/src/resiprocate/resip/stack/DataParameter.cxx
Line | Count | Source (jump to first uncovered line) |
1 | | #if defined(HAVE_CONFIG_H) |
2 | | #include "config.h" |
3 | | #endif |
4 | | |
5 | | #include "rutil/ResipAssert.h" |
6 | | #include "resip/stack/DataParameter.hxx" |
7 | | #include "resip/stack/Symbols.hxx" |
8 | | #include "rutil/ParseBuffer.hxx" |
9 | | #include "rutil/ParseException.hxx" |
10 | | #include "rutil/Logger.hxx" |
11 | | #include "rutil/WinLeakCheck.hxx" |
12 | | |
13 | | using namespace resip; |
14 | | using namespace std; |
15 | | |
16 | | #define RESIPROCATE_SUBSYSTEM Subsystem::SIP |
17 | | |
18 | | DataParameter::DataParameter(ParameterTypes::Type type, |
19 | | ParseBuffer& pb, |
20 | | const std::bitset<256>& terminators) |
21 | | : Parameter(type), |
22 | | mValue(), |
23 | | mQuoted(false) |
24 | 20.2k | { |
25 | 20.2k | pb.skipWhitespace(); |
26 | 20.2k | pb.skipChar(Symbols::EQUALS[0]); |
27 | 20.2k | pb.skipWhitespace(); |
28 | 20.2k | if(terminators[(unsigned char)(*pb.position())]) // handle cases such as ;tag= |
29 | 13 | { |
30 | 13 | throw ParseException("Empty value in string-type parameter.", |
31 | 13 | "DataParameter", |
32 | 13 | __FILE__,__LINE__); |
33 | 13 | } |
34 | | |
35 | 20.2k | if (*pb.position() == Symbols::DOUBLE_QUOTE[0]) |
36 | 461 | { |
37 | 461 | setQuoted(true); |
38 | 461 | pb.skipChar(); |
39 | 461 | const char* pos = pb.position(); |
40 | 461 | pb.skipToEndQuote(); |
41 | 461 | pb.data(mValue, pos); |
42 | 461 | pb.skipChar(); |
43 | 461 | } |
44 | 19.7k | else |
45 | 19.7k | { |
46 | 19.7k | const char* pos = pb.position(); |
47 | 19.7k | pb.skipToOneOf(terminators); |
48 | 19.7k | pb.data(mValue, pos); |
49 | 19.7k | } |
50 | | |
51 | 20.2k | if(!mQuoted && mValue.empty()) |
52 | 0 | { |
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 | 0 | } |
61 | 20.2k | } |
62 | | |
63 | | DataParameter::DataParameter(ParameterTypes::Type type) |
64 | | : Parameter(type), |
65 | | mValue(), |
66 | | mQuoted(false) |
67 | 34.9k | { |
68 | 34.9k | } |
69 | | |
70 | | Parameter* |
71 | | DataParameter::clone() const |
72 | 266 | { |
73 | 266 | return new DataParameter(*this); |
74 | 266 | } |
75 | | |
76 | | EncodeStream& |
77 | | DataParameter::encode(EncodeStream& stream) const |
78 | 0 | { |
79 | 0 | if (mQuoted) |
80 | 0 | { |
81 | 0 | return stream << getName() << Symbols::EQUALS |
82 | 0 | << Symbols::DOUBLE_QUOTE << mValue << Symbols::DOUBLE_QUOTE; |
83 | 0 | } |
84 | 0 | else |
85 | 0 | { |
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 | 0 | if (mValue.empty()) |
90 | 0 | { |
91 | 0 | ErrLog(<< "Accessing defaulted DataParameter: '" << getName() << "'"); |
92 | 0 | } |
93 | 0 | resip_assert(!mValue.empty()); // !jf! probably should throw here |
94 | 0 | return stream << getName() << Symbols::EQUALS << mValue; |
95 | 0 | } |
96 | 0 | } |
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 | | */ |