// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: configuration.cc,v 1.1 1998/07/07 04:17:10 jgg Exp $
+// $Id: configuration.cc,v 1.2 1998/07/09 05:12:33 jgg Exp $
/* ######################################################################
Configuration Class
#include <stdio.h>
/*}}}*/
-Configuration *_config;
+
+Configuration *_config = new Configuration;
// Configuration::Configuration - Constructor /*{{{*/
// ---------------------------------------------------------------------
Item *I = Head->Child;
Item **Last = &Head->Child;
for (; I != 0; Last = &I->Next, I = I->Next)
- if ((Res = stringcasecmp(I->Value.begin(),I->Value.end(),S,S + Len)) == 0)
+ if ((Res = stringcasecmp(I->Tag.begin(),I->Tag.end(),S,S + Len)) == 0)
break;
-
+
if (Res == 0)
return I;
if (Create == false)
return 0;
I = new Item;
- I->Value = string(S,Len);
+ I->Tag = string(S,Len);
I->Next = *Last;
+ I->Parent = Head;
*Last = I;
return I;
}
}
Itm = Lookup(Itm,Start,End - Start,Create);
- if (Itm == 0)
- return 0;
return Itm;
}
/*}}}*/
{
Item *Itm = Lookup(Name,false);
if (Itm == 0 || Itm->Value.empty() == true)
- return Default;
+ {
+ if (Default == 0)
+ return string();
+ else
+ return Default;
+ }
+
return Itm->Value;
}
/*}}}*/
+// Configuration::FindDir - Find a directory /*{{{*/
+// ---------------------------------------------------------------------
+/* Directories are stored as the base dir in the Parent node and the
+ */
+string Configuration::FindDir(const char *Name,const char *Default = 0)
+{
+ Item *Itm = Lookup(Name,false);
+ if (Itm == 0 || Itm->Value.empty() == true)
+ {
+ if (Default == 0)
+ return string();
+ else
+ return Default;
+ }
+
+ if (Itm->Value[0] == '/' || Itm->Parent == 0)
+ return Itm->Value;
+ if (Itm->Parent->Value.end()[-1] == '/')
+ return Itm->Parent->Value + Itm->Value;
+ else
+ return Itm->Parent->Value + '/' + Itm->Value;
+}
+ /*}}}*/
// Configuration::FindI - Find an integer value /*{{{*/
// ---------------------------------------------------------------------
/* */
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: configuration.h,v 1.1 1998/07/07 04:17:10 jgg Exp $
+// $Id: configuration.h,v 1.2 1998/07/09 05:12:34 jgg Exp $
/* ######################################################################
Configuration Class
##################################################################### */
/*}}}*/
// Header section: pkglib
-#ifndef PKGLIB_TAGFILE_H
-#define PKGLIB_TAGFILE_H
+#ifndef PKGLIB_CONFIGURATION_H
+#define PKGLIB_CONFIGURATION_H
#ifdef __GNUG__
#pragma interface "pkglib/configuration.h"
{
string Value;
string Tag;
+ Item *Parent;
Item *Child;
Item *Next;
Item() : Child(0), Next(0) {};
public:
string Find(const char *Name,const char *Default = 0);
+ string FindDir(const char *Name,const char *Default = 0);
int FindI(const char *Name,int Default = 0);
void Set(const char *Name,string Value);
void Set(const char *Name,int Value);
-
+
Configuration();
};
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.h,v 1.1 1998/07/07 04:17:16 jgg Exp $
+// $Id: strutl.h,v 1.2 1998/07/09 05:12:35 jgg Exp $
/* ######################################################################
String Util - These are some usefull string functions
string Base64Encode(string Str);
int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
+inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
+inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
#endif
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: deblistparser.cc,v 1.4 1998/07/07 04:17:16 jgg Exp $
+// $Id: deblistparser.cc,v 1.5 1998/07/09 05:12:37 jgg Exp $
/* ######################################################################
Package Cache Generator - Generator for the cache structure.
// Include Files /*{{{*/
#include <pkglib/deblistparser.h>
#include <pkglib/error.h>
+#include <pkglib/configuration.h>
+#include <strutl.h>
+
#include <system.h>
/*}}}*/
return true;
int Set = 2;
- if (strncasecmp(Start,"yes",Stop - Start) == 0)
+ if (stringcasecmp(Start,Stop,"yes") == 0)
Set = 1;
- if (strncasecmp(Start,"true",Stop - Start) == 0)
+ if (stringcasecmp(Start,Stop,"true") == 0)
Set = 1;
- if (strncasecmp(Start,"no",Stop - Start) == 0)
+ if (stringcasecmp(Start,Stop,"no") == 0)
Set = 0;
- if (strncasecmp(Start,"false",Stop - Start) == 0)
+ if (stringcasecmp(Start,Stop,"false") == 0)
Set = 0;
if (Set == 2)
{
bool debListParser::Step()
{
iOffset = Tags.Offset();
+ string Arch = _config->Find("APT::architecture");
while (Tags.Step(Section) == true)
{
/* See if this is the correct Architecture, if it isnt then we
const char *Stop;
if (Section.Find("Architecture",Start,Stop) == false)
return true;
-
- if (strncmp(Start,"i386",Stop - Start) == 0 &&
- strlen("i386") == (unsigned)(Stop - Start))
+
+ if (stringcmp(Start,Stop,Arch.begin(),Arch.end()) == 0)
return true;
- if (strncmp(Start,"all",Stop - Start) == 0 &&
- 3 == (unsigned)(Stop - Start))
+ if (stringcmp(Start,Stop,"all") == 0)
return true;
iOffset = Tags.Offset();
--- /dev/null
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: init.cc,v 1.1 1998/07/09 05:12:27 jgg Exp $
+/* ######################################################################
+
+ Init - Initialize the package library
+
+ ##################################################################### */
+ /*}}}*/
+// Include files /*{{{*/
+#include <pkglib/init.h>
+ /*}}}*/
+
+// pkglibInitialize - Initialize the configuration class /*{{{*/
+// ---------------------------------------------------------------------
+/* Directories are specified in such a way that the FindDir function will
+ understand them. That is, if they don't start with a / then their parent
+ is prepended, this allows a fair degree of flexability. */
+bool pkglibInitialize(Configuration &Cnf)
+{
+ // General APT things
+ Cnf.Set("APT::Architecture","i386");
+
+ // State
+ Cnf.Set("Dir::State","/var/state/apt/");
+ Cnf.Set("Dir::State::lists","lists/");
+ Cnf.Set("Dir::State::xstatus","xstatus");
+ Cnf.Set("Dir::State::userstatus","status.user");
+
+ // Cache
+ Cnf.Set("Dir::Cache","/etc/apt/");
+ Cnf.Set("Dir::Cache::archives","archives/");
+ Cnf.Set("Dir::Cache::srcpkgcache","srcpkgcache");
+ Cnf.Set("Dir::Cache::pkhcache","pkgcache");
+
+ // Configuration
+ Cnf.Set("Dir::Etc","/etc/apt/");
+ Cnf.Set("Dir::Etc::sourcelist","sources.list");
+ Cnf.Set("Dir::Etc::main","apt.conf");
+
+ return true;
+}
+ /*}}}*/
--- /dev/null
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: init.h,v 1.1 1998/07/09 05:12:27 jgg Exp $
+/* ######################################################################
+
+ Init - Initialize the package library
+
+ This function must be called to configure the config class before
+ calling many APT library functions.
+
+ ##################################################################### */
+ /*}}}*/
+// Header section: pkglib
+#ifndef PKGLIB_INIT_H
+#define PKGLIB_INIT_H
+
+#include <pkglib/configuration.h>
+
+bool pkglibInitialize(Configuration &Cnf);
+
+#endif
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: pkgcachegen.cc,v 1.7 1998/07/07 04:17:04 jgg Exp $
+// $Id: pkgcachegen.cc,v 1.8 1998/07/09 05:12:27 jgg Exp $
/* ######################################################################
Package Cache Generator - Generator for the cache structure.
#include <pkglib/pkgcachegen.h>
#include <pkglib/error.h>
#include <pkglib/version.h>
+#include <strutl.h>
#include <sys/stat.h>
#include <unistd.h>
for (; I != Cache.StringItemP; Last = &I->NextItem,
I = Cache.StringItemP + I->NextItem)
{
- Res = strncmp(Cache.StrP + I->String,S,Size);
- if (Res == 0 && *(Cache.StrP + I->String + Size) != 0)
- Res = 1;
+ Res = stringcmp(S,S+Size,Cache.StrP + I->String);
if (Res >= 0)
break;
}
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: sourcelist.cc,v 1.1 1998/07/07 04:17:06 jgg Exp $
+// $Id: sourcelist.cc,v 1.2 1998/07/09 05:12:28 jgg Exp $
/* ######################################################################
List of Sources
#include <pkglib/sourcelist.h>
#include <pkglib/error.h>
#include <pkglib/fileutl.h>
+#include <pkglib/configuration.h>
#include <strutl.h>
-#include <options.h>
#include <fstream.h>
#include <stdio.h>
/* */
bool pkgSourceList::ReadMainList()
{
- return Read(PKG_DEB_CF_SOURCELIST);
+ return Read(_config->Find("APT::Etc:sourcelist"));
}
/*}}}*/
// SourceList::Read - Parse the sourcelist file /*{{{*/
{
if (ParseQuoteWord(C,Itm.Section) == true)
return _error->Error("Malformed line %u in source list %s (Absolute dist)",CurLine,File.c_str());
- Itm.Dist = SubstVar(Itm.Dist,"$(ARCH)",PKG_DEB_ARCH);
+ Itm.Dist = SubstVar(Itm.Dist,"$(ARCH)",_config->Find("APT::Architecture"));
List.push_back(Itm);
continue;
}
file */
pkgSourceList::const_iterator pkgSourceList::MatchPkgFile(pkgCache::VerIterator Ver)
{
- string Base = PKG_DEB_ST_LIST;
+ string Base = _config->Find("APT::Architecture");
for (const_iterator I = List.begin(); I != List.end(); I++)
{
string URI = I->PackagesURI();
switch (I->Type)
{
case Item::Deb:
- if (Base + SanitizeURI(URI) == Ver.File().FileName())
- return I;
+/* if (Base + SanitizeURI(URI) == Ver.File().FileName())
+ return I;*/
break;
};
}
if (S.find(':') == string::npos)
return false;
- S = SubstVar(S,"$(ARCH)",PKG_DEB_ARCH);
+ S = SubstVar(S,"$(ARCH)",_config->Find("APT::Architecture"));
// Make sure that the URN is / postfixed
URI = S;
if (Dist[Dist.size() - 1] == '/')
Res = URI + Dist;
else
- Res = URI + "dists/" + Dist + '/' + Section +
- "/binary-" + PKG_DEB_ARCH + '/';
+ Res = URI + "dists/" + Dist + '/' + Section +
+ "/binary-" + _config->Find("APT::Architecture") + '/';
Res += "Packages";
break;
return string(URI,0,Pos);
}
/*}}}*/
-
-// UpdateMeta - Update the meta information /*{{{*/
-// ---------------------------------------------------------------------
-/* The meta information is package files, revision information and mirror
- lists. */
-bool pkgUpdateMeta(pkgSourceList &List,pkgAquire &Engine)
-{
- if (Engine.OutputDir(PKG_DEB_ST_LIST) == false)
- return false;
-
- for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
- {
- string URI = I->PackagesURI();
- string GetInfo = I->PackagesInfo();
- switch (I->Type)
- {
- case pkgSourceList::Item::Deb:
- if (Engine.Get(URI + ".gz",List.SanitizeURI(URI),GetInfo) == false)
- return false;
- break;
- };
- }
-
- return true;
-}
- /*}}}*/
-// MakeSrcCache - Generate a cache file of all the package files /*{{{*/
-// ---------------------------------------------------------------------
-/* This goes over the source list and builds a cache of all the package
- files. */
-bool pkgMakeSrcCache(pkgSourceList &List)
-{
- // First we date check the cache
- bool Bad = false;
- while (Bad == false)
- {
- if (FileExists(PKG_DEB_CA_SRCCACHE) == false)
- break;
-
- pkgCache Cache(PKG_DEB_CA_SRCCACHE,true,true);
- if (_error->PendingError() == true)
- {
- _error->Discard();
- break;
- }
-
- // They are certianly out of sync
- if (Cache.Head().PackageFileCount != List.size())
- break;
-
- for (pkgCache::PkgFileIterator F(Cache); F.end() == false; F++)
- {
- // Search for a match in the source list
- Bad = true;
- for (pkgSourceList::const_iterator I = List.begin();
- I != List.end(); I++)
- {
- string File = string(PKG_DEB_ST_LIST) +
- List.SanitizeURI(I->PackagesURI());
- if (F.FileName() == File)
- {
- Bad = false;
- break;
- }
- }
-
- // Check if the file matches what was cached
- Bad |= !F.IsOk();
- if (Bad == true)
- break;
- }
-
- if (Bad == false)
- return true;
- }
-
- unlink(PKG_DEB_CA_SRCCACHE);
- pkgCache::MergeState Merge(PKG_DEB_CA_SRCCACHE);
- if (_error->PendingError() == true)
- return false;
-
- for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
- {
- string File = string(PKG_DEB_ST_LIST) + List.SanitizeURI(I->PackagesURI());
- if (Merge.MergePackageFile(File,"??","??") == false)
- return false;
- }
-
- return true;
-}
- /*}}}*/
-// MakeStatusCache - Generates a cache that includes the status files /*{{{*/
-// ---------------------------------------------------------------------
-/* This copies the package source cache and then merges the status and
- xstatus files into it. */
-bool pkgMakeStatusCache()
-{
- // Quickly check if the existing package cache is ok
- bool Bad = false;
- while (Bad == false)
- {
- if (FileExists(PKG_DEB_CA_PKGCACHE) == false)
- break;
-
- /* We check the dates of the two caches. This takes care of most things
- quickly and easially */
- struct stat Src;
- struct stat Pkg;
- if (stat(PKG_DEB_CA_PKGCACHE,&Pkg) != 0 ||
- stat(PKG_DEB_CA_SRCCACHE,&Src) != 0)
- break;
- if (difftime(Src.st_mtime,Pkg.st_mtime) > 0)
- break;
-
- pkgCache Cache(PKG_DEB_CA_PKGCACHE,true,true);
- if (_error->PendingError() == true)
- {
- _error->Discard();
- break;
- }
-
- for (pkgCache::PkgFileIterator F(Cache); F.end() == false; F++)
- {
- if (F.IsOk() == false)
- {
- Bad = true;
- break;
- }
- }
-
- if (Bad == false)
- return true;
- }
-
- // Check the integrity of the source cache.
- {
- pkgCache Cache(PKG_DEB_CA_SRCCACHE,true,true);
- if (_error->PendingError() == true)
- return false;
- }
-
- // Sub scope so that merge destructs before we rename the file...
- string Cache = PKG_DEB_CA_PKGCACHE ".new";
- {
- if (CopyFile(PKG_DEB_CA_SRCCACHE,Cache) == false)
- return false;
-
- pkgCache::MergeState Merge(Cache);
- if (_error->PendingError() == true)
- return false;
-
- // Merge in the user status file
- if (FileExists(PKG_DEB_ST_USERSTATUS) == true)
- if (Merge.MergePackageFile(PKG_DEB_ST_USERSTATUS,"status","0",
- pkgFLAG_NotSource) == false)
- return false;
-
- // Merge in the extra status file
- if (FileExists(PKG_DEB_ST_XSTATUS) == true)
- if (Merge.MergePackageFile(PKG_DEB_ST_XSTATUS,"status","0",
- pkgFLAG_NotSource) == false)
- return false;
-
- // Merge in the status file
- if (Merge.MergePackageFile("/var/lib/dpkg/status","status","0",
- pkgFLAG_NotSource) == false)
- return false;
- }
-
- if (rename(Cache.c_str(),PKG_DEB_CA_PKGCACHE) != 0)
- return false;
-
- return true;
-}
- /*}}}*/
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: sourcelist.h,v 1.1 1998/07/07 04:17:06 jgg Exp $
+// $Id: sourcelist.h,v 1.2 1998/07/09 05:12:31 jgg Exp $
/* ######################################################################
SourceList - Manage a list of sources
pkgSourceList(string File);
};
-bool pkgUpdateMeta(pkgSourceList &List,pkgAquire &Engine);
-bool pkgMakeSrcCache(pkgSourceList &List);
-bool pkgMakeStatusCache();
-
ostream &operator <<(ostream &O,pkgSourceList::Item &Itm);
#endif
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: tagfile.cc,v 1.5 1998/07/07 04:17:06 jgg Exp $
+// $Id: tagfile.cc,v 1.6 1998/07/09 05:12:32 jgg Exp $
/* ######################################################################
Fast scanner for RFC-822 type header information
#include <pkglib/tagfile.h>
#include <pkglib/error.h>
+#include <pkglib/init.h>
#include <string>
#include <stdio.h>
int main(int argc,char *argv[])
{
+ pkglibInitialize(*_config);
+ cout << _config->Find("APT::arch") << endl;
+ cout << _config->FindDir("DIR::Etc::sourcelist") << endl;
+
{
File CacheF("./cache",File::WriteEmpty);
DynamicMMap Map(CacheF,MMap::Public);
--- /dev/null
+/* All template instances are explicly declared here */
+
+#include <pkglib/sourcelist.h>
+
+template vector<pkgSourceList::Item>;