35 |
|
|
36 |
|
if (path != "" && file.is_open()) |
37 |
|
{ |
38 |
< |
string line; |
38 |
> |
file.close(); |
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")); |
40 |
> |
bend(path, sgetenv("HTTP_USER_AGENT")); |
41 |
|
} |
42 |
|
else |
43 |
|
{ |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
< |
void Bender::bend(const string& agent) |
59 |
> |
void Bender::bend(const string& path, const string& agent) |
60 |
|
{ |
61 |
|
Matcher matcher; |
62 |
|
|
63 |
< |
if (agent == matcher("/Opera |\\/(\\d+)\\.(\\d+)/")) |
63 |
> |
if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)")) |
64 |
|
{ |
65 |
< |
bend(); |
65 |
> |
bend(path); |
66 |
|
} |
67 |
< |
else if (agent == matcher( |
68 |
< |
"/^Mozilla/4.0 \\(compatible; MSIE (\\d+)\\.(\\d+)(\\w+)?; .*\\)$/")) |
67 |
> |
else if (agent == matcher(string("^Mozilla/4.0 \\(compatible; MSIE (\\d+)") |
68 |
> |
+ "\\.(\\d+)(\\w+)?; .*\\)$")) |
69 |
|
{ |
70 |
|
// |
71 |
+ |
|
72 |
+ |
pass(path); |
73 |
|
} |
74 |
< |
else if (agent == matcher( |
75 |
< |
"/^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(\\.d+)?(\\w+)?\\) Gecko\\/.*/" |
82 |
< |
)) |
74 |
> |
else if (agent == matcher(string("^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(") |
75 |
> |
+ "\\.d+)?(\\w+)?\\) Gecko\\/.*")) |
76 |
|
{ |
77 |
|
// |
78 |
+ |
|
79 |
+ |
pass(path); |
80 |
+ |
} |
81 |
+ |
else |
82 |
+ |
{ |
83 |
+ |
bend(path); |
84 |
+ |
} |
85 |
+ |
} |
86 |
+ |
|
87 |
+ |
void Bender::bend(const string& path) |
88 |
+ |
{ |
89 |
+ |
ostringstream output; |
90 |
+ |
XalanTransformer transformer; |
91 |
+ |
|
92 |
+ |
if (transformer.transform(path.c_str(), output) == 0) |
93 |
+ |
{ |
94 |
+ |
string type = "text/html; charset=ISO-8859-1"; |
95 |
+ |
Matcher matcher("<META http-equiv=\"Content-Type\" content=\"(.*)\">"); |
96 |
+ |
|
97 |
+ |
if (matcher == output.str()) |
98 |
+ |
{ |
99 |
+ |
type = matcher[1]; |
100 |
+ |
} |
101 |
+ |
|
102 |
+ |
cout << "Content-Type: " << type << "\n\n" << output.str(); |
103 |
|
} |
104 |
|
else |
105 |
|
{ |
106 |
< |
bend(); |
106 |
> |
pass(path); |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
< |
void Bender::bend(void) |
110 |
> |
void Bender::pass(const string& path) |
111 |
|
{ |
112 |
< |
// |
112 |
> |
cout << "Content-Type: text/xml; charset=ISO-8859-1\n\n"; |
113 |
> |
|
114 |
> |
ifstream fin(path.c_str()); |
115 |
> |
string line; |
116 |
> |
|
117 |
> |
do |
118 |
> |
{ |
119 |
> |
getline(fin, line); |
120 |
> |
|
121 |
> |
cout << line << '\n'; |
122 |
> |
} |
123 |
> |
while (fin.good()); |
124 |
|
} |