class pkgTagFilePrivate
{
public:
- pkgTagFilePrivate(FileFd *pFd, unsigned long long Size) : Fd(*pFd), Buffer(NULL),
- Start(NULL), End(NULL),
- Done(false), iOffset(0),
- Size(Size)
+ void Reset(FileFd * const pFd, unsigned long long const pSize)
{
+ if (Buffer != NULL)
+ free(Buffer);
+ Buffer = NULL;
+ Fd = pFd;
+ Start = NULL;
+ End = NULL;
+ Done = false;
+ iOffset = 0;
+ Size = pSize;
}
- FileFd &Fd;
+
+ pkgTagFilePrivate(FileFd * const pFd, unsigned long long const Size) : Buffer(NULL)
+ {
+ Reset(pFd, Size);
+ }
+ FileFd * Fd;
char *Buffer;
char *Start;
char *End;
bool Done;
unsigned long long iOffset;
unsigned long long Size;
+
+ ~pkgTagFilePrivate()
+ {
+ if (Buffer != NULL)
+ free(Buffer);
+ }
};
class pkgTagSectionPrivate
// TagFile::pkgTagFile - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long long Size)
- : d(NULL)
+pkgTagFile::pkgTagFile(FileFd * const pFd,unsigned long long const Size)
+ : d(new pkgTagFilePrivate(pFd, Size + 4))
{
Init(pFd, Size);
}
-
-void pkgTagFile::Init(FileFd *pFd,unsigned long long Size)
+void pkgTagFile::Init(FileFd * const pFd,unsigned long long Size)
{
/* The size is increased by 4 because if we start with the Size of the
filename we need to try to read 1 char more to see an EOF faster, 1
char the end-pointer can be on and maybe 2 newlines need to be added
to the end of the file -> 4 extra chars */
Size += 4;
- if(d != NULL)
- {
- free(d->Buffer);
- delete d;
- }
- d = new pkgTagFilePrivate(pFd, Size);
+ d->Reset(pFd, Size);
- if (d->Fd.IsOpen() == false)
+ if (d->Fd->IsOpen() == false)
d->Start = d->End = d->Buffer = 0;
else
d->Buffer = (char*)malloc(sizeof(char) * Size);
/* */
pkgTagFile::~pkgTagFile()
{
- free(d->Buffer);
delete d;
}
/*}}}*/
if (Resize() == false)
return _error->Error(_("Unable to parse package file %s (%d)"),
- d->Fd.Name().c_str(), 1);
+ d->Fd->Name().c_str(), 1);
} while (Tag.Scan(d->Start,d->End - d->Start, false) == false);
}
{
// See if only a bit of the file is left
unsigned long long const dataSize = d->Size - ((d->End - d->Buffer) + 1);
- if (d->Fd.Read(d->End, dataSize, &Actual) == false)
+ if (d->Fd->Read(d->End, dataSize, &Actual) == false)
return false;
if (Actual != dataSize)
d->Done = true;
// Reposition and reload..
d->iOffset = Offset;
d->Done = false;
- if (d->Fd.Seek(Offset) == false)
+ if (d->Fd->Seek(Offset) == false)
return false;
d->End = d->Start = d->Buffer;
return false;
if (Tag.Scan(d->Start, d->End - d->Start, false) == false)
- return _error->Error(_("Unable to parse package file %s (%d)"),d->Fd.Name().c_str(), 2);
+ return _error->Error(_("Unable to parse package file %s (%d)"),d->Fd->Name().c_str(), 2);
return true;
}
/* */
APT_IGNORE_DEPRECATED_PUSH
pkgTagSection::pkgTagSection()
- : Section(0), d(NULL), Stop(0)
+ : Section(0), d(new pkgTagSectionPrivate()), Stop(0)
{
- d = new pkgTagSectionPrivate();
-#if APT_PKG_ABI < 413
- TagCount = 0;
- memset(&Indexes, 0, sizeof(Indexes));
-#endif
memset(&AlphaIndexes, 0, sizeof(AlphaIndexes));
}
APT_IGNORE_DEPRECATED_POP
/*}}}*/
// TagSection::Scan - Scan for the end of the header information /*{{{*/
-#if APT_PKG_ABI < 413
-bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
-{
- return Scan(Start, MaxLength, true);
-}
-#endif
bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength, bool const Restart)
{
Section = Start;
}
d->Tags.reserve(0x100);
}
-#if APT_PKG_ABI >= 413
unsigned int TagCount = d->Tags.size();
-#else
- APT_IGNORE_DEPRECATED(TagCount = d->Tags.size();)
-#endif
if (Stop == 0)
return false;
lastTagData.NextInBucket = AlphaIndexes[lastTagHash];
APT_IGNORE_DEPRECATED_PUSH
AlphaIndexes[lastTagHash] = TagCount;
-#if APT_PKG_ABI < 413
- if (d->Tags.size() < sizeof(Indexes)/sizeof(Indexes[0]))
- Indexes[d->Tags.size()] = lastTagData.StartTag;
-#endif
APT_IGNORE_DEPRECATED_POP
d->Tags.push_back(lastTagData);
}
if (AlphaIndexes[lastTagHash] != 0)
lastTagData.NextInBucket = AlphaIndexes[lastTagHash];
APT_IGNORE_DEPRECATED(AlphaIndexes[lastTagHash] = TagCount;)
-#if APT_PKG_ABI < 413
- APT_IGNORE_DEPRECATED(Indexes[d->Tags.size()] = lastTagData.StartTag;)
-#endif
d->Tags.push_back(lastTagData);
}
pkgTagSectionPrivate::TagData const td(Stop - Section);
-#if APT_PKG_ABI < 413
- APT_IGNORE_DEPRECATED(Indexes[d->Tags.size()] = td.StartTag;)
-#endif
d->Tags.push_back(td);
TrimRecord(false,End);
return true;
}
/*}}}*/
// TagSection::Exists - return True if a tag exists /*{{{*/
-#if APT_PKG_ABI >= 413
bool pkgTagSection::Exists(const char* const Tag) const
-#else
-bool pkgTagSection::Exists(const char* const Tag)
-#endif
{
unsigned int tmp;
return Find(Tag, tmp);
return Default;
strncpy(S,Start,Stop-Start);
S[Stop - Start] = 0;
-
+
+ errno = 0;
char *End;
signed long Result = strtol(S,&End,10);
+ if (errno == ERANGE)
+ _error->Errno("strtol", _("Cannot convert %s to integer"), S);
+ if (Result < std::numeric_limits<int>::min() || Result > std::numeric_limits<int>::max()) {
+ errno = ERANGE;
+ _error->Errno("", _("Cannot convert %s to integer"), S);
+ }
if (S == End)
return Default;
return Result;
// TagSection::FindFlag - Locate a yes/no type flag /*{{{*/
// ---------------------------------------------------------------------
/* The bits marked in Flag are masked on/off in Flags */
+bool pkgTagSection::FindFlag(const char * const Tag, uint8_t &Flags,
+ uint8_t const Flag) const
+{
+ const char *Start;
+ const char *Stop;
+ if (Find(Tag,Start,Stop) == false)
+ return true;
+ return FindFlag(Flags, Flag, Start, Stop);
+}
+bool pkgTagSection::FindFlag(uint8_t &Flags, uint8_t const Flag,
+ char const* const Start, char const* const Stop)
+{
+ switch (StringToBool(string(Start, Stop)))
+ {
+ case 0:
+ Flags &= ~Flag;
+ return true;
+
+ case 1:
+ Flags |= Flag;
+ return true;
+
+ default:
+ _error->Warning("Unknown flag value: %s",string(Start,Stop).c_str());
+ return true;
+ }
+ return true;
+}
bool pkgTagSection::FindFlag(const char *Tag,unsigned long &Flags,
unsigned long Flag) const
{
}
/*}}}*/
+void pkgUserTagSection::TrimRecord(bool /*BeforeRecord*/, const char* &End)/*{{{*/
+{
+ for (; Stop < End && (Stop[0] == '\n' || Stop[0] == '\r' || Stop[0] == '#'); Stop++)
+ if (Stop[0] == '#')
+ Stop = (const char*) memchr(Stop,'\n',End-Stop);
+}
+ /*}}}*/
+
#include "tagfile-order.c"
// TFRewrite - Rewrite a control record /*{{{*/