4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
– |
#include "Bender.hpp" |
7 |
|
#include "Matcher/Matcher.hpp" |
8 |
|
|
9 |
< |
#include <menes-api/exename.hpp> |
9 |
> |
#include <menes-api/console.hpp> |
10 |
> |
#include <menes-api/environment.hpp> |
11 |
|
#include <menes-api/files.hpp> |
12 |
|
#include <menes-api/process.hpp> |
13 |
|
#include <menes-app/simple.hpp> |
14 |
+ |
#include <menes-ios/helpers.hpp> |
15 |
|
|
16 |
< |
struct |
16 |
> |
class Bender |
17 |
|
{ |
18 |
< |
ext::String get(const ext::String& name) |
19 |
< |
{ |
20 |
< |
try |
21 |
< |
{ |
22 |
< |
return api::TheEnvironment.Get(name); |
23 |
< |
} |
24 |
< |
catch (ext::Exception) |
25 |
< |
{ |
26 |
< |
return ext::String(); |
27 |
< |
} |
28 |
< |
} |
18 |
> |
private: |
19 |
> |
void bend(const ext::String& path, const ext::String& agent); |
20 |
> |
void bend(const ext::String& path); |
21 |
> |
void pass(const ext::String& path); |
22 |
> |
public: |
23 |
> |
Bender(); |
24 |
> |
}; |
25 |
> |
|
26 |
> |
struct Environment |
27 |
> |
{ |
28 |
> |
ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } } |
29 |
|
} env; |
30 |
|
|
31 |
|
int Main(const app::Options& options) |
48 |
|
|
49 |
|
bend(path, env.get("HTTP_USER_AGENT")); |
50 |
|
} |
51 |
< |
catch (ext::Exception e) |
51 |
> |
catch (ext::Exception) |
52 |
|
{ |
53 |
|
api::Cout << "Status: 404\r\n" |
54 |
|
<< "Content-Type: text/html; charset=ISO-8859-1\r\n\r\n" |
63 |
|
<< env.get("SERVER_SIGNATURE") << "</body></html>\n"; |
64 |
|
} |
65 |
|
} |
66 |
< |
else |
66 |
< |
{ |
67 |
< |
api::Cout << "Location: http://computers.douglasthrift.net/bender.xml\r\n\r\n"; |
68 |
< |
} |
66 |
> |
else api::Cout << "Location: http://computers.douglasthrift.net/bender.xml\r\n\r\n"; |
67 |
|
} |
68 |
|
|
69 |
|
void Bender::bend(const ext::String& path, const ext::String& agent) |
70 |
|
{ |
71 |
|
Matcher matcher; |
72 |
|
|
73 |
< |
if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)")) |
76 |
< |
{ |
77 |
< |
bend(path); |
78 |
< |
} |
79 |
< |
else if (agent == matcher("rv:(\\d+)\\.(\\d+).*\\) Gecko")) |
73 |
> |
if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)")) bend(path); else if (agent == matcher("rv:(\\d+)\\.(\\d+).*\\) Gecko")) |
74 |
|
{ |
75 |
|
int major_(lexical_cast<int>(matcher[1])), minor_(lexical_cast<int>(matcher[2])); |
76 |
|
|
77 |
< |
if (major_ > 1 || (major_ == 1 && minor_ >= 5)) |
84 |
< |
{ |
85 |
< |
pass(path); |
86 |
< |
} |
87 |
< |
else bend(path); |
77 |
> |
if (major_ > 1 || (major_ == 1 && minor_ >= 5)) pass(path); else bend(path); |
78 |
|
} |
79 |
|
else bend(path); |
80 |
|
} |
106 |
|
api::Cout << "Content-Type: " << type << "\r\n\r\n" << output; |
107 |
|
} |
108 |
|
else pass(path); |
119 |
– |
|
120 |
– |
xslt.Join(); |
109 |
|
} |
110 |
|
|
111 |
|
void Bender::pass(const ext::String& path) |