Imported Upstream version 0.6.35
[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 "poolarch.h"
19 #include "repodata.h"
20 #include "dataiterator.h"
21 #include "hash.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 typedef struct _Repo {
28   const char *name;             /* name pointer */
29   Id repoid;                    /* our id */
30   void *appdata;                /* application private pointer */
31
32   Pool *pool;                   /* pool containing this repo */
33
34   int start;                    /* start of this repo solvables within pool->solvables */
35   int end;                      /* last solvable + 1 of this repo */
36   int nsolvables;               /* number of solvables repo is contributing to pool */
37
38   int disabled;                 /* ignore the solvables? */
39   int priority;                 /* priority of this repo */
40   int subpriority;              /* sub-priority of this repo, used just for sorting, not pruning */
41
42   Id *idarraydata;              /* array of metadata Ids, solvable dependencies are offsets into this array */
43   int idarraysize;
44
45   int nrepodata;                /* number of our stores..  */
46
47   Id *rpmdbid;                  /* solvable side data: rpm database id */
48
49 #ifdef LIBSOLV_INTERNAL
50   Repodata *repodata;           /* our stores for non-solvable related data */
51   Offset lastoff;               /* start of last array in idarraydata */
52
53   Hashtable lastidhash;         /* hash to speed up repo_addid_dep */
54   Hashval lastidhash_mask;
55   int lastidhash_idarraysize;
56   int lastmarker;
57   Offset lastmarkerpos;
58 #endif /* LIBSOLV_INTERNAL */
59 } Repo;
60
61 extern Repo *repo_create(Pool *pool, const char *name);
62 extern void repo_free(Repo *repo, int reuseids);
63 extern void repo_empty(Repo *repo, int reuseids);
64 extern void repo_freedata(Repo *repo);
65 extern Id repo_add_solvable(Repo *repo);
66 extern Id repo_add_solvable_block(Repo *repo, int count);
67 extern void repo_free_solvable(Repo *repo, Id p, int reuseids);
68 extern void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids);
69 extern void *repo_sidedata_create(Repo *repo, size_t size);
70 extern void *repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count);
71 extern Id repo_add_solvable_block_before(Repo *repo, int count, Repo *beforerepo);
72
73 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
74 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker);
75 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
76
77 static inline const char *repo_name(const Repo *repo)
78 {
79   return repo->name;
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_disabled_solvable(const Pool *pool, Solvable *s)
90 {
91   if (s->repo && s->repo->disabled)
92     return 1;
93   if (pool->considered)
94     {
95       Id id = s - pool->solvables;
96       if (!MAPTST(pool->considered, id))
97         return 1;
98     }
99   return 0;
100 }
101
102 static inline int pool_badarch_solvable(const Pool *pool, Solvable *s)
103 {
104   if (!s->arch)
105     return 1;
106   if (pool->id2arch && pool_arch2score(pool, s->arch) == 0)
107     return 1;
108   return 0;
109 }
110
111 static inline int pool_installable(const Pool *pool, Solvable *s)
112 {
113   if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
114     return 0;
115   if (s->repo && s->repo->disabled)
116     return 0;
117   if (pool->id2arch && pool_arch2score(pool, s->arch) == 0)
118     return 0;
119   if (pool->considered)
120     {
121       Id id = s - pool->solvables;
122       if (!MAPTST(pool->considered, id))
123         return 0;
124     }
125   return 1;
126 }
127
128 /* search callback values */
129 #define SEARCH_NEXT_KEY         1
130 #define SEARCH_NEXT_SOLVABLE    2
131 #define SEARCH_STOP             3
132 #define SEARCH_ENTERSUB         -1
133
134 /* standard flags used in the repo_add functions */
135 #define REPO_REUSE_REPODATA             (1 << 0)
136 #define REPO_NO_INTERNALIZE             (1 << 1)
137 #define REPO_LOCALPOOL                  (1 << 2)
138 #define REPO_USE_LOADING                (1 << 3)
139 #define REPO_EXTEND_SOLVABLES           (1 << 4)
140 #define REPO_USE_ROOTDIR                (1 << 5)
141 #define REPO_NO_LOCATION                (1 << 6)
142
143 Repodata *repo_add_repodata(Repo *repo, int flags);
144 Repodata *repo_id2repodata(Repo *repo, Id id);
145 Repodata *repo_last_repodata(Repo *repo);
146
147 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);
148
149 /* returns the string value of the attribute, or NULL if not found */
150 Id repo_lookup_type(Repo *repo, Id entry, Id keyname);
151 const char *repo_lookup_str(Repo *repo, Id entry, Id keyname);
152 /* returns the integer value of the attribute, or notfound if not found */
153 unsigned long long repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned long long notfound);
154 Id repo_lookup_id(Repo *repo, Id entry, Id keyname);
155 int repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q);
156 int repo_lookup_deparray(Repo *repo, Id entry, Id keyname, Queue *q, Id marker);
157 int repo_lookup_void(Repo *repo, Id entry, Id keyname);
158 const char *repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
159 const unsigned char *repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
160 const void *repo_lookup_binary(Repo *repo, Id entry, Id keyname, int *lenp);
161 Id solv_depmarker(Id keyname, Id marker);
162
163 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
164 void repo_set_num(Repo *repo, Id p, Id keyname, unsigned long long num);
165 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
166 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
167 void repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str);
168 void repo_add_idarray(Repo *repo, Id p, Id keyname, Id id);
169 void repo_add_deparray(Repo *repo, Id p, Id keyname, Id dep, Id marker);
170 void repo_set_idarray(Repo *repo, Id p, Id keyname, Queue *q);
171 void repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker);
172 void repo_unset(Repo *repo, Id p, Id keyname);
173
174 void repo_internalize(Repo *repo);
175 void repo_disable_paging(Repo *repo);
176
177 /* iterator macros */
178 #define FOR_REPO_SOLVABLES(r, p, s)                                             \
179   for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p)   \
180     if (s->repo != (r))                                                         \
181       continue;                                                                 \
182     else
183
184 #ifdef LIBSOLV_INTERNAL
185 #define FOR_REPODATAS(repo, rdid, data) \
186         for (rdid = 1, data = repo->repodata + rdid; rdid < repo->nrepodata; rdid++, data++)
187 #else
188 #define FOR_REPODATAS(repo, rdid, data) \
189         for (rdid = 1; rdid < repo->nrepodata && (data = repo_id2repodata(repo, rdid)); rdid++)
190 #endif
191
192 /* weird suse stuff, do not use */
193 extern Offset repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens);
194 extern Offset repo_fix_conflicts(Repo *repo, Offset conflicts);
195 extern void repo_rewrite_suse_deps(Solvable *s, Offset freshens);
196
197 #ifdef __cplusplus
198 }
199 #endif
200
201 #endif /* LIBSOLV_REPO_H */