28 |
|
|
29 |
|
struct Environment |
30 |
|
{ |
31 |
< |
cse::String get(const cse::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return cse::String(); } } |
31 |
> |
cse::String get(const cse::String& name) |
32 |
> |
{ |
33 |
> |
try |
34 |
> |
{ |
35 |
> |
return api::TheEnvironment.Get(name); |
36 |
> |
} |
37 |
> |
catch (ext::Exception) |
38 |
> |
{ |
39 |
> |
return cse::String(); |
40 |
> |
} |
41 |
> |
} |
42 |
|
} env; |
43 |
|
|
44 |
|
int Main(const app::Options& options) |
53 |
|
cse::String path(env.get(_B("PATH_TRANSLATED"))); |
54 |
|
api::Pcre::RegEx script(_S<ios::String>() << _B("^") << env.get(_B("SCRIPT_NAME"))); |
55 |
|
|
56 |
< |
if (!path.IsEmpty() && script(env.get(_B("REQUEST_URI")))) |
56 |
> |
if (!path.IsEmpty() && !script(env.get(_B("REQUEST_URI")))) |
57 |
|
{ |
58 |
|
try |
59 |
|
{ |
76 |
|
<< env.get(_B("SERVER_SIGNATURE")) << _B("</body></html>\n"); |
77 |
|
} |
78 |
|
} |
79 |
< |
else api::Cout << _B("Location: http://computers.douglasthrift.net/bender.xml\r\n\r\n"); |
79 |
> |
else |
80 |
> |
api::Cout << _B("Location: http://computers.douglasthrift.net/bender.xml\r\n\r\n"); |
81 |
|
} |
82 |
|
|
83 |
|
void Bender::bend(const cse::String& path, const cse::String& agent) |
112 |
|
args.InsertLast(path); |
113 |
|
|
114 |
|
_S<api::Process> xslt(program, args); |
115 |
+ |
ext::Buffer line; |
116 |
+ |
api::Pcre::RegEx content("http-equiv=\"Content-Type\" content=\"(.*)\""); |
117 |
|
_S<ios::String> output; |
118 |
+ |
cse::String type(_B("text/xml")); |
119 |
|
|
120 |
< |
ios::ReadToWrite(*xslt.GetReader(), output); |
107 |
< |
|
108 |
< |
if (!output.IsEmpty()) |
120 |
> |
while (ios::ReadLine(*xslt.GetReader(), line)) |
121 |
|
{ |
122 |
< |
cse::String type(_B("text/xml")); |
111 |
< |
api::Pcre::RegEx content("http-equiv=\"Content-Type\" content=\"(.*)\""); |
122 |
> |
output << line << ios::NewLine; |
123 |
|
|
124 |
|
if (api::Pcre::RegEx::Match match = content(output)) |
125 |
+ |
{ |
126 |
|
type = match[1]; |
127 |
|
|
128 |
< |
api::Cout << "Content-Type: " << type << "\r\n\r\n" << output; |
128 |
> |
break; |
129 |
> |
} |
130 |
|
} |
131 |
+ |
|
132 |
+ |
ios::ReadToWrite(*xslt.GetReader(), output); |
133 |
+ |
|
134 |
+ |
if (!output.IsEmpty()) |
135 |
+ |
api::Cout << "Content-Type: " << type << "\r\n\r\n" << output; |
136 |
|
else |
137 |
|
pass(path); |
138 |
|
} |