Changeset 3c56016c44ec467d9baa6ed0d667e21bf44f81cb

Show
Ignore:
Timestamp:
09/23/09 00:22:56 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1253665376 +0000
git-parent:

[75ee62d07972a0eb07cde464b4d2244abd0b06ec]

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

insert the new rest API as a shim between the http listener and the realtime streamer -- for future extensibility

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/Makefile.in

    r75ee62d r3c56016  
    4646        noit_console.o noit_console_state.o noit_console_telnet.o \ 
    4747        noit_console_complete.o noit_xml.o \ 
    48         noit_conf.o noit_http.o noit_tokenizer.o \ 
     48        noit_conf.o noit_http.o noit_rest.o noit_tokenizer.o \ 
    4949        stratcon_realtime_http.o \ 
    5050        stratcon_jlog_streamer.o stratcon_datastore.o \ 
  • src/noit_rest.c

    r75ee62d r3c56016  
    173173  restc->fastpath = NULL; 
    174174} 
    175 static void 
     175void 
    176176noit_http_rest_closure_free(noit_http_rest_closure_t *restc) { 
    177177  free(restc->remote_cn); 
     
    218218    const char *primer = ""; 
    219219    ac->service_ctx = restc = noit_http_rest_closure_alloc(); 
     220    restc->ac = ac; 
    220221    restc->remote_cn = strdup(ac->remote_cn ? ac->remote_cn : ""); 
    221222    restc->http_ctx = 
     
    243244    } 
    244245    noit_http_session_prime_input(restc->http_ctx, primer, 4); 
     246  } 
     247  return restc->http_ctx->drive(e, mask, restc->http_ctx, now); 
     248} 
     249 
     250int 
     251noit_http_rest_raw_handler(eventer_t e, int mask, void *closure, 
     252                           struct timeval *now) { 
     253  int newmask = EVENTER_READ | EVENTER_EXCEPTION; 
     254  acceptor_closure_t *ac = closure; 
     255  noit_http_rest_closure_t *restc = ac->service_ctx; 
     256 
     257  if(mask & EVENTER_EXCEPTION || (restc && restc->wants_shutdown)) { 
     258    /* Exceptions cause us to simply snip the connection */ 
     259    eventer_remove_fd(e->fd); 
     260    e->opset->close(e->fd, &newmask, e); 
     261    if(restc) noit_http_rest_closure_free(restc); 
     262    if(ac) acceptor_closure_free(ac); 
     263    return 0; 
     264  } 
     265  if(!ac->service_ctx) { 
     266    ac->service_ctx = restc = noit_http_rest_closure_alloc(); 
     267    restc->ac = ac; 
     268    restc->http_ctx = 
     269        noit_http_session_ctx_new(noit_rest_request_dispatcher, 
     270                                  restc, e); 
    245271  } 
    246272  return restc->http_ctx->drive(e, mask, restc->http_ctx, now); 
     
    296322} 
    297323void noit_http_rest_init() { 
    298   eventer_name_callback("http_rest_api/1.0", noit_http_rest_handler); 
     324  eventer_name_callback("noit_wite_rest_api/1.0", noit_http_rest_handler); 
     325  eventer_name_callback("http_rest_api", noit_http_rest_raw_handler); 
    299326  noit_control_dispatch_delegate(noit_control_dispatch, 
    300327                                 NOIT_CONTROL_DELETE, 
  • src/noit_rest.h

    r75ee62d r3c56016  
    5151struct noit_http_rest_closure { 
    5252  noit_http_session_ctx *http_ctx; 
     53  acceptor_closure_t *ac; 
    5354  char *remote_cn; 
    5455  rest_request_handler fastpath; 
     
    7071                      int *mask, int *complete) ; 
    7172 
     73API_EXPORT(void) 
     74  noit_http_rest_closure_free(noit_http_rest_closure_t *restc); 
     75 
    7276#endif 
  • src/stratcon_realtime_http.c

    rbe29b6f r3c56016  
    4040#include "noit_listener.h" 
    4141#include "noit_http.h" 
     42#include "noit_rest.h" 
    4243#include "noit_livestream_listener.h" 
    4344#include "stratcon_realtime_http.h" 
     
    438439  return EVENTER_EXCEPTION; 
    439440} 
    440  
    441441int 
    442442stratcon_realtime_http_handler(eventer_t e, int mask, void *closure, 
     
    444444  acceptor_closure_t *ac = closure; 
    445445  noit_http_session_ctx *http_ctx = ac->service_ctx; 
    446   if(!http_ctx) { 
    447     const char *document_domain = NULL; 
    448  
    449     if(!noit_hash_retr_str(ac->config, 
    450                            "document_domain", strlen("document_domain"), 
    451                            &document_domain)) { 
    452       noitL(noit_error, "Document domain not set!  Realtime streaming will be broken\n"); 
    453       document_domain = ""; 
    454     } 
    455  
    456     http_ctx = ac->service_ctx = 
    457       noit_http_session_ctx_new(stratcon_request_dispatcher, 
    458                                 alloc_realtime_context(document_domain), 
    459                                 e); 
    460   } 
    461446  return http_ctx->drive(e, mask, http_ctx, now); 
     447} 
     448static int 
     449rest_stream_data(noit_http_rest_closure_t *restc, 
     450                 int npats, char **pats) { 
     451  /* We're here and want to subvert the rest system */ 
     452  const char *document_domain = NULL; 
     453  noit_http_session_ctx *ctx = restc->http_ctx; 
     454 
     455  /* Rewire the handler */ 
     456  restc->ac->service_ctx = ctx; 
     457 
     458  if(!noit_hash_retr_str(restc->ac->config, 
     459                         "document_domain", strlen("document_domain"), 
     460                         &document_domain)) { 
     461    noitL(noit_error, "Document domain not set!  Realtime streaming will be broken\n"); 
     462    document_domain = ""; 
     463  } 
     464  noit_http_rest_closure_free(restc); 
     465 
     466  /* Rewire the http context */ 
     467  ctx->conn.e->callback = stratcon_realtime_http_handler; 
     468  ctx->dispatcher = stratcon_request_dispatcher; 
     469  ctx->dispatcher_closure = alloc_realtime_context(document_domain); 
     470  //ctx->drive = stratcon_realtime_http_handler; 
     471  return stratcon_request_dispatcher(ctx); 
    462472} 
    463473 
     
    466476  eventer_name_callback("stratcon_realtime_http", 
    467477                        stratcon_realtime_http_handler); 
    468 
     478  assert(noit_http_rest_register( 
     479    "GET", "/data/", "^((?:\\d+(?:@\\d+)?)(?:/\\d+(?:@\\d+)?)*)$", 
     480    rest_stream_data 
     481  ) == 0); 
     482
  • src/stratcond.c

    rb9a4230 r3c56016  
    4949#include "noit_module.h" 
    5050#include "noit_conf.h" 
     51#include "noit_rest.h" 
    5152#include "stratcon_jlog_streamer.h" 
    5253#include "stratcon_datastore.h" 
     
    170171 
    171172  noit_console_init(APPNAME); 
     173  noit_http_rest_init(); 
    172174  stratcon_realtime_http_init(APPNAME); 
    173175  noit_listener_init(APPNAME);