2 * Copyright (c) 2007-2012, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef LIBSOLV_DATAITERATOR_H
14 #define LIBSOLV_DATAITERATOR_H
16 #include "pooltypes.h"
21 typedef struct _KeyValue {
27 int entry; /* array entry, starts with 0 */
28 int eof; /* last entry reached */
30 struct _KeyValue *parent;
33 #define SOLV_KV_NUM64(kv) (((unsigned long long)((kv)->num2)) << 32 | (kv)->num)
35 /* search matcher flags */
36 #define SEARCH_STRINGMASK 15
37 #define SEARCH_STRING 1
38 #define SEARCH_STRINGSTART 2
39 #define SEARCH_STRINGEND 3
40 #define SEARCH_SUBSTRING 4
42 #define SEARCH_REGEX 6
43 #define SEARCH_ERROR 15
44 #define SEARCH_NOCASE (1<<7)
46 /* iterator control */
47 #define SEARCH_NO_STORAGE_SOLVABLE (1<<8)
48 #define SEARCH_SUB (1<<9)
49 #define SEARCH_ARRAYSENTINEL (1<<10)
50 #define SEARCH_DISABLED_REPOS (1<<11)
51 #define SEARCH_COMPLETE_FILELIST (1<<12)
53 /* stringification flags */
54 #define SEARCH_SKIP_KIND (1<<16)
55 /* By default we stringify just to the basename of a file because
56 the construction of the full filename is costly. Specify this
57 flag if you want to match full filenames */
58 #define SEARCH_FILES (1<<17)
59 #define SEARCH_CHECKSUMS (1<<18)
61 /* dataiterator internal */
62 #define SEARCH_THISSOLVID (1<<31)
65 * Datamatcher: match a string against a query
67 typedef struct _Datamatcher {
68 int flags; /* see matcher flags above */
69 const char *match; /* the query string */
70 void *matchdata; /* e.g. compiled regexp */
74 int datamatcher_init(Datamatcher *ma, const char *match, int flags);
75 void datamatcher_free(Datamatcher *ma);
76 int datamatcher_match(Datamatcher *ma, const char *str);
82 * Iterator like interface to 'search' functionality
84 * Dataiterator is per-pool, additional filters can be applied
85 * to limit the search domain. See dataiterator_init below.
89 * dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
90 * while (dataiterator_step(&di))
91 * dosomething(di.solvid, di.key, di.kv);
92 * dataiterator_free(&di);
94 typedef struct _Dataiterator
101 struct _Repodata *data;
110 struct _Repokey *key;
116 /* iterators/filters */
138 * Initialize dataiterator
140 * di: Pointer to Dataiterator to be initialized
141 * pool: Search domain for the iterator
142 * repo: if non-null, limit search to this repo
143 * solvid: if non-null, limit search to this solvable
144 * keyname: if non-null, limit search to this keyname
145 * match: if non-null, limit search to this match
147 int dataiterator_init(Dataiterator *di, Pool *pool, struct _Repo *repo, Id p, Id keyname, const char *match, int flags);
148 void dataiterator_init_clone(Dataiterator *di, Dataiterator *from);
149 void dataiterator_set_search(Dataiterator *di, struct _Repo *repo, Id p);
150 void dataiterator_set_keyname(Dataiterator *di, Id keyname);
151 int dataiterator_set_match(Dataiterator *di, const char *match, int flags);
153 void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
154 void dataiterator_free(Dataiterator *di);
155 int dataiterator_step(Dataiterator *di);
156 void dataiterator_setpos(Dataiterator *di);
157 void dataiterator_setpos_parent(Dataiterator *di);
158 int dataiterator_match(Dataiterator *di, Datamatcher *ma);
159 void dataiterator_skip_attribute(Dataiterator *di);
160 void dataiterator_skip_solvable(Dataiterator *di);
161 void dataiterator_skip_repo(Dataiterator *di);
162 void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
163 void dataiterator_jump_to_repo(Dataiterator *di, struct _Repo *repo);
164 void dataiterator_entersub(Dataiterator *di);
165 void dataiterator_clonepos(Dataiterator *di, Dataiterator *from);
166 void dataiterator_seek(Dataiterator *di, int whence);
168 #define DI_SEEK_STAY (1 << 16)
169 #define DI_SEEK_CHILD 1
170 #define DI_SEEK_PARENT 2
171 #define DI_SEEK_REWIND 3
173 #endif /* LIBSOLV_DATAITERATOR_H */