2 * libdpkg - Debian packaging suite library routines
3 * parsedump.h - declarations for in-core database reading/writing
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2001 Wichert Akkerman
7 * Copyright © 2008-2011 Guillem Jover <guillem@debian.org>
9 * This is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 #ifndef LIBDPKG_PARSEDUMP_H
24 #define LIBDPKG_PARSEDUMP_H
29 #include <dpkg/error.h>
30 #include <dpkg/dpkg-db.h>
35 * @defgroup parsedump In-core package database parsing and reading
36 * @ingroup dpkg-public
52 struct parsedb_state
{
53 enum parsedbtype type
;
54 enum parsedbflags flags
;
55 struct dpkg_error err
;
58 struct pkgbin
*pkgbin
;
67 #define parse_at_eof(ps) ((ps)->dataptr >= (ps)->endptr)
68 #define parse_getc(ps) *(ps)->dataptr++
69 #define parse_ungetc(c, ps) (ps)->dataptr--
72 const char *fieldstart
;
73 const char *valuestart
;
77 int *fieldencountered
;
80 struct parsedb_state
*
81 parsedb_new(const char *filename
, int fd
, enum parsedbflags flags
);
82 struct parsedb_state
*
83 parsedb_open(const char *filename
, enum parsedbflags flags
);
85 parsedb_load(struct parsedb_state
*ps
);
87 parsedb_parse(struct parsedb_state
*ps
, struct pkginfo
**pkgp
);
89 parsedb_close(struct parsedb_state
*ps
);
91 typedef void parse_field_func(struct parsedb_state
*ps
, struct field_state
*fs
,
94 bool parse_stanza(struct parsedb_state
*ps
, struct field_state
*fs
,
95 parse_field_func
*parse_field
, void *parse_obj
);
97 #define STRUCTFIELD(klass, off, type) (*(type *)((uintptr_t)(klass) + (off)))
99 #define PKGIFPOFF(f) (offsetof(struct pkgbin, f))
100 #define ARCHIVEFOFF(f) (offsetof(struct archivedetails, f))
102 typedef void freadfunction(struct pkginfo
*pkg
, struct pkgbin
*pkgbin
,
103 struct parsedb_state
*ps
,
104 const char *value
, const struct fieldinfo
*fip
);
105 freadfunction f_name
;
106 freadfunction f_charfield
;
107 freadfunction f_priority
;
108 freadfunction f_obs_class
;
109 freadfunction f_section
;
110 freadfunction f_status
;
111 freadfunction f_boolean
;
112 freadfunction f_dependency
;
113 freadfunction f_conffiles
;
114 freadfunction f_version
;
115 freadfunction f_obs_revision
;
116 freadfunction f_obs_dependency
;
117 freadfunction f_configversion
;
118 freadfunction f_multiarch
;
119 freadfunction f_architecture
;
120 freadfunction f_trigpend
, f_trigaw
;
121 freadfunction f_archives
;
123 enum DPKG_ATTR_ENUM_FLAGS fwriteflags
{
126 /** Print field header and trailing newline. */
127 fw_printheader
= DPKG_BIT(0),
130 typedef void fwritefunction(struct varbuf
*,
131 const struct pkginfo
*, const struct pkgbin
*,
132 enum fwriteflags flags
, const struct fieldinfo
*);
133 fwritefunction w_name
, w_charfield
, w_priority
, w_section
, w_status
, w_configversion
;
134 fwritefunction w_version
, w_null
, w_booleandefno
, w_dependency
, w_conffiles
;
135 fwritefunction w_multiarch
;
136 fwritefunction w_architecture
;
137 fwritefunction w_trigpend
, w_trigaw
;
138 fwritefunction w_archives
;
141 varbuf_add_arbfield(struct varbuf
*vb
, const struct arbitraryfield
*arbfield
,
142 enum fwriteflags flags
);
144 #define FIELD(name) name, sizeof(name) - 1
149 freadfunction
*rcall
;
150 fwritefunction
*wcall
;
155 parse_db_version(struct parsedb_state
*ps
,
156 struct dpkg_version
*version
, const char *value
)
159 void parse_error(struct parsedb_state
*ps
, const char *fmt
, ...)
160 DPKG_ATTR_NORET
DPKG_ATTR_PRINTF(2);
161 void parse_warn(struct parsedb_state
*ps
, const char *fmt
, ...)
164 parse_lax_problem(struct parsedb_state
*ps
, enum parsedbflags flags_lax
,
165 const char *fmt
, ...)
168 parse_problem(struct parsedb_state
*ps
, const char *fmt
, ...)
171 void parse_must_have_field(struct parsedb_state
*ps
,
172 const char *value
, const char *what
);
173 void parse_ensure_have_field(struct parsedb_state
*ps
,
174 const char **value
, const char *what
);
176 #define MSDOS_EOF_CHAR '\032' /* ^Z */
178 extern const struct fieldinfo fieldinfos
[];
184 #endif /* LIBDPKG_PARSEDUMP_H */