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#include "webserver_debug.h"
17
18enum http_state {
19    HTTP_STATE_CLOSED,              // dead connection
20    HTTP_STATE_NEW,                 // new connection
21    HTTP_STATE_REQUEST,             // receiving request
22    HTTP_STATE_SENDHEADER,          // sending reply header
23    HTTP_STATE_SENDFILE,            // sending file
24    HTTP_STATE_CLOSING,             // closing connection
25    HTTP_STATE_BACKEND_BUSY         // backend busy
26};
27
28
29struct buff_holder {
30    long                r_counter;   /* reference counter */
31    void                *data;      /* cached data (file-contents) */
32    size_t              len;        /* length of data */
33};
34
35struct http_conn {
36    int                 request_no;
37    enum http_state     state;
38    /* request data and length (on heap) */
39    char                *request;
40    size_t              request_length;
41    /* reply header, position and length (static) */
42    const char          *header;
43    size_t              header_pos, header_length, header_sent;
44
45    struct buff_holder  *hbuff;      /* reply buffer holder */
46    size_t              reply_pos;  /* amount of data sent from reply */
47    size_t              reply_sent;
48
49    // Time taken to send reply
50    uint64_t            start_ts;
51    /* number of send retries */
52    int                 retries;
53    int                 error; /*flag for internal errors */
54    char                *filename;     /* name of the requested file */
55    struct net_socket   *pcb;
56    void (*callback) (struct http_conn *);
57    int                 mark_invalid;     /* is it marked for delete? */
58    long                ref_count;
59    struct http_conn    *next;     /* for making the linked list */
60};
61
62
63errval_t http_fetch_file(const char *name, struct http_conn *cs);
64long decrement_http_conn_reference (struct http_conn *cs);
65long increment_http_conn_reference (struct http_conn *cs);
66#endif // WEBSERVER_SESSION_H
67