1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/*
Copyright (C) 2005-2009 Michel de Boer <michel@twinklephone.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Request
#ifndef _REQUEST_H
#define _REQUEST_H
#include <string>
#include "response.h"
#include "sip_message.h"
#include "sockets/url.h"
#include "user.h"
// Forward declaration
class t_user;
using namespace std;
class t_request : public t_sip_message {
private:
/**
* A DNS lookup on the request URI (or outbound proxy) might resolve
* into multiple destinations. @ref get_destination() will return the first
* destination. All destinations are stored here.
* @ref next_destination() will remove the first destination of this
* list.
*/
list<t_ip_port> destinations;
/**
* Indicates if the destination specified a transport, i.e. via the
* transport parameter in a URI.
*/
bool transport_specified;
/**
* Add destinations for a given URI based on transport settings.
* @param user_profile [in] User profile
* @param dst_uri [in] The URI to resolve.
*/
void add_destinations(const t_user &user_profile, const t_url &dst_uri);
/**
* Calculate credentials based on the challenge.
* @param chlg [in] The challenge
* @param user_config [in] User configuration for user to be authorized.
* @param username [in] User authentication name
* @param passwd [in] Authentication password.
* @param nc [in] Nonce count
* @param cnonce [in] Client nonce
* @param cr [out] Credentials on successful return.
* @param fail_reason [out] Failure reason on failure return.
* @return false, if authorization fails.
* @return true, if authorization succeeded
*/
bool authorize(const t_challenge &chlg, t_user *user_config,
const string &username, const string &passwd, unsigned long nc,
const string &cnonce, t_credentials &cr,
string &fail_reason) const;
/**
* Calculate MD5 response based on the challenge.
* @param chlg [in] The challenge
* @param username [in] User authentication name
* @param passwd [in] Authentication password.
* @param nc [in] Nonce count
* @param cnonce [in] Client nonce
* @param qop [in] Quality of protection
* @param resp [out] Response on successful return.
* @param fail_reason [out] Failure reason on failure return.
* @return false, if authorization fails.
* @return true, if authorization succeeded
*/
bool authorize_md5(const t_digest_challenge &dchlg,
const string &username, const string &passwd, unsigned long nc,
const string &cnonce, const string &qop, string &resp,
string &fail_reason) const;
/**
* Calculate AKAv1-MD5 response based on the challenge.
* @param chlg [in] The challenge
* @param username [in] User authentication name
* @param passwd [in] Authentication password.
* @param op [in] Operator variant key
* @param amf [in] Authentication method field
* @param nc [in] Nonce count
* @param cnonce [in] Client nonce
* @param qop [in] Quality of protection
* @param resp [out] Response on successful return.
* @param fail_reason [out] Failure reason on failure return.
* @return false, if authorization fails.
* @return true, if authorization succeeded
*/
bool authorize_akav1_md5(const t_digest_challenge &dchlg,
const string &username, const string &passwd,
uint8 *op, uint8 *amf,
unsigned long nc,
const string &cnonce, const string &qop, string &resp,
string &fail_reason) const;
public:
t_url uri;
t_method method;
string unknown_method; // set if method is UNKNOWN
t_request();
t_request(const t_request &r);
t_request(const t_method m);
t_msg_type get_type(void) const { return MSG_REQUEST; }
void set_method(const string &s);
string encode(bool add_content_length = true);
list<string> encode_env(void);
t_sip_message *copy(void) const;
/**
* Set the Request-URI and the Route header.
* This is done according to the procedures of RFC 3261 12.2.1.1
* @param target_uri [in] The URI of the destination for this request.
* @param route_set [in] The route set for this request (may be empty).
*/
void set_route(const t_url &target_uri, const list<t_route> &route_set);
// Create a response with response code based on the
// request. The response is created following the general
// rules in RFC 3261 8.2.6.2.
// The to-hdr is simply copied from the request to the
// response.
// If the to-tag is missing, then
// a to-tag will be generated and added to the to-header
// of the response.
// A specific reason may be added to the status code.
t_response *create_response(int code, string reason = "") const;
bool is_valid(bool &fatal, string &reason) const;
// Calculate the set of possible destinations for this request.
void calc_destinations(const t_user &user_profile);
// Get destination to send this request to.
void get_destination(t_ip_port &ip_port, const t_user &user_profile);
void get_current_destination(t_ip_port &ip_port);
// Move to next destination. This method should only be called after
// calc_destination() was called.
// Returns true if there is a next destination, otherwise returns false.
bool next_destination(void);
// Set a single destination to send this request to.
void set_destination(const t_ip_port &ip_port);
/**
* Create WWW authorization credentials based on the challenge.
* @param chlg [in] The challenge
* @param user_config [in] User configuration for user to be authorized.
* @param username [in] User authentication name
* @param passwd [in] Authentication password.
* @param nc [in] Nonce count
* @param cnonce [in] Client nonce
* @param cr [out] Credentials on successful return.
* @param fail_reason [out] Failure reason on failure return.
* @return false, if challenge is not supported.
* @return true, if authorization succeeded
*/
bool www_authorize(const t_challenge &chlg, t_user *user_config,
const string &username, const string &passwd, unsigned long nc,
const string &cnonce, t_credentials &cr, string &fail_reason);
/**
* Create proxy authorization credentials based on the challenge.
* @param chlg [in] The challenge
* @param user_config [in] User configuration for user to be authorized.
* @param username [in] User authentication name
* @param passwd [in] Authentication password.
* @param nc [in] Nonce count
* @param cnonce [in] Client nonce
* @param cr [out] Credentials on successful return.
* @param fail_reason [out] Failure reason on failure return.
* @return false, if challenge is not supported.
* @return true, if authorization succeeded
*/
bool proxy_authorize(const t_challenge &chlg, t_user *user_config,
const string &username, const string &passwd, unsigned long nc,
const string &cnonce, t_credentials &cr, string &fail_reason);
virtual void calc_local_ip(void);
/**
* Check if the request is a registration request.
* @return True if the request is a registration request, otherwise false.
*/
bool is_registration_request(void) const;
/**
* Check if the request is a de-registration request.
* @return True if the request is a de-registration request, otherwise false.
*/
bool is_de_registration_request(void) const;
};
#endif
|