0c1c849286e1f4157b78735c8fd0e4f5c9e60e94
[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 typedef struct _Datamatcher {
63   int flags;
64   const char *match;
65   void *matchdata;
66   int error;
67 } Datamatcher;
68
69 typedef struct _Dataiterator
70 {
71   int state;
72   int flags;
73
74   Pool *pool;
75   struct _Repo *repo;
76   struct _Repodata *data;
77
78   /* data pointers */
79   unsigned char *dp;
80   unsigned char *ddp;
81   Id *idp;
82   Id *keyp;
83
84   /* the result */
85   struct _Repokey *key;
86   KeyValue kv;
87
88   /* our matcher */
89   Datamatcher matcher;
90
91   /* iterators/filters */
92   Id keyname;
93   Id repodataid;
94   Id solvid;
95   Id repoid;
96
97   Id keynames[3 + 1];
98   int nkeynames;
99   int rootlevel;
100
101   /* recursion data */
102   struct di_parent {
103     KeyValue kv;
104     unsigned char *dp;
105     Id *keyp;
106   } parents[3];
107   int nparents;
108
109 } Dataiterator;
110
111 int  datamatcher_init(Datamatcher *ma, const char *match, int flags);
112 void datamatcher_free(Datamatcher *ma);
113 int  datamatcher_match(Datamatcher *ma, const char *str);
114
115 /*
116  * Dataiterator
117  * 
118  * Iterator like interface to 'search' functionality
119  * 
120  * Dataiterator is per-pool, additional filters can be applied
121  * to limit the search domain. See dataiterator_init below.
122  * 
123  * Use these like:
124  *    Dataiterator di;
125  *    dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
126  *    while (dataiterator_step(&di))
127  *      dosomething(di.solvid, di.key, di.kv);
128  *    dataiterator_free(&di);
129  */
130
131 /*
132  * Initialize dataiterator
133  * 
134  * di:      Pointer to Dataiterator to be initialized
135  * pool:    Search domain for the iterator
136  * repo:    if non-null, limit search to this repo
137  * solvid:  if non-null, limit search to this solvable
138  * keyname: if non-null, limit search to this keyname
139  * match:   if non-null, limit search to this match
140  */
141 int  dataiterator_init(Dataiterator *di, Pool *pool, struct _Repo *repo, Id p, Id keyname, const char *match, int flags);
142 void dataiterator_init_clone(Dataiterator *di, Dataiterator *from);
143 void dataiterator_set_search(Dataiterator *di, struct _Repo *repo, Id p);
144 void dataiterator_set_keyname(Dataiterator *di, Id keyname);
145 int  dataiterator_set_match(Dataiterator *di, const char *match, int flags);
146
147 void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
148 void dataiterator_free(Dataiterator *di);
149 int  dataiterator_step(Dataiterator *di);
150 void dataiterator_setpos(Dataiterator *di);
151 void dataiterator_setpos_parent(Dataiterator *di);
152 int  dataiterator_match(Dataiterator *di, Datamatcher *ma);
153 void dataiterator_skip_attribute(Dataiterator *di);
154 void dataiterator_skip_solvable(Dataiterator *di);
155 void dataiterator_skip_repo(Dataiterator *di);
156 void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
157 void dataiterator_jump_to_repo(Dataiterator *di, struct _Repo *repo);
158 void dataiterator_entersub(Dataiterator *di);
159 void dataiterator_clonepos(Dataiterator *di, Dataiterator *from);
160 void dataiterator_seek(Dataiterator *di, int whence);
161
162 #define DI_SEEK_STAY    (1 << 16)
163 #define DI_SEEK_CHILD   1
164 #define DI_SEEK_PARENT  2
165 #define DI_SEEK_REWIND  3
166
167 #endif /* LIBSOLV_DATAITERATOR_H */