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 120 by Douglas Thrift, 2004-03-17T22:01:55-08: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 >
36 >        if (path != "")
37          {
38 <                string line;
39 <                
40 <                do
38 >                ifstream file(path.c_str());
39 >
40 >                if (file.is_open())
41                  {
42 <                        getline(file, line);
42 >                        file.close();
43  
44 <                        buffer << line << "\n";
44 >                        bend(path, sgetenv("HTTP_USER_AGENT"));
45 >
46 >                        return;
47                  }
46                while (file.good());
47                
48                bend(sgetenv("HTTP_USER_AGENT"));
49        }
50        else
51        {
52                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";
48          }
49 +
50 +        cout << "Location: http://computers.douglasthrift.net/bender.xml\n\n";
51   }
52  
53 < void Bender::bend(const string& agent)
53 > void Bender::bend(const string& path, const string& agent)
54   {
55          Matcher matcher;
56  
57 <        if (agent == matcher("/Opera |\\/(\\d+)\\.(\\d+)/"))
57 >        if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)"))
58 >        {
59 >                bend(path);
60 >        }
61 >        else if (agent == matcher(string("^Mozilla/4.0 \\(compatible; MSIE (\\d+)")
62 >                + "\\.(\\d+)(\\w+)?; .*\\)$"))
63          {
64 <                bend();
64 >                int version;
65 >                istringstream number(matcher[1]);
66 >
67 >                number >> version;
68 >
69 >                if (version >= 6)
70 >                {
71 >                        pass(path);
72 >                }
73 >                else
74 >                {
75 >                        bend(path);
76 >                }
77 >        }
78 >        else if (agent == matcher(string("^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(")
79 >                + "\\.d+)?(\\w+)?\\) Gecko\\/.*"))
80 >        {
81 >                int major, minor;
82 >                istringstream number(matcher[1] + ' ' + matcher[2]);
83 >
84 >                number >> major;
85 >                number >> minor;
86 >
87 >                if (major > 1 || (major == 1 && minor >= 5))
88 >                {
89 >                        pass(path);
90 >                }
91 >                else
92 >                {
93 >                        bend(path);
94 >                }
95          }
96 <        else if (agent == matcher(
76 <                "/^Mozilla/4.0 \\(compatible; MSIE (\\d+)\\.(\\d+)(\\w+)?; .*\\)$/"))
96 >        else
97          {
98 <                //
98 >                bend(path);
99          }
100 <        else if (agent == matcher(
101 <                "/^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(\\.d+)?(\\w+)?\\) Gecko\\/.*/"
102 <                ))
100 > }
101 >
102 > void Bender::bend(const string& path)
103 > {
104 >        ostringstream output;
105 >        XalanTransformer transformer;
106 >
107 >        if (transformer.transform(path.c_str(), output) == 0)
108          {
109 <                //
109 >                string type = "text/html; charset=ISO-8859-1";
110 >                Matcher matcher("<META http-equiv=\"Content-Type\" content=\"(.*)\">");
111 >
112 >                if (matcher == output.str())
113 >                {
114 >                        type = matcher[1];
115 >                }
116 >
117 >                cout << "Content-Type: " << type << "\n\n" << output.str();
118          }
119          else
120          {
121 <                bend();
121 >                pass(path);
122          }
123   }
124  
125 < void Bender::bend(void)
125 > void Bender::pass(const string& path)
126   {
127 <        //
127 >        cout << "Content-Type: text/xml; charset=ISO-8859-1\n\n";
128 >
129 >        ifstream fin(path.c_str());
130 >        string line;
131 >
132 >        do
133 >        {
134 >                getline(fin, line);
135 >
136 >                cout << line << '\n';
137 >        }
138 >        while (fin.good());
139   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines