From a604a6212609e9b809abd09f91e9f60111f25df7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 19 Oct 2011 10:32:24 +0200 Subject: [PATCH] HTTP recording saves both requests and responses --- src/http.c | 17 +++++++++++++++-- src/pazpar2_play.c | 19 ++++++++++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/http.c b/src/http.c index c9cca1d..2df1706 100644 --- a/src/http.c +++ b/src/http.c @@ -889,7 +889,7 @@ static void http_io(IOCHAN i, int event) { struct timeval tv; gettimeofday(&tv, 0); - fprintf(hc->http_server->record_file, "%lld %lld %lld 0\n", + fprintf(hc->http_server->record_file, "r %lld %lld %lld 0\n", (long long) tv.tv_sec, (long long) tv.tv_usec, (long long) iochan_getfd(i)); } @@ -921,7 +921,7 @@ static void http_io(IOCHAN i, int event) for (hb = hc->iqueue; hb; hb = hb->next) sz += hb->len; gettimeofday(&tv, 0); - fprintf(hc->http_server->record_file, "%lld %lld %lld %d\n", + fprintf(hc->http_server->record_file, "r %lld %lld %lld %d\n", (long long) tv.tv_sec, (long long) tv.tv_usec, (long long) iochan_getfd(i), sz); for (hb = hc->iqueue; hb; hb = hb->next) @@ -968,6 +968,19 @@ static void http_io(IOCHAN i, int event) } if (res == wb->len) { +#if HAVE_SYS_TIME_H + if (hc->http_server->record_file) + { + struct timeval tv; + int sz = wb->offset + wb->len; + gettimeofday(&tv, 0); + fprintf(hc->http_server->record_file, "w %lld %lld %lld %d\n", + (long long) tv.tv_sec, (long long) tv.tv_usec, + (long long) iochan_getfd(i), sz); + fwrite(wb->buf, 1, wb->offset + wb->len, + hc->http_server->record_file); + } + #endif hc->oqueue = hc->oqueue->next; http_buf_destroy(hc->http_server, wb); } diff --git a/src/pazpar2_play.c b/src/pazpar2_play.c index 622885a..5339f2d 100644 --- a/src/pazpar2_play.c +++ b/src/pazpar2_play.c @@ -54,6 +54,7 @@ static int run(FILE *inf, struct addrinfo *res) long long id; int sz, r, c; char req[100]; + char request_type[100]; size_t i; struct con **conp; c = fgetc(inf); @@ -66,8 +67,9 @@ static int run(FILE *inf, struct addrinfo *res) c = fgetc(inf); } req[i] = 0; - r = sscanf(req, "%lld %lld %lld %d", &tv_sec1, &tv_usec1, &id, &sz); - if (r != 4) + r = sscanf(req, "%s %lld %lld %lld %d", request_type, + &tv_sec1, &tv_usec1, &id, &sz); + if (r != 5) { fprintf(stderr, "bad line %s\n", req); return -1; @@ -145,11 +147,14 @@ static int run(FILE *inf, struct addrinfo *res) (long long) toread, (long long) r); return -1; } - w = write((*conp)->fd, buf, toread); - if (w != toread) - { - fprintf(stderr, "write truncated\n"); - return -1; + if (*request_type == 'r') + { /* Only deal with things tha Pazpar2 received */ + w = write((*conp)->fd, buf, toread); + if (w != toread) + { + fprintf(stderr, "write truncated\n"); + return -1; + } } cnt += toread; } -- 1.7.10.4