aboutsummaryrefslogtreecommitdiff
path: root/src/my
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-03 09:53:10 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-03 09:53:10 +0000
commita7b1bfa4c5304d864d02187824ea1998ee53e59d (patch)
treea3bc4a74c7008d3c669c3f36ccb5155eae0c52e5 /src/my
parentb114c5d82d3984e6baa216ed47dee20fae9bf4d6 (diff)
downloadgnunet-a7b1bfa4c5304d864d02187824ea1998ee53e59d.tar.gz
gnunet-a7b1bfa4c5304d864d02187824ea1998ee53e59d.zip
refactoring my API
Diffstat (limited to 'src/my')
-rw-r--r--src/my/my.c202
-rw-r--r--src/my/my_result_helper.c310
2 files changed, 273 insertions, 239 deletions
diff --git a/src/my/my.c b/src/my/my.c
index 54b2a49b0..1d78a08cf 100644
--- a/src/my/my.c
+++ b/src/my/my.c
@@ -35,7 +35,7 @@
35 * @param mc mysql context 35 * @param mc mysql context
36 * @param sh handle to SELECT statment 36 * @param sh handle to SELECT statment
37 * @param params parameters to the statement 37 * @param params parameters to the statement
38 * @return 38 * @return
39 #GNUNET_YES if we can prepare all statement 39 #GNUNET_YES if we can prepare all statement
40 #GNUNET_SYSERR if we can't prepare all statement 40 #GNUNET_SYSERR if we can't prepare all statement
41 */ 41 */
@@ -98,37 +98,24 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
98 98
99 99
100/** 100/**
101 * Extract results from a query result according 101 * Extract results from a query result according to the given
102 * to the given specification. If colums are NULL, 102 * specification. Always fetches the next row.
103 * the destination is not modified, and #GNUNET_NO is returned4
104 * 103 *
105 * 104 *
106 * @param result 105 * @param sh statement that returned results
107 * @param row, the row from the result to extract 106 * @param rs specification to extract for
108 * @param result specificatio to extract for
109 * @return 107 * @return
110 #GNUNET_YES if all results could be extracted 108 * #GNUNET_YES if all results could be extracted
111 #GNUNET_NO if at least one result was NULL 109 * #GNUNET_NO if there is no more data in the result set
112 #GNUNET_SYSERR if a result was invalid 110 * #GNUNET_SYSERR if a result was invalid
113*/ 111 */
114int 112int
115GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, 113GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
116 struct GNUNET_MY_QueryParam *qp, 114 struct GNUNET_MY_ResultSpec *rs)
117 struct GNUNET_MY_ResultSpec *rs,
118 int row)
119{ 115{
120 MYSQL_BIND *result; 116 unsigned int num_fields;
121
122 int num_fields;
123 MYSQL_FIELD *fields;
124 MYSQL_RES *res;
125
126 unsigned int i; 117 unsigned int i;
127 unsigned int j;
128 int had_null = GNUNET_NO;
129 int ret; 118 int ret;
130
131 result = NULL;
132 MYSQL_STMT *stmt; 119 MYSQL_STMT *stmt;
133 120
134 stmt = GNUNET_MYSQL_statement_get_stmt (NULL /* FIXME */, sh); 121 stmt = GNUNET_MYSQL_statement_get_stmt (NULL /* FIXME */, sh);
@@ -141,115 +128,104 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
141 return GNUNET_SYSERR; 128 return GNUNET_SYSERR;
142 } 129 }
143 130
131 num_fields = 0;
132 for (i=0;NULL != rs[i].conv;i++)
133 num_fields += rs[i].num_fields;
144 134
145 num_fields = mysql_stmt_field_count (stmt); 135 if (mysql_stmt_field_count (stmt) != num_fields)
146 res = mysql_stmt_result_metadata (stmt);
147 fields = mysql_fetch_fields (res);
148
149 int int_data[num_fields];
150 long int long_data[num_fields];
151 short short_data[num_fields];
152 char str_data[STRING_SIZE];
153 int error[num_fields];
154
155 result = (MYSQL_BIND *)malloc (sizeof (MYSQL_BIND)*num_fields);
156 if(!result)
157 { 136 {
158 fprintf(stderr, "Error to allocate output buffers\n"); 137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
138 "Number of fields missmatch between SQL result and result specification\n");
159 return GNUNET_SYSERR; 139 return GNUNET_SYSERR;
160 } 140 }
161 141
162 memset(result, 0, sizeof (MYSQL_BIND) * num_fields);
163
164/** INITIALISER LE MYSQL_BIND ****/
165
166 for(i = 0 ; i< num_fields ;i++)
167 { 142 {
168 result[i].buffer_type = fields[i].type; 143 MYSQL_BIND result[num_fields];
169 result[i].is_null = 0; 144 unsigned int field_off;
170 result[i].error = &error[i];
171 145
172 switch (fields[i].type) 146 memset (result, 0, sizeof (MYSQL_BIND) * num_fields);
147 field_off = 0;
148 for (i=0;NULL != rs[i].conv;i++)
173 { 149 {
174 case MYSQL_TYPE_LONG: 150 struct GNUNET_MY_ResultSpec *rp = &rs[i];
175 result[i].buffer = &(int_data[i]);
176 result[i].buffer_length = sizeof (int_data);
177 break;
178
179 case MYSQL_TYPE_LONGLONG:
180 result[i].buffer = &(long_data[i]);
181 result[i].buffer_length = sizeof (long_data);
182 break;
183
184 case MYSQL_TYPE_STRING:
185 result[i].buffer = (char *)str_data;
186 result[i].buffer_length = sizeof (str_data);
187 break;
188
189 case MYSQL_TYPE_SHORT:
190 result[i].buffer = &(short_data[i]);
191 result[i].buffer_length = sizeof (short_data);
192 break;
193
194 default:
195 fprintf(stderr, "Failed : wrong type : %d!\n", fields[i].type);
196 }
197 }
198 151
199 if (mysql_stmt_bind_result(stmt, result)) 152 if (GNUNET_OK !=
200 { 153 rp->pre_conv (rp->cls,
201 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", 154 rp,
155 stmt,
156 field_off,
157 &result[field_off]))
158 {
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 "Pre-conversion for MySQL result failed at offset %u\n",
161 i);
162 GNUNET_MY_cleanup_result (rs);
163 return GNUNET_SYSERR;
164 }
165 field_off += rp->num_fields;
166 }
167 if (mysql_stmt_bind_result (stmt, result))
168 {
169 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
170 "my",
202 _("`%s' failed at %s:%d with error: %s\n"), 171 _("`%s' failed at %s:%d with error: %s\n"),
203 "mysql_stmt_bind_result", __FILE__, __LINE__, 172 "mysql_stmt_bind_result", __FILE__, __LINE__,
204 mysql_stmt_error (stmt)); 173 mysql_stmt_error (stmt));
205 return GNUNET_SYSERR; 174 return GNUNET_SYSERR;
206 }
207
208 /*** FAILED HERE ***/
209 if (mysql_stmt_fetch (stmt))
210 {
211 for(j = 0 ; j < num_fields ;j++)
212 {
213 fprintf(stderr, "Error Bind [%d] : %d\n", j, error[j]);
214 } 175 }
215 176 ret = mysql_stmt_fetch (stmt);
216 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", 177 if (MYSQL_NO_DATA == ret)
217 _("`%s' failed at %s:%d with error: %s\n"), 178 return GNUNET_NO;
218 "mysql_stmt_fetch", __FILE__, __LINE__, 179 if (0 != ret)
180 {
181 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
182 "my",
183 _("mysql_stmt_fetch failed at %s:%d with error: %s\n"),
184 __FILE__, __LINE__,
219 mysql_stmt_error (stmt)); 185 mysql_stmt_error (stmt));
220 return GNUNET_SYSERR; 186 return GNUNET_SYSERR;
221 } 187 }
222 188 field_off = 0;
223/* 189 for (i=0;NULL != rs[i].conv;i++)
224 while (1)
225 {
226 mysql_stmt_fetch (stmt);
227
228 for (i = 0 ; NULL != rs[i].conv ; i++)
229 { 190 {
230 struct GNUNET_MY_ResultSpec *spec; 191 struct GNUNET_MY_ResultSpec *rp = &rs[i];
231 192
232 spec = &rs[i]; 193 if (NULL != rp->post_conv)
233 ret = spec->conv (spec->conv_cls, 194 if (GNUNET_OK !=
234 spec, 195 rp->post_conv (rp->cls,
235 result); 196 rp,
236 197 stmt,
237 if (GNUNET_SYSERR == ret) 198 field_off,
238 { 199 &result[field_off]))
239 return GNUNET_SYSERR; 200 {
240 } 201 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
241 202 "Post-conversion for MySQL result failed at offset %u\n",
242 if (NULL != spec->result_size) 203 i);
243 *spec->result_size = spec->dst_size; 204 GNUNET_MY_cleanup_result (rs);
205 return GNUNET_SYSERR;
206 }
207 field_off += rp->num_fields;
244 } 208 }
245 } 209 }
210 return GNUNET_OK;
211}
246 212
247 if (GNUNET_YES == had_null)
248 return GNUNET_NO;
249*/
250 213
251 free (result); 214/**
252 return GNUNET_OK; 215 * Free all memory that was allocated in @a rs during
216 * #GNUNET_MY_extract_result().
217 *
218 * @param rs reult specification to clean up
219 */
220void
221GNUNET_MY_cleanup_result (struct GNUNET_PQ_ResultSpec *rs)
222{
223 unsigned int i;
224
225 for (i=0;NULL != rs[i].conv;i++)
226 rs[i].cleaner (rs[i].cls,
227 &rs[i]);
253} 228}
254 229
230
255/* end of my.c */ 231/* end of my.c */
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c
index a5c39913c..108edb62d 100644
--- a/src/my/my_result_helper.c
+++ b/src/my/my_result_helper.c
@@ -21,116 +21,166 @@
21#include "gnunet_my_lib.h" 21#include "gnunet_my_lib.h"
22 22
23/** 23/**
24 * extract data from a Mysql database @a result at row @a row 24 * extract data from a Mysql database @a result at row @a row
25 * 25 *
26 * @param cls closure 26 * @param cls closure
27 * @param qp data about the query 27 * @param qp data about the query
28 * @param result mysql result 28 * @param result mysql result
29 * @return 29 * @return
30 * #GNUNET_OK if all results could be extracted 30 * #GNUNET_OK if all results could be extracted
31 * #GNUNET_SYSERR if a result was invalid 31 * #GNUNET_SYSERR if a result was invalid
32 */ 32 */
33
34static int 33static int
35extract_varsize_blob (void *cls, 34pre_extract_varsize_blob (void *cls,
36 struct GNUNET_MY_ResultSpec *rs, 35 struct GNUNET_MY_ResultSpec *rs,
37 MYSQL_BIND *results) 36 MYSQL_BIND *results)
38{ 37{
39 size_t len; 38 results[0].buffer = NULL;
40 void *idst; 39 results[0].buffer_length = 0;
41 char * res; 40 results[0].length = &rs->mysql_bind_output_length;
41 return GNUNET_OK;
42}
42 43
43 if (results->is_null) 44
45/**
46 * extract data from a Mysql database @a result at row @a row
47 *
48 * @param cls closure
49 * @param[in,out] rs
50 * @param stmt the mysql statement that is being run
51 * @param column the column that is being processed
52 * @param[out] results
53 * @return
54 * #GNUNET_OK if all results could be extracted
55 * #GNUNET_SYSERR if a result was invalid
56 */
57static int
58post_extract_varsize_blob (void *cls,
59 struct GNUNET_MY_ResultSpec *rs,
60 MYSQL_STMT *stmt,
61 unsigned int column,
62 MYSQL_BIND *results)
63{
64 void *buf;
65 size_t size;
66
67 size = (size_t) rs->mysql_bind_output_length;
68 if (rs->mysql_bind_output_length != size)
69 return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
70 buf = GNUNET_malloc (size);
71 results[0].buffer = buf;
72 results[0].buffer_length = size;
73 if (0 !=
74 mysql_stmt_fetch_column (stmt,
75 results,
76 column,
77 0))
44 { 78 {
79 GNUNET_free (buf);
45 return GNUNET_SYSERR; 80 return GNUNET_SYSERR;
46 } 81 }
82 *(void **) rs->dst = buf;
83 *rs->result_size = size;
84 return GNUNET_OK;
85}
47 86
48 len = results->buffer_length;
49 res = results->buffer;
50
51 GNUNET_assert (NULL != res);
52
53 rs->dst_size = len;
54
55 idst = GNUNET_malloc (len);
56 *(void **)rs->dst = idst;
57
58 memcpy (idst,
59 res,
60 len);
61 87
62 return GNUNET_OK; 88/**
89 * extract data from a Mysql database @a result at row @a row
90 *
91 * @param cls closure
92 * @param[in,out] rs
93 */
94static void
95cleanup_varsize_blob (void *cls,
96 struct GNUNET_MY_ResultSpec *rs)
97{
98 void *ptr;
99
100 ptr = * (void **) rs->dst;
101 if (NULL == ptr)
102 return;
103 GNUNET_free (ptr);
104 *(void **) rs->dst = NULL;
105 *rs->result_size = 0;
63} 106}
64 107
108
65/** 109/**
66 * Variable-size result expected 110 * Variable-size result expected
67 * 111 *
68 * @param[out] dst where to store the result, allocated 112 * @param[out] dst where to store the result, allocated
69 * @param[out] sptr where to store the size of @a dst 113 * @param[out] sptr where to store the size of @a dst
70 * @return array entru for the result specification to use 114 * @return array entru for the result specification to use
71 */ 115 */
72struct GNUNET_MY_ResultSpec 116struct GNUNET_MY_ResultSpec
73GNUNET_MY_result_spec_variable_size (void **dst, 117GNUNET_MY_result_spec_variable_size (void **dst,
74 size_t *ptr_size) 118 size_t *ptr_size)
75{ 119{
76 struct GNUNET_MY_ResultSpec res = 120 struct GNUNET_MY_ResultSpec res =
77 { 121 {
78 &extract_varsize_blob, 122 .pre_conv = &pre_extract_varsize_blob,
79 NULL, 123 .post_conv = &post_extract_varsize_blob,
80 (void *)(dst), 124 .cleaner = &cleanup_varsize_blob,
81 0, 125 .dst = (void *)(dst),
82 ptr_size 126 .result_size = ptr_size,
127 .num_fields = 1
83 }; 128 };
84 129
85 return res; 130 return res;
86} 131}
87 132
133
88/** 134/**
89 * Extract data from a Mysql database @a result at row @a row 135 * Extract data from a Mysql database @a result at row @a row
90 * 136 *
91 * @param cls closure 137 * @param cls closure
92 * @param result where to extract data from 138 * @param result where to extract data from
93 * @param int row to extract data from 139 * @param int row to extract data from
94 * @param fname name (or prefix) of the fields to extract from 140 * @param fname name (or prefix) of the fields to extract from
95 * @param[in] dst_size desired size, never NULL 141 * @param[in] dst_size desired size, never NULL
96 * @param[out] dst where to store the result 142 * @param[out] dst where to store the result
97 * @return 143 * @return
98 * #GNUNET_OK if all results could be extracted 144 * #GNUNET_OK if all results could be extracted
99 * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) 145 * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL)
100 * 146 */
101 */
102static int 147static int
103extract_fixed_blob (void *cls, 148pre_extract_fixed_blob (void *cls,
104 struct GNUNET_MY_ResultSpec *rs, 149 struct GNUNET_MY_ResultSpec *rs,
105 MYSQL_BIND *results) 150 MYSQL_BIND *results)
106{ 151{
107 size_t len; 152 results[0].buffer = rs->dst;
108 const char *res; 153 results[0].buffer_length = rs->dst_size;
154 results[0].length = &rs->mysql_bind_output_length;
155 return GNUNET_OK;
156}
109 157
110 if (results->is_null)
111 {
112 return GNUNET_SYSERR;
113 }
114 158
115 len = results->buffer_length; 159/**
116 if (rs->dst_size != len) 160 * Check size of extracted fixed size data from a Mysql database @a
117 { 161 * result at row @a row
118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 162 *
119 "Results has wrong size (got %u, expected %u)\n", 163 * @param cls closure
120 (unsigned int)len, 164 * @param result where to extract data from
121 (unsigned int)rs->dst_size); 165 * @param int row to extract data from
166 * @param fname name (or prefix) of the fields to extract from
167 * @param[in] dst_size desired size, never NULL
168 * @param[out] dst where to store the result
169 * @return
170 * #GNUNET_OK if all results could be extracted
171 * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL)
172 */
173static int
174post_extract_fixed_blob (void *cls,
175 struct GNUNET_MY_ResultSpec *rs,
176 MYSQL_BIND *results)
177{
178 if (rs->dst_size != rs->mysql_bind_output_length)
122 return GNUNET_SYSERR; 179 return GNUNET_SYSERR;
123 }
124
125 res = results->buffer;
126
127 GNUNET_assert (NULL != res);
128 memcpy (rs->dst,
129 res,
130 len);
131
132 return GNUNET_OK; 180 return GNUNET_OK;
133} 181}
182
183
134/** 184/**
135 * Fixed-size result expected. 185 * Fixed-size result expected.
136 * 186 *
@@ -143,15 +193,15 @@ struct GNUNET_MY_ResultSpec
143GNUNET_MY_result_spec_fixed_size (void *ptr, 193GNUNET_MY_result_spec_fixed_size (void *ptr,
144 size_t ptr_size) 194 size_t ptr_size)
145{ 195{
146 struct GNUNET_MY_ResultSpec res = 196 struct GNUNET_MY_ResultSpec res =
147 { 197 {
148 &extract_fixed_blob, 198 .pre_conv = &pre_extract_fixed_blob,
149 NULL, 199 .post_conv = &post_extract_fixed_blob,
150 (void *)(ptr), 200 .dst = (void *)(ptr),
151 ptr_size, 201 .dst_size = ptr_size,
152 NULL 202 .num_fields = 1
153 }; 203 };
154 204
155 return res; 205 return res;
156} 206}
157 207
@@ -175,7 +225,7 @@ extract_rsa_public_key (void *cls,
175 225
176{ 226{
177 struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst; 227 struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst;
178 228
179 size_t len; 229 size_t len;
180 const char *res; 230 const char *res;
181 231
@@ -215,7 +265,8 @@ GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa)
215 NULL, 265 NULL,
216 (void *) rsa, 266 (void *) rsa,
217 0, 267 0,
218 NULL 268 NULL,
269 1
219 }; 270 };
220 271
221 return res; 272 return res;
@@ -273,13 +324,14 @@ extract_rsa_signature (void *cls,
273struct GNUNET_MY_ResultSpec 324struct GNUNET_MY_ResultSpec
274GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) 325GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
275{ 326{
276 struct GNUNET_MY_ResultSpec res = 327 struct GNUNET_MY_ResultSpec res =
277 { 328 {
278 &extract_rsa_signature, 329 &extract_rsa_signature,
279 NULL, 330 NULL,
280 (void *)sig, 331 (void *)sig,
281 0, 332 0,
282 NULL 333 NULL,
334 1
283 }; 335 };
284 return res; 336 return res;
285} 337}
@@ -326,13 +378,15 @@ extract_string (void * cls,
326 return GNUNET_SYSERR; 378 return GNUNET_SYSERR;
327 } 379 }
328 return GNUNET_OK; 380 return GNUNET_OK;
329} 381}
382
383
330/** 384/**
331 * 0- terminated string exprected. 385 * 0- terminated string exprected.
332 * 386 *
333 * @param[out] dst where to store the result, allocated 387 * @param[out] dst where to store the result, allocated
334 * @return array entry for the result specification to use 388 * @return array entry for the result specification to use
335 */ 389 */
336struct GNUNET_MY_ResultSpec 390struct GNUNET_MY_ResultSpec
337GNUNET_MY_result_spec_string (char **dst) 391GNUNET_MY_result_spec_string (char **dst)
338{ 392{
@@ -341,17 +395,19 @@ GNUNET_MY_result_spec_string (char **dst)
341 NULL, 395 NULL,
342 (void *) dst, 396 (void *) dst,
343 0, 397 0,
344 NULL 398 NULL,
399 1
345 }; 400 };
346 return res; 401 return res;
347} 402}
348 403
404
349/** 405/**
350 * Absolute time expected 406 * Absolute time expected
351 * 407 *
352 * @param name name of the field in the table 408 * @param name name of the field in the table
353 * @param[out] at where to store the result 409 * @param[out] at where to store the result
354 * @return array entry for the result specification to use 410 * @return array entry for the result specification to use
355 */ 411 */
356struct GNUNET_MY_ResultSpec 412struct GNUNET_MY_ResultSpec
357GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at) 413GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
@@ -359,6 +415,7 @@ GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
359 return GNUNET_MY_result_spec_uint64 (&at->abs_value_us); 415 return GNUNET_MY_result_spec_uint64 (&at->abs_value_us);
360} 416}
361 417
418
362/** 419/**
363 * Absolute time in network byte order expected 420 * Absolute time in network byte order expected
364 * 421 *
@@ -368,11 +425,12 @@ GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
368struct GNUNET_MY_ResultSpec 425struct GNUNET_MY_ResultSpec
369GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) 426GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at)
370{ 427{
371 struct GNUNET_MY_ResultSpec res = 428 struct GNUNET_MY_ResultSpec res =
372 GNUNET_MY_result_spec_auto_from_type (&at->abs_value_us__); 429 GNUNET_MY_result_spec_auto_from_type (&at->abs_value_us__);
373 return res; 430 return res;
374} 431}
375 432
433
376/** 434/**
377 * Extract data from a Postgres database @a result at row @a row. 435 * Extract data from a Postgres database @a result at row @a row.
378 * 436 *
@@ -390,7 +448,7 @@ static int
390extract_uint16 (void *cls, 448extract_uint16 (void *cls,
391 struct GNUNET_MY_ResultSpec *rs, 449 struct GNUNET_MY_ResultSpec *rs,
392 MYSQL_BIND *results) 450 MYSQL_BIND *results)
393{ 451{
394 uint16_t *udst = rs->dst; 452 uint16_t *udst = rs->dst;
395 const uint16_t *res; 453 const uint16_t *res;
396 454
@@ -412,12 +470,13 @@ extract_uint16 (void *cls,
412 return GNUNET_OK; 470 return GNUNET_OK;
413} 471}
414 472
473
415/** 474/**
416 * uint16_t expected 475 * uint16_t expected
417 * 476 *
418 * @param[out] u16 where to store the result 477 * @param[out] u16 where to store the result
419 * @return array entry for the result specification to use 478 * @return array entry for the result specification to use
420 */ 479 */
421struct GNUNET_MY_ResultSpec 480struct GNUNET_MY_ResultSpec
422GNUNET_MY_result_spec_uint16 (uint16_t *u16) 481GNUNET_MY_result_spec_uint16 (uint16_t *u16)
423{ 482{
@@ -426,7 +485,8 @@ GNUNET_MY_result_spec_uint16 (uint16_t *u16)
426 NULL, 485 NULL,
427 (void *) u16, 486 (void *) u16,
428 sizeof (*u16), 487 sizeof (*u16),
429 NULL 488 NULL,
489 1
430 }; 490 };
431 return res; 491 return res;
432} 492}
@@ -467,7 +527,7 @@ extract_uint32 (void *cls,
467 res = (uint32_t *)results->buffer; 527 res = (uint32_t *)results->buffer;
468 528
469 *udst = ntohl (*res); 529 *udst = ntohl (*res);
470 530
471 return GNUNET_OK; 531 return GNUNET_OK;
472} 532}
473 533
@@ -485,7 +545,8 @@ GNUNET_MY_result_spec_uint32 (uint32_t *u32)
485 NULL, 545 NULL,
486 (void *) u32, 546 (void *) u32,
487 sizeof (*u32), 547 sizeof (*u32),
488 NULL 548 NULL,
549 1
489 }; 550 };
490 return res; 551 return res;
491} 552}
@@ -511,10 +572,8 @@ extract_uint64 (void *cls,
511 uint64_t *udst = rs->dst; 572 uint64_t *udst = rs->dst;
512 const uint64_t *res; 573 const uint64_t *res;
513 574
514 if (results->is_null) 575 results[0].buffer = &rs->dst;
515 { 576 results[0].buffer_length = 42;
516 return GNUNET_SYSERR;
517 }
518 577
519 GNUNET_assert (NULL != rs->dst); 578 GNUNET_assert (NULL != rs->dst);
520 if (sizeof (uint64_t) != rs->dst_size) 579 if (sizeof (uint64_t) != rs->dst_size)
@@ -540,13 +599,12 @@ struct GNUNET_MY_ResultSpec
540GNUNET_MY_result_spec_uint64 (uint64_t *u64) 599GNUNET_MY_result_spec_uint64 (uint64_t *u64)
541{ 600{
542 struct GNUNET_MY_ResultSpec res = { 601 struct GNUNET_MY_ResultSpec res = {
543 &extract_uint64, 602 .pre_conv = &extract_uint64,
544 NULL, 603 .dst = (void *) u64,
545 (void *) u64, 604 .dst_size = sizeof (*u64),
546 sizeof (*u64), 605 .num_fields = 1
547 NULL
548 }; 606 };
549 return res; 607 return res;
550} 608}
551 609
552/* end of pq_result_helper.c */ \ No newline at end of file 610/* end of pq_result_helper.c */