summaryrefslogtreecommitdiff
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.c153
1 files changed, 78 insertions, 75 deletions
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c
index 8d4435b01..764021057 100644
--- a/src/my/my_query_helper.c
+++ b/src/my/my_query_helper.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file my/my_query_helper.c 21 * @file my/my_query_helper.c
22 * @brief library to help with access to a MySQL database 22 * @brief library to help with access to a MySQL database
@@ -36,11 +36,11 @@
36 * @param qbind array of parameter to clean up 36 * @param qbind array of parameter to clean up
37 */ 37 */
38static void 38static void
39my_clean_query (void *cls, 39my_clean_query(void *cls,
40 MYSQL_BIND *qbind) 40 MYSQL_BIND *qbind)
41{ 41{
42 (void) cls; 42 (void)cls;
43 GNUNET_free (qbind[0].buffer); 43 GNUNET_free(qbind[0].buffer);
44} 44}
45 45
46 46
@@ -53,13 +53,13 @@ my_clean_query (void *cls,
53 * @return -1 on error 53 * @return -1 on error
54 */ 54 */
55static int 55static int
56my_conv_fixed_size (void *cls, 56my_conv_fixed_size(void *cls,
57 const struct GNUNET_MY_QueryParam *qp, 57 const struct GNUNET_MY_QueryParam *qp,
58 MYSQL_BIND *qbind) 58 MYSQL_BIND *qbind)
59{ 59{
60 (void) cls; 60 (void)cls;
61 GNUNET_assert (1 == qp->num_params); 61 GNUNET_assert(1 == qp->num_params);
62 qbind->buffer = (void *) qp->data; 62 qbind->buffer = (void *)qp->data;
63 qbind->buffer_length = qp->data_len; 63 qbind->buffer_length = qp->data_len;
64 qbind->buffer_type = MYSQL_TYPE_BLOB; 64 qbind->buffer_type = MYSQL_TYPE_BLOB;
65 65
@@ -75,8 +75,8 @@ my_conv_fixed_size (void *cls,
75 * @param ptr_size number of bytes in @a ptr 75 * @param ptr_size number of bytes in @a ptr
76 */ 76 */
77struct GNUNET_MY_QueryParam 77struct GNUNET_MY_QueryParam
78GNUNET_MY_query_param_fixed_size (const void *ptr, 78GNUNET_MY_query_param_fixed_size(const void *ptr,
79 size_t ptr_size) 79 size_t ptr_size)
80{ 80{
81 struct GNUNET_MY_QueryParam qp = { 81 struct GNUNET_MY_QueryParam qp = {
82 .conv = &my_conv_fixed_size, 82 .conv = &my_conv_fixed_size,
@@ -84,8 +84,9 @@ GNUNET_MY_query_param_fixed_size (const void *ptr,
84 .conv_cls = NULL, 84 .conv_cls = NULL,
85 .num_params = 1, 85 .num_params = 1,
86 .data = ptr, 86 .data = ptr,
87 .data_len = (unsigned long) ptr_size 87 .data_len = (unsigned long)ptr_size
88 }; 88 };
89
89 return qp; 90 return qp;
90} 91}
91 92
@@ -99,13 +100,13 @@ GNUNET_MY_query_param_fixed_size (const void *ptr,
99 * @return -1 on error 100 * @return -1 on error
100 */ 101 */
101static int 102static int
102my_conv_string (void *cls, 103my_conv_string(void *cls,
103 const struct GNUNET_MY_QueryParam *qp, 104 const struct GNUNET_MY_QueryParam *qp,
104 MYSQL_BIND *qbind) 105 MYSQL_BIND *qbind)
105{ 106{
106 (void) cls; 107 (void)cls;
107 GNUNET_assert (1 == qp->num_params); 108 GNUNET_assert(1 == qp->num_params);
108 qbind->buffer = (void *) qp->data; 109 qbind->buffer = (void *)qp->data;
109 qbind->buffer_length = qp->data_len; 110 qbind->buffer_length = qp->data_len;
110 qbind->buffer_type = MYSQL_TYPE_STRING; 111 qbind->buffer_type = MYSQL_TYPE_STRING;
111 return 1; 112 return 1;
@@ -118,7 +119,7 @@ my_conv_string (void *cls,
118 * @param ptr pointer to the string query parameter to pass 119 * @param ptr pointer to the string query parameter to pass
119 */ 120 */
120struct GNUNET_MY_QueryParam 121struct GNUNET_MY_QueryParam
121GNUNET_MY_query_param_string (const char *ptr) 122GNUNET_MY_query_param_string(const char *ptr)
122{ 123{
123 struct GNUNET_MY_QueryParam qp = { 124 struct GNUNET_MY_QueryParam qp = {
124 .conv = &my_conv_string, 125 .conv = &my_conv_string,
@@ -126,8 +127,9 @@ GNUNET_MY_query_param_string (const char *ptr)
126 .conv_cls = NULL, 127 .conv_cls = NULL,
127 .num_params = 1, 128 .num_params = 1,
128 .data = ptr, 129 .data = ptr,
129 .data_len = strlen (ptr) 130 .data_len = strlen(ptr)
130 }; 131 };
132
131 return qp; 133 return qp;
132} 134}
133 135
@@ -141,14 +143,14 @@ GNUNET_MY_query_param_string (const char *ptr)
141 * @return -1 on error 143 * @return -1 on error
142 */ 144 */
143static int 145static int
144my_conv_uint16 (void *cls, 146my_conv_uint16(void *cls,
145 const struct GNUNET_MY_QueryParam *qp, 147 const struct GNUNET_MY_QueryParam *qp,
146 MYSQL_BIND *qbind) 148 MYSQL_BIND *qbind)
147{ 149{
148 (void) cls; 150 (void)cls;
149 GNUNET_assert (1 == qp->num_params); 151 GNUNET_assert(1 == qp->num_params);
150 qbind->buffer = (void *) qp->data; 152 qbind->buffer = (void *)qp->data;
151 qbind->buffer_length = sizeof (uint16_t); 153 qbind->buffer_length = sizeof(uint16_t);
152 qbind->buffer_type = MYSQL_TYPE_SHORT; 154 qbind->buffer_type = MYSQL_TYPE_SHORT;
153 qbind->is_unsigned = 1; 155 qbind->is_unsigned = 1;
154 return 1; 156 return 1;
@@ -161,7 +163,7 @@ my_conv_uint16 (void *cls,
161 * @param x pointer to the query parameter to pass 163 * @param x pointer to the query parameter to pass
162 */ 164 */
163struct GNUNET_MY_QueryParam 165struct GNUNET_MY_QueryParam
164GNUNET_MY_query_param_uint16 (const uint16_t *x) 166GNUNET_MY_query_param_uint16(const uint16_t *x)
165{ 167{
166 struct GNUNET_MY_QueryParam res = { 168 struct GNUNET_MY_QueryParam res = {
167 .conv = &my_conv_uint16, 169 .conv = &my_conv_uint16,
@@ -169,7 +171,7 @@ GNUNET_MY_query_param_uint16 (const uint16_t *x)
169 .conv_cls = NULL, 171 .conv_cls = NULL,
170 .num_params = 1, 172 .num_params = 1,
171 .data = x, 173 .data = x,
172 .data_len = sizeof (*x) 174 .data_len = sizeof(*x)
173 }; 175 };
174 176
175 return res; 177 return res;
@@ -185,13 +187,13 @@ GNUNET_MY_query_param_uint16 (const uint16_t *x)
185 * @return -1 on error 187 * @return -1 on error
186 */ 188 */
187static int 189static int
188my_conv_uint32 (void *cls, 190my_conv_uint32(void *cls,
189 const struct GNUNET_MY_QueryParam *qp, 191 const struct GNUNET_MY_QueryParam *qp,
190 MYSQL_BIND *qbind) 192 MYSQL_BIND *qbind)
191{ 193{
192 (void) cls; 194 (void)cls;
193 GNUNET_assert (1 == qp->num_params); 195 GNUNET_assert(1 == qp->num_params);
194 qbind->buffer = (void *) qp->data; 196 qbind->buffer = (void *)qp->data;
195 qbind->buffer_length = sizeof(uint32_t); 197 qbind->buffer_length = sizeof(uint32_t);
196 qbind->buffer_type = MYSQL_TYPE_LONG; 198 qbind->buffer_type = MYSQL_TYPE_LONG;
197 qbind->is_unsigned = 1; 199 qbind->is_unsigned = 1;
@@ -205,7 +207,7 @@ my_conv_uint32 (void *cls,
205 * @param x pointer to the query parameter to pass 207 * @param x pointer to the query parameter to pass
206 */ 208 */
207struct GNUNET_MY_QueryParam 209struct GNUNET_MY_QueryParam
208GNUNET_MY_query_param_uint32 (const uint32_t *x) 210GNUNET_MY_query_param_uint32(const uint32_t *x)
209{ 211{
210 struct GNUNET_MY_QueryParam res = { 212 struct GNUNET_MY_QueryParam res = {
211 .conv = &my_conv_uint32, 213 .conv = &my_conv_uint32,
@@ -213,7 +215,7 @@ GNUNET_MY_query_param_uint32 (const uint32_t *x)
213 .conv_cls = NULL, 215 .conv_cls = NULL,
214 .num_params = 1, 216 .num_params = 1,
215 .data = x, 217 .data = x,
216 .data_len = sizeof (*x) 218 .data_len = sizeof(*x)
217 }; 219 };
218 220
219 return res; 221 return res;
@@ -229,14 +231,14 @@ GNUNET_MY_query_param_uint32 (const uint32_t *x)
229 * @return -1 on error 231 * @return -1 on error
230 */ 232 */
231static int 233static int
232my_conv_uint64 (void *cls, 234my_conv_uint64(void *cls,
233 const struct GNUNET_MY_QueryParam *qp, 235 const struct GNUNET_MY_QueryParam *qp,
234 MYSQL_BIND * qbind) 236 MYSQL_BIND * qbind)
235{ 237{
236 (void) cls; 238 (void)cls;
237 GNUNET_assert (1 == qp->num_params); 239 GNUNET_assert(1 == qp->num_params);
238 qbind->buffer = (void *) qp->data; 240 qbind->buffer = (void *)qp->data;
239 qbind->buffer_length = sizeof (uint64_t); 241 qbind->buffer_length = sizeof(uint64_t);
240 qbind->buffer_type = MYSQL_TYPE_LONGLONG; 242 qbind->buffer_type = MYSQL_TYPE_LONGLONG;
241 qbind->is_unsigned = 1; 243 qbind->is_unsigned = 1;
242 return 1; 244 return 1;
@@ -249,7 +251,7 @@ my_conv_uint64 (void *cls,
249 * @param x pointer to the query parameter to pass 251 * @param x pointer to the query parameter to pass
250 */ 252 */
251struct GNUNET_MY_QueryParam 253struct GNUNET_MY_QueryParam
252GNUNET_MY_query_param_uint64 (const uint64_t *x) 254GNUNET_MY_query_param_uint64(const uint64_t *x)
253{ 255{
254 struct GNUNET_MY_QueryParam res = { 256 struct GNUNET_MY_QueryParam res = {
255 .conv = &my_conv_uint64, 257 .conv = &my_conv_uint64,
@@ -273,19 +275,19 @@ GNUNET_MY_query_param_uint64 (const uint64_t *x)
273 * @return -1 on error 275 * @return -1 on error
274 */ 276 */
275static int 277static int
276my_conv_rsa_public_key (void *cls, 278my_conv_rsa_public_key(void *cls,
277 const struct GNUNET_MY_QueryParam *qp, 279 const struct GNUNET_MY_QueryParam *qp,
278 MYSQL_BIND * qbind) 280 MYSQL_BIND * qbind)
279{ 281{
280 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data; 282 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data;
281 char *buf; 283 char *buf;
282 size_t buf_size; 284 size_t buf_size;
283 285
284 (void) cls; 286 (void)cls;
285 GNUNET_assert(1 == qp->num_params); 287 GNUNET_assert(1 == qp->num_params);
286 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, 288 buf_size = GNUNET_CRYPTO_rsa_public_key_encode(rsa,
287 &buf); 289 &buf);
288 qbind->buffer = (void *) buf; 290 qbind->buffer = (void *)buf;
289 qbind->buffer_length = buf_size; 291 qbind->buffer_length = buf_size;
290 qbind->buffer_type = MYSQL_TYPE_BLOB; 292 qbind->buffer_type = MYSQL_TYPE_BLOB;
291 return 1; 293 return 1;
@@ -300,7 +302,7 @@ my_conv_rsa_public_key (void *cls,
300 * @return array entry for the query parameters to use 302 * @return array entry for the query parameters to use
301 */ 303 */
302struct GNUNET_MY_QueryParam 304struct GNUNET_MY_QueryParam
303GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) 305GNUNET_MY_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x)
304{ 306{
305 struct GNUNET_MY_QueryParam res = { 307 struct GNUNET_MY_QueryParam res = {
306 .conv = &my_conv_rsa_public_key, 308 .conv = &my_conv_rsa_public_key,
@@ -316,27 +318,27 @@ GNUNET_MY_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x
316 318
317 319
318/** 320/**
319 * Function called to convert input argument into SQL parameters 321 * Function called to convert input argument into SQL parameters
320 * 322 *
321 *@param cls closure 323 *@param cls closure
322 *@param pq data about the query 324 *@param pq data about the query
323 *@param qbind array of parameters to initialize 325 *@param qbind array of parameters to initialize
324 *@return -1 on error 326 *@return -1 on error
325 */ 327 */
326static int 328static int
327my_conv_rsa_signature (void *cls, 329my_conv_rsa_signature(void *cls,
328 const struct GNUNET_MY_QueryParam *qp, 330 const struct GNUNET_MY_QueryParam *qp,
329 MYSQL_BIND *qbind) 331 MYSQL_BIND *qbind)
330{ 332{
331 const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data; 333 const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data;
332 char *buf; 334 char *buf;
333 size_t buf_size; 335 size_t buf_size;
334 336
335 (void) cls; 337 (void)cls;
336 GNUNET_assert(1 == qp->num_params); 338 GNUNET_assert(1 == qp->num_params);
337 buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig, 339 buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig,
338 &buf); 340 &buf);
339 qbind->buffer = (void *) buf; 341 qbind->buffer = (void *)buf;
340 qbind->buffer_length = buf_size; 342 qbind->buffer_length = buf_size;
341 qbind->buffer_type = MYSQL_TYPE_BLOB; 343 qbind->buffer_type = MYSQL_TYPE_BLOB;
342 return 1; 344 return 1;
@@ -351,7 +353,7 @@ my_conv_rsa_signature (void *cls,
351 * @return array entry for the query parameters to use 353 * @return array entry for the query parameters to use
352 */ 354 */
353struct GNUNET_MY_QueryParam 355struct GNUNET_MY_QueryParam
354GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) 356GNUNET_MY_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
355{ 357{
356 struct GNUNET_MY_QueryParam res = { 358 struct GNUNET_MY_QueryParam res = {
357 .conv = &my_conv_rsa_signature, 359 .conv = &my_conv_rsa_signature,
@@ -361,6 +363,7 @@ GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
361 .data = (x), 363 .data = (x),
362 .data_len = 0 364 .data_len = 0
363 }; 365 };
366
364 return res; 367 return res;
365} 368}
366 369
@@ -373,9 +376,9 @@ GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
373 * @return array entry for the query parameters to use 376 * @return array entry for the query parameters to use
374 */ 377 */
375struct GNUNET_MY_QueryParam 378struct GNUNET_MY_QueryParam
376GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) 379GNUNET_MY_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
377{ 380{
378 return GNUNET_MY_query_param_uint64 (&x->abs_value_us); 381 return GNUNET_MY_query_param_uint64(&x->abs_value_us);
379} 382}
380 383
381 384
@@ -386,9 +389,9 @@ GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
386 * @param x pointer to the query parameter to pass 389 * @param x pointer to the query parameter to pass
387 */ 390 */
388struct GNUNET_MY_QueryParam 391struct GNUNET_MY_QueryParam
389GNUNET_MY_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x) 392GNUNET_MY_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x)
390{ 393{
391 return GNUNET_MY_query_param_auto_from_type (&x->abs_value_us__); 394 return GNUNET_MY_query_param_auto_from_type(&x->abs_value_us__);
392} 395}
393 396
394 397