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 117 by Douglas Thrift, 2004-03-17T02:02:43-08:00

# Line 35 | Line 35 | Bender::Bender()
35  
36          if (path != "" && file.is_open())
37          {
38 <                string line;
38 >                file.close();
39                  
40 <                do
41 <                {
42 <                        getline(file, line);
43 <
44 <                        buffer << line << "\n";
45 <                }
46 <                while (file.good());
47 <                
48 <                bend(sgetenv("HTTP_USER_AGENT"));
40 >                bend(path, sgetenv("HTTP_USER_AGENT"));
41          }
42          else
43          {
# Line 64 | Line 56 | Bender::Bender()
56          }
57   }
58  
59 < void Bender::bend(const string& agent)
59 > void Bender::bend(const string& path, const string& agent)
60   {
61          Matcher matcher;
62  
63 <        if (agent == matcher("/Opera |\\/(\\d+)\\.(\\d+)/"))
63 >        if (agent == matcher("Opera( |\\/)(\\d+)\\.(\\d+)"))
64          {
65 <                bend();
65 >                bend(path);
66 >        }
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 >        }
84 >        else if (agent == matcher(string("^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(")
85 >                + "\\.d+)?(\\w+)?\\) Gecko\\/.*"))
86 >        {
87 >                int major, minor;
88 >                istringstream number(matcher[1] + ' ' + matcher[2]);
89 >
90 >                number >> major;
91 >                number >> minor;
92 >
93 >                if (major > 1 || (major == 1 && minor >= 5))
94 >                {
95 >                        pass(path);
96 >                }
97 >                else
98 >                {
99 >                        bend(path);
100 >                }
101          }
102 <        else if (agent == matcher(
76 <                "/^Mozilla/4.0 \\(compatible; MSIE (\\d+)\\.(\\d+)(\\w+)?; .*\\)$/"))
102 >        else
103          {
104 <                //
104 >                bend(path);
105          }
106 <        else if (agent == matcher(
107 <                "/^Mozilla/5.0 \\(.*; rv:(\\d+)\\.(\\d+)(\\.d+)?(\\w+)?\\) Gecko\\/.*/"
108 <                ))
106 > }
107 >
108 > void Bender::bend(const string& path)
109 > {
110 >        ostringstream output;
111 >        XalanTransformer transformer;
112 >
113 >        if (transformer.transform(path.c_str(), output) == 0)
114          {
115 <                //
115 >                string type = "text/html; charset=ISO-8859-1";
116 >                Matcher matcher("<META http-equiv=\"Content-Type\" content=\"(.*)\">");
117 >
118 >                if (matcher == output.str())
119 >                {
120 >                        type = matcher[1];
121 >                }
122 >                
123 >                cout << "Content-Type: " << type << "\n\n" << output.str();
124          }
125          else
126          {
127 <                bend();
127 >                pass(path);
128          }
129   }
130  
131 < void Bender::bend(void)
131 > void Bender::pass(const string& path)
132   {
133 <        //
133 >        cout << "Content-Type: text/xml; charset=ISO-8859-1\n\n";
134 >
135 >        ifstream fin(path.c_str());
136 >        string line;
137 >
138 >        do
139 >        {
140 >                getline(fin, line);
141 >
142 >                cout << line << '\n';
143 >        }
144 >        while (fin.good());
145   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines