- add support for repository disabling
[platform/upstream/libsolv.git] / src / repodata.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  * repodata.h
10  * 
11  */
12
13 #ifndef SATSOLVER_REPODATA_H
14 #define SATSOLVER_REPODATA_H
15
16 #include <stdio.h> 
17
18 #include "pooltypes.h"
19 #include "pool.h"
20 #include "dirpool.h"
21 #include "repopage.h"
22
23 #define SIZEOF_MD5      16
24 #define SIZEOF_SHA1     20
25 #define SIZEOF_SHA256   32
26
27 struct _Repo;
28 struct _KeyValue;
29
30 typedef struct _Repokey {
31   Id name;
32   Id type;               /* REPOKEY_TYPE_xxx */
33   unsigned int size;
34   unsigned int storage; /* KEY_STORAGE_xxx */
35 } Repokey;
36
37 #define KEY_STORAGE_DROPPED             0
38 #define KEY_STORAGE_SOLVABLE            1
39 #define KEY_STORAGE_INCORE              2
40 #define KEY_STORAGE_VERTICAL_OFFSET     3
41
42
43 typedef struct _Repodata {
44   struct _Repo *repo;           /* back pointer to repo */
45
46 #define REPODATA_AVAILABLE      0
47 #define REPODATA_STUB           1
48 #define REPODATA_ERROR          2
49 #define REPODATA_STORE          3
50   int state;                    /* available, stub or error */
51
52   void (*loadcallback)(struct _Repodata *);
53
54   int start;                    /* start of solvables this repodata is valid for */
55   int end;                      /* last solvable + 1 of this repodata */
56
57   FILE *fp;                     /* file pointer of solv file */
58   int error;                    /* corrupt solv file */
59
60   Repokey *keys;                /* keys, first entry is always zero */
61   unsigned int nkeys;           /* length of keys array */
62   unsigned char keybits[32];    /* keyname hash */
63
64   Id *schemata;                 /* schema -> offset into schemadata */
65   unsigned int nschemata;       /* number of schemata */
66   Id *schemadata;               /* schema storage */
67   unsigned int schemadatalen;   /* schema storage size */
68   Id *schematahash;             /* unification helper */
69
70   Stringpool spool;             /* local string pool */
71   int localpool;                /* is local string pool used */
72
73   Dirpool dirpool;              /* local dir pool */
74
75   unsigned char *incoredata;    /* in-core data */
76   unsigned int incoredatalen;   /* in-core data used */
77   unsigned int incoredatafree;  /* free data len */
78
79   Id mainschema;                /* SOLVID_META schema */
80   Id *mainschemaoffsets;        /* SOLVID_META offsets into incoredata */
81
82   Id *incoreoffset;             /* offset for all entries */
83
84   Id *verticaloffset;           /* offset for all verticals, nkeys elements */
85   Id lastverticaloffset;        /* end of verticals */
86
87   Repopagestore store;          /* our page store */
88
89   unsigned char *vincore;       /* internal vertical data */
90   unsigned int vincorelen;      /* data size */
91
92   Id **attrs;                   /* un-internalized attributes */
93   Id **xattrs;                  /* anonymous handles */
94   int nxattrs;                  /* number of handles */
95
96   unsigned char *attrdata;      /* their string data space */
97   unsigned int attrdatalen;     /* its len */
98   Id *attriddata;               /* their id space */
99   unsigned int attriddatalen;   /* its len */
100
101   /* array cache to speed up repodata_add functions*/
102   Id lasthandle;
103   Id lastkey;
104   Id lastdatalen;
105
106 } Repodata;
107
108 #define SOLVID_META             -1
109 #define SOLVID_POS              -2
110 #define SOLVID_SUBSCHEMA        -3              /* internal! */
111
112
113 /*-----
114  * management functions
115  */
116 void repodata_initdata(Repodata *data, struct _Repo *repo, int localpool);
117 void repodata_freedata(Repodata *data);
118 void repodata_free(Repodata *data);
119
120
121 /*
122  * key management functions
123  */
124 Id repodata_key2id(Repodata *data, Repokey *key, int create);
125 static inline Repokey *
126 repodata_id2key(Repodata *data, Id keyid)
127 {
128   return data->keys + keyid;
129 }
130
131 /*
132  * schema management functions
133  */
134 Id repodata_schema2id(Repodata *data, Id *schema, int create);
135 static inline Id *
136 repodata_id2schema(Repodata *data, Id schemaid)
137 {
138   return data->schemadata + data->schemata[schemaid];
139 }
140
141 /*
142  * data search and access
143  */
144
145 /* check if there is a chance that the repodata contains data for
146  * the specified keyname */
147 static inline int
148 repodata_precheck_keyname(Repodata *data, Id keyname)
149 {
150   unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
151   return x && (x & (1 << (keyname & 7))) ? 1 : 0;
152 }
153
154 /* search key <keyname> (all keys, if keyname == 0) for Id <solvid>
155  * Call <callback> for each match */
156 void repodata_search(Repodata *data, Id solvid, Id keyname, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct _KeyValue *kv), void *cbdata);
157
158 /* Make sure the found KeyValue has the "str" field set. Return false
159  * if not possible */
160 int repodata_stringify(Pool *pool, Repodata *data, Repokey *key, struct _KeyValue *kv, int flags);
161
162
163 /* lookup functions */
164 Id repodata_lookup_id(Repodata *data, Id solvid, Id keyname);
165 const char *repodata_lookup_str(Repodata *data, Id solvid, Id keyname);
166 int repodata_lookup_num(Repodata *data, Id solvid, Id keyname, unsigned int *value);
167 int repodata_lookup_void(Repodata *data, Id solvid, Id keyname);
168 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep);
169
170
171
172 /*-----
173  * data assignment functions
174  */
175
176 /*
177  * extend the data so that it contains the specified solvables
178  * (no longer needed, as the repodata_set functions autoextend)
179  */
180 void repodata_extend(Repodata *data, Id p);
181 void repodata_extend_block(Repodata *data, Id p, int num);
182
183 /* internalize freshly set data, so that it is found by the search
184  * functions and written out */
185 void repodata_internalize(Repodata *data);
186
187 /* create an anonymous handle. useful for substructures like
188  * fixarray/flexarray  */
189 Id repodata_new_handle(Repodata *data);
190
191 /* basic types: void, num, string, Id */
192 void repodata_set_void(Repodata *data, Id solvid, Id keyname);
193 void repodata_set_num(Repodata *data, Id solvid, Id keyname, unsigned int num);
194 void repodata_set_id(Repodata *data, Id solvid, Id keyname, Id id);
195 void repodata_set_str(Repodata *data, Id solvid, Id keyname, const char *str);
196 /* create id from string, then set_id */
197 void repodata_set_poolstr(Repodata *data, Id solvid, Id keyname, const char *str);
198
199 /* set numeric constant */
200 void repodata_set_constant(Repodata *data, Id solvid, Id keyname, unsigned int constant);
201
202 /* set Id constant */
203 void repodata_set_constantid(Repodata *data, Id solvid, Id keyname, Id id);
204
205 /* checksum */
206 void repodata_set_bin_checksum(Repodata *data, Id solvid, Id keyname, Id type,
207                                const unsigned char *buf);
208 void repodata_set_checksum(Repodata *data, Id solvid, Id keyname, Id type,
209                            const char *str);
210
211 /* directory (for package file list) */
212 void repodata_add_dirnumnum(Repodata *data, Id solvid, Id keyname, Id dir, Id num, Id num2);
213 void repodata_add_dirstr(Repodata *data, Id solvid, Id keyname, Id dir, const char *str);
214
215
216 /* Arrays */
217 void repodata_add_idarray(Repodata *data, Id solvid, Id keyname, Id id);
218 void repodata_add_poolstr_array(Repodata *data, Id solvid, Id keyname, const char *str);
219 void repodata_add_fixarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
220 void repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
221
222 /* 
223  merge attributes from one solvable to another
224  works only if the data is not yet internalized
225 */
226 void repodata_merge_attrs(Repodata *data, Id dest, Id src);
227
228 /*
229  * load all paged data, used to speed up copying in repo_rpmdb
230  */
231 void repodata_disable_paging(Repodata *data);
232
233 /* helper functions */
234 Id repodata_globalize_id(Repodata *data, Id id, int create);
235 Id repodata_str2dir(Repodata *data, const char *dir, int create);
236 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
237 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
238 void repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file);
239
240 #endif /* SATSOLVER_REPODATA_H */