/src/resiprocate/resip/stack/QValueParameter.hxx
Line | Count | Source |
1 | | #if !defined(RESIP_QVALUEPARAMETER_HXX) |
2 | | #define RESIP_QVALUEPARAMETER_HXX |
3 | | |
4 | | #include "rutil/resipfaststreams.hxx" |
5 | | |
6 | | #include "resip/stack/Parameter.hxx" |
7 | | #include "resip/stack/ParameterTypeEnums.hxx" |
8 | | #include "resip/stack/QValue.hxx" |
9 | | #include "rutil/PoolBase.hxx" |
10 | | #include <iosfwd> |
11 | | |
12 | | namespace resip |
13 | | { |
14 | | |
15 | | class ParseBuffer; |
16 | | |
17 | | /** |
18 | | @ingroup sip_grammar |
19 | | |
20 | | @brief Represents the "q" parameter value of the RFC 3261 grammar. |
21 | | |
22 | | @see Parameter |
23 | | |
24 | | First reference to q-values in 3261 reproduced here: |
25 | | |
26 | | 8.1.3.4 Processing 3xx Responses |
27 | | |
28 | | Upon receipt of a redirection response (for example, a 301 response |
29 | | status code), clients SHOULD use the URI(s) in the Contact header |
30 | | field to formulate one or more new requests based on the redirected |
31 | | request. This process is similar to that of a proxy recursing on a |
32 | | 3xx class response as detailed in Sections 16.5 and 16.6. A client |
33 | | starts with an initial target set containing exactly one URI, the |
34 | | Request-URI of the original request. If a client wishes to formulate |
35 | | new requests based on a 3xx class response to that request, it places |
36 | | the URIs to try into the target set. Subject to the restrictions in |
37 | | this specification, a client can choose which Contact URIs it places |
38 | | into the target set. As with proxy recursion, a client processing |
39 | | 3xx class responses MUST NOT add any given URI to the target set more |
40 | | than once. If the original request had a SIPS URI in the Request- |
41 | | URI, the client MAY choose to recurse to a non-SIPS URI, but SHOULD |
42 | | inform the user of the redirection to an insecure URI. |
43 | | |
44 | | Any new request may receive 3xx responses themselves containing |
45 | | the original URI as a contact. Two locations can be configured to |
46 | | redirect to each other. Placing any given URI in the target set |
47 | | only once prevents infinite redirection loops. |
48 | | |
49 | | As the target set grows, the client MAY generate new requests to the |
50 | | URIs in any order. A common mechanism is to order the set by the "q" |
51 | | parameter value from the Contact header field value. Requests to the |
52 | | URIs MAY be generated serially or in parallel. One approach is to |
53 | | process groups of decreasing q-values serially and process the URIs |
54 | | in each q-value group in parallel. Another is to perform only serial |
55 | | processing in decreasing q-value order, arbitrarily choosing between |
56 | | contacts of equal q-value. |
57 | | */ |
58 | | class QValueParameter : public Parameter |
59 | | { |
60 | | public: |
61 | | typedef QValue Type; |
62 | | |
63 | | /** |
64 | | @brief constructor |
65 | | @param type used to initialize Parameter |
66 | | @param pb input is expected to be in the format " = qvalue" |
67 | | The blanks before and after the "=" sign are optional in this |
68 | | implementation. But absence of "=" will throw a ParseException. |
69 | | @param terminators not used |
70 | | @see Parameter |
71 | | @throw ParseException |
72 | | */ |
73 | | QValueParameter(ParameterTypes::Type, ParseBuffer& pb, const std::bitset<256>& terminators); |
74 | | /** |
75 | | @brief constructor creates object and sets q value to zero |
76 | | @param type used to initialize Parameter |
77 | | @throw nothing |
78 | | */ |
79 | | explicit QValueParameter(ParameterTypes::Type type); |
80 | | |
81 | | /** |
82 | | @brief creates a QValueParameter object and returns a pointer to it. |
83 | | @param type used to initialize Parameter |
84 | | @param pb input is expected to be in the format " = qvalue" |
85 | | The blanks before and after the "=" sign are optional in this |
86 | | implementation. But absence of "=" will throw a ParseException. |
87 | | @param terminators not used |
88 | | @return a new QValueParameter object that is a copy of this one. |
89 | | @throw ParseException |
90 | | */ |
91 | | static Parameter* decode(ParameterTypes::Type type, |
92 | | ParseBuffer& pb, |
93 | | const std::bitset<256>& terminators, |
94 | | PoolBase* pool) |
95 | 3.51k | { |
96 | 3.51k | return new (pool) QValueParameter(type, pb, terminators); |
97 | 3.51k | } |
98 | | |
99 | | /** |
100 | | @brief creates a new QValueParameter object that is a copy of this one. |
101 | | @return a new QValueParameter object that is a copy of this one. |
102 | | */ |
103 | | virtual Parameter* clone() const; |
104 | | |
105 | | /** |
106 | | @brief returns "q=3" or equivalent in the stream it receives |
107 | | @param stream ostream to write into |
108 | | @return ostream with information written into it |
109 | | */ |
110 | | virtual EncodeStream& encode(EncodeStream& stream) const; |
111 | | |
112 | 0 | Type& value() {return mValue;} |
113 | 0 | int qval() const {return mValue.getValue();} |
114 | | |
115 | | private: |
116 | | Type mValue; |
117 | | }; |
118 | | |
119 | | /** |
120 | | @brief calls encode and returns "q=3" or equivalent ostream |
121 | | @param stream ostream to write into |
122 | | @param qvalue qvalue |
123 | | @return ostream with q value divided by 1000 and expressed in decimal to |
124 | | 3 decimal places |
125 | | @see QValue |
126 | | */ |
127 | | EncodeStream& operator<<(EncodeStream& stream, const QValue& qvalue); |
128 | | |
129 | | } |
130 | | |
131 | | #endif |
132 | | |
133 | | /* ==================================================================== |
134 | | * The Vovida Software License, Version 1.0 |
135 | | * |
136 | | * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. |
137 | | * |
138 | | * Redistribution and use in source and binary forms, with or without |
139 | | * modification, are permitted provided that the following conditions |
140 | | * are met: |
141 | | * |
142 | | * 1. Redistributions of source code must retain the above copyright |
143 | | * notice, this list of conditions and the following disclaimer. |
144 | | * |
145 | | * 2. Redistributions in binary form must reproduce the above copyright |
146 | | * notice, this list of conditions and the following disclaimer in |
147 | | * the documentation and/or other materials provided with the |
148 | | * distribution. |
149 | | * |
150 | | * 3. The names "VOCAL", "Vovida Open Communication Application Library", |
151 | | * and "Vovida Open Communication Application Library (VOCAL)" must |
152 | | * not be used to endorse or promote products derived from this |
153 | | * software without prior written permission. For written |
154 | | * permission, please contact vocal@vovida.org. |
155 | | * |
156 | | * 4. Products derived from this software may not be called "VOCAL", nor |
157 | | * may "VOCAL" appear in their name, without prior written |
158 | | * permission of Vovida Networks, Inc. |
159 | | * |
160 | | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
161 | | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
162 | | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND |
163 | | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA |
164 | | * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES |
165 | | * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, |
166 | | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
167 | | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
168 | | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
169 | | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
170 | | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
171 | | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
172 | | * DAMAGE. |
173 | | * |
174 | | * ==================================================================== |
175 | | * |
176 | | * This software consists of voluntary contributions made by Vovida |
177 | | * Networks, Inc. and many individuals on behalf of Vovida Networks, |
178 | | * Inc. For more information on Vovida Networks, Inc., please see |
179 | | * <http://www.vovida.org/>. |
180 | | * |
181 | | */ |