fixing leak
[oweals/gnunet.git] / src / monkey / gnunet_monkey_edb.h
1 /*
2       This file is part of GNUnet
3       (C) 2009, 2010 Christian Grothoff (and other contributing authors)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * @file monkey/gnunet_monkey_edb.h
23  * @brief Monkey API for accessing the Expression Database (edb)
24  */
25
26 #ifndef GNUNET_MONKEY_EDB_H
27 #define GNUNET_MONKEY_EDB_H
28
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #if 0                           /* keep Emacsens' auto-indent happy */
33 }
34 #endif
35 #endif
36
37
38 struct GNUNET_MONKEY_EDB_Context;
39
40 /**
41  * Establish a connection to the Expression Database
42  *
43  * @param db_file_name path the Expression Database file
44  * @return context to use for Accessing the Expression Database, NULL on error
45  */
46 struct GNUNET_MONKEY_EDB_Context *GNUNET_MONKEY_EDB_connect (const char
47                                                              *db_file_name);
48
49
50 /**
51  * Disconnect from Database, and cleanup resources
52  *
53  * @param context context
54  * @return GNUNET_OK on success, GNUNET_NO on failure
55  */
56 int GNUNET_MONKEY_EDB_disconnect (struct GNUNET_MONKEY_EDB_Context *cntxt);
57
58
59 typedef int (*GNUNET_MONKEY_ExpressionIterator) (void *, int, char **,
60                                                  char **);
61
62
63
64 /**
65  * Return the line number of the end-of-scope for the expression indicated by start_line_no
66  *
67  * @param cntxt context containing the Expression Database handle
68  * @param file_name path to the file in which the expression in question exists
69  * @param start_line_no expression's line
70  * @param iter callback function, iterator for values returned from the Database
71  * @param iter_cls closure for the expression iterator, will contain the scope-end line number
72  * @return GNUNET_OK on success, GNUNET_NO on failure
73  */
74 int
75 GNUNET_MONKEY_EDB_get_expression_scope_end(struct GNUNET_MONKEY_EDB_Context *cntxt,
76                                   const char *file_name, int start_line_no,
77                                   GNUNET_MONKEY_ExpressionIterator iter,
78                                   void *iter_cls);
79
80
81 /**
82  * Run an SQLite query to retrieve those expressions that are previous to
83  * given expression and are in the same scope of the given expression
84  * For example, consider the following code snippet:
85  *
86  * {
87  *   struct Something whole; // line no.1 
88  *   struct SomethingElse part; // line no.2
89  *   whole.part = ∂ // line no.3
90  *   whole.part->member = 1; // line no.4
91  * }
92  *
93  * If the expression supplied to the function is that of line no.4 "whole.part->member = 1;"
94  * The returned list of expressions will be: whole.part (line no.4), whole.part->member (line no.4),
95  * whole (line no.3), whole.part (line no.3), &part (line no.3), whole.part = &part (line no.3)
96  *
97  * @param cntxt context containing the Expression Database handle.
98  * @param file_name path to the file in which the expression in question exists
99  * @param start_line_no expression beginning line
100  * @param end_line_no line number for the expression's scope end
101  * @param iter callback function, iterator for expressions returned from the Database
102  * @param iter_cls closure for the expression iterator
103  * @return GNUNET_OK success, GNUNET_NO failure
104  */
105 int
106 GNUNET_MONKEY_EDB_get_expressions (struct GNUNET_MONKEY_EDB_Context *cntxt,
107                                    const char *file_name, int start_line_no,
108                                    int end_line_no,
109                                    GNUNET_MONKEY_ExpressionIterator iter,
110                                    void *iter_cls);
111
112
113
114 #if 0                           /* keep Emacsens' auto-indent happy */
115 {
116 #endif
117 #ifdef __cplusplus
118 }
119 #endif
120
121 #endif