diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-03 09:53:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-03 09:53:10 +0000 |
commit | a7b1bfa4c5304d864d02187824ea1998ee53e59d (patch) | |
tree | a3bc4a74c7008d3c669c3f36ccb5155eae0c52e5 /src/include/gnunet_my_lib.h | |
parent | b114c5d82d3984e6baa216ed47dee20fae9bf4d6 (diff) | |
download | gnunet-a7b1bfa4c5304d864d02187824ea1998ee53e59d.tar.gz gnunet-a7b1bfa4c5304d864d02187824ea1998ee53e59d.zip |
refactoring my API
Diffstat (limited to 'src/include/gnunet_my_lib.h')
-rw-r--r-- | src/include/gnunet_my_lib.h | 76 |
1 files changed, 68 insertions, 8 deletions
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h index c0a6f4b90..1ab139d31 100644 --- a/src/include/gnunet_my_lib.h +++ b/src/include/gnunet_my_lib.h | |||
@@ -95,7 +95,7 @@ struct GNUNET_MY_QueryParam | |||
95 | /** | 95 | /** |
96 | * Information to pass to @e conv. Size of @a data. | 96 | * Information to pass to @e conv. Size of @a data. |
97 | */ | 97 | */ |
98 | unsigned long data_len ; | 98 | unsigned long data_len; |
99 | 99 | ||
100 | }; | 100 | }; |
101 | 101 | ||
@@ -149,15 +149,31 @@ struct GNUNET_MY_ResultSpec; | |||
149 | * Function called to convert input argument into SQL parameters. | 149 | * Function called to convert input argument into SQL parameters. |
150 | * | 150 | * |
151 | * @param cls closure | 151 | * @param cls closure |
152 | * @param pq data about the query | 152 | * @param[in,out] rs |
153 | * @param stmt the mysql statement that is being run | ||
154 | * @param column the column that is being processed | ||
155 | * @param[out] results | ||
153 | * @return -1 on error | 156 | * @return -1 on error |
154 | */ | 157 | */ |
155 | typedef int | 158 | typedef int |
156 | (*GNUNET_MY_ResultConverter)(void *cls, | 159 | (*GNUNET_MY_ResultConverter)(void *cls, |
157 | struct GNUNET_MY_ResultSpec *rs, | 160 | struct GNUNET_MY_ResultSpec *rs, |
161 | MYSQL_STMT *stmt, | ||
162 | unsigned int column, | ||
158 | MYSQL_BIND *results); | 163 | MYSQL_BIND *results); |
159 | 164 | ||
160 | /** | 165 | /** |
166 | * Function called to cleanup result data. | ||
167 | * | ||
168 | * @param cls closure | ||
169 | * @param rs spec to clean up | ||
170 | */ | ||
171 | typedef void | ||
172 | (*GNUNET_MY_ResultCleanup)(void *cls, | ||
173 | struct GNUNET_MY_ResultSpec *rs); | ||
174 | |||
175 | |||
176 | /** | ||
161 | * Information we pass to #GNUNET_MY_extract_result() to | 177 | * Information we pass to #GNUNET_MY_extract_result() to |
162 | * initialize the arguments of the prepared statement. | 178 | * initialize the arguments of the prepared statement. |
163 | */ | 179 | */ |
@@ -165,9 +181,19 @@ struct GNUNET_MY_ResultSpec | |||
165 | { | 181 | { |
166 | 182 | ||
167 | /** | 183 | /** |
168 | * Function to call for the type conversion. | 184 | * Function to call to initialize the MYSQL_BIND array. |
169 | */ | 185 | */ |
170 | GNUNET_MY_ResultConverter conv; | 186 | GNUNET_MY_ResultConverter pre_conv; |
187 | |||
188 | /** | ||
189 | * Function to call for converting the result. Can be NULL. | ||
190 | */ | ||
191 | GNUNET_MY_ResultConverter post_conv; | ||
192 | |||
193 | /** | ||
194 | * Function to call for cleaning up the result. Can be NULL. | ||
195 | */ | ||
196 | GNUNET_MY_ResultCleanup cleaner; | ||
171 | 197 | ||
172 | /** | 198 | /** |
173 | * Closure for @e conv. | 199 | * Closure for @e conv. |
@@ -191,6 +217,18 @@ struct GNUNET_MY_ResultSpec | |||
191 | */ | 217 | */ |
192 | size_t *result_size; | 218 | size_t *result_size; |
193 | 219 | ||
220 | /** | ||
221 | * How many fields does this result specification occupy | ||
222 | * in the result returned by MySQL. | ||
223 | */ | ||
224 | unsigned int num_fields; | ||
225 | |||
226 | /** | ||
227 | * Location where we temporarily store the output buffer | ||
228 | * length from MySQL. Internal to libgnunetmy. | ||
229 | */ | ||
230 | unsigned long mysql_bind_output_length; | ||
231 | |||
194 | }; | 232 | }; |
195 | 233 | ||
196 | 234 | ||
@@ -199,7 +237,7 @@ struct GNUNET_MY_ResultSpec | |||
199 | * | 237 | * |
200 | * @return array last entry for the result specification to use | 238 | * @return array last entry for the result specification to use |
201 | */ | 239 | */ |
202 | #define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL } | 240 | #define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL, 0 } |
203 | 241 | ||
204 | 242 | ||
205 | 243 | ||
@@ -392,11 +430,33 @@ GNUNET_MY_result_spec_uint32 (uint32_t *u32); | |||
392 | struct GNUNET_MY_ResultSpec | 430 | struct GNUNET_MY_ResultSpec |
393 | GNUNET_MY_result_spec_uint64 (uint64_t *u64); | 431 | GNUNET_MY_result_spec_uint64 (uint64_t *u64); |
394 | 432 | ||
433 | |||
434 | /** | ||
435 | * Extract results from a query result according to the given | ||
436 | * specification. Always fetches the next row. | ||
437 | * | ||
438 | * @param sh statement that returned results | ||
439 | * @param rs specification to extract for | ||
440 | * @return | ||
441 | * #GNUNET_YES if all results could be extracted | ||
442 | * #GNUNET_NO if there is no more data in the result set | ||
443 | * #GNUNET_SYSERR if a result was invalid | ||
444 | */ | ||
395 | int | 445 | int |
396 | GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | 446 | GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, |
397 | struct GNUNET_MY_QueryParam *qp, | 447 | struct GNUNET_MY_ResultSpec *specs); |
398 | struct GNUNET_MY_ResultSpec *specs, | 448 | |
399 | int row); | 449 | |
450 | |||
451 | /** | ||
452 | * Free all memory that was allocated in @a rs during | ||
453 | * #GNUNET_MY_extract_result(). | ||
454 | * | ||
455 | * @param rs reult specification to clean up | ||
456 | */ | ||
457 | void | ||
458 | GNUNET_MY_cleanup_result (struct GNUNET_PQ_ResultSpec *rs); | ||
459 | |||
400 | 460 | ||
401 | #if 0 /* keep Emacsens' auto-indent happy */ | 461 | #if 0 /* keep Emacsens' auto-indent happy */ |
402 | { | 462 | { |