e58103557f3f976d6da2b8d2e28cb7961f66b7bd
[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
25 struct _Repo;
26 struct _Repokey;
27 struct _KeyValue;
28
29 typedef struct _Attrblobpage
30 {
31   /* mapped_at == -1  --> not loaded, otherwise offset into
32      store->blob_store.  The size of the mapping is BLOB_PAGESIZE
33      except for the last page.  */
34   unsigned int mapped_at;
35   long file_offset;
36   /* file_size == 0 means the page is not backed by some file storage.
37      Otherwise it is L*2+(compressed ? 1 : 0), with L being the data
38      length.  */
39   long file_size;
40 } Attrblobpage;
41
42 typedef struct _Repodata {
43   struct _Repo *repo;           /* back pointer to repo */
44
45 #define REPODATA_AVAILABLE      0
46 #define REPODATA_STUB           1
47 #define REPODATA_ERROR          2
48 #define REPODATA_STORE          3
49   int state;                    /* available, stub or error */
50
51   void (*loadcallback)(struct _Repodata *);
52   char *location;               /* E.g. filename or the like */
53   char *checksum;               /* Checksum of the file */
54   unsigned nchecksum;           /* Length of the checksum */
55   unsigned checksumtype;        /* Type of checksum */
56
57   int start;                    /* start of solvables this repodata is valid for */
58   int end;                      /* last solvable + 1 of this repodata */
59
60   FILE *fp;                     /* file pointer of solv file */
61   int error;                    /* corrupt solv file */
62
63
64   struct _Repokey *keys;        /* keys, first entry is always zero */
65   unsigned int nkeys;           /* length of keys array */
66
67   Id *schemata;                 /* schema -> offset into schemadata */
68   unsigned int nschemata;       /* number of schemata */
69
70   Id *schemadata;               /* schema storage */
71   unsigned int schemadatalen;   /* schema storage size */
72
73   Stringpool spool;             /* local string pool */
74   int localpool;                /* is local string pool used */
75
76   Dirpool dirpool;              /* local dir pool */
77
78   unsigned char *incoredata;    /* in-core data (flat_attrs) */
79   unsigned int incoredatalen;   /* data len (attr_next_free) */
80   unsigned int incoredatafree;  /* free data len */
81
82   Id *incoreoffset;             /* offset for all entries (ent2attr) */
83
84   Id *verticaloffset;           /* offset for all verticals, nkeys elements */
85   Id lastverticaloffset;        /* end of verticals */
86
87   int pagefd;                   /* file descriptor of page file */
88   unsigned char *blob_store;
89   Attrblobpage *pages;
90   unsigned int num_pages;
91
92   /* mapped[i] is zero if nothing is mapped at logical page I,
93      otherwise it contains the pagenumber plus one (of the mapped page).  */
94   unsigned int *mapped;
95   unsigned int nmapped, ncanmap;
96   unsigned int rr_counter;
97
98   unsigned char *vincore;       
99   unsigned int vincorelen;
100
101   Id **attrs;                   /* un-internalized attributes */
102   unsigned char *attrdata;      /* their string data space */
103   unsigned int attrdatalen;
104   Id *attriddata;               /* their id space */
105   unsigned int attriddatalen;
106
107   Id *addedfileprovides;
108 } Repodata;
109
110 /* Search key <keyname> (all keys, if keyname == 0) for Id <entry>
111  * <entry> is _relative_ Id for <data>
112  * Call <callback> for each match
113  */
114 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);
115
116 /*
117  * lookup string type attribute
118  */
119 const char *repodata_lookup_str(Repodata *data, Id entry, Id keyid);
120
121 /*
122  * lookup integer type attribute
123  */
124 int repodata_lookup_num(Repodata *data, Id entry, Id keyid, unsigned *value);
125 int repodata_lookup_void(Repodata *data, Id entry, Id keyid);
126
127 void repodata_init(Repodata *data, struct _Repo *repo, int localpool);
128 void repodata_extend(Repodata *data, Id p);
129 void repodata_extend_block(Repodata *data, Id p, int num);
130 void repodata_free(Repodata *data);
131
132 void repodata_set_id(Repodata *data, Id entry, Id keyname, Id id);
133 void repodata_set_num(Repodata *data, Id entry, Id keyname, Id num);
134 void repodata_set_poolstr(Repodata *data, Id entry, Id keyname, const char *str);
135 void repodata_set_constant(Repodata *data, Id entry, Id keyname, Id constant);
136 void repodata_set_constantid(Repodata *data, Id entry, Id keyname, Id id);
137 void repodata_set_void(Repodata *data, Id entry, Id keyname);
138 void repodata_set_str(Repodata *data, Id entry, Id keyname, const char *str);
139 void repodata_set_bin_checksum(Repodata *data, Id entry, Id keyname, Id type,
140                                const unsigned char *buf);
141 void repodata_set_checksum(Repodata *data, Id entry, Id keyname, Id type,
142                            const char *str);
143 void repodata_add_dirnumnum(Repodata *data, Id entry, Id keyname, Id dir, Id num, Id num2);
144 void repodata_add_dirstr(Repodata *data, Id entry, Id keyname, Id dir, const char *str);
145 void repodata_add_idarray(Repodata *data, Id entry, Id keyname, Id id);
146 void repodata_add_poolstr_array(Repodata *data, Id entry, Id keyname,
147                                 const char *str);
148 void repodata_merge_attrs (Repodata *data, Id dest, Id src);
149
150 void repodata_internalize(Repodata *data);
151 void repodata_disable_paging(Repodata *data);
152
153 Id repodata_str2dir(Repodata *data, const char *dir, int create);
154 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
155 const char *repodata_chk2str(Repodata *data, Id type, const char *buf);
156
157 unsigned int repodata_compress_page(unsigned char *, unsigned int, unsigned char *, unsigned int);
158 void repodata_read_or_setup_pages(Repodata *data, unsigned int pagesz, unsigned int blobsz);
159
160 #endif /* SATSOLVER_REPODATA_H */