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