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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27