2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef SATSOLVER_REPODATA_H
14 #define SATSOLVER_REPODATA_H
18 #include "pooltypes.h"
24 #define SIZEOF_SHA1 20
25 #define SIZEOF_SHA256 32
31 typedef struct _Repodata {
32 struct _Repo *repo; /* back pointer to repo */
34 #define REPODATA_AVAILABLE 0
35 #define REPODATA_STUB 1
36 #define REPODATA_ERROR 2
37 #define REPODATA_STORE 3
38 int state; /* available, stub or error */
40 void (*loadcallback)(struct _Repodata *);
42 int start; /* start of solvables this repodata is valid for */
43 int end; /* last solvable + 1 of this repodata */
45 FILE *fp; /* file pointer of solv file */
46 int error; /* corrupt solv file */
49 struct _Repokey *keys; /* keys, first entry is always zero */
50 unsigned int nkeys; /* length of keys array */
51 unsigned char keybits[32]; /* keyname hash */
53 Id *schemata; /* schema -> offset into schemadata */
54 unsigned int nschemata; /* number of schemata */
55 Id *schemadata; /* schema storage */
56 unsigned int schemadatalen; /* schema storage size */
57 Id *schematahash; /* unification helper */
59 Stringpool spool; /* local string pool */
60 int localpool; /* is local string pool used */
62 Dirpool dirpool; /* local dir pool */
65 Id *mainschemaoffsets;
67 unsigned char *incoredata; /* in-core data (flat_attrs) */
68 unsigned int incoredatalen; /* data len (attr_next_free) */
69 unsigned int incoredatafree; /* free data len */
71 Id *incoreoffset; /* offset for all entries (ent2attr) */
73 Id *verticaloffset; /* offset for all verticals, nkeys elements */
74 Id lastverticaloffset; /* end of verticals */
76 Repopagestore store; /* our page store */
78 unsigned char *vincore;
79 unsigned int vincorelen;
81 Id **attrs; /* un-internalized attributes */
82 Id **xattrs; /* anonymous handles */
85 unsigned char *attrdata; /* their string data space */
86 unsigned int attrdatalen;
87 Id *attriddata; /* their id space */
88 unsigned int attriddatalen;
97 #define REPOENTRY_META -1
98 #define REPOENTRY_POS -2
99 #define REPOENTRY_SUBSCHEMA -3 /* internal! */
102 * management functions
104 void repodata_init(Repodata *data, struct _Repo *repo, int localpool);
105 void repodata_extend(Repodata *data, Id p);
106 void repodata_extend_block(Repodata *data, Id p, int num);
107 void repodata_free(Repodata *data);
109 /* internalize repodata into .solv, required before writing out a .solv file */
110 void repodata_internalize(Repodata *data);
112 Id repodata_key2id(Repodata *data, struct _Repokey *key, int create);
113 Id repodata_schema2id(Repodata *data, Id *schema, int create);
116 repodata_precheck_keyname(Repodata *data, Id keyname)
118 unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
119 return x && (x & (1 << (keyname & 7))) ? 1 : 0;
126 /* Search key <keyname> (all keys, if keyname == 0) for Id <entry>
127 * <entry> is _relative_ Id for <data>
128 * Call <callback> for each match
130 void repodata_search(Repodata *data, Id entry, Id keyname, int (*callback)(void *cbdata, Solvable *s, Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata);
132 /* lookup functions */
133 Id repodata_lookup_id(Repodata *data, Id entry, Id keyname);
134 const char *repodata_lookup_str(Repodata *data, Id entry, Id keyname);
135 int repodata_lookup_num(Repodata *data, Id entry, Id keyname, unsigned int *value);
136 int repodata_lookup_void(Repodata *data, Id entry, Id keyname);
137 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id entry, Id keyname, Id *typep);
141 * data assignment functions
144 /* create an anonymous handle. useful for substructures like
145 * fixarray/flexarray */
146 Id repodata_new_handle(Repodata *data);
148 /* basic types: void, num, string, Id */
150 void repodata_set_void(Repodata *data, Id handle, Id keyname);
151 void repodata_set_num(Repodata *data, Id handle, Id keyname, unsigned int num);
152 void repodata_set_str(Repodata *data, Id handle, Id keyname, const char *str);
153 void repodata_set_id(Repodata *data, Id handle, Id keyname, Id id);
157 void repodata_set_poolstr(Repodata *data, Id handle, Id keyname, const char *str);
159 /* set numeric constant */
160 void repodata_set_constant(Repodata *data, Id handle, Id keyname, unsigned int constant);
162 /* set Id constant */
163 void repodata_set_constantid(Repodata *data, Id handle, Id keyname, Id id);
166 void repodata_set_bin_checksum(Repodata *data, Id handle, Id keyname, Id type,
167 const unsigned char *buf);
168 void repodata_set_checksum(Repodata *data, Id handle, Id keyname, Id type,
171 /* directory (for package file list) */
172 void repodata_add_dirnumnum(Repodata *data, Id handle, Id keyname, Id dir, Id num, Id num2);
173 void repodata_add_dirstr(Repodata *data, Id handle, Id keyname, Id dir, const char *str);
177 void repodata_add_idarray(Repodata *data, Id handle, Id keyname, Id id);
178 void repodata_add_poolstr_array(Repodata *data, Id handle, Id keyname, const char *str);
179 void repodata_add_fixarray(Repodata *data, Id handle, Id keyname, Id ghandle);
180 void repodata_add_flexarray(Repodata *data, Id handle, Id keyname, Id ghandle);
188 merge attributes fro one solvable to another
189 works only if the data is not yet internalized
191 void repodata_merge_attrs (Repodata *data, Id dest, Id src);
194 void repodata_disable_paging(Repodata *data);
196 /* helper functions */
197 Id repodata_globalize_id(Repodata *data, Id id);
198 Id repodata_str2dir(Repodata *data, const char *dir, int create);
199 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
200 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
202 #endif /* SATSOLVER_REPODATA_H */