forked from artyom-beilis/cppcms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmount_point.cpp
More file actions
236 lines (203 loc) · 4.69 KB
/
mount_point.cpp
File metadata and controls
236 lines (203 loc) · 4.69 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#define CPPCMS_SOURCE
#include <cppcms/mount_point.h>
#include <booster/regex.h>
namespace cppcms {
struct mount_point::_data {};
mount_point::mount_point() :
group_(0),
selection_(match_path_info)
{
}
mount_point::mount_point(std::string const &path,int group) :
path_info_(path),
group_(group),
selection_(match_path_info)
{
}
mount_point::mount_point(std::string const &script) :
script_name_(script),
group_(0),
selection_(match_path_info)
{
}
mount_point::mount_point(std::string const &script,std::string const &path,int group) :
script_name_(script),
path_info_(path),
group_(group),
selection_(match_path_info)
{
}
mount_point::mount_point(mount_point::selection_type sel,std::string const &selected,int group) :
group_(group),
selection_(sel)
{
if(sel == match_path_info)
path_info_ = booster::regex(selected);
else
script_name_ = booster::regex(selected);
}
mount_point::mount_point(mount_point::selection_type sel,std::string const &non,std::string const &selected,int group) :
group_(group),
selection_(sel)
{
if(sel == match_path_info) {
path_info_ = booster::regex(selected);
script_name_ = booster::regex(non);
}
else {
script_name_ = booster::regex(selected);
path_info_ = booster::regex(non);
}
}
mount_point::mount_point(mount_point::selection_type sel,std::string const &non) :
group_(0),
selection_(sel)
{
if(sel == match_path_info) {
script_name_ = booster::regex(non);
}
else {
path_info_ = booster::regex(non);
}
}
mount_point::mount_point( selection_type sel,
booster::regex const &http_host,
booster::regex const &script,
booster::regex const &path,
int group)
: host_(http_host),
script_name_(script),
path_info_(path),
group_(group),
selection_(sel)
{
}
mount_point::~mount_point()
{
}
mount_point::mount_point(mount_point const &other) :
host_(other.host_),
script_name_(other.script_name_),
path_info_(other.path_info_),
group_(other.group_),
selection_(other.selection_)
{
}
mount_point const &mount_point::operator=(mount_point const &other)
{
if(this!=&other) {
host_ = other.host_;
script_name_ = other.script_name_;
path_info_ = other.path_info_;
group_ = other.group_;
selection_ = other.selection_;
}
return *this;
}
void mount_point::host(booster::regex const &h)
{
host_ = h;
}
void mount_point::script_name(booster::regex const &s)
{
script_name_ = s;
}
void mount_point::path_info(booster::regex const &p)
{
path_info_ = p;
}
void mount_point::group(int g)
{
group_ = g;
}
void mount_point::selection(mount_point::selection_type s)
{
selection_ = s;
}
booster::regex mount_point::host() const
{
return host_;
}
booster::regex mount_point::script_name() const
{
return script_name_;
}
booster::regex mount_point::path_info() const
{
return path_info_;
}
int mount_point::group() const
{
return group_;
}
mount_point::selection_type mount_point::selection() const
{
return selection_;
}
std::pair<bool,std::string> mount_point::match(std::string const &h,std::string const &s,std::string const &p) const
{
return match(h.c_str(),s.c_str(),p.c_str());
}
std::pair<bool,std::string> mount_point::match(char const *h,char const *s,char const *p) const
{
std::pair<bool,std::string> res;
res.first = false;
if(!host_.empty() && !booster::regex_match(h,host_))
return res;
if(selection_ == match_path_info) {
if(!script_name_.empty() && !booster::regex_match(s,script_name_))
return res;
if(path_info_.empty()) {
res.second = p;
res.first = true;
return res;
}
if(group_ == 0) {
if(!booster::regex_match(p,path_info_))
return res;
res.second=p;
res.first=true;
return res;
}
else {
booster::cmatch m;
if(!booster::regex_match(p,m,path_info_))
return res;
res.second=m[group_];
res.first = true;
return res;
}
}
else {
if(!path_info_.empty() && !booster::regex_match(p,path_info_))
return res;
if(script_name_.empty()) {
res.second=s;
res.first = true;
return res;
}
if(group_ == 0) {
if(!booster::regex_match(s,script_name_))
return res;
res.second=s;
res.first = true;
return res;
}
else {
booster::cmatch m;
if(!booster::regex_match(s,m,script_name_))
return res;
res.second=m[group_];
res.first = true;
return res;
}
}
}
} // cppcms