void TSPluginInit(int argc, const char *argv[]) { const char prefix[] = "http://"; int uri_len; TSPluginRegistrationInfo info; info.plugin_name = "redirect-1"; info.vendor_name = "MyCompany"; info.support_email = "*****@*****.**"; if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) { TSError("Plugin registration failed.\n"); } if (!check_ts_version()) { TSError("Plugin requires Traffic Server 3.0 or later\n"); return; } if (argc == 3) { block_ip = TSstrdup(argv[1]); /* * The Location header must contain an absolute URI: */ url_redirect = TSstrdup(argv[2]); uri_len = strlen(prefix) + strlen(url_redirect) + 1; uri_redirect = TSmalloc(uri_len); TSstrlcpy(uri_redirect, prefix, uri_len); TSstrlcat(uri_redirect, url_redirect, uri_len); } else { TSError("Incorrect syntax in plugin.conf: correct usage is" "redirect-1.so ip_deny url_redirect"); return; } ip_deny = inet_addr(block_ip); TSDebug("redirect_init", "initializing stats..."); init_stats(); TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(redirect_plugin, NULL)); TSDebug("redirect_init", "block_ip is %s, url_redirect is %s, and uri_redirect is %s", block_ip, url_redirect, uri_redirect); // ToDo: Should figure out how to print IPs which are IPv4 / v6. // TSDebug("redirect_init", "ip_deny is %ld\n", ip_deny); /* * Demonstrate another tracing function. This can be used to * enable debug calculations and other work that should only * be done in debug mode. */ if (TSIsDebugTagSet("redirect_demo")) TSDebug("redirect_init", "The redirect_demo tag is set"); else TSDebug("redirect_init", "The redirect_demo tag is not set"); }
void TSPluginInit(int argc, const char *argv[]) { const char prefix[] = "http://"; int uri_len; TSPluginRegistrationInfo info; info.plugin_name = PLUGIN_NAME; info.vendor_name = "Apache Software Foundation"; info.support_email = "*****@*****.**"; if (TSPluginRegister(&info) != TS_SUCCESS) { TSError("[%s] Plugin registration failed", PLUGIN_NAME); } if (argc == 3) { block_ip = TSstrdup(argv[1]); /* * The Location header must contain an absolute URI: */ url_redirect = TSstrdup(argv[2]); uri_len = strlen(prefix) + strlen(url_redirect) + 1; uri_redirect = TSmalloc(uri_len); TSstrlcpy(uri_redirect, prefix, uri_len); TSstrlcat(uri_redirect, url_redirect, uri_len); } else { TSError("[%s] Incorrect syntax in plugin.conf: correct usage is", PLUGIN_NAME "redirect_1.so ip_deny url_redirect"); return; } ip_deny = inet_addr(block_ip); TSDebug(PLUGIN_NAME, "initializing stats"); init_stats(); TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(redirect_plugin, NULL)); TSDebug(PLUGIN_NAME ".init", "block_ip is %s, url_redirect is %s, and uri_redirect is %s", block_ip, url_redirect, uri_redirect); /* * Demonstrate another tracing function. This can be used to * enable debug calculations and other work that should only * be done in debug mode. */ if (TSIsDebugTagSet(PLUGIN_NAME ".demo")) { TSDebug(PLUGIN_NAME ".init", "The redirect_demo tag is set"); } else { TSDebug(PLUGIN_NAME ".init", "The redirect_demo tag is not set"); } }