This is the global continuation, used to deal with various hooks as well as setting up a per TXN continuation if needed. ToDo: Other non-TXN hooks should be added here.
| 633 | // This is the global continuation, used to deal with various hooks as well as setting up |
| 634 | // a per TXN continuation if needed. ToDo: Other non-TXN hooks should be added here. |
| 635 | int |
| 636 | global_cont(TSCont contp, TSEvent event, void *edata) |
| 637 | { |
| 638 | // Duplicated, but this is cheap and we don't need it in the instance. |
| 639 | static bool has_glb_txn_start = wrap_glb_txn_start(static_cast<cripts::Context *>(nullptr), false, CaseArg); |
| 640 | |
| 641 | auto glb_ctx = static_cast<cripts::InstanceContext *>(TSContDataGet(contp)); |
| 642 | auto txnp = static_cast<TSHttpTxn>(edata); |
| 643 | auto ssnp = TSHttpTxnSsnGet(txnp); |
| 644 | auto enabled_hooks = glb_ctx->p_instance.Callbacks(); |
| 645 | |
| 646 | switch (event) { |
| 647 | case TS_EVENT_HTTP_TXN_START: { |
| 648 | auto *context = cripts::Context::Factory(txnp, ssnp, nullptr, glb_ctx->p_instance); |
| 649 | |
| 650 | context->state.hook = TS_HTTP_TXN_START_HOOK; |
| 651 | context->state.enabled_hooks = enabled_hooks; |
| 652 | |
| 653 | if (has_glb_txn_start) { |
| 654 | wrap_glb_txn_start(context, true, CaseArg); |
| 655 | } |
| 656 | |
| 657 | if (enabled_hooks) { |
| 658 | context->contp = TSContCreate(http_txn_cont, nullptr); |
| 659 | TSContDataSet(context->contp, context); |
| 660 | if (enabled_hooks & cripts::Callbacks::GLB_READ_REQUEST) { |
| 661 | TSHttpTxnHookAdd(txnp, TS_HTTP_READ_REQUEST_HDR_HOOK, context->contp); |
| 662 | } |
| 663 | if (enabled_hooks & cripts::Callbacks::GLB_PRE_REMAP) { |
| 664 | TSHttpTxnHookAdd(txnp, TS_HTTP_PRE_REMAP_HOOK, context->contp); |
| 665 | } |
| 666 | if (enabled_hooks & cripts::Callbacks::GLB_POST_REMAP) { |
| 667 | TSHttpTxnHookAdd(txnp, TS_HTTP_POST_REMAP_HOOK, context->contp); |
| 668 | } |
| 669 | if (enabled_hooks & cripts::Callbacks::GLB_CACHE_LOOKUP) { |
| 670 | TSHttpTxnHookAdd(txnp, TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, context->contp); |
| 671 | } |
| 672 | if (enabled_hooks & cripts::Callbacks::GLB_SEND_REQUEST) { |
| 673 | TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_REQUEST_HDR_HOOK, context->contp); |
| 674 | } |
| 675 | if (enabled_hooks & cripts::Callbacks::GLB_READ_RESPONSE) { |
| 676 | TSHttpTxnHookAdd(txnp, TS_HTTP_READ_RESPONSE_HDR_HOOK, context->contp); |
| 677 | } |
| 678 | if (enabled_hooks & cripts::Callbacks::GLB_SEND_RESPONSE) { |
| 679 | TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_RESPONSE_HDR_HOOK, context->contp); |
| 680 | } |
| 681 | TSHttpTxnHookAdd(txnp, TS_HTTP_TXN_CLOSE_HOOK, context->contp); // Release the context later |
| 682 | } else { |
| 683 | context->Release(); |
| 684 | } |
| 685 | } break; |
| 686 | |
| 687 | // ToDo: Add handlers for other non-HTTP hooks here. |
| 688 | |
| 689 | default: |
| 690 | CFatal("Cripts continuation: Unknown event %d", event); |
| 691 | break; |
| 692 | } |
nothing calls this directly
no test coverage detected