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 114 by Douglas Thrift, 2004-03-16T14:33:08-08:00 vs.
Revision 160 by Douglas Thrift, 2004-06-16T21:10:28-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("REQUEST_URI").find("SCRIPT_NAME") != 0)
36          {
37 <                string line;
38 <                
39 <                do
37 >                ifstream file(path.c_str());
38 >
39 >                if (file.is_open())
40                  {
41 <                        getline(file, line);
41 >                        file.close();
42  
43 <                        buffer << line << "\n";
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                  }
46                while (file.good());
47                
48                bend(sgetenv("HTTP_USER_AGENT"));
60          }
61          else
62          {
63 <                cout << "Status: 404\n"
53 <                        << "Content-Type: text/html; charset=ISO-8859-1\n\n"
54 <                        << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
55 <                        << "<html><head>\n"
56 <                        << "<title>404 Not Found</title>\n"
57 <                        << "</head><body>\n"
58 <                        << "<h1>Not Found</h1>\n"
59 <                        << "<p>The requested URL " << sgetenv("PATH_INFO") << " was not fo"
60 <                        << "und on this server.</p>\n"
61 <                        << "<hr />\n"
62 <                        << sgetenv("SERVER_SIGNATURE")
63 <                        << "</body></html>\n";
63 >                cout << "Location: http://computers.douglasthrift.net/bender.xml\n\n";
64          }
65   }
66  
67 < void Bender::bend(const string& agent)
67 > void Bender::bend(const string& path, const string& agent)
68   {
69          Matcher matcher;
70  
71 <        if (agent == matcher("/Opera |\\/(\\d+)\\.(\\d+)/"))
71 >        if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)"))
72          {
73 <                bend();
73 >                bend(path);
74          }
75 <        else if (agent == matcher(
76 <                "/^Mozilla/4.0 \\(compatible; MSIE (\\d+)\\.(\\d+)(\\w+)?; .*\\)$/"))
75 >        else if (agent == matcher(string("^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(")
76 >                + "\\.d+)?(\\w+)?\\) Gecko\\/.*"))
77 >        {
78 >                int major, minor;
79 >                istringstream number(matcher[1] + ' ' + matcher[2]);
80 >
81 >                number >> major;
82 >                number >> minor;
83 >
84 >                if (major > 1 || (major == 1 && minor >= 5))
85 >                {
86 >                        pass(path);
87 >                }
88 >                else
89 >                {
90 >                        bend(path);
91 >                }
92 >        }
93 >        else
94          {
95 <                //
95 >                bend(path);
96          }
97 <        else if (agent == matcher(
98 <                "/^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(\\.d+)?(\\w+)?\\) Gecko\\/.*/"
99 <                ))
97 > }
98 >
99 > void Bender::bend(const string& path)
100 > {
101 >        ostringstream output;
102 >        XalanTransformer transformer;
103 >
104 >        if (transformer.transform(path.c_str(), output) == 0)
105          {
106 <                //
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 >
114 >                cout << "Content-Type: " << type << "\n\n" << output.str();
115          }
116          else
117          {
118 <                bend();
118 >                pass(path);
119          }
120   }
121  
122 < void Bender::bend(void)
122 > void Bender::pass(const string& path)
123   {
124 <        //
124 >        cout << "Content-Type: text/xml\n\n";
125 >
126 >        ifstream fin(path.c_str());
127 >        string line;
128 >
129 >        do
130 >        {
131 >                getline(fin, line);
132 >
133 >                cout << line << '\n';
134 >        }
135 >        while (fin.good());
136   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines