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 112 by Douglas Thrift, 2004-03-16T00:28:49-08:00 vs.
Revision 116 by Douglas Thrift, 2004-03-17T00:24:32-08:00

# Line 5 | Line 5
5   // $Id$
6  
7   #include "Bender.hpp"
8 + #include "Matcher.hpp"
9 +
10 + #include <xalanc/Include/PlatformDefinitions.hpp>
11 + #include <xercesc/util/PlatformUtils.hpp>
12 + #include <xalanc/XalanTransformer/XalanTransformer.hpp>
13 +
14 + XALAN_USING_XERCES(XMLPlatformUtils)
15 + XALAN_USING_XALAN(XalanTransformer)
16  
17   int main(int argc, char* argv[])
18   {
# Line 23 | Line 31 | int main(int argc, char* argv[])
31   Bender::Bender()
32   {
33          string path = sgetenv("PATH_TRANSLATED");
34 +        ifstream file(path.c_str());
35  
36 <        if (path != "")
36 >        if (path != "" && file.is_open())
37          {
38 <                cout << "Content-Type: text/html\n\n";
38 >                file.close();
39                  
40 <                XalanTransformer transformer;
40 >                bend(path, sgetenv("HTTP_USER_AGENT"));
41 >        }
42 >        else
43 >        {
44 >                cout << "Status: 404\n"
45 >                        << "Content-Type: text/html; charset=ISO-8859-1\n\n"
46 >                        << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
47 >                        << "<html><head>\n"
48 >                        << "<title>404 Not Found</title>\n"
49 >                        << "</head><body>\n"
50 >                        << "<h1>Not Found</h1>\n"
51 >                        << "<p>The requested URL " << sgetenv("PATH_INFO") << " was not fo"
52 >                        << "und on this server.</p>\n"
53 >                        << "<hr />\n"
54 >                        << sgetenv("SERVER_SIGNATURE")
55 >                        << "</body></html>\n";
56 >        }
57 > }
58  
59 <                if (transformer.transform(path.c_str(), cout) != 0)
60 <                {
61 <                        ifstream fin(path.c_str());
62 <                        string line;
59 > void Bender::bend(const string& path, const string& agent)
60 > {
61 >        Matcher matcher;
62 >
63 >        if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)"))
64 >        {
65 >                bend(path);
66 >        }
67 >        else if (agent == matcher(string("^Mozilla/4.0 \\(compatible; MSIE (\\d+)")
68 >                + "\\.(\\d+)(\\w+)?; .*\\)$"))
69 >        {
70 >                //
71 >
72 >                pass(path);
73 >        }
74 >        else if (agent == matcher(string("^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(")
75 >                + "\\.d+)?(\\w+)?\\) Gecko\\/.*"))
76 >        {
77 >                //
78 >                
79 >                pass(path);
80 >        }
81 >        else
82 >        {
83 >                bend(path);
84 >        }
85 > }
86  
87 <                        do
88 <                        {
89 <                                getline(fin, line);
90 <
91 <                                cout << line << "\n";
92 <                        }
93 <                        while (fin.good());
87 > void Bender::bend(const string& path)
88 > {
89 >        ostringstream output;
90 >        XalanTransformer transformer;
91 >
92 >        if (transformer.transform(path.c_str(), output) == 0)
93 >        {
94 >                string type = "text/html; charset=ISO-8859-1";
95 >                Matcher matcher("<META http-equiv=\"Content-Type\" content=\"(.*)\">");
96 >
97 >                if (matcher == output.str())
98 >                {
99 >                        type = matcher[1];
100                  }
101 +                
102 +                cout << "Content-Type: " << type << "\n\n" << output.str();
103 +        }
104 +        else
105 +        {
106 +                pass(path);
107 +        }
108 + }
109 +
110 + void Bender::pass(const string& path)
111 + {
112 +        cout << "Content-Type: text/xml; charset=ISO-8859-1\n\n";
113 +
114 +        ifstream fin(path.c_str());
115 +        string line;
116 +
117 +        do
118 +        {
119 +                getline(fin, line);
120 +
121 +                cout << line << '\n';
122          }
123 +        while (fin.good());
124   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines