summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_pq_lib.h3
-rw-r--r--src/pq/pq.c6
-rw-r--r--src/pq/pq_result_helper.c73
3 files changed, 36 insertions, 46 deletions
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index 8483b72cf..fdb959aec 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -199,8 +199,7 @@ GNUNET_PQ_query_param_uint64 (const uint64_t *x);
199 * @param[out] dst where to store the result 199 * @param[out] dst where to store the result
200 * @return 200 * @return
201 * #GNUNET_YES if all results could be extracted 201 * #GNUNET_YES if all results could be extracted
202 * #GNUNET_NO if at least one result was NULL 202 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
203 * #GNUNET_SYSERR if a result was invalid (non-existing field)
204 */ 203 */
205typedef int 204typedef int
206(*GNUNET_PQ_ResultConverter)(void *cls, 205(*GNUNET_PQ_ResultConverter)(void *cls,
diff --git a/src/pq/pq.c b/src/pq/pq.c
index 37d067edd..43186c41e 100644
--- a/src/pq/pq.c
+++ b/src/pq/pq.c
@@ -151,11 +151,9 @@ GNUNET_PQ_extract_result (PGresult *result,
151 &spec->dst_size, 151 &spec->dst_size,
152 spec->dst); 152 spec->dst);
153 if (GNUNET_SYSERR == ret) 153 if (GNUNET_SYSERR == ret)
154 return GNUNET_SYSERR;
155 if (GNUNET_NO == ret)
156 { 154 {
157 had_null = GNUNET_YES; 155 GNUNET_PQ_cleanup_result (rs);
158 continue; 156 return GNUNET_SYSERR;
159 } 157 }
160 if (NULL != spec->result_size) 158 if (NULL != spec->result_size)
161 *spec->result_size = spec->dst_size; 159 *spec->result_size = spec->dst_size;
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 8baf0b00f..c3f3cfb2f 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -55,9 +55,8 @@ clean_varsize_blob (void *cls,
55 * @param[out] dst where to store the result 55 * @param[out] dst where to store the result
56 * @return 56 * @return
57 * #GNUNET_YES if all results could be extracted 57 * #GNUNET_YES if all results could be extracted
58 * #GNUNET_NO if at least one result was NULL
59 * #GNUNET_SYSERR if a result was invalid (non-existing field) 58 * #GNUNET_SYSERR if a result was invalid (non-existing field)
60 */ 59 */
61static int 60static int
62extract_varsize_blob (void *cls, 61extract_varsize_blob (void *cls,
63 PGresult *result, 62 PGresult *result,
@@ -70,7 +69,7 @@ extract_varsize_blob (void *cls,
70 const char *res; 69 const char *res;
71 void *idst; 70 void *idst;
72 int fnum; 71 int fnum;
73 72
74 fnum = PQfnumber (result, 73 fnum = PQfnumber (result,
75 fname); 74 fname);
76 if (fnum < 0) 75 if (fnum < 0)
@@ -83,8 +82,8 @@ extract_varsize_blob (void *cls,
83 if (PQgetisnull (result, 82 if (PQgetisnull (result,
84 row, 83 row,
85 fnum)) 84 fnum))
86 return GNUNET_NO; 85 return GNUNET_SYSERR;
87 86
88 /* if a field is null, continue but 87 /* if a field is null, continue but
89 * remember that we now return a different result */ 88 * remember that we now return a different result */
90 len = PQgetlength (result, 89 len = PQgetlength (result,
@@ -119,7 +118,7 @@ GNUNET_PQ_result_spec_variable_size (const char *name,
119{ 118{
120 struct GNUNET_PQ_ResultSpec res = 119 struct GNUNET_PQ_ResultSpec res =
121 { &extract_varsize_blob, 120 { &extract_varsize_blob,
122 &clean_varsize_blob, NULL, 121 &clean_varsize_blob, NULL,
123 (void *) (dst), 0, name, sptr }; 122 (void *) (dst), 0, name, sptr };
124 return res; 123 return res;
125} 124}
@@ -136,9 +135,8 @@ GNUNET_PQ_result_spec_variable_size (const char *name,
136 * @param[out] dst where to store the result 135 * @param[out] dst where to store the result
137 * @return 136 * @return
138 * #GNUNET_YES if all results could be extracted 137 * #GNUNET_YES if all results could be extracted
139 * #GNUNET_NO if at least one result was NULL 138 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
140 * #GNUNET_SYSERR if a result was invalid (non-existing field) 139 */
141 */
142static int 140static int
143extract_fixed_blob (void *cls, 141extract_fixed_blob (void *cls,
144 PGresult *result, 142 PGresult *result,
@@ -150,7 +148,7 @@ extract_fixed_blob (void *cls,
150 size_t len; 148 size_t len;
151 const char *res; 149 const char *res;
152 int fnum; 150 int fnum;
153 151
154 fnum = PQfnumber (result, 152 fnum = PQfnumber (result,
155 fname); 153 fname);
156 if (fnum < 0) 154 if (fnum < 0)
@@ -163,14 +161,14 @@ extract_fixed_blob (void *cls,
163 if (PQgetisnull (result, 161 if (PQgetisnull (result,
164 row, 162 row,
165 fnum)) 163 fnum))
166 return GNUNET_NO; 164 return GNUNET_SYSERR;
167 165
168 /* if a field is null, continue but 166 /* if a field is null, continue but
169 * remember that we now return a different result */ 167 * remember that we now return a different result */
170 len = PQgetlength (result, 168 len = PQgetlength (result,
171 row, 169 row,
172 fnum); 170 fnum);
173 if (*dst_size != len) 171 if (*dst_size != len)
174 { 172 {
175 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
176 "Field `%s' has wrong size (got %u, expected %u)\n", 174 "Field `%s' has wrong size (got %u, expected %u)\n",
@@ -205,7 +203,7 @@ GNUNET_PQ_result_spec_fixed_size (const char *name,
205{ 203{
206 struct GNUNET_PQ_ResultSpec res = 204 struct GNUNET_PQ_ResultSpec res =
207 { &extract_fixed_blob, 205 { &extract_fixed_blob,
208 NULL, NULL, 206 NULL, NULL,
209 (dst), dst_size, name, NULL }; 207 (dst), dst_size, name, NULL };
210 return res; 208 return res;
211} 209}
@@ -222,9 +220,8 @@ GNUNET_PQ_result_spec_fixed_size (const char *name,
222 * @param[out] dst where to store the result 220 * @param[out] dst where to store the result
223 * @return 221 * @return
224 * #GNUNET_YES if all results could be extracted 222 * #GNUNET_YES if all results could be extracted
225 * #GNUNET_NO if at least one result was NULL 223 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
226 * #GNUNET_SYSERR if a result was invalid (non-existing field) 224 */
227 */
228static int 225static int
229extract_rsa_public_key (void *cls, 226extract_rsa_public_key (void *cls,
230 PGresult *result, 227 PGresult *result,
@@ -251,7 +248,7 @@ extract_rsa_public_key (void *cls,
251 if (PQgetisnull (result, 248 if (PQgetisnull (result,
252 row, 249 row,
253 fnum)) 250 fnum))
254 return GNUNET_NO; 251 return GNUNET_SYSERR;
255 252
256 /* if a field is null, continue but 253 /* if a field is null, continue but
257 * remember that we now return a different result */ 254 * remember that we now return a different result */
@@ -286,7 +283,7 @@ clean_rsa_public_key (void *cls,
286 void *rd) 283 void *rd)
287{ 284{
288 struct GNUNET_CRYPTO_RsaPublicKey **pk = rd; 285 struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
289 286
290 if (NULL != *pk) 287 if (NULL != *pk)
291 { 288 {
292 GNUNET_CRYPTO_rsa_public_key_free (*pk); 289 GNUNET_CRYPTO_rsa_public_key_free (*pk);
@@ -326,9 +323,8 @@ GNUNET_PQ_result_spec_rsa_public_key (const char *name,
326 * @param[out] dst where to store the result 323 * @param[out] dst where to store the result
327 * @return 324 * @return
328 * #GNUNET_YES if all results could be extracted 325 * #GNUNET_YES if all results could be extracted
329 * #GNUNET_NO if at least one result was NULL 326 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
330 * #GNUNET_SYSERR if a result was invalid (non-existing field) 327 */
331 */
332static int 328static int
333extract_rsa_signature (void *cls, 329extract_rsa_signature (void *cls,
334 PGresult *result, 330 PGresult *result,
@@ -341,7 +337,7 @@ extract_rsa_signature (void *cls,
341 size_t len; 337 size_t len;
342 const char *res; 338 const char *res;
343 int fnum; 339 int fnum;
344 340
345 *sig = NULL; 341 *sig = NULL;
346 fnum = PQfnumber (result, 342 fnum = PQfnumber (result,
347 fname); 343 fname);
@@ -355,7 +351,7 @@ extract_rsa_signature (void *cls,
355 if (PQgetisnull (result, 351 if (PQgetisnull (result,
356 row, 352 row,
357 fnum)) 353 fnum))
358 return GNUNET_NO; 354 return GNUNET_SYSERR;
359 355
360 /* if a field is null, continue but 356 /* if a field is null, continue but
361 * remember that we now return a different result */ 357 * remember that we now return a different result */
@@ -463,9 +459,8 @@ GNUNET_PQ_result_spec_absolute_time_nbo (const char *name,
463 * @param[out] dst where to store the result 459 * @param[out] dst where to store the result
464 * @return 460 * @return
465 * #GNUNET_YES if all results could be extracted 461 * #GNUNET_YES if all results could be extracted
466 * #GNUNET_NO if at least one result was NULL 462 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
467 * #GNUNET_SYSERR if a result was invalid (non-existing field) 463 */
468 */
469static int 464static int
470extract_uint16 (void *cls, 465extract_uint16 (void *cls,
471 PGresult *result, 466 PGresult *result,
@@ -477,7 +472,7 @@ extract_uint16 (void *cls,
477 uint16_t *udst = dst; 472 uint16_t *udst = dst;
478 const uint16_t *res; 473 const uint16_t *res;
479 int fnum; 474 int fnum;
480 475
481 fnum = PQfnumber (result, 476 fnum = PQfnumber (result,
482 fname); 477 fname);
483 if (fnum < 0) 478 if (fnum < 0)
@@ -490,7 +485,7 @@ extract_uint16 (void *cls,
490 if (PQgetisnull (result, 485 if (PQgetisnull (result,
491 row, 486 row,
492 fnum)) 487 fnum))
493 return GNUNET_NO; 488 return GNUNET_SYSERR;
494 GNUNET_assert (NULL != dst); 489 GNUNET_assert (NULL != dst);
495 if (sizeof (uint16_t) != *dst_size) 490 if (sizeof (uint16_t) != *dst_size)
496 { 491 {
@@ -536,9 +531,8 @@ GNUNET_PQ_result_spec_uint16 (const char *name,
536 * @param[out] dst where to store the result 531 * @param[out] dst where to store the result
537 * @return 532 * @return
538 * #GNUNET_YES if all results could be extracted 533 * #GNUNET_YES if all results could be extracted
539 * #GNUNET_NO if at least one result was NULL 534 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
540 * #GNUNET_SYSERR if a result was invalid (non-existing field) 535 */
541 */
542static int 536static int
543extract_uint32 (void *cls, 537extract_uint32 (void *cls,
544 PGresult *result, 538 PGresult *result,
@@ -550,7 +544,7 @@ extract_uint32 (void *cls,
550 uint32_t *udst = dst; 544 uint32_t *udst = dst;
551 const uint32_t *res; 545 const uint32_t *res;
552 int fnum; 546 int fnum;
553 547
554 fnum = PQfnumber (result, 548 fnum = PQfnumber (result,
555 fname); 549 fname);
556 if (fnum < 0) 550 if (fnum < 0)
@@ -563,7 +557,7 @@ extract_uint32 (void *cls,
563 if (PQgetisnull (result, 557 if (PQgetisnull (result,
564 row, 558 row,
565 fnum)) 559 fnum))
566 return GNUNET_NO; 560 return GNUNET_SYSERR;
567 GNUNET_assert (NULL != dst); 561 GNUNET_assert (NULL != dst);
568 if (sizeof (uint32_t) != *dst_size) 562 if (sizeof (uint32_t) != *dst_size)
569 { 563 {
@@ -590,7 +584,7 @@ GNUNET_PQ_result_spec_uint32 (const char *name,
590 uint32_t *u32) 584 uint32_t *u32)
591{ 585{
592 struct GNUNET_PQ_ResultSpec res = 586 struct GNUNET_PQ_ResultSpec res =
593 { &extract_uint32, 587 { &extract_uint32,
594 NULL, 588 NULL,
595 NULL, 589 NULL,
596 (void *) u32, sizeof (*u32), (name), NULL }; 590 (void *) u32, sizeof (*u32), (name), NULL };
@@ -609,9 +603,8 @@ GNUNET_PQ_result_spec_uint32 (const char *name,
609 * @param[out] dst where to store the result 603 * @param[out] dst where to store the result
610 * @return 604 * @return
611 * #GNUNET_YES if all results could be extracted 605 * #GNUNET_YES if all results could be extracted
612 * #GNUNET_NO if at least one result was NULL 606 * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
613 * #GNUNET_SYSERR if a result was invalid (non-existing field) 607 */
614 */
615static int 608static int
616extract_uint64 (void *cls, 609extract_uint64 (void *cls,
617 PGresult *result, 610 PGresult *result,
@@ -623,7 +616,7 @@ extract_uint64 (void *cls,
623 uint64_t *udst = dst; 616 uint64_t *udst = dst;
624 const uint64_t *res; 617 const uint64_t *res;
625 int fnum; 618 int fnum;
626 619
627 fnum = PQfnumber (result, 620 fnum = PQfnumber (result,
628 fname); 621 fname);
629 if (fnum < 0) 622 if (fnum < 0)
@@ -636,7 +629,7 @@ extract_uint64 (void *cls,
636 if (PQgetisnull (result, 629 if (PQgetisnull (result,
637 row, 630 row,
638 fnum)) 631 fnum))
639 return GNUNET_NO; 632 return GNUNET_SYSERR;
640 GNUNET_assert (NULL != dst); 633 GNUNET_assert (NULL != dst);
641 if (sizeof (uint64_t) != *dst_size) 634 if (sizeof (uint64_t) != *dst_size)
642 { 635 {