aboutsummaryrefslogtreecommitdiff
path: root/src/my
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/my
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/my')
-rw-r--r--src/my/my.c274
-rw-r--r--src/my/my_query_helper.c153
-rw-r--r--src/my/my_result_helper.c600
-rw-r--r--src/my/test_my.c366
4 files changed, 701 insertions, 692 deletions
diff --git a/src/my/my.c b/src/my/my.c
index dd2140c31..bee18145d 100644
--- a/src/my/my.c
+++ b/src/my/my.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file my/my.c 21 * @file my/my.c
22 * @brief library to help with access to a MySQL database 22 * @brief library to help with access to a MySQL database
@@ -35,69 +35,69 @@
35 * @param sh handle to SELECT statment 35 * @param sh handle to SELECT statment
36 * @param params parameters to the statement 36 * @param params parameters to the statement
37 * @return 37 * @return
38 #GNUNET_YES if we can prepare all statement 38 #GNUNET_YES if we can prepare all statement
39 #GNUNET_SYSERR if we can't prepare all statement 39 #GNUNET_SYSERR if we can't prepare all statement
40 */ 40 */
41int 41int
42GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, 42GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc,
43 struct GNUNET_MYSQL_StatementHandle *sh, 43 struct GNUNET_MYSQL_StatementHandle *sh,
44 struct GNUNET_MY_QueryParam *params) 44 struct GNUNET_MY_QueryParam *params)
45{ 45{
46 const struct GNUNET_MY_QueryParam *p; 46 const struct GNUNET_MY_QueryParam *p;
47 unsigned int num; 47 unsigned int num;
48 MYSQL_STMT *stmt; 48 MYSQL_STMT *stmt;
49 49
50 num = 0; 50 num = 0;
51 for (unsigned int i=0;NULL != params[i].conv;i++) 51 for (unsigned int i = 0; NULL != params[i].conv; i++)
52 num += params[i].num_params; 52 num += params[i].num_params;
53 { 53 {
54 MYSQL_BIND qbind[num]; 54 MYSQL_BIND qbind[num];
55 unsigned int off; 55 unsigned int off;
56 56
57 memset (qbind, 57 memset(qbind,
58 0, 58 0,
59 sizeof(qbind)); 59 sizeof(qbind));
60 off = 0; 60 off = 0;
61 for (unsigned int i=0;NULL != (p = &params[i])->conv;i++) 61 for (unsigned int i = 0; NULL != (p = &params[i])->conv; i++)
62 { 62 {
63 if (GNUNET_OK != 63 if (GNUNET_OK !=
64 p->conv (p->conv_cls, 64 p->conv(p->conv_cls,
65 p, 65 p,
66 &qbind[off])) 66 &qbind[off]))
67 {
68 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
69 "Conversion for MySQL query failed at offset %u\n",
70 i);
71 return GNUNET_SYSERR;
72 }
73 off += p->num_params;
74 }
75 stmt = GNUNET_MYSQL_statement_get_stmt(sh);
76 if (mysql_stmt_bind_param(stmt,
77 qbind))
67 { 78 {
68 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 79 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
69 "Conversion for MySQL query failed at offset %u\n", 80 "my",
70 i); 81 _("`%s' failed at %s:%d with error: %s\n"),
82 "mysql_stmt_bind_param",
83 __FILE__, __LINE__,
84 mysql_stmt_error(stmt));
85 GNUNET_MYSQL_statements_invalidate(mc);
71 return GNUNET_SYSERR; 86 return GNUNET_SYSERR;
72 } 87 }
73 off += p->num_params;
74 }
75 stmt = GNUNET_MYSQL_statement_get_stmt (sh);
76 if (mysql_stmt_bind_param (stmt,
77 qbind))
78 {
79 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
80 "my",
81 _("`%s' failed at %s:%d with error: %s\n"),
82 "mysql_stmt_bind_param",
83 __FILE__, __LINE__,
84 mysql_stmt_error (stmt));
85 GNUNET_MYSQL_statements_invalidate (mc);
86 return GNUNET_SYSERR;
87 }
88 88
89 if (mysql_stmt_execute (stmt)) 89 if (mysql_stmt_execute(stmt))
90 { 90 {
91 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 91 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
92 "my", 92 "my",
93 _("`%s' failed at %s:%d with error: %s\n"), 93 _("`%s' failed at %s:%d with error: %s\n"),
94 "mysql_stmt_execute", __FILE__, __LINE__, 94 "mysql_stmt_execute", __FILE__, __LINE__,
95 mysql_stmt_error (stmt)); 95 mysql_stmt_error(stmt));
96 GNUNET_MYSQL_statements_invalidate (mc); 96 GNUNET_MYSQL_statements_invalidate(mc);
97 return GNUNET_SYSERR; 97 return GNUNET_SYSERR;
98 } 98 }
99 GNUNET_MY_cleanup_query (params, 99 GNUNET_MY_cleanup_query(params,
100 qbind); 100 qbind);
101 } 101 }
102 return GNUNET_OK; 102 return GNUNET_OK;
103} 103}
@@ -111,13 +111,13 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
111 * @param qbind array of parameter to clean up 111 * @param qbind array of parameter to clean up
112 */ 112 */
113void 113void
114GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp, 114GNUNET_MY_cleanup_query(struct GNUNET_MY_QueryParam *qp,
115 MYSQL_BIND *qbind) 115 MYSQL_BIND *qbind)
116{ 116{
117 for (unsigned int i=0; NULL != qp[i].conv ;i++) 117 for (unsigned int i = 0; NULL != qp[i].conv; i++)
118 if (NULL != qp[i].cleaner) 118 if (NULL != qp[i].cleaner)
119 qp[i].cleaner (qp[i].conv_cls, 119 qp[i].cleaner(qp[i].conv_cls,
120 &qbind[i]); 120 &qbind[i]);
121} 121}
122 122
123 123
@@ -133,115 +133,115 @@ GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp,
133 * #GNUNET_SYSERR if a result was invalid 133 * #GNUNET_SYSERR if a result was invalid
134 */ 134 */
135int 135int
136GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, 136GNUNET_MY_extract_result(struct GNUNET_MYSQL_StatementHandle *sh,
137 struct GNUNET_MY_ResultSpec *rs) 137 struct GNUNET_MY_ResultSpec *rs)
138{ 138{
139 unsigned int num_fields; 139 unsigned int num_fields;
140 int ret; 140 int ret;
141 MYSQL_STMT *stmt; 141 MYSQL_STMT *stmt;
142 142
143 stmt = GNUNET_MYSQL_statement_get_stmt (sh); 143 stmt = GNUNET_MYSQL_statement_get_stmt(sh);
144 if (NULL == stmt) 144 if (NULL == stmt)
145 { 145 {
146 GNUNET_break (0); 146 GNUNET_break(0);
147 return GNUNET_SYSERR; 147 return GNUNET_SYSERR;
148 } 148 }
149 if (NULL == rs) 149 if (NULL == rs)
150 { 150 {
151 mysql_stmt_free_result (stmt); 151 mysql_stmt_free_result(stmt);
152 return GNUNET_NO; 152 return GNUNET_NO;
153 } 153 }
154 154
155 num_fields = 0; 155 num_fields = 0;
156 for (unsigned int i=0;NULL != rs[i].pre_conv;i++) 156 for (unsigned int i = 0; NULL != rs[i].pre_conv; i++)
157 num_fields += rs[i].num_fields; 157 num_fields += rs[i].num_fields;
158 158
159 if (mysql_stmt_field_count (stmt) != num_fields) 159 if (mysql_stmt_field_count(stmt) != num_fields)
160 { 160 {
161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 161 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
162 "Number of fields mismatch between SQL result and result specification\n"); 162 "Number of fields mismatch between SQL result and result specification\n");
163 return GNUNET_SYSERR; 163 return GNUNET_SYSERR;
164 } 164 }
165 165
166 { 166 {
167 MYSQL_BIND result[num_fields]; 167 MYSQL_BIND result[num_fields];
168 unsigned int field_off; 168 unsigned int field_off;
169 169
170 memset (result, 0, sizeof (MYSQL_BIND) * num_fields); 170 memset(result, 0, sizeof(MYSQL_BIND) * num_fields);
171 field_off = 0; 171 field_off = 0;
172 for (unsigned int i=0;NULL != rs[i].pre_conv;i++) 172 for (unsigned int i = 0; NULL != rs[i].pre_conv; i++)
173 { 173 {
174 struct GNUNET_MY_ResultSpec *rp = &rs[i]; 174 struct GNUNET_MY_ResultSpec *rp = &rs[i];
175 175
176 if (GNUNET_OK != 176 if (GNUNET_OK !=
177 rp->pre_conv (rp->conv_cls, 177 rp->pre_conv(rp->conv_cls,
178 rp, 178 rp,
179 stmt, 179 stmt,
180 field_off, 180 field_off,
181 &result[field_off])) 181 &result[field_off]))
182
183 {
184 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
185 "Pre-conversion for MySQL result failed at offset %u\n",
186 i);
187 return GNUNET_SYSERR;
188 }
189 field_off += rp->num_fields;
190 }
182 191
192 if (mysql_stmt_bind_result(stmt, result))
183 { 193 {
184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 194 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
185 "Pre-conversion for MySQL result failed at offset %u\n", 195 "my",
186 i); 196 _("%s failed at %s:%d with error: %s\n"),
197 "mysql_stmt_bind_result",
198 __FILE__, __LINE__,
199 mysql_stmt_error(stmt));
187 return GNUNET_SYSERR; 200 return GNUNET_SYSERR;
188 } 201 }
189 field_off += rp->num_fields;
190 }
191
192 if (mysql_stmt_bind_result (stmt, result))
193 {
194 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
195 "my",
196 _("%s failed at %s:%d with error: %s\n"),
197 "mysql_stmt_bind_result",
198 __FILE__, __LINE__,
199 mysql_stmt_error (stmt));
200 return GNUNET_SYSERR;
201 }
202#if TEST_OPTIMIZATION 202#if TEST_OPTIMIZATION
203 (void) mysql_stmt_store_result (stmt); 203 (void)mysql_stmt_store_result(stmt);
204#endif 204#endif
205 ret = mysql_stmt_fetch (stmt); 205 ret = mysql_stmt_fetch(stmt);
206 if (MYSQL_NO_DATA == ret) 206 if (MYSQL_NO_DATA == ret)
207 { 207 {
208 mysql_stmt_free_result (stmt); 208 mysql_stmt_free_result(stmt);
209 return GNUNET_NO; 209 return GNUNET_NO;
210 } 210 }
211 if (1 == ret) 211 if (1 == ret)
212 { 212 {
213 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 213 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR,
214 "my", 214 "my",
215 _("%s failed at %s:%d with error: %s\n"), 215 _("%s failed at %s:%d with error: %s\n"),
216 "mysql_stmt_fetch", 216 "mysql_stmt_fetch",
217 __FILE__, __LINE__, 217 __FILE__, __LINE__,
218 mysql_stmt_error (stmt)); 218 mysql_stmt_error(stmt));
219 GNUNET_MY_cleanup_result (rs); 219 GNUNET_MY_cleanup_result(rs);
220 mysql_stmt_free_result (stmt); 220 mysql_stmt_free_result(stmt);
221 return GNUNET_SYSERR; 221 return GNUNET_SYSERR;
222 } 222 }
223 field_off = 0; 223 field_off = 0;
224 for (unsigned int i=0;NULL != rs[i].post_conv;i++) 224 for (unsigned int i = 0; NULL != rs[i].post_conv; i++)
225 { 225 {
226 struct GNUNET_MY_ResultSpec *rp = &rs[i]; 226 struct GNUNET_MY_ResultSpec *rp = &rs[i];
227 227
228 if (NULL != rp->post_conv) 228 if (NULL != rp->post_conv)
229 if (GNUNET_OK != 229 if (GNUNET_OK !=
230 rp->post_conv (rp->conv_cls, 230 rp->post_conv(rp->conv_cls,
231 rp, 231 rp,
232 stmt, 232 stmt,
233 field_off, 233 field_off,
234 &result[field_off])) 234 &result[field_off]))
235 { 235 {
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 236 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
237 "Post-conversion for MySQL result failed at offset %u\n", 237 "Post-conversion for MySQL result failed at offset %u\n",
238 i); 238 i);
239 mysql_stmt_free_result (stmt); 239 mysql_stmt_free_result(stmt);
240 GNUNET_MY_cleanup_result (rs); 240 GNUNET_MY_cleanup_result(rs);
241 return GNUNET_SYSERR; 241 return GNUNET_SYSERR;
242 } 242 }
243 field_off += rp->num_fields; 243 field_off += rp->num_fields;
244 } 244 }
245 } 245 }
246 return GNUNET_OK; 246 return GNUNET_OK;
247} 247}
@@ -254,12 +254,12 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
254 * @param rs result specification to clean up 254 * @param rs result specification to clean up
255 */ 255 */
256void 256void
257GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs) 257GNUNET_MY_cleanup_result(struct GNUNET_MY_ResultSpec *rs)
258{ 258{
259 for (unsigned int i=0;NULL != rs[i].post_conv;i++) 259 for (unsigned int i = 0; NULL != rs[i].post_conv; i++)
260 if (NULL != rs[i].cleaner) 260 if (NULL != rs[i].cleaner)
261 rs[i].cleaner (rs[i].conv_cls, 261 rs[i].cleaner(rs[i].conv_cls,
262 &rs[i]); 262 &rs[i]);
263} 263}
264 264
265 265
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c
index 8d4435b01..764021057 100644
--- a/src/my/my_query_helper.c
+++ b/src/my/my_query_helper.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file my/my_query_helper.c 21 * @file my/my_query_helper.c
22 * @brief library to help with access to a MySQL database 22 * @brief library to help with access to a MySQL database
@@ -36,11 +36,11 @@
36 * @param qbind array of parameter to clean up 36 * @param qbind array of parameter to clean up
37 */ 37 */
38static void 38static void
39my_clean_query (void *cls, 39my_clean_query(void *cls,
40 MYSQL_BIND *qbind) 40 MYSQL_BIND *qbind)
41{ 41{
42 (void) cls; 42 (void)cls;
43 GNUNET_free (qbind[0].buffer); 43 GNUNET_free(qbind[0].buffer);
44} 44}
45 45
46 46
@@ -53,13 +53,13 @@ my_clean_query (void *cls,
53 * @return -1 on error 53 * @return -1 on error
54 */ 54 */
55static int 55static int
56my_conv_fixed_size (void *cls, 56my_conv_fixed_size(void *cls,
57 const struct GNUNET_MY_QueryParam *qp, 57 const struct GNUNET_MY_QueryParam *qp,
58 MYSQL_BIND *qbind) 58 MYSQL_BIND *qbind)
59{ 59{
60 (void) cls; 60 (void)cls;
61 GNUNET_assert (1 == qp->num_params); 61 GNUNET_assert(1 == qp->num_params);
62 qbind->buffer = (void *) qp->data; 62 qbind->buffer = (void *)qp->data;
63 qbind->buffer_length = qp->data_len; 63 qbind->buffer_length = qp->data_len;
64 qbind->buffer_type = MYSQL_TYPE_BLOB; 64 qbind->buffer_type = MYSQL_TYPE_BLOB;
65 65
@@ -75,8 +75,8 @@ my_conv_fixed_size (void *cls,
75 * @param ptr_size number of bytes in @a ptr 75 * @param ptr_size number of bytes in @a ptr
76 */ 76 */
77struct GNUNET_MY_QueryParam 77struct GNUNET_MY_QueryParam
78GNUNET_MY_query_param_fixed_size (const void *ptr, 78GNUNET_MY_query_param_fixed_size(const void *ptr,
79 size_t ptr_size) 79 size_t ptr_size)
80{ 80{
81 struct GNUNET_MY_QueryParam qp = { 81 struct GNUNET_MY_QueryParam qp = {
82 .conv = &my_conv_fixed_size, 82 .conv = &my_conv_fixed_size,
@@ -84,8 +84,9 @@ GNUNET_MY_query_param_fixed_size (const void *ptr,
84 .conv_cls = NULL, 84 .conv_cls = NULL,
85 .num_params = 1, 85 .num_params = 1,
86 .data = ptr, 86 .data = ptr,
87 .data_len = (unsigned long) ptr_size 87 .data_len = (unsigned long)ptr_size
88 }; 88 };
89
89 return qp; 90 return qp;
90} 91}
91 92
@@ -99,13 +100,13 @@ GNUNET_MY_query_param_fixed_size (const void *ptr,
99 * @return -1 on error 100 * @return -1 on error
100 */ 101 */
101static int 102static int
102my_conv_string (void *cls, 103my_conv_string(void *cls,
103 const struct GNUNET_MY_QueryParam *qp, 104 const struct GNUNET_MY_QueryParam *qp,
104 MYSQL_BIND *qbind) 105 MYSQL_BIND *qbind)
105{ 106{
106 (void) cls; 107 (void)cls;
107 GNUNET_assert (1 == qp->num_params); 108 GNUNET_assert(1 == qp->num_params);
108 qbind->buffer = (void *) qp->data; 109 qbind->buffer = (void *)qp->data;
109 qbind->buffer_length = qp->data_len; 110 qbind->buffer_length = qp->data_len;
110 qbind->buffer_type = MYSQL_TYPE_STRING; 111 qbind->buffer_type = MYSQL_TYPE_STRING;
111 return 1; 112 return 1;
@@ -118,7 +119,7 @@ my_conv_string (void *cls,
118 * @param ptr pointer to the string query parameter to pass 119 * @param ptr pointer to the string query parameter to pass
119 */ 120 */
120struct GNUNET_MY_QueryParam 121struct GNUNET_MY_QueryParam
121GNUNET_MY_query_param_string (const char *ptr) 122GNUNET_MY_query_param_string(const char *ptr)
122{ 123{
123 struct GNUNET_MY_QueryParam qp = { 124 struct GNUNET_MY_QueryParam qp = {
124 .conv = &my_conv_string, 125 .conv = &my_conv_string,
@@ -126,8 +127,9 @@ GNUNET_MY_query_param_string (const char *ptr)
126 .conv_cls = NULL, 127 .conv_cls = NULL,
127 .num_params = 1, 128 .num_params = 1,
128 .data = ptr, 129 .data = ptr,
129 .data_len = strlen (ptr) 130 .data_len = strlen(ptr)
130 }; 131 };
132
131 return qp; 133 return qp;
132} 134}
133 135
@@ -141,14 +143,14 @@ GNUNET_MY_query_param_string (const char *ptr)
141 * @return -1 on error 143 * @return -1 on error
142 */ 144 */
143static int 145static int
144my_conv_uint16 (void *cls, 146my_conv_uint16(void *cls,
145 const struct GNUNET_MY_QueryParam *qp, 147 const struct GNUNET_MY_QueryParam *qp,
146 MYSQL_BIND *qbind) 148 MYSQL_BIND *qbind)
147{ 149{
148 (void) cls; 150 (void)cls;
149 GNUNET_assert (1 == qp->num_params); 151 GNUNET_assert(1 == qp->num_params);
150 qbind->buffer = (void *) qp->data; 152 qbind->buffer = (void *)qp->data;
151 qbind->buffer_length = sizeof (uint16_t); 153 qbind->buffer_length = sizeof(uint16_t);
152 qbind->buffer_type = MYSQL_TYPE_SHORT; 154 qbind->buffer_type = MYSQL_TYPE_SHORT;
153 qbind->is_unsigned = 1; 155 qbind->is_unsigned = 1;
154 return 1; 156 return 1;
@@ -161,7 +163,7 @@ my_conv_uint16 (void *cls,
161 * @param x pointer to the query parameter to pass 163 * @param x pointer to the query parameter to pass
162 */ 164 */
163struct GNUNET_MY_QueryParam 165struct GNUNET_MY_QueryParam
164GNUNET_MY_query_param_uint16 (const uint16_t *x) 166GNUNET_MY_query_param_uint16(const uint16_t *x)
165{ 167{
166 struct GNUNET_MY_QueryParam res = { 168 struct GNUNET_MY_QueryParam res = {
167 .conv = &my_conv_uint16, 169 .conv = &my_conv_uint16,
@@ -169,7 +171,7 @@ GNUNET_MY_query_param_uint16 (const uint16_t *x)
169 .conv_cls = NULL, 171 .conv_cls = NULL,
170 .num_params = 1, 172 .num_params = 1,
171 .data = x, 173 .data = x,
172 .data_len = sizeof (*x) 174 .data_len = sizeof(*x)
173 }; 175 };
174 176
175 return res; 177 return res;
@@ -185,13 +187,13 @@ GNUNET_MY_query_param_uint16 (const uint16_t *x)
185 * @return -1 on error 187 * @return -1 on error
186 */ 188 */
187static int 189static int
188my_conv_uint32 (void *cls, 190my_conv_uint32(void *cls,
189 const struct GNUNET_MY_QueryParam *qp, 191 const struct GNUNET_MY_QueryParam *qp,
190 MYSQL_BIND *qbind) 192 MYSQL_BIND *qbind)
191{ 193{
192 (void) cls; 194 (void)cls;
193 GNUNET_assert (1 == qp->num_params); 195 GNUNET_assert(1 == qp->num_params);
194 qbind->buffer = (void *) qp->data; 196 qbind->buffer = (void *)qp->data;
195 qbind->buffer_length = sizeof(uint32_t); 197 qbind->buffer_length = sizeof(uint32_t);
196 qbind->buffer_type = MYSQL_TYPE_LONG; 198 qbind->buffer_type = MYSQL_TYPE_LONG;
197 qbind->is_unsigned = 1; 199 qbind->is_unsigned = 1;
@@ -205,7 +207,7 @@ my_conv_uint32 (void *cls,
205 * @param x pointer to the query parameter to pass 207 * @param x pointer to the query parameter to pass
206 */ 208 */
207struct GNUNET_MY_QueryParam 209struct GNUNET_MY_QueryParam
208GNUNET_MY_query_param_uint32 (const uint32_t *x) 210GNUNET_MY_query_param_uint32(const uint32_t *x)
209{ 211{
210 struct GNUNET_MY_QueryParam res = { 212 struct GNUNET_MY_QueryParam res = {
211 .conv = &my_conv_uint32, 213 .conv = &my_conv_uint32,
@@ -213,7 +215,7 @@ GNUNET_MY_query_param_uint32 (const uint32_t *x)
213 .conv_cls = NULL, 215 .conv_cls = NULL,
214 .num_params = 1, 216 .num_params = 1,
215 .data = x, 217 .data = x,
216 .data_len = sizeof (*x) 218 .data_len = sizeof(*x)
217 }; 219 };
218 220
219 return res; 221 return res;
@@ -229,14 +231,14 @@ GNUNET_MY_query_param_uint32 (const uint32_t *x)
229 * @return -1 on error 231 * @return -1 on error
230 */ 232 */
231static int 233static int
232my_conv_uint64 (void *cls, 234my_conv_uint64(void *cls,
233 const struct GNUNET_MY_QueryParam *qp, 235 const struct GNUNET_MY_QueryParam *qp,
234 MYSQL_BIND * qbind) 236 MYSQL_BIND * qbind)
235{ 237{
236 (void) cls; 238 (void)cls;
237 GNUNET_assert (1 == qp->num_params); 239 GNUNET_assert(1 == qp->num_params);
238 qbind->buffer = (void *) qp->data; 240 qbind->buffer = (void *)qp->data;
239 qbind->buffer_length = sizeof (uint64_t); 241 qbind->buffer_length = sizeof(uint64_t);
240 qbind->buffer_type = MYSQL_TYPE_LONGLONG; 242 qbind->buffer_type = MYSQL_TYPE_LONGLONG;
241 qbind->is_unsigned = 1; 243 qbind->is_unsigned = 1;
242 return 1; 244 return 1;
@@ -249,7 +251,7 @@ my_conv_uint64 (void *cls,
249 * @param x pointer to the query parameter to pass 251 * @param x pointer to the query parameter to pass
250 */ 252 */
251struct GNUNET_MY_QueryParam 253struct GNUNET_MY_QueryParam
252GNUNET_MY_query_param_uint64 (const uint64_t *x) 254GNUNET_MY_query_param_uint64(const uint64_t *x)
253{ 255{
254 struct GNUNET_MY_QueryParam res = { 256 struct GNUNET_MY_QueryParam res = {
255 .conv = &my_conv_uint64, 257 .conv = &my_conv_uint64,
@@ -273,19 +275,19 @@ GNUNET_MY_query_param_uint64 (const uint64_t *x)
273 * @return -1 on error 275 * @return -1 on error
274 */ 276 */
275static int 277static int
276my_conv_rsa_public_key (void *cls, 278my_conv_rsa_public_key(void *cls,
277 const struct GNUNET_MY_QueryParam *qp, 279 const struct GNUNET_MY_QueryParam *qp,
278 MYSQL_BIND * qbind) 280 MYSQL_BIND * qbind)
279{ 281{
280 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data; 282 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data;
281 char *buf; 283 char *buf;
282 size_t buf_size; 284 size_t buf_size;
283 285
284 (void) cls; 286 (void)cls;
285 GNUNET_assert(1 == qp->num_params); 287 GNUNET_assert(1 == qp->num_params);
286 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, 288 buf_size = GNUNET_CRYPTO_rsa_public_key_encode(rsa,
287 &buf); 289 &buf);
288 qbind->buffer = (void *) buf; 290 qbind->buffer = (void *)buf;
289 qbind->buffer_length = buf_size; 291 qbind->buffer_length = buf_size;
290 qbind->buffer_type = MYSQL_TYPE_BLOB; 292 qbind->buffer_type = MYSQL_TYPE_BLOB;
291 return 1; 293 return 1;
@@ -300,7 +302,7 @@ my_conv_rsa_public_key (void *cls,
300 * @return array entry for the query parameters to use 302 * @return array entry for the query parameters to use
301 */ 303 */
302struct GNUNET_MY_QueryParam 304struct GNUNET_MY_QueryParam
303GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) 305GNUNET_MY_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x)
304{ 306{
305 struct GNUNET_MY_QueryParam res = { 307 struct GNUNET_MY_QueryParam res = {
306 .conv = &my_conv_rsa_public_key, 308 .conv = &my_conv_rsa_public_key,
@@ -316,27 +318,27 @@ GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x
316 318
317 319
318/** 320/**
319 * Function called to convert input argument into SQL parameters 321 * Function called to convert input argument into SQL parameters
320 * 322 *
321 *@param cls closure 323 *@param cls closure
322 *@param pq data about the query 324 *@param pq data about the query
323 *@param qbind array of parameters to initialize 325 *@param qbind array of parameters to initialize
324 *@return -1 on error 326 *@return -1 on error
325 */ 327 */
326static int 328static int
327my_conv_rsa_signature (void *cls, 329my_conv_rsa_signature(void *cls,
328 const struct GNUNET_MY_QueryParam *qp, 330 const struct GNUNET_MY_QueryParam *qp,
329 MYSQL_BIND *qbind) 331 MYSQL_BIND *qbind)
330{ 332{
331 const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data; 333 const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data;
332 char *buf; 334 char *buf;
333 size_t buf_size; 335 size_t buf_size;
334 336
335 (void) cls; 337 (void)cls;
336 GNUNET_assert(1 == qp->num_params); 338 GNUNET_assert(1 == qp->num_params);
337 buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig, 339 buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig,
338 &buf); 340 &buf);
339 qbind->buffer = (void *) buf; 341 qbind->buffer = (void *)buf;
340 qbind->buffer_length = buf_size; 342 qbind->buffer_length = buf_size;
341 qbind->buffer_type = MYSQL_TYPE_BLOB; 343 qbind->buffer_type = MYSQL_TYPE_BLOB;
342 return 1; 344 return 1;
@@ -351,7 +353,7 @@ my_conv_rsa_signature (void *cls,
351 * @return array entry for the query parameters to use 353 * @return array entry for the query parameters to use
352 */ 354 */
353struct GNUNET_MY_QueryParam 355struct GNUNET_MY_QueryParam
354GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) 356GNUNET_MY_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
355{ 357{
356 struct GNUNET_MY_QueryParam res = { 358 struct GNUNET_MY_QueryParam res = {
357 .conv = &my_conv_rsa_signature, 359 .conv = &my_conv_rsa_signature,
@@ -361,6 +363,7 @@ GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
361 .data = (x), 363 .data = (x),
362 .data_len = 0 364 .data_len = 0
363 }; 365 };
366
364 return res; 367 return res;
365} 368}
366 369
@@ -373,9 +376,9 @@ GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
373 * @return array entry for the query parameters to use 376 * @return array entry for the query parameters to use
374 */ 377 */
375struct GNUNET_MY_QueryParam 378struct GNUNET_MY_QueryParam
376GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) 379GNUNET_MY_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
377{ 380{
378 return GNUNET_MY_query_param_uint64 (&x->abs_value_us); 381 return GNUNET_MY_query_param_uint64(&x->abs_value_us);
379} 382}
380 383
381 384
@@ -386,9 +389,9 @@ GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
386 * @param x pointer to the query parameter to pass 389 * @param x pointer to the query parameter to pass
387 */ 390 */
388struct GNUNET_MY_QueryParam 391struct GNUNET_MY_QueryParam
389GNUNET_MY_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x) 392GNUNET_MY_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x)
390{ 393{
391 return GNUNET_MY_query_param_auto_from_type (&x->abs_value_us__); 394 return GNUNET_MY_query_param_auto_from_type(&x->abs_value_us__);
392} 395}
393 396
394 397
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c
index 75a340014..2fedc1f19 100644
--- a/src/my/my_result_helper.c
+++ b/src/my/my_result_helper.c
@@ -1,22 +1,22 @@
1 /* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2014, 2015, 2016 GNUnet e.V. 3 Copyright (C) 2014, 2015, 2016 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file my/my_result_helper.c 21 * @file my/my_result_helper.c
22 * @brief functions to extract result values 22 * @brief functions to extract result values
@@ -41,11 +41,11 @@
41 * #GNUNET_SYSERR if a result was invalid 41 * #GNUNET_SYSERR if a result was invalid
42 */ 42 */
43static int 43static int
44pre_extract_varsize_blob (void *cls, 44pre_extract_varsize_blob(void *cls,
45 struct GNUNET_MY_ResultSpec *rs, 45 struct GNUNET_MY_ResultSpec *rs,
46 MYSQL_STMT *stmt, 46 MYSQL_STMT *stmt,
47 unsigned int column, 47 unsigned int column,
48 MYSQL_BIND *results) 48 MYSQL_BIND *results)
49{ 49{
50 results[0].buffer = NULL; 50 results[0].buffer = NULL;
51 results[0].buffer_length = 0; 51 results[0].buffer_length = 0;
@@ -70,39 +70,39 @@ pre_extract_varsize_blob (void *cls,
70 * #GNUNET_SYSERR if a result was invalid 70 * #GNUNET_SYSERR if a result was invalid
71 */ 71 */
72static int 72static int
73post_extract_varsize_blob (void *cls, 73post_extract_varsize_blob(void *cls,
74 struct GNUNET_MY_ResultSpec *rs, 74 struct GNUNET_MY_ResultSpec *rs,
75 MYSQL_STMT *stmt, 75 MYSQL_STMT *stmt,
76 unsigned int column, 76 unsigned int column,
77 MYSQL_BIND *results) 77 MYSQL_BIND *results)
78{ 78{
79 void *buf; 79 void *buf;
80 size_t size; 80 size_t size;
81 81
82 if (*results->is_null) 82 if (*results->is_null)
83 return GNUNET_SYSERR; 83 return GNUNET_SYSERR;
84 size = (size_t) rs->mysql_bind_output_length; 84 size = (size_t)rs->mysql_bind_output_length;
85 85
86 if (rs->mysql_bind_output_length != size) 86 if (rs->mysql_bind_output_length != size)
87 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ 87 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
88 88
89 buf = GNUNET_malloc (size); 89 buf = GNUNET_malloc(size);
90 90
91 results[0].buffer = buf; 91 results[0].buffer = buf;
92 results[0].buffer_length = size; 92 results[0].buffer_length = size;
93 results[0].buffer_type = MYSQL_TYPE_BLOB; 93 results[0].buffer_type = MYSQL_TYPE_BLOB;
94 94
95 if (0 != 95 if (0 !=
96 mysql_stmt_fetch_column (stmt, 96 mysql_stmt_fetch_column(stmt,
97 results, 97 results,
98 column, 98 column,
99 0)) 99 0))
100 { 100 {
101 GNUNET_free (buf); 101 GNUNET_free(buf);
102 return GNUNET_SYSERR; 102 return GNUNET_SYSERR;
103 } 103 }
104 104
105 *(void **) rs->dst = buf; 105 *(void **)rs->dst = buf;
106 *rs->result_size = size; 106 *rs->result_size = size;
107 107
108 return GNUNET_OK; 108 return GNUNET_OK;
@@ -116,16 +116,16 @@ post_extract_varsize_blob (void *cls,
116 * @param[in,out] rs 116 * @param[in,out] rs
117 */ 117 */
118static void 118static void
119cleanup_varsize_blob (void *cls, 119cleanup_varsize_blob(void *cls,
120 struct GNUNET_MY_ResultSpec *rs) 120 struct GNUNET_MY_ResultSpec *rs)
121{ 121{
122 void **ptr = (void **)rs->dst; 122 void **ptr = (void **)rs->dst;
123 123
124 if (NULL != *ptr) 124 if (NULL != *ptr)
125 { 125 {
126 GNUNET_free (*ptr); 126 GNUNET_free(*ptr);
127 *ptr = NULL; 127 *ptr = NULL;
128 } 128 }
129} 129}
130 130
131 131
@@ -137,7 +137,7 @@ cleanup_varsize_blob (void *cls,
137 * @return array entru for the result specification to use 137 * @return array entru for the result specification to use
138 */ 138 */
139struct GNUNET_MY_ResultSpec 139struct GNUNET_MY_ResultSpec
140GNUNET_MY_result_spec_variable_size (void **dst, 140GNUNET_MY_result_spec_variable_size(void **dst,
141 size_t *ptr_size) 141 size_t *ptr_size)
142{ 142{
143 struct GNUNET_MY_ResultSpec res = 143 struct GNUNET_MY_ResultSpec res =
@@ -145,7 +145,7 @@ GNUNET_MY_result_spec_variable_size (void **dst,
145 .pre_conv = &pre_extract_varsize_blob, 145 .pre_conv = &pre_extract_varsize_blob,
146 .post_conv = &post_extract_varsize_blob, 146 .post_conv = &post_extract_varsize_blob,
147 .cleaner = &cleanup_varsize_blob, 147 .cleaner = &cleanup_varsize_blob,
148 .dst = (void *)(dst), 148 .dst = (void *)(dst),
149 .result_size = ptr_size, 149 .result_size = ptr_size,
150 .num_fields = 1 150 .num_fields = 1
151 }; 151 };
@@ -167,11 +167,11 @@ GNUNET_MY_result_spec_variable_size (void **dst,
167 * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) 167 * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL)
168 */ 168 */
169static int 169static int
170pre_extract_fixed_blob (void *cls, 170pre_extract_fixed_blob(void *cls,
171 struct GNUNET_MY_ResultSpec *rs, 171 struct GNUNET_MY_ResultSpec *rs,
172 MYSQL_STMT *stmt, 172 MYSQL_STMT *stmt,
173 unsigned int column, 173 unsigned int column,
174 MYSQL_BIND *results) 174 MYSQL_BIND *results)
175{ 175{
176 results[0].buffer = rs->dst; 176 results[0].buffer = rs->dst;
177 results[0].buffer_length = rs->dst_size; 177 results[0].buffer_length = rs->dst_size;
@@ -198,11 +198,11 @@ pre_extract_fixed_blob (void *cls,
198 * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) 198 * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL)
199 */ 199 */
200static int 200static int
201post_extract_fixed_blob (void *cls, 201post_extract_fixed_blob(void *cls,
202 struct GNUNET_MY_ResultSpec *rs, 202 struct GNUNET_MY_ResultSpec *rs,
203 MYSQL_STMT *stmt, 203 MYSQL_STMT *stmt,
204 unsigned int column, 204 unsigned int column,
205 MYSQL_BIND *results) 205 MYSQL_BIND *results)
206{ 206{
207 if (*results->is_null) 207 if (*results->is_null)
208 return GNUNET_SYSERR; 208 return GNUNET_SYSERR;
@@ -221,8 +221,8 @@ post_extract_fixed_blob (void *cls,
221 * @return array entry for the result specification to use 221 * @return array entry for the result specification to use
222 */ 222 */
223struct GNUNET_MY_ResultSpec 223struct GNUNET_MY_ResultSpec
224GNUNET_MY_result_spec_fixed_size (void *ptr, 224GNUNET_MY_result_spec_fixed_size(void *ptr,
225 size_t ptr_size) 225 size_t ptr_size)
226{ 226{
227 struct GNUNET_MY_ResultSpec res = 227 struct GNUNET_MY_ResultSpec res =
228 { 228 {
@@ -239,23 +239,23 @@ GNUNET_MY_result_spec_fixed_size (void *ptr,
239 239
240 240
241/** 241/**
242 * Extract data from a Mysql database @a result at row @a row 242 * Extract data from a Mysql database @a result at row @a row
243 * 243 *
244 * @param cls closure 244 * @param cls closure
245 * @param[in,out] rs 245 * @param[in,out] rs
246 * @param stmt the mysql statement that is being run 246 * @param stmt the mysql statement that is being run
247 * @param column the column that is being processed 247 * @param column the column that is being processed
248 * @param[out] results 248 * @param[out] results
249 * @return 249 * @return
250 * #GNUNET_OK if all results could be extracted 250 * #GNUNET_OK if all results could be extracted
251 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 251 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
252 */ 252 */
253static int 253static int
254pre_extract_rsa_public_key (void *cls, 254pre_extract_rsa_public_key(void *cls,
255 struct GNUNET_MY_ResultSpec *rs, 255 struct GNUNET_MY_ResultSpec *rs,
256 MYSQL_STMT *stmt, 256 MYSQL_STMT *stmt,
257 unsigned int column, 257 unsigned int column,
258 MYSQL_BIND *results) 258 MYSQL_BIND *results)
259{ 259{
260 results[0].buffer = NULL; 260 results[0].buffer = NULL;
261 results[0].buffer_length = 0; 261 results[0].buffer_length = 0;
@@ -269,24 +269,24 @@ pre_extract_rsa_public_key (void *cls,
269 269
270 270
271/** 271/**
272 * Check size of extracted fixed size data from a Mysql database @a 272 * Check size of extracted fixed size data from a Mysql database @a
273 * result at row @a row 273 * result at row @a row
274 * 274 *
275 * @param cls closure 275 * @param cls closure
276 * @param[in,out] rs 276 * @param[in,out] rs
277 * @param stmt the mysql statement that is being run 277 * @param stmt the mysql statement that is being run
278 * @param column the column that is being processed 278 * @param column the column that is being processed
279 * @param[out] results 279 * @param[out] results
280 * @return 280 * @return
281 * #GNUNET_OK if all results could be extracted 281 * #GNUNET_OK if all results could be extracted
282 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 282 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
283 */ 283 */
284static int 284static int
285post_extract_rsa_public_key (void *cls, 285post_extract_rsa_public_key(void *cls,
286 struct GNUNET_MY_ResultSpec *rs, 286 struct GNUNET_MY_ResultSpec *rs,
287 MYSQL_STMT *stmt, 287 MYSQL_STMT *stmt,
288 unsigned int column, 288 unsigned int column,
289 MYSQL_BIND *results) 289 MYSQL_BIND *results)
290 290
291{ 291{
292 struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; 292 struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst;
@@ -295,34 +295,34 @@ post_extract_rsa_public_key (void *cls,
295 295
296 if (*results->is_null) 296 if (*results->is_null)
297 return GNUNET_SYSERR; 297 return GNUNET_SYSERR;
298 size = (size_t) rs->mysql_bind_output_length; 298 size = (size_t)rs->mysql_bind_output_length;
299 299
300 if (rs->mysql_bind_output_length != size) 300 if (rs->mysql_bind_output_length != size)
301 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ 301 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
302 buf = GNUNET_malloc (size); 302 buf = GNUNET_malloc(size);
303 303
304 results[0].buffer = buf; 304 results[0].buffer = buf;
305 results[0].buffer_length = size; 305 results[0].buffer_length = size;
306 results[0].buffer_type = MYSQL_TYPE_BLOB; 306 results[0].buffer_type = MYSQL_TYPE_BLOB;
307 if (0 != 307 if (0 !=
308 mysql_stmt_fetch_column (stmt, 308 mysql_stmt_fetch_column(stmt,
309 results, 309 results,
310 column, 310 column,
311 0)) 311 0))
312 { 312 {
313 GNUNET_free (buf); 313 GNUNET_free(buf);
314 return GNUNET_SYSERR; 314 return GNUNET_SYSERR;
315 } 315 }
316 316
317 *pk = GNUNET_CRYPTO_rsa_public_key_decode (buf, 317 *pk = GNUNET_CRYPTO_rsa_public_key_decode(buf,
318 size); 318 size);
319 GNUNET_free (buf); 319 GNUNET_free(buf);
320 if (NULL == *pk) 320 if (NULL == *pk)
321 { 321 {
322 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 322 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
323 "Results contains bogus public key value (fail to decode)\n"); 323 "Results contains bogus public key value (fail to decode)\n");
324 return GNUNET_SYSERR; 324 return GNUNET_SYSERR;
325 } 325 }
326 326
327 return GNUNET_OK; 327 return GNUNET_OK;
328} 328}
@@ -336,34 +336,34 @@ post_extract_rsa_public_key (void *cls,
336 * @param rs result data to clean up 336 * @param rs result data to clean up
337 */ 337 */
338static void 338static void
339clean_rsa_public_key (void *cls, 339clean_rsa_public_key(void *cls,
340 struct GNUNET_MY_ResultSpec *rs) 340 struct GNUNET_MY_ResultSpec *rs)
341{ 341{
342 struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; 342 struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst;
343 343
344 if (NULL != *pk) 344 if (NULL != *pk)
345 { 345 {
346 GNUNET_CRYPTO_rsa_public_key_free (*pk); 346 GNUNET_CRYPTO_rsa_public_key_free(*pk);
347 *pk = NULL; 347 *pk = NULL;
348 } 348 }
349} 349}
350 350
351 351
352/** 352/**
353 * RSA public key expected 353 * RSA public key expected
354 * 354 *
355 * @param name name of the field in the table 355 * @param name name of the field in the table
356 * @param[out] rsa where to store the result 356 * @param[out] rsa where to store the result
357 * @return array entry for the result specification to use 357 * @return array entry for the result specification to use
358 */ 358 */
359struct GNUNET_MY_ResultSpec 359struct GNUNET_MY_ResultSpec
360GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) 360GNUNET_MY_result_spec_rsa_public_key(struct GNUNET_CRYPTO_RsaPublicKey **rsa)
361{ 361{
362 struct GNUNET_MY_ResultSpec res = { 362 struct GNUNET_MY_ResultSpec res = {
363 .pre_conv = &pre_extract_rsa_public_key, 363 .pre_conv = &pre_extract_rsa_public_key,
364 .post_conv = &post_extract_rsa_public_key, 364 .post_conv = &post_extract_rsa_public_key,
365 .cleaner = &clean_rsa_public_key, 365 .cleaner = &clean_rsa_public_key,
366 .dst = (void *) rsa, 366 .dst = (void *)rsa,
367 .dst_size = 0, 367 .dst_size = 0,
368 .num_fields = 1 368 .num_fields = 1
369 }; 369 };
@@ -373,23 +373,23 @@ GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa)
373 373
374 374
375/** 375/**
376 * Extract data from a Mysql database @a result at row @a row. 376 * Extract data from a Mysql database @a result at row @a row.
377 * 377 *
378 * @param cls closure 378 * @param cls closure
379 * @param[in,out] rs 379 * @param[in,out] rs
380 * @param stmt the mysql statement that is being run 380 * @param stmt the mysql statement that is being run
381 * @param column the column that is being processed 381 * @param column the column that is being processed
382 * @param[out] results 382 * @param[out] results
383 * @return 383 * @return
384 * #GNUNET_OK if all results could be extracted 384 * #GNUNET_OK if all results could be extracted
385 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 385 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
386 */ 386 */
387static int 387static int
388pre_extract_rsa_signature (void *cls, 388pre_extract_rsa_signature(void *cls,
389 struct GNUNET_MY_ResultSpec *rs, 389 struct GNUNET_MY_ResultSpec *rs,
390 MYSQL_STMT *stmt, 390 MYSQL_STMT *stmt,
391 unsigned int column, 391 unsigned int column,
392 MYSQL_BIND *results) 392 MYSQL_BIND *results)
393{ 393{
394 results[0].buffer = 0; 394 results[0].buffer = 0;
395 results[0].buffer_length = 0; 395 results[0].buffer_length = 0;
@@ -403,23 +403,23 @@ pre_extract_rsa_signature (void *cls,
403 403
404 404
405/** 405/**
406 * Extract data from a Mysql database @a result at row @a row. 406 * Extract data from a Mysql database @a result at row @a row.
407 * 407 *
408 * @param cls closure 408 * @param cls closure
409 * @param[in,out] rs 409 * @param[in,out] rs
410 * @param stmt the mysql statement that is being run 410 * @param stmt the mysql statement that is being run
411 * @param column the column that is being processed 411 * @param column the column that is being processed
412 * @param[out] results 412 * @param[out] results
413 * @return 413 * @return
414 * #GNUNET_OK if all results could be extracted 414 * #GNUNET_OK if all results could be extracted
415 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 415 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
416 */ 416 */
417static int 417static int
418post_extract_rsa_signature (void *cls, 418post_extract_rsa_signature(void *cls,
419 struct GNUNET_MY_ResultSpec *rs, 419 struct GNUNET_MY_ResultSpec *rs,
420 MYSQL_STMT *stmt, 420 MYSQL_STMT *stmt,
421 unsigned int column, 421 unsigned int column,
422 MYSQL_BIND *results) 422 MYSQL_BIND *results)
423{ 423{
424 struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; 424 struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst;
425 void *buf; 425 void *buf;
@@ -427,34 +427,34 @@ post_extract_rsa_signature (void *cls,
427 427
428 if (*results->is_null) 428 if (*results->is_null)
429 return GNUNET_SYSERR; 429 return GNUNET_SYSERR;
430 size = (size_t) rs->mysql_bind_output_length; 430 size = (size_t)rs->mysql_bind_output_length;
431 431
432 if (rs->mysql_bind_output_length != size) 432 if (rs->mysql_bind_output_length != size)
433 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ 433 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
434 buf = GNUNET_malloc (size); 434 buf = GNUNET_malloc(size);
435 435
436 results[0].buffer = buf; 436 results[0].buffer = buf;
437 results[0].buffer_length = size; 437 results[0].buffer_length = size;
438 results[0].buffer_type = MYSQL_TYPE_BLOB; 438 results[0].buffer_type = MYSQL_TYPE_BLOB;
439 if (0 != 439 if (0 !=
440 mysql_stmt_fetch_column (stmt, 440 mysql_stmt_fetch_column(stmt,
441 results, 441 results,
442 column, 442 column,
443 0)) 443 0))
444 { 444 {
445 GNUNET_free (buf); 445 GNUNET_free(buf);
446 return GNUNET_SYSERR; 446 return GNUNET_SYSERR;
447 } 447 }
448 448
449 *sig = GNUNET_CRYPTO_rsa_signature_decode (buf, 449 *sig = GNUNET_CRYPTO_rsa_signature_decode(buf,
450 size); 450 size);
451 GNUNET_free (buf); 451 GNUNET_free(buf);
452 if (NULL == *sig) 452 if (NULL == *sig)
453 { 453 {
454 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 454 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
455 "Resuls contains bogus signature value (fails to decode)\n"); 455 "Resuls contains bogus signature value (fails to decode)\n");
456 return GNUNET_SYSERR; 456 return GNUNET_SYSERR;
457 } 457 }
458 return GNUNET_OK; 458 return GNUNET_OK;
459} 459}
460 460
@@ -467,27 +467,27 @@ post_extract_rsa_signature (void *cls,
467 * @param rd result data to clean up 467 * @param rd result data to clean up
468 */ 468 */
469static void 469static void
470clean_rsa_signature (void *cls, 470clean_rsa_signature(void *cls,
471 struct GNUNET_MY_ResultSpec *rs) 471 struct GNUNET_MY_ResultSpec *rs)
472{ 472{
473 struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst; 473 struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst;
474 474
475 if (NULL != *sig) 475 if (NULL != *sig)
476 { 476 {
477 GNUNET_CRYPTO_rsa_signature_free (*sig); 477 GNUNET_CRYPTO_rsa_signature_free(*sig);
478 *sig = NULL; 478 *sig = NULL;
479 } 479 }
480} 480}
481 481
482 482
483/** 483/**
484 * RSA signature expected. 484 * RSA signature expected.
485 * 485 *
486 * @param[out] sig where to store the result; 486 * @param[out] sig where to store the result;
487 * @return array entry for the result specification to use 487 * @return array entry for the result specification to use
488 */ 488 */
489struct GNUNET_MY_ResultSpec 489struct GNUNET_MY_ResultSpec
490GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) 490GNUNET_MY_result_spec_rsa_signature(struct GNUNET_CRYPTO_RsaSignature **sig)
491{ 491{
492 struct GNUNET_MY_ResultSpec res = 492 struct GNUNET_MY_ResultSpec res =
493 { 493 {
@@ -498,6 +498,7 @@ GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
498 .dst_size = 0, 498 .dst_size = 0,
499 .num_fields = 1 499 .num_fields = 1
500 }; 500 };
501
501 return res; 502 return res;
502} 503}
503 504
@@ -515,11 +516,11 @@ GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
515 * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) 516 * #GNUNET_SYSERR if a result was invalid (non existing field or NULL)
516 */ 517 */
517static int 518static int
518pre_extract_string (void * cls, 519pre_extract_string(void * cls,
519 struct GNUNET_MY_ResultSpec *rs, 520 struct GNUNET_MY_ResultSpec *rs,
520 MYSQL_STMT *stmt, 521 MYSQL_STMT *stmt,
521 unsigned int column, 522 unsigned int column,
522 MYSQL_BIND *results) 523 MYSQL_BIND *results)
523{ 524{
524 results[0].buffer = NULL; 525 results[0].buffer = NULL;
525 results[0].buffer_length = 0; 526 results[0].buffer_length = 0;
@@ -545,39 +546,39 @@ pre_extract_string (void * cls,
545 * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) 546 * #GNUNET_SYSERR if a result was invalid (non existing field or NULL)
546 */ 547 */
547static int 548static int
548post_extract_string (void * cls, 549post_extract_string(void * cls,
549 struct GNUNET_MY_ResultSpec *rs, 550 struct GNUNET_MY_ResultSpec *rs,
550 MYSQL_STMT *stmt, 551 MYSQL_STMT *stmt,
551 unsigned int column, 552 unsigned int column,
552 MYSQL_BIND *results) 553 MYSQL_BIND *results)
553{ 554{
554 size_t size = (size_t) rs->mysql_bind_output_length; 555 size_t size = (size_t)rs->mysql_bind_output_length;
555 char *buf; 556 char *buf;
556 557
557 if (rs->mysql_bind_output_length != size) 558 if (rs->mysql_bind_output_length != size)
558 return GNUNET_SYSERR; 559 return GNUNET_SYSERR;
559 if (*results->is_null) 560 if (*results->is_null)
560 { 561 {
561 *(void **) rs->dst = NULL; 562 *(void **)rs->dst = NULL;
562 return GNUNET_OK; 563 return GNUNET_OK;
563 } 564 }
564 565
565 buf = GNUNET_malloc (size); 566 buf = GNUNET_malloc(size);
566 results[0].buffer = buf; 567 results[0].buffer = buf;
567 results[0].buffer_length = size; 568 results[0].buffer_length = size;
568 results[0].buffer_type = MYSQL_TYPE_BLOB; 569 results[0].buffer_type = MYSQL_TYPE_BLOB;
569 570
570 if (0 != 571 if (0 !=
571 mysql_stmt_fetch_column (stmt, 572 mysql_stmt_fetch_column(stmt,
572 results, 573 results,
573 column, 574 column,
574 0)) 575 0))
575 { 576 {
576 GNUNET_free (buf); 577 GNUNET_free(buf);
577 return GNUNET_SYSERR; 578 return GNUNET_SYSERR;
578 } 579 }
579 buf[size] = '\0'; 580 buf[size] = '\0';
580 *(void **) rs->dst = buf; 581 *(void **)rs->dst = buf;
581 return GNUNET_OK; 582 return GNUNET_OK;
582} 583}
583 584
@@ -589,16 +590,17 @@ post_extract_string (void * cls,
589 * @return array entry for the result specification to use 590 * @return array entry for the result specification to use
590 */ 591 */
591struct GNUNET_MY_ResultSpec 592struct GNUNET_MY_ResultSpec
592GNUNET_MY_result_spec_string (char **dst) 593GNUNET_MY_result_spec_string(char **dst)
593{ 594{
594 struct GNUNET_MY_ResultSpec res = { 595 struct GNUNET_MY_ResultSpec res = {
595 .pre_conv = &pre_extract_string, 596 .pre_conv = &pre_extract_string,
596 .post_conv = &post_extract_string, 597 .post_conv = &post_extract_string,
597 .cleaner = NULL, 598 .cleaner = NULL,
598 .dst = (void *) dst, 599 .dst = (void *)dst,
599 .dst_size = 0, 600 .dst_size = 0,
600 .num_fields = 1 601 .num_fields = 1
601 }; 602 };
603
602 return res; 604 return res;
603} 605}
604 606
@@ -609,25 +611,26 @@ GNUNET_MY_result_spec_string (char **dst)
609 * @param name name of the field in the table 611 * @param name name of the field in the table
610 * @param[out] at where to store the result 612 * @param[out] at where to store the result
611 * @return array entry for the result specification to use 613 * @return array entry for the result specification to use
612 */ 614 */
613struct GNUNET_MY_ResultSpec 615struct GNUNET_MY_ResultSpec
614GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) 616GNUNET_MY_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at)
615{ 617{
616 return GNUNET_MY_result_spec_uint64 (&at->abs_value_us); 618 return GNUNET_MY_result_spec_uint64(&at->abs_value_us);
617} 619}
618 620
619 621
620/** 622/**
621 * Absolute time in network byte order expected 623 * Absolute time in network byte order expected
622 * 624 *
623 * @param[out] at where to store the result 625 * @param[out] at where to store the result
624 * @return array entry for the result specification to use 626 * @return array entry for the result specification to use
625 */ 627 */
626struct GNUNET_MY_ResultSpec 628struct GNUNET_MY_ResultSpec
627GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) 629GNUNET_MY_result_spec_absolute_time_nbo(struct GNUNET_TIME_AbsoluteNBO *at)
628{ 630{
629 struct GNUNET_MY_ResultSpec res = 631 struct GNUNET_MY_ResultSpec res =
630 GNUNET_MY_result_spec_auto_from_type (&at->abs_value_us__); 632 GNUNET_MY_result_spec_auto_from_type(&at->abs_value_us__);
633
631 return res; 634 return res;
632} 635}
633 636
@@ -645,11 +648,11 @@ GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at)
645 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 648 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
646 */ 649 */
647static int 650static int
648pre_extract_uint16 (void *cls, 651pre_extract_uint16(void *cls,
649 struct GNUNET_MY_ResultSpec *rs, 652 struct GNUNET_MY_ResultSpec *rs,
650 MYSQL_STMT *stmt, 653 MYSQL_STMT *stmt,
651 unsigned int column, 654 unsigned int column,
652 MYSQL_BIND *results) 655 MYSQL_BIND *results)
653{ 656{
654 results[0].buffer = rs->dst; 657 results[0].buffer = rs->dst;
655 results[0].buffer_length = rs->dst_size; 658 results[0].buffer_length = rs->dst_size;
@@ -675,11 +678,11 @@ pre_extract_uint16 (void *cls,
675 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 678 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
676 */ 679 */
677static int 680static int
678post_extract_uint16 (void *cls, 681post_extract_uint16(void *cls,
679 struct GNUNET_MY_ResultSpec *rs, 682 struct GNUNET_MY_ResultSpec *rs,
680 MYSQL_STMT *stmt, 683 MYSQL_STMT *stmt,
681 unsigned int column, 684 unsigned int column,
682 MYSQL_BIND *results) 685 MYSQL_BIND *results)
683{ 686{
684 if (rs->dst_size != rs->mysql_bind_output_length) 687 if (rs->dst_size != rs->mysql_bind_output_length)
685 return GNUNET_SYSERR; 688 return GNUNET_SYSERR;
@@ -696,39 +699,40 @@ post_extract_uint16 (void *cls,
696 * @return array entry for the result specification to use 699 * @return array entry for the result specification to use
697 */ 700 */
698struct GNUNET_MY_ResultSpec 701struct GNUNET_MY_ResultSpec
699GNUNET_MY_result_spec_uint16 (uint16_t *u16) 702GNUNET_MY_result_spec_uint16(uint16_t *u16)
700{ 703{
701 struct GNUNET_MY_ResultSpec res = { 704 struct GNUNET_MY_ResultSpec res = {
702 .pre_conv = &pre_extract_uint16, 705 .pre_conv = &pre_extract_uint16,
703 .post_conv = &post_extract_uint16, 706 .post_conv = &post_extract_uint16,
704 .cleaner = NULL, 707 .cleaner = NULL,
705 .dst = (void *) u16, 708 .dst = (void *)u16,
706 .dst_size = sizeof (*u16), 709 .dst_size = sizeof(*u16),
707 .num_fields = 1 710 .num_fields = 1
708 }; 711 };
712
709 return res; 713 return res;
710} 714}
711 715
712 716
713/** 717/**
714 * Extrac data from a MYSQL database @a result at row @a row 718 * Extrac data from a MYSQL database @a result at row @a row
715 * 719 *
716 * @param cls closure 720 * @param cls closure
717 * @param cls closure 721 * @param cls closure
718 * @param[in,out] rs 722 * @param[in,out] rs
719 * @param stmt the mysql statement that is being run 723 * @param stmt the mysql statement that is being run
720 * @param column the column that is being processed 724 * @param column the column that is being processed
721 * @param[out] results 725 * @param[out] results
722 * @return 726 * @return
723 * #GNUNET_OK if all results could be extracted 727 * #GNUNET_OK if all results could be extracted
724 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 728 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
725 */ 729 */
726static int 730static int
727pre_extract_uint32 (void *cls, 731pre_extract_uint32(void *cls,
728 struct GNUNET_MY_ResultSpec *rs, 732 struct GNUNET_MY_ResultSpec *rs,
729 MYSQL_STMT *stmt, 733 MYSQL_STMT *stmt,
730 unsigned int column, 734 unsigned int column,
731 MYSQL_BIND *results) 735 MYSQL_BIND *results)
732{ 736{
733 results[0].buffer = rs->dst; 737 results[0].buffer = rs->dst;
734 results[0].buffer_length = rs->dst_size; 738 results[0].buffer_length = rs->dst_size;
@@ -742,24 +746,24 @@ pre_extract_uint32 (void *cls,
742 746
743 747
744/** 748/**
745 * Extrac data from a MYSQL database @a result at row @a row 749 * Extrac data from a MYSQL database @a result at row @a row
746 * 750 *
747 * @param cls closure 751 * @param cls closure
748 * @param cls closure 752 * @param cls closure
749 * @param[in,out] rs 753 * @param[in,out] rs
750 * @param stmt the mysql statement that is being run 754 * @param stmt the mysql statement that is being run
751 * @param column the column that is being processed 755 * @param column the column that is being processed
752 * @param[out] results 756 * @param[out] results
753 * @return 757 * @return
754 * #GNUNET_OK if all results could be extracted 758 * #GNUNET_OK if all results could be extracted
755 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 759 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
756 */ 760 */
757static int 761static int
758post_extract_uint32 (void *cls, 762post_extract_uint32(void *cls,
759 struct GNUNET_MY_ResultSpec *rs, 763 struct GNUNET_MY_ResultSpec *rs,
760 MYSQL_STMT * stmt, 764 MYSQL_STMT * stmt,
761 unsigned int column, 765 unsigned int column,
762 MYSQL_BIND *results) 766 MYSQL_BIND *results)
763{ 767{
764 if (rs->dst_size != rs->mysql_bind_output_length) 768 if (rs->dst_size != rs->mysql_bind_output_length)
765 return GNUNET_SYSERR; 769 return GNUNET_SYSERR;
@@ -770,22 +774,23 @@ post_extract_uint32 (void *cls,
770 774
771 775
772/** 776/**
773 * uint32_t expected 777 * uint32_t expected
774 * 778 *
775 * @param[out] u32 where to store the result 779 * @param[out] u32 where to store the result
776 * @return array entry for the result specification to use 780 * @return array entry for the result specification to use
777 */ 781 */
778struct GNUNET_MY_ResultSpec 782struct GNUNET_MY_ResultSpec
779GNUNET_MY_result_spec_uint32 (uint32_t *u32) 783GNUNET_MY_result_spec_uint32(uint32_t *u32)
780{ 784{
781 struct GNUNET_MY_ResultSpec res = { 785 struct GNUNET_MY_ResultSpec res = {
782 .pre_conv = &pre_extract_uint32, 786 .pre_conv = &pre_extract_uint32,
783 .post_conv = &post_extract_uint32, 787 .post_conv = &post_extract_uint32,
784 .cleaner = NULL, 788 .cleaner = NULL,
785 .dst = (void *) u32, 789 .dst = (void *)u32,
786 .dst_size = sizeof (*u32), 790 .dst_size = sizeof(*u32),
787 .num_fields = 1 791 .num_fields = 1
788 }; 792 };
793
789 return res; 794 return res;
790} 795}
791 796
@@ -803,13 +808,13 @@ GNUNET_MY_result_spec_uint32 (uint32_t *u32)
803 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 808 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
804 */ 809 */
805static int 810static int
806pre_extract_uint64 (void *cls, 811pre_extract_uint64(void *cls,
807 struct GNUNET_MY_ResultSpec *rs, 812 struct GNUNET_MY_ResultSpec *rs,
808 MYSQL_STMT *stmt, 813 MYSQL_STMT *stmt,
809 unsigned int column, 814 unsigned int column,
810 MYSQL_BIND *results) 815 MYSQL_BIND *results)
811{ 816{
812 if (sizeof (uint64_t) != rs->dst_size) 817 if (sizeof(uint64_t) != rs->dst_size)
813 return GNUNET_SYSERR; 818 return GNUNET_SYSERR;
814 results[0].buffer = rs->dst; 819 results[0].buffer = rs->dst;
815 results[0].buffer_length = rs->dst_size; 820 results[0].buffer_length = rs->dst_size;
@@ -835,13 +840,13 @@ pre_extract_uint64 (void *cls,
835 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) 840 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
836 */ 841 */
837static int 842static int
838post_extract_uint64 (void *cls, 843post_extract_uint64(void *cls,
839 struct GNUNET_MY_ResultSpec *rs, 844 struct GNUNET_MY_ResultSpec *rs,
840 MYSQL_STMT *stmt, 845 MYSQL_STMT *stmt,
841 unsigned int column, 846 unsigned int column,
842 MYSQL_BIND *results) 847 MYSQL_BIND *results)
843{ 848{
844 if (sizeof (uint64_t) != rs->dst_size) 849 if (sizeof(uint64_t) != rs->dst_size)
845 return GNUNET_SYSERR; 850 return GNUNET_SYSERR;
846 if (*results->is_null) 851 if (*results->is_null)
847 return GNUNET_SYSERR; 852 return GNUNET_SYSERR;
@@ -856,16 +861,17 @@ post_extract_uint64 (void *cls,
856 * @return array entry for the result specification to use 861 * @return array entry for the result specification to use
857 */ 862 */
858struct GNUNET_MY_ResultSpec 863struct GNUNET_MY_ResultSpec
859GNUNET_MY_result_spec_uint64 (uint64_t *u64) 864GNUNET_MY_result_spec_uint64(uint64_t *u64)
860{ 865{
861 struct GNUNET_MY_ResultSpec res = { 866 struct GNUNET_MY_ResultSpec res = {
862 .pre_conv = &pre_extract_uint64, 867 .pre_conv = &pre_extract_uint64,
863 .post_conv = &post_extract_uint64, 868 .post_conv = &post_extract_uint64,
864 .cleaner = NULL, 869 .cleaner = NULL,
865 .dst = (void *) u64, 870 .dst = (void *)u64,
866 .dst_size = sizeof (*u64), 871 .dst_size = sizeof(*u64),
867 .num_fields = 1 872 .num_fields = 1
868 }; 873 };
874
869 return res; 875 return res;
870} 876}
871 877
diff --git a/src/my/test_my.c b/src/my/test_my.c
index 556d2baa2..d9dcc71f9 100644
--- a/src/my/test_my.c
+++ b/src/my/test_my.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file my/test_my.c 21 * @file my/test_my.c
22 * @brief Tests for convenience MySQL database 22 * @brief Tests for convenience MySQL database
@@ -30,23 +30,23 @@
30 30
31 31
32/** 32/**
33 * Run actual test queries. 33 * Run actual test queries.
34 * 34 *
35 * @param contexte the current context of mysql 35 * @param contexte the current context of mysql
36 * @return 0 on succes 36 * @return 0 on succes
37 */ 37 */
38static int 38static int
39run_queries (struct GNUNET_MYSQL_Context *context) 39run_queries(struct GNUNET_MYSQL_Context *context)
40{ 40{
41 struct GNUNET_CRYPTO_RsaPublicKey *pub = NULL; 41 struct GNUNET_CRYPTO_RsaPublicKey *pub = NULL;
42 struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL; 42 struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL;
43 struct GNUNET_CRYPTO_RsaSignature *sig = NULL;; 43 struct GNUNET_CRYPTO_RsaSignature *sig = NULL;;
44 struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL; 44 struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL;
45 struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get (); 45 struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get();
46 struct GNUNET_TIME_Absolute abs_time2; 46 struct GNUNET_TIME_Absolute abs_time2;
47 struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS; 47 struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS;
48 struct GNUNET_TIME_Absolute forever2; 48 struct GNUNET_TIME_Absolute forever2;
49 const struct GNUNET_TIME_AbsoluteNBO abs_time_nbo = GNUNET_TIME_absolute_hton (abs_time); 49 const struct GNUNET_TIME_AbsoluteNBO abs_time_nbo = GNUNET_TIME_absolute_hton(abs_time);
50 struct GNUNET_HashCode hc; 50 struct GNUNET_HashCode hc;
51 struct GNUNET_HashCode hc2; 51 struct GNUNET_HashCode hc2;
52 const char msg[] = "hello"; 52 const char msg[] = "hello";
@@ -71,163 +71,163 @@ run_queries (struct GNUNET_MYSQL_Context *context)
71 struct GNUNET_CRYPTO_RsaPrivateKey *priv = NULL; 71 struct GNUNET_CRYPTO_RsaPrivateKey *priv = NULL;
72 struct GNUNET_HashCode hmsg; 72 struct GNUNET_HashCode hmsg;
73 73
74 priv = GNUNET_CRYPTO_rsa_private_key_create (1024); 74 priv = GNUNET_CRYPTO_rsa_private_key_create(1024);
75 pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); 75 pub = GNUNET_CRYPTO_rsa_private_key_get_public(priv);
76 memset (&hmsg, 42, sizeof(hmsg)); 76 memset(&hmsg, 42, sizeof(hmsg));
77 sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, 77 sig = GNUNET_CRYPTO_rsa_sign_fdh(priv,
78 &hmsg); 78 &hmsg);
79 u16 = 16; 79 u16 = 16;
80 u32 = 32; 80 u32 = 32;
81 u64 = UINT64_MAX; 81 u64 = UINT64_MAX;
82 82
83 memset (&hc, 0, sizeof(hc)); 83 memset(&hc, 0, sizeof(hc));
84 memset (&hc2, 0, sizeof(hc2)); 84 memset(&hc2, 0, sizeof(hc2));
85 85
86 statements_handle_insert 86 statements_handle_insert
87 = GNUNET_MYSQL_statement_prepare (context, 87 = GNUNET_MYSQL_statement_prepare(context,
88 "INSERT INTO test_my2 (" 88 "INSERT INTO test_my2 ("
89 " pub" 89 " pub"
90 ",sig" 90 ",sig"
91 ",abs_time" 91 ",abs_time"
92 ",forever" 92 ",forever"
93 ",abs_time_nbo" 93 ",abs_time_nbo"
94 ",hash" 94 ",hash"
95 ",vsize" 95 ",vsize"
96 ",str" 96 ",str"
97 ",u16" 97 ",u16"
98 ",u32" 98 ",u32"
99 ",u64" 99 ",u64"
100 ") VALUES " 100 ") VALUES "
101 "( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); 101 "( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
102 102
103 if (NULL == statements_handle_insert) 103 if (NULL == statements_handle_insert)
104 { 104 {
105 fprintf (stderr, "Failed to prepared statement INSERT\n"); 105 fprintf(stderr, "Failed to prepared statement INSERT\n");
106 GNUNET_CRYPTO_rsa_signature_free (sig); 106 GNUNET_CRYPTO_rsa_signature_free(sig);
107 GNUNET_CRYPTO_rsa_private_key_free (priv); 107 GNUNET_CRYPTO_rsa_private_key_free(priv);
108 GNUNET_CRYPTO_rsa_public_key_free (pub); 108 GNUNET_CRYPTO_rsa_public_key_free(pub);
109 return 1; 109 return 1;
110 } 110 }
111 111
112 struct GNUNET_MY_QueryParam params_insert[] = { 112 struct GNUNET_MY_QueryParam params_insert[] = {
113 GNUNET_MY_query_param_rsa_public_key (pub), 113 GNUNET_MY_query_param_rsa_public_key(pub),
114 GNUNET_MY_query_param_rsa_signature (sig), 114 GNUNET_MY_query_param_rsa_signature(sig),
115 GNUNET_MY_query_param_absolute_time (&abs_time), 115 GNUNET_MY_query_param_absolute_time(&abs_time),
116 GNUNET_MY_query_param_absolute_time (&forever), 116 GNUNET_MY_query_param_absolute_time(&forever),
117 GNUNET_MY_query_param_absolute_time_nbo (&abs_time_nbo), 117 GNUNET_MY_query_param_absolute_time_nbo(&abs_time_nbo),
118 GNUNET_MY_query_param_auto_from_type (&hc), 118 GNUNET_MY_query_param_auto_from_type(&hc),
119 GNUNET_MY_query_param_fixed_size (msg, strlen (msg)), 119 GNUNET_MY_query_param_fixed_size(msg, strlen(msg)),
120 GNUNET_MY_query_param_string (msg3), 120 GNUNET_MY_query_param_string(msg3),
121 GNUNET_MY_query_param_uint16 (&u16), 121 GNUNET_MY_query_param_uint16(&u16),
122 GNUNET_MY_query_param_uint32 (&u32), 122 GNUNET_MY_query_param_uint32(&u32),
123 GNUNET_MY_query_param_uint64 (&u64), 123 GNUNET_MY_query_param_uint64(&u64),
124 GNUNET_MY_query_param_end 124 GNUNET_MY_query_param_end
125 }; 125 };
126 126
127 if (GNUNET_OK != GNUNET_MY_exec_prepared(context, 127 if (GNUNET_OK != GNUNET_MY_exec_prepared(context,
128 statements_handle_insert, 128 statements_handle_insert,
129 params_insert)) 129 params_insert))
130 { 130 {
131 fprintf (stderr, "Failed to execute prepared statement INSERT\n"); 131 fprintf(stderr, "Failed to execute prepared statement INSERT\n");
132 GNUNET_CRYPTO_rsa_signature_free (sig); 132 GNUNET_CRYPTO_rsa_signature_free(sig);
133 GNUNET_CRYPTO_rsa_private_key_free (priv); 133 GNUNET_CRYPTO_rsa_private_key_free(priv);
134 GNUNET_CRYPTO_rsa_public_key_free (pub); 134 GNUNET_CRYPTO_rsa_public_key_free(pub);
135 return 1; 135 return 1;
136 } 136 }
137 137
138 statements_handle_select 138 statements_handle_select
139 = GNUNET_MYSQL_statement_prepare (context, 139 = GNUNET_MYSQL_statement_prepare(context,
140 "SELECT" 140 "SELECT"
141 " pub" 141 " pub"
142 ",sig" 142 ",sig"
143 ",abs_time" 143 ",abs_time"
144 ",forever" 144 ",forever"
145 ",hash" 145 ",hash"
146 ",vsize" 146 ",vsize"
147 ",str" 147 ",str"
148 ",u16" 148 ",u16"
149 ",u32" 149 ",u32"
150 ",u64" 150 ",u64"
151 " FROM test_my2"); 151 " FROM test_my2");
152 152
153 if (NULL == statements_handle_select) 153 if (NULL == statements_handle_select)
154 { 154 {
155 fprintf(stderr, "Failed to prepared statement SELECT\n"); 155 fprintf(stderr, "Failed to prepared statement SELECT\n");
156 GNUNET_CRYPTO_rsa_signature_free (sig); 156 GNUNET_CRYPTO_rsa_signature_free(sig);
157 GNUNET_CRYPTO_rsa_private_key_free (priv); 157 GNUNET_CRYPTO_rsa_private_key_free(priv);
158 GNUNET_CRYPTO_rsa_public_key_free (pub); 158 GNUNET_CRYPTO_rsa_public_key_free(pub);
159 return 1; 159 return 1;
160 } 160 }
161 161
162 struct GNUNET_MY_QueryParam params_select[] = { 162 struct GNUNET_MY_QueryParam params_select[] = {
163 GNUNET_MY_query_param_end 163 GNUNET_MY_query_param_end
164 }; 164 };
165 165
166 if (GNUNET_OK != GNUNET_MY_exec_prepared (context, 166 if (GNUNET_OK != GNUNET_MY_exec_prepared(context,
167 statements_handle_select, 167 statements_handle_select,
168 params_select)) 168 params_select))
169 { 169 {
170 fprintf (stderr, "Failed to execute prepared statement SELECT\n"); 170 fprintf(stderr, "Failed to execute prepared statement SELECT\n");
171 GNUNET_CRYPTO_rsa_signature_free (sig); 171 GNUNET_CRYPTO_rsa_signature_free(sig);
172 GNUNET_CRYPTO_rsa_private_key_free (priv); 172 GNUNET_CRYPTO_rsa_private_key_free(priv);
173 GNUNET_CRYPTO_rsa_public_key_free (pub); 173 GNUNET_CRYPTO_rsa_public_key_free(pub);
174 return 1; 174 return 1;
175 } 175 }
176 176
177 struct GNUNET_MY_ResultSpec results_select[] = { 177 struct GNUNET_MY_ResultSpec results_select[] = {
178 GNUNET_MY_result_spec_rsa_public_key (&pub2), 178 GNUNET_MY_result_spec_rsa_public_key(&pub2),
179 GNUNET_MY_result_spec_rsa_signature (&sig2), 179 GNUNET_MY_result_spec_rsa_signature(&sig2),
180 GNUNET_MY_result_spec_absolute_time (&abs_time2), 180 GNUNET_MY_result_spec_absolute_time(&abs_time2),
181 GNUNET_MY_result_spec_absolute_time (&forever2), 181 GNUNET_MY_result_spec_absolute_time(&forever2),
182 GNUNET_MY_result_spec_auto_from_type (&hc2), 182 GNUNET_MY_result_spec_auto_from_type(&hc2),
183 GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), 183 GNUNET_MY_result_spec_variable_size(&msg2, &msg2_len),
184 GNUNET_MY_result_spec_string (&msg4), 184 GNUNET_MY_result_spec_string(&msg4),
185 GNUNET_MY_result_spec_uint16 (&u162), 185 GNUNET_MY_result_spec_uint16(&u162),
186 GNUNET_MY_result_spec_uint32 (&u322), 186 GNUNET_MY_result_spec_uint32(&u322),
187 GNUNET_MY_result_spec_uint64 (&u642), 187 GNUNET_MY_result_spec_uint64(&u642),
188 GNUNET_MY_result_spec_end 188 GNUNET_MY_result_spec_end
189 }; 189 };
190 190
191 ret = GNUNET_MY_extract_result (statements_handle_select, 191 ret = GNUNET_MY_extract_result(statements_handle_select,
192 results_select); 192 results_select);
193 193
194 GNUNET_assert (GNUNET_YES == ret); 194 GNUNET_assert(GNUNET_YES == ret);
195 GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us); 195 GNUNET_break(abs_time.abs_value_us == abs_time2.abs_value_us);
196 GNUNET_break (forever.abs_value_us == forever2.abs_value_us); 196 GNUNET_break(forever.abs_value_us == forever2.abs_value_us);
197 GNUNET_break (0 == 197 GNUNET_break(0 ==
198 memcmp (&hc, 198 memcmp(&hc,
199 &hc2, 199 &hc2,
200 sizeof (struct GNUNET_HashCode))); 200 sizeof(struct GNUNET_HashCode)));
201 201
202 GNUNET_assert (NULL != sig2); 202 GNUNET_assert(NULL != sig2);
203 GNUNET_assert (NULL != pub2); 203 GNUNET_assert(NULL != pub2);
204 GNUNET_break (0 == 204 GNUNET_break(0 ==
205 GNUNET_CRYPTO_rsa_signature_cmp (sig, 205 GNUNET_CRYPTO_rsa_signature_cmp(sig,
206 sig2)); 206 sig2));
207 GNUNET_break (0 == 207 GNUNET_break(0 ==
208 GNUNET_CRYPTO_rsa_public_key_cmp (pub, 208 GNUNET_CRYPTO_rsa_public_key_cmp(pub,
209 pub2)); 209 pub2));
210 210
211 GNUNET_break (strlen (msg) == msg2_len); 211 GNUNET_break(strlen(msg) == msg2_len);
212 GNUNET_break (0 == 212 GNUNET_break(0 ==
213 strncmp (msg, 213 strncmp(msg,
214 msg2, 214 msg2,
215 msg2_len)); 215 msg2_len));
216 216
217 GNUNET_break (strlen (msg3) == strlen(msg4)); 217 GNUNET_break(strlen(msg3) == strlen(msg4));
218 GNUNET_break (0 == 218 GNUNET_break(0 ==
219 strcmp (msg3, 219 strcmp(msg3,
220 msg4)); 220 msg4));
221 221
222 GNUNET_break (16 == u162); 222 GNUNET_break(16 == u162);
223 GNUNET_break (32 == u322); 223 GNUNET_break(32 == u322);
224 GNUNET_break (UINT64_MAX == u642); 224 GNUNET_break(UINT64_MAX == u642);
225 225
226 GNUNET_MY_cleanup_result (results_select); 226 GNUNET_MY_cleanup_result(results_select);
227 227
228 GNUNET_CRYPTO_rsa_signature_free (sig); 228 GNUNET_CRYPTO_rsa_signature_free(sig);
229 GNUNET_CRYPTO_rsa_private_key_free (priv); 229 GNUNET_CRYPTO_rsa_private_key_free(priv);
230 GNUNET_CRYPTO_rsa_public_key_free (pub); 230 GNUNET_CRYPTO_rsa_public_key_free(pub);
231 231
232 if (GNUNET_OK != ret) 232 if (GNUNET_OK != ret)
233 return 1; 233 return 1;
@@ -237,63 +237,63 @@ run_queries (struct GNUNET_MYSQL_Context *context)
237 237
238 238
239int 239int
240main (int argc, const char *const argv[]) 240main(int argc, const char *const argv[])
241{ 241{
242 struct GNUNET_CONFIGURATION_Handle *config; 242 struct GNUNET_CONFIGURATION_Handle *config;
243 struct GNUNET_MYSQL_Context *context; 243 struct GNUNET_MYSQL_Context *context;
244 int ret; 244 int ret;
245 245
246 GNUNET_log_setup ("test-my", 246 GNUNET_log_setup("test-my",
247 "WARNING", 247 "WARNING",
248 NULL); 248 NULL);
249 249
250 config = GNUNET_CONFIGURATION_create (); 250 config = GNUNET_CONFIGURATION_create();
251 if (GNUNET_OK != 251 if (GNUNET_OK !=
252 GNUNET_CONFIGURATION_parse (config, "test_my.conf")) 252 GNUNET_CONFIGURATION_parse(config, "test_my.conf"))
253 { 253 {
254 fprintf (stderr, "Failed to parse configuaration\n"); 254 fprintf(stderr, "Failed to parse configuaration\n");
255 return 1; 255 return 1;
256 } 256 }
257 257
258 context = GNUNET_MYSQL_context_create (config, 258 context = GNUNET_MYSQL_context_create(config,
259 "datastore-mysql"); 259 "datastore-mysql");
260 if (NULL == context) 260 if (NULL == context)
261 { 261 {
262 fprintf(stderr, "Failed to connect to database\n"); 262 fprintf(stderr, "Failed to connect to database\n");
263 return 77; 263 return 77;
264 } 264 }
265 265
266 (void) GNUNET_MYSQL_statement_run (context, 266 (void)GNUNET_MYSQL_statement_run(context,
267 "DROP TABLE test_my2;"); 267 "DROP TABLE test_my2;");
268 268
269 if (GNUNET_OK != 269 if (GNUNET_OK !=
270 GNUNET_MYSQL_statement_run (context, 270 GNUNET_MYSQL_statement_run(context,
271 "CREATE TABLE IF NOT EXISTS test_my2(" 271 "CREATE TABLE IF NOT EXISTS test_my2("
272 " pub BLOB NOT NULL" 272 " pub BLOB NOT NULL"
273 ",sig BLOB NOT NULL" 273 ",sig BLOB NOT NULL"
274 ",abs_time BIGINT NOT NULL" 274 ",abs_time BIGINT NOT NULL"
275 ",forever BIGINT NOT NULL" 275 ",forever BIGINT NOT NULL"
276 ",abs_time_nbo BIGINT NOT NULL" 276 ",abs_time_nbo BIGINT NOT NULL"
277 ",hash BLOB NOT NULL CHECK(LENGTH(hash)=64)" 277 ",hash BLOB NOT NULL CHECK(LENGTH(hash)=64)"
278 ",vsize BLOB NOT NULL" 278 ",vsize BLOB NOT NULL"
279 ",str BLOB NOT NULL" 279 ",str BLOB NOT NULL"
280 ",u16 SMALLINT NOT NULL" 280 ",u16 SMALLINT NOT NULL"
281 ",u32 INT NOT NULL" 281 ",u32 INT NOT NULL"
282 ",u64 BIGINT NOT NULL" 282 ",u64 BIGINT NOT NULL"
283 ")")) 283 ")"))
284 { 284 {
285 fprintf (stderr, 285 fprintf(stderr,
286 "Failed to create table. Database likely not setup correctly.\n"); 286 "Failed to create table. Database likely not setup correctly.\n");
287 GNUNET_MYSQL_statements_invalidate (context); 287 GNUNET_MYSQL_statements_invalidate(context);
288 GNUNET_MYSQL_context_destroy (context); 288 GNUNET_MYSQL_context_destroy(context);
289 289
290 return 77; 290 return 77;
291 } 291 }
292 292
293 ret = run_queries (context); 293 ret = run_queries(context);
294 294
295 GNUNET_MYSQL_context_destroy (context); 295 GNUNET_MYSQL_context_destroy(context);
296 GNUNET_free (config); 296 GNUNET_free(config);
297 297
298 return ret; 298 return ret;
299} 299}