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