repodata.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007, Novell Inc.
00003  *
00004  * This program is licensed under the BSD license, read LICENSE.BSD
00005  * for further information
00006  */
00007 
00008 /*
00009  * repodata.h
00010  * 
00011  */
00012 
00013 #ifndef SATSOLVER_REPODATA_H
00014 #define SATSOLVER_REPODATA_H
00015 
00016 #include <stdio.h> 
00017 
00018 #include "pooltypes.h"
00019 #include "pool.h"
00020 #include "dirpool.h"
00021 #include "repopage.h"
00022 
00023 #define SIZEOF_MD5      16
00024 #define SIZEOF_SHA1     20
00025 #define SIZEOF_SHA256   32
00026 
00027 struct _Repo;
00028 struct _KeyValue;
00029 
00030 typedef struct _Repokey {
00031   Id name;
00032   Id type;               /* REPOKEY_TYPE_xxx */
00033   unsigned int size;
00034   unsigned int storage; /* KEY_STORAGE_xxx */
00035 } Repokey;
00036 
00037 #define KEY_STORAGE_DROPPED             0
00038 #define KEY_STORAGE_SOLVABLE            1
00039 #define KEY_STORAGE_INCORE              2
00040 #define KEY_STORAGE_VERTICAL_OFFSET     3
00041 
00042 
00043 typedef struct _Repodata {
00044   struct _Repo *repo;           /* back pointer to repo */
00045 
00046 #define REPODATA_AVAILABLE      0
00047 #define REPODATA_STUB           1
00048 #define REPODATA_ERROR          2
00049 #define REPODATA_STORE          3
00050 #define REPODATA_LOADING        4
00051 
00052   int state;                    /* available, stub or error */
00053 
00054   void (*loadcallback)(struct _Repodata *);
00055 
00056   int start;                    /* start of solvables this repodata is valid for */
00057   int end;                      /* last solvable + 1 of this repodata */
00058 
00059   FILE *fp;                     /* file pointer of solv file */
00060   int error;                    /* corrupt solv file */
00061 
00062   Repokey *keys;                /* keys, first entry is always zero */
00063   unsigned int nkeys;           /* length of keys array */
00064   unsigned char keybits[32];    /* keyname hash */
00065 
00066   Id *schemata;                 /* schema -> offset into schemadata */
00067   unsigned int nschemata;       /* number of schemata */
00068   Id *schemadata;               /* schema storage */
00069   unsigned int schemadatalen;   /* schema storage size */
00070   Id *schematahash;             /* unification helper */
00071 
00072   Stringpool spool;             /* local string pool */
00073   int localpool;                /* is local string pool used */
00074 
00075   Dirpool dirpool;              /* local dir pool */
00076 
00077   unsigned char *incoredata;    /* in-core data */
00078   unsigned int incoredatalen;   /* in-core data used */
00079   unsigned int incoredatafree;  /* free data len */
00080 
00081   Id mainschema;                /* SOLVID_META schema */
00082   Id *mainschemaoffsets;        /* SOLVID_META offsets into incoredata */
00083 
00084   Id *incoreoffset;             /* offset for all entries */
00085 
00086   Id *verticaloffset;           /* offset for all verticals, nkeys elements */
00087   Id lastverticaloffset;        /* end of verticals */
00088 
00089   Repopagestore store;          /* our page store */
00090 
00091   unsigned char *vincore;       /* internal vertical data */
00092   unsigned int vincorelen;      /* data size */
00093 
00094   Id **attrs;                   /* un-internalized attributes */
00095   Id **xattrs;                  /* anonymous handles */
00096   int nxattrs;                  /* number of handles */
00097 
00098   unsigned char *attrdata;      /* their string data space */
00099   unsigned int attrdatalen;     /* its len */
00100   Id *attriddata;               /* their id space */
00101   unsigned int attriddatalen;   /* its len */
00102 
00103   /* array cache to speed up repodata_add functions*/
00104   Id lasthandle;
00105   Id lastkey;
00106   Id lastdatalen;
00107 
00108 } Repodata;
00109 
00110 #define SOLVID_META             -1
00111 #define SOLVID_POS              -2
00112 #define SOLVID_SUBSCHEMA        -3              /* internal! */
00113 
00114 
00115 /*-----
00116  * management functions
00117  */
00118 void repodata_initdata(Repodata *data, struct _Repo *repo, int localpool);
00119 void repodata_freedata(Repodata *data);
00120 
00121 Repodata *repodata_create(struct _Repo *repo, int localpool);
00122 void repodata_free(Repodata *data);
00123 void repodata_empty(Repodata *data, int localpool);
00124 
00125 
00126 /*
00127  * key management functions
00128  */
00129 Id repodata_key2id(Repodata *data, Repokey *key, int create);
00130 
00131 static inline Repokey *
00132 repodata_id2key(Repodata *data, Id keyid)
00133 {
00134   return data->keys + keyid;
00135 }
00136 
00137 /*
00138  * schema management functions
00139  */
00140 Id repodata_schema2id(Repodata *data, Id *schema, int create);
00141 void repodata_free_schemahash(Repodata *data);
00142 
00143 static inline Id *
00144 repodata_id2schema(Repodata *data, Id schemaid)
00145 {
00146   return data->schemadata + data->schemata[schemaid];
00147 }
00148 
00149 /*
00150  * data search and access
00151  */
00152 
00153 /* check if there is a chance that the repodata contains data for
00154  * the specified keyname */
00155 static inline int
00156 repodata_precheck_keyname(Repodata *data, Id keyname)
00157 {
00158   unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
00159   return x && (x & (1 << (keyname & 7))) ? 1 : 0;
00160 }
00161 
00162 /* check if the repodata contains data for the specified keyname */
00163 static inline int
00164 repodata_has_keyname(Repodata *data, Id keyname)
00165 {
00166   int i;
00167   if (!repodata_precheck_keyname(data, keyname))
00168     return 0;
00169   for (i = 1; i < data->nkeys; i++)
00170     if (data->keys[i].name == keyname)
00171       return 1;
00172   return 0;
00173 }
00174 
00175 /* search key <keyname> (all keys, if keyname == 0) for Id <solvid>
00176  * Call <callback> for each match */
00177 void repodata_search(Repodata *data, Id solvid, Id keyname, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct _KeyValue *kv), void *cbdata);
00178 
00179 /* Make sure the found KeyValue has the "str" field set. Return false
00180  * if not possible */
00181 int repodata_stringify(Pool *pool, Repodata *data, Repokey *key, struct _KeyValue *kv, int flags);
00182 
00183 int repodata_filelistfilter_matches(Repodata *data, const char *str);
00184 
00185 
00186 /* lookup functions */
00187 Id repodata_lookup_type(Repodata *data, Id solvid, Id keyname);
00188 Id repodata_lookup_id(Repodata *data, Id solvid, Id keyname);
00189 const char *repodata_lookup_str(Repodata *data, Id solvid, Id keyname);
00190 int repodata_lookup_num(Repodata *data, Id solvid, Id keyname, unsigned int *value);
00191 int repodata_lookup_void(Repodata *data, Id solvid, Id keyname);
00192 const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep);
00193 int repodata_lookup_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
00194 
00195 
00196 /*-----
00197  * data assignment functions
00198  */
00199 
00200 /*
00201  * extend the data so that it contains the specified solvables
00202  * (no longer needed, as the repodata_set functions autoextend)
00203  */
00204 void repodata_extend(Repodata *data, Id p);
00205 void repodata_extend_block(Repodata *data, Id p, int num);
00206 void repodata_shrink(Repodata *data, int end);
00207 
00208 /* internalize freshly set data, so that it is found by the search
00209  * functions and written out */
00210 void repodata_internalize(Repodata *data);
00211 
00212 /* create an anonymous handle. useful for substructures like
00213  * fixarray/flexarray  */
00214 Id repodata_new_handle(Repodata *data);
00215 
00216 /* basic types: void, num, string, Id */
00217 void repodata_set_void(Repodata *data, Id solvid, Id keyname);
00218 void repodata_set_num(Repodata *data, Id solvid, Id keyname, unsigned int num);
00219 void repodata_set_id(Repodata *data, Id solvid, Id keyname, Id id);
00220 void repodata_set_str(Repodata *data, Id solvid, Id keyname, const char *str);
00221 void repodata_set_binary(Repodata *data, Id solvid, Id keyname, void *buf, int len);
00222 /* create id from string, then set_id */
00223 void repodata_set_poolstr(Repodata *data, Id solvid, Id keyname, const char *str);
00224 
00225 /* set numeric constant */
00226 void repodata_set_constant(Repodata *data, Id solvid, Id keyname, unsigned int constant);
00227 
00228 /* set Id constant */
00229 void repodata_set_constantid(Repodata *data, Id solvid, Id keyname, Id id);
00230 
00231 /* checksum */
00232 void repodata_set_bin_checksum(Repodata *data, Id solvid, Id keyname, Id type,
00233                                const unsigned char *buf);
00234 void repodata_set_checksum(Repodata *data, Id solvid, Id keyname, Id type,
00235                            const char *str);
00236 void repodata_set_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
00237 
00238 
00239 /* directory (for package file list) */
00240 void repodata_add_dirnumnum(Repodata *data, Id solvid, Id keyname, Id dir, Id num, Id num2);
00241 void repodata_add_dirstr(Repodata *data, Id solvid, Id keyname, Id dir, const char *str);
00242 
00243 
00244 /* Arrays */
00245 void repodata_add_idarray(Repodata *data, Id solvid, Id keyname, Id id);
00246 void repodata_add_poolstr_array(Repodata *data, Id solvid, Id keyname, const char *str);
00247 void repodata_add_fixarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
00248 void repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
00249 
00250 void repodata_delete(Repodata *data, Id solvid, Id keyname);
00251 void repodata_delete_uninternalized(Repodata *data, Id solvid, Id keyname);
00252 
00253 /* 
00254  merge attributes from one solvable to another
00255  works only if the data is not yet internalized
00256 */
00257 void repodata_merge_attrs(Repodata *data, Id dest, Id src);
00258 void repodata_merge_some_attrs(Repodata *data, Id dest, Id src, Map *keyidmap, int overwrite);
00259 
00260 void repodata_create_stubs(Repodata *data);
00261 void repodata_join(Repodata *data, Id joinkey);
00262 
00263 /*
00264  * load all paged data, used to speed up copying in repo_rpmdb
00265  */
00266 void repodata_disable_paging(Repodata *data);
00267 
00268 /* helper functions */
00269 Id repodata_globalize_id(Repodata *data, Id id, int create);
00270 Id repodata_localize_id(Repodata *data, Id id, int create);
00271 Id repodata_str2dir(Repodata *data, const char *dir, int create);
00272 const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
00273 const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
00274 void repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file);
00275 
00276 #endif /* SATSOLVER_REPODATA_H */

Generated on Mon Dec 15 17:56:24 2014 for satsolver by  doxygen 1.5.6