root/src/noit_http.h

Revision 21b0c6c1011f78327925b8a1914d98cdd5cd43d5, 3.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 years ago)

first whack at feeding actual data. refs #71

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #ifndef _NOIT_HTTP_H
7 #define _NOIT_HTTP_H
8
9 #include "noit_defines.h"
10 #include "eventer/eventer.h"
11 #include "utils/noit_hash.h"
12 #include "utils/noit_atomic.h"
13
14 typedef enum {
15   NOIT_HTTP_OTHER, NOIT_HTTP_GET, NOIT_HTTP_HEAD
16 } noit_http_method;
17 typedef enum {
18   NOIT_HTTP09, NOIT_HTTP10, NOIT_HTTP11
19 } noit_http_protocol;
20
21 #define NOIT_HTTP_CHUNKED 0x0001
22 #define NOIT_HTTP_CLOSE   0x0002
23 #define NOIT_HTTP_GZIP    0x0010
24 #define NOIT_HTTP_DEFLATE 0x0020
25
26 #define DEFAULT_BCHAINSIZE ((1 << 15)-(3*sizeof(size_t))-(2*sizeof(void *)))
27 /* 64k - delta */
28 #define DEFAULT_BCHAINMINREAD (DEFAULT_BCHAINSIZE/4)
29
30 struct bchain {
31   struct bchain *next, *prev;
32   size_t start; /* where data starts (buff + start) */
33   size_t size;  /* data length (past start) */
34   size_t allocd;/* total allocation */
35   char buff[1]; /* over allocate as needed */
36 };
37
38 #define BCHAIN_SPACE(a) ((a)->allocd - (a)->size - (a)->start)
39
40 API_EXPORT(struct bchain *) bchain_alloc(size_t size);
41 API_EXPORT(void) bchain_free(struct bchain *);
42
43 typedef struct {
44   eventer_t e;
45   int needs_close;
46 } noit_http_connection;
47
48 typedef struct {
49   struct bchain *first_input; /* The start of the input chain */
50   struct bchain *last_input;  /* The end of the input chain */
51   struct bchain *current_input;  /* The point of the input where we */
52   size_t         current_offset; /* analyzing. */
53
54   struct bchain *current_request_chain;
55   char *method_str;
56   char *uri_str;
57   char *protocol_str;
58   u_int32_t opts;
59   noit_http_method method;
60   noit_http_protocol protocol;
61   noit_hash_table headers;
62   noit_boolean complete;
63 } noit_http_request;
64
65 typedef struct {
66   noit_http_protocol protocol;
67   int status_code;
68   char *status_reason;
69
70   noit_hash_table headers;
71   struct bchain *leader; /* serialization of status line and headers */
72
73   u_int32_t output_options;
74   struct bchain *output;       /* data is pushed in here */
75   struct bchain *output_raw;   /* internally transcoded here for output */
76   size_t output_raw_offset;    /* tracks our offset */
77   noit_boolean output_started; /* locks the options and leader */
78                                /*   and possibly output. */
79   noit_boolean closed;         /* set by _end() */
80   noit_boolean complete;       /* complete, drained and disposable */
81 } noit_http_response;
82
83 struct noit_http_session_ctx;
84 typedef int (*noit_http_dispatch_func) (struct noit_http_session_ctx *);
85
86 typedef struct noit_http_session_ctx {
87   noit_atomic32_t ref_cnt;
88   noit_http_connection conn;
89   noit_http_request req;
90   noit_http_response res;
91   noit_http_dispatch_func dispatcher;
92   void *dispatcher_closure;
93   eventer_func_t drive;
94 } noit_http_session_ctx;
95
96 API_EXPORT(noit_http_session_ctx *)
97   noit_http_session_ctx_new(noit_http_dispatch_func, void *, eventer_t);
98 API_EXPORT(void)
99   noit_http_session_ctx_release(noit_http_session_ctx *);
100
101 API_EXPORT(int)
102   noit_http_session_drive(eventer_t, int, void *, struct timeval *);
103
104 API_EXPORT(noit_boolean)
105   noit_http_response_status_set(noit_http_session_ctx *, int, const char *);
106 API_EXPORT(noit_boolean)
107   noit_http_response_header_set(noit_http_session_ctx *,
108                                 const char *, const char *);
109 API_EXPORT(noit_boolean)
110   noit_http_response_option_set(noit_http_session_ctx *, u_int32_t);
111 API_EXPORT(noit_boolean)
112   noit_http_response_append(noit_http_session_ctx *, const void *, size_t);
113 API_EXPORT(noit_boolean)
114   noit_http_response_append_bchain(noit_http_session_ctx *, struct bchain *);
115 API_EXPORT(noit_boolean)
116   noit_http_response_flush(noit_http_session_ctx *, noit_boolean);
117 API_EXPORT(noit_boolean) noit_http_response_end(noit_http_session_ctx *);
118
119 #endif
Note: See TracBrowser for help on using the browser.