50 |
|
|
51 |
|
#include "URL.hpp" |
52 |
|
|
53 |
– |
URL::URL(const string& url) |
54 |
– |
{ |
55 |
– |
setURL(url); |
56 |
– |
} |
57 |
– |
|
58 |
– |
URL::URL(const string& address, unsigned port, const string& path) |
59 |
– |
{ |
60 |
– |
this->address = address; |
61 |
– |
this->port = port; |
62 |
– |
this->path = path; |
63 |
– |
#ifdef _OpenSSL_ |
64 |
– |
tls = false; |
65 |
– |
#endif |
66 |
– |
} |
67 |
– |
|
68 |
– |
#ifdef _OpenSSL_ |
69 |
– |
URL::URL(const string& address, unsigned port, const string& path, bool tls) |
70 |
– |
{ |
71 |
– |
this->address = address; |
72 |
– |
this->port = port; |
73 |
– |
this->path = path; |
74 |
– |
this->tls = tls; |
75 |
– |
} |
76 |
– |
#endif |
77 |
– |
|
53 |
|
string URL::getURL() |
54 |
|
{ |
55 |
|
ostringstream url; |
56 |
+ |
|
57 |
|
#ifndef _OpenSSL_ |
58 |
|
url << "http://" << address; |
59 |
|
|
91 |
|
exit(1); |
92 |
|
} |
93 |
|
|
94 |
< |
unsigned begin = 7; |
94 |
> |
unsigned begin(7); |
95 |
> |
|
96 |
|
#else |
97 |
|
tls = false; |
98 |
|
|
103 |
|
else if (url.find("http://") != 0 || url.length() <= 7) |
104 |
|
{ |
105 |
|
cerr << program << ": Malformed URL: " << url << "\n"; |
106 |
+ |
|
107 |
|
exit(1); |
108 |
|
} |
109 |
|
|
110 |
< |
unsigned begin = tls ? 8 : 7; |
110 |
> |
unsigned begin(tls ? 8 : 7); |
111 |
|
#endif |
112 |
< |
unsigned colon = url.find(':', begin); |
113 |
< |
unsigned end = url.find('/', begin); |
112 |
> |
|
113 |
> |
unsigned colon(url.find(':', begin)), end(url.find('/', begin)); |
114 |
|
|
115 |
|
if (colon != string::npos && colon < end) |
116 |
|
{ |
161 |
|
|
162 |
|
string getLink(string link, URL& url) |
163 |
|
{ |
164 |
< |
string hyperlink = ""; |
164 |
> |
string hyperlink; |
165 |
|
|
166 |
|
if (link.find('#') != string::npos) |
167 |
|
{ |
168 |
< |
unsigned pound = link.find('#'); |
168 |
> |
unsigned pound(link.find('#')); |
169 |
> |
|
170 |
|
link.erase(pound); |
171 |
|
} |
172 |
|
|
187 |
|
{ |
188 |
|
// do nothing this isn't Google Groups |
189 |
|
} |
190 |
+ |
else if (link.find("aim:") == 0) |
191 |
+ |
{ |
192 |
+ |
// do nothing we don't do AIM |
193 |
+ |
} |
194 |
|
else if (link.find("//") == 0) |
195 |
|
{ |
196 |
|
#ifndef _OpenSSL_ |
204 |
|
hyperlink = url.getURL(); |
205 |
|
|
206 |
|
#ifndef _OpenSSL_ |
207 |
< |
unsigned path = hyperlink.find('/', 7); |
207 |
> |
unsigned path(hyperlink.find('/', 7)); |
208 |
|
#else |
209 |
< |
unsigned path = hyperlink.find('/', url.getTls() ? 8 : 7); |
209 |
> |
unsigned path(hyperlink.find('/', url.getTls() ? 8 : 7)); |
210 |
|
#endif |
211 |
+ |
|
212 |
|
hyperlink.erase(path); |
213 |
|
|
214 |
|
hyperlink += link; |
220 |
|
else |
221 |
|
{ |
222 |
|
hyperlink = url.getURL(); |
239 |
– |
string path = url.getPath(); |
223 |
|
|
224 |
< |
unsigned cutoff = hyperlink.rfind(path); |
224 |
> |
string path(url.getPath()); |
225 |
> |
unsigned cutoff(hyperlink.rfind(path)); |
226 |
> |
|
227 |
|
hyperlink.erase(cutoff); |
228 |
|
|
229 |
< |
unsigned dir = path.rfind('/') + 1; |
229 |
> |
unsigned dir(path.rfind('/') + 1); |
230 |
> |
|
231 |
|
path.erase(dir); |
232 |
|
|
233 |
|
while (link.find("../") == 0) |
234 |
|
{ |
235 |
< |
unsigned dot = path.rfind('/') - 1; |
250 |
< |
unsigned up = path.rfind('/', dot) + 1; |
235 |
> |
unsigned dot(path.rfind('/') - 1), up(path.rfind('/', dot) + 1); |
236 |
|
|
237 |
|
path.erase(up); |
238 |
|
link.erase(0, 3); |