1/*
2 * Copyright (c) 2007, 2008, 2011, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#ifndef WEBSERVER_SESSION_H
11#define WEBSERVER_SESSION_H
12
13
14#include <nfs/nfs.h>
15
16//#define DEBUGWS 1
17
18#ifdef DEBUGWS
19#define DEBUGPRINT(arg...) printf(arg)
20#else
21#define DEBUGPRINT(arg...) ((void)0)
22#endif /* DEBUGWS */
23
24enum http_state {
25    HTTP_STATE_CLOSED,              // dead connection
26    HTTP_STATE_NEW,                 // new connection
27    HTTP_STATE_REQUEST,             // receiving request
28    HTTP_STATE_SENDHEADER,          // sending reply header
29    HTTP_STATE_SENDFILE,            // sending file
30    HTTP_STATE_CLOSING,             // closing connection
31    HTTP_STATE_BACKEND_BUSY         // backend busy
32};
33
34
35struct buff_holder {
36    long                r_counter;   /* reference counter */
37    void                *data;      /* cached data (file-contents) */
38    size_t              len;        /* length of data */
39};
40
41struct http_conn {
42    int                 request_no;
43    enum http_state     state;
44    /* request data and length (on heap) */
45    char                *request;
46    size_t              request_length;
47    /* reply header, position and length (static) */
48    const char          *header;
49    size_t              header_pos, header_length;
50
51    struct buff_holder  *hbuff;      /* reply buffer holder */
52    size_t              reply_pos;  /* amount of data sent from reply */
53
54    // Time taken to send reply
55    uint64_t            start_ts;
56    /* number of send retries */
57    int                 retries;
58    int                 error; /*flag for internal errors */
59    char                *filename;     /* name of the requested file */
60    struct tcp_pcb      *pcb;
61    void (*callback) (struct http_conn *);
62    int                 mark_invalid;     /* is it marked for delete? */
63    long                ref_count;
64    struct http_conn    *next;     /* for making the linked list */
65};
66
67
68err_t http_fetch_file(const char *name, struct http_conn *cs);
69long decrement_http_conn_reference (struct http_conn *cs);
70long increment_http_conn_reference (struct http_conn *cs);
71#endif // WEBSERVER_SESSION_H
72