summaryrefslogtreecommitdiff
path: root/methods/mirror.cc
blob: fad076e91a272834eccf9b0bbdb6811af2912ea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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();
}