* prototype of mirror method added
[ntk/apt.git] / methods / mirror.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: mirror.cc,v 1.59 2004/05/08 19:42:35 mdz Exp $
4 /* ######################################################################
5
6 Mirror Aquire Method - This is the Mirror aquire method for APT.
7
8 ##################################################################### */
9 /*}}}*/
10 // Include Files /*{{{*/
11 #include <apt-pkg/fileutl.h>
12 #include <apt-pkg/acquire-method.h>
13 #include <apt-pkg/acquire-item.h>
14 #include <apt-pkg/acquire.h>
15 #include <apt-pkg/error.h>
16 #include <apt-pkg/hashes.h>
17
18 #include <fstream>
19 #include <iostream>
20 using namespace std;
21
22 #include "mirror.h"
23 #include "http.h"
24
25 /*}}}*/
26
27 MirrorMethod::MirrorMethod()
28 : pkgAcqMethod("1.2",Pipeline | SendConfig), HasMirrorFile(false)
29 {
30 #if 0
31 HasMirrorFile=true;
32 BaseUri="http://people.ubuntu.com/~mvo/mirror/mirrors///";
33 Mirror="http://de.archive.ubuntu.com/ubuntu/";
34 #endif
35 };
36
37 bool MirrorMethod::GetMirrorFile(string uri)
38 {
39 string Marker = _config->Find("Acquire::Mirror::MagicMarker","///");
40 BaseUri = uri.substr(0,uri.find(Marker));
41 BaseUri.replace(0,strlen("mirror://"),"http://");
42
43 MirrorFile = _config->FindDir("Dir::State::lists") + URItoFileName(BaseUri);
44
45 cerr << "base-uri: " << BaseUri << endl;
46 cerr << "mirror-file: " << MirrorFile << endl;
47
48 // FIXME: fetch it with curl
49 pkgAcquire Fetcher;
50 new pkgAcqFile(&Fetcher, BaseUri, "", 0, "", "", "", MirrorFile);
51 bool res = (Fetcher.Run() == pkgAcquire::Continue);
52 cerr << "fetch-result: " << res << endl;
53
54 if(res)
55 HasMirrorFile = true;
56 Fetcher.Shutdown();
57 return true;
58 }
59
60 bool MirrorMethod::SelectMirror()
61 {
62 ifstream in(MirrorFile.c_str());
63 getline(in, Mirror);
64 cerr << "Mirror: " << Mirror << endl;
65 }
66
67 // MirrorMethod::Fetch - Fetch an item /*{{{*/
68 // ---------------------------------------------------------------------
69 /* This adds an item to the pipeline. We keep the pipeline at a fixed
70 depth. */
71 bool MirrorMethod::Fetch(FetchItem *Itm)
72 {
73 // get mirror information
74 if(!HasMirrorFile)
75 {
76 GetMirrorFile(Itm->Uri);
77 SelectMirror();
78 }
79
80 // change the items in the queue
81 Itm->Uri.replace(0,BaseUri.size()+_config->Find("Acquire::Mirror::MagicMarker","///").size()+2/*len("mirror")-len("http")*/,Mirror);
82 cerr << "new Fetch-uri: " << Itm->Uri << endl;
83
84 // FIXME: fetch it with!
85
86 };
87
88 int main()
89 {
90 setlocale(LC_ALL, "");
91
92 MirrorMethod Mth;
93
94 return Mth.Run();
95 }
96
97