dataiterator.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (c) 2007-2012, Novell Inc.
  3. *
  4. * This program is licensed under the BSD license, read LICENSE.BSD
  5. * for further information
  6. */
  7. /*
  8. * dataiterator.h
  9. *
  10. */
  11. #ifndef LIBSOLV_DATAITERATOR_H
  12. #define LIBSOLV_DATAITERATOR_H
  13. #include "pooltypes.h"
  14. #include "pool.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. struct s_Repo;
  19. typedef struct s_KeyValue {
  20. Id id;
  21. const char *str;
  22. unsigned int num;
  23. unsigned int num2;
  24. int entry; /* array entry, starts with 0 */
  25. int eof; /* last entry reached */
  26. struct s_KeyValue *parent;
  27. } KeyValue;
  28. #define SOLV_KV_NUM64(kv) (((unsigned long long)((kv)->num2)) << 32 | (kv)->num)
  29. /* search matcher flags */
  30. #define SEARCH_STRINGMASK 15
  31. #define SEARCH_STRING 1
  32. #define SEARCH_STRINGSTART 2
  33. #define SEARCH_STRINGEND 3
  34. #define SEARCH_SUBSTRING 4
  35. #define SEARCH_GLOB 5
  36. #define SEARCH_REGEX 6
  37. #define SEARCH_ERROR 15
  38. #define SEARCH_NOCASE (1<<7)
  39. /* iterator control */
  40. #define SEARCH_NO_STORAGE_SOLVABLE (1<<8)
  41. #define SEARCH_SUB (1<<9)
  42. #define SEARCH_ARRAYSENTINEL (1<<10)
  43. #define SEARCH_DISABLED_REPOS (1<<11)
  44. #define SEARCH_KEEP_TYPE_DELETED (1<<12) /* only has effect if no keyname is given */
  45. /* stringification flags */
  46. #define SEARCH_SKIP_KIND (1<<16)
  47. /* By default we stringify just to the basename of a file because
  48. the construction of the full filename is costly. Specify this
  49. flag if you want to match full filenames */
  50. #define SEARCH_FILES (1<<17)
  51. #define SEARCH_CHECKSUMS (1<<18)
  52. /* internal */
  53. #define SEARCH_SUBSCHEMA (1<<30)
  54. #define SEARCH_THISSOLVID (1<<31)
  55. /* obsolete */
  56. #define SEARCH_COMPLETE_FILELIST 0 /* ignored, this is the default */
  57. /*
  58. * Datamatcher: match a string against a query
  59. */
  60. typedef struct s_Datamatcher {
  61. int flags; /* see matcher flags above */
  62. const char *match; /* the query string */
  63. void *matchdata; /* e.g. compiled regexp */
  64. int error;
  65. } Datamatcher;
  66. int datamatcher_init(Datamatcher *ma, const char *match, int flags);
  67. void datamatcher_free(Datamatcher *ma);
  68. int datamatcher_match(Datamatcher *ma, const char *str);
  69. int datamatcher_checkbasename(Datamatcher *ma, const char *str);
  70. /*
  71. * Dataiterator
  72. *
  73. * Iterator like interface to 'search' functionality
  74. *
  75. * Dataiterator is per-pool, additional filters can be applied
  76. * to limit the search domain. See dataiterator_init below.
  77. *
  78. * Use these like:
  79. * Dataiterator di;
  80. * dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
  81. * while (dataiterator_step(&di))
  82. * dosomething(di.solvid, di.key, di.kv);
  83. * dataiterator_free(&di);
  84. */
  85. typedef struct s_Dataiterator
  86. {
  87. int state;
  88. int flags;
  89. Pool *pool;
  90. struct s_Repo *repo;
  91. struct s_Repodata *data;
  92. /* data pointers */
  93. unsigned char *dp;
  94. unsigned char *ddp;
  95. Id *idp;
  96. Id *keyp;
  97. /* the result */
  98. struct s_Repokey *key;
  99. KeyValue kv;
  100. /* our matcher */
  101. Datamatcher matcher;
  102. /* iterators/filters */
  103. Id keyname;
  104. Id repodataid;
  105. Id solvid;
  106. Id repoid;
  107. Id keynames[3 + 1];
  108. int nkeynames;
  109. int rootlevel;
  110. /* recursion data */
  111. struct di_parent {
  112. KeyValue kv;
  113. unsigned char *dp;
  114. Id *keyp;
  115. } parents[3];
  116. int nparents;
  117. /* vertical data */
  118. unsigned char *vert_ddp;
  119. Id vert_off;
  120. Id vert_len;
  121. Id vert_storestate;
  122. /* strdup data */
  123. char *dupstr;
  124. int dupstrn;
  125. Id *keyskip;
  126. Id *oldkeyskip;
  127. } Dataiterator;
  128. /*
  129. * Initialize dataiterator
  130. *
  131. * di: Pointer to Dataiterator to be initialized
  132. * pool: Search domain for the iterator
  133. * repo: if non-null, limit search to this repo
  134. * solvid: if non-null, limit search to this solvable
  135. * keyname: if non-null, limit search to this keyname
  136. * match: if non-null, limit search to this match
  137. */
  138. int dataiterator_init(Dataiterator *di, Pool *pool, struct s_Repo *repo, Id p, Id keyname, const char *match, int flags);
  139. void dataiterator_init_clone(Dataiterator *di, Dataiterator *from);
  140. void dataiterator_set_search(Dataiterator *di, struct s_Repo *repo, Id p);
  141. void dataiterator_set_keyname(Dataiterator *di, Id keyname);
  142. int dataiterator_set_match(Dataiterator *di, const char *match, int flags);
  143. void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
  144. void dataiterator_free(Dataiterator *di);
  145. int dataiterator_step(Dataiterator *di);
  146. void dataiterator_setpos(Dataiterator *di);
  147. void dataiterator_setpos_parent(Dataiterator *di);
  148. int dataiterator_match(Dataiterator *di, Datamatcher *ma);
  149. void dataiterator_skip_attribute(Dataiterator *di);
  150. void dataiterator_skip_solvable(Dataiterator *di);
  151. void dataiterator_skip_repo(Dataiterator *di);
  152. void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
  153. void dataiterator_jump_to_repo(Dataiterator *di, struct s_Repo *repo);
  154. void dataiterator_entersub(Dataiterator *di);
  155. void dataiterator_clonepos(Dataiterator *di, Dataiterator *from);
  156. void dataiterator_seek(Dataiterator *di, int whence);
  157. void dataiterator_strdup(Dataiterator *di);
  158. #define DI_SEEK_STAY (1 << 16)
  159. #define DI_SEEK_CHILD 1
  160. #define DI_SEEK_PARENT 2
  161. #define DI_SEEK_REWIND 3
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. #endif /* LIBSOLV_DATAITERATOR_H */