diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-27 01:18:50 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-27 01:18:50 +0100 |
commit | 3112e64ef06f71b06e9f047f2c6dd1be0941a565 (patch) | |
tree | c5eed6bcdbb0c24d72466c6f052bece931307cc6 /src | |
parent | befd2f9fc787c2ac75790b06e1601f2f65305375 (diff) | |
download | gnunet-3112e64ef06f71b06e9f047f2c6dd1be0941a565.tar.gz gnunet-3112e64ef06f71b06e9f047f2c6dd1be0941a565.zip |
skeleton for libgnunetsq implementation
Diffstat (limited to 'src')
-rw-r--r-- | src/sq/Makefile.am | 40 | ||||
-rw-r--r-- | src/sq/sq.c | 68 | ||||
-rw-r--r-- | src/sq/sq_query_helper.c | 129 | ||||
-rw-r--r-- | src/sq/sq_result_helper.c | 164 |
4 files changed, 401 insertions, 0 deletions
diff --git a/src/sq/Makefile.am b/src/sq/Makefile.am new file mode 100644 index 000000000..7197e7ab4 --- /dev/null +++ b/src/sq/Makefile.am | |||
@@ -0,0 +1,40 @@ | |||
1 | # This Makefile.am is in the public domain | ||
2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include $(POSTGRESQL_CPPFLAGS) | ||
3 | |||
4 | if MINGW | ||
5 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | ||
6 | endif | ||
7 | |||
8 | if USE_COVERAGE | ||
9 | AM_CFLAGS = --coverage | ||
10 | endif | ||
11 | |||
12 | if HAVE_POSTGRESQL | ||
13 | lib_LTLIBRARIES = libgnunetsq.la | ||
14 | endif | ||
15 | |||
16 | libgnunetsq_la_SOURCES = \ | ||
17 | sq.c \ | ||
18 | sq_query_helper.c \ | ||
19 | sq_result_helper.c | ||
20 | libgnunetsq_la_LIBADD = -lsq \ | ||
21 | $(top_builddir)/src/util/libgnunetutil.la | ||
22 | libgnunetsq_la_LDFLAGS = \ | ||
23 | $(POSTGRESQL_LDFLAGS) \ | ||
24 | $(GN_LIB_LDFLAGS) \ | ||
25 | -version-info 0:0:0 | ||
26 | |||
27 | if ENABLE_TEST_RUN | ||
28 | TESTS = \ | ||
29 | test_sq | ||
30 | endif | ||
31 | |||
32 | check_PROGRAMS= \ | ||
33 | test_sq | ||
34 | |||
35 | test_sq_SOURCES = \ | ||
36 | test_sq.c | ||
37 | test_sq_LDADD = \ | ||
38 | libgnunetsq.la \ | ||
39 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
40 | -lsqlite3 $(XLIB) | ||
diff --git a/src/sq/sq.c b/src/sq/sq.c new file mode 100644 index 000000000..524014b0f --- /dev/null +++ b/src/sq/sq.c | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2017 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify it under the | ||
6 | terms of the GNU General Public License as published by the Free Software | ||
7 | Foundation; either version 3, or (at your option) any later version. | ||
8 | |||
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with | ||
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | ||
15 | */ | ||
16 | /** | ||
17 | * @file sq/sq.c | ||
18 | * @brief helper functions for Sqlite3 DB interactions | ||
19 | * @author Christian Grothoff | ||
20 | */ | ||
21 | #include "platform.h" | ||
22 | #include "gnunet_sq_lib.h" | ||
23 | |||
24 | |||
25 | /** | ||
26 | * Execute a prepared statement. | ||
27 | * | ||
28 | * @param db_conn database connection | ||
29 | * @param params parameters to the statement | ||
30 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
31 | */ | ||
32 | int | ||
33 | GNUNET_SQ_bind (sqlite3_stmt *stmt, | ||
34 | const struct GNUNET_SQ_QueryParam *params) | ||
35 | { | ||
36 | } | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Extract results from a query result according to the given specification. | ||
41 | * | ||
42 | * @param result result to process | ||
43 | * @param[in,out] rs result specification to extract for | ||
44 | * @param row row from the result to extract | ||
45 | * @return | ||
46 | * #GNUNET_YES if all results could be extracted | ||
47 | * #GNUNET_SYSERR if a result was invalid (non-existing field) | ||
48 | */ | ||
49 | int | ||
50 | GNUNET_SQ_extract_result (sqlite3_stmt *result, | ||
51 | struct GNUNET_SQ_ResultSpec *rs, | ||
52 | int row) | ||
53 | { | ||
54 | } | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Free all memory that was allocated in @a rs during | ||
59 | * #GNUNET_SQ_extract_result(). | ||
60 | * | ||
61 | * @param rs reult specification to clean up | ||
62 | */ | ||
63 | void | ||
64 | GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs) | ||
65 | { | ||
66 | } | ||
67 | |||
68 | /* end of sq.c */ | ||
diff --git a/src/sq/sq_query_helper.c b/src/sq/sq_query_helper.c new file mode 100644 index 000000000..613a0c746 --- /dev/null +++ b/src/sq/sq_query_helper.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2017 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify it under the | ||
6 | terms of the GNU General Public License as published by the Free Software | ||
7 | Foundation; either version 3, or (at your option) any later version. | ||
8 | |||
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with | ||
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | ||
15 | */ | ||
16 | /** | ||
17 | * @file sq/sq_query_helper.c | ||
18 | * @brief helper functions for queries | ||
19 | * @author Christian Grothoff | ||
20 | */ | ||
21 | #include "gnunet_sq_lib.h" | ||
22 | |||
23 | |||
24 | /** | ||
25 | * Generate query parameter for a buffer @a ptr of | ||
26 | * @a ptr_size bytes. | ||
27 | * | ||
28 | * @param ptr pointer to the query parameter to pass | ||
29 | * @oaran ptr_size number of bytes in @a ptr | ||
30 | */ | ||
31 | struct GNUNET_SQ_QueryParam | ||
32 | GNUNET_SQ_query_param_fixed_size (const void *ptr, | ||
33 | size_t ptr_size) | ||
34 | { | ||
35 | } | ||
36 | |||
37 | |||
38 | /** | ||
39 | * Generate query parameter for a string. | ||
40 | * | ||
41 | * @param ptr pointer to the string query parameter to pass | ||
42 | */ | ||
43 | struct GNUNET_SQ_QueryParam | ||
44 | GNUNET_SQ_query_param_string (const char *ptr) | ||
45 | { | ||
46 | } | ||
47 | |||
48 | |||
49 | /** | ||
50 | * Generate query parameter for an RSA public key. The | ||
51 | * database must contain a BLOB type in the respective position. | ||
52 | * | ||
53 | * @param x the query parameter to pass. | ||
54 | */ | ||
55 | struct GNUNET_SQ_QueryParam | ||
56 | GNUNET_SQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) | ||
57 | { | ||
58 | } | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Generate query parameter for an RSA signature. The | ||
63 | * database must contain a BLOB type in the respective position. | ||
64 | * | ||
65 | * @param x the query parameter to pass | ||
66 | */ | ||
67 | struct GNUNET_SQ_QueryParam | ||
68 | GNUNET_SQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | ||
69 | { | ||
70 | } | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Generate query parameter for an absolute time value. | ||
75 | * The database must store a 64-bit integer. | ||
76 | * | ||
77 | * @param x pointer to the query parameter to pass | ||
78 | */ | ||
79 | struct GNUNET_SQ_QueryParam | ||
80 | GNUNET_SQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) | ||
81 | { | ||
82 | } | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Generate query parameter for an absolute time value. | ||
87 | * The database must store a 64-bit integer. | ||
88 | * | ||
89 | * @param x pointer to the query parameter to pass | ||
90 | */ | ||
91 | struct GNUNET_SQ_QueryParam | ||
92 | GNUNET_SQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x) | ||
93 | { | ||
94 | } | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Generate query parameter for an uint16_t in host byte order. | ||
99 | * | ||
100 | * @param x pointer to the query parameter to pass | ||
101 | */ | ||
102 | struct GNUNET_SQ_QueryParam | ||
103 | GNUNET_SQ_query_param_uint16 (const uint16_t *x) | ||
104 | { | ||
105 | } | ||
106 | |||
107 | |||
108 | /** | ||
109 | * Generate query parameter for an uint32_t in host byte order. | ||
110 | * | ||
111 | * @param x pointer to the query parameter to pass | ||
112 | */ | ||
113 | struct GNUNET_SQ_QueryParam | ||
114 | GNUNET_SQ_query_param_uint32 (const uint32_t *x) | ||
115 | { | ||
116 | } | ||
117 | |||
118 | |||
119 | /** | ||
120 | * Generate query parameter for an uint16_t in host byte order. | ||
121 | * | ||
122 | * @param x pointer to the query parameter to pass | ||
123 | */ | ||
124 | struct GNUNET_SQ_QueryParam | ||
125 | GNUNET_SQ_query_param_uint64 (const uint64_t *x) | ||
126 | { | ||
127 | } | ||
128 | |||
129 | /* end of sq_query_helper.c */ | ||
diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c new file mode 100644 index 000000000..361fea7bf --- /dev/null +++ b/src/sq/sq_result_helper.c | |||
@@ -0,0 +1,164 @@ | |||
1 | |||
2 | /* | ||
3 | This file is part of GNUnet | ||
4 | Copyright (C) 2017 GNUnet e.V. | ||
5 | |||
6 | GNUnet is free software; you can redistribute it and/or modify it under the | ||
7 | terms of the GNU General Public License as published by the Free Software | ||
8 | Foundation; either version 3, or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | ||
11 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
12 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along with | ||
15 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | ||
16 | */ | ||
17 | /** | ||
18 | * @file sq/sq_result_helper.c | ||
19 | * @brief helper functions for queries | ||
20 | * @author Christian Grothoff | ||
21 | */ | ||
22 | #include "platform.h" | ||
23 | #include "gnunet_sq_lib.h" | ||
24 | |||
25 | |||
26 | /** | ||
27 | * Variable-size result expected. | ||
28 | * | ||
29 | * @param[out] dst where to store the result, allocated | ||
30 | * @param[out] sptr where to store the size of @a dst | ||
31 | * @return array entry for the result specification to use | ||
32 | */ | ||
33 | struct GNUNET_SQ_ResultSpec | ||
34 | GNUNET_SQ_result_spec_variable_size (void **dst, | ||
35 | size_t *sptr) | ||
36 | { | ||
37 | } | ||
38 | |||
39 | |||
40 | /** | ||
41 | * Fixed-size result expected. | ||
42 | * | ||
43 | * @param[out] dst where to store the result | ||
44 | * @param dst_size number of bytes in @a dst | ||
45 | * @return array entry for the result specification to use | ||
46 | */ | ||
47 | struct GNUNET_SQ_ResultSpec | ||
48 | GNUNET_SQ_result_spec_fixed_size (void *dst, | ||
49 | size_t dst_size) | ||
50 | { | ||
51 | } | ||
52 | |||
53 | |||
54 | /** | ||
55 | * Variable-size result expected. | ||
56 | * | ||
57 | * @param[out] dst where to store the result, allocated | ||
58 | * @param[out] sptr where to store the size of @a dst | ||
59 | * @return array entry for the result specification to use | ||
60 | */ | ||
61 | struct GNUNET_SQ_ResultSpec | ||
62 | GNUNET_SQ_result_spec_variable_size (void **dst, | ||
63 | size_t *sptr) | ||
64 | { | ||
65 | } | ||
66 | |||
67 | |||
68 | /** | ||
69 | * 0-terminated string expected. | ||
70 | * | ||
71 | * @param[out] dst where to store the result, allocated | ||
72 | * @return array entry for the result specification to use | ||
73 | */ | ||
74 | struct GNUNET_SQ_ResultSpec | ||
75 | GNUNET_SQ_result_spec_string (char **dst) | ||
76 | { | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * RSA public key expected. | ||
82 | * | ||
83 | * @param[out] rsa where to store the result | ||
84 | * @return array entry for the result specification to use | ||
85 | */ | ||
86 | struct GNUNET_SQ_ResultSpec | ||
87 | GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) | ||
88 | { | ||
89 | } | ||
90 | |||
91 | |||
92 | /** | ||
93 | * RSA signature expected. | ||
94 | * | ||
95 | * @param[out] sig where to store the result; | ||
96 | * @return array entry for the result specification to use | ||
97 | */ | ||
98 | struct GNUNET_SQ_ResultSpec | ||
99 | GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) | ||
100 | { | ||
101 | } | ||
102 | |||
103 | |||
104 | /** | ||
105 | * Absolute time expected. | ||
106 | * | ||
107 | * @param[out] at where to store the result | ||
108 | * @return array entry for the result specification to use | ||
109 | */ | ||
110 | struct GNUNET_SQ_ResultSpec | ||
111 | GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) | ||
112 | { | ||
113 | } | ||
114 | |||
115 | |||
116 | /** | ||
117 | * Absolute time expected. | ||
118 | * | ||
119 | * @param[out] at where to store the result | ||
120 | * @return array entry for the result specification to use | ||
121 | */ | ||
122 | struct GNUNET_SQ_ResultSpec | ||
123 | GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) | ||
124 | { | ||
125 | } | ||
126 | |||
127 | |||
128 | /** | ||
129 | * uint16_t expected. | ||
130 | * | ||
131 | * @param[out] u16 where to store the result | ||
132 | * @return array entry for the result specification to use | ||
133 | */ | ||
134 | struct GNUNET_SQ_ResultSpec | ||
135 | GNUNET_SQ_result_spec_uint16 (uint16_t *u16) | ||
136 | { | ||
137 | } | ||
138 | |||
139 | |||
140 | /** | ||
141 | * uint32_t expected. | ||
142 | * | ||
143 | * @param[out] u32 where to store the result | ||
144 | * @return array entry for the result specification to use | ||
145 | */ | ||
146 | struct GNUNET_SQ_ResultSpec | ||
147 | GNUNET_SQ_result_spec_uint32 (uint32_t *u32) | ||
148 | { | ||
149 | } | ||
150 | |||
151 | |||
152 | /** | ||
153 | * uint64_t expected. | ||
154 | * | ||
155 | * @param[out] u64 where to store the result | ||
156 | * @return array entry for the result specification to use | ||
157 | */ | ||
158 | struct GNUNET_SQ_ResultSpec | ||
159 | GNUNET_SQ_result_spec_uint64 (uint64_t *u64) | ||
160 | { | ||
161 | } | ||
162 | |||
163 | |||
164 | /* end of sq_result_helper.c */ | ||