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 117 by Douglas Thrift, 2004-03-17T02:02:43-08:00 vs.
Revision 159 by Douglas Thrift, 2004-06-16T20:51:10-07:00

# Line 18 | Line 18 | int main(int argc, char* argv[])
18   {
19          XMLPlatformUtils::Initialize();
20          XalanTransformer::initialize();
21 <        
21 >
22          Bender bender;
23  
24          XalanTransformer::terminate();
# Line 31 | Line 31 | int main(int argc, char* argv[])
31   Bender::Bender()
32   {
33          string path = sgetenv("PATH_TRANSLATED");
34        ifstream file(path.c_str());
34  
35 <        if (path != "" && file.is_open())
35 >        if (path != "" && sgetenv("PATH_INFO") == sgetenv("REQUEST_URI"))
36          {
37 <                file.close();
38 <                
39 <                bend(path, sgetenv("HTTP_USER_AGENT"));
37 >                ifstream file(path.c_str());
38 >
39 >                if (file.is_open())
40 >                {
41 >                        file.close();
42 >
43 >                        bend(path, sgetenv("HTTP_USER_AGENT"));
44 >                }
45 >                else
46 >                {
47 >                        cout << "Status: 404\n"
48 >                                << "Content-Type: text/html; charset=ISO-8859-1\n\n"
49 >                                << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
50 >                                << "<html><head>\n"
51 >                                << "<title>404 Not Found</title>\n"
52 >                                << "</head><body>\n"
53 >                                << "<h1>Not Found</h1>\n"
54 >                                << "<p>The requested URL " << sgetenv("PATH_INFO") << " was no"
55 >                                << "t found on this server.</p>\n"
56 >                                << "<hr />\n"
57 >                                << sgetenv("SERVER_SIGNATURE")
58 >                                << "</body></html>\n";
59 >                }
60          }
61          else
62          {
63 <                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";
63 >                cout << "Location: http://computers.douglasthrift.net/bender.xml\n\n";
64          }
65   }
66  
# Line 64 | Line 72 | void Bender::bend(const string& path, co
72          {
73                  bend(path);
74          }
67        else if (agent == matcher(string("^Mozilla/4.0 \\(compatible; MSIE (\\d+)")
68                + "\\.(\\d+)(\\w+)?; .*\\)$"))
69        {
70                int version;
71                istringstream number(matcher[1]);
72
73                number >> version;
74
75                if (version >= 6)
76                {
77                        pass(path);
78                }
79                else
80                {
81                        bend(path);
82                }
83        }
75          else if (agent == matcher(string("^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(")
76                  + "\\.d+)?(\\w+)?\\) Gecko\\/.*"))
77          {
# Line 112 | Line 103 | void Bender::bend(const string& path)
103  
104          if (transformer.transform(path.c_str(), output) == 0)
105          {
106 <                string type = "text/html; charset=ISO-8859-1";
107 <                Matcher matcher("<META http-equiv=\"Content-Type\" content=\"(.*)\">");
106 >                string type = "text/xml";
107 >                Matcher matcher("http-equiv=\"Content-Type\" content=\"(.*)\"");
108  
109                  if (matcher == output.str())
110                  {
111                          type = matcher[1];
112                  }
113 <                
113 >
114                  cout << "Content-Type: " << type << "\n\n" << output.str();
115          }
116          else
# Line 130 | Line 121 | void Bender::bend(const string& path)
121  
122   void Bender::pass(const string& path)
123   {
124 <        cout << "Content-Type: text/xml; charset=ISO-8859-1\n\n";
124 >        cout << "Content-Type: text/xml\n\n";
125  
126          ifstream fin(path.c_str());
127          string line;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines