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