| 840 | } |
| 841 | |
| 842 | void |
| 843 | TSPluginInit(int argc, const char *argv[]) |
| 844 | { |
| 845 | Dbg(dbg_ctl, "initializing plugin"); |
| 846 | |
| 847 | static const struct option longopt[] = { |
| 848 | {const_cast<char *>("header"), required_argument, nullptr, 'h' }, |
| 849 | {const_cast<char *>("enable"), required_argument, nullptr, 'e' }, |
| 850 | {nullptr, no_argument, nullptr, '\0'} |
| 851 | }; |
| 852 | TSPluginRegistrationInfo info; |
| 853 | |
| 854 | info.plugin_name = (char *)"xdebug"; |
| 855 | info.vendor_name = (char *)"Apache Software Foundation"; |
| 856 | info.support_email = (char *)"dev@trafficserver.apache.org"; |
| 857 | |
| 858 | if (TSPluginRegister(&info) != TS_SUCCESS) { |
| 859 | TSError("[xdebug] Plugin registration failed"); |
| 860 | } |
| 861 | |
| 862 | // Parse the arguments |
| 863 | while (true) { |
| 864 | int opt = getopt_long(argc, const_cast<char *const *>(argv), "", longopt, nullptr); |
| 865 | |
| 866 | switch (opt) { |
| 867 | case 'h': |
| 868 | Dbg(dbg_ctl, "Setting header: %s", optarg); |
| 869 | xDebugHeader.str = TSstrdup(optarg); |
| 870 | break; |
| 871 | case 'e': |
| 872 | updateAllowedHeaders(optarg); |
| 873 | break; |
| 874 | } |
| 875 | |
| 876 | if (opt == -1) { |
| 877 | break; |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | if (allowedHeaders == 0) { |
| 882 | TSError("[xdebug] No features are enabled"); |
| 883 | } |
| 884 | |
| 885 | if (nullptr == xDebugHeader.str) { |
| 886 | xDebugHeader.str = TSstrdup("X-Debug"); // We malloc this, for consistency for future plugin unload events |
| 887 | } |
| 888 | xDebugHeader.len = strlen(xDebugHeader.str); |
| 889 | |
| 890 | // Make xDebugHeader available to other plugins, as a C-style string. |
| 891 | // |
| 892 | int idx = -1; |
| 893 | auto ret = TSUserArgIndexReserve(TS_USER_ARGS_GLB, "XDebugHeader", "XDebug header name", &idx); |
| 894 | TSReleaseAssert(ret == TS_SUCCESS); |
| 895 | TSReleaseAssert(idx >= 0); |
| 896 | TSUserArgSet(nullptr, idx, const_cast<char *>(xDebugHeader.str)); |
| 897 | |
| 898 | AuxDataMgr::init("xdebug"); |
| 899 |
nothing calls this directly
no test coverage detected