aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/gnunet-datastore.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
committerng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
commit6e599264ad13e8fc105493d74d7c11d46f8739ed (patch)
tree169bef1ecbade5a659831fb169f3ae6943af127f /src/datastore/gnunet-datastore.c
parent4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff)
downloadgnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz
gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip
first step to remove plibc
Diffstat (limited to 'src/datastore/gnunet-datastore.c')
-rw-r--r--src/datastore/gnunet-datastore.c120
1 files changed, 54 insertions, 66 deletions
diff --git a/src/datastore/gnunet-datastore.c b/src/datastore/gnunet-datastore.c
index cd089071c..4cf318777 100644
--- a/src/datastore/gnunet-datastore.c
+++ b/src/datastore/gnunet-datastore.c
@@ -66,7 +66,6 @@ struct DataRecord
66 * Key under which the item can be found. 66 * Key under which the item can be found.
67 */ 67 */
68 struct GNUNET_HashCode key; 68 struct GNUNET_HashCode key;
69
70}; 69};
71GNUNET_NETWORK_STRUCT_END 70GNUNET_NETWORK_STRUCT_END
72 71
@@ -185,13 +184,11 @@ get_cb (void *cls,
185 qe = NULL; 184 qe = NULL;
186 if (NULL == key) 185 if (NULL == key)
187 { 186 {
188 FPRINTF (stderr, 187 fprintf (stderr, _ ("Dumped %" PRIu64 " records\n"), record_count);
189 _("Dumped %" PRIu64 " records\n"),
190 record_count);
191 GNUNET_DISK_file_close (file_handle); 188 GNUNET_DISK_file_close (file_handle);
192 file_handle = NULL; 189 file_handle = NULL;
193 if (insert) 190 if (insert)
194 start_insert(); 191 start_insert ();
195 else 192 else
196 { 193 {
197 ret = 0; 194 ret = 0;
@@ -213,8 +210,8 @@ get_cb (void *cls,
213 len = GNUNET_DISK_file_write (file_handle, &dr, sizeof (dr)); 210 len = GNUNET_DISK_file_write (file_handle, &dr, sizeof (dr));
214 if (sizeof (dr) != len) 211 if (sizeof (dr) != len)
215 { 212 {
216 FPRINTF (stderr, 213 fprintf (stderr,
217 _("Short write to file: %zd bytes expecting %zd\n"), 214 _ ("Short write to file: %zd bytes expecting %zd\n"),
218 len, 215 len,
219 sizeof (dr)); 216 sizeof (dr));
220 ret = 1; 217 ret = 1;
@@ -225,8 +222,8 @@ get_cb (void *cls,
225 len = GNUNET_DISK_file_write (file_handle, data, size); 222 len = GNUNET_DISK_file_write (file_handle, data, size);
226 if (size != len) 223 if (size != len)
227 { 224 {
228 FPRINTF (stderr, 225 fprintf (stderr,
229 _("Short write to file: %zd bytes expecting %zd\n"), 226 _ ("Short write to file: %zd bytes expecting %zd\n"),
230 len, 227 len,
231 size); 228 size);
232 ret = 1; 229 ret = 1;
@@ -235,7 +232,7 @@ get_cb (void *cls,
235 } 232 }
236 233
237 record_count++; 234 record_count++;
238 do_get(uid + 1); 235 do_get (uid + 1);
239} 236}
240 237
241 238
@@ -257,8 +254,7 @@ do_get (const uint64_t next_uid)
257 NULL /* proc_cls */); 254 NULL /* proc_cls */);
258 if (NULL == qe) 255 if (NULL == qe)
259 { 256 {
260 FPRINTF (stderr, 257 fprintf (stderr, _ ("Error queueing datastore GET operation\n"));
261 _("Error queueing datastore GET operation\n"));
262 ret = 1; 258 ret = 1;
263 GNUNET_SCHEDULER_shutdown (); 259 GNUNET_SCHEDULER_shutdown ();
264 } 260 }
@@ -277,15 +273,13 @@ start_dump ()
277 { 273 {
278 file_handle = GNUNET_DISK_file_open (file_name, 274 file_handle = GNUNET_DISK_file_open (file_name,
279 GNUNET_DISK_OPEN_WRITE | 275 GNUNET_DISK_OPEN_WRITE |
280 GNUNET_DISK_OPEN_TRUNCATE | 276 GNUNET_DISK_OPEN_TRUNCATE |
281 GNUNET_DISK_OPEN_CREATE, 277 GNUNET_DISK_OPEN_CREATE,
282 GNUNET_DISK_PERM_USER_READ | 278 GNUNET_DISK_PERM_USER_READ |
283 GNUNET_DISK_PERM_USER_WRITE); 279 GNUNET_DISK_PERM_USER_WRITE);
284 if (NULL == file_handle) 280 if (NULL == file_handle)
285 { 281 {
286 FPRINTF (stderr, 282 fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name);
287 _("Unable to open dump file: %s\n"),
288 file_name);
289 ret = 1; 283 ret = 1;
290 GNUNET_SCHEDULER_shutdown (); 284 GNUNET_SCHEDULER_shutdown ();
291 return; 285 return;
@@ -296,7 +290,7 @@ start_dump ()
296 file_handle = GNUNET_DISK_get_handle_from_int_fd (STDOUT_FILENO); 290 file_handle = GNUNET_DISK_get_handle_from_int_fd (STDOUT_FILENO);
297 } 291 }
298 GNUNET_DISK_file_write (file_handle, MAGIC_BYTES, MAGIC_LEN); 292 GNUNET_DISK_file_write (file_handle, MAGIC_BYTES, MAGIC_LEN);
299 do_get(0); 293 do_get (0);
300} 294}
301 295
302 296
@@ -322,9 +316,7 @@ put_cb (void *cls,
322 qe = NULL; 316 qe = NULL;
323 if (GNUNET_SYSERR == success) 317 if (GNUNET_SYSERR == success)
324 { 318 {
325 FPRINTF (stderr, 319 fprintf (stderr, _ ("Failed to store item: %s, aborting\n"), msg);
326 _("Failed to store item: %s, aborting\n"),
327 msg);
328 ret = 1; 320 ret = 1;
329 GNUNET_SCHEDULER_shutdown (); 321 GNUNET_SCHEDULER_shutdown ();
330 return; 322 return;
@@ -336,17 +328,15 @@ put_cb (void *cls,
336 len = GNUNET_DISK_file_read (file_handle, &dr, sizeof (dr)); 328 len = GNUNET_DISK_file_read (file_handle, &dr, sizeof (dr));
337 if (0 == len) 329 if (0 == len)
338 { 330 {
339 FPRINTF (stderr, 331 fprintf (stderr, _ ("Inserted %" PRIu64 " records\n"), record_count);
340 _("Inserted %" PRIu64 " records\n"),
341 record_count);
342 ret = 0; 332 ret = 0;
343 GNUNET_SCHEDULER_shutdown (); 333 GNUNET_SCHEDULER_shutdown ();
344 return; 334 return;
345 } 335 }
346 else if (sizeof (dr) != len) 336 else if (sizeof (dr) != len)
347 { 337 {
348 FPRINTF (stderr, 338 fprintf (stderr,
349 _("Short read from file: %zd bytes expecting %zd\n"), 339 _ ("Short read from file: %zd bytes expecting %zd\n"),
350 len, 340 len,
351 sizeof (dr)); 341 sizeof (dr));
352 ret = 1; 342 ret = 1;
@@ -359,8 +349,8 @@ put_cb (void *cls,
359 len = GNUNET_DISK_file_read (file_handle, data, size); 349 len = GNUNET_DISK_file_read (file_handle, data, size);
360 if (size != len) 350 if (size != len)
361 { 351 {
362 FPRINTF (stderr, 352 fprintf (stderr,
363 _("Short read from file: %zd bytes expecting %zd\n"), 353 _ ("Short read from file: %zd bytes expecting %zd\n"),
364 len, 354 len,
365 size); 355 size);
366 ret = 1; 356 ret = 1;
@@ -385,8 +375,7 @@ put_cb (void *cls,
385 NULL); 375 NULL);
386 if (NULL == qe) 376 if (NULL == qe)
387 { 377 {
388 FPRINTF (stderr, 378 fprintf (stderr, _ ("Error queueing datastore PUT operation\n"));
389 _("Error queueing datastore PUT operation\n"));
390 ret = 1; 379 ret = 1;
391 GNUNET_SCHEDULER_shutdown (); 380 GNUNET_SCHEDULER_shutdown ();
392 } 381 }
@@ -408,9 +397,7 @@ start_insert ()
408 GNUNET_DISK_PERM_NONE); 397 GNUNET_DISK_PERM_NONE);
409 if (NULL == file_handle) 398 if (NULL == file_handle)
410 { 399 {
411 FPRINTF (stderr, 400 fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name);
412 _("Unable to open dump file: %s\n"),
413 file_name);
414 ret = 1; 401 ret = 1;
415 GNUNET_SCHEDULER_shutdown (); 402 GNUNET_SCHEDULER_shutdown ();
416 return; 403 return;
@@ -425,11 +412,9 @@ start_insert ()
425 ssize_t len; 412 ssize_t len;
426 413
427 len = GNUNET_DISK_file_read (file_handle, buf, MAGIC_LEN); 414 len = GNUNET_DISK_file_read (file_handle, buf, MAGIC_LEN);
428 if (len != MAGIC_LEN || 415 if (len != MAGIC_LEN || 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN))
429 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN))
430 { 416 {
431 FPRINTF (stderr, 417 fprintf (stderr, _ ("Input file is not of a supported format\n"));
432 _("Input file is not of a supported format\n"));
433 return; 418 return;
434 } 419 }
435 put_cb (NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL); 420 put_cb (NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
@@ -454,20 +439,19 @@ run (void *cls,
454 datastore = GNUNET_DATASTORE_connect (cfg); 439 datastore = GNUNET_DATASTORE_connect (cfg);
455 if (NULL == datastore) 440 if (NULL == datastore)
456 { 441 {
457 FPRINTF (stderr, 442 fprintf (stderr, _ ("Failed connecting to the datastore.\n"));
458 _("Failed connecting to the datastore.\n"));
459 ret = 1; 443 ret = 1;
460 GNUNET_SCHEDULER_shutdown (); 444 GNUNET_SCHEDULER_shutdown ();
461 return; 445 return;
462 } 446 }
463 if (dump) 447 if (dump)
464 start_dump(); 448 start_dump ();
465 else if (insert) 449 else if (insert)
466 start_insert(); 450 start_insert ();
467 else 451 else
468 { 452 {
469 FPRINTF (stderr, 453 fprintf (stderr,
470 _("Please choose at least one operation: %s, %s\n"), 454 _ ("Please choose at least one operation: %s, %s\n"),
471 "dump", 455 "dump",
472 "insert"); 456 "insert");
473 ret = 1; 457 ret = 1;
@@ -484,34 +468,38 @@ run (void *cls,
484 * @return 0 ok, 1 on error 468 * @return 0 ok, 1 on error
485 */ 469 */
486int 470int
487main (int argc, 471main (int argc, char *const *argv)
488 char *const *argv)
489{ 472{
490 struct GNUNET_GETOPT_CommandLineOption options[] = { 473 struct GNUNET_GETOPT_CommandLineOption options[] =
491 GNUNET_GETOPT_option_flag ('d', 474 {GNUNET_GETOPT_option_flag ('d',
492 "dump", 475 "dump",
493 gettext_noop ("Dump all records from the datastore"), 476 gettext_noop (
494 &dump), 477 "Dump all records from the datastore"),
495 GNUNET_GETOPT_option_flag ('i', 478 &dump),
496 "insert", 479 GNUNET_GETOPT_option_flag ('i',
497 gettext_noop ("Insert records into the datastore"), 480 "insert",
498 &insert), 481 gettext_noop (
499 GNUNET_GETOPT_option_filename ('f', 482 "Insert records into the datastore"),
500 "file", 483 &insert),
501 "FILENAME", 484 GNUNET_GETOPT_option_filename ('f',
502 gettext_noop ("File to dump or insert"), 485 "file",
503 &file_name), 486 "FILENAME",
504 GNUNET_GETOPT_OPTION_END 487 gettext_noop ("File to dump or insert"),
505 }; 488 &file_name),
489 GNUNET_GETOPT_OPTION_END};
506 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 490 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
507 return 2; 491 return 2;
508 492
509 if (GNUNET_OK != 493 if (GNUNET_OK !=
510 GNUNET_PROGRAM_run (argc, argv, "gnunet-datastore", 494 GNUNET_PROGRAM_run (argc,
511 gettext_noop ("Manipulate GNUnet datastore"), 495 argv,
512 options, &run, NULL)) 496 "gnunet-datastore",
497 gettext_noop ("Manipulate GNUnet datastore"),
498 options,
499 &run,
500 NULL))
513 ret = 1; 501 ret = 1;
514 GNUNET_free ((void*) argv); 502 GNUNET_free ((void *) argv);
515 return ret; 503 return ret;
516} 504}
517 505