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_REPO_H
14 #define LIBSOLV_REPO_H
16 #include "pooltypes.h"
23 typedef struct _Repo {
24 const char *name; /* name pointer */
25 Id repoid; /* our id */
26 void *appdata; /* application private pointer */
28 Pool *pool; /* pool containing this repo */
30 int start; /* start of this repo solvables within pool->solvables */
31 int end; /* last solvable + 1 of this repo */
32 int nsolvables; /* number of solvables repo is contributing to pool */
34 int disabled; /* ignore the solvables? */
35 int priority; /* priority of this repo */
36 int subpriority; /* sub-priority of this repo, used just for sorting, not pruning */
38 Id *idarraydata; /* array of metadata Ids, solvable dependencies are offsets into this array */
41 Repodata *repodata; /* our stores for non-solvable related data */
42 unsigned nrepodata; /* number of our stores.. */
44 Id *rpmdbid; /* solvable side data: rpm database id */
46 #ifdef LIBSOLV_INTERNAL
47 Offset lastoff; /* start of last array in idarraydata */
49 Hashtable lastidhash; /* hash to speed up repo_addid_dep */
50 Hashmask lastidhash_mask;
51 int lastidhash_idarraysize;
54 #endif /* LIBSOLV_INTERNAL */
57 extern Repo *repo_create(Pool *pool, const char *name);
58 extern void repo_free(Repo *repo, int reuseids);
59 extern void repo_empty(Repo *repo, int reuseids);
60 extern void repo_freedata(Repo *repo);
61 extern Id repo_add_solvable(Repo *repo);
62 extern Id repo_add_solvable_block(Repo *repo, int count);
63 extern void repo_free_solvable(Repo *repo, Id p, int reuseids);
64 extern void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids);
65 extern void *repo_sidedata_create(Repo *repo, size_t size);
66 extern void *repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count);
68 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
69 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker);
70 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
71 extern Offset repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens);
72 extern Offset repo_fix_conflicts(Repo *repo, Offset conflicts);
74 static inline const char *repo_name(const Repo *repo)
79 static inline Repodata *repo_id2repodata(Repo *repo, Id id)
81 return id ? repo->repodata + id : 0;
84 #define FOR_REPO_SOLVABLES(r, p, s) \
85 for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p) \
89 /* those two functions are here because they need the Repo definition */
91 static inline Repo *pool_id2repo(Pool *pool, Id repoid)
93 return repoid < pool->nrepos ? pool->repos[repoid] : 0;
96 static inline int pool_installable(const Pool *pool, Solvable *s)
98 if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
100 if (s->repo && s->repo->disabled)
102 if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
104 if (pool->considered)
106 Id id = s - pool->solvables;
107 if (!MAPTST(pool->considered, id))
113 /* search callback values */
115 #define SEARCH_NEXT_KEY 1
116 #define SEARCH_NEXT_SOLVABLE 2
117 #define SEARCH_STOP 3
118 #define SEARCH_ENTERSUB -1
120 typedef struct _KeyValue {
126 int entry; /* array entry, starts with 0 */
127 int eof; /* last entry reached */
129 struct _KeyValue *parent;
132 /* search matcher flags */
133 #define SEARCH_STRINGMASK 15
134 #define SEARCH_STRING 1
135 #define SEARCH_STRINGSTART 2
136 #define SEARCH_STRINGEND 3
137 #define SEARCH_SUBSTRING 4
138 #define SEARCH_GLOB 5
139 #define SEARCH_REGEX 6
140 #define SEARCH_ERROR 15
141 #define SEARCH_NOCASE (1<<7)
143 /* iterator control */
144 #define SEARCH_NO_STORAGE_SOLVABLE (1<<8)
145 #define SEARCH_SUB (1<<9)
146 #define SEARCH_ARRAYSENTINEL (1<<10)
147 #define SEARCH_DISABLED_REPOS (1<<11)
148 #define SEARCH_COMPLETE_FILELIST (1<<12)
150 /* stringification flags */
151 #define SEARCH_SKIP_KIND (1<<16)
152 /* By default we stringify just to the basename of a file because
153 the construction of the full filename is costly. Specify this
154 flag if you want to match full filenames */
155 #define SEARCH_FILES (1<<17)
156 #define SEARCH_CHECKSUMS (1<<18)
158 /* dataiterator internal */
159 #define SEARCH_THISSOLVID (1<<31)
162 /* standard flags used in the repo_add functions */
163 #define REPO_REUSE_REPODATA (1 << 0)
164 #define REPO_NO_INTERNALIZE (1 << 1)
165 #define REPO_LOCALPOOL (1 << 2)
166 #define REPO_USE_LOADING (1 << 3)
167 #define REPO_EXTEND_SOLVABLES (1 << 4)
169 Repodata *repo_add_repodata(Repo *repo, int flags);
170 Repodata *repo_last_repodata(Repo *repo);
172 void repo_search(Repo *repo, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata);
174 /* returns the string value of the attribute, or NULL if not found */
175 Id repo_lookup_type(Repo *repo, Id entry, Id keyname);
176 const char *repo_lookup_str(Repo *repo, Id entry, Id keyname);
177 /* returns the integer value of the attribute, or notfound if not found */
178 unsigned int repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned int notfound);
179 Id repo_lookup_id(Repo *repo, Id entry, Id keyname);
180 int repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q);
181 int repo_lookup_void(Repo *repo, Id entry, Id keyname);
182 const char *repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
183 const unsigned char *repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
185 typedef struct _Datamatcher {
192 typedef struct _Dataiterator
214 /* iterators/filters */
234 int datamatcher_init(Datamatcher *ma, const char *match, int flags);
235 void datamatcher_free(Datamatcher *ma);
236 int datamatcher_match(Datamatcher *ma, const char *str);
241 * Iterator like interface to 'search' functionality
243 * Dataiterator is per-pool, additional filters can be applied
244 * to limit the search domain. See dataiterator_init below.
248 * dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
249 * while (dataiterator_step(&di))
250 * dosomething(di.solvid, di.key, di.kv);
251 * dataiterator_free(&di);
255 * Initialize dataiterator
257 * di: Pointer to Dataiterator to be initialized
258 * pool: Search domain for the iterator
259 * repo: if non-null, limit search to this repo
260 * solvid: if non-null, limit search to this solvable
261 * keyname: if non-null, limit search to this keyname
262 * match: if non-null, limit search to this match
264 int dataiterator_init(Dataiterator *di, Pool *pool, Repo *repo, Id p, Id keyname, const char *match, int flags);
265 void dataiterator_init_clone(Dataiterator *di, Dataiterator *from);
266 void dataiterator_set_search(Dataiterator *di, Repo *repo, Id p);
267 void dataiterator_set_keyname(Dataiterator *di, Id keyname);
268 int dataiterator_set_match(Dataiterator *di, const char *match, int flags);
270 void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
271 void dataiterator_free(Dataiterator *di);
272 int dataiterator_step(Dataiterator *di);
273 void dataiterator_setpos(Dataiterator *di);
274 void dataiterator_setpos_parent(Dataiterator *di);
275 int dataiterator_match(Dataiterator *di, Datamatcher *ma);
276 void dataiterator_skip_attribute(Dataiterator *di);
277 void dataiterator_skip_solvable(Dataiterator *di);
278 void dataiterator_skip_repo(Dataiterator *di);
279 void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
280 void dataiterator_jump_to_repo(Dataiterator *di, Repo *repo);
281 void dataiterator_entersub(Dataiterator *di);
282 void dataiterator_clonepos(Dataiterator *di, Dataiterator *from);
283 void dataiterator_seek(Dataiterator *di, int whence);
285 #define DI_SEEK_STAY (1 << 16)
286 #define DI_SEEK_CHILD 1
287 #define DI_SEEK_PARENT 2
288 #define DI_SEEK_REWIND 3
291 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
292 void repo_set_num(Repo *repo, Id p, Id keyname, unsigned int num);
293 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
294 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
295 void repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str);
296 void repo_internalize(Repo *repo);
297 void repo_disable_paging(Repo *repo);
299 #define FOR_REPODATAS(repo, rdid, data) \
300 for (rdid = 1, data = repo->repodata + rdid; rdid < repo->nrepodata; rdid++, data++)
302 #endif /* LIBSOLV_REPO_H */