1 |
// Bender |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#include "Bender.hpp" |
8 |
#include "Matcher.hpp" |
9 |
|
10 |
#include <xalanc/Include/PlatformDefinitions.hpp> |
11 |
#include <xercesc/util/PlatformUtils.hpp> |
12 |
#include <xalanc/XalanTransformer/XalanTransformer.hpp> |
13 |
|
14 |
XALAN_USING_XERCES(XMLPlatformUtils) |
15 |
XALAN_USING_XALAN(XalanTransformer) |
16 |
|
17 |
int main(int argc, char* argv[]) |
18 |
{ |
19 |
XMLPlatformUtils::Initialize(); |
20 |
XalanTransformer::initialize(); |
21 |
|
22 |
Bender bender; |
23 |
|
24 |
XalanTransformer::terminate(); |
25 |
XMLPlatformUtils::Terminate(); |
26 |
XalanTransformer::ICUCleanUp(); |
27 |
|
28 |
return 0; |
29 |
} |
30 |
|
31 |
Bender::Bender() |
32 |
{ |
33 |
string path = sgetenv("PATH_TRANSLATED"); |
34 |
ifstream file(path.c_str()); |
35 |
|
36 |
if (path != "" && file.is_open()) |
37 |
{ |
38 |
string line; |
39 |
|
40 |
do |
41 |
{ |
42 |
getline(file, line); |
43 |
|
44 |
buffer << line << "\n"; |
45 |
} |
46 |
while (file.good()); |
47 |
|
48 |
bend(sgetenv("HTTP_USER_AGENT")); |
49 |
} |
50 |
else |
51 |
{ |
52 |
cout << "Status: 404\n" |
53 |
<< "Content-Type: text/html; charset=ISO-8859-1\n\n" |
54 |
<< "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" |
55 |
<< "<html><head>\n" |
56 |
<< "<title>404 Not Found</title>\n" |
57 |
<< "</head><body>\n" |
58 |
<< "<h1>Not Found</h1>\n" |
59 |
<< "<p>The requested URL " << sgetenv("PATH_INFO") << " was not fo" |
60 |
<< "und on this server.</p>\n" |
61 |
<< "<hr />\n" |
62 |
<< sgetenv("SERVER_SIGNATURE") |
63 |
<< "</body></html>\n"; |
64 |
} |
65 |
} |
66 |
|
67 |
void Bender::bend(const string& agent) |
68 |
{ |
69 |
Matcher matcher; |
70 |
|
71 |
if (agent == matcher("/Opera |\\/(\\d+)\\.(\\d+)/")) |
72 |
{ |
73 |
bend(); |
74 |
} |
75 |
else if (agent == matcher( |
76 |
"/^Mozilla/4.0 \\(compatible; MSIE (\\d+)\\.(\\d+)(\\w+)?; .*\\)$/")) |
77 |
{ |
78 |
// |
79 |
} |
80 |
else if (agent == matcher( |
81 |
"/^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(\\.d+)?(\\w+)?\\) Gecko\\/.*/" |
82 |
)) |
83 |
{ |
84 |
// |
85 |
} |
86 |
else |
87 |
{ |
88 |
bend(); |
89 |
} |
90 |
} |
91 |
|
92 |
void Bender::bend(void) |
93 |
{ |
94 |
// |
95 |
} |