reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
WsCookieContext.cxx
Go to the documentation of this file.
4#include "rutil/Data.hxx"
5#include "rutil/Logger.hxx"
6
7using namespace resip;
8
9#define RESIPROCATE_SUBSYSTEM Subsystem::TRANSPORT
10
14
16{
17 mWsSessionInfo = rhs.getWsSessionInfo();
18 mWsSessionExtra = rhs.getWsSessionExtra();
19 mWsSessionMAC = rhs.getWsSessionMAC();
20 mWsFromUri = rhs.getWsFromUri();
21 mWsDestUri = rhs.getWsDestUri();
22 mExpiresTime = rhs.getExpiresTime();
23}
24
25
27{
28 if(this != &rhs)
29 {
30 mWsSessionInfo = rhs.getWsSessionInfo();
31 mWsSessionExtra = rhs.getWsSessionExtra();
32 mWsSessionMAC = rhs.getWsSessionMAC();
33 mWsFromUri = rhs.getWsFromUri();
34 mWsDestUri = rhs.getWsDestUri();
35 mExpiresTime = rhs.getExpiresTime();
36 }
37 return *this;
38}
39
40WsCookieContext::WsCookieContext(const CookieList& cookieList, const Data& infoCookieName, const Data& extraCookieName, const Data& macCookieName, const Uri& requestUri)
41{
42 for (CookieList::const_iterator it = cookieList.begin(); it != cookieList.end(); ++it)
43 {
44 if ((*it).name() == infoCookieName)
45 {
46 mWsSessionInfo = (*it).value();
47 }
48 else if ((*it).name() == extraCookieName)
49 {
50 mWsSessionExtra = (*it).value();
51 }
52 else if ((*it).name() == macCookieName)
53 {
54 mWsSessionMAC = (*it).value();
55 }
56 }
57
58 // If present, parameters in the request URI override those in the cookies
59 UnknownParameterType pInfo(infoCookieName);
60 if(requestUri.exists(pInfo))
61 {
62 mWsSessionInfo = requestUri.param(pInfo).urlDecoded();
63 }
64 UnknownParameterType pExtra(extraCookieName);
65 if(requestUri.exists(pExtra))
66 {
67 mWsSessionExtra = requestUri.param(pExtra).urlDecoded();
68 }
69 UnknownParameterType pMac(macCookieName);
70 if(requestUri.exists(pMac))
71 {
72 mWsSessionMAC = requestUri.param(pMac).urlDecoded();
73 }
74
75 if(mWsSessionInfo.empty())
76 {
77 ErrLog(<<"Cookie " << infoCookieName << " missing or empty");
78 throw Transport::Exception("Required cookie missing", __FILE__, __LINE__);
79 }
80 if(mWsSessionMAC.empty())
81 {
82 ErrLog(<<"Cookie " << macCookieName << " missing or empty");
83 throw Transport::Exception("Required cookie missing", __FILE__, __LINE__);
84 }
85
86 ParseBuffer pb(mWsSessionInfo);
87 StackLog(<<"Checking Cookie scheme version");
88 int contextVersion = pb.uInt32();
89 if(contextVersion != RESIP_WS_COOKIE_CONTEXT_VERSION)
90 {
91 // Cookie created for another version of the code
92 ErrLog(<<"Expecting cookie version " << RESIP_WS_COOKIE_CONTEXT_VERSION << " but found " << contextVersion);
93 throw ParseException("Cookie version mismatch", pb.getContext(), __FILE__, __LINE__);
94 }
95 pb.skipToChar(':');
96 pb.skipChar(':');
97
98 pb.skipToChar(':'); // skip the creation time
99 pb.skipChar(':');
100 mExpiresTime = (time_t) pb.uInt64();
101
102 const char* anchor;
103 Data uriString;
104
105 pb.skipToChar(':');
106 pb.skipChar(':');
107 anchor = pb.position();
108 pb.skipToChar(':');
109 pb.data(uriString, anchor);
110 mWsFromUri = Uri("sip:" + uriString);
111
112 pb.skipChar(':');
113 anchor = pb.position();
114 pb.skipToChar(':');
115 pb.data(uriString, anchor);
116 mWsDestUri = Uri("sip:" + uriString);
117}
118
122
123
124/* ====================================================================
125 * BSD License
126 *
127 * Copyright (c) 2013 Catalin Constantin Usurelu All rights reserved.
128 *
129 * Redistribution and use in source and binary forms, with or without
130 * modification, are permitted provided that the following conditions
131 * are met:
132 *
133 * 1. Redistributions of source code must retain the above copyright
134 * notice, this list of conditions and the following disclaimer.
135 *
136 * 2. Redistributions in binary form must reproduce the above copyright
137 * notice, this list of conditions and the following disclaimer in
138 * the documentation and/or other materials provided with the
139 * distribution.
140 *
141 * 3. Neither the name of the author(s) nor the names of any contributors
142 * may be used to endorse or promote products derived from this software
143 * without specific prior written permission.
144 *
145 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
146 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
147 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
148 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
149 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
150 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
151 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
152 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
153 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
154 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
155 * SUCH DAMAGE.
156 *
157 * ====================================================================
158 *
159 */
#define StackLog(args_)
Definition Logger.hxx:125
#define ErrLog(args_)
Definition Logger.hxx:137
#define RESIP_WS_COOKIE_CONTEXT_VERSION
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
Data urlDecoded() const
Performs in-place HTTP URL un-escaping of a Data.
Definition Data.cxx:1341
Provides string-parsing functionality with protection from buffer overflow.
uint32_t uInt32()
dcm! – merge these, ask about length checks
CurrentPosition skipToChar(char c)
CurrentPosition position() const
const Data & getContext() const
CurrentPosition skipChar()
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
BaseException used to indicate parse failures.
General exception class for Transport.
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
bool exists(const Param< Uri > &paramType) const
Definition Uri.cxx:1701
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
WsCookieContext & operator=(const WsCookieContext &rhs)
time_t getExpiresTime() const
dcm! – add UnusedChecking(_enum) below;
std::vector< Cookie > CookieList
Definition Cookie.hxx:35