/[resiprocate]/branches/b-directory-reorg/sip/resiprocate/Via.cxx
ViewVC logotype

Contents of /branches/b-directory-reorg/sip/resiprocate/Via.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3309 - (show annotations) (download)
Mon Sep 13 02:14:37 2004 UTC (15 years, 4 months ago) by dlb
Original Path: main/sip/resiprocate/Via.cxx
File size: 6473 byte(s)
ParseUtil deprecated; use DnsUtil & added TimeLimitFifo
1 #if defined(HAVE_CONFIG_H)
2 #include "resiprocate/config.hxx"
3 #endif
4
5 #include "resiprocate/Via.hxx"
6 #include "resiprocate/os/DnsUtil.hxx"
7 #include "resiprocate/os/Logger.hxx"
8 #include "resiprocate/os/ParseBuffer.hxx"
9
10 using namespace resip;
11 using namespace std;
12
13 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
14
15
16 //====================
17 // Via:
18 //====================
19 Via::Via()
20 : ParserCategory(),
21 mProtocolName(Symbols::ProtocolName),
22 mProtocolVersion(Symbols::ProtocolVersion),
23 mTransport(),
24 mSentHost(),
25 mSentPort(0)
26 {
27 // insert a branch in all Vias (default constructor)
28 this->param(p_branch);
29 this->param(p_rport); // add the rport parameter by default as per rfc 3581
30 }
31
32 Via::Via(HeaderFieldValue* hfv, Headers::Type type)
33 : ParserCategory(hfv, type),
34 mProtocolName(Symbols::ProtocolName),
35 mProtocolVersion(Symbols::ProtocolVersion),
36 mTransport(Symbols::UDP), // !jf!
37 mSentHost(),
38 mSentPort(-1)
39 {}
40
41 Via::Via(const Via& rhs)
42 : ParserCategory(rhs),
43 mProtocolName(rhs.mProtocolName),
44 mProtocolVersion(rhs.mProtocolVersion),
45 mTransport(rhs.mTransport),
46 mSentHost(rhs.mSentHost),
47 mSentPort(rhs.mSentPort)
48 {
49 }
50
51 Via&
52 Via::operator=(const Via& rhs)
53 {
54 if (this != &rhs)
55 {
56 ParserCategory::operator=(rhs);
57 mProtocolName = rhs.mProtocolName;
58 mProtocolVersion = rhs.mProtocolVersion;
59 mTransport = rhs.mTransport;
60 mSentHost = rhs.mSentHost;
61 mSentPort = rhs.mSentPort;
62 }
63 return *this;
64 }
65
66 ParserCategory *
67 Via::clone() const
68 {
69 return new Via(*this);
70 }
71
72 Data&
73 Via::protocolName()
74 {
75 checkParsed();
76 return mProtocolName;
77 }
78
79 const Data&
80 Via::protocolName() const
81 {
82 checkParsed();
83 return mProtocolName;
84 }
85
86 Data&
87 Via::protocolVersion()
88 {
89 checkParsed();
90 return mProtocolVersion;
91 }
92
93 const Data&
94 Via::protocolVersion() const
95 {
96 checkParsed();
97 return mProtocolVersion;
98 }
99
100 Data& Via::
101 transport()
102 {
103 checkParsed();
104 return mTransport;
105 }
106
107 const Data& Via::
108 transport() const
109 {
110 checkParsed();
111 return mTransport;
112 }
113
114 Data&
115 Via::sentHost()
116 {
117 checkParsed();
118 return mSentHost;
119 }
120
121 const Data&
122 Via::sentHost() const
123 {
124 checkParsed();
125 return mSentHost;
126 }
127
128 int&
129 Via::sentPort()
130 {
131 checkParsed();
132 return mSentPort;
133 }
134
135 int
136 Via::sentPort() const
137 {
138 checkParsed();
139 return mSentPort;
140 }
141
142 void
143 Via::parse(ParseBuffer& pb)
144 {
145 const char* startMark;
146 startMark = pb.skipWhitespace();
147 pb.skipToOneOf(ParseBuffer::Whitespace, Symbols::SLASH);
148 pb.data(mProtocolName, startMark);
149 pb.skipToChar('/');
150 pb.skipChar();
151 startMark = pb.skipWhitespace();
152 pb.skipToOneOf(ParseBuffer::Whitespace, Symbols::SLASH);
153 pb.data(mProtocolVersion, startMark);
154
155 pb.skipToChar('/');
156 pb.skipChar();
157 startMark = pb.skipWhitespace();
158
159 // !jf! this should really be skipTokenChar() since for instance, if the
160 // protocol token is missing it will read the rest of the Via into this field
161 pb.skipNonWhitespace();
162 pb.data(mTransport, startMark);
163
164 startMark = pb.skipWhitespace();
165 pb.assertNotEof();
166 if (*startMark == '[')
167 {
168 startMark = pb.skipChar();
169 pb.skipToChar(']');
170 pb.data(mSentHost, startMark);
171 DnsUtil::canonicalizeIpV6Address(mSentHost);
172 pb.skipChar();
173 }
174 else
175 {
176 pb.skipToOneOf(";:");
177 pb.data(mSentHost, startMark);
178 }
179
180 pb.skipToOneOf(";:");
181 if (!pb.eof() && *pb.position() == ':')
182 {
183 startMark = pb.skipChar(':');
184 mSentPort = pb.integer();
185 pb.skipToOneOf(ParseBuffer::Whitespace, Symbols::SEMI_COLON);
186 }
187 else
188 {
189 mSentPort = 0;
190 }
191 parseParameters(pb);
192 }
193
194 ostream&
195 Via::encodeParsed(ostream& str) const
196 {
197 str << mProtocolName << Symbols::SLASH << mProtocolVersion << Symbols::SLASH << mTransport
198 << Symbols::SPACE;
199
200 if (DnsUtil::isIpV6Address(mSentHost))
201 {
202 str << '[' << mSentHost << ']';
203 }
204 else
205 {
206 str << mSentHost;
207 }
208
209 if (mSentPort != 0)
210 {
211 str << Symbols::COLON << mSentPort;
212 }
213 encodeParameters(str);
214 return str;
215 }
216
217 /* ====================================================================
218 * The Vovida Software License, Version 1.0
219 *
220 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
221 *
222 * Redistribution and use in source and binary forms, with or without
223 * modification, are permitted provided that the following conditions
224 * are met:
225 *
226 * 1. Redistributions of source code must retain the above copyright
227 * notice, this list of conditions and the following disclaimer.
228 *
229 * 2. Redistributions in binary form must reproduce the above copyright
230 * notice, this list of conditions and the following disclaimer in
231 * the documentation and/or other materials provided with the
232 * distribution.
233 *
234 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
235 * and "Vovida Open Communication Application Library (VOCAL)" must
236 * not be used to endorse or promote products derived from this
237 * software without prior written permission. For written
238 * permission, please contact vocal@vovida.org.
239 *
240 * 4. Products derived from this software may not be called "VOCAL", nor
241 * may "VOCAL" appear in their name, without prior written
242 * permission of Vovida Networks, Inc.
243 *
244 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
245 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
246 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
247 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
248 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
249 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
250 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
251 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
252 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
253 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
255 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
256 * DAMAGE.
257 *
258 * ====================================================================
259 *
260 * This software consists of voluntary contributions made by Vovida
261 * Networks, Inc. and many individuals on behalf of Vovida Networks,
262 * Inc. For more information on Vovida Networks, Inc., please see
263 * <http://www.vovida.org/>.
264 *
265 */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27