18 |
|
{ |
19 |
|
XMLPlatformUtils::Initialize(); |
20 |
|
XalanTransformer::initialize(); |
21 |
< |
|
21 |
> |
|
22 |
|
Bender bender; |
23 |
|
|
24 |
|
XalanTransformer::terminate(); |
31 |
|
Bender::Bender() |
32 |
|
{ |
33 |
|
string path = sgetenv("PATH_TRANSLATED"); |
34 |
– |
ifstream file(path.c_str()); |
34 |
|
|
35 |
< |
if (path != "" && file.is_open()) |
35 |
> |
|
36 |
> |
if (path != "") |
37 |
|
{ |
38 |
< |
string line; |
39 |
< |
|
40 |
< |
do |
38 |
> |
ifstream file(path.c_str()); |
39 |
> |
|
40 |
> |
if (file.is_open()) |
41 |
|
{ |
42 |
< |
getline(file, line); |
42 |
> |
file.close(); |
43 |
|
|
44 |
< |
buffer << line << "\n"; |
44 |
> |
bend(path, sgetenv("HTTP_USER_AGENT")); |
45 |
> |
|
46 |
> |
return; |
47 |
|
} |
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"; |
48 |
|
} |
49 |
+ |
|
50 |
+ |
cout << "Status: 404\n" |
51 |
+ |
<< "Content-Type: text/html; charset=ISO-8859-1\n\n" |
52 |
+ |
<< "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" |
53 |
+ |
<< "<html><head>\n" |
54 |
+ |
<< "<title>404 Not Found</title>\n" |
55 |
+ |
<< "</head><body>\n" |
56 |
+ |
<< "<h1>Not Found</h1>\n" |
57 |
+ |
<< "<p>The requested URL " << sgetenv("PATH_INFO") << " was not found " |
58 |
+ |
<< "on this server.</p>\n" |
59 |
+ |
<< "<hr />\n" |
60 |
+ |
<< sgetenv("SERVER_SIGNATURE") |
61 |
+ |
<< "</body></html>\n"; |
62 |
|
} |
63 |
|
|
64 |
< |
void Bender::bend(const string& agent) |
64 |
> |
void Bender::bend(const string& path, const string& agent) |
65 |
|
{ |
66 |
|
Matcher matcher; |
67 |
|
|
68 |
< |
if (agent == matcher("/Opera |\\/(\\d+)\\.(\\d+)/")) |
68 |
> |
if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)")) |
69 |
> |
{ |
70 |
> |
bend(path); |
71 |
> |
} |
72 |
> |
else if (agent == matcher(string("^Mozilla/4.0 \\(compatible; MSIE (\\d+)") |
73 |
> |
+ "\\.(\\d+)(\\w+)?; .*\\)$")) |
74 |
|
{ |
75 |
< |
bend(); |
75 |
> |
int version; |
76 |
> |
istringstream number(matcher[1]); |
77 |
> |
|
78 |
> |
number >> version; |
79 |
> |
|
80 |
> |
if (version >= 6) |
81 |
> |
{ |
82 |
> |
pass(path); |
83 |
> |
} |
84 |
> |
else |
85 |
> |
{ |
86 |
> |
bend(path); |
87 |
> |
} |
88 |
> |
} |
89 |
> |
else if (agent == matcher(string("^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(") |
90 |
> |
+ "\\.d+)?(\\w+)?\\) Gecko\\/.*")) |
91 |
> |
{ |
92 |
> |
int major, minor; |
93 |
> |
istringstream number(matcher[1] + ' ' + matcher[2]); |
94 |
> |
|
95 |
> |
number >> major; |
96 |
> |
number >> minor; |
97 |
> |
|
98 |
> |
if (major > 1 || (major == 1 && minor >= 5)) |
99 |
> |
{ |
100 |
> |
pass(path); |
101 |
> |
} |
102 |
> |
else |
103 |
> |
{ |
104 |
> |
bend(path); |
105 |
> |
} |
106 |
|
} |
107 |
< |
else if (agent == matcher( |
76 |
< |
"/^Mozilla/4.0 \\(compatible; MSIE (\\d+)\\.(\\d+)(\\w+)?; .*\\)$/")) |
107 |
> |
else |
108 |
|
{ |
109 |
< |
// |
109 |
> |
bend(path); |
110 |
|
} |
111 |
< |
else if (agent == matcher( |
112 |
< |
"/^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(\\.d+)?(\\w+)?\\) Gecko\\/.*/" |
113 |
< |
)) |
111 |
> |
} |
112 |
> |
|
113 |
> |
void Bender::bend(const string& path) |
114 |
> |
{ |
115 |
> |
ostringstream output; |
116 |
> |
XalanTransformer transformer; |
117 |
> |
|
118 |
> |
if (transformer.transform(path.c_str(), output) == 0) |
119 |
|
{ |
120 |
< |
// |
120 |
> |
string type = "text/html; charset=ISO-8859-1"; |
121 |
> |
Matcher matcher("<META http-equiv=\"Content-Type\" content=\"(.*)\">"); |
122 |
> |
|
123 |
> |
if (matcher == output.str()) |
124 |
> |
{ |
125 |
> |
type = matcher[1]; |
126 |
> |
} |
127 |
> |
|
128 |
> |
cout << "Content-Type: " << type << "\n\n" << output.str(); |
129 |
|
} |
130 |
|
else |
131 |
|
{ |
132 |
< |
bend(); |
132 |
> |
pass(path); |
133 |
|
} |
134 |
|
} |
135 |
|
|
136 |
< |
void Bender::bend(void) |
136 |
> |
void Bender::pass(const string& path) |
137 |
|
{ |
138 |
< |
// |
138 |
> |
cout << "Content-Type: text/xml; charset=ISO-8859-1\n\n"; |
139 |
> |
|
140 |
> |
ifstream fin(path.c_str()); |
141 |
> |
string line; |
142 |
> |
|
143 |
> |
do |
144 |
> |
{ |
145 |
> |
getline(fin, line); |
146 |
> |
|
147 |
> |
cout << line << '\n'; |
148 |
> |
} |
149 |
> |
while (fin.good()); |
150 |
|
} |