Show
Ignore:
Timestamp:
01/05/11 02:42:51 (8 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1294195371 +0000
git-parent:

[000581aaa029b35ddf2cf5f65f70c943df0cb405]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1294195371 +0000
Message:

updates... yay! for test suites... all passes, refs #334

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_http.c

    r1e1b047 r6de024f  
    4747#define HEADER_EXPECT "expect" 
    4848 
     49struct noit_http_connection { 
     50  eventer_t e; 
     51  int needs_close; 
     52}; 
     53 
     54struct noit_http_request { 
     55  struct bchain *first_input; /* The start of the input chain */ 
     56  struct bchain *last_input;  /* The end of the input chain */ 
     57  struct bchain *current_input;  /* The point of the input where we */ 
     58  size_t         current_offset; /* analyzing. */ 
     59 
     60  enum { NOIT_HTTP_REQ_HEADERS = 0, 
     61         NOIT_HTTP_REQ_EXPECT, 
     62         NOIT_HTTP_REQ_PAYLOAD } state; 
     63  struct bchain *current_request_chain; 
     64  noit_boolean has_payload; 
     65  int64_t content_length; 
     66  int64_t content_length_read; 
     67  char *method_str; 
     68  char *uri_str; 
     69  char *protocol_str; 
     70  noit_hash_table querystring; 
     71  u_int32_t opts; 
     72  noit_http_method method; 
     73  noit_http_protocol protocol; 
     74  noit_hash_table headers; 
     75  noit_boolean complete; 
     76  struct timeval start_time; 
     77  char *orig_qs; 
     78}; 
     79 
     80struct noit_http_response { 
     81  noit_http_protocol protocol; 
     82  int status_code; 
     83  char *status_reason; 
     84 
     85  noit_hash_table headers; 
     86  struct bchain *leader; /* serialization of status line and headers */ 
     87 
     88  u_int32_t output_options; 
     89  struct bchain *output;       /* data is pushed in here */ 
     90  struct bchain *output_raw;   /* internally transcoded here for output */ 
     91  size_t output_raw_offset;    /* tracks our offset */ 
     92  noit_boolean output_started; /* locks the options and leader */ 
     93                               /*   and possibly output. */ 
     94  noit_boolean closed;         /* set by _end() */ 
     95  noit_boolean complete;       /* complete, drained and disposable */ 
     96  size_t bytes_written;        /* tracks total bytes written */ 
     97}; 
     98 
     99struct noit_http_session_ctx { 
     100  noit_atomic32_t ref_cnt; 
     101  int64_t drainage; 
     102  int max_write; 
     103  noit_http_connection conn; 
     104  noit_http_request req; 
     105  noit_http_response res; 
     106  noit_http_dispatch_func dispatcher; 
     107  void *dispatcher_closure; 
     108  acceptor_closure_t *ac; 
     109}; 
     110 
    49111static noit_log_stream_t http_debug = NULL; 
    50112static noit_log_stream_t http_io = NULL; 
     
    125187  n->size = size; 
    126188  return n; 
     189} 
     190 
     191noit_http_request * 
     192noit_http_session_request(noit_http_session_ctx *ctx) { 
     193  return &ctx->req; 
     194} 
     195noit_http_response * 
     196noit_http_session_response(noit_http_session_ctx *ctx) { 
     197  return &ctx->res; 
     198} 
     199noit_http_connection * 
     200noit_http_session_connection(noit_http_session_ctx *ctx) { 
     201  return &ctx->conn; 
     202} 
     203void 
     204noit_http_session_set_dispatcher(noit_http_session_ctx *ctx, 
     205                                 int (*d)(noit_http_session_ctx *), void *dc) { 
     206  ctx->dispatcher = d; 
     207  ctx->dispatcher_closure = dc; 
     208} 
     209void *noit_http_session_dispatcher_closure(noit_http_session_ctx *ctx) { 
     210  return ctx->dispatcher_closure; 
     211} 
     212void noit_http_session_trigger(noit_http_session_ctx *ctx, int state) { 
     213  if(ctx->conn.e) eventer_trigger(ctx->conn.e, state); 
     214} 
     215uint32_t noit_http_session_ref_cnt(noit_http_session_ctx *ctx) { 
     216  return ctx->ref_cnt; 
     217} 
     218uint32_t noit_http_session_ref_dec(noit_http_session_ctx *ctx) { 
     219  return noit_atomic_dec32(&ctx->ref_cnt); 
     220} 
     221uint32_t noit_http_session_ref_inc(noit_http_session_ctx *ctx) { 
     222  return noit_atomic_inc32(&ctx->ref_cnt); 
     223} 
     224eventer_t noit_http_connection_event(noit_http_connection *conn) { 
     225  return conn->e; 
     226} 
     227const char *noit_http_request_uri_str(noit_http_request *req) { 
     228  return req->uri_str; 
     229} 
     230const char *noit_http_request_method_str(noit_http_request *req) { 
     231  return req->method_str; 
     232} 
     233const char *noit_http_request_protocol_str(noit_http_request *req) { 
     234  return req->protocol_str; 
     235} 
     236size_t noit_http_request_content_length(noit_http_request *req) { 
     237  return req->content_length; 
     238} 
     239const char *noit_http_request_querystring(noit_http_request *req, const char *k) { 
     240  void *vv; 
     241  const char *v = NULL; 
     242  if(noit_hash_retrieve(&req->querystring, k, strlen(k), &vv)) 
     243    v = vv; 
     244  return v; 
     245} 
     246noit_hash_table *noit_http_request_querystring_table(noit_http_request *req) { 
     247  return &req->querystring; 
     248} 
     249noit_hash_table *noit_http_request_headers_table(noit_http_request *req) { 
     250  return &req->headers; 
     251} 
     252noit_boolean noit_http_response_closed(noit_http_response *res) { 
     253  return res->closed; 
    127254} 
    128255