diff options
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/include/gnunet_my_lib.h | 79 | ||||
-rw-r--r-- | src/my/my.c | 18 | ||||
-rw-r--r-- | src/my/my_query_helper.c | 283 |
4 files changed, 367 insertions, 14 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in index 7e20cb025..a31609cdd 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in | |||
@@ -227,6 +227,7 @@ src/multicast/gnunet-service-multicast.c | |||
227 | src/multicast/multicast_api.c | 227 | src/multicast/multicast_api.c |
228 | src/my/my.c | 228 | src/my/my.c |
229 | src/my/my_query_helper.c | 229 | src/my/my_query_helper.c |
230 | src/my/my_result_helper.c | ||
230 | src/mysql/mysql.c | 231 | src/mysql/mysql.c |
231 | src/namecache/gnunet-namecache.c | 232 | src/namecache/gnunet-namecache.c |
232 | src/namecache/gnunet-service-namecache.c | 233 | src/namecache/gnunet-service-namecache.c |
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h index 9a26022c8..8d60bf78c 100644 --- a/src/include/gnunet_my_lib.h +++ b/src/include/gnunet_my_lib.h | |||
@@ -120,7 +120,6 @@ struct GNUNET_MY_QueryParam | |||
120 | GNUNET_MY_query_param_fixed_size (const void *ptr, | 120 | GNUNET_MY_query_param_fixed_size (const void *ptr, |
121 | size_t ptr_size); | 121 | size_t ptr_size); |
122 | 122 | ||
123 | |||
124 | /** | 123 | /** |
125 | * Run a prepared SELECT statement. | 124 | * Run a prepared SELECT statement. |
126 | * | 125 | * |
@@ -212,6 +211,84 @@ struct GNUNET_MY_ResultSpec | |||
212 | GNUNET_MY_result_spec_fixed_size (void *ptr, | 211 | GNUNET_MY_result_spec_fixed_size (void *ptr, |
213 | size_t ptr_size); | 212 | size_t ptr_size); |
214 | 213 | ||
214 | /** | ||
215 | * Generate query parameter for a string | ||
216 | * | ||
217 | *@param ptr pointer to the string query parameter to pass | ||
218 | */ | ||
219 | struct GNUNET_MY_QueryParam | ||
220 | GNUNET_MY_query_param_string (const char *ptr); | ||
221 | |||
222 | /** | ||
223 | * Generate fixed-size query parameter with size determined | ||
224 | * by variable type. | ||
225 | * | ||
226 | * @param x pointer to the query parameter to pass | ||
227 | */ | ||
228 | #define GNUNET_MY_query_param_auto_from_type(x) GNUNET_MY_query_param_fixed_size ((x), sizeof (*(x))) | ||
229 | |||
230 | /** | ||
231 | * Generate query parameter for an RSA public key. The | ||
232 | * database must contain a BLOB type in the respective position. | ||
233 | * | ||
234 | * @param x the query parameter to pass | ||
235 | * @return array entry for the query parameters to use | ||
236 | */ | ||
237 | struct GNUNET_MY_QueryParam | ||
238 | GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x); | ||
239 | |||
240 | /** | ||
241 | * Generate query parameter for an RSA signature. The | ||
242 | * database must contain a BLOB type in the respective position | ||
243 | * | ||
244 | *@param x the query parameter to pass | ||
245 | *@return array entry for the query parameters to use | ||
246 | */ | ||
247 | struct GNUNET_MY_QueryParam | ||
248 | GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x); | ||
249 | |||
250 | /** | ||
251 | * Generate query parameter for an absolute time value. | ||
252 | * The database must store a 64-bit integer. | ||
253 | * | ||
254 | *@param x pointer to the query parameter to pass | ||
255 | *@return array entry for the query parameters to use | ||
256 | */ | ||
257 | struct GNUNET_MY_QueryParam | ||
258 | GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x); | ||
259 | |||
260 | /** | ||
261 | * Generate query parameter for an absolute time value. | ||
262 | * The database must store a 64-bit integer. | ||
263 | * | ||
264 | *@param x pointer to the query parameter to pass | ||
265 | */ | ||
266 | struct GNUNET_MY_QueryParam | ||
267 | GNUNET_MY_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x); | ||
268 | |||
269 | /** | ||
270 | * Generate query parameter for an uint16_t in host byte order. | ||
271 | * | ||
272 | * @param x pointer to the query parameter to pass | ||
273 | */ | ||
274 | struct GNUNET_MY_QueryParam | ||
275 | GNUNET_MY_query_param_uint16 (const uint16_t *x); | ||
276 | |||
277 | /** | ||
278 | * Generate query parameter for an uint32_t in host byte order | ||
279 | * | ||
280 | *@param x pointer to the query parameter to pass | ||
281 | */ | ||
282 | struct GNUNET_MY_QueryParam | ||
283 | GNUNET_MY_query_param_uint32 (const uint32_t *x); | ||
284 | |||
285 | /** | ||
286 | * Generate query parameter for an uint64_t in host byte order | ||
287 | * | ||
288 | *@param x pointer to the query parameter to pass | ||
289 | */ | ||
290 | struct GNUNET_MY_QueryParam | ||
291 | GNUNET_MY_query_param_uint64 (const uint64_t *x); | ||
215 | 292 | ||
216 | /** | 293 | /** |
217 | * We expect a fixed-size result, with size determined by the type of `* dst` | 294 | * We expect a fixed-size result, with size determined by the type of `* dst` |
diff --git a/src/my/my.c b/src/my/my.c index 71d30dd16..89d8c3370 100644 --- a/src/my/my.c +++ b/src/my/my.c | |||
@@ -109,30 +109,30 @@ GNUNET_MY_extract_result (MYSQL_BIND * result, | |||
109 | int row, | 109 | int row, |
110 | struct GNUNET_MY_ResultSpec *specs) | 110 | struct GNUNET_MY_ResultSpec *specs) |
111 | { | 111 | { |
112 | unsigned int i ; | 112 | unsigned int i; |
113 | int had_null = GNUNET_NO ; | 113 | int had_null = GNUNET_NO; |
114 | int ret ; | 114 | int ret; |
115 | 115 | ||
116 | for(i = 0 ; NULL != specs[i].conv ; i++) | 116 | for(i = 0 ; NULL != specs[i].conv ; i++) |
117 | { | 117 | { |
118 | struct GNUNET_MY_ResultSpec * spec ; | 118 | struct GNUNET_MY_ResultSpec *spec; |
119 | 119 | ||
120 | spec = &specs[i] ; | 120 | spec = &specs[i]; |
121 | ret = spec->conv(spec->conv_cls, | 121 | ret = spec->conv(spec->conv_cls, |
122 | NULL, //wait GNUNET_MY_QueryParam | 122 | NULL, //wait GNUNET_MY_QueryParam |
123 | result); | 123 | result); |
124 | 124 | ||
125 | if(ret == GNUNET_SYSERR) | 125 | if(ret == GNUNET_SYSERR) |
126 | return GNUNET_SYSERR ; | 126 | return GNUNET_SYSERR; |
127 | 127 | ||
128 | if(spec->result_size != NULL) | 128 | if(spec->result_size != NULL) |
129 | *spec->result_size = spec->dst_size; | 129 | *spec->result_size = spec->dst_size; |
130 | } | 130 | } |
131 | 131 | ||
132 | if(GNUNET_YES == had_null) | 132 | if(GNUNET_YES == had_null) |
133 | return GNUNET_NO ; | 133 | return GNUNET_NO; |
134 | 134 | ||
135 | return GNUNET_OK ; | 135 | return GNUNET_OK; |
136 | } | 136 | } |
137 | 137 | ||
138 | /* end of my.c */ | 138 | /* end of my.c */ \ No newline at end of file |
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c index 057c32d9f..3b5d90179 100644 --- a/src/my/my_query_helper.c +++ b/src/my/my_query_helper.c | |||
@@ -36,7 +36,7 @@ | |||
36 | * @return -1 on error | 36 | * @return -1 on error |
37 | */ | 37 | */ |
38 | static int | 38 | static int |
39 | pq_conv_fixed_size (void *cls, | 39 | my_conv_fixed_size (void *cls, |
40 | const struct GNUNET_MY_QueryParam *qp, | 40 | const struct GNUNET_MY_QueryParam *qp, |
41 | MYSQL_BIND *qbind) | 41 | MYSQL_BIND *qbind) |
42 | { | 42 | { |
@@ -53,14 +53,14 @@ pq_conv_fixed_size (void *cls, | |||
53 | * @a ptr_size bytes. | 53 | * @a ptr_size bytes. |
54 | * | 54 | * |
55 | * @param ptr pointer to the query parameter to pass | 55 | * @param ptr pointer to the query parameter to pass |
56 | * @oaran ptr_size number of bytes in @a ptr | 56 | * @param ptr_size number of bytes in @a ptr |
57 | */ | 57 | */ |
58 | struct GNUNET_MY_QueryParam | 58 | struct GNUNET_MY_QueryParam |
59 | GNUNET_MY_query_param_fixed_size (const void *ptr, | 59 | GNUNET_MY_query_param_fixed_size (const void *ptr, |
60 | size_t ptr_size) | 60 | size_t ptr_size) |
61 | { | 61 | { |
62 | struct GNUNET_MY_QueryParam qp = { | 62 | struct GNUNET_MY_QueryParam qp = { |
63 | &pq_conv_fixed_size, | 63 | &my_conv_fixed_size, |
64 | NULL, | 64 | NULL, |
65 | 1, | 65 | 1, |
66 | ptr, | 66 | ptr, |
@@ -70,4 +70,279 @@ GNUNET_MY_query_param_fixed_size (const void *ptr, | |||
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | /* end of my_query_helper.c */ | 73 | /** |
74 | * Generate query parameter for a string | ||
75 | * | ||
76 | *@param ptr pointer to the string query parameter to pass | ||
77 | */ | ||
78 | struct GNUNET_MY_QueryParam | ||
79 | GNUNET_MY_query_param_string (const char *ptr) | ||
80 | { | ||
81 | return GNUNET_MY_query_param_fixed_size(ptr, | ||
82 | strlen(ptr)); | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * Function called to convert input argument into SQL parameters | ||
87 | * | ||
88 | *@param cls closure | ||
89 | *@param pq data about the query | ||
90 | * @param qbind array of parameters to initialize | ||
91 | *@return -1 on error | ||
92 | */ | ||
93 | static int | ||
94 | my_conv_uint16 (void *cls, | ||
95 | const struct GNUNET_MY_QueryParam * qp, | ||
96 | MYSQL_BIND *qbind) | ||
97 | { | ||
98 | const uint16_t *u_hbo = qp->data; | ||
99 | uint16_t *u_nbo; | ||
100 | |||
101 | GNUNET_assert (1 == qp->num_params); | ||
102 | |||
103 | u_nbo = GNUNET_new (uint16_t); | ||
104 | *u_nbo = htons (*u_hbo); | ||
105 | qbind->buffer = (void *) u_nbo; | ||
106 | qbind->buffer_length = sizeof(uint16_t); | ||
107 | qbind->buffer_type = 1; | ||
108 | |||
109 | return 1; | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * Generate query parameter for an uint16_t in host byte order. | ||
114 | * | ||
115 | * @param x pointer to the query parameter to pass | ||
116 | */ | ||
117 | struct GNUNET_MY_QueryParam | ||
118 | GNUNET_MY_query_param_uint16 (const uint16_t *x) | ||
119 | { | ||
120 | struct GNUNET_MY_QueryParam res = { | ||
121 | &my_conv_uint16, | ||
122 | NULL, | ||
123 | 1, | ||
124 | x, | ||
125 | sizeof (*x) | ||
126 | }; | ||
127 | |||
128 | return res; | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * Function called to convert input argument into SQL parameters | ||
133 | * | ||
134 | *@param cls closure | ||
135 | *@param pq data about the query | ||
136 | * @param qbind array of parameters to initialize | ||
137 | *@return -1 on error | ||
138 | */ | ||
139 | static int | ||
140 | my_conv_uint32 (void *cls, | ||
141 | const struct GNUNET_MY_QueryParam *qp, | ||
142 | MYSQL_BIND *qbind) | ||
143 | { | ||
144 | const uint32_t *u_hbo = qp->data; | ||
145 | uint32_t * u_nbo; | ||
146 | |||
147 | GNUNET_assert (1 == qp->num_params); | ||
148 | |||
149 | u_nbo = GNUNET_new (uint32_t); | ||
150 | *u_nbo = htonl (*u_hbo); | ||
151 | |||
152 | qbind->buffer = (void *) u_nbo; | ||
153 | qbind->buffer_length = sizeof(uint32_t); | ||
154 | qbind->buffer_type = 1; | ||
155 | |||
156 | return 1; | ||
157 | } | ||
158 | |||
159 | /** | ||
160 | * Generate query parameter for an uint32_t in host byte order | ||
161 | * | ||
162 | *@param x pointer to the query parameter to pass | ||
163 | */ | ||
164 | struct GNUNET_MY_QueryParam | ||
165 | GNUNET_MY_query_param_uint32 (const uint32_t *x) | ||
166 | { | ||
167 | struct GNUNET_MY_QueryParam res = { | ||
168 | &my_conv_uint32, | ||
169 | NULL, | ||
170 | 1, | ||
171 | x, | ||
172 | sizeof (*x) | ||
173 | }; | ||
174 | |||
175 | return res; | ||
176 | } | ||
177 | |||
178 | /** | ||
179 | * Function called to convert input argument into SQL parameters | ||
180 | * | ||
181 | *@param cls closure | ||
182 | *@param pq data about the query | ||
183 | * @param qbind array of parameters to initialize | ||
184 | *@return -1 on error | ||
185 | */ | ||
186 | static int | ||
187 | my_conv_uint64 (void *cls, | ||
188 | const struct GNUNET_MY_QueryParam *qp, | ||
189 | MYSQL_BIND * qbind) | ||
190 | { | ||
191 | const uint64_t * u_hbo = qp->data; | ||
192 | uint64_t *u_nbo; | ||
193 | |||
194 | GNUNET_assert (1 == qp->num_params); | ||
195 | |||
196 | u_nbo = GNUNET_new(uint64_t); | ||
197 | *u_nbo = GNUNET_htonll (*u_hbo); | ||
198 | |||
199 | qbind->buffer = (void *) u_nbo; | ||
200 | qbind->buffer_length = sizeof (uint64_t); | ||
201 | qbind->buffer_type = 1; | ||
202 | |||
203 | return 1; | ||
204 | } | ||
205 | |||
206 | /** | ||
207 | * Generate query parameter for an uint64_t in host byte order | ||
208 | * | ||
209 | *@param x pointer to the query parameter to pass | ||
210 | */ | ||
211 | struct GNUNET_MY_QueryParam | ||
212 | GNUNET_MY_query_param_uint64 (const uint64_t *x) | ||
213 | { | ||
214 | struct GNUNET_MY_QueryParam res = { | ||
215 | &my_conv_uint64, | ||
216 | NULL, | ||
217 | 1, | ||
218 | x, | ||
219 | sizeof(*x) | ||
220 | }; | ||
221 | |||
222 | return res; | ||
223 | } | ||
224 | |||
225 | /** | ||
226 | * Function called to convert input argument into SQL parameters | ||
227 | * | ||
228 | *@param cls closure | ||
229 | *@param pq data about the query | ||
230 | * @param qbind array of parameters to initialize | ||
231 | *@return -1 on error | ||
232 | */ | ||
233 | static int | ||
234 | my_conv_rsa_public_key (void *cls, | ||
235 | const struct GNUNET_MY_QueryParam *qp, | ||
236 | MYSQL_BIND * qbind) | ||
237 | { | ||
238 | const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data; | ||
239 | char *buf; | ||
240 | size_t buf_size; | ||
241 | |||
242 | GNUNET_assert(1 == qp->num_params); | ||
243 | |||
244 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, &buf); | ||
245 | |||
246 | qbind->buffer = (void *)buf; | ||
247 | qbind->buffer_length = buf_size - 1; | ||
248 | qbind->buffer_type = 1; | ||
249 | |||
250 | return 1; | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * Generate query parameter for an RSA public key. The | ||
255 | * database must contain a BLOB type in the respective position. | ||
256 | * | ||
257 | * @param x the query parameter to pass | ||
258 | * @return array entry for the query parameters to use | ||
259 | */ | ||
260 | struct GNUNET_MY_QueryParam | ||
261 | GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) | ||
262 | { | ||
263 | struct GNUNET_MY_QueryParam res = { | ||
264 | &my_conv_rsa_public_key, | ||
265 | NULL, | ||
266 | 1, | ||
267 | x, | ||
268 | 0 | ||
269 | }; | ||
270 | |||
271 | return res; | ||
272 | } | ||
273 | |||
274 | /** | ||
275 | * Function called to convert input argument into SQL parameters | ||
276 | * | ||
277 | *@param cls closure | ||
278 | *@param pq data about the query | ||
279 | * @param qbind array of parameters to initialize | ||
280 | *@return -1 on error | ||
281 | */ | ||
282 | static int | ||
283 | my_conv_rsa_signature (void *cls, | ||
284 | const struct GNUNET_MY_QueryParam *qp, | ||
285 | MYSQL_BIND * qbind) | ||
286 | { | ||
287 | const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data; | ||
288 | char *buf; | ||
289 | size_t buf_size; | ||
290 | |||
291 | GNUNET_assert(1 == qp->num_params); | ||
292 | |||
293 | buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig, | ||
294 | &buf); | ||
295 | |||
296 | qbind->buffer = (void *)buf; | ||
297 | qbind->buffer_length = buf_size - 1; | ||
298 | qbind->buffer_type = 1; | ||
299 | |||
300 | return 1; | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * Generate query parameter for an RSA signature. The | ||
305 | * database must contain a BLOB type in the respective position | ||
306 | * | ||
307 | *@param x the query parameter to pass | ||
308 | *@return array entry for the query parameters to use | ||
309 | */ | ||
310 | struct GNUNET_MY_QueryParam | ||
311 | GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | ||
312 | { | ||
313 | struct GNUNET_MY_QueryParam res = { | ||
314 | &my_conv_rsa_signature, | ||
315 | NULL, | ||
316 | 1, | ||
317 | (x), | ||
318 | 0 | ||
319 | }; | ||
320 | return res; | ||
321 | } | ||
322 | |||
323 | /** | ||
324 | * Generate query parameter for an absolute time value. | ||
325 | * The database must store a 64-bit integer. | ||
326 | * | ||
327 | *@param x pointer to the query parameter to pass | ||
328 | *@return array entry for the query parameters to use | ||
329 | */ | ||
330 | struct GNUNET_MY_QueryParam | ||
331 | GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) | ||
332 | { | ||
333 | return GNUNET_MY_query_param_uint64 (&x->abs_value_us); | ||
334 | } | ||
335 | |||
336 | /** | ||
337 | * Generate query parameter for an absolute time value. | ||
338 | * The database must store a 64-bit integer. | ||
339 | * | ||
340 | *@param x pointer to the query parameter to pass | ||
341 | */ | ||
342 | struct GNUNET_MY_QueryParam | ||
343 | GNUNET_MY_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x) | ||
344 | { | ||
345 | return GNUNET_MY_query_param_auto_from_type (&x->abs_value_us__); | ||
346 | } | ||
347 | |||
348 | /* end of my_query_helper.c */ \ No newline at end of file | ||