jigdo API
Last update by Admin on 2010-05-23
job/jigdo-io.hh
Go to the documentation of this file.00001 /* $Id: jigdo-io.hh,v 1.5 2003/09/16 23:32:10 atterer Exp $ -*- C++ -*- 00002 __ _ 00003 |_) /| Copyright (C) 2003 | richard@ 00004 | \/¯| Richard Atterer | atterer.net 00005 ¯ '` ¯ 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License, version 2. See 00008 the file COPYING for details. 00009 00010 */ 00016 #ifndef JIGDO_IO_HH 00017 #define JIGDO_IO_HH 00018 00019 #include <config.h> 00020 #include <vector> 00021 #include <string> 00022 00023 #include <datasource.hh> 00024 #include <gunzip.hh> 00025 #include <jigdo-io.fh> 00026 #include <makeimagedl.hh> 00027 #include <md5sum.fh> 00028 #include <nocopy.hh> 00029 #include <status.hh> 00030 //______________________________________________________________________ 00031 00032 namespace Job { 00033 class JigdoIO; 00034 struct JigdoIOTest; 00035 } 00036 00038 class Job::JigdoIO : NoCopy, public Job::DataSource::IO, Gunzip::IO { 00039 public: 00040 00046 JigdoIO(MakeImageDl::Child* c, const string& url/* IOPtr, 00047 DataSource::IO* frontendIo*/); 00048 ~JigdoIO(); 00049 00050 inline MakeImageDl* master() const; 00051 inline DataSource* source() const; 00052 00053 private: 00054 friend struct Job::JigdoIOTest; 00055 00056 /* Create object for an [Include]d file */ 00057 JigdoIO(MakeImageDl::Child* c, const string& url, 00058 /*DataSource::IO* frontendIo,*/ JigdoIO* parentJigdo, 00059 int inclLine); 00060 00062 inline JigdoIO* root(); 00063 inline const JigdoIO* root() const; 00065 inline bool isRoot() const; 00071 inline JigdoIO* imgSectCandidate() const; 00073 inline void setImgSectCandidate(JigdoIO* c); 00074 // The methods below are called in various places to find 1st image section 00075 inline void imgSect_newChild(JigdoIO* child); // Child created after [Incl. 00076 inline void imgSect_parsed(); // [Image] occurred in current .jigdo data 00077 /* End of current file without any [Image]. Returns 1 if OK and all 00078 JigdoIOs finished */ 00079 inline XStatus imgSect_eof(); 00080 00081 // Create error message with URL and line number 00082 void generateError(const string& msg); 00083 void generateError(const char* msg); 00084 // As above, but directly pass on error string, do not add URL/line 00085 void generateError_plain(const string& err); 00086 // True after above was called 00087 inline bool failed() const; 00088 // Called by gunzip_data(): New .jigdo line ready. Arg is empty on exit. 00089 void jigdoLine(string* l); 00090 void include(string* url); // "[Include http://xxx]" found 00091 void entry(string* label, string* data, unsigned valueOff); 00092 /* Called at the end of a [Section] (=start of another section or EOF) 00093 Returns FAILURE if there is an error. */ 00094 Status sectionEnd(); 00095 00096 // Virtual methods from DataSource::IO 00097 virtual void job_deleted(); 00098 virtual void job_succeeded(); 00099 virtual void job_failed(const string& message); 00100 virtual void job_message(const string& message); 00101 virtual void dataSource_dataSize(uint64 n); 00102 virtual void dataSource_data(const byte* data, unsigned size, 00103 uint64 currentSize); 00104 00105 // Virtual methods from Gunzip::IO 00106 virtual void gunzip_deleted(); 00107 virtual void gunzip_data(Gunzip*, byte* decompressed, unsigned size); 00108 virtual void gunzip_needOut(Gunzip*); 00109 virtual void gunzip_failed(string* message); 00110 00111 MakeImageDl::Child* childDl; 00112 string urlVal; // Absolute URL of this .jigdo file 00113 00114 /* Representation of the tree of [Include] directives. Most of the time, 00115 the order of data in the .jigdo files is not relevant, with one 00116 exception: We must interpret the first [Image] section only, and ignore 00117 all following ones. */ 00118 JigdoIO* parent; // .jigdo file which [Include]d us, or null if top-level 00119 int includeLine; // If parent!=null, line num of [Include] in parent 00120 JigdoIO* firstChild; // First file we [Include], or null if none 00121 JigdoIO* next; // Right sibling, or null if none 00122 /* For the root object, contains imgSectCandidate, else ptr to root object. 00123 Don't access directly, use accessor methods. */ 00124 JigdoIO* rootAndImageSectionCandidate; 00125 00126 int line; // Line number, for errors. 0 if no data yet, -1 if finished 00127 bool finished() { return line < 0; } 00128 void setFinished() { line = -1; } 00129 string section; // Current section name, empty if none yet 00130 00131 // Info about first image section of this .jigdo, if any 00132 int imageSectionLine; // 0 if no [Image] found yet 00133 string imageName; 00134 string imageInfo, imageShortInfo; 00135 SmartPtr<PartUrlMapping> templateUrls; // Can contain a list of altern. URLs 00136 MD5* templateMd5; 00137 00138 /* Transparent gunzipping of .jigdo file. GUNZIP_BUF_SIZE is also the max 00139 size a single line in the .jigdo is allowed to have */ 00140 static const unsigned GUNZIP_BUF_SIZE = 16384; 00141 Gunzip gunzip; 00142 byte gunzipBuf[GUNZIP_BUF_SIZE]; 00143 }; 00144 //______________________________________________________________________ 00145 00146 Job::JigdoIO* Job::JigdoIO::root() { 00147 if (isRoot()) return this; else return rootAndImageSectionCandidate; 00148 } 00149 const Job::JigdoIO* Job::JigdoIO::root() const { 00150 if (isRoot()) return this; else return rootAndImageSectionCandidate; 00151 } 00152 bool Job::JigdoIO::isRoot() const { 00153 return parent == 0; 00154 } 00155 00156 Job::JigdoIO* Job::JigdoIO::imgSectCandidate() const { 00157 if (isRoot()) 00158 return rootAndImageSectionCandidate; 00159 else 00160 return rootAndImageSectionCandidate->rootAndImageSectionCandidate; 00161 } 00162 void Job::JigdoIO::setImgSectCandidate(JigdoIO* c) { 00163 if (isRoot()) 00164 rootAndImageSectionCandidate = c; 00165 else 00166 rootAndImageSectionCandidate->rootAndImageSectionCandidate = c; 00167 } 00168 00169 Job::MakeImageDl* Job::JigdoIO::master() const { return childDl->master(); } 00170 Job::DataSource* Job::JigdoIO::source() const { return childDl->source(); } 00171 00172 bool Job::JigdoIO::failed() const { 00173 return (imageName.length() == 1 && imageName[0] == '\0'); 00174 //return (childFailedId != 0); 00175 } 00176 00177 #endif
Generated on Tue Sep 23 14:27:41 2008 for jigdo by
