summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 16:51:16 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 16:51:16 +0000
commitbe4401bfa4a240bbc894e1bfeb1e1e8d63fc7b18 (patch)
tree3d48bdf9a7abff3b51c02323ea1ed26767d576d7 /apt-pkg
parentf0a53b6301cd1f5d0878f2d6ed21811d70a86f9a (diff)
New http method
Author: jgg Date: 1998-11-01 05:27:29 GMT New http method
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-method.cc129
-rw-r--r--apt-pkg/acquire-method.h33
-rw-r--r--apt-pkg/acquire-worker.cc6
-rw-r--r--apt-pkg/acquire.cc19
-rw-r--r--apt-pkg/acquire.h3
-rw-r--r--apt-pkg/contrib/md5.cc4
-rw-r--r--apt-pkg/contrib/strutl.cc6
-rw-r--r--apt-pkg/contrib/strutl.h15
8 files changed, 164 insertions, 51 deletions
diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc
index bd7dd6779..0629995a0 100644
--- a/apt-pkg/acquire-method.cc
+++ b/apt-pkg/acquire-method.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: acquire-method.cc,v 1.1 1998/10/30 07:53:35 jgg Exp $
+// $Id: acquire-method.cc,v 1.2 1998/11/01 05:27:30 jgg Exp $
/* ######################################################################
Acquire Method
@@ -45,6 +45,8 @@ pkgAcqMethod::pkgAcqMethod(const char *Ver,unsigned long Flags)
if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
exit(100);
+
+ SetNonBlock(STDIN_FILENO,true);
}
/*}}}*/
// AcqMethod::Fail - A fetch has failed /*{{{*/
@@ -65,9 +67,20 @@ void pkgAcqMethod::Fail()
void pkgAcqMethod::Fail(string Err)
{
char S[1024];
- snprintf(S,sizeof(S),"400 URI Failure\nURI: %s\n"
- "Message %s\n\n",CurrentURI.c_str(),Err.c_str());
-
+ if (Queue != 0)
+ {
+ snprintf(S,sizeof(S),"400 URI Failure\nURI: %s\n"
+ "Message: %s\n\n",Queue->Uri.c_str(),Err.c_str());
+
+ // Dequeue
+ FetchItem *Tmp = Queue;
+ Queue = Queue->Next;
+ delete Tmp;
+ }
+ else
+ snprintf(S,sizeof(S),"400 URI Failure\nURI: <UNKNOWN>\n"
+ "Message: %s\n\n",Err.c_str());
+
if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
exit(100);
}
@@ -75,12 +88,15 @@ void pkgAcqMethod::Fail(string Err)
// AcqMethod::URIStart - Indicate a download is starting /*{{{*/
// ---------------------------------------------------------------------
/* */
-void pkgAcqMethod::URIStart(FetchResult &Res,unsigned long Resume = 0)
+void pkgAcqMethod::URIStart(FetchResult &Res)
{
+ if (Queue == 0)
+ abort();
+
char S[1024] = "";
char *End = S;
- End += snprintf(S,sizeof(S),"200 URI Start\nURI: %s\n",CurrentURI.c_str());
+ End += snprintf(S,sizeof(S),"200 URI Start\nURI: %s\n",Queue->Uri.c_str());
if (Res.Size != 0)
End += snprintf(End,sizeof(S) - (End - S),"Size: %u\n",Res.Size);
@@ -88,9 +104,9 @@ void pkgAcqMethod::URIStart(FetchResult &Res,unsigned long Resume = 0)
End += snprintf(End,sizeof(S) - (End - S),"Last-Modified: %s\n",
TimeRFC1123(Res.LastModified).c_str());
- if (Resume != 0)
+ if (Res.ResumePoint != 0)
End += snprintf(End,sizeof(S) - (End - S),"Resume-Point: %u\n",
- Resume);
+ Res.ResumePoint);
strcat(End,"\n");
if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
@@ -102,10 +118,13 @@ void pkgAcqMethod::URIStart(FetchResult &Res,unsigned long Resume = 0)
/* */
void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
{
+ if (Queue == 0)
+ abort();
+
char S[1024] = "";
char *End = S;
- End += snprintf(S,sizeof(S),"201 URI Done\nURI: %s\n",CurrentURI.c_str());
+ End += snprintf(S,sizeof(S),"201 URI Done\nURI: %s\n",Queue->Uri.c_str());
if (Res.Filename.empty() == false)
End += snprintf(End,sizeof(S) - (End - S),"Filename: %s\n",Res.Filename.c_str());
@@ -147,6 +166,11 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
strcat(End,"\n");
if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
exit(100);
+
+ // Dequeue
+ FetchItem *Tmp = Queue;
+ Queue = Queue->Next;
+ delete Tmp;
}
/*}}}*/
// AcqMethod::Configuration - Handle the configuration message /*{{{*/
@@ -186,19 +210,25 @@ bool pkgAcqMethod::Configuration(string Message)
// AcqMethod::Run - Run the message engine /*{{{*/
// ---------------------------------------------------------------------
/* */
-int pkgAcqMethod::Run()
+int pkgAcqMethod::Run(bool Single)
{
- SetNonBlock(STDIN_FILENO,true);
-
while (1)
{
+ // Block if the message queue is empty
if (Messages.empty() == true)
- if (WaitFd(STDIN_FILENO) == false)
- return 0;
+ {
+ if (Single == false)
+ if (WaitFd(STDIN_FILENO) == false)
+ return 0;
+ }
if (ReadMessages(STDIN_FILENO,Messages) == false)
return 0;
-
+
+ // Single mode exits if the message queue is empty
+ if (Single == true && Messages.empty() == true)
+ return 0;
+
string Message = Messages.front();
Messages.erase(Messages.begin());
@@ -219,12 +249,20 @@ int pkgAcqMethod::Run()
break;
case 600:
- {
- CurrentURI = LookupTag(Message,"URI");
- DestFile = LookupTag(Message,"FileName");
- StrToTime(LookupTag(Message,"Last-Modified"),LastModified);
-
- if (Fetch(Message,CurrentURI) == false)
+ {
+ FetchItem *Tmp = new FetchItem;
+
+ Tmp->Uri = LookupTag(Message,"URI");
+ Tmp->DestFile = LookupTag(Message,"FileName");
+ StrToTime(LookupTag(Message,"Last-Modified"),Tmp->LastModified);
+ Tmp->Next = 0;
+
+ // Append it to the list
+ FetchItem **I = &Queue;
+ for (; *I != 0 && (*I)->Next != 0; I = &(*I)->Next);
+ *I = Tmp;
+
+ if (Fetch(Tmp) == false)
Fail();
break;
}
@@ -234,6 +272,55 @@ int pkgAcqMethod::Run()
return 0;
}
/*}}}*/
+// AcqMethod::Log - Send a log message /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgAcqMethod::Log(const char *Format,...)
+{
+ string CurrentURI = "<UNKNOWN>";
+ if (Queue != 0)
+ CurrentURI = Queue->Uri;
+
+ va_list args;
+ va_start(args,Format);
+
+ // sprintf the description
+ char S[1024];
+ unsigned int Len = snprintf(S,sizeof(S),"101 Log\nURI: %s\n"
+ "Message: ",CurrentURI.c_str());
+
+ vsnprintf(S+Len,sizeof(S)-Len,Format,args);
+ strcat(S,"\n\n");
+
+ if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
+ exit(100);
+}
+ /*}}}*/
+// AcqMethod::Status - Send a status message /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgAcqMethod::Status(const char *Format,...)
+{
+ string CurrentURI = "<UNKNOWN>";
+ if (Queue != 0)
+ CurrentURI = Queue->Uri;
+
+ va_list args;
+ va_start(args,Format);
+
+ // sprintf the description
+ char S[1024];
+ unsigned int Len = snprintf(S,sizeof(S),"101 Log\nURI: %s\n"
+ "Message: ",CurrentURI.c_str());
+
+ vsnprintf(S+Len,sizeof(S)-Len,Format,args);
+ strcat(S,"\n\n");
+
+ if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
+ exit(100);
+}
+ /*}}}*/
+
// AcqMethod::FetchResult::FetchResult - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h
index 74489913f..e3d18e341 100644
--- a/apt-pkg/acquire-method.h
+++ b/apt-pkg/acquire-method.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: acquire-method.h,v 1.1 1998/10/30 07:53:35 jgg Exp $
+// $Id: acquire-method.h,v 1.2 1998/11/01 05:27:32 jgg Exp $
/* ######################################################################
Acquire Method - Method helper class + functions
@@ -23,12 +23,16 @@
class pkgAcqMethod
{
protected:
-
- string CurrentURI;
- string DestFile;
- time_t LastModified;
- vector<string> Messages;
+ struct FetchItem
+ {
+ FetchItem *Next;
+
+ string Uri;
+ string DestFile;
+ time_t LastModified;
+ };
+
struct FetchResult
{
@@ -37,18 +41,22 @@ class pkgAcqMethod
bool IMSHit;
string Filename;
unsigned long Size;
+ unsigned long ResumePoint;
FetchResult();
};
-
+
+ // State
+ vector<string> Messages;
+ FetchItem *Queue;
+
// Handlers for messages
virtual bool Configuration(string Message);
- virtual bool Fetch(string Message,URI Get) {return true;};
+ virtual bool Fetch(FetchItem *Item) {return true;};
// Outgoing messages
void Fail();
void Fail(string Why);
-// void Log(const char *Format,...);
- void URIStart(FetchResult &Res,unsigned long Resume = 0);
+ void URIStart(FetchResult &Res);
void URIDone(FetchResult &Res,FetchResult *Alt = 0);
public:
@@ -56,7 +64,10 @@ class pkgAcqMethod
enum CnfFlags {SingleInstance = (1<<0), PreScan = (1<<1),
Pipeline = (1<<2), SendConfig = (1<<3)};
- int Run();
+ void Log(const char *Format,...);
+ void Status(const char *Format,...);
+
+ int Run(bool Single = false);
pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
virtual ~pkgAcqMethod() {};
diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc
index 5195b5b8d..a02c6bc04 100644
--- a/apt-pkg/acquire-worker.cc
+++ b/apt-pkg/acquire-worker.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: acquire-worker.cc,v 1.8 1998/10/30 07:53:35 jgg Exp $
+// $Id: acquire-worker.cc,v 1.9 1998/11/01 05:27:33 jgg Exp $
/* ######################################################################
Acquire Worker
@@ -237,9 +237,9 @@ bool pkgAcquire::Worker::RunMessages()
break;
}
+ OwnerQ->ItemDone(Itm);
Itm->Owner->Done(Message,atoi(LookupTag(Message,"Size","0").c_str()),
LookupTag(Message,"MD5-Hash"));
- OwnerQ->ItemDone(Itm);
break;
}
@@ -252,8 +252,8 @@ bool pkgAcquire::Worker::RunMessages()
break;
}
- Itm->Owner->Failed(Message);
OwnerQ->ItemDone(Itm);
+ Itm->Owner->Failed(Message);
break;
}
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index 3ed0e5d28..91b2a7590 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: acquire.cc,v 1.6 1998/10/30 07:53:37 jgg Exp $
+// $Id: acquire.cc,v 1.7 1998/11/01 05:27:34 jgg Exp $
/* ######################################################################
Acquire - File Acquiration
@@ -290,21 +290,23 @@ bool pkgAcquire::Run()
if (_error->PendingError() == true)
break;
}
-
+
+ // Shut down the acquire bits
+ Running = false;
for (Queue *I = Queues; I != 0; I = I->Next)
I->Shutdown();
- Running = false;
return _error->PendingError();
}
/*}}}*/
-// pkgAcquire::Bump - Called when an item is dequeued /*{{{*/
+// Acquire::Bump - Called when an item is dequeued /*{{{*/
// ---------------------------------------------------------------------
/* This routine bumps idle queues in hopes that they will be able to fetch
the dequeued item */
void pkgAcquire::Bump()
{
-
+ for (Queue *I = Queues; I != 0; I = I->Next)
+ I->Bump();
}
/*}}}*/
@@ -476,3 +478,10 @@ bool pkgAcquire::Queue::Cycle()
return Workers->QueueItem(I);
}
/*}}}*/
+// Queue::Bump - Fetch any pending objects if we are idle /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgAcquire::Queue::Bump()
+{
+}
+ /*}}}*/
diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h
index 20ce2873f..25fe4b761 100644
--- a/apt-pkg/acquire.h
+++ b/apt-pkg/acquire.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: acquire.h,v 1.6 1998/10/30 07:53:38 jgg Exp $
+// $Id: acquire.h,v 1.7 1998/11/01 05:27:35 jgg Exp $
/* ######################################################################
Acquire - File Acquiration
@@ -133,6 +133,7 @@ class pkgAcquire::Queue
bool Startup();
bool Shutdown();
bool Cycle();
+ void Bump();
Queue(string Name,pkgAcquire *Owner);
~Queue();
diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc
index 046135f5e..671d61d06 100644
--- a/apt-pkg/contrib/md5.cc
+++ b/apt-pkg/contrib/md5.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: md5.cc,v 1.1 1998/10/31 05:19:59 jgg Exp $
+// $Id: md5.cc,v 1.2 1998/11/01 05:27:36 jgg Exp $
/* ######################################################################
MD5Sum - MD5 Message Digest Algorithm.
@@ -40,7 +40,7 @@
/*}}}*/
// Include Files /*{{{*/
#ifdef __GNUG__
-#pragma interface "apt-pkg/md5.h"
+#pragma implementation "apt-pkg/md5.h"
#endif
#include <apt-pkg/md5.h>
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index d6a7143e4..2c3106ceb 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.9 1998/10/30 07:53:45 jgg Exp $
+// $Id: strutl.cc,v 1.10 1998/11/01 05:27:37 jgg Exp $
/* ######################################################################
String Util - Some usefull string functions.
@@ -609,10 +609,10 @@ bool StrToTime(string Val,time_t &Result)
}
/*}}}*/
-// URI::URI - Constructor /*{{{*/
+// URI::CopyFrom - Copy from an object /*{{{*/
// ---------------------------------------------------------------------
/* This parses the URI into all of its components */
-URI::URI(string U)
+void URI::CopyFrom(string U)
{
string::const_iterator I = U.begin();
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 7e3e47344..f93184a24 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.8 1998/10/30 07:53:46 jgg Exp $
+// $Id: strutl.h,v 1.9 1998/11/01 05:27:38 jgg Exp $
/* ######################################################################
String Util - These are some usefull string functions
@@ -13,8 +13,6 @@
##################################################################### */
/*}}}*/
-// This is a private header
-// Header section: /
#ifndef STRUTL_H
#define STRUTL_H
@@ -40,11 +38,15 @@ bool ReadMessages(int Fd, vector<string> &List);
int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
+inline int stringcmp(string A,const char *B) {return stringcmp(A.begin(),A.end(),B,B+strlen(B));};
int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
+inline int stringcasecmp(string A,const char *B) {return stringcasecmp(A.begin(),A.end(),B,B+strlen(B));};
class URI
{
+ void CopyFrom(string From);
+
public:
string Access;
@@ -54,9 +56,12 @@ class URI
string Path;
unsigned int Port;
- operator string();
+ inline operator string();
+ inline operator =(string From) {CopyFrom(From);};
+ inline bool empty() {return Access.empty();};
- URI(string Path);
+ URI(string Path) {CopyFrom(Path);};
+ URI() : Port(0) {};
};
#endif