ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Bender/Bender.cpp
(Generate patch)

Comparing Bender/Bender.cpp (file contents):
Revision 266 by Douglas Thrift, 2004-10-27T04:14:56-07:00 vs.
Revision 320 by douglas, 2004-12-13T16:06:29-08:00

# Line 5 | Line 5
5   // $Id$
6  
7   #include "Bender.hpp"
8 < #include "Matcher.hpp"
8 > #include "Matcher/Matcher.hpp"
9  
10   #include <menes-api/exename.hpp>
11   #include <menes-api/files.hpp>
12   #include <menes-api/process.hpp>
13   #include <menes-app/simple.hpp>
14  
15 < int Main(const app::Options& options)
15 > struct
16   {
17 <        try
17 >        ext::String get(const ext::String& name)
18          {
19 <                Bender bender;
19 >                try
20 >                {
21 >                        return api::TheEnvironment.Get(name);
22 >                }
23 >                catch (ext::Exception)
24 >                {
25 >                        return ext::String();
26 >                }
27          }
28 <        catch (ext::Exception e) {}
28 > } env;
29 >
30 > int Main(const app::Options& options)
31 > {
32 >        Bender bender;
33  
34          return 0;
35   }
36  
37   Bender::Bender()
38   {
39 <        ext::String path(api::TheEnvironment.Get("PATH_TRANSLATED"));
40 <        Matcher matcher("^" + api::TheEnvironment.Get("SCRIPT_NAME"));
39 >        ext::String path(env.get("PATH_TRANSLATED"));
40 >        Matcher matcher("^" + env.get("SCRIPT_NAME"));
41  
42 <        if (!path.IsEmpty() && api::TheEnvironment.Get("REQUEST_URI") != matcher)
42 >        if (!path.IsEmpty() && env.get("REQUEST_URI") != matcher)
43          {
44                  try
45                  {
46                          api::FileReader file(path);
47  
48 <                        bend(path, api::TheEnvironment.Get("HTTP_USER_AGENT"));
48 >                        bend(path, env.get("HTTP_USER_AGENT"));
49                  }
50                  catch (ext::Exception e)
51                  {
# Line 45 | Line 56 | Bender::Bender()
56                                  << "<title>404 Not Found</title>\n"
57                                  << "</head><body>\n"
58                                  << "<h1>Not Found</h1>\n"
59 <                                << "<p>The requested URL "
49 <                                << api::TheEnvironment.Get("PATH_INFO")
59 >                                << "<p>The requested URL " << env.get("PATH_INFO")
60                                  << " was not found on this server.</p>\n"
61                                  << "<hr />\n"
62 <                                << api::TheEnvironment.Get("SERVER_SIGNATURE")
53 <                                << "</body></html>\n";
62 >                                << env.get("SERVER_SIGNATURE") << "</body></html>\n";
63                  }
64          }
65          else
# Line 82 | Line 91 | void Bender::bend(const ext::String& pat
91  
92   void Bender::bend(const ext::String& path)
93   {
94 <        _L<ext::String> args(1, path);
95 <        _S<api::Process> xslt("/usr/local/bin/xsltproc", args);
94 >        _L<ext::String> args(1, "-a");
95 >
96 >        args.InsertLast(path);
97 >
98 > #if defined(__FreeBSD__)
99 >        _S<api::Process> xslt("/usr/local/bin/Xalan", args);
100 > #elif defined(_WIN32)
101 >        _S<api::Process> xslt("Xalan.exe", args);
102 > #else
103 >        _S<api::Process> xslt("Xalan", args);
104 > #endif
105          ios::String output;
106  
107          ios::ReadToWrite(*xslt.GetReader(), output);
# Line 98 | Line 116 | void Bender::bend(const ext::String& pat
116                  api::Cout << "Content-Type: " << type << "\r\n\r\n" << output;
117          }
118          else pass(path);
119 +
120 +        xslt.Join();
121   }
122  
123   void Bender::pass(const ext::String& path)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines