diff options
Diffstat (limited to 'src/pq')
-rw-r--r-- | src/pq/pq.c | 26 | ||||
-rw-r--r-- | src/pq/pq_connect.c | 20 | ||||
-rw-r--r-- | src/pq/pq_eval.c | 18 | ||||
-rw-r--r-- | src/pq/pq_exec.c | 22 | ||||
-rw-r--r-- | src/pq/pq_prepare.c | 20 | ||||
-rw-r--r-- | src/pq/pq_query_helper.c | 80 | ||||
-rw-r--r-- | src/pq/pq_result_helper.c | 107 | ||||
-rw-r--r-- | src/pq/test_pq.c | 20 |
8 files changed, 237 insertions, 76 deletions
diff --git a/src/pq/pq.c b/src/pq/pq.c index 4e24e1ef8..ae12f461e 100644 --- a/src/pq/pq.c +++ b/src/pq/pq.c | |||
@@ -2,16 +2,18 @@ | |||
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 under the | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | terms of the GNU General Public License as published by the Free Software | 6 | under the terms of the GNU Affero General Public License as published |
7 | Foundation; either version 3, or (at your option) any later version. | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | 8 | or (at your option) any later version. | |
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | 9 | |
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | You should have received a copy of the GNU General Public License along with | 13 | Affero General Public License for more details. |
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | 14 | |
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/>. | ||
15 | */ | 17 | */ |
16 | /** | 18 | /** |
17 | * @file pq/pq.c | 19 | * @file pq/pq.c |
@@ -41,6 +43,10 @@ GNUNET_PQ_exec_prepared (PGconn *db_conn, | |||
41 | unsigned int len; | 43 | unsigned int len; |
42 | unsigned int i; | 44 | unsigned int i; |
43 | 45 | ||
46 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
47 | "Running prepared statement `%s' on %p\n", | ||
48 | name, | ||
49 | db_conn); | ||
44 | /* count the number of parameters */ | 50 | /* count the number of parameters */ |
45 | len = 0; | 51 | len = 0; |
46 | for (i=0;0 != params[i].num_params;i++) | 52 | for (i=0;0 != params[i].num_params;i++) |
diff --git a/src/pq/pq_connect.c b/src/pq/pq_connect.c index 99ad06485..25619f8c0 100644 --- a/src/pq/pq_connect.c +++ b/src/pq/pq_connect.c | |||
@@ -2,16 +2,18 @@ | |||
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2017 GNUnet e.V. | 3 | Copyright (C) 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify it under the | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | terms of the GNU General Public License as published by the Free Software | 6 | under the terms of the GNU Affero General Public License as published |
7 | Foundation; either version 3, or (at your option) any later version. | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | ||
8 | 9 | ||
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | 10 | GNUnet is distributed in the hope that it will be useful, but |
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | 13 | Affero General Public License for more details. | |
13 | You should have received a copy of the GNU General Public License along with | 14 | |
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | 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/>. | ||
15 | */ | 17 | */ |
16 | /** | 18 | /** |
17 | * @file pq/pq_connect.c | 19 | * @file pq/pq_connect.c |
diff --git a/src/pq/pq_eval.c b/src/pq/pq_eval.c index 0f28aec7e..586de6fea 100644 --- a/src/pq/pq_eval.c +++ b/src/pq/pq_eval.c | |||
@@ -2,16 +2,18 @@ | |||
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2017 GNUnet e.V. | 3 | Copyright (C) 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify it under the | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | terms of the GNU General Public License as published by the Free Software | 6 | under the terms of the GNU Affero General Public License as published |
7 | Foundation; either version 3, or (at your option) any later version. | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | ||
8 | 9 | ||
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | 10 | GNUnet is distributed in the hope that it will be useful, but |
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | ||
12 | 14 | ||
13 | You should have received a copy of the GNU General Public License along with | 15 | You should have received a copy of the GNU Affero General Public License |
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ | 17 | */ |
16 | /** | 18 | /** |
17 | * @file pq/pq_eval.c | 19 | * @file pq/pq_eval.c |
diff --git a/src/pq/pq_exec.c b/src/pq/pq_exec.c index eacc1f2b3..f089d7c0a 100644 --- a/src/pq/pq_exec.c +++ b/src/pq/pq_exec.c | |||
@@ -2,16 +2,18 @@ | |||
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2017 GNUnet e.V. | 3 | Copyright (C) 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify it under the | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | terms of the GNU General Public License as published by the Free Software | 6 | under the terms of the GNU Affero General Public License as published |
7 | Foundation; either version 3, or (at your option) any later version. | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | ||
8 | 9 | ||
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | 10 | GNUnet is distributed in the hope that it will be useful, but |
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | ||
12 | 14 | ||
13 | You should have received a copy of the GNU General Public License along with | 15 | You should have received a copy of the GNU Affero General Public License |
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ | 17 | */ |
16 | /** | 18 | /** |
17 | * @file pq/pq_exec.c | 19 | * @file pq/pq_exec.c |
@@ -77,6 +79,10 @@ GNUNET_PQ_exec_statements (PGconn *connection, | |||
77 | { | 79 | { |
78 | PGresult *result; | 80 | PGresult *result; |
79 | 81 | ||
82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
83 | "Running statement `%s' on %p\n", | ||
84 | es[i].sql, | ||
85 | connection); | ||
80 | result = PQexec (connection, | 86 | result = PQexec (connection, |
81 | es[i].sql); | 87 | es[i].sql); |
82 | if ( (GNUNET_NO == es[i].ignore_errors) && | 88 | if ( (GNUNET_NO == es[i].ignore_errors) && |
diff --git a/src/pq/pq_prepare.c b/src/pq/pq_prepare.c index 612d6df7c..d55741073 100644 --- a/src/pq/pq_prepare.c +++ b/src/pq/pq_prepare.c | |||
@@ -2,16 +2,18 @@ | |||
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2017 GNUnet e.V. | 3 | Copyright (C) 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify it under the | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | terms of the GNU General Public License as published by the Free Software | 6 | under the terms of the GNU Affero General Public License as published |
7 | Foundation; either version 3, or (at your option) any later version. | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | ||
8 | 9 | ||
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | 10 | GNUnet is distributed in the hope that it will be useful, but |
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | 13 | Affero General Public License for more details. | |
13 | You should have received a copy of the GNU General Public License along with | 14 | |
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | 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/>. | ||
15 | */ | 17 | */ |
16 | /** | 18 | /** |
17 | * @file pq/pq_prepare.c | 19 | * @file pq/pq_prepare.c |
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c index d80a3d99a..98f697b5d 100644 --- a/src/pq/pq_query_helper.c +++ b/src/pq/pq_query_helper.c | |||
@@ -2,16 +2,18 @@ | |||
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 under the | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | terms of the GNU General Public License as published by the Free Software | 6 | under the terms of the GNU Affero General Public License as published |
7 | Foundation; either version 3, or (at your option) any later version. | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | 8 | or (at your option) any later version. | |
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | 9 | |
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | You should have received a copy of the GNU General Public License along with | 13 | Affero General Public License for more details. |
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | 14 | |
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/>. | ||
15 | */ | 17 | */ |
16 | /** | 18 | /** |
17 | * @file pq/pq_query_helper.c | 19 | * @file pq/pq_query_helper.c |
@@ -48,6 +50,8 @@ qconv_fixed (void *cls, | |||
48 | void *scratch[], | 50 | void *scratch[], |
49 | unsigned int scratch_length) | 51 | unsigned int scratch_length) |
50 | { | 52 | { |
53 | (void) scratch; | ||
54 | (void) scratch_length; | ||
51 | GNUNET_break (NULL == cls); | 55 | GNUNET_break (NULL == cls); |
52 | if (1 != param_length) | 56 | if (1 != param_length) |
53 | return -1; | 57 | return -1; |
@@ -115,6 +119,8 @@ qconv_uint16 (void *cls, | |||
115 | const uint16_t *u_hbo = data; | 119 | const uint16_t *u_hbo = data; |
116 | uint16_t *u_nbo; | 120 | uint16_t *u_nbo; |
117 | 121 | ||
122 | (void) scratch; | ||
123 | (void) scratch_length; | ||
118 | GNUNET_break (NULL == cls); | 124 | GNUNET_break (NULL == cls); |
119 | if (1 != param_length) | 125 | if (1 != param_length) |
120 | return -1; | 126 | return -1; |
@@ -170,6 +176,8 @@ qconv_uint32 (void *cls, | |||
170 | const uint32_t *u_hbo = data; | 176 | const uint32_t *u_hbo = data; |
171 | uint32_t *u_nbo; | 177 | uint32_t *u_nbo; |
172 | 178 | ||
179 | (void) scratch; | ||
180 | (void) scratch_length; | ||
173 | GNUNET_break (NULL == cls); | 181 | GNUNET_break (NULL == cls); |
174 | if (1 != param_length) | 182 | if (1 != param_length) |
175 | return -1; | 183 | return -1; |
@@ -225,6 +233,8 @@ qconv_uint64 (void *cls, | |||
225 | const uint64_t *u_hbo = data; | 233 | const uint64_t *u_hbo = data; |
226 | uint64_t *u_nbo; | 234 | uint64_t *u_nbo; |
227 | 235 | ||
236 | (void) scratch; | ||
237 | (void) scratch_length; | ||
228 | GNUNET_break (NULL == cls); | 238 | GNUNET_break (NULL == cls); |
229 | if (1 != param_length) | 239 | if (1 != param_length) |
230 | return -1; | 240 | return -1; |
@@ -369,6 +379,51 @@ GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | |||
369 | 379 | ||
370 | 380 | ||
371 | /** | 381 | /** |
382 | * Function called to convert input argument into SQL parameters. | ||
383 | * | ||
384 | * @param cls closure | ||
385 | * @param data pointer to input argument | ||
386 | * @param data_len number of bytes in @a data (if applicable) | ||
387 | * @param[out] param_values SQL data to set | ||
388 | * @param[out] param_lengths SQL length data to set | ||
389 | * @param[out] param_formats SQL format data to set | ||
390 | * @param param_length number of entries available in the @a param_values, @a param_lengths and @a param_formats arrays | ||
391 | * @param[out] scratch buffer for dynamic allocations (to be done via #GNUNET_malloc() | ||
392 | * @param scratch_length number of entries left in @a scratch | ||
393 | * @return -1 on error, number of offsets used in @a scratch otherwise | ||
394 | */ | ||
395 | static int | ||
396 | qconv_abs_time (void *cls, | ||
397 | const void *data, | ||
398 | size_t data_len, | ||
399 | void *param_values[], | ||
400 | int param_lengths[], | ||
401 | int param_formats[], | ||
402 | unsigned int param_length, | ||
403 | void *scratch[], | ||
404 | unsigned int scratch_length) | ||
405 | { | ||
406 | const struct GNUNET_TIME_Absolute *u = data; | ||
407 | struct GNUNET_TIME_Absolute abs; | ||
408 | uint64_t *u_nbo; | ||
409 | |||
410 | GNUNET_break (NULL == cls); | ||
411 | if (1 != param_length) | ||
412 | return -1; | ||
413 | abs = *u; | ||
414 | if (abs.abs_value_us > INT64_MAX) | ||
415 | abs.abs_value_us = INT64_MAX; | ||
416 | u_nbo = GNUNET_new (uint64_t); | ||
417 | scratch[0] = u_nbo; | ||
418 | *u_nbo = GNUNET_htonll (abs.abs_value_us); | ||
419 | param_values[0] = (void *) u_nbo; | ||
420 | param_lengths[0] = sizeof (uint64_t); | ||
421 | param_formats[0] = 1; | ||
422 | return 1; | ||
423 | } | ||
424 | |||
425 | |||
426 | /** | ||
372 | * Generate query parameter for an absolute time value. | 427 | * Generate query parameter for an absolute time value. |
373 | * The database must store a 64-bit integer. | 428 | * The database must store a 64-bit integer. |
374 | * | 429 | * |
@@ -378,7 +433,10 @@ GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | |||
378 | struct GNUNET_PQ_QueryParam | 433 | struct GNUNET_PQ_QueryParam |
379 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) | 434 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) |
380 | { | 435 | { |
381 | return GNUNET_PQ_query_param_uint64 (&x->abs_value_us); | 436 | struct GNUNET_PQ_QueryParam res = |
437 | { &qconv_abs_time, NULL, x, sizeof (*x), 1 }; | ||
438 | |||
439 | return res; | ||
382 | } | 440 | } |
383 | 441 | ||
384 | 442 | ||
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index d9fed26a6..dc1a1554f 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c | |||
@@ -2,16 +2,18 @@ | |||
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 under the | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | terms of the GNU General Public License as published by the Free Software | 6 | under the terms of the GNU Affero General Public License as published |
7 | Foundation; either version 3, or (at your option) any later version. | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | 8 | or (at your option) any later version. | |
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | 9 | |
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | You should have received a copy of the GNU General Public License along with | 13 | Affero General Public License for more details. |
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | 14 | |
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/>. | ||
15 | */ | 17 | */ |
16 | /** | 18 | /** |
17 | * @file pq/pq_result_helper.c | 19 | * @file pq/pq_result_helper.c |
@@ -36,6 +38,7 @@ clean_varsize_blob (void *cls, | |||
36 | { | 38 | { |
37 | void **dst = rd; | 39 | void **dst = rd; |
38 | 40 | ||
41 | (void) cls; | ||
39 | if (NULL != *dst) | 42 | if (NULL != *dst) |
40 | { | 43 | { |
41 | GNUNET_free (*dst); | 44 | GNUNET_free (*dst); |
@@ -70,6 +73,7 @@ extract_varsize_blob (void *cls, | |||
70 | void *idst; | 73 | void *idst; |
71 | int fnum; | 74 | int fnum; |
72 | 75 | ||
76 | (void) cls; | ||
73 | *dst_size = 0; | 77 | *dst_size = 0; |
74 | *((void **) dst) = NULL; | 78 | *((void **) dst) = NULL; |
75 | 79 | ||
@@ -152,6 +156,7 @@ extract_fixed_blob (void *cls, | |||
152 | const char *res; | 156 | const char *res; |
153 | int fnum; | 157 | int fnum; |
154 | 158 | ||
159 | (void) cls; | ||
155 | fnum = PQfnumber (result, | 160 | fnum = PQfnumber (result, |
156 | fname); | 161 | fname); |
157 | if (fnum < 0) | 162 | if (fnum < 0) |
@@ -235,6 +240,7 @@ extract_rsa_public_key (void *cls, | |||
235 | const char *res; | 240 | const char *res; |
236 | int fnum; | 241 | int fnum; |
237 | 242 | ||
243 | (void) cls; | ||
238 | *pk = NULL; | 244 | *pk = NULL; |
239 | fnum = PQfnumber (result, | 245 | fnum = PQfnumber (result, |
240 | fname); | 246 | fname); |
@@ -282,6 +288,7 @@ clean_rsa_public_key (void *cls, | |||
282 | { | 288 | { |
283 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rd; | 289 | struct GNUNET_CRYPTO_RsaPublicKey **pk = rd; |
284 | 290 | ||
291 | (void) cls; | ||
285 | if (NULL != *pk) | 292 | if (NULL != *pk) |
286 | { | 293 | { |
287 | GNUNET_CRYPTO_rsa_public_key_free (*pk); | 294 | GNUNET_CRYPTO_rsa_public_key_free (*pk); |
@@ -336,6 +343,7 @@ extract_rsa_signature (void *cls, | |||
336 | const char *res; | 343 | const char *res; |
337 | int fnum; | 344 | int fnum; |
338 | 345 | ||
346 | (void) cls; | ||
339 | *sig = NULL; | 347 | *sig = NULL; |
340 | fnum = PQfnumber (result, | 348 | fnum = PQfnumber (result, |
341 | fname); | 349 | fname); |
@@ -383,6 +391,7 @@ clean_rsa_signature (void *cls, | |||
383 | { | 391 | { |
384 | struct GNUNET_CRYPTO_RsaSignature **sig = rd; | 392 | struct GNUNET_CRYPTO_RsaSignature **sig = rd; |
385 | 393 | ||
394 | (void) cls; | ||
386 | if (NULL != *sig) | 395 | if (NULL != *sig) |
387 | { | 396 | { |
388 | GNUNET_CRYPTO_rsa_signature_free (*sig); | 397 | GNUNET_CRYPTO_rsa_signature_free (*sig); |
@@ -437,6 +446,7 @@ extract_string (void *cls, | |||
437 | const char *res; | 446 | const char *res; |
438 | int fnum; | 447 | int fnum; |
439 | 448 | ||
449 | (void) cls; | ||
440 | *str = NULL; | 450 | *str = NULL; |
441 | fnum = PQfnumber (result, | 451 | fnum = PQfnumber (result, |
442 | fname); | 452 | fname); |
@@ -484,6 +494,7 @@ clean_string (void *cls, | |||
484 | { | 494 | { |
485 | char **str = rd; | 495 | char **str = rd; |
486 | 496 | ||
497 | (void) cls; | ||
487 | if (NULL != *str) | 498 | if (NULL != *str) |
488 | { | 499 | { |
489 | GNUNET_free (*str); | 500 | GNUNET_free (*str); |
@@ -513,6 +524,71 @@ GNUNET_PQ_result_spec_string (const char *name, | |||
513 | 524 | ||
514 | 525 | ||
515 | /** | 526 | /** |
527 | * Extract data from a Postgres database @a result at row @a row. | ||
528 | * | ||
529 | * @param cls closure | ||
530 | * @param result where to extract data from | ||
531 | * @param int row to extract data from | ||
532 | * @param fname name (or prefix) of the fields to extract from | ||
533 | * @param[in,out] dst_size where to store size of result, may be NULL | ||
534 | * @param[out] dst where to store the result | ||
535 | * @return | ||
536 | * #GNUNET_YES if all results could be extracted | ||
537 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | ||
538 | */ | ||
539 | static int | ||
540 | extract_abs_time (void *cls, | ||
541 | PGresult *result, | ||
542 | int row, | ||
543 | const char *fname, | ||
544 | size_t *dst_size, | ||
545 | void *dst) | ||
546 | { | ||
547 | struct GNUNET_TIME_Absolute *udst = dst; | ||
548 | const int64_t *res; | ||
549 | int fnum; | ||
550 | |||
551 | (void) cls; | ||
552 | fnum = PQfnumber (result, | ||
553 | fname); | ||
554 | if (fnum < 0) | ||
555 | { | ||
556 | GNUNET_break (0); | ||
557 | return GNUNET_SYSERR; | ||
558 | } | ||
559 | if (PQgetisnull (result, | ||
560 | row, | ||
561 | fnum)) | ||
562 | { | ||
563 | GNUNET_break (0); | ||
564 | return GNUNET_SYSERR; | ||
565 | } | ||
566 | GNUNET_assert (NULL != dst); | ||
567 | if (sizeof (struct GNUNET_TIME_Absolute) != *dst_size) | ||
568 | { | ||
569 | GNUNET_break (0); | ||
570 | return GNUNET_SYSERR; | ||
571 | } | ||
572 | if (sizeof (int64_t) != | ||
573 | PQgetlength (result, | ||
574 | row, | ||
575 | fnum)) | ||
576 | { | ||
577 | GNUNET_break (0); | ||
578 | return GNUNET_SYSERR; | ||
579 | } | ||
580 | res = (int64_t *) PQgetvalue (result, | ||
581 | row, | ||
582 | fnum); | ||
583 | if (INT64_MAX == *res) | ||
584 | *udst = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
585 | else | ||
586 | udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res); | ||
587 | return GNUNET_OK; | ||
588 | } | ||
589 | |||
590 | |||
591 | /** | ||
516 | * Absolute time expected. | 592 | * Absolute time expected. |
517 | * | 593 | * |
518 | * @param name name of the field in the table | 594 | * @param name name of the field in the table |
@@ -523,8 +599,12 @@ struct GNUNET_PQ_ResultSpec | |||
523 | GNUNET_PQ_result_spec_absolute_time (const char *name, | 599 | GNUNET_PQ_result_spec_absolute_time (const char *name, |
524 | struct GNUNET_TIME_Absolute *at) | 600 | struct GNUNET_TIME_Absolute *at) |
525 | { | 601 | { |
526 | return GNUNET_PQ_result_spec_uint64 (name, | 602 | struct GNUNET_PQ_ResultSpec res = |
527 | &at->abs_value_us); | 603 | { &extract_abs_time, |
604 | NULL, | ||
605 | NULL, | ||
606 | (void *) at, sizeof (*at), (name), NULL }; | ||
607 | return res; | ||
528 | } | 608 | } |
529 | 609 | ||
530 | 610 | ||
@@ -570,6 +650,7 @@ extract_uint16 (void *cls, | |||
570 | const uint16_t *res; | 650 | const uint16_t *res; |
571 | int fnum; | 651 | int fnum; |
572 | 652 | ||
653 | (void) cls; | ||
573 | fnum = PQfnumber (result, | 654 | fnum = PQfnumber (result, |
574 | fname); | 655 | fname); |
575 | if (fnum < 0) | 656 | if (fnum < 0) |
@@ -651,6 +732,7 @@ extract_uint32 (void *cls, | |||
651 | const uint32_t *res; | 732 | const uint32_t *res; |
652 | int fnum; | 733 | int fnum; |
653 | 734 | ||
735 | (void) cls; | ||
654 | fnum = PQfnumber (result, | 736 | fnum = PQfnumber (result, |
655 | fname); | 737 | fname); |
656 | if (fnum < 0) | 738 | if (fnum < 0) |
@@ -732,6 +814,7 @@ extract_uint64 (void *cls, | |||
732 | const uint64_t *res; | 814 | const uint64_t *res; |
733 | int fnum; | 815 | int fnum; |
734 | 816 | ||
817 | (void) cls; | ||
735 | fnum = PQfnumber (result, | 818 | fnum = PQfnumber (result, |
736 | fname); | 819 | fname); |
737 | if (fnum < 0) | 820 | if (fnum < 0) |
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c index b54318110..437f3b4e1 100644 --- a/src/pq/test_pq.c +++ b/src/pq/test_pq.c | |||
@@ -2,16 +2,18 @@ | |||
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2015, 2016 GNUnet e.V. | 3 | (C) 2015, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify it under the | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | terms of the GNU General Public License as published by the Free Software | 6 | under the terms of the GNU Affero General Public License as published |
7 | Foundation; either version 3, or (at your option) any later version. | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | ||
8 | 9 | ||
9 | GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | 10 | GNUnet is distributed in the hope that it will be useful, but |
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | 13 | Affero General Public License for more details. | |
13 | You should have received a copy of the GNU General Public License along with | 14 | |
14 | GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | 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/>. | ||
15 | */ | 17 | */ |
16 | /** | 18 | /** |
17 | * @file pq/test_pq.c | 19 | * @file pq/test_pq.c |