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 335 by douglas, 2004-12-13T21:10:19-08:00 vs.
Revision 420 by douglas, 2005-03-09T17:47:41-08:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 #include "Bender.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 + #include <menes-xml/document.hpp>
16 + #include <menes-xml/nodeset.hpp>
17 + #include <menes-xml/parse.hpp>
18  
19 < struct
19 > class Bender
20   {
21 <        ext::String get(const ext::String& name)
22 <        {
23 <                try
24 <                {
25 <                        return api::TheEnvironment.Get(name);
26 <                }
27 <                catch (ext::Exception)
28 <                {
29 <                        return ext::String();
30 <                }
31 <        }
21 > private:
22 >        void bend(const ext::String& path, const ext::String& agent);
23 >        void bend(const ext::String& path);
24 >        void pass(const ext::String& path);
25 > public:
26 >        Bender();
27 > };
28 >
29 > struct Environment
30 > {
31 >        ext::String get(const ext::String& name) { try { return api::TheEnvironment.Get(name); } catch (ext::Exception) { return ext::String(); } }
32   } env;
33  
34   int Main(const app::Options& options)
# Line 47 | Line 51 | Bender::Bender()
51  
52                          bend(path, env.get("HTTP_USER_AGENT"));
53                  }
54 <                catch (ext::Exception e)
54 >                catch (ext::Exception)
55                  {
56                          api::Cout << "Status: 404\r\n"
57                                  << "Content-Type: text/html; charset=ISO-8859-1\r\n\r\n"
# Line 62 | Line 66 | Bender::Bender()
66                                  << env.get("SERVER_SIGNATURE") << "</body></html>\n";
67                  }
68          }
69 <        else
66 <        {
67 <                api::Cout << "Location: http://computers.douglasthrift.net/bender.xml\r\n\r\n";
68 <        }
69 >        else api::Cout << "Location: http://computers.douglasthrift.net/bender.xml\r\n\r\n";
70   }
71  
72   void Bender::bend(const ext::String& path, const ext::String& agent)
73   {
74          Matcher matcher;
75  
76 <        if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)"))
76 <        {
77 <                bend(path);
78 <        }
79 <        else if (agent == matcher("rv:(\\d+)\\.(\\d+).*\\) Gecko"))
76 >        if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)")) bend(path); else if (agent == matcher("rv:(\\d+)\\.(\\d+).*\\) Gecko"))
77          {
78                  int major_(lexical_cast<int>(matcher[1])), minor_(lexical_cast<int>(matcher[2]));
79  
80 <                if (major_ > 1 || (major_ == 1 && minor_ >= 5))
84 <                {
85 <                        pass(path);
86 <                }
87 <                else bend(path);
80 >                if (major_ > 1 || (major_ == 1 && minor_ >= 5)) pass(path); else bend(path);
81          }
82          else bend(path);
83   }
84  
85   void Bender::bend(const ext::String& path)
86   {
87 <        _L<ext::String> args(1, "-a");
87 >        _H<xml::Document> document(xml::Parse("bender.xml"));
88 >        _H<xml::Node> node(*document/"bender");
89 >        ext::String program(*node/"program");
90 >        _L<ext::String> args;
91 >
92 >        _foreach (const xml::NodeSet, arg, *node/"argument") args.InsertLast(**arg);
93  
94          args.InsertLast(path);
95  
96 < #if defined(__FreeBSD__)
97 <        _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;
96 >        _S<api::Process> xslt(program, args);
97 >        _S<ios::String> output;
98  
99          ios::ReadToWrite(*xslt.GetReader(), output);
100  
# Line 116 | Line 108 | void Bender::bend(const ext::String& pat
108                  api::Cout << "Content-Type: " << type << "\r\n\r\n" << output;
109          }
110          else pass(path);
119
120        xslt.Join();
111   }
112  
113   void Bender::pass(const ext::String& path)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines