summaryrefslogtreecommitdiff
path: root/src/libdisfluid/disfluid-cache-entry.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libdisfluid/disfluid-cache-entry.h')
-rw-r--r--src/libdisfluid/disfluid-cache-entry.h65
1 files changed, 64 insertions, 1 deletions
diff --git a/src/libdisfluid/disfluid-cache-entry.h b/src/libdisfluid/disfluid-cache-entry.h
index ea76217..eb78a6c 100644
--- a/src/libdisfluid/disfluid-cache-entry.h
+++ b/src/libdisfluid/disfluid-cache-entry.h
@@ -115,6 +115,14 @@ cache_entry_write (const struct disfluid_cache_entry *entry, int fd);
MAYBE_UNUSED static int
cache_entry_fwrite (const struct disfluid_cache_entry *entry, FILE * f);
+MAYBE_UNUSED static int
+cache_entry_describe_request_date (const struct disfluid_cache_entry *entry,
+ char **description);
+
+MAYBE_UNUSED static int
+cache_entry_describe_response_date (const struct disfluid_cache_entry *entry,
+ char **description);
+
# include <assert.h>
# include <flexmember.h>
@@ -198,7 +206,7 @@ cache_entry_init (struct disfluid_cache_entry *entry, size_t max_key,
entry->header_length = 0;
entry->body_length = 0;
char *key = cache_entry_key (entry);
- char *header = cache_entry_key (entry);
+ char *header = cache_entry_header (entry);
*key = '\0';
*header = '\0';
}
@@ -260,14 +268,17 @@ cache_entry_copy (struct disfluid_cache_entry *restrict dest,
{
strcpy (dest_key, src_key);
}
+ dest->key_length = src_key_size;
if (!(src->flags & HEADER_NOT_LOADED))
{
strcpy (dest_header, src_header);
}
+ dest->header_length = src_header_size;
if (!(src->flags & BODY_NOT_LOADED))
{
memcpy (dest_body, src_body, src_body_size);
}
+ dest->body_length = src_body_size;
}
return -flags;
}
@@ -1023,4 +1034,56 @@ cache_entry_fwrite (const struct disfluid_cache_entry *entry, FILE * f)
return cache_entry_save (entry, disfluid_cache_entry_saver_fwrite, f);
}
+static int
+cache_entry_describe_date (const struct timespec *ts, const char *format,
+ char **description)
+{
+ struct tm date;
+ struct tm *result = localtime_r (&(ts->tv_sec), &date);
+ if (result == NULL)
+ {
+ return -1;
+ }
+ char buffer[256];
+ size_t n_buffer = strftime (buffer, sizeof (buffer), "%c", &date);
+ if (n_buffer == 0)
+ {
+ return -1;
+ }
+ if (n_buffer >= sizeof (buffer))
+ {
+ buffer[n_buffer - 1] = '\0';
+ }
+ else
+ {
+ buffer[n_buffer] = '\0';
+ }
+ /* TRANSLATORS: the argument is a date in the preferred format for
+ the locale. */
+ int error = asprintf (description, format, buffer);
+ if (error < 0)
+ {
+ return -2;
+ }
+ return 0;
+}
+
+static int
+cache_entry_describe_request_date (const struct disfluid_cache_entry *entry,
+ char **description)
+{
+ struct timespec ts;
+ cache_entry_get_request_date (entry, &ts);
+ return cache_entry_describe_date (&ts, _("Requested %s"), description);
+}
+
+static int
+cache_entry_describe_response_date (const struct disfluid_cache_entry *entry,
+ char **description)
+{
+ struct timespec ts;
+ cache_entry_get_response_date (entry, &ts);
+ return cache_entry_describe_date (&ts, _("Responded %s"), description);
+}
+
#endif /* DISFLUID_DISFLUID_CACHE_ENTRY_INCLUDED */