/[resiprocate]/branches/b-identity-0505/BranchParameter.cxx
ViewVC logotype

Contents of /branches/b-identity-0505/BranchParameter.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4598 - (show annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 6 months ago) by derek
File size: 7490 byte(s)
set svn:eol-style to LF
1 #if defined(HAVE_CONFIG_H)
2 #include "resiprocate/config.hxx"
3 #endif
4
5 #include <cassert>
6 #include "resiprocate/BranchParameter.hxx"
7 #include "resiprocate/Symbols.hxx"
8 #include "resiprocate/os/ParseBuffer.hxx"
9 #include "resiprocate/os/Random.hxx"
10 #include "resiprocate/os/Coders.hxx"
11 #include "resiprocate/ParseException.hxx"
12
13 #include "resiprocate/os/Logger.hxx"
14 #include "resiprocate/os/WinLeakCheck.hxx"
15
16 using namespace resip;
17 using namespace std;
18
19 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
20
21 BranchParameter::BranchParameter(ParameterTypes::Type type,
22 ParseBuffer& pb, const char* terminators)
23 : Parameter(type),
24 mHasMagicCookie(false),
25 mIsMyBranch(false),
26 mTransactionId(Random::getRandomHex(8)),
27 mTransportSeq(1),
28 mClientData()
29 {
30 pb.skipChar(Symbols::EQUALS[0]);
31 if (strncasecmp(pb.position(), Symbols::MagicCookie, 7) == 0)
32 {
33 mHasMagicCookie = true;
34 pb.skipN(7);
35 }
36
37 const char* start = pb.position();
38 const char* end = pb.skipToOneOf(ParseBuffer::Whitespace, ";=?>"); // !dlb! add to ParseBuffer as terminator set
39
40 if (mHasMagicCookie &&
41 (end - start > 2*8) &&
42 // look for prefix cookie
43 (strncasecmp(start, Symbols::resipCookie, 8) == 0) &&
44 // look for postfix cookie
45 (strncasecmp(end - 8, Symbols::resipCookie, 8) == 0))
46 {
47 mIsMyBranch = true;
48 start += 8;
49
50 // s = start, e = end, S = anchorStart, E = anchorEnd
51 // rfc3261cookie-sip2cookie-tid-transportseq-clientdata-sip2cookie
52 // s e
53
54 pb.skipBackN(8);
55 const char* anchorEnd = pb.position();
56 pb.skipBackToChar(Symbols::DASH[0]);
57 const char* anchorStart = pb.position();
58 // rfc3261cookie-sip2cookie-tid-transportseq-clientdata-sip2cookie
59 // s S E e
60
61 if ((anchorEnd - anchorStart) > 1)
62 {
63 pb.reset(anchorEnd);
64 Data encoded;
65 pb.data(encoded, anchorStart);
66 mClientData = encoded.base64decode();
67 pb.reset(anchorStart);
68 }
69
70 pb.skipBackChar(Symbols::DASH[0]);
71 pb.skipBackToChar(Symbols::DASH[0]);
72 pb.skipBackChar(Symbols::DASH[0]);
73 // rfc3261cookie-sip2cookie-tid-transportseq-clientdata-sip2cookie
74 // s S E e
75
76 pb.data(mTransactionId, start);
77 pb.skipChar();
78 mTransportSeq = pb.integer();
79 pb.reset(end);
80 }
81 else
82 {
83 pb.data(mTransactionId, start);
84 }
85 }
86
87 BranchParameter::BranchParameter(ParameterTypes::Type type)
88 : Parameter(type),
89 mHasMagicCookie(true),
90 mIsMyBranch(true),
91 mTransactionId(Random::getRandomHex(8)),
92 mTransportSeq(1)
93 {
94 }
95
96 BranchParameter::BranchParameter(const BranchParameter& other)
97 : Parameter(other),
98 mHasMagicCookie(other.mHasMagicCookie),
99 mIsMyBranch(other.mIsMyBranch),
100 mTransactionId(other.mTransactionId),
101 mTransportSeq(other.mTransportSeq),
102 mClientData(other.mClientData)
103 {
104 }
105
106 BranchParameter&
107 BranchParameter::operator=(const BranchParameter& other)
108 {
109 if (this != &other)
110 {
111 mHasMagicCookie = other.mHasMagicCookie;
112 mIsMyBranch = other.mIsMyBranch;
113 mTransactionId = other.mTransactionId;
114 mTransportSeq = other.mTransportSeq;
115 mClientData = other.mClientData;
116 }
117 return *this;
118 }
119
120 bool
121 BranchParameter::operator==(const BranchParameter& other)
122 {
123 if (mIsMyBranch != other.mIsMyBranch ||
124 mHasMagicCookie != other.mHasMagicCookie ||
125 mTransportSeq != other.mTransportSeq ||
126 mTransactionId != other.mTransactionId ||
127 mClientData != other.mClientData)
128 {
129 return false;
130 }
131 return true;
132 }
133
134 bool
135 BranchParameter::hasMagicCookie() const
136 {
137 return mHasMagicCookie;
138 }
139
140 const Data&
141 BranchParameter::getTransactionId() const
142 {
143 return mTransactionId;
144 }
145
146 void
147 BranchParameter::incrementTransportSequence()
148 {
149 assert(mIsMyBranch);
150 mTransportSeq++;
151 }
152
153 Data&
154 BranchParameter::clientData()
155 {
156 return mClientData;
157 }
158
159 const Data&
160 BranchParameter::clientData() const
161 {
162 return mClientData;
163 }
164
165 void
166 BranchParameter::reset(const Data& transactionId)
167 {
168 mHasMagicCookie = true;
169 mIsMyBranch = true;
170
171 mTransportSeq = 1;
172 if (!transactionId.empty())
173 {
174 mTransactionId = transactionId;
175 }
176 else
177 {
178 mTransactionId = Random::getRandomHex(8);
179 }
180 }
181
182 Parameter*
183 BranchParameter::clone() const
184 {
185 return new BranchParameter(*this);
186 }
187
188 ostream&
189 BranchParameter::encode(ostream& stream) const
190 {
191 stream << getName() << Symbols::EQUALS;
192 if (mHasMagicCookie)
193 {
194 stream << Symbols::MagicCookie;
195 }
196 if (mIsMyBranch)
197 {
198 stream << Symbols::resipCookie
199 << mTransactionId
200 << Symbols::DASH[0]
201 << mTransportSeq
202 << Symbols::DASH[0]
203 << mClientData.base64encode(true/*safe URL*/)
204 << Symbols::resipCookie;
205 }
206 else
207 {
208 stream << mTransactionId;
209 }
210
211 return stream;
212 }
213
214
215 /* ====================================================================
216 * The Vovida Software License, Version 1.0
217 *
218 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
219 *
220 * Redistribution and use in source and binary forms, with or without
221 * modification, are permitted provided that the following conditions
222 * are met:
223 *
224 * 1. Redistributions of source code must retain the above copyright
225 * notice, this list of conditions and the following disclaimer.
226 *
227 * 2. Redistributions in binary form must reproduce the above copyright
228 * notice, this list of conditions and the following disclaimer in
229 * the documentation and/or other materials provided with the
230 * distribution.
231 *
232 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
233 * and "Vovida Open Communication Application Library (VOCAL)" must
234 * not be used to endorse or promote products derived from this
235 * software without prior written permission. For written
236 * permission, please contact vocal@vovida.org.
237 *
238 * 4. Products derived from this software may not be called "VOCAL", nor
239 * may "VOCAL" appear in their name, without prior written
240 * permission of Vovida Networks, Inc.
241 *
242 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
243 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
244 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
245 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
246 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
247 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
248 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
249 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
250 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
251 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
253 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
254 * DAMAGE.
255 *
256 * ====================================================================
257 *
258 * This software consists of voluntary contributions made by Vovida
259 * Networks, Inc. and many individuals on behalf of Vovida Networks,
260 * Inc. For more information on Vovida Networks, Inc., please see
261 * <http://www.vovida.org/>.
262 *
263 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27