1 /*
2 * Copyright (c) 2007, Novell Inc.
3 *
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
6 */
7
8 /*
9 * repodata.h
10 *
11 */
12
13 #ifndef LIBSOLV_REPODATA_H
14 #define LIBSOLV_REPODATA_H
15
16 #include <stdio.h>
17
18 #include "pooltypes.h"
19 #include "pool.h"
20 #include "dirpool.h"
21
22 #ifdef LIBSOLV_INTERNAL
23 #include "repopage.h"
24 #endif
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #define SIZEOF_MD5 16
31 #define SIZEOF_SHA1 20
32 #define SIZEOF_SHA256 32
33
34 struct _Repo;
35 struct _KeyValue;
36
37 typedef struct _Repokey {
38 Id name;
39 Id type; /* REPOKEY_TYPE_xxx */
40 unsigned int size;
41 unsigned int storage; /* KEY_STORAGE_xxx */
42 } Repokey;
43
44 #define KEY_STORAGE_DROPPED 0
45 #define KEY_STORAGE_SOLVABLE 1
46 #define KEY_STORAGE_INCORE 2
47 #define KEY_STORAGE_VERTICAL_OFFSET 3
48
49 #ifdef LIBSOLV_INTERNAL
50 struct dircache;
51 #endif
52
53 typedef struct _Repodata {
54 Id repodataid; /* our id */
55 struct _Repo *repo; /* back pointer to repo */
56
57 #define REPODATA_AVAILABLE 0
58 #define REPODATA_STUB 1
59 #define REPODATA_ERROR 2
60 #define REPODATA_STORE 3
61 #define REPODATA_LOADING 4
62
63 int state; /* available, stub or error */
64
65 void (*loadcallback)(struct _Repodata *);
66
67 int start; /* start of solvables this repodata is valid for */
68 int end; /* last solvable + 1 of this repodata */
69
70 Repokey *keys; /* keys, first entry is always zero */
71 int nkeys; /* length of keys array */
72 unsigned char keybits[32]; /* keyname hash */
73
74 Id *schemata; /* schema -> offset into schemadata */
75 int nschemata; /* number of schemata */
76 Id *schemadata; /* schema storage */
77
78 Stringpool spool; /* local string pool */
79 int localpool; /* is local string pool used */
80
81 Dirpool dirpool; /* local dir pool */
82
83 #ifdef LIBSOLV_INTERNAL
84 FILE *fp; /* file pointer of solv file */
85 int error; /* corrupt solv file */
86
87 unsigned int schemadatalen; /* schema storage size */
88 Id *schematahash; /* unification helper */
89
90 unsigned char *incoredata; /* in-core data */
91 unsigned int incoredatalen; /* in-core data used */
92 unsigned int incoredatafree; /* free data len */
93
94 Id mainschema; /* SOLVID_META schema */
95 Id *mainschemaoffsets; /* SOLVID_META offsets into incoredata */
96
97 Id *incoreoffset; /* offset for all entries */
98
99 Id *verticaloffset; /* offset for all verticals, nkeys elements */
100 Id lastverticaloffset; /* end of verticals */
101
102 Repopagestore store; /* our page store */
103 Id storestate; /* incremented every time the store might change */
104
105 unsigned char *vincore; /* internal vertical data */
106 unsigned int vincorelen; /* data size */
107
108 Id **attrs; /* un-internalized attributes */
109 Id **xattrs; /* anonymous handles */
110 int nxattrs; /* number of handles */
111
112 unsigned char *attrdata; /* their string data space */
113 unsigned int attrdatalen; /* its len */
114 Id *attriddata; /* their id space */
115 unsigned int attriddatalen; /* its len */
116 unsigned long long *attrnum64data; /* their 64bit num data space */
117 unsigned int attrnum64datalen; /* its len */
118
119 /* array cache to speed up repodata_add functions*/
120 Id lasthandle;
121 Id lastkey;
122 Id lastdatalen;
123
124 /* directory cache to speed up repodata_str2dir */
125 struct dircache *dircache;
126 #endif
127
128 } Repodata;
129
130 #define SOLVID_META -1
131 #define SOLVID_POS -2
132 #define SOLVID_SUBSCHEMA -3 /* internal! */
133
134
135 /*-----
136 * management functions
137 */
138 void repodata_initdata(Repodata *data, struct _Repo *repo, int localpool);
139 void repodata_freedata(Repodata *data);
140
141 void repodata_free(Repodata *data);
142 void repodata_empty(Repodata *data, int localpool);
143
144
145 /*
146 * key management functions
147 */
148 Id repodata_key2id(Repodata *data, Repokey *key, int create);
149
150 static inline Repokey *
repodata_id2key(Repodata * data,Id keyid)151 repodata_id2key(Repodata *data, Id keyid)
152 {
153 return data->keys + keyid;
154 }
155
156 /*
157 * schema management functions
158 */
159 Id repodata_schema2id(Repodata *data, Id *schema, int create);
160 void repodata_free_schemahash(Repodata *data);
161
162 static inline Id *
repodata_id2schema(Repodata * data,Id schemaid)163 repodata_id2schema(Repodata *data, Id schemaid)
164 {
165 return data->schemadata + data->schemata[schemaid];
166 }
167
168 /*
169 * data search and access
170 */
171
172 /* check if there is a chance that the repodata contains data for
173 * the specified keyname */
174 static inline int
repodata_precheck_keyname(Repodata * data,Id keyname)175 repodata_precheck_keyname(Repodata *data, Id keyname)
176 {
177 unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
178 return x && (x & (1 << (keyname & 7))) ? 1 : 0;
179 }
180
181 /* check if the repodata contains data for the specified keyname */
182 static inline int
repodata_has_keyname(Repodata * data,Id keyname)183 repodata_has_keyname(Repodata *data, Id keyname)
184 {
185 int i;
186 if (!repodata_precheck_keyname(data, keyname))
187 return 0;
188 for (i = 1; i < data->nkeys; i++)
189 if (data->keys[i].name == keyname)
190 return 1;
191 return 0;
192 }
193
194 /* search key <keyname> (all keys, if keyname == 0) for Id <solvid>
195 * Call <callback> for each match */
196 void repodata_search(Repodata *data, Id solvid, Id keyname, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct _KeyValue *kv), void *cbdata);
197
198 /* Make sure the found KeyValue has the "str" field set. Return false
199 * if not possible */
200 int repodata_stringify(Pool *pool, Repodata *data, Repokey *key, struct _KeyValue *kv, int flags);
201
202 int repodata_filelistfilter_matches(Repodata *data, const char *str);
203
204
205 /* lookup functions */
206 Id repodata_lookup_type(Repodata *data, Id solvid, Id keyname);
207 Id repodata_lookup_id(Repodata *data, Id solvid, Id keyname);
208 const char *repodata_lookup_str(Repodata *data, Id solvid, Id keyname);
209 int repodata_lookup_num(Repodata *data, Id solvid, Id keyname, unsigned long long *value);
210 int repodata_lookup_void(Repodata *data, Id solvid, Id keyname);
211 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep);
212 int repodata_lookup_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
213
214
215 /*-----
216 * data assignment functions
217 */
218
219 /*
220 * extend the data so that it contains the specified solvables
221 * (no longer needed, as the repodata_set functions autoextend)
222 */
223 void repodata_extend(Repodata *data, Id p);
224 void repodata_extend_block(Repodata *data, Id p, int num);
225 void repodata_shrink(Repodata *data, int end);
226
227 /* internalize freshly set data, so that it is found by the search
228 * functions and written out */
229 void repodata_internalize(Repodata *data);
230
231 /* create an anonymous handle. useful for substructures like
232 * fixarray/flexarray */
233 Id repodata_new_handle(Repodata *data);
234
235 /* basic types: void, num, string, Id */
236 void repodata_set_void(Repodata *data, Id solvid, Id keyname);
237 void repodata_set_num(Repodata *data, Id solvid, Id keyname, unsigned long long num);
238 void repodata_set_id(Repodata *data, Id solvid, Id keyname, Id id);
239 void repodata_set_str(Repodata *data, Id solvid, Id keyname, const char *str);
240 void repodata_set_binary(Repodata *data, Id solvid, Id keyname, void *buf, int len);
241 /* create id from string, then set_id */
242 void repodata_set_poolstr(Repodata *data, Id solvid, Id keyname, const char *str);
243
244 /* set numeric constant */
245 void repodata_set_constant(Repodata *data, Id solvid, Id keyname, unsigned int constant);
246
247 /* set Id constant */
248 void repodata_set_constantid(Repodata *data, Id solvid, Id keyname, Id id);
249
250 /* checksum */
251 void repodata_set_bin_checksum(Repodata *data, Id solvid, Id keyname, Id type,
252 const unsigned char *buf);
253 void repodata_set_checksum(Repodata *data, Id solvid, Id keyname, Id type,
254 const char *str);
255 void repodata_set_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
256
257
258 /* directory (for package file list) */
259 void repodata_add_dirnumnum(Repodata *data, Id solvid, Id keyname, Id dir, Id num, Id num2);
260 void repodata_add_dirstr(Repodata *data, Id solvid, Id keyname, Id dir, const char *str);
261 void repodata_free_dircache(Repodata *data);
262
263
264 /* Arrays */
265 void repodata_add_idarray(Repodata *data, Id solvid, Id keyname, Id id);
266 void repodata_add_poolstr_array(Repodata *data, Id solvid, Id keyname, const char *str);
267 void repodata_add_fixarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
268 void repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
269
270 void repodata_unset(Repodata *data, Id solvid, Id keyname);
271 void repodata_unset_uninternalized(Repodata *data, Id solvid, Id keyname);
272
273 /*
274 merge/swap attributes from one solvable to another
275 works only if the data is not yet internalized
276 */
277 void repodata_merge_attrs(Repodata *data, Id dest, Id src);
278 void repodata_merge_some_attrs(Repodata *data, Id dest, Id src, Map *keyidmap, int overwrite);
279 void repodata_swap_attrs(Repodata *data, Id dest, Id src);
280
281 void repodata_create_stubs(Repodata *data);
282 void repodata_join(Repodata *data, Id joinkey);
283
284 /*
285 * load all paged data, used to speed up copying in repo_rpmdb
286 */
287 void repodata_disable_paging(Repodata *data);
288
289 /* helper functions */
290 Id repodata_globalize_id(Repodata *data, Id id, int create);
291 Id repodata_localize_id(Repodata *data, Id id, int create);
292 Id repodata_str2dir(Repodata *data, const char *dir, int create);
293 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
294 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
295 void repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file);
296 void repodata_set_deltalocation(Repodata *data, Id handle, int medianr, const char *dir, const char *file);
297 void repodata_set_sourcepkg(Repodata *data, Id solvid, const char *sourcepkg);
298 Id repodata_lookup_id_uninternalized(Repodata *data, Id solvid, Id keyname, Id voidid);
299
300 /* stats */
301 unsigned int repodata_memused(Repodata *data);
302
303 #ifdef __cplusplus
304 }
305 #endif
306
307 #endif /* LIBSOLV_REPODATA_H */
308