]> git.saurik.com Git - apt.git/blobdiff - methods/http.cc
Added subprocess to segfault error
[apt.git] / methods / http.cc
index f014193a01cd005495db1f07445950db42cb4ee6..7a9a97a1dc2545c430b0f6e7783ca7f633a1cd2e 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: http.cc,v 1.34 1999/05/29 03:25:03 jgg Exp $
+// $Id: http.cc,v 1.43 1999/12/10 23:40:29 jgg Exp $
 /* ######################################################################
 
    HTTP Aquire Method - This is the HTTP aquire method for APT.
@@ -54,6 +54,7 @@ int HttpMethod::FailFd = -1;
 time_t HttpMethod::FailTime = 0;
 unsigned long PipelineDepth = 10;
 unsigned long TimeOut = 120;
+bool Debug = false;
 
 // CircleBuf::CircleBuf - Circular input buffer                                /*{{{*/
 // ---------------------------------------------------------------------
@@ -288,6 +289,27 @@ bool ServerState::Open()
    else
       Proxy = getenv("http_proxy");
    
+   // Parse no_proxy, a , seperated list of hosts
+   if (getenv("no_proxy") != 0)
+   {
+      const char *Start = getenv("no_proxy");
+      for (const char *Cur = Start; true ; Cur++)
+      {
+        if (*Cur != ',' && *Cur != 0)
+           continue;
+        if (stringcasecmp(ServerName.Host.begin(),ServerName.Host.end(),
+                          Start,Cur) == 0)
+        {
+           Proxy = "";
+           break;
+        }
+        
+        Start = Cur + 1;
+        if (*Cur == 0)
+           break;
+      }         
+   }      
+   
    // Determine what host and port to use based on the proxy settings
    int Port = 0;
    string Host;   
@@ -305,7 +327,7 @@ bool ServerState::Open()
    }
    
    // Connect to the remote server
-   if (Connect(Host,Port,"http",ServerFd,TimeOut,Owner) == false)
+   if (Connect(Host,Port,"http",80,ServerFd,TimeOut,Owner) == false)
       return false;
    
    return true;
@@ -613,7 +635,7 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
    if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
    {
       // In this case we send an if-range query with a range header
-      sprintf(Buf,"Range: bytes=%li-\r\nIf-Range: %s\r\n",SBuf.st_size - 1,
+      sprintf(Buf,"Range: bytes=%li-\r\nIf-Range: %s\r\n",(long)SBuf.st_size - 1,
              TimeRFC1123(SBuf.st_mtime).c_str());
       Req += Buf;
    }
@@ -631,7 +653,9 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
           Base64Encode(Proxy.User + ":" + Proxy.Password) + "\r\n";
 
    Req += "User-Agent: Debian APT-HTTP/1.2\r\n\r\n";
-//   cerr << Req << endl;
+   
+   if (Debug == true)
+      cerr << Req << endl;
 
    Out.Read(Req);
 }
@@ -643,13 +667,13 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
 bool HttpMethod::Go(bool ToFile,ServerState *Srv)
 {
    // Server has closed the connection
-   if (Srv->ServerFd == -1 && Srv->In.WriteSpace() == false)
+   if (Srv->ServerFd == -1 && (Srv->In.WriteSpace() == false || 
+                              ToFile == false))
       return false;
    
-   fd_set rfds,wfds,efds;
+   fd_set rfds,wfds;
    FD_ZERO(&rfds);
    FD_ZERO(&wfds);
-   FD_ZERO(&efds);
    
    // Add the server
    if (Srv->Out.WriteSpace() == true && Srv->ServerFd != -1) 
@@ -668,23 +692,17 @@ bool HttpMethod::Go(bool ToFile,ServerState *Srv)
    // Add stdin
    FD_SET(STDIN_FILENO,&rfds);
          
-   // Error Set
-   if (FileFD != -1)
-      FD_SET(FileFD,&efds);
-   if (Srv->ServerFd != -1)
-      FD_SET(Srv->ServerFd,&efds);
-
    // Figure out the max fd
    int MaxFd = FileFD;
    if (MaxFd < Srv->ServerFd)
       MaxFd = Srv->ServerFd;
-   
+
    // Select
    struct timeval tv;
    tv.tv_sec = TimeOut;
    tv.tv_usec = 0;
    int Res = 0;
-   if ((Res = select(MaxFd+1,&rfds,&wfds,&efds,&tv)) < 0)
+   if ((Res = select(MaxFd+1,&rfds,&wfds,0,&tv)) < 0)
       return _error->Errno("select","Select failed");
    
    if (Res == 0)
@@ -693,11 +711,6 @@ bool HttpMethod::Go(bool ToFile,ServerState *Srv)
       return ServerDie(Srv);
    }
    
-   // Some kind of exception (error) on the sockets, die
-   if ((FileFD != -1 && FD_ISSET(FileFD,&efds)) || 
-       (Srv->ServerFd != -1 && FD_ISSET(Srv->ServerFd,&efds)))
-      return _error->Error("Socket Exception");
-
    // Handle server IO
    if (Srv->ServerFd != -1 && FD_ISSET(Srv->ServerFd,&rfds))
    {
@@ -723,7 +736,7 @@ bool HttpMethod::Go(bool ToFile,ServerState *Srv)
    // Handle commands from APT
    if (FD_ISSET(STDIN_FILENO,&rfds))
    {
-      if (Run(true) != 0)
+      if (Run(true) != -1)
         exit(100);
    }   
        
@@ -885,7 +898,7 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
 void HttpMethod::SigTerm(int)
 {
    if (FailFd == -1)
-      exit(100);
+      _exit(100);
    close(FailFd);
    
    // Timestamp
@@ -894,7 +907,7 @@ void HttpMethod::SigTerm(int)
    UBuf.modtime = FailTime;
    utime(FailFile.c_str(),&UBuf);
    
-   exit(100);
+   _exit(100);
 }
                                                                        /*}}}*/
 // HttpMethod::Fetch - Fetch an item                                   /*{{{*/
@@ -909,8 +922,13 @@ bool HttpMethod::Fetch(FetchItem *)
    // Queue the requests
    int Depth = -1;
    bool Tail = false;
-   for (FetchItem *I = Queue; I != 0 && Depth < (signed)PipelineDepth; I = I->Next, Depth++)
+   for (FetchItem *I = Queue; I != 0 && Depth < (signed)PipelineDepth; 
+       I = I->Next, Depth++)
    {
+      // If pipelining is disabled, we only queue 1 request
+      if (Server->Pipeline == false && Depth >= 0)
+        break;
+      
       // Make sure we stick with the same server
       if (Server->Comp(I->Uri) == false)
         break;
@@ -921,7 +939,7 @@ bool HttpMethod::Fetch(FetchItem *)
         QueueBack = I->Next;
         SendReq(I,Server->Out);
         continue;
-      }         
+      }
    }
    
    return true;
@@ -938,6 +956,7 @@ bool HttpMethod::Configuration(string Message)
    TimeOut = _config->FindI("Acquire::http::Timeout",TimeOut);
    PipelineDepth = _config->FindI("Acquire::http::Pipeline-Depth",
                                  PipelineDepth);
+   Debug = _config->FindB("Debug::Acquire::http",false);
    
    return true;
 }
@@ -962,8 +981,10 @@ int HttpMethod::Loop()
            return 0;
       }
       
-      // Run messages
-      if (Run(true) != 0)
+      /* Run messages, we can accept 0 (no message) if we didn't
+         do a WaitFd above.. Otherwise the FD is closed. */
+      int Result = Run(true);
+      if (Result != -1 && (Result != 0 || Queue == 0))
         return 100;
 
       if (Queue == 0)
@@ -1013,10 +1034,11 @@ int HttpMethod::Loop()
            FailCounter++;
            _error->Discard();
            Server->Close();
-
+           Server->Pipeline = false;
+           
            if (FailCounter >= 2)
            {
-              Fail("Connection timed out",true);
+              Fail("Connection failed",true);
               FailCounter = 0;
            }