3133686b0ed4c5b47f45ed54c0f170fb3a1c1d95
[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 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 struct _Repo;
24
25 typedef struct _KeyValue {
26   Id id;
27   const char *str;
28   unsigned int num;
29   unsigned int num2;
30
31   int entry;    /* array entry, starts with 0 */
32   int eof;      /* last entry reached */
33
34   struct _KeyValue *parent;
35 } KeyValue;
36
37 #define SOLV_KV_NUM64(kv) (((unsigned long long)((kv)->num2)) << 32 | (kv)->num)
38
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
45 #define SEARCH_GLOB                     5
46 #define SEARCH_REGEX                    6
47 #define SEARCH_ERROR                    15
48 #define SEARCH_NOCASE                   (1<<7)
49
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)
56
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)
64
65 /* dataiterator internal */
66 #define SEARCH_THISSOLVID               (1<<31)
67
68 /*
69  * Datamatcher: match a string against a query
70  */
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 */
75   int error;
76 } Datamatcher;
77
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);
82
83
84 /*
85  * Dataiterator
86  *
87  * Iterator like interface to 'search' functionality
88  *
89  * Dataiterator is per-pool, additional filters can be applied
90  * to limit the search domain. See dataiterator_init below.
91  *
92  * Use these like:
93  *    Dataiterator di;
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);
98  */
99 typedef struct _Dataiterator
100 {
101   int state;
102   int flags;
103
104   Pool *pool;
105   struct _Repo *repo;
106   struct _Repodata *data;
107
108   /* data pointers */
109   unsigned char *dp;
110   unsigned char *ddp;
111   Id *idp;
112   Id *keyp;
113
114   /* the result */
115   struct _Repokey *key;
116   KeyValue kv;
117
118   /* our matcher */
119   Datamatcher matcher;
120
121   /* iterators/filters */
122   Id keyname;
123   Id repodataid;
124   Id solvid;
125   Id repoid;
126
127   Id keynames[3 + 1];
128   int nkeynames;
129   int rootlevel;
130
131   /* recursion data */
132   struct di_parent {
133     KeyValue kv;
134     unsigned char *dp;
135     Id *keyp;
136   } parents[3];
137   int nparents;
138
139   /* vertical data */
140   unsigned char *vert_ddp;
141   Id vert_off;
142   Id vert_len;
143   Id vert_storestate;
144
145   /* strdup data */
146   char *dupstr;
147   int dupstrn;
148
149 } Dataiterator;
150
151
152 /*
153  * Initialize dataiterator
154  *
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
161  */
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);
167
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);
183
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
188
189 #ifdef __cplusplus
190 }
191 #endif
192
193 #endif /* LIBSOLV_DATAITERATOR_H */