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