X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fcommon_logging.c;h=5b355b2e1d570ee3c8a23382c0762075657e7b41;hb=72c8645af31896829b674b575c5375706f362a30;hp=8734204606058f7539ad3e0cc72fae0f488f0ea8;hpb=4063a80951c4c42a49f3811b81b3b642634dcd31;p=oweals%2Fgnunet.git diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 873420460..5b355b2e1 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -798,7 +798,7 @@ flush_bulk (const char *datestr) char msg[DATE_STR_SIZE + BULK_TRACK_SIZE + 256]; int rev; char *last; - char *ft; + const char *ft; if ((last_bulk_time.abs_value == 0) || (last_bulk_repeat == 0)) return; @@ -814,11 +814,10 @@ flush_bulk (const char *datestr) last[0] = '\0'; } ft = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration - (last_bulk_time)); + (last_bulk_time), GNUNET_YES); snprintf (msg, sizeof (msg), _("Message `%.*s' repeated %u times in the last %s\n"), BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft); - GNUNET_free (ft); if (rev == 1) last[0] = '\n'; output_message (last_bulk_kind, last_bulk_comp, datestr, msg); @@ -843,7 +842,7 @@ GNUNET_log_skip (int n, int check_reset) ok = (0 == skip_log); skip_log = 0; if (check_reset) - GNUNET_assert (ok); + GNUNET_break (ok); } else { @@ -887,11 +886,14 @@ mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message, memset (date, 0, DATE_STR_SIZE); { char buf[size]; + long long offset; #ifdef WINDOWS LARGE_INTEGER pc; time_t timetmp; + offset = GNUNET_TIME_get_offset (); time (&timetmp); + timetmp += offset / 1000; tmptr = localtime (&timetmp); pc.QuadPart = 0; QueryPerformanceCounter (&pc); @@ -910,6 +912,30 @@ mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message, struct timeval timeofday; gettimeofday (&timeofday, NULL); + offset = GNUNET_TIME_get_offset (); + if (offset > 0) + { + timeofday.tv_sec += offset / 1000LL; + timeofday.tv_usec += (offset % 1000LL) * 1000LL; + if (timeofday.tv_usec > 1000000LL) + { + timeofday.tv_usec -= 1000000LL; + timeofday.tv_sec++; + } + } + else + { + timeofday.tv_sec += offset / 1000LL; + if (timeofday.tv_usec > - (offset % 1000LL) * 1000LL) + { + timeofday.tv_usec += (offset % 1000LL) * 1000LL; + } + else + { + timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL; + timeofday.tv_sec--; + } + } tmptr = localtime (&timeofday.tv_sec); if (NULL == tmptr) { @@ -1012,6 +1038,43 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind) } +/** + * Convert a short hash to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param hc the short hash code + * @return string form; will be overwritten by next call to GNUNET_h2s. + */ +const char * +GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc) +{ + static struct GNUNET_CRYPTO_ShortHashAsciiEncoded ret; + + GNUNET_CRYPTO_short_hash_to_enc (hc, &ret); + ret.short_encoding[8] = '\0'; + return (const char *) ret.short_encoding; +} + + +/** + * Convert a short hash to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param hc the short hash code + * @return string form; will be overwritten by next call to GNUNET_h2s_full. + */ +const char * +GNUNET_short_h2s_full (const struct GNUNET_CRYPTO_ShortHashCode * hc) +{ + static struct GNUNET_CRYPTO_ShortHashAsciiEncoded ret; + + GNUNET_CRYPTO_short_hash_to_enc (hc, &ret); + ret.short_encoding[sizeof (ret) - 1] = '\0'; + return (const char *) ret.short_encoding; +} + /** * Convert a hash to a string (for printing debug messages). * This is one of the very few calls in the entire API that is @@ -1143,7 +1206,8 @@ GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen) off = 0; if (un->sun_path[0] == '\0') off++; - snprintf (buf, sizeof (buf), "%s%.*s", (off == 1) ? "@" : "", + memset (buf, 0, sizeof (buf)); + snprintf (buf, sizeof (buf) - 1, "%s%.*s", (off == 1) ? "@" : "", (int) (addrlen - sizeof (sa_family_t) - 1 - off), &un->sun_path[off]); return buf; @@ -1153,6 +1217,45 @@ GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen) } +/** + * Log error message about missing configuration option. + * + * @param kind log level + * @param section section with missing option + * @param option name of missing option + */ +void +GNUNET_log_config_missing (enum GNUNET_ErrorType kind, + const char *section, + const char *option) +{ + GNUNET_log (kind, + _("Configuration fails to specify option `%s' in section `%s'!\n"), + option, + section); +} + + +/** + * Log error message about invalid configuration option value. + * + * @param kind log level + * @param section section with invalid option + * @param option name of invalid option + * @param required what is required that is invalid about the option + */ +void +GNUNET_log_config_invalid (enum GNUNET_ErrorType kind, + const char *section, + const char *option, + const char *required) +{ + GNUNET_log (kind, + _("Configuration specifies invalid value for option `%s' in section `%s': %s\n"), + option, section, required); +} + + /** * Initializer */