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 340 by douglas, 2004-12-14T15:49:53-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 + struct Environment
16 + {
17 +        ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } }
18 + } env;
19 +
20   int Main(const app::Options& options)
21   {
22 <        try
18 <        {
19 <                Bender bender;
20 <        }
21 <        catch (ext::Exception e) {}
22 >        Bender bender;
23  
24          return 0;
25   }
26  
27   Bender::Bender()
28   {
29 <        ext::String path(api::TheEnvironment.Get("PATH_TRANSLATED"));
30 <        Matcher matcher("^" + api::TheEnvironment.Get("SCRIPT_NAME"));
29 >        ext::String path(env.get("PATH_TRANSLATED"));
30 >        Matcher matcher("^" + env.get("SCRIPT_NAME"));
31  
32 <        if (!path.IsEmpty() && api::TheEnvironment.Get("REQUEST_URI") != matcher)
32 >        if (!path.IsEmpty() && env.get("REQUEST_URI") != matcher)
33          {
34                  try
35                  {
36                          api::FileReader file(path);
37  
38 <                        bend(path, api::TheEnvironment.Get("HTTP_USER_AGENT"));
38 >                        bend(path, env.get("HTTP_USER_AGENT"));
39                  }
40                  catch (ext::Exception e)
41                  {
# Line 45 | Line 46 | Bender::Bender()
46                                  << "<title>404 Not Found</title>\n"
47                                  << "</head><body>\n"
48                                  << "<h1>Not Found</h1>\n"
49 <                                << "<p>The requested URL "
49 <                                << api::TheEnvironment.Get("PATH_INFO")
49 >                                << "<p>The requested URL " << env.get("PATH_INFO")
50                                  << " was not found on this server.</p>\n"
51                                  << "<hr />\n"
52 <                                << api::TheEnvironment.Get("SERVER_SIGNATURE")
53 <                                << "</body></html>\n";
52 >                                << env.get("SERVER_SIGNATURE") << "</body></html>\n";
53                  }
54          }
55 <        else
57 <        {
58 <                api::Cout << "Location: http://computers.douglasthrift.net/bender.xml\r\n\r\n";
59 <        }
55 >        else api::Cout << "Location: http://computers.douglasthrift.net/bender.xml\r\n\r\n";
56   }
57  
58   void Bender::bend(const ext::String& path, const ext::String& agent)
59   {
60          Matcher matcher;
61  
62 <        if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)"))
67 <        {
68 <                bend(path);
69 <        }
70 <        else if (agent == matcher("rv:(\\d+)\\.(\\d+).*\\) Gecko"))
62 >        if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)")) bend(path); else if (agent == matcher("rv:(\\d+)\\.(\\d+).*\\) Gecko"))
63          {
64                  int major_(lexical_cast<int>(matcher[1])), minor_(lexical_cast<int>(matcher[2]));
65  
66 <                if (major_ > 1 || (major_ == 1 && minor_ >= 5))
75 <                {
76 <                        pass(path);
77 <                }
78 <                else bend(path);
66 >                if (major_ > 1 || (major_ == 1 && minor_ >= 5)) pass(path); else bend(path);
67          }
68          else bend(path);
69   }
70  
71   void Bender::bend(const ext::String& path)
72   {
73 <        _L<ext::String> args(1, path);
74 <        _S<api::Process> xslt("/usr/local/bin/xsltproc", args);
73 >        _L<ext::String> args(1, "-a");
74 >
75 >        args.InsertLast(path);
76 >
77 > #if defined(__FreeBSD__)
78 >        _S<api::Process> xslt("/usr/local/bin/Xalan", args);
79 > #elif defined(_WIN32)
80 >        _S<api::Process> xslt("Xalan.exe", args);
81 > #else
82 >        _S<api::Process> xslt("Xalan", args);
83 > #endif
84          ios::String output;
85  
86          ios::ReadToWrite(*xslt.GetReader(), output);
# Line 91 | Line 88 | void Bender::bend(const ext::String& pat
88          if (!output.IsEmpty())
89          {
90                  ext::String type("text/xml");
91 <                Matcher matcher("http-equiv=\"Content-Type\" content=\"(.*)\"");
91 >                Matcher matcher("http-equiv=\"Content-Type\" content=\"(.*)\"", PCRE_MULTILINE);
92  
93                  if (matcher == output) type = matcher[1];
94  
95                  api::Cout << "Content-Type: " << type << "\r\n\r\n" << output;
96          }
97          else pass(path);
98 +
99 +        xslt.Join();
100   }
101  
102   void Bender::pass(const ext::String& path)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines