- start support for 64bit nums
[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 LIBSOLV_REPODATA_H
14 #define LIBSOLV_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 #ifdef LIBSOLV_INTERNAL
43 struct dircache;
44 #endif
45
46 typedef struct _Repodata {
47   Id repodataid;                /* our id */
48   struct _Repo *repo;           /* back pointer to repo */
49
50 #define REPODATA_AVAILABLE      0
51 #define REPODATA_STUB           1
52 #define REPODATA_ERROR          2
53 #define REPODATA_STORE          3
54 #define REPODATA_LOADING        4
55
56   int state;                    /* available, stub or error */
57
58   void (*loadcallback)(struct _Repodata *);
59
60   int start;                    /* start of solvables this repodata is valid for */
61   int end;                      /* last solvable + 1 of this repodata */
62
63   Repokey *keys;                /* keys, first entry is always zero */
64   int nkeys;                    /* length of keys array */
65   unsigned char keybits[32];    /* keyname hash */
66
67   Id *schemata;                 /* schema -> offset into schemadata */
68   int nschemata;                /* number of schemata */
69   Id *schemadata;               /* schema storage */
70
71   Stringpool spool;             /* local string pool */
72   int localpool;                /* is local string pool used */
73
74   Dirpool dirpool;              /* local dir pool */
75
76 #ifdef LIBSOLV_INTERNAL
77   FILE *fp;                     /* file pointer of solv file */
78   int error;                    /* corrupt solv file */
79
80   unsigned int schemadatalen;   /* schema storage size */
81   Id *schematahash;             /* unification helper */
82
83   unsigned char *incoredata;    /* in-core data */
84   unsigned int incoredatalen;   /* in-core data used */
85   unsigned int incoredatafree;  /* free data len */
86
87   Id mainschema;                /* SOLVID_META schema */
88   Id *mainschemaoffsets;        /* SOLVID_META offsets into incoredata */
89
90   Id *incoreoffset;             /* offset for all entries */
91
92   Id *verticaloffset;           /* offset for all verticals, nkeys elements */
93   Id lastverticaloffset;        /* end of verticals */
94
95   Repopagestore store;          /* our page store */
96
97   unsigned char *vincore;       /* internal vertical data */
98   unsigned int vincorelen;      /* data size */
99
100   Id **attrs;                   /* un-internalized attributes */
101   Id **xattrs;                  /* anonymous handles */
102   int nxattrs;                  /* number of handles */
103
104   unsigned char *attrdata;      /* their string data space */
105   unsigned int attrdatalen;     /* its len */
106   Id *attriddata;               /* their id space */
107   unsigned int attriddatalen;   /* its len */
108   unsigned long long *attrnum64data;    /* their 64bit num data space */
109   unsigned int attrnum64datalen;        /* its len */
110
111   /* array cache to speed up repodata_add functions*/
112   Id lasthandle;
113   Id lastkey;
114   Id lastdatalen;
115
116   /* directory cache to speed up repodata_str2dir */
117   struct dircache *dircache;
118 #endif
119
120 } Repodata;
121
122 #define SOLVID_META             -1
123 #define SOLVID_POS              -2
124 #define SOLVID_SUBSCHEMA        -3              /* internal! */
125
126
127 /*-----
128  * management functions
129  */
130 void repodata_initdata(Repodata *data, struct _Repo *repo, int localpool);
131 void repodata_freedata(Repodata *data);
132
133 void repodata_free(Repodata *data);
134 void repodata_empty(Repodata *data, int localpool);
135
136
137 /*
138  * key management functions
139  */
140 Id repodata_key2id(Repodata *data, Repokey *key, int create);
141
142 static inline Repokey *
143 repodata_id2key(Repodata *data, Id keyid)
144 {
145   return data->keys + keyid;
146 }
147
148 /*
149  * schema management functions
150  */
151 Id repodata_schema2id(Repodata *data, Id *schema, int create);
152 void repodata_free_schemahash(Repodata *data);
153
154 static inline Id *
155 repodata_id2schema(Repodata *data, Id schemaid)
156 {
157   return data->schemadata + data->schemata[schemaid];
158 }
159
160 /*
161  * data search and access
162  */
163
164 /* check if there is a chance that the repodata contains data for
165  * the specified keyname */
166 static inline int
167 repodata_precheck_keyname(Repodata *data, Id keyname)
168 {
169   unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
170   return x && (x & (1 << (keyname & 7))) ? 1 : 0;
171 }
172
173 /* check if the repodata contains data for the specified keyname */
174 static inline int
175 repodata_has_keyname(Repodata *data, Id keyname)
176 {
177   int i;
178   if (!repodata_precheck_keyname(data, keyname))
179     return 0;
180   for (i = 1; i < data->nkeys; i++)
181     if (data->keys[i].name == keyname)
182       return 1;
183   return 0;
184 }
185
186 /* search key <keyname> (all keys, if keyname == 0) for Id <solvid>
187  * Call <callback> for each match */
188 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);
189
190 /* Make sure the found KeyValue has the "str" field set. Return false
191  * if not possible */
192 int repodata_stringify(Pool *pool, Repodata *data, Repokey *key, struct _KeyValue *kv, int flags);
193
194 int repodata_filelistfilter_matches(Repodata *data, const char *str);
195
196
197 /* lookup functions */
198 Id repodata_lookup_type(Repodata *data, Id solvid, Id keyname);
199 Id repodata_lookup_id(Repodata *data, Id solvid, Id keyname);
200 const char *repodata_lookup_str(Repodata *data, Id solvid, Id keyname);
201 int repodata_lookup_num(Repodata *data, Id solvid, Id keyname, unsigned int *value);
202 int repodata_lookup_void(Repodata *data, Id solvid, Id keyname);
203 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep);
204 int repodata_lookup_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
205
206
207 /*-----
208  * data assignment functions
209  */
210
211 /*
212  * extend the data so that it contains the specified solvables
213  * (no longer needed, as the repodata_set functions autoextend)
214  */
215 void repodata_extend(Repodata *data, Id p);
216 void repodata_extend_block(Repodata *data, Id p, int num);
217 void repodata_shrink(Repodata *data, int end);
218
219 /* internalize freshly set data, so that it is found by the search
220  * functions and written out */
221 void repodata_internalize(Repodata *data);
222
223 /* create an anonymous handle. useful for substructures like
224  * fixarray/flexarray  */
225 Id repodata_new_handle(Repodata *data);
226
227 /* basic types: void, num, string, Id */
228 void repodata_set_void(Repodata *data, Id solvid, Id keyname);
229 void repodata_set_num(Repodata *data, Id solvid, Id keyname, unsigned int num);
230 void repodata_set_id(Repodata *data, Id solvid, Id keyname, Id id);
231 void repodata_set_str(Repodata *data, Id solvid, Id keyname, const char *str);
232 void repodata_set_binary(Repodata *data, Id solvid, Id keyname, void *buf, int len);
233 /* create id from string, then set_id */
234 void repodata_set_poolstr(Repodata *data, Id solvid, Id keyname, const char *str);
235
236 /* set numeric constant */
237 void repodata_set_constant(Repodata *data, Id solvid, Id keyname, unsigned int constant);
238
239 /* set Id constant */
240 void repodata_set_constantid(Repodata *data, Id solvid, Id keyname, Id id);
241
242 /* checksum */
243 void repodata_set_bin_checksum(Repodata *data, Id solvid, Id keyname, Id type,
244                                const unsigned char *buf);
245 void repodata_set_checksum(Repodata *data, Id solvid, Id keyname, Id type,
246                            const char *str);
247 void repodata_set_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
248
249
250 /* directory (for package file list) */
251 void repodata_add_dirnumnum(Repodata *data, Id solvid, Id keyname, Id dir, Id num, Id num2);
252 void repodata_add_dirstr(Repodata *data, Id solvid, Id keyname, Id dir, const char *str);
253 void repodata_free_dircache(Repodata *data);
254
255
256 /* Arrays */
257 void repodata_add_idarray(Repodata *data, Id solvid, Id keyname, Id id);
258 void repodata_add_poolstr_array(Repodata *data, Id solvid, Id keyname, const char *str);
259 void repodata_add_fixarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
260 void repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
261
262 void repodata_delete(Repodata *data, Id solvid, Id keyname);
263 void repodata_delete_uninternalized(Repodata *data, Id solvid, Id keyname);
264
265 /* 
266  merge/swap attributes from one solvable to another
267  works only if the data is not yet internalized
268 */
269 void repodata_merge_attrs(Repodata *data, Id dest, Id src);
270 void repodata_merge_some_attrs(Repodata *data, Id dest, Id src, Map *keyidmap, int overwrite);
271 void repodata_swap_attrs(Repodata *data, Id dest, Id src);
272
273 void repodata_create_stubs(Repodata *data);
274 void repodata_join(Repodata *data, Id joinkey);
275
276 /*
277  * load all paged data, used to speed up copying in repo_rpmdb
278  */
279 void repodata_disable_paging(Repodata *data);
280
281 /* helper functions */
282 Id repodata_globalize_id(Repodata *data, Id id, int create);
283 Id repodata_localize_id(Repodata *data, Id id, int create);
284 Id repodata_str2dir(Repodata *data, const char *dir, int create);
285 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
286 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
287 void repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file);
288 Id repodata_lookup_id_uninternalized(Repodata *data, Id solvid, Id keyname, Id voidid);
289
290 /* stats */
291 unsigned int repodata_memused(Repodata *data);
292
293 #endif /* LIBSOLV_REPODATA_H */