adapt repo_content to create one product per base arch, attributes not working yet
[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   char *location;               /* E.g. filename or the like */
54   char *checksum;               /* Checksum of the file */
55   unsigned nchecksum;           /* Length of the checksum */
56   unsigned checksumtype;        /* Type of checksum */
57
58   int start;                    /* start of solvables this repodata is valid for */
59   int end;                      /* last solvable + 1 of this repodata */
60   int extrastart;
61   int nextra;
62
63   FILE *fp;                     /* file pointer of solv file */
64   int error;                    /* corrupt solv file */
65
66
67   struct _Repokey *keys;        /* keys, first entry is always zero */
68   unsigned int nkeys;           /* length of keys array */
69
70   Id *schemata;                 /* schema -> offset into schemadata */
71   unsigned int nschemata;       /* number of schemata */
72
73   Id *schemadata;               /* schema storage */
74   unsigned int schemadatalen;   /* schema storage size */
75
76   Stringpool spool;             /* local string pool */
77   int localpool;                /* is local string pool used */
78
79   Dirpool dirpool;              /* local dir pool */
80
81   unsigned char *incoredata;    /* in-core data (flat_attrs) */
82   unsigned int incoredatalen;   /* data len (attr_next_free) */
83   unsigned int incoredatafree;  /* free data len */
84
85   Id *incoreoffset;             /* offset for all entries (ent2attr) */
86   Id *extraoffset;              /* offset for all extra entries */
87
88   Id *verticaloffset;           /* offset for all verticals, nkeys elements */
89   Id lastverticaloffset;        /* end of verticals */
90
91   int pagefd;                   /* file descriptor of page file */
92   unsigned char *blob_store;
93   Attrblobpage *pages;
94   unsigned int num_pages;
95
96   /* mapped[i] is zero if nothing is mapped at logical page I,
97      otherwise it contains the pagenumber plus one (of the mapped page).  */
98   unsigned int *mapped;
99   unsigned int nmapped, ncanmap;
100   unsigned int rr_counter;
101
102   unsigned char *vincore;       
103   unsigned int vincorelen;
104
105   Id *attrs;                    /* un-internalized attributes */
106   Id *extraattrs;               /* Same, but for extra objects.  */
107   unsigned char *attrdata;      /* their string data space */
108   unsigned int attrdatalen;
109   Id *attriddata;               /* their id space */
110   unsigned int attriddatalen;
111   Id **structs;                 /* key-value lists */
112   unsigned int nstructs;
113
114   /* array cache */
115   Id lasthandle;
116   Id lastkey;
117   Id lastdatalen;
118
119   Id *addedfileprovides;
120 } Repodata;
121
122
123 /*-----
124  * management functions
125  */
126 void repodata_init(Repodata *data, struct _Repo *repo, int localpool);
127 void repodata_extend(Repodata *data, Id p);
128 void repodata_extend_extra(Repodata *data, int nextra);
129 void repodata_extend_block(Repodata *data, Id p, int num);
130 void repodata_free(Repodata *data);
131
132 /* internalize repodata into .solv, required before writing out a .solv file */
133 void repodata_internalize(Repodata *data);
134
135
136 /*----
137  * access functions
138  */
139
140 /* Search key <keyname> (all keys, if keyname == 0) for Id <entry>
141  * <entry> is _relative_ Id for <data>
142  * Call <callback> for each match
143  */
144 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);
145
146 /* lookup functions */
147 Id repodata_lookup_id(Repodata *data, Id entry, Id keyid);
148 const char *repodata_lookup_str(Repodata *data, Id entry, Id keyid);
149 int repodata_lookup_num(Repodata *data, Id entry, Id keyid, unsigned int *value);
150 int repodata_lookup_void(Repodata *data, Id entry, Id keyid);
151 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id entry, Id keyid, Id *typep);
152
153
154 /*-----
155  * data assignment functions
156  */
157
158 /* Returns a handle for the attributes of ENTRY.  ENTRY >= 0
159    corresponds to data associated with a solvable, ENTRY < 0 is
160    extra data.  The returned handle is used in the various repodata_set_*
161    functions to add attributes to it.  */
162 Id repodata_get_handle(Repodata *data, Id entry);
163
164 /* basic types: void, num, string, Id */
165
166 void repodata_set_void(Repodata *data, Id handle, Id keyname);
167 void repodata_set_num(Repodata *data, Id handle, Id keyname, unsigned int num);
168 void repodata_set_str(Repodata *data, Id handle, Id keyname, const char *str);
169 void repodata_set_id(Repodata *data, Id handle, Id keyname, Id id);
170
171 /*  */
172
173 void repodata_set_poolstr(Repodata *data, Id handle, Id keyname, const char *str);
174
175 /* set numeric constant */
176 void repodata_set_constant(Repodata *data, Id handle, Id keyname, unsigned int constant);
177
178 /* set Id constant */
179 void repodata_set_constantid(Repodata *data, Id handle, Id keyname, Id id);
180
181 /* checksum */
182 void repodata_set_bin_checksum(Repodata *data, Id handle, Id keyname, Id type,
183                                const unsigned char *buf);
184 void repodata_set_checksum(Repodata *data, Id handle, Id keyname, Id type,
185                            const char *str);
186
187 /* directory (for package file list) */
188 void repodata_add_dirnumnum(Repodata *data, Id handle, Id keyname, Id dir, Id num, Id num2);
189 void repodata_add_dirstr(Repodata *data, Id handle, Id keyname, Id dir, const char *str);
190
191
192 /* Arrays */
193 void repodata_add_idarray(Repodata *data, Id handle, Id keyname, Id id);
194 void repodata_add_poolstr_array(Repodata *data, Id handle, Id keyname,
195                                 const char *str);
196 /* Creates a new substructure.  Returns a handle for it (usable with the
197    other repodata_{set,add}_* functions.  */
198 Id repodata_create_struct(Repodata *data, Id handle, Id keyname);
199
200 /*-----
201  * data management
202  */
203
204 /* 
205  merge attributes fro one solvable to another
206  works only if the data is not yet internalized
207 */
208 void repodata_merge_attrs (Repodata *data, Id dest, Id src);
209
210 /* */
211 void repodata_disable_paging(Repodata *data);
212
213 /* helper functions */
214 Id repodata_globalize_id(Repodata *data, Id id);
215 Id repodata_str2dir(Repodata *data, const char *dir, int create);
216 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
217 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
218
219 /* internal */
220 unsigned int repodata_compress_page(unsigned char *, unsigned int, unsigned char *, unsigned int);
221 void repodata_read_or_setup_pages(Repodata *data, unsigned int pagesz, unsigned int blobsz);
222
223 #endif /* SATSOLVER_REPODATA_H */