- more cleanups:
[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 _Repokey;
29 struct _KeyValue;
30
31 typedef struct _Repodata {
32   struct _Repo *repo;           /* back pointer to repo */
33
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 */
39
40   void (*loadcallback)(struct _Repodata *);
41
42   int start;                    /* start of solvables this repodata is valid for */
43   int end;                      /* last solvable + 1 of this repodata */
44
45   FILE *fp;                     /* file pointer of solv file */
46   int error;                    /* corrupt solv file */
47
48
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 */
52
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 */
58
59   Stringpool spool;             /* local string pool */
60   int localpool;                /* is local string pool used */
61
62   Dirpool dirpool;              /* local dir pool */
63
64   Id mainschema;
65   Id *mainschemaoffsets;
66
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 */
70
71   Id *incoreoffset;             /* offset for all entries (ent2attr) */
72
73   Id *verticaloffset;           /* offset for all verticals, nkeys elements */
74   Id lastverticaloffset;        /* end of verticals */
75
76   Repopagestore store;          /* our page store */
77
78   unsigned char *vincore;       
79   unsigned int vincorelen;
80
81   Id **attrs;                   /* un-internalized attributes */
82   Id **xattrs;                  /* anonymous handles */
83   int nxattrs;
84
85   unsigned char *attrdata;      /* their string data space */
86   unsigned int attrdatalen;
87   Id *attriddata;               /* their id space */
88   unsigned int attriddatalen;
89
90   /* array cache */
91   Id lasthandle;
92   Id lastkey;
93   Id lastdatalen;
94
95 } Repodata;
96
97 #define SOLVID_META             -1
98 #define SOLVID_POS              -2
99 #define SOLVID_SUBSCHEMA        -3              /* internal! */
100
101 /*-----
102  * management functions
103  */
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);
108
109 /* internalize repodata into .solv, required before writing out a .solv file */
110 void repodata_internalize(Repodata *data);
111
112 Id repodata_key2id(Repodata *data, struct _Repokey *key, int create);
113 Id repodata_schema2id(Repodata *data, Id *schema, int create);
114
115 static inline int
116 repodata_precheck_keyname(Repodata *data, Id keyname)
117 {
118   unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
119   return x && (x & (1 << (keyname & 7))) ? 1 : 0;
120 }
121
122 /*----
123  * access functions
124  */
125
126 /* Search key <keyname> (all keys, if keyname == 0) for Id <solvid>
127  * Call <callback> for each match
128  */
129 void repodata_search(Repodata *data, Id solvid, Id keyname, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata);
130 int repodata_stringify(Pool *pool, Repodata *data, struct _Repokey *key, struct _KeyValue *kv, int flags);
131
132
133 /* lookup functions */
134 Id repodata_lookup_id(Repodata *data, Id solvid, Id keyname);
135 const char *repodata_lookup_str(Repodata *data, Id solvid, Id keyname);
136 int repodata_lookup_num(Repodata *data, Id solvid, Id keyname, unsigned int *value);
137 int repodata_lookup_void(Repodata *data, Id solvid, Id keyname);
138 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep);
139
140
141 /*-----
142  * data assignment functions
143  */
144
145 /* create an anonymous handle. useful for substructures like
146  * fixarray/flexarray  */
147 Id repodata_new_handle(Repodata *data);
148
149 /* basic types: void, num, string, Id */
150
151 void repodata_set_void(Repodata *data, Id solvid, Id keyname);
152 void repodata_set_num(Repodata *data, Id solvid, Id keyname, unsigned int num);
153 void repodata_set_str(Repodata *data, Id solvid, Id keyname, const char *str);
154 void repodata_set_id(Repodata *data, Id solvid, Id keyname, Id id);
155
156 /*  */
157
158 void repodata_set_poolstr(Repodata *data, Id solvid, Id keyname, const char *str);
159
160 /* set numeric constant */
161 void repodata_set_constant(Repodata *data, Id solvid, Id keyname, unsigned int constant);
162
163 /* set Id constant */
164 void repodata_set_constantid(Repodata *data, Id solvid, Id keyname, Id id);
165
166 /* checksum */
167 void repodata_set_bin_checksum(Repodata *data, Id solvid, Id keyname, Id type,
168                                const unsigned char *buf);
169 void repodata_set_checksum(Repodata *data, Id solvid, Id keyname, Id type,
170                            const char *str);
171
172 /* directory (for package file list) */
173 void repodata_add_dirnumnum(Repodata *data, Id solvid, Id keyname, Id dir, Id num, Id num2);
174 void repodata_add_dirstr(Repodata *data, Id solvid, Id keyname, Id dir, const char *str);
175
176
177 /* Arrays */
178 void repodata_add_idarray(Repodata *data, Id solvid, Id keyname, Id id);
179 void repodata_add_poolstr_array(Repodata *data, Id solvid, Id keyname, const char *str);
180 void repodata_add_fixarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
181 void repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
182
183
184 /*-----
185  * data management
186  */
187
188 /* 
189  merge attributes fro one solvable to another
190  works only if the data is not yet internalized
191 */
192 void repodata_merge_attrs (Repodata *data, Id dest, Id src);
193
194 /* */
195 void repodata_disable_paging(Repodata *data);
196
197 /* helper functions */
198 Id repodata_globalize_id(Repodata *data, Id id);
199 Id repodata_str2dir(Repodata *data, const char *dir, int create);
200 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
201 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
202
203 #endif /* SATSOLVER_REPODATA_H */