diff --git a/src/ChangeLog b/src/ChangeLog index a97437ad..d13fbc79 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2014-11-24 Tim Ruehsen + + * warc.c, warc.h, http.c: Add size of buffer to warc_timestamp() + 2014-11-24 Tim Ruehsen * wget.h, test.c, main.c: Make program_name and program_argstring const diff --git a/src/http.c b/src/http.c index 87ceffd5..073d694b 100644 --- a/src/http.c +++ b/src/http.c @@ -2191,8 +2191,9 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy, if (warc_enabled) { bool warc_result; + /* Generate a timestamp and uuid for this request. */ - warc_timestamp (warc_timestamp_str); + warc_timestamp (warc_timestamp_str, sizeof(warc_timestamp_str)); warc_uuid_str (warc_request_uuid); /* Create a request record and store it in the WARC file. */ diff --git a/src/warc.c b/src/warc.c index 581d7294..8da2d74d 100644 --- a/src/warc.c +++ b/src/warc.c @@ -391,12 +391,9 @@ static bool warc_write_date_header (const char *timestamp) { char current_timestamp[21]; - if (timestamp == NULL) - { - warc_timestamp (current_timestamp); - timestamp = current_timestamp; - } - return warc_write_header ("WARC-Date", timestamp); + + return warc_write_header ("WARC-Date", timestamp ? timestamp : + warc_timestamp (current_timestamp, sizeof(current_timestamp))); } /* Writes the WARC-IP-Address header for the given IP to @@ -591,14 +588,16 @@ warc_write_digest_headers (FILE *file, long payload_offset) The UTC time is formatted following ISO 8601, as required for use in the WARC-Date header. The timestamp will be 21 characters long. */ -void -warc_timestamp (char *timestamp) +char * +warc_timestamp (char *timestamp, size_t timestamp_size) { - time_t rawtime; - struct tm * timeinfo; - time ( &rawtime ); - timeinfo = gmtime (&rawtime); - strftime (timestamp, 21, "%Y-%m-%dT%H:%M:%SZ", timeinfo); + time_t rawtime = time (NULL); + struct tm * timeinfo = gmtime (&rawtime); + + if (strftime (timestamp, timestamp_size, "%Y-%m-%dT%H:%M:%SZ", timeinfo) == 0 && timestamp_size > 0) + *timestamp = 0; + + return timestamp; } #if HAVE_LIBUUID || HAVE_UUID_CREATE @@ -672,7 +671,7 @@ warc_write_warcinfo_record (char *filename) warc_current_warcinfo_uuid_str = (char *) malloc (48); warc_uuid_str (warc_current_warcinfo_uuid_str); - warc_timestamp (timestamp); + warc_timestamp (timestamp, sizeof(timestamp)); filename_copy = strdup (filename); filename_basename = strdup (basename (filename_copy)); diff --git a/src/warc.h b/src/warc.h index 45632cb7..25e07b90 100644 --- a/src/warc.h +++ b/src/warc.h @@ -6,9 +6,10 @@ void warc_init (void); void warc_close (void); -void warc_timestamp (char *timestamp); void warc_uuid_str (char *id_str); +char * warc_timestamp (char *timestamp, size_t timestamp_size); + FILE * warc_tempfile (void); bool warc_write_request_record (char *url, char *timestamp_str,