diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/util/common_logging.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/util/common_logging.c')
-rw-r--r-- | src/util/common_logging.c | 1032 |
1 files changed, 517 insertions, 515 deletions
diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 7a2d5a0b5..3ff9bf18e 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c | |||
@@ -77,7 +77,8 @@ | |||
77 | /** | 77 | /** |
78 | * Linked list of active loggers. | 78 | * Linked list of active loggers. |
79 | */ | 79 | */ |
80 | struct CustomLogger { | 80 | struct CustomLogger |
81 | { | ||
81 | /** | 82 | /** |
82 | * This is a linked list. | 83 | * This is a linked list. |
83 | */ | 84 | */ |
@@ -166,7 +167,8 @@ static FILE *GNUNET_stderr; | |||
166 | /** | 167 | /** |
167 | * Represents a single logging definition | 168 | * Represents a single logging definition |
168 | */ | 169 | */ |
169 | struct LogDef { | 170 | struct LogDef |
171 | { | ||
170 | /** | 172 | /** |
171 | * Component name regex | 173 | * Component name regex |
172 | */ | 174 | */ |
@@ -209,7 +211,7 @@ struct LogDef { | |||
209 | }; | 211 | }; |
210 | 212 | ||
211 | 213 | ||
212 | #if !defined(GNUNET_CULL_LOGGING) | 214 | #if ! defined(GNUNET_CULL_LOGGING) |
213 | /** | 215 | /** |
214 | * Dynamic array of logging definitions | 216 | * Dynamic array of logging definitions |
215 | */ | 217 | */ |
@@ -250,21 +252,21 @@ static int gnunet_force_log_present; | |||
250 | * @return GNUNET_GE_INVALID if log does not parse | 252 | * @return GNUNET_GE_INVALID if log does not parse |
251 | */ | 253 | */ |
252 | static enum GNUNET_ErrorType | 254 | static enum GNUNET_ErrorType |
253 | get_type(const char *log) | 255 | get_type (const char *log) |
254 | { | 256 | { |
255 | if (NULL == log) | 257 | if (NULL == log) |
256 | return GNUNET_ERROR_TYPE_UNSPECIFIED; | 258 | return GNUNET_ERROR_TYPE_UNSPECIFIED; |
257 | if (0 == strcasecmp(log, _("DEBUG"))) | 259 | if (0 == strcasecmp (log, _ ("DEBUG"))) |
258 | return GNUNET_ERROR_TYPE_DEBUG; | 260 | return GNUNET_ERROR_TYPE_DEBUG; |
259 | if (0 == strcasecmp(log, _("INFO"))) | 261 | if (0 == strcasecmp (log, _ ("INFO"))) |
260 | return GNUNET_ERROR_TYPE_INFO; | 262 | return GNUNET_ERROR_TYPE_INFO; |
261 | if (0 == strcasecmp(log, _("MESSAGE"))) | 263 | if (0 == strcasecmp (log, _ ("MESSAGE"))) |
262 | return GNUNET_ERROR_TYPE_MESSAGE; | 264 | return GNUNET_ERROR_TYPE_MESSAGE; |
263 | if (0 == strcasecmp(log, _("WARNING"))) | 265 | if (0 == strcasecmp (log, _ ("WARNING"))) |
264 | return GNUNET_ERROR_TYPE_WARNING; | 266 | return GNUNET_ERROR_TYPE_WARNING; |
265 | if (0 == strcasecmp(log, _("ERROR"))) | 267 | if (0 == strcasecmp (log, _ ("ERROR"))) |
266 | return GNUNET_ERROR_TYPE_ERROR; | 268 | return GNUNET_ERROR_TYPE_ERROR; |
267 | if (0 == strcasecmp(log, _("NONE"))) | 269 | if (0 == strcasecmp (log, _ ("NONE"))) |
268 | return GNUNET_ERROR_TYPE_NONE; | 270 | return GNUNET_ERROR_TYPE_NONE; |
269 | return GNUNET_ERROR_TYPE_INVALID; | 271 | return GNUNET_ERROR_TYPE_INVALID; |
270 | } | 272 | } |
@@ -274,32 +276,32 @@ get_type(const char *log) | |||
274 | * Abort the process, generate a core dump if possible. | 276 | * Abort the process, generate a core dump if possible. |
275 | */ | 277 | */ |
276 | void | 278 | void |
277 | GNUNET_abort_() | 279 | GNUNET_abort_ () |
278 | { | 280 | { |
279 | abort(); | 281 | abort (); |
280 | } | 282 | } |
281 | 283 | ||
282 | 284 | ||
283 | #if !defined(GNUNET_CULL_LOGGING) | 285 | #if ! defined(GNUNET_CULL_LOGGING) |
284 | /** | 286 | /** |
285 | * Utility function - reallocates logdefs array to be twice as large. | 287 | * Utility function - reallocates logdefs array to be twice as large. |
286 | */ | 288 | */ |
287 | static void | 289 | static void |
288 | resize_logdefs() | 290 | resize_logdefs () |
289 | { | 291 | { |
290 | logdefs_size = (logdefs_size + 1) * 2; | 292 | logdefs_size = (logdefs_size + 1) * 2; |
291 | logdefs = GNUNET_realloc(logdefs, logdefs_size * sizeof(struct LogDef)); | 293 | logdefs = GNUNET_realloc (logdefs, logdefs_size * sizeof(struct LogDef)); |
292 | } | 294 | } |
293 | 295 | ||
294 | 296 | ||
295 | #if !TALER_WALLET_ONLY | 297 | #if ! TALER_WALLET_ONLY |
296 | /** | 298 | /** |
297 | * Rotate logs, deleting the oldest log. | 299 | * Rotate logs, deleting the oldest log. |
298 | * | 300 | * |
299 | * @param new_name new name to add to the rotation | 301 | * @param new_name new name to add to the rotation |
300 | */ | 302 | */ |
301 | static void | 303 | static void |
302 | log_rotate(const char *new_name) | 304 | log_rotate (const char *new_name) |
303 | { | 305 | { |
304 | static char *rotation[ROTATION_KEEP]; | 306 | static char *rotation[ROTATION_KEEP]; |
305 | static unsigned int rotation_off; | 307 | static unsigned int rotation_off; |
@@ -309,13 +311,13 @@ log_rotate(const char *new_name) | |||
309 | return; /* not a real log file name */ | 311 | return; /* not a real log file name */ |
310 | discard = rotation[rotation_off % ROTATION_KEEP]; | 312 | discard = rotation[rotation_off % ROTATION_KEEP]; |
311 | if (NULL != discard) | 313 | if (NULL != discard) |
312 | { | 314 | { |
313 | /* Note: can't log errors during logging (recursion!), so this | 315 | /* Note: can't log errors during logging (recursion!), so this |
314 | operation MUST silently fail... */ | 316 | operation MUST silently fail... */ |
315 | (void)unlink(discard); | 317 | (void) unlink (discard); |
316 | GNUNET_free(discard); | 318 | GNUNET_free (discard); |
317 | } | 319 | } |
318 | rotation[rotation_off % ROTATION_KEEP] = GNUNET_strdup(new_name); | 320 | rotation[rotation_off % ROTATION_KEEP] = GNUNET_strdup (new_name); |
319 | rotation_off++; | 321 | rotation_off++; |
320 | } | 322 | } |
321 | 323 | ||
@@ -327,7 +329,7 @@ log_rotate(const char *new_name) | |||
327 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 329 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
328 | */ | 330 | */ |
329 | static int | 331 | static int |
330 | setup_log_file(const struct tm *tm) | 332 | setup_log_file (const struct tm *tm) |
331 | { | 333 | { |
332 | static char last_fn[PATH_MAX + 1]; | 334 | static char last_fn[PATH_MAX + 1]; |
333 | char fn[PATH_MAX + 1]; | 335 | char fn[PATH_MAX + 1]; |
@@ -338,64 +340,64 @@ setup_log_file(const struct tm *tm) | |||
338 | 340 | ||
339 | if (NULL == log_file_name) | 341 | if (NULL == log_file_name) |
340 | return GNUNET_SYSERR; | 342 | return GNUNET_SYSERR; |
341 | if (0 == strftime(fn, sizeof(fn), log_file_name, tm)) | 343 | if (0 == strftime (fn, sizeof(fn), log_file_name, tm)) |
342 | return GNUNET_SYSERR; | 344 | return GNUNET_SYSERR; |
343 | leftsquare = strrchr(fn, '['); | 345 | leftsquare = strrchr (fn, '['); |
344 | if ((NULL != leftsquare) && (']' == leftsquare[1])) | 346 | if ((NULL != leftsquare) && (']' == leftsquare[1])) |
345 | { | 347 | { |
346 | char *logfile_copy = GNUNET_strdup(fn); | 348 | char *logfile_copy = GNUNET_strdup (fn); |
347 | 349 | ||
348 | logfile_copy[leftsquare - fn] = '\0'; | 350 | logfile_copy[leftsquare - fn] = '\0'; |
349 | logfile_copy[leftsquare - fn + 1] = '\0'; | 351 | logfile_copy[leftsquare - fn + 1] = '\0'; |
350 | snprintf(fn, | 352 | snprintf (fn, |
351 | PATH_MAX, | 353 | PATH_MAX, |
352 | "%s%d%s", | 354 | "%s%d%s", |
353 | logfile_copy, | 355 | logfile_copy, |
354 | getpid(), | 356 | getpid (), |
355 | &logfile_copy[leftsquare - fn + 2]); | 357 | &logfile_copy[leftsquare - fn + 2]); |
356 | GNUNET_free(logfile_copy); | 358 | GNUNET_free (logfile_copy); |
357 | } | 359 | } |
358 | if (0 == strcmp(fn, last_fn)) | 360 | if (0 == strcmp (fn, last_fn)) |
359 | return GNUNET_OK; /* no change */ | 361 | return GNUNET_OK; /* no change */ |
360 | log_rotate(last_fn); | 362 | log_rotate (last_fn); |
361 | strcpy(last_fn, fn); | 363 | strcpy (last_fn, fn); |
362 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file(fn)) | 364 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (fn)) |
363 | { | 365 | { |
364 | fprintf(stderr, | 366 | fprintf (stderr, |
365 | "Failed to create directory for `%s': %s\n", | 367 | "Failed to create directory for `%s': %s\n", |
366 | fn, | 368 | fn, |
367 | strerror(errno)); | 369 | strerror (errno)); |
368 | return GNUNET_SYSERR; | 370 | return GNUNET_SYSERR; |
369 | } | 371 | } |
370 | altlog_fd = open(fn, | 372 | altlog_fd = open (fn, |
371 | O_APPEND | O_WRONLY | O_CREAT, | 373 | O_APPEND | O_WRONLY | O_CREAT, |
372 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); | 374 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
373 | 375 | ||
374 | if (-1 != altlog_fd) | 376 | if (-1 != altlog_fd) |
377 | { | ||
378 | if (NULL != GNUNET_stderr) | ||
379 | fclose (GNUNET_stderr); | ||
380 | dup_return = dup2 (altlog_fd, 2); | ||
381 | (void) close (altlog_fd); | ||
382 | if (-1 != dup_return) | ||
375 | { | 383 | { |
376 | if (NULL != GNUNET_stderr) | 384 | altlog = fdopen (2, "ab"); |
377 | fclose(GNUNET_stderr); | 385 | if (NULL == altlog) |
378 | dup_return = dup2(altlog_fd, 2); | 386 | { |
379 | (void)close(altlog_fd); | 387 | (void) close (2); |
380 | if (-1 != dup_return) | 388 | altlog_fd = -1; |
381 | { | 389 | } |
382 | altlog = fdopen(2, "ab"); | ||
383 | if (NULL == altlog) | ||
384 | { | ||
385 | (void)close(2); | ||
386 | altlog_fd = -1; | ||
387 | } | ||
388 | } | ||
389 | else | ||
390 | { | ||
391 | altlog_fd = -1; | ||
392 | } | ||
393 | } | 390 | } |
394 | if (-1 == altlog_fd) | 391 | else |
395 | { | 392 | { |
396 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", fn); | 393 | altlog_fd = -1; |
397 | return GNUNET_SYSERR; | ||
398 | } | 394 | } |
395 | } | ||
396 | if (-1 == altlog_fd) | ||
397 | { | ||
398 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); | ||
399 | return GNUNET_SYSERR; | ||
400 | } | ||
399 | GNUNET_stderr = altlog; | 401 | GNUNET_stderr = altlog; |
400 | return GNUNET_OK; | 402 | return GNUNET_OK; |
401 | } | 403 | } |
@@ -415,44 +417,44 @@ setup_log_file(const struct tm *tm) | |||
415 | * @return 0 on success, regex-specific error otherwise | 417 | * @return 0 on success, regex-specific error otherwise |
416 | */ | 418 | */ |
417 | static int | 419 | static int |
418 | add_definition(const char *component, | 420 | add_definition (const char *component, |
419 | const char *file, | 421 | const char *file, |
420 | const char *function, | 422 | const char *function, |
421 | int from_line, | 423 | int from_line, |
422 | int to_line, | 424 | int to_line, |
423 | int level, | 425 | int level, |
424 | int force) | 426 | int force) |
425 | { | 427 | { |
426 | struct LogDef n; | 428 | struct LogDef n; |
427 | int r; | 429 | int r; |
428 | 430 | ||
429 | if (logdefs_size == logdefs_len) | 431 | if (logdefs_size == logdefs_len) |
430 | resize_logdefs(); | 432 | resize_logdefs (); |
431 | memset(&n, 0, sizeof(n)); | 433 | memset (&n, 0, sizeof(n)); |
432 | if (0 == strlen(component)) | 434 | if (0 == strlen (component)) |
433 | component = (char *)".*"; | 435 | component = (char *) ".*"; |
434 | r = regcomp(&n.component_regex, (const char *)component, REG_NOSUB); | 436 | r = regcomp (&n.component_regex, (const char *) component, REG_NOSUB); |
435 | if (0 != r) | 437 | if (0 != r) |
436 | { | 438 | { |
437 | return r; | 439 | return r; |
438 | } | 440 | } |
439 | if (0 == strlen(file)) | 441 | if (0 == strlen (file)) |
440 | file = (char *)".*"; | 442 | file = (char *) ".*"; |
441 | r = regcomp(&n.file_regex, (const char *)file, REG_NOSUB); | 443 | r = regcomp (&n.file_regex, (const char *) file, REG_NOSUB); |
442 | if (0 != r) | 444 | if (0 != r) |
443 | { | 445 | { |
444 | regfree(&n.component_regex); | 446 | regfree (&n.component_regex); |
445 | return r; | 447 | return r; |
446 | } | 448 | } |
447 | if ((NULL == function) || (0 == strlen(function))) | 449 | if ((NULL == function) || (0 == strlen (function))) |
448 | function = (char *)".*"; | 450 | function = (char *) ".*"; |
449 | r = regcomp(&n.function_regex, (const char *)function, REG_NOSUB); | 451 | r = regcomp (&n.function_regex, (const char *) function, REG_NOSUB); |
450 | if (0 != r) | 452 | if (0 != r) |
451 | { | 453 | { |
452 | regfree(&n.component_regex); | 454 | regfree (&n.component_regex); |
453 | regfree(&n.file_regex); | 455 | regfree (&n.file_regex); |
454 | return r; | 456 | return r; |
455 | } | 457 | } |
456 | n.from_line = from_line; | 458 | n.from_line = from_line; |
457 | n.to_line = to_line; | 459 | n.to_line = to_line; |
458 | n.level = level; | 460 | n.level = level; |
@@ -476,11 +478,11 @@ add_definition(const char *component, | |||
476 | * @return 0 to disallow the call, 1 to allow it | 478 | * @return 0 to disallow the call, 1 to allow it |
477 | */ | 479 | */ |
478 | int | 480 | int |
479 | GNUNET_get_log_call_status(int caller_level, | 481 | GNUNET_get_log_call_status (int caller_level, |
480 | const char *comp, | 482 | const char *comp, |
481 | const char *file, | 483 | const char *file, |
482 | const char *function, | 484 | const char *function, |
483 | int line) | 485 | int line) |
484 | { | 486 | { |
485 | struct LogDef *ld; | 487 | struct LogDef *ld; |
486 | int i; | 488 | int i; |
@@ -499,18 +501,18 @@ GNUNET_get_log_call_status(int caller_level, | |||
499 | /* Only look for forced definitions? */ | 501 | /* Only look for forced definitions? */ |
500 | force_only = min_level >= 0; | 502 | force_only = min_level >= 0; |
501 | for (i = 0; i < logdefs_len; i++) | 503 | for (i = 0; i < logdefs_len; i++) |
504 | { | ||
505 | ld = &logdefs[i]; | ||
506 | if (((! force_only) || ld->force) && | ||
507 | ((line >= ld->from_line) &&(line <= ld->to_line) ) && | ||
508 | (0 == regexec (&ld->component_regex, comp, 0, NULL, 0)) && | ||
509 | (0 == regexec (&ld->file_regex, file, 0, NULL, 0)) && | ||
510 | (0 == regexec (&ld->function_regex, function, 0, NULL, 0))) | ||
502 | { | 511 | { |
503 | ld = &logdefs[i]; | 512 | /* We're finished */ |
504 | if (((!force_only) || ld->force) && | 513 | return caller_level <= ld->level; |
505 | (line >= ld->from_line && line <= ld->to_line) && | ||
506 | (0 == regexec(&ld->component_regex, comp, 0, NULL, 0)) && | ||
507 | (0 == regexec(&ld->file_regex, file, 0, NULL, 0)) && | ||
508 | (0 == regexec(&ld->function_regex, function, 0, NULL, 0))) | ||
509 | { | ||
510 | /* We're finished */ | ||
511 | return caller_level <= ld->level; | ||
512 | } | ||
513 | } | 514 | } |
515 | } | ||
514 | /* No matches - use global level, if defined */ | 516 | /* No matches - use global level, if defined */ |
515 | if (min_level >= 0) | 517 | if (min_level >= 0) |
516 | return caller_level <= min_level; | 518 | return caller_level <= min_level; |
@@ -546,7 +548,7 @@ GNUNET_get_log_call_status(int caller_level, | |||
546 | * @return number of added definitions | 548 | * @return number of added definitions |
547 | */ | 549 | */ |
548 | static int | 550 | static int |
549 | parse_definitions(const char *constname, int force) | 551 | parse_definitions (const char *constname, int force) |
550 | { | 552 | { |
551 | char *def; | 553 | char *def; |
552 | const char *tmp; | 554 | const char *tmp; |
@@ -562,116 +564,116 @@ parse_definitions(const char *constname, int force) | |||
562 | int counter = 0; | 564 | int counter = 0; |
563 | int keep_looking = 1; | 565 | int keep_looking = 1; |
564 | 566 | ||
565 | tmp = getenv(constname); | 567 | tmp = getenv (constname); |
566 | if (NULL == tmp) | 568 | if (NULL == tmp) |
567 | return 0; | 569 | return 0; |
568 | def = GNUNET_strdup(tmp); | 570 | def = GNUNET_strdup (tmp); |
569 | from_line = 0; | 571 | from_line = 0; |
570 | to_line = INT_MAX; | 572 | to_line = INT_MAX; |
571 | for (p = def, state = 0, start = def; keep_looking; p++) | 573 | for (p = def, state = 0, start = def; keep_looking; p++) |
574 | { | ||
575 | switch (p[0]) | ||
572 | { | 576 | { |
573 | switch (p[0]) | 577 | case ';': /* found a field separator */ |
574 | { | 578 | p[0] = '\0'; |
575 | case ';': /* found a field separator */ | 579 | switch (state) |
576 | p[0] = '\0'; | 580 | { |
577 | switch (state) | 581 | case 0: /* within a component name */ |
578 | { | 582 | comp = start; |
579 | case 0: /* within a component name */ | 583 | break; |
580 | comp = start; | 584 | |
581 | break; | 585 | case 1: /* within a file name */ |
582 | 586 | file = start; | |
583 | case 1: /* within a file name */ | 587 | break; |
584 | file = start; | ||
585 | break; | ||
586 | |||
587 | case 2: /* within a function name */ | ||
588 | /* after a file name there must be a function name */ | ||
589 | function = start; | ||
590 | break; | ||
591 | |||
592 | case 3: /* within a from-to line range */ | ||
593 | if (strlen(start) > 0) | ||
594 | { | ||
595 | errno = 0; | ||
596 | from_line = strtol(start, &t, 10); | ||
597 | if ((0 != errno) || (from_line < 0)) | ||
598 | { | ||
599 | GNUNET_free(def); | ||
600 | return counter; | ||
601 | } | ||
602 | if ((t < p) && ('-' == t[0])) | ||
603 | { | ||
604 | errno = 0; | ||
605 | start = t + 1; | ||
606 | to_line = strtol(start, &t, 10); | ||
607 | if ((0 != errno) || (to_line < 0) || (t != p)) | ||
608 | { | ||
609 | GNUNET_free(def); | ||
610 | return counter; | ||
611 | } | ||
612 | } | ||
613 | else /* one number means "match this line only" */ | ||
614 | to_line = from_line; | ||
615 | } | ||
616 | else /* default to 0-max */ | ||
617 | { | ||
618 | from_line = 0; | ||
619 | to_line = INT_MAX; | ||
620 | } | ||
621 | break; | ||
622 | |||
623 | default: | ||
624 | fprintf( | ||
625 | stderr, | ||
626 | _("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"), | ||
627 | p); | ||
628 | break; | ||
629 | } | ||
630 | start = p + 1; | ||
631 | state++; | ||
632 | break; | ||
633 | 588 | ||
634 | case '\0': /* found EOL */ | 589 | case 2: /* within a function name */ |
635 | keep_looking = 0; | 590 | /* after a file name there must be a function name */ |
591 | function = start; | ||
592 | break; | ||
636 | 593 | ||
637 | /* fall through to '/' */ | 594 | case 3: /* within a from-to line range */ |
638 | case '/': /* found a definition separator */ | 595 | if (strlen (start) > 0) |
639 | switch (state) | 596 | { |
597 | errno = 0; | ||
598 | from_line = strtol (start, &t, 10); | ||
599 | if ((0 != errno) || (from_line < 0)) | ||
600 | { | ||
601 | GNUNET_free (def); | ||
602 | return counter; | ||
603 | } | ||
604 | if ((t < p) && ('-' == t[0])) | ||
605 | { | ||
606 | errno = 0; | ||
607 | start = t + 1; | ||
608 | to_line = strtol (start, &t, 10); | ||
609 | if ((0 != errno) || (to_line < 0) || (t != p)) | ||
640 | { | 610 | { |
641 | case 4: /* within a log level */ | 611 | GNUNET_free (def); |
642 | p[0] = '\0'; | 612 | return counter; |
643 | state = 0; | ||
644 | level = get_type((const char *)start); | ||
645 | if ((GNUNET_ERROR_TYPE_INVALID == level) || | ||
646 | (GNUNET_ERROR_TYPE_UNSPECIFIED == level) || | ||
647 | (0 != add_definition(comp, | ||
648 | file, | ||
649 | function, | ||
650 | from_line, | ||
651 | to_line, | ||
652 | level, | ||
653 | force))) | ||
654 | { | ||
655 | GNUNET_free(def); | ||
656 | return counter; | ||
657 | } | ||
658 | counter++; | ||
659 | start = p + 1; | ||
660 | break; | ||
661 | |||
662 | default: | ||
663 | fprintf( | ||
664 | stderr, | ||
665 | _("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"), | ||
666 | p); | ||
667 | break; | ||
668 | } | 613 | } |
614 | } | ||
615 | else /* one number means "match this line only" */ | ||
616 | to_line = from_line; | ||
617 | } | ||
618 | else /* default to 0-max */ | ||
619 | { | ||
620 | from_line = 0; | ||
621 | to_line = INT_MAX; | ||
622 | } | ||
623 | break; | ||
624 | |||
625 | default: | ||
626 | fprintf ( | ||
627 | stderr, | ||
628 | _ ("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"), | ||
629 | p); | ||
630 | break; | ||
631 | } | ||
632 | start = p + 1; | ||
633 | state++; | ||
634 | break; | ||
669 | 635 | ||
670 | default: | 636 | case '\0': /* found EOL */ |
671 | break; | 637 | keep_looking = 0; |
638 | |||
639 | /* fall through to '/' */ | ||
640 | case '/': /* found a definition separator */ | ||
641 | switch (state) | ||
642 | { | ||
643 | case 4: /* within a log level */ | ||
644 | p[0] = '\0'; | ||
645 | state = 0; | ||
646 | level = get_type ((const char *) start); | ||
647 | if ((GNUNET_ERROR_TYPE_INVALID == level) || | ||
648 | (GNUNET_ERROR_TYPE_UNSPECIFIED == level) || | ||
649 | (0 != add_definition (comp, | ||
650 | file, | ||
651 | function, | ||
652 | from_line, | ||
653 | to_line, | ||
654 | level, | ||
655 | force))) | ||
656 | { | ||
657 | GNUNET_free (def); | ||
658 | return counter; | ||
672 | } | 659 | } |
660 | counter++; | ||
661 | start = p + 1; | ||
662 | break; | ||
663 | |||
664 | default: | ||
665 | fprintf ( | ||
666 | stderr, | ||
667 | _ ("ERROR: Unable to parse log definition: Syntax error at `%s'.\n"), | ||
668 | p); | ||
669 | break; | ||
670 | } | ||
671 | |||
672 | default: | ||
673 | break; | ||
673 | } | 674 | } |
674 | GNUNET_free(def); | 675 | } |
676 | GNUNET_free (def); | ||
675 | return counter; | 677 | return counter; |
676 | } | 678 | } |
677 | 679 | ||
@@ -680,15 +682,15 @@ parse_definitions(const char *constname, int force) | |||
680 | * Utility function - parses GNUNET_LOG and GNUNET_FORCE_LOG. | 682 | * Utility function - parses GNUNET_LOG and GNUNET_FORCE_LOG. |
681 | */ | 683 | */ |
682 | static void | 684 | static void |
683 | parse_all_definitions() | 685 | parse_all_definitions () |
684 | { | 686 | { |
685 | if (GNUNET_NO == gnunet_force_log_parsed) | 687 | if (GNUNET_NO == gnunet_force_log_parsed) |
686 | gnunet_force_log_present = | 688 | gnunet_force_log_present = |
687 | parse_definitions("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO; | 689 | parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO; |
688 | gnunet_force_log_parsed = GNUNET_YES; | 690 | gnunet_force_log_parsed = GNUNET_YES; |
689 | 691 | ||
690 | if (GNUNET_NO == gnunet_log_parsed) | 692 | if (GNUNET_NO == gnunet_log_parsed) |
691 | parse_definitions("GNUNET_LOG", 0); | 693 | parse_definitions ("GNUNET_LOG", 0); |
692 | gnunet_log_parsed = GNUNET_YES; | 694 | gnunet_log_parsed = GNUNET_YES; |
693 | } | 695 | } |
694 | #endif | 696 | #endif |
@@ -703,40 +705,40 @@ parse_all_definitions() | |||
703 | * @return #GNUNET_OK on success | 705 | * @return #GNUNET_OK on success |
704 | */ | 706 | */ |
705 | int | 707 | int |
706 | GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile) | 708 | GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) |
707 | { | 709 | { |
708 | const char *env_logfile; | 710 | const char *env_logfile; |
709 | 711 | ||
710 | min_level = get_type(loglevel); | 712 | min_level = get_type (loglevel); |
711 | #if !defined(GNUNET_CULL_LOGGING) | 713 | #if ! defined(GNUNET_CULL_LOGGING) |
712 | parse_all_definitions(); | 714 | parse_all_definitions (); |
713 | #endif | 715 | #endif |
714 | GNUNET_free_non_null(component); | 716 | GNUNET_free_non_null (component); |
715 | GNUNET_asprintf(&component, "%s-%d", comp, getpid()); | 717 | GNUNET_asprintf (&component, "%s-%d", comp, getpid ()); |
716 | GNUNET_free_non_null(component_nopid); | 718 | GNUNET_free_non_null (component_nopid); |
717 | component_nopid = GNUNET_strdup(comp); | 719 | component_nopid = GNUNET_strdup (comp); |
718 | 720 | ||
719 | env_logfile = getenv("GNUNET_FORCE_LOGFILE"); | 721 | env_logfile = getenv ("GNUNET_FORCE_LOGFILE"); |
720 | if ((NULL != env_logfile) && (strlen(env_logfile) > 0)) | 722 | if ((NULL != env_logfile) && (strlen (env_logfile) > 0)) |
721 | logfile = env_logfile; | 723 | logfile = env_logfile; |
722 | if (NULL == logfile) | 724 | if (NULL == logfile) |
723 | return GNUNET_OK; | 725 | return GNUNET_OK; |
724 | GNUNET_free_non_null(log_file_name); | 726 | GNUNET_free_non_null (log_file_name); |
725 | log_file_name = GNUNET_STRINGS_filename_expand(logfile); | 727 | log_file_name = GNUNET_STRINGS_filename_expand (logfile); |
726 | if (NULL == log_file_name) | 728 | if (NULL == log_file_name) |
727 | return GNUNET_SYSERR; | 729 | return GNUNET_SYSERR; |
728 | #if TALER_WALLET_ONLY || defined(GNUNET_CULL_LOGGING) | 730 | #if TALER_WALLET_ONLY || defined(GNUNET_CULL_LOGGING) |
729 | /* log file option not allowed for wallet logic */ | 731 | /* log file option not allowed for wallet logic */ |
730 | GNUNET_assert(NULL == logfile); | 732 | GNUNET_assert (NULL == logfile); |
731 | return GNUNET_OK; | 733 | return GNUNET_OK; |
732 | #else | 734 | #else |
733 | { | 735 | { |
734 | time_t t; | 736 | time_t t; |
735 | const struct tm *tm; | 737 | const struct tm *tm; |
736 | 738 | ||
737 | t = time(NULL); | 739 | t = time (NULL); |
738 | tm = gmtime(&t); | 740 | tm = gmtime (&t); |
739 | return setup_log_file(tm); | 741 | return setup_log_file (tm); |
740 | } | 742 | } |
741 | #endif | 743 | #endif |
742 | } | 744 | } |
@@ -752,11 +754,11 @@ GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile) | |||
752 | * @param logger_cls closure for @a logger | 754 | * @param logger_cls closure for @a logger |
753 | */ | 755 | */ |
754 | void | 756 | void |
755 | GNUNET_logger_add(GNUNET_Logger logger, void *logger_cls) | 757 | GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls) |
756 | { | 758 | { |
757 | struct CustomLogger *entry; | 759 | struct CustomLogger *entry; |
758 | 760 | ||
759 | entry = GNUNET_new(struct CustomLogger); | 761 | entry = GNUNET_new (struct CustomLogger); |
760 | entry->logger = logger; | 762 | entry->logger = logger; |
761 | entry->logger_cls = logger_cls; | 763 | entry->logger_cls = logger_cls; |
762 | entry->next = loggers; | 764 | entry->next = loggers; |
@@ -771,7 +773,7 @@ GNUNET_logger_add(GNUNET_Logger logger, void *logger_cls) | |||
771 | * @param logger_cls closure for @a logger | 773 | * @param logger_cls closure for @a logger |
772 | */ | 774 | */ |
773 | void | 775 | void |
774 | GNUNET_logger_remove(GNUNET_Logger logger, void *logger_cls) | 776 | GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls) |
775 | { | 777 | { |
776 | struct CustomLogger *pos; | 778 | struct CustomLogger *pos; |
777 | struct CustomLogger *prev; | 779 | struct CustomLogger *prev; |
@@ -780,16 +782,16 @@ GNUNET_logger_remove(GNUNET_Logger logger, void *logger_cls) | |||
780 | pos = loggers; | 782 | pos = loggers; |
781 | while ((NULL != pos) && | 783 | while ((NULL != pos) && |
782 | ((pos->logger != logger) || (pos->logger_cls != logger_cls))) | 784 | ((pos->logger != logger) || (pos->logger_cls != logger_cls))) |
783 | { | 785 | { |
784 | prev = pos; | 786 | prev = pos; |
785 | pos = pos->next; | 787 | pos = pos->next; |
786 | } | 788 | } |
787 | GNUNET_assert(NULL != pos); | 789 | GNUNET_assert (NULL != pos); |
788 | if (NULL == prev) | 790 | if (NULL == prev) |
789 | loggers = pos->next; | 791 | loggers = pos->next; |
790 | else | 792 | else |
791 | prev->next = pos->next; | 793 | prev->next = pos->next; |
792 | GNUNET_free(pos); | 794 | GNUNET_free (pos); |
793 | } | 795 | } |
794 | 796 | ||
795 | 797 | ||
@@ -802,67 +804,67 @@ GNUNET_logger_remove(GNUNET_Logger logger, void *logger_cls) | |||
802 | * @param msg the actual message | 804 | * @param msg the actual message |
803 | */ | 805 | */ |
804 | static void | 806 | static void |
805 | output_message(enum GNUNET_ErrorType kind, | 807 | output_message (enum GNUNET_ErrorType kind, |
806 | const char *comp, | 808 | const char *comp, |
807 | const char *datestr, | 809 | const char *datestr, |
808 | const char *msg) | 810 | const char *msg) |
809 | { | 811 | { |
810 | struct CustomLogger *pos; | 812 | struct CustomLogger *pos; |
811 | 813 | ||
812 | /* only use the standard logger if no custom loggers are present */ | 814 | /* only use the standard logger if no custom loggers are present */ |
813 | if ((NULL != GNUNET_stderr) && (NULL == loggers)) | 815 | if ((NULL != GNUNET_stderr) && (NULL == loggers)) |
816 | { | ||
817 | if (kind == GNUNET_ERROR_TYPE_MESSAGE) | ||
814 | { | 818 | { |
815 | if (kind == GNUNET_ERROR_TYPE_MESSAGE) | 819 | /* The idea here is to produce "normal" output messages |
816 | { | 820 | * for end users while still having the power of the |
817 | /* The idea here is to produce "normal" output messages | 821 | * logging engine for developer needs. So ideally this |
818 | * for end users while still having the power of the | 822 | * is what it should look like when CLI tools are used |
819 | * logging engine for developer needs. So ideally this | 823 | * interactively, yet the same message shouldn't look |
820 | * is what it should look like when CLI tools are used | 824 | * this way if the output is going to logfiles or robots |
821 | * interactively, yet the same message shouldn't look | 825 | * instead. |
822 | * this way if the output is going to logfiles or robots | 826 | */ |
823 | * instead. | 827 | fprintf (GNUNET_stderr, "* %s", msg); |
824 | */ | ||
825 | fprintf(GNUNET_stderr, "* %s", msg); | ||
826 | } | ||
827 | else if (GNUNET_YES == current_async_scope.have_scope) | ||
828 | { | ||
829 | static GNUNET_THREAD_LOCAL char id_buf[27]; | ||
830 | char *end; | ||
831 | |||
832 | /* We're logging, so skip_log must be currently 0. */ | ||
833 | skip_log = 100; | ||
834 | end = GNUNET_STRINGS_data_to_string(¤t_async_scope.scope_id, | ||
835 | sizeof(struct GNUNET_AsyncScopeId), | ||
836 | id_buf, | ||
837 | sizeof(id_buf) - 1); | ||
838 | GNUNET_assert(NULL != end); | ||
839 | *end = '\0'; | ||
840 | skip_log = 0; | ||
841 | fprintf(GNUNET_stderr, | ||
842 | "%s %s(%s) %s %s", | ||
843 | datestr, | ||
844 | comp, | ||
845 | id_buf, | ||
846 | GNUNET_error_type_to_string(kind), | ||
847 | msg); | ||
848 | } | ||
849 | else | ||
850 | { | ||
851 | fprintf(GNUNET_stderr, | ||
852 | "%s %s %s %s", | ||
853 | datestr, | ||
854 | comp, | ||
855 | GNUNET_error_type_to_string(kind), | ||
856 | msg); | ||
857 | } | ||
858 | fflush(GNUNET_stderr); | ||
859 | } | 828 | } |
860 | pos = loggers; | 829 | else if (GNUNET_YES == current_async_scope.have_scope) |
861 | while (NULL != pos) | ||
862 | { | 830 | { |
863 | pos->logger(pos->logger_cls, kind, comp, datestr, msg); | 831 | static GNUNET_THREAD_LOCAL char id_buf[27]; |
864 | pos = pos->next; | 832 | char *end; |
833 | |||
834 | /* We're logging, so skip_log must be currently 0. */ | ||
835 | skip_log = 100; | ||
836 | end = GNUNET_STRINGS_data_to_string (¤t_async_scope.scope_id, | ||
837 | sizeof(struct GNUNET_AsyncScopeId), | ||
838 | id_buf, | ||
839 | sizeof(id_buf) - 1); | ||
840 | GNUNET_assert (NULL != end); | ||
841 | *end = '\0'; | ||
842 | skip_log = 0; | ||
843 | fprintf (GNUNET_stderr, | ||
844 | "%s %s(%s) %s %s", | ||
845 | datestr, | ||
846 | comp, | ||
847 | id_buf, | ||
848 | GNUNET_error_type_to_string (kind), | ||
849 | msg); | ||
865 | } | 850 | } |
851 | else | ||
852 | { | ||
853 | fprintf (GNUNET_stderr, | ||
854 | "%s %s %s %s", | ||
855 | datestr, | ||
856 | comp, | ||
857 | GNUNET_error_type_to_string (kind), | ||
858 | msg); | ||
859 | } | ||
860 | fflush (GNUNET_stderr); | ||
861 | } | ||
862 | pos = loggers; | ||
863 | while (NULL != pos) | ||
864 | { | ||
865 | pos->logger (pos->logger_cls, kind, comp, datestr, msg); | ||
866 | pos = pos->next; | ||
867 | } | ||
866 | } | 868 | } |
867 | 869 | ||
868 | 870 | ||
@@ -872,7 +874,7 @@ output_message(enum GNUNET_ErrorType kind, | |||
872 | * @param datestr our current timestamp | 874 | * @param datestr our current timestamp |
873 | */ | 875 | */ |
874 | static void | 876 | static void |
875 | flush_bulk(const char *datestr) | 877 | flush_bulk (const char *datestr) |
876 | { | 878 | { |
877 | char msg[DATE_STR_SIZE + BULK_TRACK_SIZE + 256]; | 879 | char msg[DATE_STR_SIZE + BULK_TRACK_SIZE + 256]; |
878 | int rev; | 880 | int rev; |
@@ -882,31 +884,31 @@ flush_bulk(const char *datestr) | |||
882 | if ((0 == last_bulk_time.abs_value_us) || (0 == last_bulk_repeat)) | 884 | if ((0 == last_bulk_time.abs_value_us) || (0 == last_bulk_repeat)) |
883 | return; | 885 | return; |
884 | rev = 0; | 886 | rev = 0; |
885 | last = memchr(last_bulk, '\0', BULK_TRACK_SIZE); | 887 | last = memchr (last_bulk, '\0', BULK_TRACK_SIZE); |
886 | if (last == NULL) | 888 | if (last == NULL) |
887 | last = &last_bulk[BULK_TRACK_SIZE - 1]; | 889 | last = &last_bulk[BULK_TRACK_SIZE - 1]; |
888 | else if (last != last_bulk) | 890 | else if (last != last_bulk) |
889 | last--; | 891 | last--; |
890 | if (last[0] == '\n') | 892 | if (last[0] == '\n') |
891 | { | 893 | { |
892 | rev = 1; | 894 | rev = 1; |
893 | last[0] = '\0'; | 895 | last[0] = '\0'; |
894 | } | 896 | } |
895 | ft = | 897 | ft = |
896 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration( | 898 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration ( |
897 | last_bulk_time), | 899 | last_bulk_time), |
898 | GNUNET_YES); | 900 | GNUNET_YES); |
899 | snprintf(msg, | 901 | snprintf (msg, |
900 | sizeof(msg), | 902 | sizeof(msg), |
901 | _("Message `%.*s' repeated %u times in the last %s\n"), | 903 | _ ("Message `%.*s' repeated %u times in the last %s\n"), |
902 | BULK_TRACK_SIZE, | 904 | BULK_TRACK_SIZE, |
903 | last_bulk, | 905 | last_bulk, |
904 | last_bulk_repeat, | 906 | last_bulk_repeat, |
905 | ft); | 907 | ft); |
906 | if (rev == 1) | 908 | if (rev == 1) |
907 | last[0] = '\n'; | 909 | last[0] = '\n'; |
908 | output_message(last_bulk_kind, last_bulk_comp, datestr, msg); | 910 | output_message (last_bulk_kind, last_bulk_comp, datestr, msg); |
909 | last_bulk_time = GNUNET_TIME_absolute_get(); | 911 | last_bulk_time = GNUNET_TIME_absolute_get (); |
910 | last_bulk_repeat = 0; | 912 | last_bulk_repeat = 0; |
911 | } | 913 | } |
912 | 914 | ||
@@ -918,21 +920,21 @@ flush_bulk(const char *datestr) | |||
918 | * @param check_reset #GNUNET_YES to assert that the log skip counter is currently zero | 920 | * @param check_reset #GNUNET_YES to assert that the log skip counter is currently zero |
919 | */ | 921 | */ |
920 | void | 922 | void |
921 | GNUNET_log_skip(int n, int check_reset) | 923 | GNUNET_log_skip (int n, int check_reset) |
922 | { | 924 | { |
923 | int ok; | 925 | int ok; |
924 | 926 | ||
925 | if (0 == n) | 927 | if (0 == n) |
926 | { | 928 | { |
927 | ok = (0 == skip_log); | 929 | ok = (0 == skip_log); |
928 | skip_log = 0; | 930 | skip_log = 0; |
929 | if (check_reset) | 931 | if (check_reset) |
930 | GNUNET_break(ok); | 932 | GNUNET_break (ok); |
931 | } | 933 | } |
932 | else | 934 | else |
933 | { | 935 | { |
934 | skip_log += n; | 936 | skip_log += n; |
935 | } | 937 | } |
936 | } | 938 | } |
937 | 939 | ||
938 | 940 | ||
@@ -942,7 +944,7 @@ GNUNET_log_skip(int n, int check_reset) | |||
942 | * @return number of log calls to be ignored | 944 | * @return number of log calls to be ignored |
943 | */ | 945 | */ |
944 | int | 946 | int |
945 | GNUNET_get_log_skip() | 947 | GNUNET_get_log_skip () |
946 | { | 948 | { |
947 | return skip_log; | 949 | return skip_log; |
948 | } | 950 | } |
@@ -957,10 +959,10 @@ GNUNET_get_log_skip() | |||
957 | * @param va arguments to the format string "message" | 959 | * @param va arguments to the format string "message" |
958 | */ | 960 | */ |
959 | static void | 961 | static void |
960 | mylog(enum GNUNET_ErrorType kind, | 962 | mylog (enum GNUNET_ErrorType kind, |
961 | const char *comp, | 963 | const char *comp, |
962 | const char *message, | 964 | const char *message, |
963 | va_list va) | 965 | va_list va) |
964 | { | 966 | { |
965 | char date[DATE_STR_SIZE]; | 967 | char date[DATE_STR_SIZE]; |
966 | char date2[DATE_STR_SIZE]; | 968 | char date2[DATE_STR_SIZE]; |
@@ -968,78 +970,78 @@ mylog(enum GNUNET_ErrorType kind, | |||
968 | size_t size; | 970 | size_t size; |
969 | va_list vacp; | 971 | va_list vacp; |
970 | 972 | ||
971 | va_copy(vacp, va); | 973 | va_copy (vacp, va); |
972 | size = vsnprintf(NULL, 0, message, vacp) + 1; | 974 | size = vsnprintf (NULL, 0, message, vacp) + 1; |
973 | GNUNET_assert(0 != size); | 975 | GNUNET_assert (0 != size); |
974 | va_end(vacp); | 976 | va_end (vacp); |
975 | memset(date, 0, DATE_STR_SIZE); | 977 | memset (date, 0, DATE_STR_SIZE); |
976 | { | 978 | { |
977 | char buf[size]; | 979 | char buf[size]; |
978 | long long offset; | 980 | long long offset; |
979 | 981 | ||
980 | struct timeval timeofday; | 982 | struct timeval timeofday; |
981 | 983 | ||
982 | gettimeofday(&timeofday, NULL); | 984 | gettimeofday (&timeofday, NULL); |
983 | offset = GNUNET_TIME_get_offset(); | 985 | offset = GNUNET_TIME_get_offset (); |
984 | if (offset > 0) | 986 | if (offset > 0) |
987 | { | ||
988 | timeofday.tv_sec += offset / 1000LL; | ||
989 | timeofday.tv_usec += (offset % 1000LL) * 1000LL; | ||
990 | if (timeofday.tv_usec > 1000000LL) | ||
985 | { | 991 | { |
986 | timeofday.tv_sec += offset / 1000LL; | 992 | timeofday.tv_usec -= 1000000LL; |
987 | timeofday.tv_usec += (offset % 1000LL) * 1000LL; | 993 | timeofday.tv_sec++; |
988 | if (timeofday.tv_usec > 1000000LL) | ||
989 | { | ||
990 | timeofday.tv_usec -= 1000000LL; | ||
991 | timeofday.tv_sec++; | ||
992 | } | ||
993 | } | 994 | } |
995 | } | ||
994 | else | 996 | else |
997 | { | ||
998 | timeofday.tv_sec += offset / 1000LL; | ||
999 | if (timeofday.tv_usec > -(offset % 1000LL) * 1000LL) | ||
995 | { | 1000 | { |
996 | timeofday.tv_sec += offset / 1000LL; | 1001 | timeofday.tv_usec += (offset % 1000LL) * 1000LL; |
997 | if (timeofday.tv_usec > -(offset % 1000LL) * 1000LL) | ||
998 | { | ||
999 | timeofday.tv_usec += (offset % 1000LL) * 1000LL; | ||
1000 | } | ||
1001 | else | ||
1002 | { | ||
1003 | timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL; | ||
1004 | timeofday.tv_sec--; | ||
1005 | } | ||
1006 | } | 1002 | } |
1007 | tmptr = localtime(&timeofday.tv_sec); | 1003 | else |
1008 | if (NULL == tmptr) | ||
1009 | { | 1004 | { |
1010 | strcpy(date, "localtime error"); | 1005 | timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL; |
1006 | timeofday.tv_sec--; | ||
1011 | } | 1007 | } |
1008 | } | ||
1009 | tmptr = localtime (&timeofday.tv_sec); | ||
1010 | if (NULL == tmptr) | ||
1011 | { | ||
1012 | strcpy (date, "localtime error"); | ||
1013 | } | ||
1012 | else | 1014 | else |
1013 | { | 1015 | { |
1014 | if (0 == strftime(date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr)) | 1016 | if (0 == strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr)) |
1015 | abort(); | 1017 | abort (); |
1016 | if (0 > snprintf(date, sizeof(date), date2, timeofday.tv_usec)) | 1018 | if (0 > snprintf (date, sizeof(date), date2, timeofday.tv_usec)) |
1017 | abort(); | 1019 | abort (); |
1018 | } | 1020 | } |
1019 | 1021 | ||
1020 | vsnprintf(buf, size, message, va); | 1022 | vsnprintf (buf, size, message, va); |
1021 | #if !(defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY) | 1023 | #if ! (defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY) |
1022 | if (NULL != tmptr) | 1024 | if (NULL != tmptr) |
1023 | (void)setup_log_file(tmptr); | 1025 | (void) setup_log_file (tmptr); |
1024 | #endif | 1026 | #endif |
1025 | if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && | 1027 | if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && |
1026 | (0 != last_bulk_time.abs_value_us) && | 1028 | (0 != last_bulk_time.abs_value_us) && |
1027 | (0 == strncmp(buf, last_bulk, sizeof(last_bulk)))) | 1029 | (0 == strncmp (buf, last_bulk, sizeof(last_bulk)))) |
1028 | { | 1030 | { |
1029 | last_bulk_repeat++; | 1031 | last_bulk_repeat++; |
1030 | if ((GNUNET_TIME_absolute_get_duration(last_bulk_time).rel_value_us > | 1032 | if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value_us > |
1031 | BULK_DELAY_THRESHOLD) || | 1033 | BULK_DELAY_THRESHOLD) || |
1032 | (last_bulk_repeat > BULK_REPEAT_THRESHOLD)) | 1034 | (last_bulk_repeat > BULK_REPEAT_THRESHOLD)) |
1033 | flush_bulk(date); | 1035 | flush_bulk (date); |
1034 | return; | 1036 | return; |
1035 | } | 1037 | } |
1036 | flush_bulk(date); | 1038 | flush_bulk (date); |
1037 | GNUNET_strlcpy(last_bulk, buf, sizeof(last_bulk)); | 1039 | GNUNET_strlcpy (last_bulk, buf, sizeof(last_bulk)); |
1038 | last_bulk_repeat = 0; | 1040 | last_bulk_repeat = 0; |
1039 | last_bulk_kind = kind; | 1041 | last_bulk_kind = kind; |
1040 | last_bulk_time = GNUNET_TIME_absolute_get(); | 1042 | last_bulk_time = GNUNET_TIME_absolute_get (); |
1041 | GNUNET_strlcpy(last_bulk_comp, comp, sizeof(last_bulk_comp)); | 1043 | GNUNET_strlcpy (last_bulk_comp, comp, sizeof(last_bulk_comp)); |
1042 | output_message(kind, comp, date, buf); | 1044 | output_message (kind, comp, date, buf); |
1043 | } | 1045 | } |
1044 | } | 1046 | } |
1045 | 1047 | ||
@@ -1052,13 +1054,13 @@ mylog(enum GNUNET_ErrorType kind, | |||
1052 | * @param ... arguments for format string | 1054 | * @param ... arguments for format string |
1053 | */ | 1055 | */ |
1054 | void | 1056 | void |
1055 | GNUNET_log_nocheck(enum GNUNET_ErrorType kind, const char *message, ...) | 1057 | GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...) |
1056 | { | 1058 | { |
1057 | va_list va; | 1059 | va_list va; |
1058 | 1060 | ||
1059 | va_start(va, message); | 1061 | va_start (va, message); |
1060 | mylog(kind, component, message, va); | 1062 | mylog (kind, component, message, va); |
1061 | va_end(va); | 1063 | va_end (va); |
1062 | } | 1064 | } |
1063 | 1065 | ||
1064 | 1066 | ||
@@ -1072,10 +1074,10 @@ GNUNET_log_nocheck(enum GNUNET_ErrorType kind, const char *message, ...) | |||
1072 | * @param ... arguments for format string | 1074 | * @param ... arguments for format string |
1073 | */ | 1075 | */ |
1074 | void | 1076 | void |
1075 | GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, | 1077 | GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, |
1076 | const char *comp, | 1078 | const char *comp, |
1077 | const char *message, | 1079 | const char *message, |
1078 | ...) | 1080 | ...) |
1079 | { | 1081 | { |
1080 | va_list va; | 1082 | va_list va; |
1081 | char comp_w_pid[128]; | 1083 | char comp_w_pid[128]; |
@@ -1083,10 +1085,10 @@ GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, | |||
1083 | if (comp == NULL) | 1085 | if (comp == NULL) |
1084 | comp = component_nopid; | 1086 | comp = component_nopid; |
1085 | 1087 | ||
1086 | va_start(va, message); | 1088 | va_start (va, message); |
1087 | GNUNET_snprintf(comp_w_pid, sizeof(comp_w_pid), "%s-%d", comp, getpid()); | 1089 | GNUNET_snprintf (comp_w_pid, sizeof(comp_w_pid), "%s-%d", comp, getpid ()); |
1088 | mylog(kind, comp_w_pid, message, va); | 1090 | mylog (kind, comp_w_pid, message, va); |
1089 | va_end(va); | 1091 | va_end (va); |
1090 | } | 1092 | } |
1091 | 1093 | ||
1092 | 1094 | ||
@@ -1097,21 +1099,21 @@ GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, | |||
1097 | * @return string corresponding to the type | 1099 | * @return string corresponding to the type |
1098 | */ | 1100 | */ |
1099 | const char * | 1101 | const char * |
1100 | GNUNET_error_type_to_string(enum GNUNET_ErrorType kind) | 1102 | GNUNET_error_type_to_string (enum GNUNET_ErrorType kind) |
1101 | { | 1103 | { |
1102 | if ((kind & GNUNET_ERROR_TYPE_ERROR) > 0) | 1104 | if ((kind & GNUNET_ERROR_TYPE_ERROR) > 0) |
1103 | return _("ERROR"); | 1105 | return _ ("ERROR"); |
1104 | if ((kind & GNUNET_ERROR_TYPE_WARNING) > 0) | 1106 | if ((kind & GNUNET_ERROR_TYPE_WARNING) > 0) |
1105 | return _("WARNING"); | 1107 | return _ ("WARNING"); |
1106 | if ((kind & GNUNET_ERROR_TYPE_MESSAGE) > 0) | 1108 | if ((kind & GNUNET_ERROR_TYPE_MESSAGE) > 0) |
1107 | return _("MESSAGE"); | 1109 | return _ ("MESSAGE"); |
1108 | if ((kind & GNUNET_ERROR_TYPE_INFO) > 0) | 1110 | if ((kind & GNUNET_ERROR_TYPE_INFO) > 0) |
1109 | return _("INFO"); | 1111 | return _ ("INFO"); |
1110 | if ((kind & GNUNET_ERROR_TYPE_DEBUG) > 0) | 1112 | if ((kind & GNUNET_ERROR_TYPE_DEBUG) > 0) |
1111 | return _("DEBUG"); | 1113 | return _ ("DEBUG"); |
1112 | if ((kind & ~GNUNET_ERROR_TYPE_BULK) == 0) | 1114 | if ((kind & ~GNUNET_ERROR_TYPE_BULK) == 0) |
1113 | return _("NONE"); | 1115 | return _ ("NONE"); |
1114 | return _("INVALID"); | 1116 | return _ ("INVALID"); |
1115 | } | 1117 | } |
1116 | 1118 | ||
1117 | 1119 | ||
@@ -1122,13 +1124,13 @@ GNUNET_error_type_to_string(enum GNUNET_ErrorType kind) | |||
1122 | * @return string form; will be overwritten by next call to GNUNET_h2s. | 1124 | * @return string form; will be overwritten by next call to GNUNET_h2s. |
1123 | */ | 1125 | */ |
1124 | const char * | 1126 | const char * |
1125 | GNUNET_h2s(const struct GNUNET_HashCode *hc) | 1127 | GNUNET_h2s (const struct GNUNET_HashCode *hc) |
1126 | { | 1128 | { |
1127 | static GNUNET_THREAD_LOCAL struct GNUNET_CRYPTO_HashAsciiEncoded ret; | 1129 | static GNUNET_THREAD_LOCAL struct GNUNET_CRYPTO_HashAsciiEncoded ret; |
1128 | 1130 | ||
1129 | GNUNET_CRYPTO_hash_to_enc(hc, &ret); | 1131 | GNUNET_CRYPTO_hash_to_enc (hc, &ret); |
1130 | ret.encoding[8] = '\0'; | 1132 | ret.encoding[8] = '\0'; |
1131 | return (const char *)ret.encoding; | 1133 | return (const char *) ret.encoding; |
1132 | } | 1134 | } |
1133 | 1135 | ||
1134 | 1136 | ||
@@ -1143,13 +1145,13 @@ GNUNET_h2s(const struct GNUNET_HashCode *hc) | |||
1143 | * @return string form; will be overwritten by next call to GNUNET_h2s. | 1145 | * @return string form; will be overwritten by next call to GNUNET_h2s. |
1144 | */ | 1146 | */ |
1145 | const char * | 1147 | const char * |
1146 | GNUNET_h2s2(const struct GNUNET_HashCode *hc) | 1148 | GNUNET_h2s2 (const struct GNUNET_HashCode *hc) |
1147 | { | 1149 | { |
1148 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | 1150 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; |
1149 | 1151 | ||
1150 | GNUNET_CRYPTO_hash_to_enc(hc, &ret); | 1152 | GNUNET_CRYPTO_hash_to_enc (hc, &ret); |
1151 | ret.encoding[8] = '\0'; | 1153 | ret.encoding[8] = '\0'; |
1152 | return (const char *)ret.encoding; | 1154 | return (const char *) ret.encoding; |
1153 | } | 1155 | } |
1154 | 1156 | ||
1155 | 1157 | ||
@@ -1163,15 +1165,15 @@ GNUNET_h2s2(const struct GNUNET_HashCode *hc) | |||
1163 | * @return string | 1165 | * @return string |
1164 | */ | 1166 | */ |
1165 | const char * | 1167 | const char * |
1166 | GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p) | 1168 | GNUNET_p2s (const struct GNUNET_CRYPTO_EddsaPublicKey *p) |
1167 | { | 1169 | { |
1168 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | 1170 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; |
1169 | struct GNUNET_HashCode hc; | 1171 | struct GNUNET_HashCode hc; |
1170 | 1172 | ||
1171 | GNUNET_CRYPTO_hash(p, sizeof(*p), &hc); | 1173 | GNUNET_CRYPTO_hash (p, sizeof(*p), &hc); |
1172 | GNUNET_CRYPTO_hash_to_enc(&hc, &ret); | 1174 | GNUNET_CRYPTO_hash_to_enc (&hc, &ret); |
1173 | ret.encoding[6] = '\0'; | 1175 | ret.encoding[6] = '\0'; |
1174 | return (const char *)ret.encoding; | 1176 | return (const char *) ret.encoding; |
1175 | } | 1177 | } |
1176 | 1178 | ||
1177 | 1179 | ||
@@ -1185,15 +1187,15 @@ GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p) | |||
1185 | * @return string | 1187 | * @return string |
1186 | */ | 1188 | */ |
1187 | const char * | 1189 | const char * |
1188 | GNUNET_p2s2(const struct GNUNET_CRYPTO_EddsaPublicKey *p) | 1190 | GNUNET_p2s2 (const struct GNUNET_CRYPTO_EddsaPublicKey *p) |
1189 | { | 1191 | { |
1190 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | 1192 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; |
1191 | struct GNUNET_HashCode hc; | 1193 | struct GNUNET_HashCode hc; |
1192 | 1194 | ||
1193 | GNUNET_CRYPTO_hash(p, sizeof(*p), &hc); | 1195 | GNUNET_CRYPTO_hash (p, sizeof(*p), &hc); |
1194 | GNUNET_CRYPTO_hash_to_enc(&hc, &ret); | 1196 | GNUNET_CRYPTO_hash_to_enc (&hc, &ret); |
1195 | ret.encoding[6] = '\0'; | 1197 | ret.encoding[6] = '\0'; |
1196 | return (const char *)ret.encoding; | 1198 | return (const char *) ret.encoding; |
1197 | } | 1199 | } |
1198 | 1200 | ||
1199 | 1201 | ||
@@ -1207,15 +1209,15 @@ GNUNET_p2s2(const struct GNUNET_CRYPTO_EddsaPublicKey *p) | |||
1207 | * @return string | 1209 | * @return string |
1208 | */ | 1210 | */ |
1209 | const char * | 1211 | const char * |
1210 | GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p) | 1212 | GNUNET_e2s (const struct GNUNET_CRYPTO_EcdhePublicKey *p) |
1211 | { | 1213 | { |
1212 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | 1214 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; |
1213 | struct GNUNET_HashCode hc; | 1215 | struct GNUNET_HashCode hc; |
1214 | 1216 | ||
1215 | GNUNET_CRYPTO_hash(p, sizeof(*p), &hc); | 1217 | GNUNET_CRYPTO_hash (p, sizeof(*p), &hc); |
1216 | GNUNET_CRYPTO_hash_to_enc(&hc, &ret); | 1218 | GNUNET_CRYPTO_hash_to_enc (&hc, &ret); |
1217 | ret.encoding[6] = '\0'; | 1219 | ret.encoding[6] = '\0'; |
1218 | return (const char *)ret.encoding; | 1220 | return (const char *) ret.encoding; |
1219 | } | 1221 | } |
1220 | 1222 | ||
1221 | 1223 | ||
@@ -1229,15 +1231,15 @@ GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p) | |||
1229 | * @return string | 1231 | * @return string |
1230 | */ | 1232 | */ |
1231 | const char * | 1233 | const char * |
1232 | GNUNET_e2s2(const struct GNUNET_CRYPTO_EcdhePublicKey *p) | 1234 | GNUNET_e2s2 (const struct GNUNET_CRYPTO_EcdhePublicKey *p) |
1233 | { | 1235 | { |
1234 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | 1236 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; |
1235 | struct GNUNET_HashCode hc; | 1237 | struct GNUNET_HashCode hc; |
1236 | 1238 | ||
1237 | GNUNET_CRYPTO_hash(p, sizeof(*p), &hc); | 1239 | GNUNET_CRYPTO_hash (p, sizeof(*p), &hc); |
1238 | GNUNET_CRYPTO_hash_to_enc(&hc, &ret); | 1240 | GNUNET_CRYPTO_hash_to_enc (&hc, &ret); |
1239 | ret.encoding[6] = '\0'; | 1241 | ret.encoding[6] = '\0'; |
1240 | return (const char *)ret.encoding; | 1242 | return (const char *) ret.encoding; |
1241 | } | 1243 | } |
1242 | 1244 | ||
1243 | 1245 | ||
@@ -1251,13 +1253,13 @@ GNUNET_e2s2(const struct GNUNET_CRYPTO_EcdhePublicKey *p) | |||
1251 | * @return string | 1253 | * @return string |
1252 | */ | 1254 | */ |
1253 | const char * | 1255 | const char * |
1254 | GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc) | 1256 | GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc) |
1255 | { | 1257 | { |
1256 | static char buf[64]; | 1258 | static char buf[64]; |
1257 | 1259 | ||
1258 | GNUNET_STRINGS_data_to_string(shc, sizeof(*shc), buf, sizeof(buf)); | 1260 | GNUNET_STRINGS_data_to_string (shc, sizeof(*shc), buf, sizeof(buf)); |
1259 | buf[6] = '\0'; | 1261 | buf[6] = '\0'; |
1260 | return (const char *)buf; | 1262 | return (const char *) buf; |
1261 | } | 1263 | } |
1262 | 1264 | ||
1263 | 1265 | ||
@@ -1271,13 +1273,13 @@ GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc) | |||
1271 | * @return string | 1273 | * @return string |
1272 | */ | 1274 | */ |
1273 | const char * | 1275 | const char * |
1274 | GNUNET_uuid2s(const struct GNUNET_Uuid *uuid) | 1276 | GNUNET_uuid2s (const struct GNUNET_Uuid *uuid) |
1275 | { | 1277 | { |
1276 | static char buf[32]; | 1278 | static char buf[32]; |
1277 | 1279 | ||
1278 | GNUNET_STRINGS_data_to_string(uuid, sizeof(*uuid), buf, sizeof(buf)); | 1280 | GNUNET_STRINGS_data_to_string (uuid, sizeof(*uuid), buf, sizeof(buf)); |
1279 | buf[6] = '\0'; | 1281 | buf[6] = '\0'; |
1280 | return (const char *)buf; | 1282 | return (const char *) buf; |
1281 | } | 1283 | } |
1282 | 1284 | ||
1283 | 1285 | ||
@@ -1290,13 +1292,13 @@ GNUNET_uuid2s(const struct GNUNET_Uuid *uuid) | |||
1290 | * @return string form; will be overwritten by next call to GNUNET_h2s_full. | 1292 | * @return string form; will be overwritten by next call to GNUNET_h2s_full. |
1291 | */ | 1293 | */ |
1292 | const char * | 1294 | const char * |
1293 | GNUNET_h2s_full(const struct GNUNET_HashCode *hc) | 1295 | GNUNET_h2s_full (const struct GNUNET_HashCode *hc) |
1294 | { | 1296 | { |
1295 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; | 1297 | static struct GNUNET_CRYPTO_HashAsciiEncoded ret; |
1296 | 1298 | ||
1297 | GNUNET_CRYPTO_hash_to_enc(hc, &ret); | 1299 | GNUNET_CRYPTO_hash_to_enc (hc, &ret); |
1298 | ret.encoding[sizeof(ret) - 1] = '\0'; | 1300 | ret.encoding[sizeof(ret) - 1] = '\0'; |
1299 | return (const char *)ret.encoding; | 1301 | return (const char *) ret.encoding; |
1300 | } | 1302 | } |
1301 | 1303 | ||
1302 | 1304 | ||
@@ -1308,16 +1310,16 @@ GNUNET_h2s_full(const struct GNUNET_HashCode *hc) | |||
1308 | * call to #GNUNET_i2s. | 1310 | * call to #GNUNET_i2s. |
1309 | */ | 1311 | */ |
1310 | const char * | 1312 | const char * |
1311 | GNUNET_i2s(const struct GNUNET_PeerIdentity *pid) | 1313 | GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) |
1312 | { | 1314 | { |
1313 | static GNUNET_THREAD_LOCAL char buf[5]; | 1315 | static GNUNET_THREAD_LOCAL char buf[5]; |
1314 | char *ret; | 1316 | char *ret; |
1315 | 1317 | ||
1316 | if (NULL == pid) | 1318 | if (NULL == pid) |
1317 | return "NULL"; | 1319 | return "NULL"; |
1318 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string(&pid->public_key); | 1320 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1319 | GNUNET_strlcpy(buf, ret, sizeof(buf)); | 1321 | GNUNET_strlcpy (buf, ret, sizeof(buf)); |
1320 | GNUNET_free(ret); | 1322 | GNUNET_free (ret); |
1321 | return buf; | 1323 | return buf; |
1322 | } | 1324 | } |
1323 | 1325 | ||
@@ -1333,16 +1335,16 @@ GNUNET_i2s(const struct GNUNET_PeerIdentity *pid) | |||
1333 | * call to #GNUNET_i2s. | 1335 | * call to #GNUNET_i2s. |
1334 | */ | 1336 | */ |
1335 | const char * | 1337 | const char * |
1336 | GNUNET_i2s2(const struct GNUNET_PeerIdentity *pid) | 1338 | GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) |
1337 | { | 1339 | { |
1338 | static GNUNET_THREAD_LOCAL char buf[5]; | 1340 | static GNUNET_THREAD_LOCAL char buf[5]; |
1339 | char *ret; | 1341 | char *ret; |
1340 | 1342 | ||
1341 | if (NULL == pid) | 1343 | if (NULL == pid) |
1342 | return "NULL"; | 1344 | return "NULL"; |
1343 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string(&pid->public_key); | 1345 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1344 | GNUNET_strlcpy(buf, ret, sizeof(buf)); | 1346 | GNUNET_strlcpy (buf, ret, sizeof(buf)); |
1345 | GNUNET_free(ret); | 1347 | GNUNET_free (ret); |
1346 | return buf; | 1348 | return buf; |
1347 | } | 1349 | } |
1348 | 1350 | ||
@@ -1355,14 +1357,14 @@ GNUNET_i2s2(const struct GNUNET_PeerIdentity *pid) | |||
1355 | * call to #GNUNET_i2s_full. | 1357 | * call to #GNUNET_i2s_full. |
1356 | */ | 1358 | */ |
1357 | const char * | 1359 | const char * |
1358 | GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid) | 1360 | GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid) |
1359 | { | 1361 | { |
1360 | static GNUNET_THREAD_LOCAL char buf[256]; | 1362 | static GNUNET_THREAD_LOCAL char buf[256]; |
1361 | char *ret; | 1363 | char *ret; |
1362 | 1364 | ||
1363 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string(&pid->public_key); | 1365 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1364 | strcpy(buf, ret); | 1366 | strcpy (buf, ret); |
1365 | GNUNET_free(ret); | 1367 | GNUNET_free (ret); |
1366 | return buf; | 1368 | return buf; |
1367 | } | 1369 | } |
1368 | 1370 | ||
@@ -1378,11 +1380,11 @@ GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid) | |||
1378 | * will be overwritten by next call to #GNUNET_a2s. | 1380 | * will be overwritten by next call to #GNUNET_a2s. |
1379 | */ | 1381 | */ |
1380 | const char * | 1382 | const char * |
1381 | GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen) | 1383 | GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen) |
1382 | { | 1384 | { |
1383 | #define LEN \ | 1385 | #define LEN \ |
1384 | GNUNET_MAX((INET6_ADDRSTRLEN + 8), \ | 1386 | GNUNET_MAX ((INET6_ADDRSTRLEN + 8), \ |
1385 | (1 + sizeof(struct sockaddr_un) - sizeof(sa_family_t))) | 1387 | (1 + sizeof(struct sockaddr_un) - sizeof(sa_family_t))) |
1386 | static char buf[LEN]; | 1388 | static char buf[LEN]; |
1387 | #undef LEN | 1389 | #undef LEN |
1388 | static char b2[6]; | 1390 | static char b2[6]; |
@@ -1392,53 +1394,53 @@ GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen) | |||
1392 | unsigned int off; | 1394 | unsigned int off; |
1393 | 1395 | ||
1394 | if (addr == NULL) | 1396 | if (addr == NULL) |
1395 | return _("unknown address"); | 1397 | return _ ("unknown address"); |
1396 | switch (addr->sa_family) | 1398 | switch (addr->sa_family) |
1397 | { | 1399 | { |
1398 | case AF_INET: | 1400 | case AF_INET: |
1399 | if (addrlen != sizeof(struct sockaddr_in)) | 1401 | if (addrlen != sizeof(struct sockaddr_in)) |
1400 | return "<invalid v4 address>"; | 1402 | return "<invalid v4 address>"; |
1401 | v4 = (const struct sockaddr_in *)addr; | 1403 | v4 = (const struct sockaddr_in *) addr; |
1402 | inet_ntop(AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); | 1404 | inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); |
1403 | if (0 == ntohs(v4->sin_port)) | 1405 | if (0 == ntohs (v4->sin_port)) |
1404 | return buf; | ||
1405 | strcat(buf, ":"); | ||
1406 | GNUNET_snprintf(b2, sizeof(b2), "%u", ntohs(v4->sin_port)); | ||
1407 | strcat(buf, b2); | ||
1408 | return buf; | ||
1409 | |||
1410 | case AF_INET6: | ||
1411 | if (addrlen != sizeof(struct sockaddr_in6)) | ||
1412 | return "<invalid v4 address>"; | ||
1413 | v6 = (const struct sockaddr_in6 *)addr; | ||
1414 | buf[0] = '['; | ||
1415 | inet_ntop(AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN); | ||
1416 | if (0 == ntohs(v6->sin6_port)) | ||
1417 | return &buf[1]; | ||
1418 | strcat(buf, "]:"); | ||
1419 | GNUNET_snprintf(b2, sizeof(b2), "%u", ntohs(v6->sin6_port)); | ||
1420 | strcat(buf, b2); | ||
1421 | return buf; | ||
1422 | |||
1423 | case AF_UNIX: | ||
1424 | if (addrlen <= sizeof(sa_family_t)) | ||
1425 | return "<unbound UNIX client>"; | ||
1426 | un = (const struct sockaddr_un *)addr; | ||
1427 | off = 0; | ||
1428 | if ('\0' == un->sun_path[0]) | ||
1429 | off++; | ||
1430 | memset(buf, 0, sizeof(buf)); | ||
1431 | GNUNET_snprintf(buf, | ||
1432 | sizeof(buf), | ||
1433 | "%s%.*s", | ||
1434 | (1 == off) ? "@" : "", | ||
1435 | (int)(addrlen - sizeof(sa_family_t) - off), | ||
1436 | &un->sun_path[off]); | ||
1437 | return buf; | 1406 | return buf; |
1438 | 1407 | strcat (buf, ":"); | |
1439 | default: | 1408 | GNUNET_snprintf (b2, sizeof(b2), "%u", ntohs (v4->sin_port)); |
1440 | return _("invalid address"); | 1409 | strcat (buf, b2); |
1441 | } | 1410 | return buf; |
1411 | |||
1412 | case AF_INET6: | ||
1413 | if (addrlen != sizeof(struct sockaddr_in6)) | ||
1414 | return "<invalid v4 address>"; | ||
1415 | v6 = (const struct sockaddr_in6 *) addr; | ||
1416 | buf[0] = '['; | ||
1417 | inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN); | ||
1418 | if (0 == ntohs (v6->sin6_port)) | ||
1419 | return &buf[1]; | ||
1420 | strcat (buf, "]:"); | ||
1421 | GNUNET_snprintf (b2, sizeof(b2), "%u", ntohs (v6->sin6_port)); | ||
1422 | strcat (buf, b2); | ||
1423 | return buf; | ||
1424 | |||
1425 | case AF_UNIX: | ||
1426 | if (addrlen <= sizeof(sa_family_t)) | ||
1427 | return "<unbound UNIX client>"; | ||
1428 | un = (const struct sockaddr_un *) addr; | ||
1429 | off = 0; | ||
1430 | if ('\0' == un->sun_path[0]) | ||
1431 | off++; | ||
1432 | memset (buf, 0, sizeof(buf)); | ||
1433 | GNUNET_snprintf (buf, | ||
1434 | sizeof(buf), | ||
1435 | "%s%.*s", | ||
1436 | (1 == off) ? "@" : "", | ||
1437 | (int) (addrlen - sizeof(sa_family_t) - off), | ||
1438 | &un->sun_path[off]); | ||
1439 | return buf; | ||
1440 | |||
1441 | default: | ||
1442 | return _ ("invalid address"); | ||
1443 | } | ||
1442 | } | 1444 | } |
1443 | 1445 | ||
1444 | 1446 | ||
@@ -1450,15 +1452,15 @@ GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen) | |||
1450 | * @param option name of missing option | 1452 | * @param option name of missing option |
1451 | */ | 1453 | */ |
1452 | void | 1454 | void |
1453 | GNUNET_log_config_missing(enum GNUNET_ErrorType kind, | 1455 | GNUNET_log_config_missing (enum GNUNET_ErrorType kind, |
1454 | const char *section, | 1456 | const char *section, |
1455 | const char *option) | 1457 | const char *option) |
1456 | { | 1458 | { |
1457 | GNUNET_log(kind, | 1459 | GNUNET_log (kind, |
1458 | _( | 1460 | _ ( |
1459 | "Configuration fails to specify option `%s' in section `%s'!\n"), | 1461 | "Configuration fails to specify option `%s' in section `%s'!\n"), |
1460 | option, | 1462 | option, |
1461 | section); | 1463 | section); |
1462 | } | 1464 | } |
1463 | 1465 | ||
1464 | 1466 | ||
@@ -1471,14 +1473,14 @@ GNUNET_log_config_missing(enum GNUNET_ErrorType kind, | |||
1471 | * @param required what is required that is invalid about the option | 1473 | * @param required what is required that is invalid about the option |
1472 | */ | 1474 | */ |
1473 | void | 1475 | void |
1474 | GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, | 1476 | GNUNET_log_config_invalid (enum GNUNET_ErrorType kind, |
1475 | const char *section, | 1477 | const char *section, |
1476 | const char *option, | 1478 | const char *option, |
1477 | const char *required) | 1479 | const char *required) |
1478 | { | 1480 | { |
1479 | GNUNET_log( | 1481 | GNUNET_log ( |
1480 | kind, | 1482 | kind, |
1481 | _( | 1483 | _ ( |
1482 | "Configuration specifies invalid value for option `%s' in section `%s': %s\n"), | 1484 | "Configuration specifies invalid value for option `%s' in section `%s': %s\n"), |
1483 | option, | 1485 | option, |
1484 | section, | 1486 | section, |
@@ -1493,8 +1495,8 @@ GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, | |||
1493 | * @param old_scope[out] location to save the old scope | 1495 | * @param old_scope[out] location to save the old scope |
1494 | */ | 1496 | */ |
1495 | void | 1497 | void |
1496 | GNUNET_async_scope_enter(const struct GNUNET_AsyncScopeId *aid, | 1498 | GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid, |
1497 | struct GNUNET_AsyncScopeSave *old_scope) | 1499 | struct GNUNET_AsyncScopeSave *old_scope) |
1498 | { | 1500 | { |
1499 | *old_scope = current_async_scope; | 1501 | *old_scope = current_async_scope; |
1500 | current_async_scope.have_scope = GNUNET_YES; | 1502 | current_async_scope.have_scope = GNUNET_YES; |
@@ -1508,7 +1510,7 @@ GNUNET_async_scope_enter(const struct GNUNET_AsyncScopeId *aid, | |||
1508 | * @param old_scope scope to restore | 1510 | * @param old_scope scope to restore |
1509 | */ | 1511 | */ |
1510 | void | 1512 | void |
1511 | GNUNET_async_scope_restore(struct GNUNET_AsyncScopeSave *old_scope) | 1513 | GNUNET_async_scope_restore (struct GNUNET_AsyncScopeSave *old_scope) |
1512 | { | 1514 | { |
1513 | current_async_scope = *old_scope; | 1515 | current_async_scope = *old_scope; |
1514 | } | 1516 | } |
@@ -1520,11 +1522,11 @@ GNUNET_async_scope_restore(struct GNUNET_AsyncScopeSave *old_scope) | |||
1520 | * @param[out] aid_ret pointer to where the result is stored | 1522 | * @param[out] aid_ret pointer to where the result is stored |
1521 | */ | 1523 | */ |
1522 | void | 1524 | void |
1523 | GNUNET_async_scope_fresh(struct GNUNET_AsyncScopeId *aid_ret) | 1525 | GNUNET_async_scope_fresh (struct GNUNET_AsyncScopeId *aid_ret) |
1524 | { | 1526 | { |
1525 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, | 1527 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, |
1526 | aid_ret, | 1528 | aid_ret, |
1527 | sizeof(struct GNUNET_AsyncScopeId)); | 1529 | sizeof(struct GNUNET_AsyncScopeId)); |
1528 | } | 1530 | } |
1529 | 1531 | ||
1530 | 1532 | ||
@@ -1534,7 +1536,7 @@ GNUNET_async_scope_fresh(struct GNUNET_AsyncScopeId *aid_ret) | |||
1534 | * @param[out] scope_ret pointer to where the result is stored | 1536 | * @param[out] scope_ret pointer to where the result is stored |
1535 | */ | 1537 | */ |
1536 | void | 1538 | void |
1537 | GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret) | 1539 | GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret) |
1538 | { | 1540 | { |
1539 | *scope_ret = current_async_scope; | 1541 | *scope_ret = current_async_scope; |
1540 | } | 1542 | } |
@@ -1543,7 +1545,7 @@ GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret) | |||
1543 | /** | 1545 | /** |
1544 | * Initializer | 1546 | * Initializer |
1545 | */ | 1547 | */ |
1546 | void __attribute__ ((constructor)) GNUNET_util_cl_init() | 1548 | void __attribute__ ((constructor)) GNUNET_util_cl_init () |
1547 | { | 1549 | { |
1548 | GNUNET_stderr = stderr; | 1550 | GNUNET_stderr = stderr; |
1549 | } | 1551 | } |
@@ -1552,7 +1554,7 @@ void __attribute__ ((constructor)) GNUNET_util_cl_init() | |||
1552 | /** | 1554 | /** |
1553 | * Destructor | 1555 | * Destructor |
1554 | */ | 1556 | */ |
1555 | void __attribute__ ((destructor)) GNUNET_util_cl_fini() | 1557 | void __attribute__ ((destructor)) GNUNET_util_cl_fini () |
1556 | { | 1558 | { |
1557 | 1559 | ||
1558 | } | 1560 | } |