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