2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef SATSOLVER_REPO_H
14 #define SATSOLVER_REPO_H
16 #include "pooltypes.h"
22 typedef struct _Repo {
23 const char *name; /* name pointer */
24 Id repoid; /* our id */
25 void *appdata; /* application private pointer */
27 Pool *pool; /* pool containing this repo */
29 int start; /* start of this repo solvables within pool->solvables */
30 int end; /* last solvable + 1 of this repo */
31 int nsolvables; /* number of solvables repo is contributing to pool */
33 int disabled; /* ignore the solvables? */
34 int priority; /* priority of this repo */
35 int subpriority; /* sub-priority of this repo, used just for sorting, not pruning */
37 Id *idarraydata; /* array of metadata Ids, solvable dependencies are offsets into this array */
39 Offset lastoff; /* start of last array in idarraydata */
41 Id *rpmdbid; /* solvable side data */
43 Repodata *repodata; /* our stores for non-solvable related data */
44 unsigned nrepodata; /* number of our stores.. */
47 extern Repo *repo_create(Pool *pool, const char *name);
48 extern void repo_free(Repo *repo, int reuseids);
49 extern void repo_empty(Repo *repo, int reuseids);
50 extern void repo_freeallrepos(Pool *pool, int reuseids);
51 extern void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids);
52 extern void *repo_sidedata_create(Repo *repo, size_t size);
53 extern void *repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count);
55 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
56 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker);
57 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
58 extern Offset repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens);
59 extern Offset repo_fix_conflicts(Repo *repo, Offset conflicts);
61 static inline const char *repo_name(const Repo *repo)
66 static inline Id repo_add_solvable(Repo *repo)
68 extern Id pool_add_solvable(Pool *pool);
69 Id p = pool_add_solvable(repo->pool);
70 if (!repo->start || repo->start == repo->end)
71 repo->start = repo->end = p;
72 /* warning: sidedata must be extended before adapting start/end */
74 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, 1);
77 if (p + 1 > repo->end)
80 repo->pool->solvables[p].repo = repo;
84 static inline Id repo_add_solvable_block(Repo *repo, int count)
86 extern Id pool_add_solvable_block(Pool *pool, int count);
91 p = pool_add_solvable_block(repo->pool, count);
92 if (!repo->start || repo->start == repo->end)
93 repo->start = repo->end = p;
94 /* warning: sidedata must be extended before adapting start/end */
96 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, count);
99 if (p + count > repo->end)
100 repo->end = p + count;
101 repo->nsolvables += count;
102 for (s = repo->pool->solvables + p; count--; s++)
108 #define FOR_REPO_SOLVABLES(r, p, s) \
109 for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p) \
113 /* those two functions are here because they need the Repo definition */
115 static inline Repo *pool_id2repo(Pool *pool, Id repoid)
117 return repoid ? pool->repos[repoid - 1] : 0;
120 static inline int pool_installable(const Pool *pool, Solvable *s)
122 if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
124 if (s->repo && s->repo->disabled)
126 if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
128 if (pool->considered)
130 Id id = s - pool->solvables;
131 if (!MAPTST(pool->considered, id))
137 /* search callback values */
139 #define SEARCH_NEXT_KEY 1
140 #define SEARCH_NEXT_SOLVABLE 2
141 #define SEARCH_STOP 3
142 #define SEARCH_ENTERSUB -1
144 typedef struct _KeyValue {
150 int entry; /* array entry, starts with 0 */
151 int eof; /* last entry reached */
153 struct _KeyValue *parent;
156 /* search matcher flags */
157 #define SEARCH_STRINGMASK 15
158 #define SEARCH_STRING 1
159 #define SEARCH_STRINGSTART 2
160 #define SEARCH_STRINGEND 3
161 #define SEARCH_SUBSTRING 4
162 #define SEARCH_GLOB 5
163 #define SEARCH_REGEX 6
164 #define SEARCH_ERROR 15
165 #define SEARCH_NOCASE (1<<7)
167 /* iterator control */
168 #define SEARCH_NO_STORAGE_SOLVABLE (1<<8)
169 #define SEARCH_SUB (1<<9)
170 #define SEARCH_ARRAYSENTINEL (1<<10)
171 #define SEARCH_DISABLED_REPOS (1<<11)
172 #define SEARCH_COMPLETE_FILELIST (1<<12)
174 /* stringification flags */
175 #define SEARCH_SKIP_KIND (1<<16)
176 /* By default we stringify just to the basename of a file because
177 the construction of the full filename is costly. Specify this
178 flag if you want to match full filenames */
179 #define SEARCH_FILES (1<<17)
180 #define SEARCH_CHECKSUMS (1<<18)
182 /* dataiterator internal */
183 #define SEARCH_THISSOLVID (1<<31)
186 /* standard flags used in the repo_add functions */
187 #define REPO_REUSE_REPODATA (1 << 0)
188 #define REPO_NO_INTERNALIZE (1 << 1)
189 #define REPO_LOCALPOOL (1 << 2)
190 #define REPO_USE_LOADING (1 << 3)
191 #define REPO_EXTEND_SOLVABLES (1 << 4)
193 Repodata *repo_add_repodata(Repo *repo, int flags);
194 Repodata *repo_last_repodata(Repo *repo);
196 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);
198 /* returns the string value of the attribute, or NULL if not found */
199 Id repo_lookup_type(Repo *repo, Id entry, Id keyname);
200 const char *repo_lookup_str(Repo *repo, Id entry, Id keyname);
201 /* returns the integer value of the attribute, or notfound if not found */
202 unsigned int repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned int notfound);
203 Id repo_lookup_id(Repo *repo, Id entry, Id keyname);
204 int repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q);
205 int repo_lookup_void(Repo *repo, Id entry, Id keyname);
206 const char *repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
207 const unsigned char *repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
209 typedef struct _Datamatcher {
216 typedef struct _Dataiterator
238 /* iterators/filters */
258 int datamatcher_init(Datamatcher *ma, const char *match, int flags);
259 void datamatcher_free(Datamatcher *ma);
260 int datamatcher_match(Datamatcher *ma, const char *str);
265 * Iterator like interface to 'search' functionality
267 * Dataiterator is per-pool, additional filters can be applied
268 * to limit the search domain. See dataiterator_init below.
272 * dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
273 * while (dataiterator_step(&di))
274 * dosomething(di.solvid, di.key, di.kv);
275 * dataiterator_free(&di);
279 * Initialize dataiterator
281 * di: Pointer to Dataiterator to be initialized
282 * pool: Search domain for the iterator
283 * repo: if non-null, limit search to this repo
284 * solvid: if non-null, limit search to this solvable
285 * keyname: if non-null, limit search to this keyname
286 * match: if non-null, limit search to this match
288 int dataiterator_init(Dataiterator *di, Pool *pool, Repo *repo, Id p, Id keyname, const char *match, int flags);
289 void dataiterator_init_clone(Dataiterator *di, Dataiterator *from);
290 void dataiterator_set_search(Dataiterator *di, Repo *repo, Id p);
291 void dataiterator_set_keyname(Dataiterator *di, Id keyname);
292 int dataiterator_set_match(Dataiterator *di, const char *match, int flags);
294 void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
295 void dataiterator_free(Dataiterator *di);
296 int dataiterator_step(Dataiterator *di);
297 void dataiterator_setpos(Dataiterator *di);
298 void dataiterator_setpos_parent(Dataiterator *di);
299 int dataiterator_match(Dataiterator *di, Datamatcher *ma);
300 void dataiterator_skip_attribute(Dataiterator *di);
301 void dataiterator_skip_solvable(Dataiterator *di);
302 void dataiterator_skip_repo(Dataiterator *di);
303 void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
304 void dataiterator_jump_to_repo(Dataiterator *di, Repo *repo);
305 void dataiterator_entersub(Dataiterator *di);
306 void dataiterator_clonepos(Dataiterator *di, Dataiterator *from);
307 void dataiterator_seek(Dataiterator *di, int whence);
309 #define DI_SEEK_STAY (1 << 16)
310 #define DI_SEEK_CHILD 1
311 #define DI_SEEK_PARENT 2
312 #define DI_SEEK_REWIND 3
315 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
316 void repo_set_num(Repo *repo, Id p, Id keyname, unsigned int num);
317 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
318 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
319 void repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str);
320 void repo_internalize(Repo *repo);
321 void repo_disable_paging(Repo *repo);
323 #endif /* SATSOLVER_REPO_H */