|
1 | | -/*------------------------------------------------------------------------- |
2 | | - * |
3 | | - * pg_backup_archiver.h |
4 | | - * |
5 | | - *Private interface to the pg_dump archiver routines. |
6 | | - *It is NOT intended that these routines be called by any |
7 | | - *dumper directly. |
8 | | - * |
9 | | - *See the headers to pg_restore for more details. |
10 | | - * |
11 | | - * Copyright (c) 2000, Philip Warner |
12 | | - * Rights are granted to use this software in any way so long |
13 | | - * as this notice is not removed. |
14 | | - * |
15 | | - *The author is not responsible for loss or damages that may |
16 | | - *result from it's use. |
17 | | - * |
18 | | - * |
19 | | - * IDENTIFICATION |
20 | | - * |
21 | | - * Modifications - 28-Jun-2000 - pjw@rhyme.com.au |
22 | | - * |
23 | | - *Initial version. |
24 | | - * |
25 | | - *------------------------------------------------------------------------- |
26 | | - */ |
27 | | - |
28 | | -#ifndef__PG_BACKUP_ARCHIVE__ |
29 | | -#define__PG_BACKUP_ARCHIVE__ |
30 | | - |
31 | | -#include<stdio.h> |
32 | | - |
33 | | -#ifdefHAVE_LIBZ |
34 | | -#include<zlib.h> |
35 | | -#defineGZCLOSE(fh) gzclose(fh) |
36 | | -#defineGZWRITE(p,s,n,fh) gzwrite(fh, p, n * s) |
37 | | -#defineGZREAD(p,s,n,fh) gzread(fh, p, n * s) |
38 | | -#else |
39 | | -#defineGZCLOSE(fh) fclose(fh) |
40 | | -#defineGZWRITE(p,s,n,fh) fwrite(p, s, n, fh) |
41 | | -#defineGZREAD(p,s,n,fh) fread(p, s, n, fh) |
42 | | -#defineZ_DEFAULT_COMPRESSION -1 |
43 | | - |
44 | | -typedefstruct_z_stream { |
45 | | -void*next_in; |
46 | | -void*next_out; |
47 | | -intavail_in; |
48 | | -intavail_out; |
49 | | -}z_stream; |
50 | | -typedefz_stream*z_streamp; |
51 | | -#endif |
52 | | - |
53 | | -#include"pg_backup.h" |
54 | | - |
55 | | -#defineK_VERS_MAJOR 1 |
56 | | -#defineK_VERS_MINOR 2 |
57 | | -#defineK_VERS_REV1 |
58 | | - |
59 | | -/* Some important version numbers (checked in code) */ |
60 | | -#defineK_VERS_1_0 (( (1 * 256 + 0) * 256 + 0) * 256 + 0) |
61 | | -#defineK_VERS_1_2 (( (1 * 256 + 2) * 256 + 0) * 256 + 0) |
62 | | -#defineK_VERS_MAX (( (1 * 256 + 2) * 256 + 255) * 256 + 0) |
63 | | - |
64 | | -struct_archiveHandle; |
65 | | -struct_tocEntry; |
66 | | -struct_restoreList; |
67 | | - |
68 | | -typedefvoid (*ClosePtr)(struct_archiveHandle*AH); |
69 | | -typedefvoid(*ArchiveEntryPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
70 | | - |
71 | | -typedefvoid(*StartDataPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
72 | | -typedefint (*WriteDataPtr)(struct_archiveHandle*AH,constvoid*data,intdLen); |
73 | | -typedefvoid(*EndDataPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
74 | | - |
75 | | -typedefint(*WriteBytePtr)(struct_archiveHandle*AH,constinti); |
76 | | -typedefint (*ReadBytePtr)(struct_archiveHandle*AH); |
77 | | -typedefint(*WriteBufPtr)(struct_archiveHandle*AH,constvoid*c,intlen); |
78 | | -typedefint(*ReadBufPtr)(struct_archiveHandle*AH,void*buf,intlen); |
79 | | -typedefvoid(*SaveArchivePtr)(struct_archiveHandle*AH); |
80 | | -typedefvoid (*WriteExtraTocPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
81 | | -typedefvoid(*ReadExtraTocPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
82 | | -typedefvoid(*PrintExtraTocPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
83 | | -typedefvoid(*PrintTocDataPtr)(struct_archiveHandle*AH,struct_tocEntry*te, |
84 | | -RestoreOptions*ropt); |
85 | | - |
86 | | -typedefint(*TocSortCompareFn)(constvoid*te1,constvoid*te2); |
87 | | - |
88 | | -typedefenum_archiveMode { |
89 | | -archModeWrite, |
90 | | -archModeRead |
91 | | -}ArchiveMode; |
92 | | - |
93 | | -typedefstruct_outputContext { |
94 | | -void*OF; |
95 | | -intgzOut; |
96 | | -}OutputContext; |
97 | | - |
98 | | -typedefstruct_archiveHandle { |
99 | | -charvmaj;/* Version of file */ |
100 | | -charvmin; |
101 | | -charvrev; |
102 | | -intversion;/* Conveniently formatted version */ |
103 | | - |
104 | | -intintSize;/* Size of an integer in the archive */ |
105 | | -ArchiveFormatformat;/* Archive format */ |
106 | | - |
107 | | -intreadHeader;/* Used if file header has been read already */ |
108 | | - |
109 | | -ArchiveEntryPtrArchiveEntryPtr;/* Called for each metadata object */ |
110 | | -StartDataPtrStartDataPtr;/* Called when table data is about to be dumped */ |
111 | | -WriteDataPtrWriteDataPtr;/* Called to send some table data to the archive */ |
112 | | -EndDataPtrEndDataPtr;/* Called when table data dump is finished */ |
113 | | -WriteBytePtrWriteBytePtr;/* Write a byte to output */ |
114 | | -ReadBytePtrReadBytePtr;/* */ |
115 | | -WriteBufPtrWriteBufPtr; |
116 | | -ReadBufPtrReadBufPtr; |
117 | | -ClosePtrClosePtr;/* Close the archive */ |
118 | | -WriteExtraTocPtrWriteExtraTocPtr;/* Write extra TOC entry data associated with */ |
119 | | -/* the current archive format */ |
120 | | -ReadExtraTocPtrReadExtraTocPtr;/* Read extr info associated with archie format */ |
121 | | -PrintExtraTocPtrPrintExtraTocPtr;/* Extra TOC info for format */ |
122 | | -PrintTocDataPtrPrintTocDataPtr; |
123 | | - |
124 | | -intlastID;/* Last internal ID for a TOC entry */ |
125 | | -char*fSpec;/* Archive File Spec */ |
126 | | -FILE*FH;/* General purpose file handle */ |
127 | | -void*OF; |
128 | | -intgzOut;/* Output file */ |
129 | | - |
130 | | -struct_tocEntry*toc;/* List of TOC entries */ |
131 | | -inttocCount;/* Number of TOC entries */ |
132 | | -struct_tocEntry*currToc;/* Used when dumping data */ |
133 | | -char*currUser;/* Restore: current username in script */ |
134 | | -intcompression;/* Compression requested on open */ |
135 | | -ArchiveModemode;/* File mode - r or w */ |
136 | | -void*formatData;/* Header data specific to file format */ |
137 | | - |
138 | | -}ArchiveHandle; |
139 | | - |
140 | | -typedefstruct_tocEntry { |
141 | | -struct_tocEntry*prev; |
142 | | -struct_tocEntry*next; |
143 | | -intid; |
144 | | -inthadDumper;/* Archiver was passed a dumper routine (used in restore) */ |
145 | | -char*oid; |
146 | | -intoidVal; |
147 | | -char*name; |
148 | | -char*desc; |
149 | | -char*defn; |
150 | | -char*dropStmt; |
151 | | -char*owner; |
152 | | -char**depOid; |
153 | | -intprinted;/* Indicates if entry defn has been dumped */ |
154 | | -DataDumperPtrdataDumper;/* Routine to dump data for object */ |
155 | | -void*dataDumperArg;/* Arg for above routine */ |
156 | | -void*formatData;/* TOC Entry data specific to file format */ |
157 | | - |
158 | | -int_moved;/* Marker used when rearranging TOC */ |
159 | | - |
160 | | -}TocEntry; |
161 | | - |
162 | | -externvoiddie_horribly(constchar*fmt, ...); |
163 | | - |
164 | | -externvoidWriteTOC(ArchiveHandle*AH); |
165 | | -externvoidReadTOC(ArchiveHandle*AH); |
166 | | -externvoidWriteHead(ArchiveHandle*AH); |
167 | | -externvoidReadHead(ArchiveHandle*AH); |
168 | | -externvoidWriteToc(ArchiveHandle*AH); |
169 | | -externvoidReadToc(ArchiveHandle*AH); |
170 | | -externvoidWriteDataChunks(ArchiveHandle*AH); |
171 | | - |
172 | | -externintTocIDRequired(ArchiveHandle*AH,intid,RestoreOptions*ropt); |
173 | | - |
174 | | -/* |
175 | | - * Mandatory routines for each supported format |
176 | | - */ |
177 | | - |
178 | | -externintWriteInt(ArchiveHandle*AH,inti); |
179 | | -externintReadInt(ArchiveHandle*AH); |
180 | | -externchar*ReadStr(ArchiveHandle*AH); |
181 | | -externintWriteStr(ArchiveHandle*AH,char*s); |
182 | | - |
183 | | -externvoidInitArchiveFmt_Custom(ArchiveHandle*AH); |
184 | | -externvoidInitArchiveFmt_Files(ArchiveHandle*AH); |
185 | | -externvoidInitArchiveFmt_PlainText(ArchiveHandle*AH); |
186 | | - |
187 | | -externOutputContextSetOutput(ArchiveHandle*AH,char*filename,intcompression); |
188 | | -externvoidResetOutput(ArchiveHandle*AH,OutputContextsavedContext); |
189 | | - |
190 | | -intahwrite(constvoid*ptr,size_tsize,size_tnmemb,ArchiveHandle*AH); |
191 | | -intahprintf(ArchiveHandle*AH,constchar*fmt, ...); |
192 | | - |
193 | | -#endif |
| 1 | +/*------------------------------------------------------------------------- |
| 2 | + * |
| 3 | + * pg_backup_archiver.h |
| 4 | + * |
| 5 | + *Private interface to the pg_dump archiver routines. |
| 6 | + *It is NOT intended that these routines be called by any |
| 7 | + *dumper directly. |
| 8 | + * |
| 9 | + *See the headers to pg_restore for more details. |
| 10 | + * |
| 11 | + * Copyright (c) 2000, Philip Warner |
| 12 | + * Rights are granted to use this software in any way so long |
| 13 | + * as this notice is not removed. |
| 14 | + * |
| 15 | + *The author is not responsible for loss or damages that may |
| 16 | + *result from it's use. |
| 17 | + * |
| 18 | + * |
| 19 | + * IDENTIFICATION |
| 20 | + * |
| 21 | + * Modifications - 28-Jun-2000 - pjw@rhyme.com.au |
| 22 | + * |
| 23 | + *Initial version. |
| 24 | + * |
| 25 | + *------------------------------------------------------------------------- |
| 26 | + */ |
| 27 | + |
| 28 | +#ifndef__PG_BACKUP_ARCHIVE__ |
| 29 | +#define__PG_BACKUP_ARCHIVE__ |
| 30 | + |
| 31 | +#include<stdio.h> |
| 32 | + |
| 33 | +#ifdefHAVE_LIBZ |
| 34 | +#include<zlib.h> |
| 35 | +#defineGZCLOSE(fh) gzclose(fh) |
| 36 | +#defineGZWRITE(p,s,n,fh) gzwrite(fh, p, n * s) |
| 37 | +#defineGZREAD(p,s,n,fh) gzread(fh, p, n * s) |
| 38 | +#else |
| 39 | +#defineGZCLOSE(fh) fclose(fh) |
| 40 | +#defineGZWRITE(p,s,n,fh) fwrite(p, s, n, fh) |
| 41 | +#defineGZREAD(p,s,n,fh) fread(p, s, n, fh) |
| 42 | +#defineZ_DEFAULT_COMPRESSION -1 |
| 43 | + |
| 44 | +typedefstruct_z_stream { |
| 45 | +void*next_in; |
| 46 | +void*next_out; |
| 47 | +intavail_in; |
| 48 | +intavail_out; |
| 49 | +}z_stream; |
| 50 | +typedefz_stream*z_streamp; |
| 51 | +#endif |
| 52 | + |
| 53 | +#include"pg_backup.h" |
| 54 | + |
| 55 | +#defineK_VERS_MAJOR 1 |
| 56 | +#defineK_VERS_MINOR 2 |
| 57 | +#defineK_VERS_REV2 |
| 58 | + |
| 59 | +/* Some important version numbers (checked in code) */ |
| 60 | +#defineK_VERS_1_0 (( (1 * 256 + 0) * 256 + 0) * 256 + 0) |
| 61 | +#defineK_VERS_1_2 (( (1 * 256 + 2) * 256 + 0) * 256 + 0) |
| 62 | +#defineK_VERS_MAX (( (1 * 256 + 2) * 256 + 255) * 256 + 0) |
| 63 | + |
| 64 | +struct_archiveHandle; |
| 65 | +struct_tocEntry; |
| 66 | +struct_restoreList; |
| 67 | + |
| 68 | +typedefvoid (*ClosePtr)(struct_archiveHandle*AH); |
| 69 | +typedefvoid(*ArchiveEntryPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
| 70 | + |
| 71 | +typedefvoid(*StartDataPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
| 72 | +typedefint (*WriteDataPtr)(struct_archiveHandle*AH,constvoid*data,intdLen); |
| 73 | +typedefvoid(*EndDataPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
| 74 | + |
| 75 | +typedefint(*WriteBytePtr)(struct_archiveHandle*AH,constinti); |
| 76 | +typedefint (*ReadBytePtr)(struct_archiveHandle*AH); |
| 77 | +typedefint(*WriteBufPtr)(struct_archiveHandle*AH,constvoid*c,intlen); |
| 78 | +typedefint(*ReadBufPtr)(struct_archiveHandle*AH,void*buf,intlen); |
| 79 | +typedefvoid(*SaveArchivePtr)(struct_archiveHandle*AH); |
| 80 | +typedefvoid (*WriteExtraTocPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
| 81 | +typedefvoid(*ReadExtraTocPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
| 82 | +typedefvoid(*PrintExtraTocPtr)(struct_archiveHandle*AH,struct_tocEntry*te); |
| 83 | +typedefvoid(*PrintTocDataPtr)(struct_archiveHandle*AH,struct_tocEntry*te, |
| 84 | +RestoreOptions*ropt); |
| 85 | + |
| 86 | +typedefint(*TocSortCompareFn)(constvoid*te1,constvoid*te2); |
| 87 | + |
| 88 | +typedefenum_archiveMode { |
| 89 | +archModeWrite, |
| 90 | +archModeRead |
| 91 | +}ArchiveMode; |
| 92 | + |
| 93 | +typedefstruct_outputContext { |
| 94 | +void*OF; |
| 95 | +intgzOut; |
| 96 | +}OutputContext; |
| 97 | + |
| 98 | +typedefstruct_archiveHandle { |
| 99 | +charvmaj;/* Version of file */ |
| 100 | +charvmin; |
| 101 | +charvrev; |
| 102 | +intversion;/* Conveniently formatted version */ |
| 103 | + |
| 104 | +intintSize;/* Size of an integer in the archive */ |
| 105 | +ArchiveFormatformat;/* Archive format */ |
| 106 | + |
| 107 | +intreadHeader;/* Used if file header has been read already */ |
| 108 | + |
| 109 | +ArchiveEntryPtrArchiveEntryPtr;/* Called for each metadata object */ |
| 110 | +StartDataPtrStartDataPtr;/* Called when table data is about to be dumped */ |
| 111 | +WriteDataPtrWriteDataPtr;/* Called to send some table data to the archive */ |
| 112 | +EndDataPtrEndDataPtr;/* Called when table data dump is finished */ |
| 113 | +WriteBytePtrWriteBytePtr;/* Write a byte to output */ |
| 114 | +ReadBytePtrReadBytePtr;/* */ |
| 115 | +WriteBufPtrWriteBufPtr; |
| 116 | +ReadBufPtrReadBufPtr; |
| 117 | +ClosePtrClosePtr;/* Close the archive */ |
| 118 | +WriteExtraTocPtrWriteExtraTocPtr;/* Write extra TOC entry data associated with */ |
| 119 | +/* the current archive format */ |
| 120 | +ReadExtraTocPtrReadExtraTocPtr;/* Read extr info associated with archie format */ |
| 121 | +PrintExtraTocPtrPrintExtraTocPtr;/* Extra TOC info for format */ |
| 122 | +PrintTocDataPtrPrintTocDataPtr; |
| 123 | + |
| 124 | +intlastID;/* Last internal ID for a TOC entry */ |
| 125 | +char*fSpec;/* Archive File Spec */ |
| 126 | +FILE*FH;/* General purpose file handle */ |
| 127 | +void*OF; |
| 128 | +intgzOut;/* Output file */ |
| 129 | + |
| 130 | +struct_tocEntry*toc;/* List of TOC entries */ |
| 131 | +inttocCount;/* Number of TOC entries */ |
| 132 | +struct_tocEntry*currToc;/* Used when dumping data */ |
| 133 | +char*currUser;/* Restore: current username in script */ |
| 134 | +intcompression;/* Compression requested on open */ |
| 135 | +ArchiveModemode;/* File mode - r or w */ |
| 136 | +void*formatData;/* Header data specific to file format */ |
| 137 | + |
| 138 | +}ArchiveHandle; |
| 139 | + |
| 140 | +typedefstruct_tocEntry { |
| 141 | +struct_tocEntry*prev; |
| 142 | +struct_tocEntry*next; |
| 143 | +intid; |
| 144 | +inthadDumper;/* Archiver was passed a dumper routine (used in restore) */ |
| 145 | +char*oid; |
| 146 | +intoidVal; |
| 147 | +char*name; |
| 148 | +char*desc; |
| 149 | +char*defn; |
| 150 | +char*dropStmt; |
| 151 | +char*owner; |
| 152 | +char**depOid; |
| 153 | +intprinted;/* Indicates if entry defn has been dumped */ |
| 154 | +DataDumperPtrdataDumper;/* Routine to dump data for object */ |
| 155 | +void*dataDumperArg;/* Arg for above routine */ |
| 156 | +void*formatData;/* TOC Entry data specific to file format */ |
| 157 | + |
| 158 | +int_moved;/* Marker used when rearranging TOC */ |
| 159 | + |
| 160 | +}TocEntry; |
| 161 | + |
| 162 | +externvoiddie_horribly(constchar*fmt, ...); |
| 163 | + |
| 164 | +externvoidWriteTOC(ArchiveHandle*AH); |
| 165 | +externvoidReadTOC(ArchiveHandle*AH); |
| 166 | +externvoidWriteHead(ArchiveHandle*AH); |
| 167 | +externvoidReadHead(ArchiveHandle*AH); |
| 168 | +externvoidWriteToc(ArchiveHandle*AH); |
| 169 | +externvoidReadToc(ArchiveHandle*AH); |
| 170 | +externvoidWriteDataChunks(ArchiveHandle*AH); |
| 171 | + |
| 172 | +externintTocIDRequired(ArchiveHandle*AH,intid,RestoreOptions*ropt); |
| 173 | + |
| 174 | +/* |
| 175 | + * Mandatory routines for each supported format |
| 176 | + */ |
| 177 | + |
| 178 | +externintWriteInt(ArchiveHandle*AH,inti); |
| 179 | +externintReadInt(ArchiveHandle*AH); |
| 180 | +externchar*ReadStr(ArchiveHandle*AH); |
| 181 | +externintWriteStr(ArchiveHandle*AH,char*s); |
| 182 | + |
| 183 | +externvoidInitArchiveFmt_Custom(ArchiveHandle*AH); |
| 184 | +externvoidInitArchiveFmt_Files(ArchiveHandle*AH); |
| 185 | +externvoidInitArchiveFmt_PlainText(ArchiveHandle*AH); |
| 186 | + |
| 187 | +externOutputContextSetOutput(ArchiveHandle*AH,char*filename,intcompression); |
| 188 | +externvoidResetOutput(ArchiveHandle*AH,OutputContextsavedContext); |
| 189 | + |
| 190 | +intahwrite(constvoid*ptr,size_tsize,size_tnmemb,ArchiveHandle*AH); |
| 191 | +intahprintf(ArchiveHandle*AH,constchar*fmt, ...); |
| 192 | + |
| 193 | +#endif |