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