]> git.saurik.com Git - apt.git/blame - apt-pkg/tagfile.h
* merged apt--curl-https branch
[apt.git] / apt-pkg / tagfile.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
0852eaef 3// $Id: tagfile.h,v 1.20 2003/05/19 17:13:57 doogie Exp $
578bfd0a
AL
4/* ######################################################################
5
6 Fast scanner for RFC-822 type header information
7
8 This parser handles Debian package files (and others). Their form is
b2e465d6 9 RFC-822 type header fields in groups separated by a blank line.
578bfd0a 10
6fc33863 11 The parser reads the file and provides methods to step linearly
578bfd0a
AL
12 over it or to jump to a pre-recorded start point and read that record.
13
14 A second class is used to perform pre-parsing of the record. It works
15 by indexing the start of each header field and providing lookup
16 functions for header fields.
17
18 ##################################################################### */
19 /*}}}*/
578bfd0a
AL
20#ifndef PKGLIB_TAGFILE_H
21#define PKGLIB_TAGFILE_H
22
6c139d6e 23
094a497d 24#include <apt-pkg/fileutl.h>
b2e465d6
AL
25#include <stdio.h>
26
578bfd0a
AL
27class pkgTagSection
28{
29 const char *Section;
30 const char *Stop;
31
32 // We have a limit of 256 tags per section.
33 unsigned short Indexes[256];
fd71171a 34 unsigned short AlphaIndexes[0x100];
c1a22377 35
578bfd0a
AL
36 unsigned int TagCount;
37
38 public:
39
40 inline bool operator ==(const pkgTagSection &rhs) {return Section == rhs.Section;};
41 inline bool operator !=(const pkgTagSection &rhs) {return Section != rhs.Section;};
42
b2e465d6
AL
43 bool Find(const char *Tag,const char *&Start, const char *&End) const;
44 bool Find(const char *Tag,unsigned &Pos) const;
45 string FindS(const char *Tag) const;
46 signed int FindI(const char *Tag,signed long Default = 0) const ;
500827ed
AL
47 bool FindFlag(const char *Tag,unsigned long &Flags,
48 unsigned long Flag) const;
0852eaef 49 bool Scan(const char *Start,unsigned long MaxLength);
b2e465d6
AL
50 inline unsigned long size() const {return Stop - Section;};
51 void Trim();
52
53 inline unsigned int Count() const {return TagCount;};
54 inline void Get(const char *&Start,const char *&Stop,unsigned int I) const
0e66b144
AL
55 {Start = Section + Indexes[I]; Stop = Section + Indexes[I+1];}
56
b2e465d6 57 inline void GetSection(const char *&Start,const char *&Stop) const
a05599f1
AL
58 {
59 Start = Section;
60 Stop = this->Stop;
61 };
62
578bfd0a
AL
63 pkgTagSection() : Section(0), Stop(0) {};
64};
65
66class pkgTagFile
67{
8e06abb2 68 FileFd &Fd;
578bfd0a
AL
69 char *Buffer;
70 char *Start;
71 char *End;
99c2e5ac 72 bool Done;
dcb79bae 73 unsigned long iOffset;
ad00ae81 74 unsigned long Size;
75c541fd 75
99c2e5ac 76 bool Fill();
75c541fd
MV
77 bool Resize();
78
578bfd0a
AL
79 public:
80
81 bool Step(pkgTagSection &Section);
dcb79bae 82 inline unsigned long Offset() {return iOffset;};
ad00ae81 83 bool Jump(pkgTagSection &Tag,unsigned long Offset);
29f7b36c 84
75c541fd 85 pkgTagFile(FileFd *F,unsigned long Size = 32*1024);
29f7b36c 86 ~pkgTagFile();
578bfd0a
AL
87};
88
b2e465d6
AL
89/* This is the list of things to rewrite. The rewriter
90 goes through and changes or adds each of these headers
91 to suit. A zero forces the header to be erased, an empty string
92 causes the old value to be used. (rewrite rule ignored) */
93struct TFRewriteData
94{
95 const char *Tag;
96 const char *Rewrite;
97 const char *NewTag;
98};
99extern const char **TFRewritePackageOrder;
100extern const char **TFRewriteSourceOrder;
101
102bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[],
103 TFRewriteData *Rewrite);
104
578bfd0a 105#endif