-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocation.cpp
More file actions
180 lines (157 loc) · 4.56 KB
/
Copy pathLocation.cpp
File metadata and controls
180 lines (157 loc) · 4.56 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
#include "Location.hpp"
Location::Location(): location("") , method(""), root("") , defaultt("") , upload("") , redirect("")
{
}
Location::~Location()
{
}
void Location::setLocation(std::string const &rot)
{
std::string tmp = rot;
if (tmp == "")
throwError(EMPTY, "location");
if(tmp[tmp.size() - 1] == '[')
tmp.erase(tmp.size() - 1);
else
throwError(SYN, "location");
if (location == "")
location = fixIt(tmp);
else
throwError(DUP , "location");
}
std::string const & Location::getLocation()const
{
return location;
}
void Location::setMethod(std::string const &rot)
{
if (rot == "")
throwError(EMPTY, "method");
if (method == "")
method = rot;
else
throwError(DUP , "method");
}
std::string const & Location::getMethod()const
{
return method;
}
void Location::setAutoindex(std::string const &rot)
{
if (rot == "")
throwError(EMPTY, "autoindex");
if (rot == "on")
autoindex = true;
else if (rot == "off")
autoindex = false;
else
throwError(IVA, "autoindex");
}
bool Location::getAutoindex()const
{
return autoindex;
}
void Location::setDefaultt(std::string const &rot)
{
if (rot == "")
throwError(EMPTY, "default");
if (defaultt == "")
defaultt = fixIt(rot);
else
throwError(DUP , "default");
}
std::string const & Location::getDefaultt()const
{
return defaultt;
}
void Location::setUpload(std::string const &rot)
{
if (rot == "")
throwError(EMPTY, "upload");
if (upload == "")
upload = rot;
else
throwError(DUP , "upload");
}
std::string const & Location::getUpload()const
{
return upload;
}
void Location::setRoot(std::string const &rot)
{
if (rot == "")
throwError(EMPTY, "root");
if (root == "")
root = rot;
else
throwError(DUP, "root");
}
void Location::setRedirect(std::string const &rot)
{
if (redirect == "")
redirect = rot;
else
throwError(DUP, "redirect");
}
std::string const & Location::getRedirect()const
{
return redirect;
}
std::string const & Location::getRoot()const
{
return root;
}
void Location::debug()
{
std::cout <<"--------------------------------------------------------" << std::endl;
std::cout << std::setw(5) << red << "location :" << reset << location << std::endl;
std::cout << std::setw(5) << red << "method :" << reset << method << std::endl;
std::cout << std::setw(5) << red << "root :" << reset << root<< std::endl;
std::cout << std::setw(5) << red << "autoindex :" << reset << autoindex << std::endl;
std::cout << std::setw(5) << red << "defaultt :" << reset << defaultt << std::endl;
std::cout << std::setw(5) << red << "upload :" << reset << upload << std::endl;
std::cout <<"--------------------------------------------------------" << std::endl;
}
void Location::throwError(int type, std::string para)
{
std::string nb = std::to_string(line);
nb = "Line : " + nb;
std::stringstream errr(nb);
switch (type)
{
case DUP :
errr << red <<nb << reset << " ERROR Duplicated Parameter " << para ;
break;
case EMPTY :
errr << red <<nb << reset << " ERROR Empty Parameter " << para ;
case IVA :
errr << red <<nb << reset << " ERROR Invalid Parameter " << para ;
break;
}
throw errr.str();
}
Location &Location::operator=(Location const & src)
{
location = src.getLocation();
method = src.getMethod();
root = src.getRoot();
autoindex =src.getAutoindex();
defaultt = src.getDefaultt();
upload = src.getUpload();
redirect = src.getRedirect();
cgimap = src.getCgiMap();
return (*this);
}
Location::Location(Location const & src)
{
*this = src;
// std::cout << yellow << "ya salam \n";
}
void Location::addtoCgiMap(std::string key, std::string val)
{
cgimap.insert(std::make_pair(key, val));
}
std::map<std::string, std::string> const & Location::getCgiMap() const
{
return cgimap;
}