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 20 by douglas, 2002-12-10T14:04:39-08:00

# Line 62 | Line 62 | HttpHandler::HttpHandler()
62          }
63   #endif // _WIN32
64  
65        begin = 0;
65          length = 0;
66          chunked = false;
67   }
# 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 >        int end = page.find(endline);
243 >        int 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);
250 >        line = page.substr(0, end);
251 >        page.erase(0, (end == string::npos ? end : end + 1));
252  
253 <        if (end == string::npos)
254 <        {
255 <                begin = end;
256 <        }
257 <        else
258 <        {
259 <                begin = end + 1;
260 <        }
253 > //      if (line == "") cerr << "line = [" << line << "]\npage = [" << page
254 > //              << "]" << (good() ? "true" : "false") << "\n";
255  
256          return *this;
257   }
258  
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
259   void HttpHandler::clear()
260   {
261          closesocket(http);
# Line 285 | Line 263 | void HttpHandler::clear()
263          type = "";
264          length = 0;
265          location = "";
288        begin = 0;
266          page = "";
267          chunked = false;
268   }
# Line 304 | Line 281 | void HttpHandler::populate()
281  
282                          if (recv(http, buffer, bytes, 0) == SOCKET_ERROR)
283                          {
284 <                                error(program + ": Revc");
284 >                                error(program + ": Recv");
285                                  exit(1);
286                          }
287  
# Line 314 | Line 291 | void HttpHandler::populate()
291          }
292          else
293          {
294 <                //
294 >                unsigned chunk;
295 >
296 >                do
297 >                {
298 >                        chunk = strtoul(getline().c_str(), 0, 16);
299 >
300 >                        unsigned left = chunk;
301 >
302 >                        while (left > 0)
303 >                        {
304 >                                memset(buffer, 0, BUFSIZ + 1);
305 >
306 >                                unsigned bytes = left > BUFSIZ ? BUFSIZ : left;
307 >
308 >                                if (recv(http, buffer, bytes, 0) == SOCKET_ERROR)
309 >                                {
310 >                                        error(program + ": Recv");
311 >                                        exit(1);
312 >                                }
313 >
314 >                                page += buffer;
315 >                                left -= bytes;
316 >                        }
317 >
318 >                        getline();
319 >                        length += chunk;
320 >                }
321 >                while (chunk > 0);
322          }
323  
324 <        cerr << "\n[" << page << "]\n";
324 >        for (unsigned index = 0; index < page.length(); index++)
325 >        {
326 >                if (page[index] == '\r' && (index + 1 < page.length()) ? page[index +
327 >                        1] == '\n' : false)
328 >                {
329 >                        page.erase(index, 1);
330 >                }
331 >                else if (page[index] == '\r')
332 >                {
333 >                        page[index] = '\n';
334 >                }
335 >        }
336   }
337  
338   void HttpHandler::putline(const string line)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines