- add new flags for the load functions:
[platform/upstream/libsolv.git] / src / repo.h
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * repo.h
10  * 
11  */
12
13 #ifndef SATSOLVER_REPO_H
14 #define SATSOLVER_REPO_H
15
16 #include "pooltypes.h"
17 #include "pool.h"
18 #include "repodata.h"
19
20
21
22 typedef struct _Repo {
23   const char *name;             /* application private name pointer */
24   Id repoid;                    /* our id */
25   void *appdata;                /* application private pointer */
26
27   Pool *pool;                   /* pool containing this repo */
28
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 */
32
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 */
36
37   Id *idarraydata;              /* array of metadata Ids, solvable dependencies are offsets into this array */
38   int idarraysize;
39   Offset lastoff;               /* start of last array in idarraydata */
40
41   Id *rpmdbid;                  /* solvable side data */
42
43   Repodata *repodata;           /* our stores for non-solvable related data */
44   unsigned nrepodata;           /* number of our stores..  */
45 } Repo;
46
47 extern Repo *repo_create(Pool *pool, const char *name);
48 extern void repo_free(Repo *repo, int reuseids);
49 extern void repo_freeallrepos(Pool *pool, int reuseids);
50 extern void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids);
51 extern void *repo_sidedata_create(Repo *repo, size_t size);
52 extern void *repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count);
53
54 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
55 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker);
56 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
57 extern Offset repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens);
58 extern Offset repo_fix_conflicts(Repo *repo, Offset conflicts);
59
60 static inline const char *repo_name(const Repo *repo)
61 {
62   return repo->name;
63 }
64
65 static inline Id repo_add_solvable(Repo *repo)
66 {
67   extern Id pool_add_solvable(Pool *pool);
68   Id p = pool_add_solvable(repo->pool);
69   if (!repo->start || repo->start == repo->end)
70     repo->start = repo->end = p;
71   /* warning: sidedata must be extended before adapting start/end */
72   if (repo->rpmdbid)
73     repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, 1);
74   if (p < repo->start)
75     repo->start = p;
76   if (p + 1 > repo->end)
77     repo->end = p + 1;
78   repo->nsolvables++;
79   repo->pool->solvables[p].repo = repo;
80   return p;
81 }
82
83 static inline Id repo_add_solvable_block(Repo *repo, int count)
84 {
85   extern Id pool_add_solvable_block(Pool *pool, int count);
86   Id p;
87   Solvable *s;
88   if (!count)
89     return 0;
90   p = pool_add_solvable_block(repo->pool, count);
91   if (!repo->start || repo->start == repo->end)
92     repo->start = repo->end = p;
93   /* warning: sidedata must be extended before adapting start/end */
94   if (repo->rpmdbid)
95     repo->rpmdbid = (Id *)repo_sidedata_extend(repo, repo->rpmdbid, sizeof(Id), p, count);
96   if (p < repo->start)
97     repo->start = p;
98   if (p + count > repo->end)
99     repo->end = p + count;
100   repo->nsolvables += count;
101   for (s = repo->pool->solvables + p; count--; s++)
102     s->repo = repo;
103   return p;
104 }
105
106
107 #define FOR_REPO_SOLVABLES(r, p, s)                                             \
108   for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p)   \
109     if (s->repo == (r))
110
111
112 /* those two functions are here because they need the Repo definition */
113
114 static inline Repo *pool_id2repo(Pool *pool, Id repoid)
115 {
116   return pool->repos[repoid - 1];
117 }
118
119 static inline int pool_installable(const Pool *pool, Solvable *s)
120 {
121   if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
122     return 0;
123   if (s->repo && s->repo->disabled)
124     return 0;
125   if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
126     return 0;
127   if (pool->considered)
128     { 
129       Id id = s - pool->solvables;
130       if (!MAPTST(pool->considered, id))
131         return 0;
132     }
133   return 1;
134 }
135
136 /* search callback values */
137
138 #define SEARCH_NEXT_KEY         1
139 #define SEARCH_NEXT_SOLVABLE    2
140 #define SEARCH_STOP             3
141 #define SEARCH_ENTERSUB         -1
142
143 typedef struct _KeyValue {
144   Id id;
145   const char *str;
146   int num;
147   int num2;
148
149   int entry;    /* array entry, starts with 0 */
150   int eof;      /* last entry reached */
151
152   struct _KeyValue *parent;
153 } KeyValue;
154
155 /* search matcher flags */
156 #define SEARCH_STRINGMASK       15
157 #define SEARCH_STRING           1
158 #define SEARCH_SUBSTRING        2
159 #define SEARCH_GLOB             3
160 #define SEARCH_REGEX            4
161 #define SEARCH_ERROR            5
162 #define SEARCH_NOCASE                   (1<<7)
163
164 /* iterator control */
165 #define SEARCH_NO_STORAGE_SOLVABLE      (1<<8)
166 #define SEARCH_SUB                      (1<<9)
167 #define SEARCH_ARRAYSENTINEL            (1<<10)
168 #define SEARCH_DISABLED_REPOS           (1<<11)
169 #define SEARCH_COMPLETE_FILELIST        (1<<12)
170
171 /* stringification flags */
172 #define SEARCH_SKIP_KIND                (1<<16)
173 /* By default we stringify just to the basename of a file because
174    the construction of the full filename is costly.  Specify this
175    flag if you want to match full filenames */
176 #define SEARCH_FILES                    (1<<17)
177 #define SEARCH_CHECKSUMS                (1<<18)
178
179 /* dataiterator internal */
180 #define SEARCH_THISSOLVID               (1<<31)
181
182
183 /* standard flags used in the repo_add functions */
184 #define REPO_REUSE_REPODATA             (1 << 0)
185 #define REPO_NO_INTERNALIZE             (1 << 1)
186 #define REPO_LOCALPOOL                  (1 << 2)
187 #define REPO_USE_LOADING                (1 << 3)
188 #define REPO_EXTEND_SOLVABLES           (1 << 4)
189
190 Repodata *repo_add_repodata(Repo *repo, int flags);
191 Repodata *repo_last_repodata(Repo *repo);
192
193 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
195 /* returns the string value of the attribute, or NULL if not found */
196 const char *repo_lookup_str(Repo *repo, Id entry, Id key);
197 /* returns the integer value of the attribute, or 0 if not found */
198 unsigned int repo_lookup_num(Repo *repo, Id entry, Id key, unsigned int notfound);
199 Id repo_lookup_id(Repo *repo, Id entry, Id keyid);
200 int repo_lookup_void(Repo *repo, Id entry, Id keyid);
201 const unsigned char *repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyid, Id *typep);
202
203 typedef struct _Datamatcher {
204   int flags;
205   const char *match;
206   void *matchdata;
207   int error;
208 } Datamatcher;
209
210 typedef struct _Dataiterator
211 {
212   int state;
213   int flags;
214
215   Pool *pool;
216   Repo *repo;
217   Repodata *data;
218
219   /* data pointers */
220   unsigned char *dp;
221   unsigned char *ddp;
222   Id *idp;
223   Id *keyp;
224
225   /* the result */
226   Repokey *key;
227   KeyValue kv;
228
229   /* our matcher */
230   Datamatcher matcher;
231
232   /* iterators/filters */
233   Id keyname;
234   Id repodataid;
235   Id solvid;
236   Id repoid;
237
238   Id keynames[3 + 1];
239   int nkeynames;
240   int rootlevel;
241
242   /* recursion data */
243   struct di_parent {
244     KeyValue kv;
245     unsigned char *dp;
246     Id *keyp;
247   } parents[3];
248   int nparents;
249
250 } Dataiterator;
251
252 int datamatcher_init(Datamatcher *ma, const char *match, int flags);
253 void datamatcher_free(Datamatcher *ma);
254 int datamatcher_match(Datamatcher *ma, const char *str);
255
256 /*
257  * Dataiterator
258  * 
259  * Iterator like interface to 'search' functionality
260  * 
261  * Dataiterator is per-pool, additional filters can be applied
262  * to limit the search domain. See dataiterator_init below.
263  * 
264  * Use these like:
265  *    Dataiterator di;
266  *    dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
267  *    while (dataiterator_step(&di))
268  *      dosomething(di.solvid, di.key, di.kv);
269  *    dataiterator_free(&di);
270  */
271
272 /*
273  * Initialize dataiterator
274  * 
275  * di:      Pointer to Dataiterator to be initialized
276  * pool:    Search domain for the iterator
277  * repo:    if non-null, limit search to this repo
278  * solvid:  if non-null, limit search to this solvable
279  * keyname: if non-null, limit search to this keyname
280  * match:   if non-null, limit search to this match
281  */
282 int dataiterator_init(Dataiterator *di, Pool *pool, Repo *repo, Id p, Id keyname, const char *match, int flags);
283 void dataiterator_init_clone(Dataiterator *di, Dataiterator *from);
284 void dataiterator_set_search(Dataiterator *di, Repo *repo, Id p);
285 void dataiterator_set_keyname(Dataiterator *di, Id keyname);
286 int dataiterator_set_match(Dataiterator *di, const char *match, int flags);
287
288 void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
289 void dataiterator_free(Dataiterator *di);
290 int dataiterator_step(Dataiterator *di);
291 void dataiterator_setpos(Dataiterator *di);
292 void dataiterator_setpos_parent(Dataiterator *di);
293 int dataiterator_match(Dataiterator *di, Datamatcher *ma);
294 void dataiterator_skip_attribute(Dataiterator *di);
295 void dataiterator_skip_solvable(Dataiterator *di);
296 void dataiterator_skip_repo(Dataiterator *di);
297 void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
298 void dataiterator_jump_to_repo(Dataiterator *di, Repo *repo);
299 void dataiterator_entersub(Dataiterator *di);
300 void dataiterator_clonepos(Dataiterator *di, Dataiterator *from);
301 void dataiterator_seek(Dataiterator *di, int whence);
302
303 #define DI_SEEK_STAY    (1 << 16)
304 #define DI_SEEK_CHILD   1
305 #define DI_SEEK_PARENT  2
306 #define DI_SEEK_REWIND  3
307
308
309 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
310 void repo_set_num(Repo *repo, Id p, Id keyname, Id num);
311 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
312 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
313 void repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str);
314 void repo_internalize(Repo *repo);
315 void repo_disable_paging(Repo *repo);
316
317 #endif /* SATSOLVER_REPO_H */