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 208 by douglas, 2003-07-18T00:17:10-07:00 vs.
Revision 213 by douglas, 2003-07-19T21:07:54-07:00

# Line 46 | Line 46
46   //
47   // Douglas Thrift
48   //
49 < // $Id: HttpHandler.cpp,v 1.20 2003/07/18 07:17:10 douglas Exp $
49 > // $Id: HttpHandler.cpp,v 1.24 2003/07/20 04:07:54 douglas Exp $
50  
51   #include "HttpHandler.h"
52  
# Line 59 | Line 59
59   #include <netinet/in.h>
60   #include <netdb.h>
61  
62 #define INVALID_SOCKET -1
63 #define SOCKET_ERROR -1
64
62   inline int closesocket(SOCKET s) { return close(s); }
63   #endif
64  
# Line 189 | Line 186 | bool HttpHandler::handle(URL &url, const
186                  unsigned dot = line.find('.');
187                  unsigned space = line.find(' ');
188  
189 <                unsigned major = strtoul(line.substr(5, dot - 5).c_str(), 0, 10);
190 <                unsigned minor = strtoul(line.substr(dot + 1, space - dot - 1).c_str(),
191 <                        0, 10);
189 >                unsigned major;
190 >                unsigned minor;
191 >
192 >                istringstream number(line.substr(5, dot - 5) + " " + line.substr(dot
193 >                        + 1, space - dot - 1));
194 >
195 >                number >> major;
196 >                number >> minor;
197  
198                  if (major > 1)
199                  {
# Line 201 | Line 203 | bool HttpHandler::handle(URL &url, const
203                          return answer;
204                  }
205  
206 <                response = code(strtoul(line.substr(space + 1).c_str(), 0, 10));
206 >                number.clear();
207 >                number.str(line.substr(space + 1, 3));
208 >                number >> response;
209  
210                  if (response < ok) do line = getline(); while (line != "");
211          }
# Line 226 | Line 230 | bool HttpHandler::handle(URL &url, const
230                          }
231                          else if (field == "Content-Length")
232                          {
233 <                                length = strtoul(value.c_str(), 0, 10);
233 >                                istringstream number(value);
234 >
235 >                                number >> length;
236                          }
237                          else if (field == "Location")
238                          {
# Line 323 | Line 329 | void HttpHandler::populate()
329                                          SSL_read(ssl, buffer, bytes)) <= 0)
330                                  {
331                                          !tls ? error(program + ": Recv") : error(program +
332 <                                                ": SSL Read", received);
332 >                                                ": SSL Read", int(received));
333                                  }
334   #endif
335                                  else if (received != bytes)
# Line 351 | Line 357 | void HttpHandler::populate()
357  
358                  do
359                  {
360 <                        chunk = strtoul(getline().c_str(), 0, 16);
360 >                        istringstream number(getline());
361 >
362 >                        number.setf(ios_base::hex, ios_base::basefield);
363 >                        number >> chunk;
364  
365                          unsigned left = chunk;
366  
# Line 376 | Line 385 | void HttpHandler::populate()
385                                                  SSL_read(ssl, buffer, bytes)) <= 0)
386                                          {
387                                                  !tls ? error(program + ": Recv") : error(program +
388 <                                                        ": SSL Read", received);
388 >                                                        ": SSL Read", int(received));
389                                                  exit(1);
390                                          }
391   #endif
# Line 761 | Line 770 | bool HttpHandler::starttls()
770          SSL_load_error_strings();
771          SSL_library_init();
772  
773 <        //
773 > #ifndef _urandomdev_
774 >        int pid = getpid();
775 >        int now = time(NULL);
776 >
777 >        unsigned seed = now > pid ? now - pid : pid - now;
778 >
779 >        char* junk = new char[seed % 30 + 2];
780 >        junk[0] = pid;
781 >        junk[seed % 30 + 1] = now;
782 >
783 >        srand(seed);
784 >
785 >        for (int index = 1; index < seed % 30 + 1; index++)
786 >        {
787 >                junk[index] = rand();
788 >        }
789 >
790 >        if (debug)
791 >        {
792 >                cerr << "junk = {\n";
793 >
794 >                for (int index = 1; index < seed % 30 + 2; index++)
795 >                {
796 >                        cerr << "   [" << index << "] = " << int(junk[index]) << "\n";
797 >                }
798 >
799 >                cerr << "}\n";
800 >        }
801 >
802 >        RAND_seed(junk, seed % 30 + 2);
803 >
804 >        delete junk;
805 > #endif
806 >
807 >        ctx = SSL_CTX_new(TLSv1_client_method());
808 >
809 >        if (ctx == NULL)
810 >        {
811 >                cerr << program << ": SSL CTX New: "
812 >                        << ERR_reason_error_string(ERR_get_error()) << "\n";
813 >                return false;
814 >        }
815 >
816 >        ssl = SSL_new(ctx);
817 >
818 >        if (SSL_set_fd(ssl, http) == 0)
819 >        {
820 >                cerr << program << ": SSL Set FD: "
821 >                        << ERR_reason_error_string(ERR_get_error()) << "\n";
822 >                return false;
823 >        }
824 >
825 >        int number;
826 >
827 >        if ((number = SSL_connect(ssl)) <= 0)
828 >        {
829 >                error(program + ": SSL Connect", number);
830 >                return false;
831 >        }
832  
833          return true;
834   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines