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 {
24 Id repoid; /* our id */
25 void *appdata; /* application private pointer */
27 Pool *pool; /* pool containing repo data */
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 priority; /* priority of this repo */
34 int subpriority; /* sub-priority of this repo, used just for sorting, not pruning */
36 Id *idarraydata; /* array of metadata Ids, solvable dependencies are offsets into this array */
40 Id *rpmdbid; /* solvable side data */
42 Repodata *repodata; /* our stores for non-solvable related data */
43 unsigned nrepodata; /* number of our stores.. */
46 extern Repo *repo_create(Pool *pool, const char *name);
47 extern void repo_free(Repo *repo, int reuseids);
48 extern void repo_freeallrepos(Pool *pool, int reuseids);
49 extern void *repo_sidedata_create(Repo *repo, size_t size);
50 extern void *repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count);
52 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
53 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker);
54 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
55 extern Offset repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens);
56 extern Offset repo_fix_conflicts(Repo *repo, Offset conflicts);
58 static inline const char *repo_name(const Repo *repo)
63 static inline Id repo_add_solvable(Repo *repo)
65 extern Id pool_add_solvable(Pool *pool);
66 Id p = pool_add_solvable(repo->pool);
67 if (!repo->start || repo->start == repo->end)
76 if (p + 1 > repo->end)
80 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, 1);
82 repo->pool->solvables[p].repo = repo;
86 static inline Id repo_add_solvable_block(Repo *repo, int count)
88 extern Id pool_add_solvable_block(Pool *pool, int count);
93 p = pool_add_solvable_block(repo->pool, count);
94 if (!repo->start || repo->start == repo->end)
97 repo->end = p + count;
103 if (p + count > repo->end)
104 repo->end = p + count;
107 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, count);
108 repo->nsolvables += count;
109 for (s = repo->pool->solvables + p; count--; s++)
114 static inline void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
116 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
119 if (start + count == repo->end)
121 repo->nsolvables -= count;
122 for (s = repo->pool->solvables + start, i = count; i--; s++)
124 pool_free_solvable_block(repo->pool, start, count, reuseids);
127 static inline Repo *pool_id2repo(Pool *pool, Id repoid)
129 return pool->repos[repoid - 1];
132 #define FOR_REPO_SOLVABLES(r, p, s) \
133 for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p) \
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;
157 #define SEARCH_STRINGMASK 15
158 #define SEARCH_STRING 1
159 #define SEARCH_SUBSTRING 2
160 #define SEARCH_GLOB 3
161 #define SEARCH_REGEX 4
162 #define SEARCH_ERROR 5
164 #define SEARCH_NOCASE (1<<8)
165 #define SEARCH_NO_STORAGE_SOLVABLE (1<<9)
166 #define SEARCH_SUB (1<<10)
167 #define SEARCH_ARRAYSENTINEL (1<<11)
168 #define SEARCH_SKIP_KIND (1<<12)
171 /* By default we don't match in attributes representing filelists
172 because the construction of those strings is costly. Specify this
173 flag if you want this. In that case kv->str will contain the full
174 filename (if matched of course). */
175 #define SEARCH_FILES (1<<13)
178 #define SEARCH_THISSOLVID (1<<31)
181 /* standard flags used in the repo_add functions */
182 #define REPO_REUSE_REPODATA (1 << 0)
183 #define REPO_NO_INTERNALIZE (1 << 1)
185 Repodata *repo_add_repodata(Repo *repo, int localpool);
186 Repodata *repo_last_repodata(Repo *repo);
188 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);
190 /* returns the string value of the attribute, or NULL if not found */
191 const char *repo_lookup_str(Repo *repo, Id entry, Id key);
192 /* returns the integer value of the attribute, or 0 if not found */
193 unsigned int repo_lookup_num(Repo *repo, Id entry, Id key, unsigned int notfound);
194 Id repo_lookup_id(Repo *repo, Id entry, Id keyid);
195 int repo_lookup_void(Repo *repo, Id entry, Id keyid);
196 const unsigned char *repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyid, Id *typep);
198 typedef struct _Datamatcher {
204 typedef struct _Dataiterator
226 /* iterators/filters */
244 int datamatcher_init(Datamatcher *ma, const char *match, int flags);
245 void datamatcher_free(Datamatcher *ma);
246 int datamatcher_match(Datamatcher *ma, const char *str);
251 * Iterator like interface to 'search' functionality
253 * Dataiterator is per-pool, additional filters can be applied
254 * to limit the search domain. See dataiterator_init below.
258 * dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
259 * while (dataiterator_step(&di))
260 * dosomething(di.solvid, di.key, di.kv);
261 * dataiterator_free(&di);
265 * Initialize dataiterator
267 * di: Pointer to Dataiterator to be initialized
268 * pool: Search domain for the iterator
269 * repo: if non-null, limit search to this repo
270 * solvid: if non-null, limit search to this solvable
271 * keyname: if non-null, limit search to this keyname
272 * match: if non-null, limit search to this match
274 int dataiterator_init(Dataiterator *di, Pool *pool, Repo *repo, Id p, Id keyname,
275 const char *match, int flags);
276 void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
277 void dataiterator_free(Dataiterator *di);
278 int dataiterator_step(Dataiterator *di);
279 void dataiterator_setpos(Dataiterator *di);
280 void dataiterator_setpos_parent(Dataiterator *di);
281 int dataiterator_match(Dataiterator *di, Datamatcher *ma);
282 void dataiterator_skip_attribute(Dataiterator *di);
283 void dataiterator_skip_solvable(Dataiterator *di);
284 void dataiterator_skip_repo(Dataiterator *di);
285 void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
286 void dataiterator_jump_to_repo(Dataiterator *di, Repo *repo);
287 void dataiterator_entersub(Dataiterator *di);
289 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
290 void repo_set_num(Repo *repo, Id p, Id keyname, Id num);
291 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
292 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
293 void repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str);
294 void repo_internalize(Repo *repo);
295 void repo_disable_paging(Repo *repo);
297 #endif /* SATSOLVER_REPO_H */