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