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 19 by douglas, 2002-12-10T00:02:22-08:00 vs.
Revision 24 by douglas, 2002-12-22T00:58:21-08:00

# Line 62 | Line 62 | HttpHandler::HttpHandler()
62          }
63   #endif // _WIN32
64  
65        begin = 0;
65          length = 0;
66          chunked = false;
67   }
# Line 133 | Line 132 | bool HttpHandler::handle(URL &url, bool
132                  delete [] port;
133          }
134  
135 < //      putline("Referer: " + ?referer?);
135 > //      putline("Referer: " + ¿referer?);
136          putline("Connection: close");
137          putline();
138  
# Line 156 | Line 155 | bool HttpHandler::handle(URL &url, bool
155                  unsigned minor = strtoul(line.substr(dot + 1, space - dot - 1).c_str(),
156                          0, 10);
157  
158 <                if (major > 1 || minor < 1)
158 >                if (major > 1)
159                  {
160                          cerr << program << ": Potentially Incompatible Server: HTTP/" <<
161                                  major << "." << minor << "\n";
# Line 240 | Line 239 | bool HttpHandler::handle(URL &url, bool
239  
240   HttpHandler& HttpHandler::getline(string& line, char endline)
241   {
242 <        int end = page.find(endline, begin);
243 <        int newline = page.find('\n', begin);
242 >        unsigned end = page.find(endline);
243 >        unsigned newline = page.find('\n');
244  
245          if (newline < end || end == string::npos)
246          {
247                  end = newline;
248          }
249  
250 <        line = page.substr(begin, end - begin);
251 <
253 <        if (end == string::npos)
254 <        {
255 <                begin = end;
256 <        }
257 <        else
258 <        {
259 <                begin = end + 1;
260 <        }
250 >        line = page.substr(0, end);
251 >        page.erase(0, (end == string::npos ? end : end + 1));
252  
253          return *this;
254   }
255  
265 bool HttpHandler::good()
266 {
267        bool answer = true;
268
269        if (begin >= page.length())
270        {
271                answer = false;
272        }
273        else if (begin == string::npos)
274        {
275                answer = false;
276        }
277
278        return answer;
279 }
280
256   void HttpHandler::clear()
257   {
258          closesocket(http);
# Line 285 | Line 260 | void HttpHandler::clear()
260          type = "";
261          length = 0;
262          location = "";
288        begin = 0;
263          page = "";
264          chunked = false;
265   }
# Line 301 | Line 275 | void HttpHandler::populate()
275                          memset(buffer, 0, BUFSIZ + 1);
276  
277                          unsigned bytes = left > BUFSIZ ? BUFSIZ : left;
278 +                        unsigned received;
279  
280 <                        if (recv(http, buffer, bytes, 0) == SOCKET_ERROR)
280 >                        if ((received = recv(http, buffer, bytes, 0)) == SOCKET_ERROR)
281                          {
282 <                                error(program + ": Revc");
282 >                                error(program + ": Recv");
283                                  exit(1);
284                          }
285 +                        else if (received != bytes)
286 +                        {
287 +                                left -= received;
288 +                                page += buffer;
289 +
290 +                                memset(buffer, 0, BUFSIZ + 1);
291 +
292 +                                bytes -= received;
293 +                                if (recv(http, buffer, bytes, 0) == SOCKET_ERROR)
294 +                                {
295 +                                        error(program + ": Recv");
296 +                                        exit(1);
297 +                                }
298 +                        }
299  
300                          page += buffer;
301                          left -= bytes;
# Line 314 | Line 303 | void HttpHandler::populate()
303          }
304          else
305          {
306 <                //
306 >                unsigned chunk;
307 >
308 >                do
309 >                {
310 >                        chunk = strtoul(getline().c_str(), 0, 16);
311 >
312 >                        unsigned left = chunk;
313 >
314 >                        while (left > 0)
315 >                        {
316 >                                memset(buffer, 0, BUFSIZ + 1);
317 >
318 >                                unsigned bytes = left > BUFSIZ ? BUFSIZ : left;
319 >                                unsigned received;
320 >
321 >                                if ((received = recv(http, buffer, bytes, 0)) == SOCKET_ERROR)
322 >                                {
323 >                                        error(program + ": Recv");
324 >                                        exit(1);
325 >                                }
326 >                                else if (received != bytes)
327 >                                {
328 >                                        left -= received;
329 >                                        page += buffer;
330 >
331 >                                        memset(buffer, 0, BUFSIZ + 1);
332 >
333 >                                        bytes -= received;
334 >                                        if (recv(http, buffer, bytes, 0) == SOCKET_ERROR)
335 >                                        {
336 >                                                error(program + ": Recv");
337 >                                                exit(1);
338 >                                        }
339 >                                }
340 >
341 >                                page += buffer;
342 >                                left -= bytes;
343 >                        }
344 >
345 >                        getline();
346 >                        length += chunk;
347 >                }
348 >                while (chunk > 0);
349          }
350  
351 <        cerr << "\n[" << page << "]\n";
351 >        for (unsigned index = 0; index < page.length(); index++)
352 >        {
353 >                if (page[index] == '\r' && (index + 1 < page.length()) ? page[index +
354 >                        1] == '\n' : false)
355 >                {
356 >                        page.erase(index, 1);
357 >                }
358 >                else if (page[index] == '\r')
359 >                {
360 >                        page[index] = '\n';
361 >                }
362 >        }
363   }
364  
365   void HttpHandler::putline(const string line)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines