2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef LIBSOLV_REPODATA_H
14 #define LIBSOLV_REPODATA_H
18 #include "pooltypes.h"
22 #ifdef LIBSOLV_INTERNAL
31 #define SIZEOF_SHA1 20
32 #define SIZEOF_SHA224 28
33 #define SIZEOF_SHA256 32
34 #define SIZEOF_SHA384 48
35 #define SIZEOF_SHA512 64
40 typedef struct _Repokey {
42 Id type; /* REPOKEY_TYPE_xxx */
44 unsigned int storage; /* KEY_STORAGE_xxx */
47 #define KEY_STORAGE_DROPPED 0
48 #define KEY_STORAGE_SOLVABLE 1
49 #define KEY_STORAGE_INCORE 2
50 #define KEY_STORAGE_VERTICAL_OFFSET 3
52 #ifdef LIBSOLV_INTERNAL
56 typedef struct _Repodata {
57 Id repodataid; /* our id */
58 struct _Repo *repo; /* back pointer to repo */
60 #define REPODATA_AVAILABLE 0
61 #define REPODATA_STUB 1
62 #define REPODATA_ERROR 2
63 #define REPODATA_STORE 3
64 #define REPODATA_LOADING 4
66 int state; /* available, stub or error */
68 void (*loadcallback)(struct _Repodata *);
70 int start; /* start of solvables this repodata is valid for */
71 int end; /* last solvable + 1 of this repodata */
73 Repokey *keys; /* keys, first entry is always zero */
74 int nkeys; /* length of keys array */
75 unsigned char keybits[32]; /* keyname hash */
77 Id *schemata; /* schema -> offset into schemadata */
78 int nschemata; /* number of schemata */
79 Id *schemadata; /* schema storage */
81 Stringpool spool; /* local string pool */
82 int localpool; /* is local string pool used */
84 Dirpool dirpool; /* local dir pool */
86 #ifdef LIBSOLV_INTERNAL
87 FILE *fp; /* file pointer of solv file */
88 int error; /* corrupt solv file */
90 unsigned int schemadatalen; /* schema storage size */
91 Id *schematahash; /* unification helper */
93 unsigned char *incoredata; /* in-core data */
94 unsigned int incoredatalen; /* in-core data used */
95 unsigned int incoredatafree; /* free data len */
97 Id mainschema; /* SOLVID_META schema */
98 Id *mainschemaoffsets; /* SOLVID_META offsets into incoredata */
100 Id *incoreoffset; /* offset for all entries */
102 Id *verticaloffset; /* offset for all verticals, nkeys elements */
103 Id lastverticaloffset; /* end of verticals */
105 Repopagestore store; /* our page store */
106 Id storestate; /* incremented every time the store might change */
108 unsigned char *vincore; /* internal vertical data */
109 unsigned int vincorelen; /* data size */
111 Id **attrs; /* un-internalized attributes */
112 Id **xattrs; /* anonymous handles */
113 int nxattrs; /* number of handles */
115 unsigned char *attrdata; /* their string data space */
116 unsigned int attrdatalen; /* its len */
117 Id *attriddata; /* their id space */
118 unsigned int attriddatalen; /* its len */
119 unsigned long long *attrnum64data; /* their 64bit num data space */
120 unsigned int attrnum64datalen; /* its len */
122 /* array cache to speed up repodata_add functions*/
127 /* directory cache to speed up repodata_str2dir */
128 struct dircache *dircache;
133 #define SOLVID_META -1
134 #define SOLVID_POS -2
135 #define SOLVID_SUBSCHEMA -3 /* internal! */
139 * management functions
141 void repodata_initdata(Repodata *data, struct _Repo *repo, int localpool);
142 void repodata_freedata(Repodata *data);
144 void repodata_free(Repodata *data);
145 void repodata_empty(Repodata *data, int localpool);
149 * key management functions
151 Id repodata_key2id(Repodata *data, Repokey *key, int create);
153 static inline Repokey *
154 repodata_id2key(Repodata *data, Id keyid)
156 return data->keys + keyid;
160 * schema management functions
162 Id repodata_schema2id(Repodata *data, Id *schema, int create);
163 void repodata_free_schemahash(Repodata *data);
166 repodata_id2schema(Repodata *data, Id schemaid)
168 return data->schemadata + data->schemata[schemaid];
172 * data search and access
175 /* check if there is a chance that the repodata contains data for
176 * the specified keyname */
178 repodata_precheck_keyname(Repodata *data, Id keyname)
180 unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
181 return x && (x & (1 << (keyname & 7))) ? 1 : 0;
184 /* check if the repodata contains data for the specified keyname */
186 repodata_has_keyname(Repodata *data, Id keyname)
189 if (!repodata_precheck_keyname(data, keyname))
191 for (i = 1; i < data->nkeys; i++)
192 if (data->keys[i].name == keyname)
197 /* search key <keyname> (all keys, if keyname == 0) for Id <solvid>
198 * Call <callback> for each match */
199 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);
201 /* Make sure the found KeyValue has the "str" field set. Return "str"
202 * if valid, NULL if not possible */
203 const char *repodata_stringify(Pool *pool, Repodata *data, Repokey *key, struct _KeyValue *kv, int flags);
205 int repodata_filelistfilter_matches(Repodata *data, const char *str);
208 /* lookup functions */
209 Id repodata_lookup_type(Repodata *data, Id solvid, Id keyname);
210 Id repodata_lookup_id(Repodata *data, Id solvid, Id keyname);
211 const char *repodata_lookup_str(Repodata *data, Id solvid, Id keyname);
212 int repodata_lookup_num(Repodata *data, Id solvid, Id keyname, unsigned long long *value);
213 int repodata_lookup_void(Repodata *data, Id solvid, Id keyname);
214 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep);
215 int repodata_lookup_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
216 const void *repodata_lookup_binary(Repodata *data, Id solvid, Id keyname, int *lenp);
220 * data assignment functions
224 * extend the data so that it contains the specified solvables
225 * (no longer needed, as the repodata_set functions autoextend)
227 void repodata_extend(Repodata *data, Id p);
228 void repodata_extend_block(Repodata *data, Id p, int num);
229 void repodata_shrink(Repodata *data, int end);
231 /* internalize freshly set data, so that it is found by the search
232 * functions and written out */
233 void repodata_internalize(Repodata *data);
235 /* create an anonymous handle. useful for substructures like
236 * fixarray/flexarray */
237 Id repodata_new_handle(Repodata *data);
239 /* basic types: void, num, string, Id */
240 void repodata_set_void(Repodata *data, Id solvid, Id keyname);
241 void repodata_set_num(Repodata *data, Id solvid, Id keyname, unsigned long long num);
242 void repodata_set_id(Repodata *data, Id solvid, Id keyname, Id id);
243 void repodata_set_str(Repodata *data, Id solvid, Id keyname, const char *str);
244 void repodata_set_binary(Repodata *data, Id solvid, Id keyname, void *buf, int len);
245 /* create id from string, then set_id */
246 void repodata_set_poolstr(Repodata *data, Id solvid, Id keyname, const char *str);
248 /* set numeric constant */
249 void repodata_set_constant(Repodata *data, Id solvid, Id keyname, unsigned int constant);
251 /* set Id constant */
252 void repodata_set_constantid(Repodata *data, Id solvid, Id keyname, Id id);
255 void repodata_set_bin_checksum(Repodata *data, Id solvid, Id keyname, Id type,
256 const unsigned char *buf);
257 void repodata_set_checksum(Repodata *data, Id solvid, Id keyname, Id type,
259 void repodata_set_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
262 /* directory (for package file list) */
263 void repodata_add_dirnumnum(Repodata *data, Id solvid, Id keyname, Id dir, Id num, Id num2);
264 void repodata_add_dirstr(Repodata *data, Id solvid, Id keyname, Id dir, const char *str);
265 void repodata_free_dircache(Repodata *data);
269 void repodata_add_idarray(Repodata *data, Id solvid, Id keyname, Id id);
270 void repodata_add_poolstr_array(Repodata *data, Id solvid, Id keyname, const char *str);
271 void repodata_add_fixarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
272 void repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
274 void repodata_unset(Repodata *data, Id solvid, Id keyname);
275 void repodata_unset_uninternalized(Repodata *data, Id solvid, Id keyname);
278 merge/swap attributes from one solvable to another
279 works only if the data is not yet internalized
281 void repodata_merge_attrs(Repodata *data, Id dest, Id src);
282 void repodata_merge_some_attrs(Repodata *data, Id dest, Id src, Map *keyidmap, int overwrite);
283 void repodata_swap_attrs(Repodata *data, Id dest, Id src);
285 Repodata *repodata_create_stubs(Repodata *data);
288 * load all paged data, used to speed up copying in repo_rpmdb
290 void repodata_disable_paging(Repodata *data);
292 /* helper functions */
293 Id repodata_globalize_id(Repodata *data, Id id, int create);
294 Id repodata_localize_id(Repodata *data, Id id, int create);
295 Id repodata_translate_id(Repodata *data, Repodata *fromdata, Id id, int create);
297 Id repodata_str2dir(Repodata *data, const char *dir, int create);
298 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
299 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
300 void repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file);
301 void repodata_set_deltalocation(Repodata *data, Id handle, int medianr, const char *dir, const char *file);
302 void repodata_set_sourcepkg(Repodata *data, Id solvid, const char *sourcepkg);
303 Id repodata_lookup_id_uninternalized(Repodata *data, Id solvid, Id keyname, Id voidid);
306 unsigned int repodata_memused(Repodata *data);
312 #endif /* LIBSOLV_REPODATA_H */