aboutsummaryrefslogtreecommitdiff
path: root/src/my/my_query_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/my/my_query_helper.c')
-rw-r--r--src/my/my_query_helper.c128
1 files changed, 56 insertions, 72 deletions
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c
index cfa52b43a..c09422160 100644
--- a/src/my/my_query_helper.c
+++ b/src/my/my_query_helper.c
@@ -26,6 +26,22 @@
26#include <mysql/mysql.h> 26#include <mysql/mysql.h>
27#include "gnunet_my_lib.h" 27#include "gnunet_my_lib.h"
28 28
29
30/**
31 * Function called to clean up memory allocated
32 * by a #GNUNET_MY_QueryConverter.
33 *
34 * @param cls closure
35 * @param rd result data to clean up
36 */
37static void
38my_clean_query (void *cls,
39 MYSQL_BIND *qbind)
40{
41 GNUNET_free (qbind[0].buffer);
42}
43
44
29/** 45/**
30 * Function called to convert input argument into SQL parameters. 46 * Function called to convert input argument into SQL parameters.
31 * 47 *
@@ -84,6 +100,7 @@ GNUNET_MY_query_param_string (const char *ptr)
84 strlen(ptr)); 100 strlen(ptr));
85} 101}
86 102
103
87/** 104/**
88 * Function called to convert input argument into SQL parameters 105 * Function called to convert input argument into SQL parameters
89 * 106 *
@@ -107,7 +124,7 @@ my_conv_uint16 (void *cls,
107 if (NULL == u_nbo) 124 if (NULL == u_nbo)
108 return -1; 125 return -1;
109 126
110 *u_nbo = *u_hbo; 127 *u_nbo = *u_hbo;
111 128
112 qbind->buffer = (void *) u_nbo; 129 qbind->buffer = (void *) u_nbo;
113 qbind->buffer_length = sizeof(uint16_t); 130 qbind->buffer_length = sizeof(uint16_t);
@@ -116,6 +133,7 @@ my_conv_uint16 (void *cls,
116 return 1; 133 return 1;
117} 134}
118 135
136
119/** 137/**
120 * Generate query parameter for an uint16_t in host byte order. 138 * Generate query parameter for an uint16_t in host byte order.
121 * 139 *
@@ -126,7 +144,7 @@ GNUNET_MY_query_param_uint16 (const uint16_t *x)
126{ 144{
127 struct GNUNET_MY_QueryParam res = { 145 struct GNUNET_MY_QueryParam res = {
128 .conv = &my_conv_uint16, 146 .conv = &my_conv_uint16,
129 .cleaner = NULL, 147 .cleaner = &my_clean_query,
130 .conv_cls = NULL, 148 .conv_cls = NULL,
131 .num_params = 1, 149 .num_params = 1,
132 .data = x, 150 .data = x,
@@ -136,6 +154,7 @@ GNUNET_MY_query_param_uint16 (const uint16_t *x)
136 return res; 154 return res;
137} 155}
138 156
157
139/** 158/**
140 * Function called to convert input argument into SQL parameters 159 * Function called to convert input argument into SQL parameters
141 * 160 *
@@ -155,8 +174,8 @@ my_conv_uint32 (void *cls,
155 GNUNET_assert (1 == qp->num_params); 174 GNUNET_assert (1 == qp->num_params);
156 175
157 u_nbo = GNUNET_new (uint32_t); 176 u_nbo = GNUNET_new (uint32_t);
158// *u_nbo = htonl (*u_hbo); 177
159 *u_nbo = *u_hbo; 178 *u_nbo = *u_hbo;
160 179
161 qbind->buffer = (void *) u_nbo; 180 qbind->buffer = (void *) u_nbo;
162 qbind->buffer_length = sizeof(uint32_t); 181 qbind->buffer_length = sizeof(uint32_t);
@@ -165,6 +184,7 @@ my_conv_uint32 (void *cls,
165 return 1; 184 return 1;
166} 185}
167 186
187
168/** 188/**
169 * Generate query parameter for an uint32_t in host byte order 189 * Generate query parameter for an uint32_t in host byte order
170 * 190 *
@@ -175,7 +195,7 @@ GNUNET_MY_query_param_uint32 (const uint32_t *x)
175{ 195{
176 struct GNUNET_MY_QueryParam res = { 196 struct GNUNET_MY_QueryParam res = {
177 .conv = &my_conv_uint32, 197 .conv = &my_conv_uint32,
178 .cleaner = NULL, 198 .cleaner = &my_clean_query,
179 .conv_cls = NULL, 199 .conv_cls = NULL,
180 .num_params = 1, 200 .num_params = 1,
181 .data = x, 201 .data = x,
@@ -185,6 +205,7 @@ GNUNET_MY_query_param_uint32 (const uint32_t *x)
185 return res; 205 return res;
186} 206}
187 207
208
188/** 209/**
189 * Function called to convert input argument into SQL parameters 210 * Function called to convert input argument into SQL parameters
190 * 211 *
@@ -204,8 +225,8 @@ my_conv_uint64 (void *cls,
204 GNUNET_assert (1 == qp->num_params); 225 GNUNET_assert (1 == qp->num_params);
205 226
206 u_nbo = GNUNET_new(uint64_t); 227 u_nbo = GNUNET_new(uint64_t);
207 //*u_nbo = GNUNET_htonll (*u_hbo); 228
208 *u_nbo = *u_hbo; 229 *u_nbo = *u_hbo;
209 230
210 qbind->buffer = (void *) u_nbo; 231 qbind->buffer = (void *) u_nbo;
211 qbind->buffer_length = sizeof (uint64_t); 232 qbind->buffer_length = sizeof (uint64_t);
@@ -214,6 +235,7 @@ my_conv_uint64 (void *cls,
214 return 1; 235 return 1;
215} 236}
216 237
238
217/** 239/**
218 * Generate query parameter for an uint64_t in host byte order 240 * Generate query parameter for an uint64_t in host byte order
219 * 241 *
@@ -224,7 +246,7 @@ GNUNET_MY_query_param_uint64 (const uint64_t *x)
224{ 246{
225 struct GNUNET_MY_QueryParam res = { 247 struct GNUNET_MY_QueryParam res = {
226 .conv = &my_conv_uint64, 248 .conv = &my_conv_uint64,
227 .cleaner = NULL, 249 .cleaner = &my_clean_query,
228 .conv_cls = NULL, 250 .conv_cls = NULL,
229 .num_params = 1, 251 .num_params = 1,
230 .data = x, 252 .data = x,
@@ -234,6 +256,7 @@ GNUNET_MY_query_param_uint64 (const uint64_t *x)
234 return res; 256 return res;
235} 257}
236 258
259
237/** 260/**
238 * Function called to convert input argument into SQL parameters 261 * Function called to convert input argument into SQL parameters
239 * 262 *
@@ -246,57 +269,36 @@ static int
246my_conv_rsa_public_key (void *cls, 269my_conv_rsa_public_key (void *cls,
247 const struct GNUNET_MY_QueryParam *qp, 270 const struct GNUNET_MY_QueryParam *qp,
248 MYSQL_BIND * qbind) 271 MYSQL_BIND * qbind)
249 { 272{
250 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data; 273 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data;
251 char *buf; 274 char *buf;
252 size_t buf_size; 275 size_t buf_size;
253
254 GNUNET_assert(1 == qp->num_params);
255 // FIXME: this leaks memory right now...
256 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, &buf);
257
258 qbind->buffer = (void *) buf;
259 qbind->buffer_length = buf_size;
260 qbind->buffer_type = MYSQL_TYPE_BLOB;
261
262 return 1;
263 }
264 276
277 GNUNET_assert(1 == qp->num_params);
278 // FIXME: this leaks memory right now...
279 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, &buf);
265 280
266/** 281 qbind->buffer = (void *) buf;
267 * Function called to clean up memory allocated 282 qbind->buffer_length = buf_size;
268 * by a #GNUNET_MY_ResultConverter. 283 qbind->buffer_type = MYSQL_TYPE_BLOB;
269 *
270 * @param cls closure
271 * @param rd result data to clean up
272 */
273static void
274my_clean_rsa_public_key (void *cls,
275 struct GNUNET_MY_QueryParam *qp)
276{
277 struct GNUNET_CRYPTO_RsaPublicKey **pk = qp->data;
278 284
279 if (NULL != *pk) 285 return 1;
280 {
281 GNUNET_CRYPTO_rsa_public_key_free (*pk);
282 *pk = NULL;
283 }
284} 286}
285 287
286 288
287 /** 289/**
288 * Generate query parameter for an RSA public key. The 290 * Generate query parameter for an RSA public key. The
289 * database must contain a BLOB type in the respective position. 291 * database must contain a BLOB type in the respective position.
290 * 292 *
291 * @param x the query parameter to pass 293 * @param x the query parameter to pass
292 * @return array entry for the query parameters to use 294 * @return array entry for the query parameters to use
293 */ 295 */
294struct GNUNET_MY_QueryParam 296struct GNUNET_MY_QueryParam
295GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) 297GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x)
296{ 298{
297 struct GNUNET_MY_QueryParam res = { 299 struct GNUNET_MY_QueryParam res = {
298 .conv = &my_conv_rsa_public_key, 300 .conv = &my_conv_rsa_public_key,
299 .cleaner = &my_clean_rsa_public_key, 301 .cleaner = &my_clean_query,
300 .conv_cls = NULL, 302 .conv_cls = NULL,
301 .num_params = 1, 303 .num_params = 1,
302 .data = x, 304 .data = x,
@@ -312,7 +314,7 @@ GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x
312 * 314 *
313 *@param cls closure 315 *@param cls closure
314 *@param pq data about the query 316 *@param pq data about the query
315 * @param qbind array of parameters to initialize 317 *@param qbind array of parameters to initialize
316 *@return -1 on error 318 *@return -1 on error
317 */ 319 */
318static int 320static int
@@ -337,27 +339,6 @@ my_conv_rsa_signature (void *cls,
337 339
338 340
339/** 341/**
340 * Function called to clean up memory allocated
341 * by a #GNUNET_MY_QueryConverter.
342 *
343 * @param cls closure
344 * @param rd result data to clean up
345 */
346static void
347my_clean_rsa_signature (void *cls,
348 struct GNUNET_MY_QueryParam *qp)
349{
350 struct GNUNET_CRYPTO_RsaSignature **sig = qp->data;
351
352 if (NULL != *sig)
353 {
354 GNUNET_CRYPTO_rsa_signature_free (*sig);
355 *sig = NULL;
356 }
357}
358
359
360/**
361 * Generate query parameter for an RSA signature. The 342 * Generate query parameter for an RSA signature. The
362 * database must contain a BLOB type in the respective position 343 * database must contain a BLOB type in the respective position
363 * 344 *
@@ -369,7 +350,7 @@ GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
369{ 350{
370 struct GNUNET_MY_QueryParam res = { 351 struct GNUNET_MY_QueryParam res = {
371 .conv = &my_conv_rsa_signature, 352 .conv = &my_conv_rsa_signature,
372 .cleaner = &my_clean_rsa_signature, 353 .cleaner = &my_clean_query,
373 .conv_cls = NULL, 354 .conv_cls = NULL,
374 .num_params = 1, 355 .num_params = 1,
375 .data = (x), 356 .data = (x),
@@ -378,6 +359,7 @@ GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
378 return res; 359 return res;
379} 360}
380 361
362
381/** 363/**
382 * Generate query parameter for an absolute time value. 364 * Generate query parameter for an absolute time value.
383 * The database must store a 64-bit integer. 365 * The database must store a 64-bit integer.
@@ -391,6 +373,7 @@ GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
391 return GNUNET_MY_query_param_uint64 (&x->abs_value_us); 373 return GNUNET_MY_query_param_uint64 (&x->abs_value_us);
392} 374}
393 375
376
394/** 377/**
395 * Generate query parameter for an absolute time value. 378 * Generate query parameter for an absolute time value.
396 * The database must store a 64-bit integer. 379 * The database must store a 64-bit integer.
@@ -403,4 +386,5 @@ GNUNET_MY_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x
403 return GNUNET_MY_query_param_auto_from_type (&x->abs_value_us__); 386 return GNUNET_MY_query_param_auto_from_type (&x->abs_value_us__);
404} 387}
405 388
406/* end of my_query_helper.c */ 389
390/* end of my_query_helper.c */ \ No newline at end of file