summaryrefslogtreecommitdiff
path: root/src/pq/pq_query_helper.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/pq/pq_query_helper.c
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/pq/pq_query_helper.c')
-rw-r--r--src/pq/pq_query_helper.c282
1 files changed, 144 insertions, 138 deletions
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index a6ce3c5d8..c3b86ee3d 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -1,22 +1,22 @@
1 /* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2014, 2015, 2016 GNUnet e.V. 3 Copyright (C) 2014, 2015, 2016 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
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 pq/pq_query_helper.c 21 * @file pq/pq_query_helper.c
22 * @brief functions to initialize parameter arrays 22 * @brief functions to initialize parameter arrays
@@ -42,22 +42,22 @@
42 * @return -1 on error, number of offsets used in @a scratch otherwise 42 * @return -1 on error, number of offsets used in @a scratch otherwise
43 */ 43 */
44static int 44static int
45qconv_fixed (void *cls, 45qconv_fixed(void *cls,
46 const void *data, 46 const void *data,
47 size_t data_len, 47 size_t data_len,
48 void *param_values[], 48 void *param_values[],
49 int param_lengths[], 49 int param_lengths[],
50 int param_formats[], 50 int param_formats[],
51 unsigned int param_length, 51 unsigned int param_length,
52 void *scratch[], 52 void *scratch[],
53 unsigned int scratch_length) 53 unsigned int scratch_length)
54{ 54{
55 (void) scratch; 55 (void)scratch;
56 (void) scratch_length; 56 (void)scratch_length;
57 GNUNET_break (NULL == cls); 57 GNUNET_break(NULL == cls);
58 if (1 != param_length) 58 if (1 != param_length)
59 return -1; 59 return -1;
60 param_values[0] = (void *) data; 60 param_values[0] = (void *)data;
61 param_lengths[0] = data_len; 61 param_lengths[0] = data_len;
62 param_formats[0] = 1; 62 param_formats[0] = 1;
63 return 0; 63 return 0;
@@ -72,11 +72,12 @@ qconv_fixed (void *cls,
72 * @oaran ptr_size number of bytes in @a ptr 72 * @oaran ptr_size number of bytes in @a ptr
73 */ 73 */
74struct GNUNET_PQ_QueryParam 74struct GNUNET_PQ_QueryParam
75GNUNET_PQ_query_param_fixed_size (const void *ptr, 75GNUNET_PQ_query_param_fixed_size(const void *ptr,
76 size_t ptr_size) 76 size_t ptr_size)
77{ 77{
78 struct GNUNET_PQ_QueryParam res = 78 struct GNUNET_PQ_QueryParam res =
79 { &qconv_fixed, NULL, ptr, ptr_size, 1 }; 79 { &qconv_fixed, NULL, ptr, ptr_size, 1 };
80
80 return res; 81 return res;
81} 82}
82 83
@@ -87,9 +88,9 @@ GNUNET_PQ_query_param_fixed_size (const void *ptr,
87 * @param ptr pointer to the string query parameter to pass 88 * @param ptr pointer to the string query parameter to pass
88 */ 89 */
89struct GNUNET_PQ_QueryParam 90struct GNUNET_PQ_QueryParam
90GNUNET_PQ_query_param_string (const char *ptr) 91GNUNET_PQ_query_param_string(const char *ptr)
91{ 92{
92 return GNUNET_PQ_query_param_fixed_size (ptr, strlen (ptr)); 93 return GNUNET_PQ_query_param_fixed_size(ptr, strlen(ptr));
93} 94}
94 95
95 96
@@ -108,29 +109,29 @@ GNUNET_PQ_query_param_string (const char *ptr)
108 * @return -1 on error, number of offsets used in @a scratch otherwise 109 * @return -1 on error, number of offsets used in @a scratch otherwise
109 */ 110 */
110static int 111static int
111qconv_uint16 (void *cls, 112qconv_uint16(void *cls,
112 const void *data, 113 const void *data,
113 size_t data_len, 114 size_t data_len,
114 void *param_values[], 115 void *param_values[],
115 int param_lengths[], 116 int param_lengths[],
116 int param_formats[], 117 int param_formats[],
117 unsigned int param_length, 118 unsigned int param_length,
118 void *scratch[], 119 void *scratch[],
119 unsigned int scratch_length) 120 unsigned int scratch_length)
120{ 121{
121 const uint16_t *u_hbo = data; 122 const uint16_t *u_hbo = data;
122 uint16_t *u_nbo; 123 uint16_t *u_nbo;
123 124
124 (void) scratch; 125 (void)scratch;
125 (void) scratch_length; 126 (void)scratch_length;
126 GNUNET_break (NULL == cls); 127 GNUNET_break(NULL == cls);
127 if (1 != param_length) 128 if (1 != param_length)
128 return -1; 129 return -1;
129 u_nbo = GNUNET_new (uint16_t); 130 u_nbo = GNUNET_new(uint16_t);
130 scratch[0] = u_nbo; 131 scratch[0] = u_nbo;
131 *u_nbo = htons (*u_hbo); 132 *u_nbo = htons(*u_hbo);
132 param_values[0] = (void *) u_nbo; 133 param_values[0] = (void *)u_nbo;
133 param_lengths[0] = sizeof (uint16_t); 134 param_lengths[0] = sizeof(uint16_t);
134 param_formats[0] = 1; 135 param_formats[0] = 1;
135 return 1; 136 return 1;
136} 137}
@@ -142,10 +143,11 @@ qconv_uint16 (void *cls,
142 * @param x pointer to the query parameter to pass 143 * @param x pointer to the query parameter to pass
143 */ 144 */
144struct GNUNET_PQ_QueryParam 145struct GNUNET_PQ_QueryParam
145GNUNET_PQ_query_param_uint16 (const uint16_t *x) 146GNUNET_PQ_query_param_uint16(const uint16_t *x)
146{ 147{
147 struct GNUNET_PQ_QueryParam res = 148 struct GNUNET_PQ_QueryParam res =
148 { &qconv_uint16, NULL, x, sizeof (*x), 1 }; 149 { &qconv_uint16, NULL, x, sizeof(*x), 1 };
150
149 return res; 151 return res;
150} 152}
151 153
@@ -165,29 +167,29 @@ GNUNET_PQ_query_param_uint16 (const uint16_t *x)
165 * @return -1 on error, number of offsets used in @a scratch otherwise 167 * @return -1 on error, number of offsets used in @a scratch otherwise
166 */ 168 */
167static int 169static int
168qconv_uint32 (void *cls, 170qconv_uint32(void *cls,
169 const void *data, 171 const void *data,
170 size_t data_len, 172 size_t data_len,
171 void *param_values[], 173 void *param_values[],
172 int param_lengths[], 174 int param_lengths[],
173 int param_formats[], 175 int param_formats[],
174 unsigned int param_length, 176 unsigned int param_length,
175 void *scratch[], 177 void *scratch[],
176 unsigned int scratch_length) 178 unsigned int scratch_length)
177{ 179{
178 const uint32_t *u_hbo = data; 180 const uint32_t *u_hbo = data;
179 uint32_t *u_nbo; 181 uint32_t *u_nbo;
180 182
181 (void) scratch; 183 (void)scratch;
182 (void) scratch_length; 184 (void)scratch_length;
183 GNUNET_break (NULL == cls); 185 GNUNET_break(NULL == cls);
184 if (1 != param_length) 186 if (1 != param_length)
185 return -1; 187 return -1;
186 u_nbo = GNUNET_new (uint32_t); 188 u_nbo = GNUNET_new(uint32_t);
187 scratch[0] = u_nbo; 189 scratch[0] = u_nbo;
188 *u_nbo = htonl (*u_hbo); 190 *u_nbo = htonl(*u_hbo);
189 param_values[0] = (void *) u_nbo; 191 param_values[0] = (void *)u_nbo;
190 param_lengths[0] = sizeof (uint32_t); 192 param_lengths[0] = sizeof(uint32_t);
191 param_formats[0] = 1; 193 param_formats[0] = 1;
192 return 1; 194 return 1;
193} 195}
@@ -199,10 +201,11 @@ qconv_uint32 (void *cls,
199 * @param x pointer to the query parameter to pass 201 * @param x pointer to the query parameter to pass
200 */ 202 */
201struct GNUNET_PQ_QueryParam 203struct GNUNET_PQ_QueryParam
202GNUNET_PQ_query_param_uint32 (const uint32_t *x) 204GNUNET_PQ_query_param_uint32(const uint32_t *x)
203{ 205{
204 struct GNUNET_PQ_QueryParam res = 206 struct GNUNET_PQ_QueryParam res =
205 { &qconv_uint32, NULL, x, sizeof (*x), 1 }; 207 { &qconv_uint32, NULL, x, sizeof(*x), 1 };
208
206 return res; 209 return res;
207} 210}
208 211
@@ -222,29 +225,29 @@ GNUNET_PQ_query_param_uint32 (const uint32_t *x)
222 * @return -1 on error, number of offsets used in @a scratch otherwise 225 * @return -1 on error, number of offsets used in @a scratch otherwise
223 */ 226 */
224static int 227static int
225qconv_uint64 (void *cls, 228qconv_uint64(void *cls,
226 const void *data, 229 const void *data,
227 size_t data_len, 230 size_t data_len,
228 void *param_values[], 231 void *param_values[],
229 int param_lengths[], 232 int param_lengths[],
230 int param_formats[], 233 int param_formats[],
231 unsigned int param_length, 234 unsigned int param_length,
232 void *scratch[], 235 void *scratch[],
233 unsigned int scratch_length) 236 unsigned int scratch_length)
234{ 237{
235 const uint64_t *u_hbo = data; 238 const uint64_t *u_hbo = data;
236 uint64_t *u_nbo; 239 uint64_t *u_nbo;
237 240
238 (void) scratch; 241 (void)scratch;
239 (void) scratch_length; 242 (void)scratch_length;
240 GNUNET_break (NULL == cls); 243 GNUNET_break(NULL == cls);
241 if (1 != param_length) 244 if (1 != param_length)
242 return -1; 245 return -1;
243 u_nbo = GNUNET_new (uint64_t); 246 u_nbo = GNUNET_new(uint64_t);
244 scratch[0] = u_nbo; 247 scratch[0] = u_nbo;
245 *u_nbo = GNUNET_htonll (*u_hbo); 248 *u_nbo = GNUNET_htonll(*u_hbo);
246 param_values[0] = (void *) u_nbo; 249 param_values[0] = (void *)u_nbo;
247 param_lengths[0] = sizeof (uint64_t); 250 param_lengths[0] = sizeof(uint64_t);
248 param_formats[0] = 1; 251 param_formats[0] = 1;
249 return 1; 252 return 1;
250} 253}
@@ -256,10 +259,11 @@ qconv_uint64 (void *cls,
256 * @param x pointer to the query parameter to pass 259 * @param x pointer to the query parameter to pass
257 */ 260 */
258struct GNUNET_PQ_QueryParam 261struct GNUNET_PQ_QueryParam
259GNUNET_PQ_query_param_uint64 (const uint64_t *x) 262GNUNET_PQ_query_param_uint64(const uint64_t *x)
260{ 263{
261 struct GNUNET_PQ_QueryParam res = 264 struct GNUNET_PQ_QueryParam res =
262 { &qconv_uint64, NULL, x, sizeof (*x), 1 }; 265 { &qconv_uint64, NULL, x, sizeof(*x), 1 };
266
263 return res; 267 return res;
264} 268}
265 269
@@ -279,27 +283,27 @@ GNUNET_PQ_query_param_uint64 (const uint64_t *x)
279 * @return -1 on error, number of offsets used in @a scratch otherwise 283 * @return -1 on error, number of offsets used in @a scratch otherwise
280 */ 284 */
281static int 285static int
282qconv_rsa_public_key (void *cls, 286qconv_rsa_public_key(void *cls,
283 const void *data, 287 const void *data,
284 size_t data_len, 288 size_t data_len,
285 void *param_values[], 289 void *param_values[],
286 int param_lengths[], 290 int param_lengths[],
287 int param_formats[], 291 int param_formats[],
288 unsigned int param_length, 292 unsigned int param_length,
289 void *scratch[], 293 void *scratch[],
290 unsigned int scratch_length) 294 unsigned int scratch_length)
291{ 295{
292 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data; 296 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
293 char *buf; 297 char *buf;
294 size_t buf_size; 298 size_t buf_size;
295 299
296 GNUNET_break (NULL == cls); 300 GNUNET_break(NULL == cls);
297 if (1 != param_length) 301 if (1 != param_length)
298 return -1; 302 return -1;
299 buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, 303 buf_size = GNUNET_CRYPTO_rsa_public_key_encode(rsa,
300 &buf); 304 &buf);
301 scratch[0] = buf; 305 scratch[0] = buf;
302 param_values[0] = (void *) buf; 306 param_values[0] = (void *)buf;
303 param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */ 307 param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */
304 param_formats[0] = 1; 308 param_formats[0] = 1;
305 return 1; 309 return 1;
@@ -314,10 +318,11 @@ qconv_rsa_public_key (void *cls,
314 * @return array entry for the query parameters to use 318 * @return array entry for the query parameters to use
315 */ 319 */
316struct GNUNET_PQ_QueryParam 320struct GNUNET_PQ_QueryParam
317GNUNET_PQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x) 321GNUNET_PQ_query_param_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *x)
318{ 322{
319 struct GNUNET_PQ_QueryParam res = 323 struct GNUNET_PQ_QueryParam res =
320 { &qconv_rsa_public_key, NULL, (x), 0, 1 }; 324 { &qconv_rsa_public_key, NULL, (x), 0, 1 };
325
321 return res; 326 return res;
322} 327}
323 328
@@ -337,27 +342,27 @@ GNUNET_PQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x
337 * @return -1 on error, number of offsets used in @a scratch otherwise 342 * @return -1 on error, number of offsets used in @a scratch otherwise
338 */ 343 */
339static int 344static int
340qconv_rsa_signature (void *cls, 345qconv_rsa_signature(void *cls,
341 const void *data, 346 const void *data,
342 size_t data_len, 347 size_t data_len,
343 void *param_values[], 348 void *param_values[],
344 int param_lengths[], 349 int param_lengths[],
345 int param_formats[], 350 int param_formats[],
346 unsigned int param_length, 351 unsigned int param_length,
347 void *scratch[], 352 void *scratch[],
348 unsigned int scratch_length) 353 unsigned int scratch_length)
349{ 354{
350 const struct GNUNET_CRYPTO_RsaSignature *sig = data; 355 const struct GNUNET_CRYPTO_RsaSignature *sig = data;
351 char *buf; 356 char *buf;
352 size_t buf_size; 357 size_t buf_size;
353 358
354 GNUNET_break (NULL == cls); 359 GNUNET_break(NULL == cls);
355 if (1 != param_length) 360 if (1 != param_length)
356 return -1; 361 return -1;
357 buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig, 362 buf_size = GNUNET_CRYPTO_rsa_signature_encode(sig,
358 &buf); 363 &buf);
359 scratch[0] = buf; 364 scratch[0] = buf;
360 param_values[0] = (void *) buf; 365 param_values[0] = (void *)buf;
361 param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */ 366 param_lengths[0] = buf_size - 1; /* DB doesn't like the trailing \0 */
362 param_formats[0] = 1; 367 param_formats[0] = 1;
363 return 1; 368 return 1;
@@ -372,10 +377,11 @@ qconv_rsa_signature (void *cls,
372 * @return array entry for the query parameters to use 377 * @return array entry for the query parameters to use
373 */ 378 */
374struct GNUNET_PQ_QueryParam 379struct GNUNET_PQ_QueryParam
375GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) 380GNUNET_PQ_query_param_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *x)
376{ 381{
377 struct GNUNET_PQ_QueryParam res = 382 struct GNUNET_PQ_QueryParam res =
378 { &qconv_rsa_signature, NULL, (x), 0, 1 }; 383 { &qconv_rsa_signature, NULL, (x), 0, 1 };
384
379 return res; 385 return res;
380} 386}
381 387
@@ -395,31 +401,31 @@ GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
395 * @return -1 on error, number of offsets used in @a scratch otherwise 401 * @return -1 on error, number of offsets used in @a scratch otherwise
396 */ 402 */
397static int 403static int
398qconv_abs_time (void *cls, 404qconv_abs_time(void *cls,
399 const void *data, 405 const void *data,
400 size_t data_len, 406 size_t data_len,
401 void *param_values[], 407 void *param_values[],
402 int param_lengths[], 408 int param_lengths[],
403 int param_formats[], 409 int param_formats[],
404 unsigned int param_length, 410 unsigned int param_length,
405 void *scratch[], 411 void *scratch[],
406 unsigned int scratch_length) 412 unsigned int scratch_length)
407{ 413{
408 const struct GNUNET_TIME_Absolute *u = data; 414 const struct GNUNET_TIME_Absolute *u = data;
409 struct GNUNET_TIME_Absolute abs; 415 struct GNUNET_TIME_Absolute abs;
410 uint64_t *u_nbo; 416 uint64_t *u_nbo;
411 417
412 GNUNET_break (NULL == cls); 418 GNUNET_break(NULL == cls);
413 if (1 != param_length) 419 if (1 != param_length)
414 return -1; 420 return -1;
415 abs = *u; 421 abs = *u;
416 if (abs.abs_value_us > INT64_MAX) 422 if (abs.abs_value_us > INT64_MAX)
417 abs.abs_value_us = INT64_MAX; 423 abs.abs_value_us = INT64_MAX;
418 u_nbo = GNUNET_new (uint64_t); 424 u_nbo = GNUNET_new(uint64_t);
419 scratch[0] = u_nbo; 425 scratch[0] = u_nbo;
420 *u_nbo = GNUNET_htonll (abs.abs_value_us); 426 *u_nbo = GNUNET_htonll(abs.abs_value_us);
421 param_values[0] = (void *) u_nbo; 427 param_values[0] = (void *)u_nbo;
422 param_lengths[0] = sizeof (uint64_t); 428 param_lengths[0] = sizeof(uint64_t);
423 param_formats[0] = 1; 429 param_formats[0] = 1;
424 return 1; 430 return 1;
425} 431}
@@ -433,10 +439,10 @@ qconv_abs_time (void *cls,
433 * @return array entry for the query parameters to use 439 * @return array entry for the query parameters to use
434 */ 440 */
435struct GNUNET_PQ_QueryParam 441struct GNUNET_PQ_QueryParam
436GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) 442GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
437{ 443{
438 struct GNUNET_PQ_QueryParam res = 444 struct GNUNET_PQ_QueryParam res =
439 { &qconv_abs_time, NULL, x, sizeof (*x), 1 }; 445 { &qconv_abs_time, NULL, x, sizeof(*x), 1 };
440 446
441 return res; 447 return res;
442} 448}
@@ -451,7 +457,7 @@ GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
451struct GNUNET_PQ_QueryParam 457struct GNUNET_PQ_QueryParam
452GNUNET_PQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x) 458GNUNET_PQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x)
453{ 459{
454 return GNUNET_PQ_query_param_auto_from_type (&x->abs_value_us__); 460 return GNUNET_PQ_query_param_auto_from_type(&x->abs_value_us__);
455} 461}
456 462
457 463