summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2006-11-29 21:24:29 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2006-11-29 21:24:29 +0100
commit5f6b130d6342965bfa49beb9413bdf742440b8ab (patch)
tree6f2516220bbeb3eccdbf997120bf031e1f7714cb /methods
parent65d71b381cc326bdf5310d8a2ea5b3f0d0307f63 (diff)
* prototype of mirror method added
Diffstat (limited to 'methods')
-rw-r--r--methods/http.cc13
-rw-r--r--methods/http.h7
-rw-r--r--methods/http_main.cc15
-rw-r--r--methods/makefile9
-rw-r--r--methods/mirror.cc97
-rw-r--r--methods/mirror.h40
6 files changed, 166 insertions, 15 deletions
diff --git a/methods/http.cc b/methods/http.cc
index c6623c46f..deaa8d0c8 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -38,7 +38,6 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
-#include <iostream>
#include <apti18n.h>
// Internet stuff
@@ -57,7 +56,7 @@ time_t HttpMethod::FailTime = 0;
unsigned long PipelineDepth = 10;
unsigned long TimeOut = 120;
bool Debug = false;
-
+URI Proxy;
unsigned long CircleBuf::BwReadLimit=0;
unsigned long CircleBuf::BwTickReadData=0;
@@ -990,7 +989,7 @@ void HttpMethod::SigTerm(int)
depth. */
bool HttpMethod::Fetch(FetchItem *)
{
- if (Server == 0)
+ if (Server == 0)
return true;
// Queue the requests
@@ -1223,13 +1222,5 @@ int HttpMethod::Loop()
}
/*}}}*/
-int main()
-{
- setlocale(LC_ALL, "");
-
- HttpMethod Mth;
-
- return Mth.Loop();
-}
diff --git a/methods/http.h b/methods/http.h
index 541e2952c..5eac11401 100644
--- a/methods/http.h
+++ b/methods/http.h
@@ -13,7 +13,7 @@
#define MAXLEN 360
-#include <iostream>
+
using std::cout;
using std::endl;
@@ -134,7 +134,6 @@ class HttpMethod : public pkgAcqMethod
bool ServerDie(ServerState *Srv);
int DealWithHeaders(FetchResult &Res,ServerState *Srv);
- virtual bool Fetch(FetchItem *);
virtual bool Configuration(string Message);
// In the event of a fatal signal this file will be closed and timestamped.
@@ -142,6 +141,9 @@ class HttpMethod : public pkgAcqMethod
static int FailFd;
static time_t FailTime;
static void SigTerm(int);
+
+ protected:
+ virtual bool Fetch(FetchItem *);
public:
friend class ServerState;
@@ -158,6 +160,5 @@ class HttpMethod : public pkgAcqMethod
};
};
-URI Proxy;
#endif
diff --git a/methods/http_main.cc b/methods/http_main.cc
new file mode 100644
index 000000000..2c46ab19d
--- /dev/null
+++ b/methods/http_main.cc
@@ -0,0 +1,15 @@
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/acquire-method.h>
+
+#include "connect.h"
+#include "rfc2553emu.h"
+#include "http.h"
+
+
+int main()
+{
+ setlocale(LC_ALL, "");
+
+ HttpMethod Mth;
+ return Mth.Loop();
+}
diff --git a/methods/makefile b/methods/makefile
index 1e3b1ef85..12e446a55 100644
--- a/methods/makefile
+++ b/methods/makefile
@@ -49,7 +49,7 @@ include $(PROGRAM_H)
PROGRAM=http
SLIBS = -lapt-pkg $(SOCKETLIBS)
LIB_MAKES = apt-pkg/makefile
-SOURCE = http.cc rfc2553emu.cc connect.cc
+SOURCE = http.cc http_main.cc rfc2553emu.cc connect.cc
include $(PROGRAM_H)
# The ftp method
@@ -66,6 +66,13 @@ LIB_MAKES = apt-pkg/makefile
SOURCE = rsh.cc
include $(PROGRAM_H)
+# The mirror method
+PROGRAM=mirror
+SLIBS = -lapt-pkg $(SOCKETLIBS)
+LIB_MAKES = apt-pkg/makefile
+SOURCE = mirror.cc http.cc rfc2553emu.cc connect.cc
+include $(PROGRAM_H)
+
# SSH and vzip2 method symlink
binary: $(BIN)/ssh $(BIN)/bzip2
veryclean: clean-$(BIN)/ssh clean-$(BIN)/bzip2
diff --git a/methods/mirror.cc b/methods/mirror.cc
new file mode 100644
index 000000000..fad076e91
--- /dev/null
+++ b/methods/mirror.cc
@@ -0,0 +1,97 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: mirror.cc,v 1.59 2004/05/08 19:42:35 mdz Exp $
+/* ######################################################################
+
+ Mirror Aquire Method - This is the Mirror aquire method for APT.
+
+ ##################################################################### */
+ /*}}}*/
+// Include Files /*{{{*/
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/acquire-method.h>
+#include <apt-pkg/acquire-item.h>
+#include <apt-pkg/acquire.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/hashes.h>
+
+#include <fstream>
+#include <iostream>
+using namespace std;
+
+#include "mirror.h"
+#include "http.h"
+
+ /*}}}*/
+
+MirrorMethod::MirrorMethod()
+ : pkgAcqMethod("1.2",Pipeline | SendConfig), HasMirrorFile(false)
+{
+#if 0
+ HasMirrorFile=true;
+ BaseUri="http://people.ubuntu.com/~mvo/mirror/mirrors///";
+ Mirror="http://de.archive.ubuntu.com/ubuntu/";
+#endif
+};
+
+bool MirrorMethod::GetMirrorFile(string uri)
+{
+ string Marker = _config->Find("Acquire::Mirror::MagicMarker","///");
+ BaseUri = uri.substr(0,uri.find(Marker));
+ BaseUri.replace(0,strlen("mirror://"),"http://");
+
+ MirrorFile = _config->FindDir("Dir::State::lists") + URItoFileName(BaseUri);
+
+ cerr << "base-uri: " << BaseUri << endl;
+ cerr << "mirror-file: " << MirrorFile << endl;
+
+ // FIXME: fetch it with curl
+ pkgAcquire Fetcher;
+ new pkgAcqFile(&Fetcher, BaseUri, "", 0, "", "", "", MirrorFile);
+ bool res = (Fetcher.Run() == pkgAcquire::Continue);
+ cerr << "fetch-result: " << res << endl;
+
+ if(res)
+ HasMirrorFile = true;
+ Fetcher.Shutdown();
+ return true;
+}
+
+bool MirrorMethod::SelectMirror()
+{
+ ifstream in(MirrorFile.c_str());
+ getline(in, Mirror);
+ cerr << "Mirror: " << Mirror << endl;
+}
+
+// MirrorMethod::Fetch - Fetch an item /*{{{*/
+// ---------------------------------------------------------------------
+/* This adds an item to the pipeline. We keep the pipeline at a fixed
+ depth. */
+bool MirrorMethod::Fetch(FetchItem *Itm)
+{
+ // get mirror information
+ if(!HasMirrorFile)
+ {
+ GetMirrorFile(Itm->Uri);
+ SelectMirror();
+ }
+
+ // change the items in the queue
+ Itm->Uri.replace(0,BaseUri.size()+_config->Find("Acquire::Mirror::MagicMarker","///").size()+2/*len("mirror")-len("http")*/,Mirror);
+ cerr << "new Fetch-uri: " << Itm->Uri << endl;
+
+ // FIXME: fetch it with!
+
+};
+
+int main()
+{
+ setlocale(LC_ALL, "");
+
+ MirrorMethod Mth;
+
+ return Mth.Run();
+}
+
+
diff --git a/methods/mirror.h b/methods/mirror.h
new file mode 100644
index 000000000..ca3428830
--- /dev/null
+++ b/methods/mirror.h
@@ -0,0 +1,40 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/// $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $
+// $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $
+/* ######################################################################
+
+ MIRROR Aquire Method - This is the MIRROR aquire method for APT.
+
+ ##################################################################### */
+ /*}}}*/
+
+#ifndef APT_MIRROR_H
+#define APT_MIRROR_H
+
+
+#include <iostream>
+
+using std::cout;
+using std::cerr;
+using std::endl;
+
+#include "http.h"
+
+class MirrorMethod : public pkgAcqMethod
+{
+ FetchResult Res;
+ string Mirror;
+ string BaseUri;
+ string MirrorFile;
+ bool HasMirrorFile;
+
+ protected:
+ bool GetMirrorFile(string uri);
+ bool SelectMirror();
+ public:
+ MirrorMethod();
+ virtual bool Fetch(FetchItem *Itm);
+};
+
+
+#endif