]> git.decadent.org.uk Git - dak.git/blob - tools/dsync-0.0/libdsync/filelist.h
Cope with empty queue
[dak.git] / tools / dsync-0.0 / libdsync / filelist.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description                                                          /*{{{*/
3 // $Id: filelist.h,v 1.10 1999/12/26 06:59:00 jgg Exp $
4 /* ######################################################################
5    
6    File List structures
7    
8    These structures represent the uncompacted binary records from the
9    file list file. Functions are provided to compact and decompact these
10    structures for reading and writing.
11
12    The dsFList class can be instantiated to get get a general 'all records'
13    storage. It also has a member to read the next record from the IO and
14    to print out a record summary.
15    
16    Be sure to read filelist.sgml which contains the precise meaning of 
17    the feilds and the compaction technique used.
18
19    ##################################################################### */
20                                                                         /*}}}*/
21 #ifndef DSYNC_FILELIST
22 #define DSYNC_FILELIST
23
24 #ifdef __GNUG__
25 #pragma interface "dsync/filelist.h"
26 #endif 
27
28 #include <string>
29 using namespace std;
30
31 class dsFList
32 {
33    public:
34       
35    class IO;
36
37    struct Header
38    {
39       unsigned long Tag;
40       unsigned long Signature;
41       unsigned long MajorVersion;
42       unsigned long MinorVersion;
43       unsigned long Epoch;
44       
45       unsigned long FlagCount;
46       unsigned long Flags[15];
47
48       bool Read(IO &IO);
49       bool Write(IO &IO);
50       
51       Header();
52    };
53    
54    struct DirEntity
55    {
56       unsigned long Tag;
57       signed long ModTime;
58       unsigned long Permissions;
59       unsigned long User;
60       unsigned long Group;
61       string Name;
62
63       enum EntFlags {FlPerm = (1<<0), FlOwner = (1<<1)};
64       
65       /* You know what? egcs-2.91.60 will not call the destructor for Name
66          if this in not here. I can't reproduce this in a simpler context
67          either. - Jgg [time passes] serious egcs bug, it was mislinking
68          the string classes :< */
69       ~DirEntity() {};
70    };
71    
72    struct Directory : public DirEntity
73    {      
74       bool Read(IO &IO);
75       bool Write(IO &IO);
76    };
77    
78    struct NormalFile : public DirEntity
79    {
80       unsigned long Size;
81       unsigned char MD5[16];
82       
83       enum Flags {FlMD5 = (1<<2)};
84       
85       bool Read(IO &IO);
86       bool Write(IO &IO);      
87    };
88    
89    struct Symlink : public DirEntity
90    {
91       unsigned long Compress;
92       string To;
93       
94       bool Read(IO &IO);
95       bool Write(IO &IO);
96    };
97    
98    struct DeviceSpecial : public DirEntity
99    {
100       unsigned long Dev;
101       
102       bool Read(IO &IO);
103       bool Write(IO &IO);
104    };
105    
106    struct Filter
107    {
108       unsigned long Tag;
109       unsigned long Type;
110       string Pattern;
111       
112       enum Types {Include=1, Exclude=2};
113       
114       bool Read(IO &IO);
115       bool Write(IO &IO);
116    };
117    
118    struct UidGidMap
119    {
120       unsigned long Tag;
121       unsigned long FileID;
122       unsigned long RealID;
123       string Name;
124       
125       enum Flags {FlRealID = (1<<0)};
126       
127       bool Read(IO &IO);
128       bool Write(IO &IO);
129    };
130    
131    struct HardLink : public NormalFile
132    {
133       unsigned long Serial;
134       
135       bool Read(IO &IO);
136       bool Write(IO &IO);
137    };
138    
139    struct Trailer
140    {
141       unsigned long Tag;   
142       unsigned long Signature;
143       
144       bool Read(IO &IO);
145       bool Write(IO &IO);
146       Trailer();
147    };
148    
149    struct RSyncChecksum
150    {
151       unsigned long Tag;
152       unsigned long BlockSize;
153       unsigned long FileSize;
154
155       // Array of 160 bit values (20 bytes) stored in Network byte order
156       unsigned char *Sums;
157       
158       bool Read(IO &IO);
159       bool Write(IO &IO);
160       RSyncChecksum();
161       ~RSyncChecksum();
162    };
163   
164    struct AggregateFile
165    {
166       unsigned long Tag;
167       string File;
168       
169       bool Read(IO &IO);
170       bool Write(IO &IO);
171    };
172   
173    
174    enum Types {tHeader=0, tDirMarker=1, tDirStart=2, tDirEnd=3, tNormalFile=4,
175       tSymlink=5, tDeviceSpecial=6, tDirectory=7, tFilter=8, 
176       tUidMap=9, tGidMap=10, tHardLink=11, tTrailer=12, tRSyncChecksum=13,
177       tAggregateFile=14, tRSyncEnd=15};
178
179    unsigned long Tag;
180    Header Head;
181    Directory Dir;
182    NormalFile NFile;
183    Symlink SLink;
184    DeviceSpecial DevSpecial; 
185    Filter Filt;
186    UidGidMap UMap;
187    HardLink HLink;
188    Trailer Trail;
189    DirEntity *Entity;
190    NormalFile *File;
191    RSyncChecksum RChk;
192    AggregateFile AgFile;
193       
194    bool Step(IO &IO);
195    bool Print(ostream &out);
196 };
197
198 class dsFList::IO
199 {
200    public:
201
202    string LastSymlink;
203    dsFList::Header Header;
204    bool NoStrings;
205    
206    virtual bool Read(void *Buf,unsigned long Len) = 0;
207    virtual bool Write(const void *Buf,unsigned long Len) = 0;
208    virtual bool Seek(unsigned long Bytes) = 0;
209    virtual unsigned long Tell() = 0;
210    
211    bool ReadNum(unsigned long &Number);
212    bool WriteNum(unsigned long Number);
213    bool ReadInt(unsigned long &Number,unsigned char Count);
214    bool WriteInt(unsigned long Number,unsigned char Count);
215    bool ReadInt(signed long &Number,unsigned char Count);
216    bool WriteInt(signed long Number,unsigned char Count);
217    bool ReadString(string &Foo);
218    bool WriteString(string const &Foo);
219    
220    IO();
221    virtual ~IO() {};
222 };
223
224 #endif