Changeset 3c56016c44ec467d9baa6ed0d667e21bf44f81cb
- Timestamp:
- 09/23/09 00:22:56
(4 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
| r75ee62d |
r3c56016 |
|
| 46 | 46 | noit_console.o noit_console_state.o noit_console_telnet.o \ |
|---|
| 47 | 47 | 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 \ |
|---|
| 49 | 49 | stratcon_realtime_http.o \ |
|---|
| 50 | 50 | stratcon_jlog_streamer.o stratcon_datastore.o \ |
|---|
| r75ee62d |
r3c56016 |
|
| 173 | 173 | restc->fastpath = NULL; |
|---|
| 174 | 174 | } |
|---|
| 175 | | static void |
|---|
| | 175 | void |
|---|
| 176 | 176 | noit_http_rest_closure_free(noit_http_rest_closure_t *restc) { |
|---|
| 177 | 177 | free(restc->remote_cn); |
|---|
| … | … | |
| 218 | 218 | const char *primer = ""; |
|---|
| 219 | 219 | ac->service_ctx = restc = noit_http_rest_closure_alloc(); |
|---|
| | 220 | restc->ac = ac; |
|---|
| 220 | 221 | restc->remote_cn = strdup(ac->remote_cn ? ac->remote_cn : ""); |
|---|
| 221 | 222 | restc->http_ctx = |
|---|
| … | … | |
| 243 | 244 | } |
|---|
| 244 | 245 | 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 | |
|---|
| | 250 | int |
|---|
| | 251 | noit_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); |
|---|
| 245 | 271 | } |
|---|
| 246 | 272 | return restc->http_ctx->drive(e, mask, restc->http_ctx, now); |
|---|
| … | … | |
| 296 | 322 | } |
|---|
| 297 | 323 | void 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); |
|---|
| 299 | 326 | noit_control_dispatch_delegate(noit_control_dispatch, |
|---|
| 300 | 327 | NOIT_CONTROL_DELETE, |
|---|
| r75ee62d |
r3c56016 |
|
| 51 | 51 | struct noit_http_rest_closure { |
|---|
| 52 | 52 | noit_http_session_ctx *http_ctx; |
|---|
| | 53 | acceptor_closure_t *ac; |
|---|
| 53 | 54 | char *remote_cn; |
|---|
| 54 | 55 | rest_request_handler fastpath; |
|---|
| … | … | |
| 70 | 71 | int *mask, int *complete) ; |
|---|
| 71 | 72 | |
|---|
| | 73 | API_EXPORT(void) |
|---|
| | 74 | noit_http_rest_closure_free(noit_http_rest_closure_t *restc); |
|---|
| | 75 | |
|---|
| 72 | 76 | #endif |
|---|
| rbe29b6f |
r3c56016 |
|
| 40 | 40 | #include "noit_listener.h" |
|---|
| 41 | 41 | #include "noit_http.h" |
|---|
| | 42 | #include "noit_rest.h" |
|---|
| 42 | 43 | #include "noit_livestream_listener.h" |
|---|
| 43 | 44 | #include "stratcon_realtime_http.h" |
|---|
| … | … | |
| 438 | 439 | return EVENTER_EXCEPTION; |
|---|
| 439 | 440 | } |
|---|
| 440 | | |
|---|
| 441 | 441 | int |
|---|
| 442 | 442 | stratcon_realtime_http_handler(eventer_t e, int mask, void *closure, |
|---|
| … | … | |
| 444 | 444 | acceptor_closure_t *ac = closure; |
|---|
| 445 | 445 | 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 | | } |
|---|
| 461 | 446 | return http_ctx->drive(e, mask, http_ctx, now); |
|---|
| | 447 | } |
|---|
| | 448 | static int |
|---|
| | 449 | rest_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); |
|---|
| 462 | 472 | } |
|---|
| 463 | 473 | |
|---|
| … | … | |
| 466 | 476 | eventer_name_callback("stratcon_realtime_http", |
|---|
| 467 | 477 | 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 | } |
|---|
| rb9a4230 |
r3c56016 |
|
| 49 | 49 | #include "noit_module.h" |
|---|
| 50 | 50 | #include "noit_conf.h" |
|---|
| | 51 | #include "noit_rest.h" |
|---|
| 51 | 52 | #include "stratcon_jlog_streamer.h" |
|---|
| 52 | 53 | #include "stratcon_datastore.h" |
|---|
| … | … | |
| 170 | 171 | |
|---|
| 171 | 172 | noit_console_init(APPNAME); |
|---|
| | 173 | noit_http_rest_init(); |
|---|
| 172 | 174 | stratcon_realtime_http_init(APPNAME); |
|---|
| 173 | 175 | noit_listener_init(APPNAME); |
|---|