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