apt @VERSION@
acquire-method.h
Go to the documentation of this file.
00001 // -*- mode: cpp; mode: fold -*-
00002 // Description                                                          /*{{{*/
00003 // $Id: acquire-method.h,v 1.15.2.1 2003/12/24 23:09:17 mdz Exp $
00004 /* ######################################################################
00005 
00006    Acquire Method - Method helper class + functions
00007    
00008    These functions are designed to be used within the method task to
00009    ease communication with APT.
00010    
00011    ##################################################################### */
00012                                                                         /*}}}*/
00013 
00020 #ifndef PKGLIB_ACQUIRE_METHOD_H
00021 #define PKGLIB_ACQUIRE_METHOD_H
00022 
00023 #include <apt-pkg/configuration.h>
00024 #include <apt-pkg/strutl.h>
00025 
00026 #include <stdarg.h>
00027 
00028 class Hashes;
00029 class pkgAcqMethod
00030 {
00031    protected:
00032 
00033    struct FetchItem
00034    {
00035       FetchItem *Next;
00036 
00037       string Uri;
00038       string DestFile;
00039       time_t LastModified;
00040       bool IndexFile;
00041       bool FailIgnore;
00042    };
00043    
00044    struct FetchResult
00045    {
00046       string MD5Sum;
00047       string SHA1Sum;
00048       string SHA256Sum;
00049       string SHA512Sum;
00050       vector<string> GPGVOutput;
00051       time_t LastModified;
00052       bool IMSHit;
00053       string Filename;
00054       unsigned long long Size;
00055       unsigned long long ResumePoint;
00056       
00057       void TakeHashes(Hashes &Hash);
00058       FetchResult();
00059    };
00060 
00061    // State
00062    vector<string> Messages;
00063    FetchItem *Queue;
00064    FetchItem *QueueBack;
00065    string FailReason;
00066    string UsedMirror;
00067    string IP;
00068    
00069    // Handlers for messages
00070    virtual bool Configuration(string Message);
00071    virtual bool Fetch(FetchItem * /*Item*/) {return true;};
00072    
00073    // Outgoing messages
00074    void Fail(bool Transient = false);
00075    inline void Fail(const char *Why, bool Transient = false) {Fail(string(Why),Transient);};
00076    virtual void Fail(string Why, bool Transient = false);
00077    virtual void URIStart(FetchResult &Res);
00078    virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
00079 
00080    bool MediaFail(string Required,string Drive);
00081    virtual void Exit() {};
00082 
00083    void PrintStatus(char const * const header, const char* Format, va_list &args) const;
00084 
00085    public:
00086    enum CnfFlags {SingleInstance = (1<<0),
00087                   Pipeline = (1<<1), SendConfig = (1<<2),
00088                   LocalOnly = (1<<3), NeedsCleanup = (1<<4), 
00089                   Removable = (1<<5)};
00090 
00091    void Log(const char *Format,...);
00092    void Status(const char *Format,...);
00093    
00094    void Redirect(const string &NewURI);
00095  
00096    int Run(bool Single = false);
00097    inline void SetFailReason(string Msg) {FailReason = Msg;};
00098    inline void SetIP(string aIP) {IP = aIP;};
00099    
00100    pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
00101    virtual ~pkgAcqMethod() {};
00102 };
00103 
00106 #endif