repodata.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. * repodata.h
  9. *
  10. */
  11. #ifndef LIBSOLV_REPODATA_H
  12. #define LIBSOLV_REPODATA_H
  13. #include <stdio.h>
  14. #include "pooltypes.h"
  15. #include "pool.h"
  16. #include "dirpool.h"
  17. #ifdef LIBSOLV_INTERNAL
  18. #include "repopage.h"
  19. #endif
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #define SIZEOF_MD5 16
  24. #define SIZEOF_SHA1 20
  25. #define SIZEOF_SHA224 28
  26. #define SIZEOF_SHA256 32
  27. #define SIZEOF_SHA384 48
  28. #define SIZEOF_SHA512 64
  29. struct s_Repo;
  30. struct s_KeyValue;
  31. typedef struct s_Repokey {
  32. Id name;
  33. Id type; /* REPOKEY_TYPE_xxx */
  34. unsigned int size;
  35. unsigned int storage; /* KEY_STORAGE_xxx */
  36. } Repokey;
  37. #define KEY_STORAGE_DROPPED 0
  38. #define KEY_STORAGE_SOLVABLE 1
  39. #define KEY_STORAGE_INCORE 2
  40. #define KEY_STORAGE_VERTICAL_OFFSET 3
  41. #define KEY_STORAGE_IDARRAYBLOCK 4
  42. #ifdef LIBSOLV_INTERNAL
  43. struct dircache;
  44. #endif
  45. /* repodata states */
  46. #define REPODATA_AVAILABLE 0
  47. #define REPODATA_STUB 1
  48. #define REPODATA_ERROR 2
  49. #define REPODATA_STORE 3
  50. #define REPODATA_LOADING 4
  51. /* repodata filelist types */
  52. /* note that FILELIST_FILTERED means that the data contains a filtered
  53. * filelist *AND* that it is authoritative for all included solvables. */
  54. #define REPODATA_FILELIST_FILTERED 1
  55. #define REPODATA_FILELIST_EXTENSION 2
  56. typedef struct s_Repodata {
  57. Id repodataid; /* our id */
  58. struct s_Repo *repo; /* back pointer to repo */
  59. int state; /* available, stub or error */
  60. void (*loadcallback)(struct s_Repodata *);
  61. int start; /* start of solvables this repodata is valid for */
  62. int end; /* last solvable + 1 of this repodata */
  63. Repokey *keys; /* keys, first entry is always zero */
  64. int nkeys; /* length of keys array */
  65. unsigned char keybits[32]; /* keyname hash */
  66. Id *schemata; /* schema -> offset into schemadata */
  67. int nschemata; /* number of schemata */
  68. Id *schemadata; /* schema storage */
  69. Stringpool spool; /* local string pool */
  70. int localpool; /* is local string pool used */
  71. Dirpool dirpool; /* local dir pool */
  72. #ifdef LIBSOLV_INTERNAL
  73. FILE *fp; /* file pointer of solv file */
  74. int error; /* corrupt solv file */
  75. int filelisttype; /* type of filelist */
  76. Id *filelistfilter; /* filelist filter used */
  77. char *filelistfilterdata; /* filelist filter string space */
  78. unsigned int schemadatalen; /* schema storage size */
  79. Id *schematahash; /* unification helper */
  80. unsigned char *incoredata; /* in-core data */
  81. unsigned int incoredatalen; /* in-core data used */
  82. unsigned int incoredatafree; /* free data len */
  83. Id mainschema; /* SOLVID_META schema */
  84. Id *mainschemaoffsets; /* SOLVID_META offsets into incoredata */
  85. Id *incoreoffset; /* offset for all entries */
  86. Id *verticaloffset; /* offset for all verticals, nkeys elements */
  87. Id lastverticaloffset; /* end of verticals */
  88. Repopagestore store; /* our page store */
  89. Id storestate; /* incremented every time the store might change */
  90. unsigned char *vincore; /* internal vertical data */
  91. unsigned int vincorelen; /* data size */
  92. Id **attrs; /* un-internalized attributes */
  93. Id **xattrs; /* anonymous handles */
  94. int nxattrs; /* number of handles */
  95. unsigned char *attrdata; /* their string data space */
  96. unsigned int attrdatalen; /* its len */
  97. Id *attriddata; /* their id space */
  98. unsigned int attriddatalen; /* its len */
  99. unsigned long long *attrnum64data; /* their 64bit num data space */
  100. unsigned int attrnum64datalen; /* its len */
  101. /* array cache to speed up repodata_add functions*/
  102. Id lasthandle;
  103. Id lastkey;
  104. Id lastdatalen;
  105. /* directory cache to speed up repodata_str2dir */
  106. struct dircache *dircache;
  107. #endif
  108. } Repodata;
  109. #define SOLVID_META -1
  110. #define SOLVID_POS -2
  111. /*-----
  112. * management functions
  113. */
  114. void repodata_initdata(Repodata *data, struct s_Repo *repo, int localpool);
  115. void repodata_freedata(Repodata *data);
  116. void repodata_free(Repodata *data);
  117. void repodata_empty(Repodata *data, int localpool);
  118. void repodata_load(Repodata *data);
  119. /*
  120. * key management functions
  121. */
  122. Id repodata_key2id(Repodata *data, Repokey *key, int create);
  123. static inline Repokey *
  124. repodata_id2key(Repodata *data, Id keyid)
  125. {
  126. return data->keys + keyid;
  127. }
  128. /*
  129. * schema management functions
  130. */
  131. Id repodata_schema2id(Repodata *data, Id *schema, int create);
  132. void repodata_free_schemahash(Repodata *data);
  133. static inline Id *
  134. repodata_id2schema(Repodata *data, Id schemaid)
  135. {
  136. return data->schemadata + data->schemata[schemaid];
  137. }
  138. /*
  139. * data search and access
  140. */
  141. /* check if there is a chance that the repodata contains data for
  142. * the specified keyname */
  143. static inline int
  144. repodata_precheck_keyname(Repodata *data, Id keyname)
  145. {
  146. unsigned char x = data->keybits[(keyname >> 3) & (sizeof(data->keybits) - 1)];
  147. return x && (x & (1 << (keyname & 7))) ? 1 : 0;
  148. }
  149. /* check if the repodata contains data for the specified keyname */
  150. static inline int
  151. repodata_has_keyname(Repodata *data, Id keyname)
  152. {
  153. int i;
  154. if (!repodata_precheck_keyname(data, keyname))
  155. return 0;
  156. for (i = 1; i < data->nkeys; i++)
  157. if (data->keys[i].name == keyname)
  158. return 1;
  159. return 0;
  160. }
  161. /* search key <keyname> (all keys, if keyname == 0) for Id <solvid>
  162. * Call <callback> for each match */
  163. void repodata_search(Repodata *data, Id solvid, Id keyname, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct s_KeyValue *kv), void *cbdata);
  164. void repodata_search_keyskip(Repodata *data, Id solvid, Id keyname, int flags, Id *keyskip, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct s_KeyValue *kv), void *cbdata);
  165. void repodata_search_arrayelement(Repodata *data, Id solvid, Id keyname, int flags, struct s_KeyValue *kv, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct s_KeyValue *kv), void *cbdata);
  166. /* Make sure the found KeyValue has the "str" field set. Return "str"
  167. * if valid, NULL if not possible */
  168. const char *repodata_stringify(Pool *pool, Repodata *data, Repokey *key, struct s_KeyValue *kv, int flags);
  169. /* filelist filter support */
  170. void repodata_set_filelisttype(Repodata *data, int filelisttype);
  171. int repodata_filelistfilter_matches(Repodata *data, const char *str);
  172. void repodata_free_filelistfilter(Repodata *data);
  173. /* lookup functions */
  174. Id repodata_lookup_type(Repodata *data, Id solvid, Id keyname);
  175. Id repodata_lookup_id(Repodata *data, Id solvid, Id keyname);
  176. const char *repodata_lookup_str(Repodata *data, Id solvid, Id keyname);
  177. unsigned long long repodata_lookup_num(Repodata *data, Id solvid, Id keyname, unsigned long long notfound);
  178. int repodata_lookup_void(Repodata *data, Id solvid, Id keyname);
  179. const unsigned char *repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep);
  180. int repodata_lookup_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
  181. const void *repodata_lookup_binary(Repodata *data, Id solvid, Id keyname, int *lenp);
  182. unsigned int repodata_lookup_count(Repodata *data, Id solvid, Id keyname); /* internal */
  183. /* internal, used in fileprovides code */
  184. const unsigned char *repodata_lookup_packed_dirstrarray(Repodata *data, Id solvid, Id keyname);
  185. /* internal, fill keyskip array with data */
  186. Id *repodata_fill_keyskip(Repodata *data, Id solvid, Id *keyskip);
  187. /*-----
  188. * data assignment functions
  189. */
  190. /*
  191. * extend the data so that it contains the specified solvables
  192. * (no longer needed, as the repodata_set functions autoextend)
  193. */
  194. void repodata_extend(Repodata *data, Id p);
  195. void repodata_extend_block(Repodata *data, Id p, int num);
  196. void repodata_shrink(Repodata *data, int end);
  197. /* internalize freshly set data, so that it is found by the search
  198. * functions and written out */
  199. void repodata_internalize(Repodata *data);
  200. /* create an anonymous handle. useful for substructures like
  201. * fixarray/flexarray */
  202. Id repodata_new_handle(Repodata *data);
  203. /* basic types: void, num, string, Id */
  204. void repodata_set_void(Repodata *data, Id solvid, Id keyname);
  205. void repodata_set_num(Repodata *data, Id solvid, Id keyname, unsigned long long num);
  206. void repodata_set_id(Repodata *data, Id solvid, Id keyname, Id id);
  207. void repodata_set_str(Repodata *data, Id solvid, Id keyname, const char *str);
  208. void repodata_set_binary(Repodata *data, Id solvid, Id keyname, void *buf, int len);
  209. /* create id from string, then set_id */
  210. void repodata_set_poolstr(Repodata *data, Id solvid, Id keyname, const char *str);
  211. /* set numeric constant */
  212. void repodata_set_constant(Repodata *data, Id solvid, Id keyname, unsigned int constant);
  213. /* set Id constant */
  214. void repodata_set_constantid(Repodata *data, Id solvid, Id keyname, Id id);
  215. /* checksum */
  216. void repodata_set_bin_checksum(Repodata *data, Id solvid, Id keyname, Id type,
  217. const unsigned char *buf);
  218. void repodata_set_checksum(Repodata *data, Id solvid, Id keyname, Id type,
  219. const char *str);
  220. void repodata_set_idarray(Repodata *data, Id solvid, Id keyname, Queue *q);
  221. /* directory (for package file list) */
  222. void repodata_add_dirnumnum(Repodata *data, Id solvid, Id keyname, Id dir, Id num, Id num2);
  223. void repodata_add_dirstr(Repodata *data, Id solvid, Id keyname, Id dir, const char *str);
  224. void repodata_free_dircache(Repodata *data);
  225. /* arrays */
  226. void repodata_add_idarray(Repodata *data, Id solvid, Id keyname, Id id);
  227. void repodata_add_poolstr_array(Repodata *data, Id solvid, Id keyname, const char *str);
  228. void repodata_add_fixarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
  229. void repodata_add_flexarray(Repodata *data, Id solvid, Id keyname, Id ghandle);
  230. /* generic */
  231. void repodata_set_kv(Repodata *data, Id solvid, Id keyname, Id keytype, struct s_KeyValue *kv);
  232. void repodata_unset(Repodata *data, Id solvid, Id keyname);
  233. void repodata_unset_uninternalized(Repodata *data, Id solvid, Id keyname);
  234. /*
  235. merge/swap attributes from one solvable to another
  236. works only if the data is not yet internalized
  237. */
  238. void repodata_merge_attrs(Repodata *data, Id dest, Id src);
  239. void repodata_merge_some_attrs(Repodata *data, Id dest, Id src, Map *keyidmap, int overwrite);
  240. void repodata_swap_attrs(Repodata *data, Id dest, Id src);
  241. Repodata *repodata_create_stubs(Repodata *data);
  242. /*
  243. * load all paged data, used to speed up copying in repo_rpmdb
  244. */
  245. void repodata_disable_paging(Repodata *data);
  246. /* helper functions */
  247. Id repodata_globalize_id(Repodata *data, Id id, int create);
  248. Id repodata_localize_id(Repodata *data, Id id, int create);
  249. Id repodata_translate_id(Repodata *data, Repodata *fromdata, Id id, int create);
  250. Id repodata_translate_dir_slow(Repodata *data, Repodata *fromdata, Id dir, int create, Id *cache);
  251. Id repodata_str2dir(Repodata *data, const char *dir, int create);
  252. const char *repodata_dir2str(Repodata *data, Id did, const char *suf);
  253. const char *repodata_chk2str(Repodata *data, Id type, const unsigned char *buf);
  254. void repodata_set_location(Repodata *data, Id solvid, int medianr, const char *dir, const char *file);
  255. void repodata_set_deltalocation(Repodata *data, Id handle, int medianr, const char *dir, const char *file);
  256. void repodata_set_sourcepkg(Repodata *data, Id solvid, const char *sourcepkg);
  257. /* uninternalized data lookup / search */
  258. Repokey *repodata_lookup_kv_uninternalized(Repodata *data, Id solvid, Id keyname, struct s_KeyValue *kv);
  259. void repodata_search_uninternalized(Repodata *data, Id solvid, Id keyname, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, struct s_KeyValue *kv), void *cbdata);
  260. /* stats */
  261. unsigned int repodata_memused(Repodata *data);
  262. static inline Id
  263. repodata_translate_dir(Repodata *data, Repodata *fromdata, Id dir, int create, Id *cache)
  264. {
  265. if (cache && dir && cache[(dir & 255) * 2] == dir)
  266. return cache[(dir & 255) * 2 + 1];
  267. return repodata_translate_dir_slow(data, fromdata, dir, create, cache);
  268. }
  269. static inline Id *
  270. repodata_create_dirtranscache(Repodata *data)
  271. {
  272. return (Id *)solv_calloc(256, sizeof(Id) * 2);
  273. }
  274. static inline Id *
  275. repodata_free_dirtranscache(Id *cache)
  276. {
  277. return (Id *)solv_free(cache);
  278. }
  279. #ifdef __cplusplus
  280. }
  281. #endif
  282. #endif /* LIBSOLV_REPODATA_H */