+static void http_log_start(struct http_state *s)
+{
+ if (!http_log_dir)
+ return;
+
+ char name[256], stamp[TIMESTAMP_LEN];
+ struct flow *f = s->flow;
+
+ sprintf(name, "%s/%06u-%d.%d.%d.%d:%d-%d.%d.%d.%d:%d", http_log_dir, s->id,
+ IPQUAD(f->saddr), ntohs(f->sport), IPQUAD(f->daddr), ntohs(f->dport));
+ if (!(s->log_file = fopen(name, "w")))
+ die("Unable to create %s: %m", name);
+
+ format_timestamp(stamp, s->req_start_time);
+ fprintf(s->log_file, "; [%s] From %d.%d.%d.%d:%d to %d.%d.%d.%d:%d (req %u)\n",
+ stamp, IPQUAD(f->saddr), ntohs(f->sport), IPQUAD(f->daddr), ntohs(f->dport),
+ s->req_counter + 1);
+}
+
+static void http_log_end(struct http_state *s)
+{
+ if (!s->log_file)
+ return;
+ fclose(s->log_file);
+ s->log_file = NULL;
+}
+
+static void http_log_req_line(struct http_state *s, byte *line)
+{
+ if (s->log_file)
+ fprintf(s->log_file, "> %s\n", line);
+}
+
+static void http_log_resp_line(struct http_state *s, byte *line)
+{
+ if (s->log_file)
+ fprintf(s->log_file, "< %s\n", line);
+}
+
+static void http_log_body(struct http_state *s, byte *data, uns len)
+{
+ if (s->log_file)
+ fwrite(data, len, 1, s->log_file);
+}
+