apt  1.5
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 <stdarg.h>
00024 
00025 #include <string>
00026 #include <vector>
00027 
00028 #ifndef APT_8_CLEANER_HEADERS
00029 #include <apt-pkg/configuration.h>
00030 #include <apt-pkg/strutl.h>
00031 #endif
00032 
00033 class Hashes;
00034 class pkgAcqMethod
00035 {
00036    protected:
00037 
00038    struct FetchItem
00039    {
00040       FetchItem *Next;
00041 
00042       std::string Uri;
00043       std::string DestFile;
00044       time_t LastModified;
00045       bool IndexFile;
00046       bool FailIgnore;
00047    };
00048    
00049    struct FetchResult
00050    {
00051       std::string MD5Sum;
00052       std::string SHA1Sum;
00053       std::string SHA256Sum;
00054       std::string SHA512Sum;
00055       std::vector<std::string> GPGVOutput;
00056       time_t LastModified;
00057       bool IMSHit;
00058       std::string Filename;
00059       unsigned long long Size;
00060       unsigned long long ResumePoint;
00061       
00062       void TakeHashes(Hashes &Hash);
00063       FetchResult();
00064    };
00065 
00066    // State
00067    std::vector<std::string> Messages;
00068    FetchItem *Queue;
00069    FetchItem *QueueBack;
00070    std::string FailReason;
00071    std::string UsedMirror;
00072    std::string IP;
00073    
00074    // Handlers for messages
00075    virtual bool Configuration(std::string Message);
00076    virtual bool Fetch(FetchItem * /*Item*/) {return true;};
00077    
00078    // Outgoing messages
00079    void Fail(bool Transient = false);
00080    inline void Fail(const char *Why, bool Transient = false) {Fail(std::string(Why),Transient);};
00081    virtual void Fail(std::string Why, bool Transient = false);
00082    virtual void URIStart(FetchResult &Res);
00083    virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
00084 
00085    bool MediaFail(std::string Required,std::string Drive);
00086    virtual void Exit() {};
00087 
00088    void PrintStatus(char const * const header, const char* Format, va_list &args) const;
00089 
00090    public:
00091    enum CnfFlags {SingleInstance = (1<<0),
00092                   Pipeline = (1<<1), SendConfig = (1<<2),
00093                   LocalOnly = (1<<3), NeedsCleanup = (1<<4), 
00094                   Removable = (1<<5)};
00095 
00096    void Log(const char *Format,...);
00097    void Status(const char *Format,...);
00098    
00099    void Redirect(const std::string &NewURI);
00100  
00101    int Run(bool Single = false);
00102    inline void SetFailReason(std::string Msg) {FailReason = Msg;};
00103    inline void SetIP(std::string aIP) {IP = aIP;};
00104    
00105    pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
00106    virtual ~pkgAcqMethod() {};
00107 };
00108 
00111 #endif