Imported Upstream version 0.7.27
[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 typedef struct s_KeyValue {
24   Id id;
25   const char *str;
26   unsigned int num;
27   unsigned int num2;
28
29   int entry;    /* array entry, starts with 0 */
30   int eof;      /* last entry reached */
31
32   struct s_KeyValue *parent;
33 } KeyValue;
34
35 #define SOLV_KV_NUM64(kv) (((unsigned long long)((kv)->num2)) << 32 | (kv)->num)
36
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
43 #define SEARCH_GLOB                     5
44 #define SEARCH_REGEX                    6
45 #define SEARCH_ERROR                    15
46 #define SEARCH_NOCASE                   (1<<7)
47
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 */
54
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)
62
63 /* internal */
64 #define SEARCH_SUBSCHEMA                (1<<30)
65 #define SEARCH_THISSOLVID               (1<<31)
66
67 /* obsolete */
68 #define SEARCH_COMPLETE_FILELIST        0               /* ignored, this is the default */
69
70 /*
71  * Datamatcher: match a string against a query
72  */
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 */
77   int error;
78 } Datamatcher;
79
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);
84
85
86 /*
87  * Dataiterator
88  *
89  * Iterator like interface to 'search' functionality
90  *
91  * Dataiterator is per-pool, additional filters can be applied
92  * to limit the search domain. See dataiterator_init below.
93  *
94  * Use these like:
95  *    Dataiterator di;
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);
100  */
101 typedef struct s_Dataiterator
102 {
103   int state;
104   int flags;
105
106   Pool *pool;
107   Repo *repo;
108   Repodata *data;
109
110   /* data pointers */
111   unsigned char *dp;
112   unsigned char *ddp;
113   Id *idp;
114   Id *keyp;
115
116   /* the result */
117   struct s_Repokey *key;
118   KeyValue kv;
119
120   /* our matcher */
121   Datamatcher matcher;
122
123   /* iterators/filters */
124   Id keyname;
125   Id repodataid;
126   Id solvid;
127   Id repoid;
128
129   Id keynames[3 + 1];
130   int nkeynames;
131   int rootlevel;
132
133   /* recursion data */
134   struct di_parent {
135     KeyValue kv;
136     unsigned char *dp;
137     Id *keyp;
138   } parents[3];
139   int nparents;
140
141   /* vertical data */
142   unsigned char *vert_ddp;
143   Id vert_off;
144   Id vert_len;
145   Id vert_storestate;
146
147   /* strdup data */
148   char *dupstr;
149   int dupstrn;
150
151   Id *keyskip;
152   Id *oldkeyskip;
153 } Dataiterator;
154
155
156 /*
157  * Initialize dataiterator
158  *
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
165  */
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);
171
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);
187
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
192
193 #ifdef __cplusplus
194 }
195 #endif
196
197 #endif /* LIBSOLV_DATAITERATOR_H */