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 355 by douglas, 2004-12-18T17:06:28-08:00

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines