ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/Search/HttpHandler.cpp
(Generate patch)

Comparing trunk/Search/HttpHandler.cpp (file contents):
Revision 14 by douglas, 2002-12-07T00:19:03-08:00 vs.
Revision 18 by douglas, 2002-12-09T21:40:12-08:00

# Line 57 | Line 57 | HttpHandler::HttpHandler()
57   #ifdef _WIN32
58          if (WSAStartup(MAKEWORD(2, 0), &data) != 0)
59          {
60 <                error(program + ": WSAStartup()");
60 >                error(program + ": WSAStartup");
61                  exit(1);
62          }
63   #endif // _WIN32
64  
65          begin = 0;
66 +        length = 0;
67 +        chunked = false;
68   }
69  
70   HttpHandler::~HttpHandler()
# Line 131 | Line 133 | bool HttpHandler::handle(URL &url, bool
133                  delete [] port;
134          }
135  
136 +        putline("Connection: close");
137          putline();
138  
139 +        code response;
140 +        string line;
141 +
142 +        do
143 +        {
144 +                line = getline();
145 +
146 +                if (line.find("HTTP/") != 0)
147 +                {
148 +                        return answer;
149 +                }
150 +
151 +                unsigned dot = line.find('.');
152 +                unsigned space = line.find(' ');
153 +
154 +                unsigned major = strtoul(line.substr(5, dot - 5).c_str(), 0, 0);
155 +                unsigned minor = strtoul(line.substr(dot + 1, space - dot - 1).c_str(), 0,
156 +                        0);
157 +
158 +                if (major > 1 || minor < 1)
159 +                {
160 +                        cerr << program << ": Potentially Incompatible Server: HTTP/" << major
161 +                                << "." << minor << "\n";
162 +
163 +                        return answer;
164 +                }
165 +
166 +                response = code(strtoul(line.substr(space + 1).c_str(), 0, 0));
167 +
168 +                if (response < ok) do line = getline(); while (line != "");
169 +        }
170 +        while (response < ok);
171 +
172 +        do
173 +        {
174 +                line = getline();
175 +
176 +                if (line != "")
177 +                {
178 +                        unsigned colon = line.find(':');
179 +
180 +                        string field = line.substr(0, colon);
181 +                        string value = line.substr(colon + 1);
182 +
183 +                        while (isspace(value[0])) value.erase(0, 1);
184 +
185 + //                      if (field =
186 +                }
187 +        }
188 +        while (line != "");
189 +
190 +        switch (response)
191 +        {
192 +        case ok:
193 +                if (debug) cerr << "response = " << response << "\n";
194 +                answer = true;
195 +                break;
196 +        case choices:
197 +        case moved:
198 +        case found:
199 +                if (debug) cerr << "response = " << response << "\n"
200 +                        << "location = " << location << "\n";
201 +                location = getLink(location, url);
202 +                break;
203 +        case notfound:
204 +        case internal:
205 +                if (debug) cerr << "response = " << response << "\n";
206 +                break;
207 +        default:
208 +                if (debug) cerr << "response = " << response << "\n";
209 +                if (response <= 299)
210 +                {
211 +                        answer = true;
212 +                }
213 +                else if (response <= 399)
214 +                {
215 +                        location = getLink(location, url);
216 +                }
217 +                break;
218 +        }
219 +
220          return answer;
221   }
222  
# Line 178 | Line 262 | bool HttpHandler::good()
262  
263   void HttpHandler::clear()
264   {
265 +        closesocket(http);
266 +
267 +        type = "";
268 +        length = 0;
269 +        location = "";
270          begin = 0;
271          page = "";
272 +        chunked = false;
273   }
274  
275   void HttpHandler::putline(const string line)
# Line 192 | Line 282 | void HttpHandler::putline(const string l
282          }
283   }
284  
285 < void HttpHandler::error(const string prefix, bool host)
285 > string HttpHandler::getline()
286 > {
287 >        string line;
288 >        char byte;
289 >
290 >        do
291 >        {
292 >                if (recv(http, &byte, 1, 0) == SOCKET_ERROR)
293 >                {
294 >                        error(program + ": Recv");
295 >                }
296 >
297 >                if (byte != '\r' && byte != '\n')
298 >                {
299 >                        line += byte;
300 >                }
301 >        }
302 >        while (byte != '\n');
303 >
304 >        return line;
305 > }
306 >
307 > void HttpHandler::error(const string& prefix, bool host)
308   {
309   #ifdef _WIN32
310          string error;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines