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
18 #include "pooltypes.h"
22 typedef struct _Repokey {
24 Id type; /* REPOKEY_TYPE_xxx */
26 unsigned int storage; /* KEY_STORAGE_xxx */
29 #define KEY_STORAGE_DROPPED 0
30 #define KEY_STORAGE_SOLVABLE 1
31 #define KEY_STORAGE_INCORE 2
32 #define KEY_STORAGE_VERTICAL_OFFSET 3
35 typedef struct _Repo {
37 struct _Pool *pool; /* pool containing repo data */
39 int start; /* start of this repo solvables within pool->solvables */
40 int end; /* last solvable + 1 of this repo */
41 int nsolvables; /* number of solvables repo is contributing to pool */
43 int priority; /* priority of this repo */
45 Id *idarraydata; /* array of metadata Ids, solvable dependencies are offsets into this array */
49 Id *rpmdbid; /* hmm, go to repodata? */
50 unsigned char rpmdbcookie[32];
52 Repodata *repodata; /* our stores for non-solvable related data */
53 unsigned nrepodata; /* number of our stores.. */
56 extern Repo *repo_create(Pool *pool, const char *name);
57 extern void repo_free(Repo *repo, int reuseids);
58 extern void repo_freeallrepos(Pool *pool, int reuseids);
59 extern void *repo_sidedata_create(Repo *repo, size_t size);
60 extern void *repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count);
62 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
63 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker);
64 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
65 extern Offset repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens);
66 extern Offset repo_fix_conflicts(Repo *repo, Offset conflicts);
68 static inline const char *repo_name(const Repo *repo)
73 static inline Id repo_add_solvable(Repo *repo)
75 extern Id pool_add_solvable(Pool *pool);
76 Id p = pool_add_solvable(repo->pool);
77 if (!repo->start || repo->start == repo->end)
85 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, 1);
88 if (p + 1 > repo->end)
92 repo->pool->solvables[p].repo = repo;
96 static inline Id repo_add_solvable_block(Repo *repo, int count)
98 extern Id pool_add_solvable_block(Pool *pool, int count);
103 p = pool_add_solvable_block(repo->pool, count);
104 if (!repo->start || repo->start == repo->end)
107 repo->end = p + count;
112 repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, count);
115 if (p + count > repo->end)
116 repo->end = p + count;
118 repo->nsolvables += count;
119 for (s = repo->pool->solvables + p; count--; s++)
124 static inline void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids)
126 extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
129 if (start + count == repo->end)
131 repo->nsolvables -= count;
132 for (s = repo->pool->solvables + start, i = count; i--; s++)
134 pool_free_solvable_block(repo->pool, start, count, reuseids);
137 #define FOR_REPO_SOLVABLES(r, p, s) \
138 for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p) \
142 /* search callback values */
144 #define SEARCH_NEXT_KEY 1
145 #define SEARCH_NEXT_SOLVABLE 2
146 #define SEARCH_STOP 3
148 typedef struct _KeyValue {
154 int entry; /* array entry, starts with 0 */
155 int eof; /* last entry reached */
157 struct _KeyValue *parent;
161 #define SEARCH_STRINGMASK 15
162 #define SEARCH_STRING 1
163 #define SEARCH_SUBSTRING 2
164 #define SEARCH_GLOB 3
165 #define SEARCH_REGEX 4
166 #define SEARCH_ERROR 5
168 #define SEARCH_NOCASE (1<<8)
169 #define SEARCH_NO_STORAGE_SOLVABLE (1<<9)
170 #define SEARCH_SUB (1<<10)
171 #define SEARCH_ALL_REPOS (1<<11)
172 #define SEARCH_SKIP_KIND (1<<12)
175 /* By default we don't match in attributes representing filelists
176 because the construction of those strings is costly. Specify this
177 flag if you want this. In that case kv->str will contain the full
178 filename (if matched of course). */
179 #define SEARCH_FILES (1<<13)
182 #define SEARCH_THISENTRY (1<<31)
185 /* standard flags used in the repo_add functions */
186 #define REPO_REUSE_REPODATA (1 << 0)
187 #define REPO_NO_INTERNALIZE (1 << 1)
189 Repodata *repo_add_repodata(Repo *repo, int localpool);
190 Repodata *repo_last_repodata(Repo *repo);
192 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);
194 /* returns the string value of the attribute, or NULL if not found */
195 const char *repo_lookup_str(Repo *repo, Id entry, Id key);
196 /* returns the integer value of the attribute, or 0 if not found */
197 unsigned int repo_lookup_num(Repo *repo, Id entry, Id key, unsigned int notfound);
198 Id repo_lookup_id(Repo *repo, Id entry, Id keyid);
199 int repo_lookup_void(Repo *repo, Id entry, Id keyid);
200 const unsigned char *repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyid, Id *typep);
204 typedef struct _Dataiterator
208 unsigned char *nextkeydp;
227 typedef struct _Datamatcher {
234 typedef struct _Dataiterator
256 /* iterators/filters */
275 dataiterator_init(&di, repo, 0, 0, "bla", SEARCH_SUBSTRING);
276 while (dataiterator_step(&di))
277 dosomething(di.solvid, di.key, di.kv); */
278 void dataiterator_init(Dataiterator *di, Repo *repo, Id p, Id keyname,
279 const char *match, int flags);
280 void dataiterator_free(Dataiterator *di);
281 int dataiterator_step(Dataiterator *di);
282 void dataiterator_setpos(Dataiterator *di);
283 int dataiterator_match(Dataiterator *di, int flags, const void *match);
284 void dataiterator_skip_attribute(Dataiterator *di);
285 void dataiterator_skip_solvable(Dataiterator *di);
286 void dataiterator_skip_repo(Dataiterator *di);
287 void dataiterator_jump_to_solvable(Dataiterator *di, Solvable *s);
288 void dataiterator_jump_to_repo(Dataiterator *di, Repo *repo);
290 /* to be removed ... */
291 int dataiterator_match(Dataiterator *di, int flags, const void *match);
293 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
294 void repo_set_num(Repo *repo, Id p, Id keyname, Id num);
295 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
296 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
297 void repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str);
298 void repo_internalize(Repo *repo);
299 void repo_disable_paging(Repo *repo);
301 #endif /* SATSOLVER_REPO_H */