memset(Sum,0,sizeof(Sum));
Set(Str);
}
+
+MD5SumValue::MD5SumValue(const srkString &Str)
+{
+ memset(Sum, 0, sizeof(Sum));
+ Set(Str);
+}
/*}}}*/
// MD5SumValue::MD5SumValue - Default constructor /*{{{*/
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
/* Converts the hex string into a set of chars */
bool MD5SumValue::Set(string Str)
+{
+ return Hex2Num(Str,Sum,sizeof(Sum));
+}
+
+bool MD5SumValue::Set(const srkString &Str)
{
return Hex2Num(Str,Sum,sizeof(Sum));
}
#include <algorithm>
#include <stdint.h>
+#include <apt-pkg/srkstring.h>
+
using std::string;
using std::min;
{for (int I = 0; I != sizeof(Sum); I++) S[I] = Sum[I];};
inline operator string() const {return Value();};
bool Set(string Str);
+ bool Set(const srkString &Str);
inline void Set(unsigned char S[16])
{for (int I = 0; I != sizeof(Sum); I++) Sum[I] = S[I];};
MD5SumValue(string Str);
+ MD5SumValue(const srkString &Str);
MD5SumValue();
};
// ---------------------------------------------------------------------
/* The length of the buffer must be exactly 1/2 the length of the string. */
bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length)
+{
+ return Hex2Num(srkString(Str), Num, Length);
+}
+
+bool Hex2Num(const srkString &Str,unsigned char *Num,unsigned int Length)
{
if (Str.length() != Length*2)
return false;
// Convert each digit. We store it in the same order as the string
int J = 0;
- for (string::const_iterator I = Str.begin(); I != Str.end();J++, I += 2)
+ for (srkString::const_iterator I = Str.begin(); I != Str.end();J++, I += 2)
{
if (isxdigit(*I) == 0 || isxdigit(I[1]) == 0)
return false;
#include <iostream>
#include <time.h>
+#include <apt-pkg/srkstring.h>
+
using std::string;
using std::vector;
using std::ostream;
bool ReadMessages(int Fd, vector<string> &List);
bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0);
bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length);
+bool Hex2Num(const srkString &Str,unsigned char *Num,unsigned int Length);
bool TokSplitString(char Tok,char *Input,char **List,
unsigned long ListMax);
void ioprintf(ostream &out,const char *format,...) APT_FORMAT2;
int tolower_ascii(int c);
#define APT_MKSTRCMP(name,func) \
+inline int name(const srkString &A,const char *B) {return func(A.Start,A.Start+A.Size,B,B+strlen(B));}; \
inline int name(const char *A,const char *B) {return func(A,A+strlen(A),B,B+strlen(B));}; \
inline int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));}; \
inline int name(const string& A,const char *B) {return func(A.c_str(),A.c_str()+A.length(),B,B+strlen(B));}; \
const char *Stop;
if (Section.Find("Priority",Start,Stop) == true)
{
- if (GrabWord(string(Start,Stop-Start),PrioList,Ver->Priority) == false)
+ if (GrabWord(srkString(Start,Stop-Start),PrioList,Ver->Priority) == false)
Ver->Priority = pkgCache::State::Extra;
}
only describe package properties */
string debListParser::Description()
{
- if (DescriptionLanguage().empty())
- return Section.FindS("Description");
- else
- return Section.FindS(("Description-" + pkgIndexFile::LanguageCode()).c_str());
+ srkString description;
+ Description(description);
+ return description;
+}
+
+void debListParser::Description(srkString &Str) {
+ const char *Start, *Stop;
+ if (!Section.Find("Description", Start, Stop))
+ if (!Section.Find(("Description-" + pkgIndexFile::LanguageCode()).c_str(), Start, Stop)) {
+ Start = NULL;
+ Stop = NULL;
+ }
+ Str.assign(Start, Stop);
}
/*}}}*/
// ListParser::DescriptionLanguage - Return the description lang string /*{{{*/
assumed to describe original description. */
string debListParser::DescriptionLanguage()
{
- return Section.FindS("Description").empty() ? pkgIndexFile::LanguageCode() : "";
+ const char *Start, *Stop;
+ return Section.Find("Description", Start, Stop) ? std::string() : pkgIndexFile::LanguageCode();
}
/*}}}*/
// ListParser::Description - Return the description_md5 MD5SumValue /*{{{*/
*/
MD5SumValue debListParser::Description_md5()
{
- string value = Section.FindS("Description-md5");
-
- if (value.empty())
+ const char *Start;
+ const char *Stop;
+ if (!Section.Find("Description-md5", Start, Stop))
{
MD5Summation md5;
- md5.Add((Description() + "\n").c_str());
+ srkString description;
+ Description(description);
+ md5.Add((const unsigned char *) description.Start, description.Size);
+ md5.Add("\n");
return md5.Result();
} else
- return MD5SumValue(value);
+ return MD5SumValue(srkString(Start, Stop));
}
/*}}}*/
// ListParser::UsePackage - Update a package structure /*{{{*/
{"deinstall",pkgCache::State::DeInstall},
{"purge",pkgCache::State::Purge},
{}};
- if (GrabWord(string(Start,I-Start),WantList,Pkg->SelectedState) == false)
+ if (GrabWord(srkString(Start,I-Start),WantList,Pkg->SelectedState) == false)
return _error->Error("Malformed 1st word in the Status line");
// Isloate the next word
{"hold",pkgCache::State::HoldInst},
{"hold-reinstreq",pkgCache::State::HoldReInstReq},
{}};
- if (GrabWord(string(Start,I-Start),FlagList,Pkg->InstState) == false)
+ if (GrabWord(srkString(Start,I-Start),FlagList,Pkg->InstState) == false)
return _error->Error("Malformed 2nd word in the Status line");
// Isloate the last word
{"post-inst-failed",pkgCache::State::HalfConfigured},
{"removal-failed",pkgCache::State::HalfInstalled},
{}};
- if (GrabWord(string(Start,I-Start),StatusList,Pkg->CurrentState) == false)
+ if (GrabWord(srkString(Start,I-Start),StatusList,Pkg->CurrentState) == false)
return _error->Error("Malformed 3rd word in the Status line");
/* A Status line marks the package as indicating the current
const char *debListParser::ParseDepends(const char *Start,const char *Stop,
string &Package,string &Ver,
unsigned int &Op, bool ParseArchFlags)
+{
+ srkString cPackage, cVer;
+ const char *Value = ParseDepends(Start, Stop, cPackage, cVer, Op, ParseArchFlags);
+ Package = cPackage;
+ Ver = cVer;
+ return Value;
+}
+
+const char *debListParser::ParseDepends(const char *Start,const char *Stop,
+ srkString &Package,srkString &Ver,
+ unsigned int &Op, bool ParseArchFlags)
{
// Strip off leading space
for (;Start != Stop && isspace(*Start) != 0; Start++);
Found = !Found;
if (Found == false)
- Package = ""; /* not for this arch */
+ Package.clear(); /* not for this arch */
}
// Skip whitespace
if (Section.Find(Tag,Start,Stop) == false)
return true;
- string Package;
- string Version;
+ srkString Package;
+ srkString Version;
unsigned int Op;
while (1)
if (Section.Find("Provides",Start,Stop) == false)
return true;
- string Package;
- string Version;
+ srkString Package;
+ srkString Version;
unsigned int Op;
while (1)
if (Start == 0)
return _error->Error("Problem parsing Provides line");
if (Op != pkgCache::Dep::NoOp) {
- _error->Warning("Ignoring Provides line with DepCompareOp for package %s", Package.c_str());
+ _error->Warning("Ignoring Provides line with DepCompareOp for package %s", std::string(Package).c_str());
} else {
if (NewProvides(Ver,Package,Version) == false)
return false;
// ---------------------------------------------------------------------
/* Looks for a word in a list of words - for ParseStatus */
bool debListParser::GrabWord(string Word,WordList *List,unsigned char &Out)
+{
+ return GrabWord(srkString(Word), List, Out);
+}
+
+bool debListParser::GrabWord(const srkString &Word,WordList *List,unsigned char &Out)
{
for (unsigned int C = 0; List[C].Str != 0; C++)
{
- if (strcasecmp(Word.c_str(),List[C].Str) == 0)
+ if (strncasecmp(Word.Start,List[C].Str,Word.Size) == 0)
{
Out = List[C].Val;
return true;
bool ParseProvides(pkgCache::VerIterator Ver);
bool ParseTag(pkgCache::PkgIterator Pkg);
static bool GrabWord(string Word,WordList *List,unsigned char &Out);
+ static bool GrabWord(const srkString &Word,WordList *List,unsigned char &Out);
public:
+ srkString Find(const char *Tag) {
+ srkString S;
+ const char *Stop;
+ if (Section.Find(Tag, S.Start, Stop))
+ S.Size = Stop - S.Start;
+ else {
+ S.Start = NULL;
+ S.Size = 0;
+ }
+ return S;
+ }
+
static unsigned char GetPrio(string Str);
// These all operate against the current section
virtual string Version();
virtual bool NewVersion(pkgCache::VerIterator Ver);
virtual string Description();
+ void Description(srkString &Str);
virtual string DescriptionLanguage();
virtual MD5SumValue Description_md5();
virtual unsigned short VersionHash();
static const char *ParseDepends(const char *Start,const char *Stop,
string &Package,string &Ver,unsigned int &Op,
bool ParseArchFlags = false);
+ static const char *ParseDepends(const char *Start,const char *Stop,
+ srkString &Package,srkString &Ver,unsigned int &Op,
+ bool ParseArchFlags = false);
static const char *ConvertRelation(const char *I,unsigned int &Op);
debListParser(FileFd *File);
acquire.h acquire-worker.h acquire-item.h acquire-method.h \
clean.h srcrecords.h cachefile.h versionmatch.h policy.h \
pkgsystem.h indexfile.h metaindex.h indexrecords.h vendor.h \
- vendorlist.h cdrom.h indexcopy.h aptconfiguration.h
+ vendorlist.h cdrom.h indexcopy.h aptconfiguration.h srkstring.h
# Source code for the debian specific components
# In theory the deb headers do not need to be exported..
return Hash % _count(HeaderP->HashTable);
}
+unsigned long pkgCache::sHash(const srkString &Str) const
+{
+ unsigned long Hash = 0;
+ for (const char *I = Str.Start, *E = I + Str.Size; I != E; I++)
+ Hash = 5*Hash + tolower_ascii(*I);
+ return Hash % _count(HeaderP->HashTable);
+}
+
/*}}}*/
// Cache::FindPkg - Locate a package by name /*{{{*/
// ---------------------------------------------------------------------
/* Returns 0 on error, pointer to the package otherwise */
pkgCache::PkgIterator pkgCache::FindPkg(const string &Name)
+{
+ return FindPkg(srkString(Name));
+}
+
+pkgCache::PkgIterator pkgCache::FindPkg(const srkString &Name)
{
// Look at the hash bucket
Package *Pkg = PkgP + HeaderP->HashTable[Hash(Name)];
#include <string>
#include <time.h>
#include <apt-pkg/mmap.h>
+#include <apt-pkg/srkstring.h>
using std::string;
-
+
class pkgVersioningSystem;
class pkgCache /*{{{*/
{
unsigned long sHash(const string &S) const;
unsigned long sHash(const char *S) const;
+ unsigned long sHash(const srkString &S) const;
public:
// String hashing function (512 range)
inline unsigned long Hash(const string &S) const {return sHash(S);};
inline unsigned long Hash(const char *S) const {return sHash(S);};
+ inline unsigned long Hash(const srkString &S) const {return sHash(S);};
// Usefull transformation things
const char *Priority(unsigned char Priority);
// Accessors
PkgIterator FindPkg(const string &Name);
+ PkgIterator FindPkg(const srkString &Name);
Header &Head() {return *HeaderP;};
inline PkgIterator PkgBegin();
inline PkgIterator PkgEnd();
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
+
+#include <apt-pkg/deblistparser.h>
/*}}}*/
typedef vector<pkgIndexFile *>::iterator FileIterator;
pkgCache::VerIterator *OutVer)
{
List.Owner = this;
+ debListParser *debian(dynamic_cast<debListParser *>(&List));
unsigned int Counter = 0;
while (List.Step() == true)
{
// Get a pointer to the package structure
- string PackageName = List.Package();
+ srkString PackageName;
+ if (debian != NULL)
+ PackageName = debian->Find("Package");
+ else
+ PackageName = List.Package();
if (PackageName.empty() == true)
return false;
pkgCache::PkgIterator Pkg;
if (NewPackage(Pkg,PackageName) == false)
- return _error->Error(_("Error occurred while processing %s (NewPackage)"),PackageName.c_str());
+ return _error->Error(_("Error occurred while processing %s (NewPackage)"),std::string(PackageName).c_str());
Counter++;
if (Counter % 100 == 0 && Progress != 0)
Progress->Progress(List.Offset());
+ string language(List.DescriptionLanguage());
+
/* Get a pointer to the version structure. We know the list is sorted
so we use that fact in the search. Insertion of new versions is
done with correct sorting */
- string Version = List.Version();
+ srkString Version;
+ if (debian != NULL)
+ Version = debian->Find("Version");
+ else
+ Version = List.Version();
if (Version.empty() == true)
{
// we first process the package, then the descriptions
// of MMap space)
if (List.UsePackage(Pkg,pkgCache::VerIterator(Cache)) == false)
return _error->Error(_("Error occurred while processing %s (UsePackage1)"),
- PackageName.c_str());
+ std::string(PackageName).c_str());
// Find the right version to write the description
MD5SumValue CurMd5 = List.Description_md5();
// md5 && language
for ( ; Desc.end() == false; Desc++)
if (MD5SumValue(Desc.md5()) == CurMd5 &&
- Desc.LanguageCode() == List.DescriptionLanguage())
+ Desc.LanguageCode() == language)
duplicate=true;
if(duplicate)
continue;
if (MD5SumValue(Desc.md5()) == CurMd5)
{
// Add new description
- *LastDesc = NewDescription(Desc, List.DescriptionLanguage(), CurMd5, *LastDesc);
+ *LastDesc = NewDescription(Desc, language, CurMd5, *LastDesc);
Desc->ParentPkg = Pkg.Index();
if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false)
- return _error->Error(_("Error occurred while processing %s (NewFileDesc1)"),PackageName.c_str());
+ return _error->Error(_("Error occurred while processing %s (NewFileDesc1)"),std::string(PackageName).c_str());
break;
}
}
{
if (List.UsePackage(Pkg,Ver) == false)
return _error->Error(_("Error occurred while processing %s (UsePackage2)"),
- PackageName.c_str());
+ std::string(PackageName).c_str());
if (NewFileVer(Ver,List) == false)
return _error->Error(_("Error occurred while processing %s (NewFileVer1)"),
- PackageName.c_str());
+ std::string(PackageName).c_str());
// Read only a single record and return
if (OutVer != 0)
if ((*LastVer == 0 && _error->PendingError()) || List.NewVersion(Ver) == false)
return _error->Error(_("Error occurred while processing %s (NewVersion1)"),
- PackageName.c_str());
+ std::string(PackageName).c_str());
if (List.UsePackage(Pkg,Ver) == false)
return _error->Error(_("Error occurred while processing %s (UsePackage3)"),
- PackageName.c_str());
+ std::string(PackageName).c_str());
if (NewFileVer(Ver,List) == false)
return _error->Error(_("Error occurred while processing %s (NewVersion2)"),
- PackageName.c_str());
+ std::string(PackageName).c_str());
// Read only a single record and return
if (OutVer != 0)
for (; Desc.end() == false; LastDesc = &Desc->NextDesc, Desc++);
// Add new description
- *LastDesc = NewDescription(Desc, List.DescriptionLanguage(), List.Description_md5(), *LastDesc);
+ *LastDesc = NewDescription(Desc, language, List.Description_md5(), *LastDesc);
Desc->ParentPkg = Pkg.Index();
if ((*LastDesc == 0 && _error->PendingError()) || NewFileDesc(Desc,List) == false)
- return _error->Error(_("Error occurred while processing %s (NewFileDesc2)"),PackageName.c_str());
+ return _error->Error(_("Error occurred while processing %s (NewFileDesc2)"),std::string(PackageName).c_str());
}
FoundFileDeps |= List.HasFileDeps();
// ---------------------------------------------------------------------
/* This creates a new package structure and adds it to the hash table */
bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name)
+{
+ return NewPackage(Pkg, srkString(Name));
+}
+
+bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const srkString &Name)
{
Pkg = Cache.FindPkg(Name);
if (Pkg.end() == false)
Cache.HeaderP->HashTable[Hash] = Package;
// Set the name and the ID
- Pkg->Name = Map.WriteString(Name);
+ Pkg->Name = Map.WriteString(Name.Start,Name.Size);
if (Pkg->Name == 0)
return false;
Pkg->ID = Cache.HeaderP->PackageCount++;
unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
const string &VerStr,
unsigned long Next)
+{
+ return NewVersion(Ver, srkString(VerStr), Next);
+}
+
+unsigned long pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
+ const srkString &VerStr,
+ unsigned long Next)
{
// Get a structure
unsigned long Version = Map.Allocate(sizeof(pkgCache::Version));
Ver = pkgCache::VerIterator(Cache,Cache.VerP + Version);
Ver->NextVer = Next;
Ver->ID = Cache.HeaderP->VersionCount++;
- Ver->VerStr = Map.WriteString(VerStr);
+ Ver->VerStr = Map.WriteString(VerStr.Start, VerStr.Size);
if (Ver->VerStr == 0)
return 0;
const string &Version,
unsigned int Op,
unsigned int Type)
+{
+ return NewDepends(Ver, srkString(PackageName), srkString(Version), Op, Type);
+}
+
+bool pkgCacheGenerator::ListParser::NewDepends(pkgCache::VerIterator Ver,
+ const srkString &PackageName,
+ const srkString &Version,
+ unsigned int Op,
+ unsigned int Type)
{
pkgCache &Cache = Owner->Cache;
bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator Ver,
const string &PackageName,
const string &Version)
+{
+ return NewProvides(Ver, srkString(PackageName), srkString(Version));
+}
+
+bool pkgCacheGenerator::ListParser::NewProvides(pkgCache::VerIterator Ver,
+ const srkString &PackageName,
+ const srkString &Version)
{
pkgCache &Cache = Owner->Cache;
bool FoundFileDeps;
bool NewPackage(pkgCache::PkgIterator &Pkg,const string &PkgName);
+ bool NewPackage(pkgCache::PkgIterator &Pkg,const srkString &PkgName);
bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List);
unsigned long NewVersion(pkgCache::VerIterator &Ver,const string &VerStr,unsigned long Next);
+ unsigned long NewVersion(pkgCache::VerIterator &Ver,const srkString &VerStr,unsigned long Next);
map_ptrloc NewDescription(pkgCache::DescIterator &Desc,const string &Lang,const MD5SumValue &md5sum,map_ptrloc Next);
public:
inline unsigned long WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);};
inline unsigned long WriteString(const string &S) {return Owner->Map.WriteString(S);};
inline unsigned long WriteString(const char *S,unsigned int Size) {return Owner->Map.WriteString(S,Size);};
+ inline unsigned long WriteString(const srkString &S) {return Owner->Map.WriteString(S.Start,S.Size);};
bool NewDepends(pkgCache::VerIterator Ver,const string &Package,
const string &Version,unsigned int Op,
unsigned int Type);
+ bool NewDepends(pkgCache::VerIterator Ver,const srkString &Package,
+ const srkString &Version,unsigned int Op,
+ unsigned int Type);
bool NewProvides(pkgCache::VerIterator Ver,const string &Package,
const string &Version);
+ bool NewProvides(pkgCache::VerIterator Ver,const srkString &Package,
+ const srkString &Version);
bool NewTag(pkgCache::PkgIterator Pkg,const char *NameStart,unsigned int NameSize);
public:
--- /dev/null
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 jgg Exp $
+/* ######################################################################
+
+ Cache - Structure definitions for the cache file
+
+ Please see doc/apt-pkg/cache.sgml for a more detailed description of
+ this format. Also be sure to keep that file up-to-date!!
+
+ Clients should always use the CacheIterators classes for access to the
+ cache. They provide a simple STL-like method for traversing the links
+ of the datastructure.
+
+ See pkgcachegen.h for information about generating cache structures.
+
+ ##################################################################### */
+ /*}}}*/
+#ifndef PKGLIB_PKGSTRING_H
+#define PKGLIB_PKGSTRING_H
+
+#include <string>
+
+class srkString
+{
+ public:
+ const char *Start;
+ size_t Size;
+
+ srkString() : Start(NULL), Size(0) {}
+
+ srkString(const char *Start, size_t Size) : Start(Start), Size(Size) {}
+ srkString(const char *Start, const char *Stop) : Start(Start), Size(Stop - Start) {}
+ srkString(const std::string &string) : Start(string.c_str()), Size(string.size()) {}
+
+ bool empty() const { return Size == 0; }
+ void clear() { Start = NULL; Size = 0; }
+
+ void assign(const char *nStart, const char *nStop) { Start = nStart; Size = nStop - nStart; }
+ void assign(const char *nStart, size_t nSize) { Start = nStart; Size = nSize; }
+
+ size_t length() const { return Size; }
+ size_t size() const { return Size; }
+
+ typedef const char *const_iterator;
+ const char *begin() const { return Start; }
+ const char *end() const { return Start + Size; }
+
+ char operator [](size_t index) const { return Start[index]; }
+
+ operator std::string() { std::string Str; Str.assign(Start, Size); return Str; }
+};
+
+int stringcasecmp(const char *lhsb, const char *lhse, const char *rhs);
+inline int stringcasecmp(const srkString &lhs, const char *rhs) {
+ return stringcasecmp(lhs.Start, lhs.Start + lhs.Size, rhs);
+}
+
+int stringcmp(const std::string &lhs, const char *rhsb, const char *rhse);
+inline bool operator ==(const std::string &lhs, const srkString &rhs) {
+ return stringcmp(lhs, rhs.begin(), rhs.end()) == 0;
+}
+
+#endif
#ifndef PKGLIB_VERSION_H
#define PKGLIB_VERSION_H
-
+#include <apt-pkg/srkstring.h>
#include <apt-pkg/strutl.h>
#include <string>