summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/contrib/configuration.h3
-rw-r--r--apt-pkg/contrib/strutl.cc21
-rw-r--r--apt-pkg/contrib/strutl.h9
-rw-r--r--methods/http.cc98
-rw-r--r--methods/http.h8
5 files changed, 116 insertions, 23 deletions
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index cf5a90f57..c5c32ef2f 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: configuration.h,v 1.7 1998/10/30 07:53:44 jgg Exp $
+// $Id: configuration.h,v 1.8 1998/11/04 07:11:12 jgg Exp $
/* ######################################################################
Configuration Class
@@ -52,6 +52,7 @@ class Configuration
public:
string Find(const char *Name,const char *Default = 0);
+ string Find(string Name,const char *Default = 0) {return Find(Name.c_str(),Default);};
string FindFile(const char *Name,const char *Default = 0);
string FindDir(const char *Name,const char *Default = 0);
int FindI(const char *Name,int Default = 0);
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 5efa6f60b..c99f88c3f 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.cc,v 1.11 1998/11/01 08:07:12 jgg Exp $
+// $Id: strutl.cc,v 1.12 1998/11/04 07:11:13 jgg Exp $
/* ######################################################################
String Util - Some usefull string functions.
@@ -15,13 +15,16 @@
##################################################################### */
/*}}}*/
// Includes /*{{{*/
+#ifdef __GNUG__
+#pragma implementation "strutl.h"
+#endif
+
#include <strutl.h>
#include <apt-pkg/fileutl.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
-#include <time.h>
/*}}}*/
// strstrip - Remove white space from the front and back of a string /*{{{*/
@@ -695,6 +698,7 @@ URI::operator string()
string Res = Access + ':';
if (Host.empty() == false)
{
+ Res += "//";
if (User.empty() == false)
{
Res += "//" + User;
@@ -703,10 +707,21 @@ URI::operator string()
Res += "@";
}
Res += Host;
+ if (Port != 0)
+ {
+ char S[30];
+ sprintf(S,":%u",Port);
+ Res += S;
+ }
}
if (Path.empty() == false)
- Res += "/" + Path;
+ {
+ if (Path[0] != '/')
+ Res += "/" + Path;
+ else
+ Res += Path;
+ }
return Res;
}
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index f93184a24..10d835ba3 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.h,v 1.9 1998/11/01 05:27:38 jgg Exp $
+// $Id: strutl.h,v 1.10 1998/11/04 07:11:14 jgg Exp $
/* ######################################################################
String Util - These are some usefull string functions
@@ -16,9 +16,14 @@
#ifndef STRUTL_H
#define STRUTL_H
+#ifdef __GNUG__
+#pragma interface "strutl.h"
+#endif
+
#include <stdlib.h>
#include <string>
#include <vector>
+#include <time.h>
char *_strstrip(char *String);
char *_strtabexpand(char *String,size_t Len);
@@ -56,7 +61,7 @@ class URI
string Path;
unsigned int Port;
- inline operator string();
+ operator string();
inline operator =(string From) {CopyFrom(From);};
inline bool empty() {return Access.empty();};
diff --git a/methods/http.cc b/methods/http.cc
index d9ac79912..4c773b064 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: http.cc,v 1.2 1998/11/01 08:07:13 jgg Exp $
+// $Id: http.cc,v 1.3 1998/11/04 07:10:49 jgg Exp $
/* ######################################################################
HTTP Aquire Method - This is the HTTP aquire method for APT.
@@ -36,6 +36,7 @@
#include <sys/time.h>
#include <utime.h>
#include <unistd.h>
+#include <signal.h>
#include <stdio.h>
// Internet stuff
@@ -47,6 +48,10 @@
#include "http.h"
/*}}}*/
+string HttpMethod::FailFile;
+int HttpMethod::FailFd = -1;
+time_t HttpMethod::FailTime = 0;
+
// CircleBuf::CircleBuf - Circular input buffer /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -258,10 +263,25 @@ bool ServerState::Open()
return true;
Close();
-
+ In.Reset();
+ Out.Reset();
+
+ // Determine the proxy setting
+ string DefProxy = _config->Find("Acquire::http::Proxy",getenv("http_proxy"));
+ string SpecificProxy = _config->Find("Acquire::http::Proxy::" + ServerName.Host);
+ if (SpecificProxy.empty() == false)
+ {
+ if (SpecificProxy == "DIRECT")
+ Proxy = "";
+ else
+ Proxy = SpecificProxy;
+ }
+ else
+ Proxy = DefProxy;
+
+ // Determine what host and port to use based on the proxy settings
int Port = 80;
- string Host;
-
+ string Host;
if (Proxy.empty() == true)
{
if (ServerName.Port != 0)
@@ -275,6 +295,9 @@ bool ServerState::Open()
Host = Proxy.Host;
}
+ /* We used a cached address record.. Yes this is against the spec but
+ the way we have setup our rotating dns suggests that this is more
+ sensible */
if (LastHost != Host)
{
Owner->Status("Connecting to %s",Host.c_str());
@@ -312,8 +335,6 @@ bool ServerState::Close()
{
close(ServerFd);
ServerFd = -1;
- In.Reset();
- Out.Reset();
return true;
}
/*}}}*/
@@ -556,7 +577,12 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
ProperHost += Buf;
}
- // Build the request
+ /* Build the request. We include a keep-alive header only for non-proxy
+ requests. This is to tweak old http/1.0 servers that do support keep-alive
+ but not HTTP/1.1 automatic keep-alive. Doing this with a proxy server
+ will glitch HTTP/1.0 proxies because they do not filter it out and
+ pass it on, HTTP/1.1 says the connection should default to keep alive
+ and we expect the proxy to do this */
if (Proxy.empty() == true)
sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n",
Uri.Path.c_str(),ProperHost.c_str());
@@ -564,7 +590,7 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n",
Itm->Uri.c_str(),ProperHost.c_str());
string Req = Buf;
-
+
// Check for a partial file
struct stat SBuf;
if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
@@ -794,7 +820,11 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
File = new FileFd(Queue->DestFile,FileFd::WriteAny);
if (_error->PendingError() == true)
return 3;
-
+
+ FailFile = Queue->DestFile;
+ FailFd = File->Fd();
+ FailTime = Srv->Date;
+
// Set the expected size
if (Srv->StartPos >= 0)
{
@@ -824,11 +854,34 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
return 0;
}
/*}}}*/
-// HttpMethod::Loop /*{{{*/
+// HttpMethod::SigTerm - Handle a fatal signal /*{{{*/
+// ---------------------------------------------------------------------
+/* This closes and timestamps the open file. This is neccessary to get
+ resume behavoir on user abort */
+void HttpMethod::SigTerm(int)
+{
+ if (FailFd == -1)
+ exit(100);
+ close(FailFd);
+
+ // Timestamp
+ struct utimbuf UBuf;
+ time(&UBuf.actime);
+ UBuf.actime = FailTime;
+ UBuf.modtime = FailTime;
+ utime(FailFile.c_str(),&UBuf);
+
+ exit(100);
+}
+ /*}}}*/
+// HttpMethod::Loop - Main loop /*{{{*/
// ---------------------------------------------------------------------
/* */
int HttpMethod::Loop()
{
+ signal(SIGTERM,SigTerm);
+ signal(SIGINT,SigTerm);
+
ServerState *Server = 0;
int FailCounter = 0;
@@ -906,16 +959,29 @@ int HttpMethod::Loop()
URIStart(Res);
// Run the data
- if (Server->RunData() == false)
- Fail();
- else
+ bool Result = Server->RunData();
+
+ // Close the file, destroy the FD object and timestamp it
+ FailFd = -1;
+ delete File;
+ File = 0;
+
+ // Timestamp
+ struct utimbuf UBuf;
+ time(&UBuf.actime);
+ UBuf.actime = Server->Date;
+ UBuf.modtime = Server->Date;
+ utime(Queue->DestFile.c_str(),&UBuf);
+
+ // Send status to APT
+ if (Result == true)
{
Res.MD5Sum = Server->In.MD5->Result();
URIDone(Res);
}
-
- delete File;
- File = 0;
+ else
+ Fail();
+
break;
}
diff --git a/methods/http.h b/methods/http.h
index 962fb0027..62f329ef5 100644
--- a/methods/http.h
+++ b/methods/http.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: http.h,v 1.2 1998/11/01 08:07:14 jgg Exp $
+// $Id: http.h,v 1.3 1998/11/04 07:10:50 jgg Exp $
/* ######################################################################
HTTP Aquire Method - This is the HTTP aquire method for APT.
@@ -119,6 +119,12 @@ class HttpMethod : public pkgAcqMethod
bool ServerDie(ServerState *Srv);
int DealWithHeaders(FetchResult &Res,ServerState *Srv);
+ // In the event of a fatal signal this file will be closed and timestamped.
+ static string FailFile;
+ static int FailFd;
+ static time_t FailTime;
+ static void SigTerm(int);
+
public:
friend ServerState;