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"
25 typedef struct _KeyValue {
31 int entry; /* array entry, starts with 0 */
32 int eof; /* last entry reached */
34 struct _KeyValue *parent;
37 #define SOLV_KV_NUM64(kv) (((unsigned long long)((kv)->num2)) << 32 | (kv)->num)
39 /* search matcher flags */
40 #define SEARCH_STRINGMASK 15
41 #define SEARCH_STRING 1
42 #define SEARCH_STRINGSTART 2
43 #define SEARCH_STRINGEND 3
44 #define SEARCH_SUBSTRING 4
46 #define SEARCH_REGEX 6
47 #define SEARCH_ERROR 15
48 #define SEARCH_NOCASE (1<<7)
50 /* iterator control */
51 #define SEARCH_NO_STORAGE_SOLVABLE (1<<8)
52 #define SEARCH_SUB (1<<9)
53 #define SEARCH_ARRAYSENTINEL (1<<10)
54 #define SEARCH_DISABLED_REPOS (1<<11)
55 #define SEARCH_COMPLETE_FILELIST (1<<12)
57 /* stringification flags */
58 #define SEARCH_SKIP_KIND (1<<16)
59 /* By default we stringify just to the basename of a file because
60 the construction of the full filename is costly. Specify this
61 flag if you want to match full filenames */
62 #define SEARCH_FILES (1<<17)
63 #define SEARCH_CHECKSUMS (1<<18)
65 /* dataiterator internal */
66 #define SEARCH_THISSOLVID (1<<31)
69 * Datamatcher: match a string against a query
71 typedef struct _Datamatcher {
72 int flags; /* see matcher flags above */
73 const char *match; /* the query string */
74 void *matchdata; /* e.g. compiled regexp */
78 int datamatcher_init(Datamatcher *ma, const char *match, int flags);
79 void datamatcher_free(Datamatcher *ma);
80 int datamatcher_match(Datamatcher *ma, const char *str);
81 int datamatcher_checkbasename(Datamatcher *ma, const char *str);
87 * Iterator like interface to 'search' functionality
89 * Dataiterator is per-pool, additional filters can be applied
90 * to limit the search domain. See dataiterator_init below.
94 * dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
95 * while (dataiterator_step(&di))
96 * dosomething(di.solvid, di.key, di.kv);
97 * dataiterator_free(&di);
99 typedef struct _Dataiterator
106 struct _Repodata *data;
115 struct _Repokey *key;
121 /* iterators/filters */
140 unsigned char *vert_ddp;
153 * Initialize dataiterator
155 * di: Pointer to Dataiterator to be initialized
156 * pool: Search domain for the iterator
157 * repo: if non-null, limit search to this repo
158 * solvid: if non-null, limit search to this solvable
159 * keyname: if non-null, limit search to this keyname
160 * match: if non-null, limit search to this match
162 int dataiterator_init(Dataiterator *di, Pool *pool, struct _Repo *repo, Id p, Id keyname, const char *match, int flags);
163 void dataiterator_init_clone(Dataiterator *di, Dataiterator *from);
164 void dataiterator_set_search(Dataiterator *di, struct _Repo *repo, Id p);
165 void dataiterator_set_keyname(Dataiterator *di, Id keyname);
166 int dataiterator_set_match(Dataiterator *di, const char *match, int flags);
168 void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
169 void dataiterator_free(Dataiterator *di);
170 int dataiterator_step(Dataiterator *di);
171 void dataiterator_setpos(Dataiterator *di);
172 void dataiterator_setpos_parent(Dataiterator *di);
173 int dataiterator_match(Dataiterator *di, Datamatcher *ma);
174 void dataiterator_skip_attribute(Dataiterator *di);
175 void dataiterator_skip_solvable(Dataiterator *di);
176 void dataiterator_skip_repo(Dataiterator *di);
177 void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
178 void dataiterator_jump_to_repo(Dataiterator *di, struct _Repo *repo);
179 void dataiterator_entersub(Dataiterator *di);
180 void dataiterator_clonepos(Dataiterator *di, Dataiterator *from);
181 void dataiterator_seek(Dataiterator *di, int whence);
182 void dataiterator_strdup(Dataiterator *di);
184 #define DI_SEEK_STAY (1 << 16)
185 #define DI_SEEK_CHILD 1
186 #define DI_SEEK_PARENT 2
187 #define DI_SEEK_REWIND 3
193 #endif /* LIBSOLV_DATAITERATOR_H */