- move search position into pool
[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
22 #define SIZEOF_MD5      16
23 #define SIZEOF_SHA1     20
24 #define SIZEOF_SHA256   32
25
26 struct _Repo;
27 struct _Repokey;
28 struct _KeyValue;
29
30 typedef struct _Attrblobpage
31 {
32   /* mapped_at == -1  --> not loaded, otherwise offset into
33      store->blob_store.  The size of the mapping is BLOB_PAGESIZE
34      except for the last page.  */
35   unsigned int mapped_at;
36   long file_offset;
37   /* file_size == 0 means the page is not backed by some file storage.
38      Otherwise it is L*2+(compressed ? 1 : 0), with L being the data
39      length.  */
40   long file_size;
41 } Attrblobpage;
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   int state;                    /* available, stub or error */
51
52   void (*loadcallback)(struct _Repodata *);
53
54   int start;                    /* start of solvables this repodata is valid for */
55   int end;                      /* last solvable + 1 of this repodata */
56
57   FILE *fp;                     /* file pointer of solv file */
58   int error;                    /* corrupt solv file */
59
60
61   struct _Repokey *keys;        /* keys, first entry is always zero */
62   unsigned int nkeys;           /* length of keys array */
63   unsigned char keybits[32];    /* keyname hash */
64
65   Id *schemata;                 /* schema -> offset into schemadata */
66   unsigned int nschemata;       /* number of schemata */
67   Id *schemadata;               /* schema storage */
68   unsigned int schemadatalen;   /* schema storage size */
69   Id *schematahash;             /* unification helper */
70
71   Stringpool spool;             /* local string pool */
72   int localpool;                /* is local string pool used */
73
74   Dirpool dirpool;              /* local dir pool */
75
76   Id mainschema;
77   Id *mainschemaoffsets;
78
79   unsigned char *incoredata;    /* in-core data (flat_attrs) */
80   unsigned int incoredatalen;   /* data len (attr_next_free) */
81   unsigned int incoredatafree;  /* free data len */
82
83   Id *incoreoffset;             /* offset for all entries (ent2attr) */
84
85   Id *verticaloffset;           /* offset for all verticals, nkeys elements */
86   Id lastverticaloffset;        /* end of verticals */
87
88   int pagefd;                   /* file descriptor of page file */
89   unsigned char *blob_store;
90   Attrblobpage *pages;
91   unsigned int num_pages;
92
93   /* mapped[i] is zero if nothing is mapped at logical page I,
94      otherwise it contains the pagenumber plus one (of the mapped page).  */
95   unsigned int *mapped;
96   unsigned int nmapped, ncanmap;
97   unsigned int rr_counter;
98
99   unsigned char *vincore;       
100   unsigned int vincorelen;
101
102   Id **attrs;                   /* un-internalized attributes */
103   Id **xattrs;                  /* anonymous handles */
104   int nxattrs;
105
106   unsigned char *attrdata;      /* their string data space */
107   unsigned int attrdatalen;
108   Id *attriddata;               /* their id space */
109   unsigned int attriddatalen;
110
111   /* array cache */
112   Id lasthandle;
113   Id lastkey;
114   Id lastdatalen;
115
116 } Repodata;
117
118 #define REPOENTRY_META          -1
119 #define REPOENTRY_POS           -2
120 #define REPOENTRY_SUBSCHEMA     -3              /* internal! */
121
122 /*-----
123  * management functions
124  */
125 void repodata_init(Repodata *data, struct _Repo *repo, int localpool);
126 void repodata_extend(Repodata *data, Id p);
127 void repodata_extend_block(Repodata *data, Id p, int num);
128 void repodata_free(Repodata *data);
129
130 /* internalize repodata into .solv, required before writing out a .solv file */
131 void repodata_internalize(Repodata *data);
132
133 Id repodata_key2id(Repodata *data, struct _Repokey *key, int create);
134 Id repodata_schema2id(Repodata *data, Id *schema, int create);
135
136 static inline int
137 repodata_precheck_keyname(Repodata *data, Id keyname)
138 {
139   unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
140   return x && (x & (1 << (keyname & 7))) ? 1 : 0;
141 }
142
143 /*----
144  * access functions
145  */
146
147 /* Search key <keyname> (all keys, if keyname == 0) for Id <entry>
148  * <entry> is _relative_ Id for <data>
149  * Call <callback> for each match
150  */
151 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);
152
153 /* lookup functions */
154 Id repodata_lookup_id(Repodata *data, Id entry, Id keyname);
155 const char *repodata_lookup_str(Repodata *data, Id entry, Id keyname);
156 int repodata_lookup_num(Repodata *data, Id entry, Id keyname, unsigned int *value);
157 int repodata_lookup_void(Repodata *data, Id entry, Id keyname);
158 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id entry, Id keyname, Id *typep);
159
160
161 /*-----
162  * data assignment functions
163  */
164
165 /* create an anonymous handle. useful for substructures like
166  * fixarray/flexarray  */
167 Id repodata_new_handle(Repodata *data);
168
169 /* basic types: void, num, string, Id */
170
171 void repodata_set_void(Repodata *data, Id handle, Id keyname);
172 void repodata_set_num(Repodata *data, Id handle, Id keyname, unsigned int num);
173 void repodata_set_str(Repodata *data, Id handle, Id keyname, const char *str);
174 void repodata_set_id(Repodata *data, Id handle, Id keyname, Id id);
175
176 /*  */
177
178 void repodata_set_poolstr(Repodata *data, Id handle, Id keyname, const char *str);
179
180 /* set numeric constant */
181 void repodata_set_constant(Repodata *data, Id handle, Id keyname, unsigned int constant);
182
183 /* set Id constant */
184 void repodata_set_constantid(Repodata *data, Id handle, Id keyname, Id id);
185
186 /* checksum */
187 void repodata_set_bin_checksum(Repodata *data, Id handle, Id keyname, Id type,
188                                const unsigned char *buf);
189 void repodata_set_checksum(Repodata *data, Id handle, Id keyname, Id type,
190                            const char *str);
191
192 /* directory (for package file list) */
193 void repodata_add_dirnumnum(Repodata *data, Id handle, Id keyname, Id dir, Id num, Id num2);
194 void repodata_add_dirstr(Repodata *data, Id handle, Id keyname, Id dir, const char *str);
195
196
197 /* Arrays */
198 void repodata_add_idarray(Repodata *data, Id handle, Id keyname, Id id);
199 void repodata_add_poolstr_array(Repodata *data, Id handle, Id keyname, const char *str);
200 void repodata_add_fixarray(Repodata *data, Id handle, Id keyname, Id ghandle);
201 void repodata_add_flexarray(Repodata *data, Id handle, Id keyname, Id ghandle);
202
203
204 /*-----
205  * data management
206  */
207
208 /* 
209  merge attributes fro one solvable to another
210  works only if the data is not yet internalized
211 */
212 void repodata_merge_attrs (Repodata *data, Id dest, Id src);
213
214 /* */
215 void repodata_disable_paging(Repodata *data);
216
217 /* helper functions */
218 Id repodata_globalize_id(Repodata *data, Id id);
219 Id repodata_str2dir(Repodata *data, const char *dir, int create);
220 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
221 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
222
223 #endif /* SATSOLVER_REPODATA_H */