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"
23 typedef struct s_KeyValue {
29 int entry; /* array entry, starts with 0 */
30 int eof; /* last entry reached */
32 struct s_KeyValue *parent;
35 #define SOLV_KV_NUM64(kv) (((unsigned long long)((kv)->num2)) << 32 | (kv)->num)
37 /* search matcher flags */
38 #define SEARCH_STRINGMASK 15
39 #define SEARCH_STRING 1
40 #define SEARCH_STRINGSTART 2
41 #define SEARCH_STRINGEND 3
42 #define SEARCH_SUBSTRING 4
44 #define SEARCH_REGEX 6
45 #define SEARCH_ERROR 15
46 #define SEARCH_NOCASE (1<<7)
48 /* iterator control */
49 #define SEARCH_NO_STORAGE_SOLVABLE (1<<8)
50 #define SEARCH_SUB (1<<9)
51 #define SEARCH_ARRAYSENTINEL (1<<10)
52 #define SEARCH_DISABLED_REPOS (1<<11)
53 #define SEARCH_KEEP_TYPE_DELETED (1<<12) /* only has effect if no keyname is given */
55 /* stringification flags */
56 #define SEARCH_SKIP_KIND (1<<16)
57 /* By default we stringify just to the basename of a file because
58 the construction of the full filename is costly. Specify this
59 flag if you want to match full filenames */
60 #define SEARCH_FILES (1<<17)
61 #define SEARCH_CHECKSUMS (1<<18)
64 #define SEARCH_SUBSCHEMA (1<<30)
65 #define SEARCH_THISSOLVID (1<<31)
68 #define SEARCH_COMPLETE_FILELIST 0 /* ignored, this is the default */
71 * Datamatcher: match a string against a query
73 typedef struct s_Datamatcher {
74 int flags; /* see matcher flags above */
75 const char *match; /* the query string */
76 void *matchdata; /* e.g. compiled regexp */
80 int datamatcher_init(Datamatcher *ma, const char *match, int flags);
81 void datamatcher_free(Datamatcher *ma);
82 int datamatcher_match(Datamatcher *ma, const char *str);
83 int datamatcher_checkbasename(Datamatcher *ma, const char *str);
89 * Iterator like interface to 'search' functionality
91 * Dataiterator is per-pool, additional filters can be applied
92 * to limit the search domain. See dataiterator_init below.
96 * dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
97 * while (dataiterator_step(&di))
98 * dosomething(di.solvid, di.key, di.kv);
99 * dataiterator_free(&di);
101 typedef struct s_Dataiterator
117 struct s_Repokey *key;
123 /* iterators/filters */
142 unsigned char *vert_ddp;
157 * Initialize dataiterator
159 * di: Pointer to Dataiterator to be initialized
160 * pool: Search domain for the iterator
161 * repo: if non-null, limit search to this repo
162 * solvid: if non-null, limit search to this solvable
163 * keyname: if non-null, limit search to this keyname
164 * match: if non-null, limit search to this match
166 int dataiterator_init(Dataiterator *di, Pool *pool, Repo *repo, Id p, Id keyname, const char *match, int flags);
167 void dataiterator_init_clone(Dataiterator *di, Dataiterator *from);
168 void dataiterator_set_search(Dataiterator *di, Repo *repo, Id p);
169 void dataiterator_set_keyname(Dataiterator *di, Id keyname);
170 int dataiterator_set_match(Dataiterator *di, const char *match, int flags);
172 void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
173 void dataiterator_free(Dataiterator *di);
174 int dataiterator_step(Dataiterator *di);
175 void dataiterator_setpos(Dataiterator *di);
176 void dataiterator_setpos_parent(Dataiterator *di);
177 int dataiterator_match(Dataiterator *di, Datamatcher *ma);
178 void dataiterator_skip_attribute(Dataiterator *di);
179 void dataiterator_skip_solvable(Dataiterator *di);
180 void dataiterator_skip_repo(Dataiterator *di);
181 void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
182 void dataiterator_jump_to_repo(Dataiterator *di, Repo *repo);
183 void dataiterator_entersub(Dataiterator *di);
184 void dataiterator_clonepos(Dataiterator *di, Dataiterator *from);
185 void dataiterator_seek(Dataiterator *di, int whence);
186 void dataiterator_strdup(Dataiterator *di);
188 #define DI_SEEK_STAY (1 << 16)
189 #define DI_SEEK_CHILD 1
190 #define DI_SEEK_PARENT 2
191 #define DI_SEEK_REWIND 3
197 #endif /* LIBSOLV_DATAITERATOR_H */