You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2015/06/15 23:31:14 UTC
[2/4] trafficserver git commit: TS-3170 First stab at cleaning out
the mgmt web server stuff TS-3170 Remove all of web2,
implement very basic server
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/mgmt/web2/WebHttpContext.cc
----------------------------------------------------------------------
diff --git a/mgmt/web2/WebHttpContext.cc b/mgmt/web2/WebHttpContext.cc
deleted file mode 100644
index 63a3324..0000000
--- a/mgmt/web2/WebHttpContext.cc
+++ /dev/null
@@ -1,106 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-/************* ***************************
- *
- * WebHttpContext.cc - the http web-ui transaction state
- *
- *
- ****************************************************************************/
-
-#include "ink_config.h"
-#include "WebHttpContext.h"
-
-//-------------------------------------------------------------------------
-// WebHttpContextCreate
-//
-// Wraps a WebHttpContext around a WebHttpConInfo and WebHttpConInfo's
-// internal WebContext. Note that the returned WebHttpContext will
-// keep pointers into the WebHttpConInfo and WebContext structures.
-// Be careful not to delete/free the WebHttpConInfo or WebContext
-// before WebHttpContext is done with them.
-//-------------------------------------------------------------------------
-
-WebHttpContext *
-WebHttpContextCreate(WebHttpConInfo *whci)
-{
- WebHttpContext *whc = (WebHttpContext *)ats_malloc(sizeof(WebHttpContext));
-
- // memset to 0; note strings are zero'd too
- memset(whc, 0, sizeof(WebHttpContext));
-
- whc->request = new httpMessage();
- whc->response_hdr = new httpResponse();
- whc->response_bdy = new textBuffer(8192);
- whc->submit_warn = new textBuffer(256);
- whc->submit_note = new textBuffer(256);
- whc->submit_warn_ht = ink_hash_table_create(InkHashTableKeyType_String);
- whc->submit_note_ht = ink_hash_table_create(InkHashTableKeyType_String);
- whc->si.fd = whci->fd;
-
- // keep pointers into the context passed to us
- whc->client_info = whci->clientInfo;
- whc->default_file = whci->context->defaultFile;
- whc->doc_root = whci->context->docRoot;
- whc->doc_root_len = whci->context->docRootLen;
-
- // set server_state
- if (whci->context == &autoconfContext) {
- whc->server_state |= WEB_HTTP_SERVER_STATE_AUTOCONF;
- }
-
- return whc;
-}
-
-//-------------------------------------------------------------------------
-// WebHttpContextDestroy
-//-------------------------------------------------------------------------
-
-void
-WebHttpContextDestroy(WebHttpContext *whc)
-{
- if (whc) {
- if (whc->request)
- delete (whc->request);
- if (whc->response_hdr)
- delete (whc->response_hdr);
- if (whc->response_bdy)
- delete (whc->response_bdy);
- if (whc->submit_warn)
- delete (whc->submit_warn);
- if (whc->submit_note)
- delete (whc->submit_note);
- if (whc->query_data_ht)
- ink_hash_table_destroy_and_xfree_values(whc->query_data_ht);
- if (whc->post_data_ht)
- ink_hash_table_destroy_and_xfree_values(whc->post_data_ht);
- if (whc->submit_warn_ht)
- ink_hash_table_destroy(whc->submit_warn_ht);
- if (whc->submit_note_ht)
- ink_hash_table_destroy(whc->submit_note_ht);
-
- ats_free(whc->top_level_render_file);
- ats_free(whc->cache_query_result);
- ats_free(whc);
- }
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/mgmt/web2/WebHttpContext.h
----------------------------------------------------------------------
diff --git a/mgmt/web2/WebHttpContext.h b/mgmt/web2/WebHttpContext.h
deleted file mode 100644
index a73a35f..0000000
--- a/mgmt/web2/WebHttpContext.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-/************* ***************************
- *
- * WebHttpContext.h - the http web-ui transaction state
- *
- *
- ****************************************************************************/
-
-#ifndef _WEB_HTTP_CONTEXT_H_
-#define _WEB_HTTP_CONTEXT_H_
-
-#include "ink_hash_table.h"
-#include "TextBuffer.h"
-
-#include "WebGlobals.h"
-#include "mgmtapi.h"
-#include "WebHttpMessage.h"
-#include "WebUtils.h"
-
-struct WebHttpContext {
- uint32_t request_state; // client request state
- uint32_t server_state; // bit-mask of enabled server features
- httpMessage *request; // client request
- httpResponse *response_hdr; // server response headers
- textBuffer *response_bdy; // server repsonse body
- textBuffer *submit_warn; // submit warn text
- textBuffer *submit_note; // submit info text
- InkHashTable *query_data_ht; // client query name/value hash-table
- InkHashTable *post_data_ht; // client POST name/value hash-table
- InkHashTable *submit_warn_ht; // ht of warn submission records
- InkHashTable *submit_note_ht; // ht of info submission records
- sockaddr_in *client_info; // client conection information
- SocketInfo si; // socket information
-
- char *top_level_render_file; // top-level file to render
- char *cache_query_result; // cache inspector query result
-
- const char *default_file; // default file
- const char *doc_root; // document root
- int doc_root_len; // length of doc_root
-};
-
-WebHttpContext *WebHttpContextCreate(WebHttpConInfo *whci);
-void WebHttpContextDestroy(WebHttpContext *whc);
-
-#endif // _WEB_HTTP_CONTEXT_H_
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/mgmt/web2/WebHttpMessage.cc
----------------------------------------------------------------------
diff --git a/mgmt/web2/WebHttpMessage.cc b/mgmt/web2/WebHttpMessage.cc
deleted file mode 100644
index ee16cff..0000000
--- a/mgmt/web2/WebHttpMessage.cc
+++ /dev/null
@@ -1,513 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#include "ink_platform.h"
-#include "ink_defs.h"
-#include "ink_string.h"
-#include "ink_time.h"
-#include "ink_memory.h"
-
-#include "WebUtils.h"
-#include "WebHttpMessage.h"
-#include "TextBuffer.h"
-#include "MIME.h"
-#include "I_Version.h"
-
-/****************************************************************************
- *
- * WebHttpMessage.cc - classes to store information about incoming requests
- * and create hdrs for outgoing requests
- *
- *
- *
- ****************************************************************************/
-
-const char *const httpStatStr[] = {
- "100 Continue\r\n", "101 Switching Protocols\r\n", "200 OK\r\n", "201 Created\r\n", "202 Accepted\r\n",
- "203 Non-Authorative Information\r\n", "204 No Content\r\n", "205 Reset Content\r\n", "206 Partial Content\r\n",
- "300 Multiple Choices\r\n", "301 Moved Permanently\r\n", "302 Moved Temporarily\r\n", "303 See Other\r\n", "304 Not Modified\r\n",
- "305 Use Proxy\r\n", "400 Bad Request\r\n", "401 Unauthorized\r\n", "402 Payment Required\r\n", "403 Forbidden\r\n",
- "404 Not Found\r\n", "500 Internal Server Error\r\n", "501 Not Implemented\r\n", "502 Bad Gateway\r\n",
- "503 Service Unvailable\r\n", "504 Gateway Timeout\r\n", "505 HTTP Version Not Supported\r\n"};
-
-const char *const httpStatCode[] = {"100", "101", "200", "201", "202", "203", "204", "205", "206", "300", "301", "302", "303",
- "304", "305", "400", "401", "402", "403", "404", "500", "501", "502", "503", "504", "505"};
-
-const char *const contentTypeStr[] = {"text/plain", "text/html", "text/css", "text/unknown", "image/gif", "image/jpeg", "image/png",
- "application/java-vm", "application/x-javascript", "application/x-x509-ca-cert",
- "application/x-ns-proxy-autoconfig", "application/zip"};
-
-
-// httpMessage::httpMessage()
-//
-httpMessage::httpMessage()
-{
- method = METHOD_NONE;
- header = NULL;
- body = NULL;
- scheme = SCHEME_NONE;
- file = NULL;
- query = NULL;
- conLen = -1;
- referer = NULL;
- conType_str = NULL;
- authMessage = NULL;
- parser = new Tokenizer(" \t\n\r");
- modificationTime = -1;
- modContentLength = -1;
- client_request = NULL;
-}
-
-void
-httpMessage::getLogInfo(const char **request)
-{
- *request = client_request;
-}
-
-// returns zero if everything was OK or non-zero if
-// the request was malformed
-int
-httpMessage::addRequestLine(char *request)
-{
- const char *method_str;
- const char *scheme_str;
- const char *URI;
- char *tmp;
- int requestLen;
-
- // Make a copy of the string so that we
- // log it later
- client_request = ats_strdup(request);
- requestLen = strlen(client_request);
- if (requestLen > 0 && client_request[requestLen - 1] == '\r') {
- client_request[requestLen - 1] = '\0';
- }
-
- parser->Initialize(request, SHARE_TOKS);
- method_str = (*parser)[0];
- URI = (*parser)[1];
- scheme_str = (*parser)[2];
-
- // Check for an empty request
- if (method_str == NULL) {
- return 1;
- }
- // Determine Method
- if (strcmp(method_str, "GET") == 0) {
- method = METHOD_GET;
- } else if (strcmp(method_str, "POST") == 0) {
- method = METHOD_POST;
- } else if (strcmp(method_str, "HEAD") == 0) {
- method = METHOD_HEAD;
- } else {
- method = METHOD_NONE;
- }
-
- if (URI == NULL) {
- return 1;
- }
- // Get the scheme
- //
- // We only understand HTTP/1.0
- //
- // If a browser asks for HTTP, we send back 1.0
- // If there is no scheme, assume HTTP
- // If there is another scheme, mark it unknown
- //
- if (scheme_str == NULL) {
- scheme = SCHEME_NONE;
- } else {
- if (strncasecmp(scheme_str, "HTTP", 4) == 0) {
- scheme = SCHEME_HTTP;
- } else if (strncasecmp(scheme_str, "SHTTP", 5) == 0) {
- scheme = SCHEME_SHTTP;
- } else {
- scheme = SCHEME_UNKNOWN;
- }
- }
-
- // Now sort out the file verses query portion of the
- // the request
- //
- // First check to see if the client sent us a full URL
- if (strncmp("http://", URI, 7) == 0) {
- URI = strstr(URI + 7, "/");
- if (URI == NULL) {
- return 1;
- }
- }
- // Now allocate space for the document path portion
- // of the URI along with the query if any
- unsigned int amtToAllocate = strlen(URI) + 1;
- file = new char[amtToAllocate];
- ink_strlcpy(file, URI, amtToAllocate + 1);
- tmp = strstr(file, "?");
- if (tmp != NULL) {
- // There is a form submission
- *tmp = '\0';
- query = tmp + 1;
- // Remove trailing "\"
- query[strlen(query)] = '\0';
- }
-
- return 0;
-}
-
-void
-httpMessage::addHeader(char *hdr)
-{
- const char *authType;
- const char *auth;
- int len;
- const char *hdrName;
- const char *hdrArg1;
-
- parser->Initialize(hdr, SHARE_TOKS);
- hdrName = (*parser)[0];
- hdrArg1 = (*parser)[1];
-
- // All headers require at least tokens
- if (hdrName == NULL || hdrArg1 == NULL) {
- return;
- }
-
- if (strncasecmp("Content-length:", hdrName, 15) == 0) {
- conLen = atoi(hdrArg1);
- } else if (strncasecmp("Referer:", hdrName, 8) == 0) {
- unsigned int amtToAllocate = strlen(hdrArg1);
- referer = new char[amtToAllocate + 1];
- ink_strlcpy(referer, hdrArg1, amtToAllocate + 1);
- } else if (strncasecmp("Content-type:", hdrName, 13) == 0) {
- unsigned int amtToAllocate = strlen(hdrArg1);
- conType_str = new char[amtToAllocate + 1];
- ink_strlcpy(conType_str, hdrArg1, amtToAllocate + 1);
- } else if (strncasecmp("Authorization:", hdrName, 14) == 0) {
- authType = hdrArg1;
- if (strcmp(authType, "Basic") == 0) {
- auth = (*parser)[2];
- len = strlen(auth) + 1;
- authMessage = new char[len];
- ink_strlcpy(authMessage, auth, len);
- }
- } else if (strncasecmp("If-Modified-Since:", hdrName, 18) == 0) {
- // Disabled due to thread safety issues
- getModDate();
- }
-}
-
-
-// httpMessage::getModDate()
-//
-// A function to extract info from the If-Modified-Since http
-// header.
-//
-// Currently brokens since both strptime and mktime are not thread
-// safe
-//
-void
-httpMessage::getModDate()
-{
- // Since the dates have spaces in them, we have to recontruct
- // them. Sigh.
- int i = 1;
- int numDateFields;
- int dateSize = 0;
- char *dateStr;
- const char *clStr;
- int tmpLen;
- Tokenizer *equalTok = NULL;
-
- // First, figure out the number of fields
- for (i = 1; (*parser)[i] != NULL && strstr((*parser)[i++], ";") == NULL;)
- ;
- numDateFields = i - 1;
-
- if (numDateFields > 0) {
- // Next, figure out the size of the string we need
- for (i = 0; i < numDateFields; i++) {
- dateSize += strlen((*parser)[i + 1]);
- }
- dateStr = new char[dateSize + 1 + numDateFields];
- *dateStr = '\0';
-
- // Rebuild the date string from the parsed
- // stuff
- for (i = 0; i < numDateFields; i++) {
- ink_strlcat(dateStr, (*parser)[i + 1], dateSize + 1);
- tmpLen = strlen(dateStr);
- dateStr[tmpLen] = ' ';
- dateStr[tmpLen + 1] = '\0';
- }
-
- // There could be junk of the end of array like a ;
- tmpLen = strlen(dateStr);
- while (!isalpha(dateStr[tmpLen])) {
- dateStr[tmpLen] = '\0';
- tmpLen--;
- }
-
- modificationTime = mime_parse_date(dateStr);
- delete[] dateStr;
-
- // Now figure out the content length from if modified
- if (parser->count() > (unsigned)(numDateFields + 1)) {
- clStr = (*parser)[numDateFields + 1];
- equalTok = new Tokenizer("=\r\n");
- equalTok->Initialize(clStr);
- if (strcasecmp("length", (*equalTok)[0]) == 0) {
- modContentLength = atoi((*equalTok)[1]);
- }
- delete equalTok;
- }
- }
-}
-
-// httpMessage::addRequestBody(int fd)
-//
-// Read the request body of of the socket and make a local
-// copy of the entire thing. Return zero if all went ok
-// or return -1 with there was an error
-int
-httpMessage::addRequestBody(SocketInfo socketD)
-{
- char *nextRead;
- int bytesRead = 0;
- int readResult;
-
- if (conLen < 0) {
- return 0;
- }
-
- body = new char[conLen + 1];
- nextRead = body;
-
- while (bytesRead < conLen) {
- readResult = socket_read(socketD, nextRead, conLen - bytesRead);
-
- if (readResult <= 0) {
- // There was an error on the read.
- *nextRead = '\0';
- return -1;
- } else {
- bytesRead += readResult;
- nextRead += readResult;
- }
- }
- *nextRead = '\0';
- return 0;
-}
-
-httpMessage::~httpMessage()
-{
- delete[] body;
- delete[] file;
- delete[] referer;
- delete[] conType_str;
- delete[] authMessage;
-
- ats_free(client_request);
- delete parser;
-}
-
-/* 01/14/99 elam -
- * Commented out because g++ is not happy with iostream.h
-void httpMessage::Print() {
- cout << "Method: " << method << endl;
- cout << "File: " << file << endl;
- cout << "Query: " << query << endl;
- cout << "Scheme: " << scheme << endl;
- cout << "Content Length: " << conLen << endl;
- cout << "First Header: " << header << endl;
- cout << "Message Body: " << body << endl << endl;
-}
- */
-
-httpResponse::httpResponse()
-{
- // Default is no refresh header;
- refresh = -1;
- conLen = -1;
- conType = TEXT_HTML;
- explicitConType = NULL;
- refreshURL = NULL;
- lastMod = -1;
- authRealm = NULL;
- dateResponse = NULL;
- status = STATUS_INTERNAL_SERVER_ERROR;
- locationURL = NULL;
- cachable = 1;
-}
-
-httpResponse::~httpResponse()
-{
- ats_free(explicitConType);
- ats_free(authRealm);
- ats_free(refreshURL);
- ats_free(locationURL);
- ats_free(dateResponse);
-}
-
-int
-httpResponse::writeHdr(SocketInfo socketD)
-{
- const char versionStr[] = "HTTP/1.0 ";
- const char serverStr[] = "Server: ";
- const char managerStr[] = "Traffic Manager ";
- const char noStoreStr[] = "Cache-Control: no-store\r\n";
- const char noCacheStr[] = "Pragma: no-cache\r\n";
- const char lenStr[] = "Content-length: ";
- const char refreshStr[] = "Refresh: ";
- const char authStr[] = "WWW-Authenticate: Basic realm=\"";
- const char dateStr[] = "Date: ";
- const char lastModStr[] = "Last-modified: ";
- const char locationStr[] = "Location: ";
- const char refreshURLStr[] = "; URL=";
- time_t currentTime;
- const int bufSize = 512;
- char buffer[bufSize];
- char *reply;
- int bytesWritten;
- textBuffer hdr(4096);
-
- hdr.copyFrom(versionStr, strlen(versionStr));
-
- // Record the status
- hdr.copyFrom(httpStatStr[status], strlen(httpStatStr[status]));
-
- // Record Server Name
- hdr.copyFrom(serverStr, strlen(serverStr));
- hdr.copyFrom(managerStr, strlen(managerStr));
- // XXX hdr.copyFrom(appVersionInfo.VersionStr, strlen(appVersionInfo.VersionStr));
- hdr.copyFrom("\r\n", 2);
-
- // Record refresh
- if (refresh >= 0) {
- hdr.copyFrom(refreshStr, strlen(refreshStr));
- snprintf(buffer, bufSize - 1, "%d", refresh);
- hdr.copyFrom(buffer, strlen(buffer));
- if (refreshURL != NULL) {
- hdr.copyFrom(refreshURLStr, strlen(refreshURLStr));
- hdr.copyFrom(refreshURL, strlen(refreshURL));
- }
- hdr.copyFrom("\r\n", 2);
- }
-
- // Location Header
- if (locationURL != NULL) {
- hdr.copyFrom(locationStr, strlen(locationStr));
- hdr.copyFrom(locationURL, strlen(locationURL));
- hdr.copyFrom("\r\n", 2);
- }
-
- // Always send the current time
- currentTime = time(NULL);
- mime_format_date(buffer, currentTime);
- // We were able to genarate the date string
- hdr.copyFrom(dateStr, strlen(dateStr));
- hdr.copyFrom(buffer, strlen(buffer));
- hdr.copyFrom("\r\n", 2);
- dateResponse = ats_strdup(buffer);
-
- // Not cachable if marked not cachable, or has no L-M date
- if ((getCachable() == 0) || (lastMod == -1)) {
- // Use "Control-Control: no-store" for HTTP 1.1
- // compliant browsers.
- hdr.copyFrom(noStoreStr, strlen(noStoreStr));
- // For non-1.1 compliant browsers, we'll set
- // "Pragma: no-cache" just to be safe
- hdr.copyFrom(noCacheStr, strlen(noCacheStr));
- } else if (lastMod != -1) {
- // Send the last modified time if we have it
- mime_format_date(buffer, lastMod);
- // We were able to genarate the date string
- hdr.copyFrom(lastModStr, strlen(lastModStr));
- hdr.copyFrom(buffer, strlen(buffer));
- hdr.copyFrom("\r\n", 2);
- }
-
- snprintf(buffer, sizeof(buffer), "Content-type: %s\r\n", contentTypeStr[conType]);
- hdr.copyFrom(buffer, strlen(buffer));
-
- // Issue an authentication challenge if we are
- // authorized
- if (status == STATUS_UNAUTHORIZED) {
- hdr.copyFrom(authStr, strlen(authStr));
- hdr.copyFrom(authRealm, strlen(authRealm));
- hdr.copyFrom("\"\r\n", 3);
- }
-
- if (conLen >= 0) {
- hdr.copyFrom(lenStr, strlen(lenStr));
- snprintf(buffer, sizeof(buffer), "%d", conLen);
- hdr.copyFrom(buffer, strlen(buffer));
- hdr.copyFrom("\r\n", 2);
- }
- // End of Header marked by empty line
- hdr.copyFrom("\r\n", 2);
-
- reply = hdr.bufPtr();
- bytesWritten = socket_write(socketD, reply, strlen(reply));
- return bytesWritten;
-}
-
-
-void
-httpResponse::setContentType(const char *str)
-{
- if (str != NULL) {
- explicitConType = ats_strdup(str);
- }
-}
-
-void
-httpResponse::setRealm(const char *realm)
-{
- if (realm != NULL) {
- authRealm = ats_strdup(realm);
- }
-}
-
-void
-httpResponse::setRefreshURL(const char *url)
-{
- if (url != NULL) {
- refreshURL = ats_strdup(url);
- }
-}
-
-void
-httpResponse::setLocationURL(const char *url)
-{
- if (url != NULL) {
- locationURL = ats_strdup(url);
- }
-}
-
-
-void
-httpResponse::getLogInfo(const char **date, HttpStatus_t *statusIn, int *length)
-{
- *date = dateResponse;
- *statusIn = status;
- *length = conLen;
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/mgmt/web2/WebHttpMessage.h
----------------------------------------------------------------------
diff --git a/mgmt/web2/WebHttpMessage.h b/mgmt/web2/WebHttpMessage.h
deleted file mode 100644
index 9635d5b..0000000
--- a/mgmt/web2/WebHttpMessage.h
+++ /dev/null
@@ -1,307 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#ifndef _WEB_HTTP_MESSAGE
-#define _WEB_HTTP_MESSAGE
-
-#include <time.h>
-#include "Tokenizer.h"
-#include "WebUtils.h"
-
-/****************************************************************************
- *
- * WebHttpMessage.h - classes to store information about incoming requests
- * and create hdrs for outgoing requests
- *
- *
- *
- ****************************************************************************/
-
-/* define method */
-enum Method_t {
- METHOD_NONE = 0,
- METHOD_OPTIONS,
- METHOD_GET,
- METHOD_HEAD,
- METHOD_POST,
- METHOD_PUT,
- METHOD_DELETE,
- METHOD_TRACE,
- METHOD_CONNECT
-};
-
-/* defined http status codes constants */
-enum HttpStatus_t {
- STATUS_CONTINUE = 0,
- STATUS_SWITCHING_PROTOCOL,
-
- STATUS_OK,
- STATUS_CREATED,
- STATUS_ACCEPTED,
- STATUS_NON_AUTHORITATIVE_INFORMATION,
- STATUS_NO_CONTENT,
- STATUS_RESET_CONTENT,
- STATUS_PARTIAL_CONTENT,
-
- STATUS_MULTIPLE_CHOICES,
- STATUS_MOVED_PERMANENTLY,
- STATUS_MOVED_TEMPORARILY,
- STATUS_SEE_OTHER,
- STATUS_NOT_MODIFIED,
- STATUS_USE_PROXY,
-
- STATUS_BAD_REQUEST,
- STATUS_UNAUTHORIZED,
- STATUS_PAYMENT_REQUIRED,
- STATUS_FORBIDDEN,
- STATUS_NOT_FOUND,
-
- STATUS_INTERNAL_SERVER_ERROR,
- STATUS_NOT_IMPLEMENTED,
- STATUS_BAD_GATEWAY,
- STATUS_SERVICE_UNAVAILABLE,
- STATUS_GATEWAY_TIMEOUT,
- STATUS_HTTPVER_NOT_SUPPORTED
-};
-
-/* define scheme type */
-enum Scheme_t {
- SCHEME_UNKNOWN = -1,
- SCHEME_NONE = 0,
- SCHEME_HTTP,
- SCHEME_SHTTP,
-};
-
-enum Content_t {
- TEXT_PLAIN = 0,
- TEXT_HTML,
- TEXT_CSS,
- TEXT_UNKNOWN,
- IMAGE_GIF,
- IMAGE_JPEG,
- IMAGE_PNG,
- APP_JAVA,
- APP_JAVASCRIPT,
- APP_X509,
- APP_AUTOCONFIG,
- APP_ZIP
-};
-
-extern const char *const httpStatStr[];
-extern const char *const httpStatCode[];
-extern const char *const contentTypeStr[];
-
-class httpMessage
-{
-public:
- httpMessage();
- ~httpMessage();
-
- Method_t
- getMethod()
- {
- return method;
- };
- const char *
- getFile()
- {
- return file;
- };
- const char *
- getQuery()
- {
- return query;
- };
- Scheme_t
- getScheme()
- {
- return scheme;
- };
- const char *
- getHeader()
- {
- return header;
- };
- char *
- getBody()
- {
- return body;
- };
- int
- getConLen()
- {
- return conLen;
- };
- const char *
- getReferer()
- {
- if (referer != NULL) {
- return referer;
- }
- return NULL;
- };
- const char *
- getContentType()
- {
- return conType_str;
- };
- const char *
- getAuthMessage()
- {
- return authMessage;
- };
- time_t
- getModTime()
- {
- return modificationTime;
- };
-
- int addRequestLine(char *);
- void addHeader(char *);
- int addRequestBody(SocketInfo socketD);
-
- // void Print();
- void getLogInfo(const char **request);
-
-private:
- httpMessage(const httpMessage &);
- void getModDate();
- Method_t method;
- char *file;
- // char* referer;
- char *query;
- Scheme_t scheme;
- char *header;
- char *body;
- int conLen;
- char *referer;
- char *conType_str;
- char *authMessage;
- Tokenizer *parser;
- time_t modificationTime;
- int modContentLength;
- char *client_request; // Request as the client sent it. For logs
-};
-
-class httpResponse
-{
-public:
- httpResponse();
- ~httpResponse();
-
- void
- setContentType(Content_t ct)
- {
- conType = ct;
- };
- // If this method is called, it will override the content type
- // stored in conType. Example: "Content-type: text/html\r\n".
- void setContentType(const char *str);
-
- void
- setLength(int x)
- {
- conLen = x;
- };
- int
- getLength()
- {
- return conLen;
- };
-
- void
- setStatus(HttpStatus_t s)
- {
- status = s;
- };
- HttpStatus_t
- getStatus()
- {
- return status;
- };
-
-
- void
- setRefresh(int i)
- {
- refresh = i;
- };
- int
- getRefresh()
- {
- return refresh;
- };
-
- const char *
- getRefreshURL()
- {
- return refreshURL;
- };
- void setRefreshURL(const char *url);
-
- const char *
- getLocationURL()
- {
- return locationURL;
- };
- void setLocationURL(const char *url);
-
- void setRealm(const char *);
- void
- setLastMod(time_t lm)
- {
- lastMod = lm;
- };
-
- void
- setCachable(int c)
- {
- if ((cachable = c) == 0) {
- lastMod = -1;
- }
- }
- int
- getCachable()
- {
- return cachable;
- }
-
- int writeHdr(SocketInfo socketD);
- void getLogInfo(const char **date, HttpStatus_t *status, int *legth);
-
-private:
- httpResponse(const httpResponse &);
- HttpStatus_t status;
- int refresh;
- int conLen;
- Content_t conType;
- char *explicitConType;
- char *authRealm;
- char *refreshURL;
- char *locationURL;
- time_t lastMod;
- int cachable;
- char *dateResponse; // for logs
-};
-
-#endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/mgmt/web2/WebIntrMain.cc
----------------------------------------------------------------------
diff --git a/mgmt/web2/WebIntrMain.cc b/mgmt/web2/WebIntrMain.cc
deleted file mode 100644
index eeacdd9..0000000
--- a/mgmt/web2/WebIntrMain.cc
+++ /dev/null
@@ -1,533 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-/************* ***************************
- *
- * WebIntrMain.cc - main loop for the Web Interface
- *
- *
- *
- ****************************************************************************/
-
-#include "libts.h"
-#include "I_Layout.h"
-#include "LocalManager.h"
-#include "Alarms.h"
-#include "WebHttp.h"
-#include "WebGlobals.h"
-#include "MgmtUtils.h"
-#include "WebMgmtUtils.h"
-#include "WebIntrMain.h"
-#include "Diags.h"
-#include "MgmtSocket.h"
-#include "NetworkUtilsRemote.h"
-
-// INKqa09866
-#include "TSControlMain.h"
-#include "EventControlMain.h"
-
-#if !defined(linux)
-// Solaris header files forget this one
-extern "C" {
-int usleep(unsigned int useconds);
-}
-#endif
-
-typedef int fd;
-static RecInt autoconf_localhost_only = 1;
-
-#define SOCKET_TIMEOUT 10 * 60
-
-
-WebInterFaceGlobals wGlobals;
-
-// There are two web ports maintained
-//
-// One is for administration. This port serves
-// all the configuration and monitoring info.
-// Most sites will have some security features
-// (authentication and SSL) active on this
-// port since it system administrator access
-// The other is for things that we want to serve
-// insecurely. Client auto configuration falls
-// in this category. The public key for the
-// administration server is another example
-//
-WebContext autoconfContext;
-
-// Used for storing argument values
-int aconf_port_arg = -1;
-
-// int checkWebContext(WebContext* wctx, char* desc)
-//
-// Checks out a WebContext to make sure that the
-// directory exists and that the default file
-// exists
-//
-// returns 0 if everything is OK
-// returns 1 if something is missing
-//
-int
-checkWebContext(WebContext *wctx, const char *desc)
-{
- struct stat fInfo;
- textBuffer defaultFile(256);
-
- if (wctx->docRoot == NULL) {
- mgmt_log(stderr, "[checkWebContext] No document root specified for %s\n", desc);
- return 1;
- }
-
- if (stat(wctx->docRoot, &fInfo) < 0) {
- mgmt_log(stderr, "[checkWebContext] Unable to access document root '%s' for %s : %s\n", wctx->docRoot, desc, strerror(errno));
- return 1;
- }
-
- if (!S_ISDIR(fInfo.st_mode)) {
- mgmt_log(stderr, "[checkWebContext] Document root '%s' for %s is not a directory\n", wctx->docRoot, desc);
- return 1;
- }
-
- if (wctx->defaultFile == NULL) {
- mgmt_log(stderr, "[checkWebContext] No default document specified for %s\n", desc);
- return 1;
- }
-
- defaultFile.copyFrom(wctx->docRoot, strlen(wctx->docRoot));
- defaultFile.copyFrom("/", 1);
- defaultFile.copyFrom(wctx->defaultFile, strlen(wctx->defaultFile));
-
- if (stat(defaultFile.bufPtr(), &fInfo) < 0) {
- mgmt_log(stderr, "Unable to access default document, %s, for %s : %s\n", wctx->defaultFile, desc, strerror(errno));
- return 1;
- }
-
- if (!S_ISREG(fInfo.st_mode)) {
- mgmt_log(stderr, "[checkWebContext] Default document for %s is not a file\n", desc);
- return 1;
- }
-
- return 0;
-}
-
-// fd newTcpSocket(int port)
-//
-// returns a file descriptor associated with a new socket
-// on the specified port
-//
-// If the socket could not be created, returns -1
-//
-// Thread Safe: NO! Call only from main Web interface thread
-//
-static fd
-newTcpSocket(int port)
-{
- struct sockaddr_in socketInfo;
- fd socketFD;
- int one = 1;
-
- memset(&socketInfo, 0, sizeof(sockaddr_in));
-
- // Create the new TCP Socket
- if ((socketFD = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
- mgmt_fatal(stderr, errno, "[newTcpSocket]: %s", "Unable to Create Socket\n");
- return -1;
- }
- // Specify our port number is network order
- memset(&socketInfo, 0, sizeof(socketInfo));
- socketInfo.sin_family = AF_INET;
- socketInfo.sin_port = htons(port);
- if (autoconf_localhost_only == 1) {
- socketInfo.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- } else {
- socketInfo.sin_addr.s_addr = htonl(INADDR_ANY);
- }
-
- // Allow for immediate re-binding to port
- if (setsockopt(socketFD, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(int)) < 0) {
- mgmt_fatal(stderr, errno, "[newTcpSocket] Unable to set socket options.\n");
- }
- // Bind the port to the socket
- if (bind(socketFD, (sockaddr *)&socketInfo, sizeof(socketInfo)) < 0) {
- mgmt_elog(stderr, 0, "[newTcpSocket] Unable to bind port %d to socket: %s\n", port, strerror(errno));
- close_socket(socketFD);
- return -1;
- }
- // Listen on the new socket
- if (listen(socketFD, 5) < 0) {
- mgmt_elog(stderr, errno, "[newTcpSocket] %s\n", "Unable to listen on the socket");
- close_socket(socketFD);
- return -1;
- }
- // Set the close on exec flag so our children do not
- // have this socket open
- if (fcntl(socketFD, F_SETFD, 1) < 0) {
- mgmt_elog(stderr, errno, "[newTcpSocket] Unable to set close on exec flag\n");
- }
-
- return socketFD;
-}
-
-// Keep track of the number of service threads for debugging
-// purposes
-static volatile int32_t numServiceThr = 0;
-
-void *
-serviceThrReaper(void * /* arg ATS_UNUSED */)
-{
- int numJoined;
-
- lmgmt->syslogThrInit();
-
- while (1) {
- numJoined = 0;
-
- // coverity[lock][lockagain]
- ink_mutex_acquire(&wGlobals.serviceThrLock);
-
- for (int i = 0; i < MAX_SERVICE_THREADS; i++) {
- if (wGlobals.serviceThrArray[i].threadId != 0) {
- if (wGlobals.serviceThrArray[i].waitingForJoin == true) {
- // fprintf(stderr, "Joining on thread %d in slot %d\n",
- // wGlobals.serviceThrArray[i].threadId, i);
-
- // Join on threads that have exited so we recycle their thrIds and
- // stack space
- ink_assert(wGlobals.serviceThrArray[i].threadId > 0);
- ink_thread_join(wGlobals.serviceThrArray[i].threadId);
-
- wGlobals.serviceThrArray[i].fd = -1;
- wGlobals.serviceThrArray[i].threadId = 0;
- wGlobals.serviceThrArray[i].startTime = 0;
- wGlobals.serviceThrArray[i].waitingForJoin = false;
- wGlobals.serviceThrArray[i].alreadyShutdown = false;
-
- numJoined++;
- }
- }
- }
-
- ink_mutex_release(&wGlobals.serviceThrLock);
-
- for (int j = 0; j < numJoined; j++) {
- ink_sem_post(&wGlobals.serviceThrCount);
- ink_atomic_increment((int32_t *)&numServiceThr, -1);
- }
-
- usleep(300000);
- }
-
- return NULL;
-} // END serviceThrReaper()
-
-static bool
-api_socket_is_restricted()
-{
- RecInt intval;
-
- // If the socket is not administratively restricted, check whether we have platform
- // support. Otherwise, default to making it restricted.
- if (RecGetRecordInt("proxy.config.admin.api.restricted", &intval) == REC_ERR_OKAY) {
- if (intval == 0) {
- return !mgmt_has_peereid();
- }
- }
-
- return true;
-}
-
-void *
-webIntr_main(void *)
-{
- fd socketFD = -1; // FD for incoming HTTP connections
- fd autoconfFD = -1; // FD for incoming autoconf connections
- fd clientFD = -1; // FD for accepted connections
- fd mgmtapiFD = -1; // FD for the api interface to issue commands
- fd eventapiFD = -1; // FD for the api and clients to handle event callbacks
-
- // dg: added init to get rid of compiler warnings
- fd acceptFD = 0; // FD that is ready for accept
- UIthr_t serviceThr = NO_THR; // type for new service thread
-
- struct sockaddr_in *clientInfo; // Info about client connection
- ink_thread thrId; // ID of service thread we just spawned
- fd_set selectFDs; // FD set passed to select
- int publicPort = -1; // Port for incoming autoconf connections
-#if !defined(linux)
- sigset_t allSigs; // Set of all signals
-#endif
- char pacFailMsg[] = "Auto-Configuration Service Failed to Initialize";
- // char gphFailMsg[] = "Dynamic Graph Service Failed to Initialize";
- char mgmtapiFailMsg[] = "Traffic server management API service Interface Failed to Initialize.";
-
- RecInt tempInt;
- bool found;
-
- int addrLen;
- int i;
-
-#if !defined(linux)
- // Start by blocking all signals
- sigfillset(&allSigs);
- ink_thread_sigsetmask(SIG_SETMASK, &allSigs, NULL);
-#endif
-
- lmgmt->syslogThrInit();
-
- // Set up the threads management
- ink_sem_init(&wGlobals.serviceThrCount, MAX_SERVICE_THREADS);
- ink_mutex_init(&wGlobals.serviceThrLock, "Web Interface Mutex");
- wGlobals.serviceThrArray = new serviceThr_t[MAX_SERVICE_THREADS];
- for (i = 0; i < MAX_SERVICE_THREADS; i++) {
- // coverity[missing_lock]
- wGlobals.serviceThrArray[i].threadId = 0;
- // coverity[missing_lock]
- wGlobals.serviceThrArray[i].fd = -1;
- // coverity[missing_lock]
- wGlobals.serviceThrArray[i].startTime = 0;
- // coverity[missing_lock]
- wGlobals.serviceThrArray[i].waitingForJoin = false;
- }
- ink_thread_create(serviceThrReaper, NULL);
-
- // Init mutex to only allow one submissions at a time
- ink_mutex_init(&wGlobals.submitLock, "Submission Mutex");
-
- // Fix for INKqa10514
- found = (RecGetRecordInt("proxy.config.admin.autoconf.localhost_only", &autoconf_localhost_only) == REC_ERR_OKAY);
- ink_assert(found);
-
- // Set up the client autoconfiguration context
- //
- // Since autoconf is public access, turn security
- // features off
- if (aconf_port_arg > 0) {
- publicPort = aconf_port_arg;
- } else {
- found = (RecGetRecordInt("proxy.config.admin.autoconf_port", &tempInt) == REC_ERR_OKAY);
- publicPort = (int)tempInt;
- ink_assert(found);
- }
- Debug("ui", "[WebIntrMain] Starting Client AutoConfig Server on Port %d", publicPort);
-
- found = (RecGetRecordString_Xmalloc("proxy.config.admin.autoconf.doc_root", &(autoconfContext.docRoot)) == REC_ERR_OKAY);
- ink_assert(found);
-
- if (autoconfContext.docRoot == NULL) {
- mgmt_fatal(stderr, 0, "[WebIntrMain] No Client AutoConf Root\n");
- } else {
- struct stat s;
- int err;
-
- if ((err = stat(autoconfContext.docRoot, &s)) < 0) {
- ats_free(autoconfContext.docRoot);
- autoconfContext.docRoot = RecConfigReadConfigDir();
- if ((err = stat(autoconfContext.docRoot, &s)) < 0) {
- mgmt_elog(0, "[WebIntrMain] unable to stat() directory '%s': %d %d, %s\n", autoconfContext.docRoot, err, errno,
- strerror(errno));
- mgmt_elog(0, "[WebIntrMain] please set the 'TS_ROOT' environment variable\n");
- mgmt_fatal(stderr, 0, "[WebIntrMain] No Client AutoConf Root\n");
- }
- }
- autoconfContext.docRootLen = strlen(autoconfContext.docRoot);
- }
- autoconfContext.defaultFile = "/proxy.pac";
-
- // INKqa09866
- // fire up interface for ts configuration through API; use absolute path from root to
- // set up socket paths;
- ats_scoped_str rundir(RecConfigReadRuntimeDir());
- ats_scoped_str apisock(Layout::relative_to(rundir, MGMTAPI_MGMT_SOCKET_NAME));
- ats_scoped_str eventsock(Layout::relative_to(rundir, MGMTAPI_EVENT_SOCKET_NAME));
-
- mode_t oldmask = umask(0);
- mode_t newmode = api_socket_is_restricted() ? 00700 : 00777;
-
- mgmtapiFD = bind_unix_domain_socket(apisock, newmode);
- if (mgmtapiFD == -1) {
- mgmt_log(stderr, "[WebIntrMain] Unable to set up socket for handling management API calls. API socket path = %s\n",
- (const char *)apisock);
- lmgmt->alarm_keeper->signalAlarm(MGMT_ALARM_WEB_ERROR, mgmtapiFailMsg);
- }
-
- eventapiFD = bind_unix_domain_socket(eventsock, newmode);
- if (eventapiFD == -1) {
- mgmt_log(stderr, "[WebIntrMain] Unable to set up so for handling management API event calls. Event Socket path: %s\n",
- (const char *)eventsock);
- }
-
- umask(oldmask);
-
- // launch threads
- // create thread for mgmtapi
- ink_thread_create(ts_ctrl_main, &mgmtapiFD);
- ink_thread_create(event_callback_main, &eventapiFD);
-
- // initialize mgmt api plugins
- // mgmt_plugin_init(config_path);
-
- // Check our web contexts to make sure everything is
- // OK. If it is, go ahead and fire up the interfaces
- if (checkWebContext(&autoconfContext, "Browser Auto-Configuration") != 0) {
- lmgmt->alarm_keeper->signalAlarm(MGMT_ALARM_WEB_ERROR, pacFailMsg);
- } else {
- if ((autoconfFD = newTcpSocket(publicPort)) < 0) {
- mgmt_elog(stderr, errno, "[WebIntrMain] Unable to start client autoconf server\n");
- lmgmt->alarm_keeper->signalAlarm(MGMT_ALARM_WEB_ERROR, pacFailMsg);
- }
- }
-
- // Initialze WebHttp Module
- WebHttpInit();
-
- while (1) {
- FD_ZERO(&selectFDs);
-
- if (socketFD >= 0) {
- FD_SET(socketFD, &selectFDs);
- }
-
- if (autoconfFD >= 0) {
- FD_SET(autoconfFD, &selectFDs);
- }
-
- // TODO: Should we check return value?
- mgmt_select(FD_SETSIZE, &selectFDs, (fd_set *)NULL, (fd_set *)NULL, NULL);
-
- if (autoconfFD >= 0 && FD_ISSET(autoconfFD, &selectFDs)) {
- acceptFD = autoconfFD;
- serviceThr = AUTOCONF_THR;
- } else {
- ink_assert(!"[webIntrMain] Error on mgmt_select()\n");
- }
- ink_sem_wait(&wGlobals.serviceThrCount);
- ink_atomic_increment((int32_t *)&numServiceThr, 1);
-
- // coverity[alloc_fn]
- clientInfo = (struct sockaddr_in *)ats_malloc(sizeof(struct sockaddr_in));
- addrLen = sizeof(struct sockaddr_in);
-
- // coverity[noescape]
- if ((clientFD = mgmt_accept(acceptFD, (sockaddr *)clientInfo, &addrLen)) < 0) {
- mgmt_log(stderr, "[WebIntrMain]: %s%s\n", "Accept on incoming connection failed: ", strerror(errno));
- ink_sem_post(&wGlobals.serviceThrCount);
- ink_atomic_increment((int32_t *)&numServiceThr, -1);
- } else { // Accept succeeded
- if (safe_setsockopt(clientFD, IPPROTO_TCP, TCP_NODELAY, SOCKOPT_ON, sizeof(int)) < 0) {
- mgmt_log(stderr, "[WebIntrMain]Failed to set sock options: %s\n", strerror(errno));
- }
-
- // Accept OK
- ink_mutex_acquire(&wGlobals.serviceThrLock);
-
- // If this a web manager, make sure that it is from an allowed ip addr
- if (serviceThr == AUTOCONF_THR && autoconf_localhost_only != 0 && strcmp(inet_ntoa(clientInfo->sin_addr), "127.0.0.1") != 0) {
- mgmt_log("WARNING: connect by disallowed client %s, closing\n", inet_ntoa(clientInfo->sin_addr));
- ink_sem_post(&wGlobals.serviceThrCount);
- ink_atomic_increment((int32_t *)&numServiceThr, -1);
- ats_free(clientInfo);
- close_socket(clientFD);
- } else { // IP is allowed
-
- for (i = 0; i < MAX_SERVICE_THREADS; i++) {
- if (wGlobals.serviceThrArray[i].threadId == 0) {
- //
- wGlobals.serviceThrArray[i].fd = clientFD;
- wGlobals.serviceThrArray[i].startTime = time(NULL);
- wGlobals.serviceThrArray[i].waitingForJoin = false;
- wGlobals.serviceThrArray[i].alreadyShutdown = false;
- wGlobals.serviceThrArray[i].type = serviceThr;
- wGlobals.serviceThrArray[i].clientInfo = clientInfo;
- thrId = ink_thread_create(serviceThrMain, &wGlobals.serviceThrArray[i], 0);
- // fprintf (stderr, "New Service Thread %d in slot %d\n", thrId, i);
-
- if (thrId > 0) {
- wGlobals.serviceThrArray[i].threadId = thrId;
- } else {
- // Failed to create thread
- mgmt_elog(stderr, errno, "[WebIntrMain] Failed to create service thread\n");
- wGlobals.serviceThrArray[i].threadId = 0;
- wGlobals.serviceThrArray[i].fd = -1;
- close_socket(clientFD);
- ink_sem_post(&wGlobals.serviceThrCount);
- ink_atomic_increment((int32_t *)&numServiceThr, -1);
- }
-
- break;
- } else if (i == MAX_SERVICE_THREADS - 1) {
- mgmt_fatal(stderr, 0, "[WebIntrMain] Syncronizaion Failure\n");
- _exit(1);
- }
- }
- }
-
- ink_mutex_release(&wGlobals.serviceThrLock);
- }
- } // end while(1)
- ink_release_assert(!"impossible"); // should never get here
- return NULL;
-}
-
-// void* serviceThrMain(void* info)
-//
-// Thread main for any type of service thread
-//
-void *
-serviceThrMain(void *info)
-{
- serviceThr_t *threadInfo = (serviceThr_t *)info;
- WebHttpConInfo httpInfo;
-
- lmgmt->syslogThrInit();
-
- // Do our work
- switch (threadInfo->type) {
- case NO_THR: // dg: added to handle init value
- ink_assert(false);
- break;
- case AUTOCONF_THR:
- httpInfo.fd = threadInfo->fd;
- httpInfo.context = &autoconfContext;
- httpInfo.clientInfo = threadInfo->clientInfo;
- WebHttpHandleConnection(&httpInfo);
- break;
- default:
- // Handled here:
- // GRAPH_THR
- break;
- }
-
- ats_free(threadInfo->clientInfo);
-
- // Mark ourselves ready to be reaped
- ink_mutex_acquire(&wGlobals.serviceThrLock);
-
- threadInfo->waitingForJoin = true;
- threadInfo->fd = -1;
-
- ink_mutex_release(&wGlobals.serviceThrLock);
-
- // Call exit so that we properly release system resources
- ink_thread_exit(NULL);
- return NULL; // No Warning
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/mgmt/web2/WebIntrMain.h
----------------------------------------------------------------------
diff --git a/mgmt/web2/WebIntrMain.h b/mgmt/web2/WebIntrMain.h
deleted file mode 100644
index ce78f1b..0000000
--- a/mgmt/web2/WebIntrMain.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#ifndef _WEB_INTR_MAIN_H_
-#define _WEB_INTR_MAIN_H_
-
-/****************************************************************************
- *
- * WebIntrMain.h - main loop for the Web Interface
- *
- ****************************************************************************/
-
-struct WebContext;
-
-#include "P_RecCore.h"
-
-void *webIntr_main(void *);
-void *serviceThrMain(void *info);
-
-extern int aconf_port_arg;
-
-#endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/mgmt/web2/WebOverview.cc
----------------------------------------------------------------------
diff --git a/mgmt/web2/WebOverview.cc b/mgmt/web2/WebOverview.cc
deleted file mode 100644
index 8372706..0000000
--- a/mgmt/web2/WebOverview.cc
+++ /dev/null
@@ -1,663 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-/****************************************************************************
- *
- * WebOverview.cc - code to overview page
- *
- *
- ****************************************************************************/
-
-#include "libts.h"
-
-#include "WebOverview.h"
-#include "WebGlobals.h"
-#include "WebMgmtUtils.h"
-
-#include "LocalManager.h"
-#include "ClusterCom.h"
-#include "MgmtUtils.h"
-#include "MgmtDefs.h"
-#include "Diags.h"
-
-// Make this pointer to avoid nasty destruction
-// problems do to alarm
-// fork, execl, exit squences
-overviewPage *overviewGenerator;
-
-overviewRecord::overviewRecord(unsigned long inet_addr, bool local, ClusterPeerInfo *cpi)
-{
- char *name_l; // hostname looked up from node record
- bool name_found;
- struct in_addr nameFailed;
-
- inetAddr = inet_addr;
-
- this->up = false;
- this->localNode = local;
-
- // If this is the local node, there is no cluster peer info
- // record. Remote nodes require a cluster peer info record
- ink_assert((local == false && cpi != NULL) || (local == true && cpi == NULL));
-
- // Set up the copy of the records array and initialize it
- if (local == true) {
- node_rec_data.num_recs = 0;
- node_rec_data.recs = NULL;
- recordArraySize = 0;
- node_rec_first_ix = 0;
- } else {
- node_rec_data.num_recs = cpi->node_rec_data.num_recs;
- recordArraySize = node_rec_data.num_recs * sizeof(RecRecord);
- node_rec_data.recs = new RecRecord[recordArraySize];
- memcpy(node_rec_data.recs, cpi->node_rec_data.recs, recordArraySize);
-
- // Recaculate the old relative index
- RecGetRecordOrderAndId(node_rec_data.recs[0].name, &node_rec_first_ix, NULL);
- }
-
-
- // Query for the name of the node. If it is not there, some
- // their cluster ip address
- name_l = this->readString("proxy.node.hostname_FQ", &name_found);
- if (name_found == false || name_l == NULL) {
- nameFailed.s_addr = inetAddr;
- mgmt_log("[overviewRecord::overviewRecord] Unable to find hostname for %s\n", inet_ntoa(nameFailed));
- ats_free(name_l); // about to overwrite name_l, so we need to free it first
- name_l = ats_strdup(inet_ntoa(nameFailed));
- }
-
- const size_t hostNameLen = strlen(name_l) + 1;
- this->hostname = new char[hostNameLen];
- ink_strlcpy(this->hostname, name_l, hostNameLen);
- ats_free(name_l);
-}
-
-overviewRecord::~overviewRecord()
-{
- delete[] hostname;
-
- if (localNode == false) {
- delete[] node_rec_data.recs;
- }
-}
-
-// void overviewRecord::updateStatus(time_t, ClusterPeerInfo*)
-// updates up/down status based on the cluster peer info record
-//
-// currentTime is the value of localtime(time()) - sent in as
-// a parameter so we do not have to make repetitive system calls.
-// overviewPage::checkForUpdates can just make one call
-//
-// cpi - is a pointer to a structure we got from ClusterCom that represnets
-// information about this node
-//
-// a machine is up if we have heard from it in the last 15 seconds
-//
-void
-overviewRecord::updateStatus(time_t currentTime, ClusterPeerInfo *cpi)
-{
- // Update if the node is up or down
- if (currentTime - cpi->idle_ticks > 15) {
- up = false;
- } else {
- up = true;
- }
-
- // Update the node records by copying them from cpi
- // (remote nodes only)
- if (localNode == false) {
- memcpy(node_rec_data.recs, cpi->node_rec_data.recs, recordArraySize);
- RecGetRecordOrderAndId(node_rec_data.recs[0].name, &node_rec_first_ix, NULL);
- }
-}
-
-// overview::readInteger
-//
-// Accessor functions for node records. For remote node,
-// we get the value in the node_data array we maintain
-// in this object. For the node, we do not maintain any data
-// and rely on lmgmt->record_data for both the retrieval
-// code and the records array
-//
-// Locking should be done by overviewPage::accessLock.
-// CALLEE is responsible for obtaining and releasing the lock
-//
-RecInt
-overviewRecord::readInteger(const char *name, bool *found)
-{
- RecInt rec = 0;
- int rec_status = REC_ERR_OKAY;
- int order = -1;
- if (localNode == false) {
- rec_status = RecGetRecordOrderAndId(name, &order, NULL);
- if (rec_status == REC_ERR_OKAY) {
- order -= node_rec_first_ix; // Offset
- ink_release_assert(order < node_rec_data.num_recs);
- ink_assert(order < node_rec_data.num_recs);
- rec = node_rec_data.recs[order].data.rec_int;
- }
- } else {
- rec_status = RecGetRecordInt(name, &rec);
- }
-
- if (found) {
- *found = (rec_status == REC_ERR_OKAY);
- } else {
- mgmt_log(stderr, "node variables '%s' not found!\n");
- }
- return rec;
-}
-
-RecFloat
-overviewRecord::readFloat(const char *name, bool *found)
-{
- RecFloat rec = 0.0;
- int rec_status = REC_ERR_OKAY;
- int order = -1;
- if (localNode == false) {
- rec_status = RecGetRecordOrderAndId(name, &order, NULL);
- if (rec_status == REC_ERR_OKAY) {
- order -= node_rec_first_ix; // Offset
- ink_release_assert(order < node_rec_data.num_recs);
- ink_assert(order < node_rec_data.num_recs);
- rec = node_rec_data.recs[order].data.rec_float;
- }
- } else {
- rec_status = RecGetRecordFloat(name, &rec);
- }
-
- if (found) {
- *found = (rec_status == REC_ERR_OKAY);
- } else {
- mgmt_log(stderr, "node variables '%s' not found!\n");
- }
- return rec;
-}
-
-RecString
-overviewRecord::readString(const char *name, bool *found)
-{
- RecString rec = NULL;
- int rec_status = REC_ERR_OKAY;
- int order = -1;
- if (localNode == false) {
- rec_status = RecGetRecordOrderAndId(name, &order, NULL);
- if (rec_status == REC_ERR_OKAY) {
- order -= node_rec_first_ix; // Offset
- ink_release_assert(order < node_rec_data.num_recs);
- ink_assert(order < node_rec_data.num_recs);
- rec = ats_strdup(node_rec_data.recs[order].data.rec_string);
- }
- } else {
- rec_status = RecGetRecordString_Xmalloc(name, &rec);
- }
-
- if (found) {
- *found = (rec_status == REC_ERR_OKAY);
- } else {
- mgmt_log(stderr, "node variables '%s' not found!\n");
- }
- return rec;
-}
-
-// overview::readData, read RecData according varType
-//
-// Accessor functions for node records. For remote node,
-// we get the value in the node_data array we maintain
-// in this object. For the node, we do not maintain any data
-// and rely on lmgmt->record_data for both the retrieval
-// code and the records array
-//
-// Locking should be done by overviewPage::accessLock.
-// CALLEE is responsible for obtaining and releasing the lock
-//
-RecData
-overviewRecord::readData(RecDataT varType, const char *name, bool *found)
-{
- int rec_status = REC_ERR_OKAY;
- int order = -1;
- RecData rec;
- RecDataClear(RECD_NULL, &rec);
-
- if (localNode == false) {
- rec_status = RecGetRecordOrderAndId(name, &order, NULL);
- if (rec_status == REC_ERR_OKAY) {
- order -= node_rec_first_ix; // Offset
- ink_release_assert(order < node_rec_data.num_recs);
- ink_assert(order < node_rec_data.num_recs);
- RecDataSet(varType, &rec, &node_rec_data.recs[order].data);
- } else {
- Fatal("node variables '%s' not found!\n", name);
- }
- } else
- rec_status = RecGetRecord_Xmalloc(name, varType, &rec, true);
-
- if (found) {
- *found = (rec_status == REC_ERR_OKAY);
- } else {
- mgmt_log(stderr, "node variables '%s' not found!\n");
- }
- return rec;
-}
-
-bool
-overviewRecord::varFloatFromName(const char *name, MgmtFloat *value)
-{
- bool found = false;
-
- if (value)
- *value = readFloat((char *)name, &found);
-
- return found;
-}
-
-overviewPage::overviewPage() : sortRecords(10, false)
-{
- ink_mutex_init(&accessLock, "overviewRecord");
- nodeRecords = ink_hash_table_create(InkHashTableKeyType_Word);
- numHosts = 0;
- ourAddr = 0; // We will update this when we add the record for
- // this machine
-}
-
-overviewPage::~overviewPage()
-{
- // Since we only have one global object and we never destruct it
- // do not actually free memeory since it causes problems the
- // process is vforked, and the child execs something
- // The below code is DELIBERTLY commented out
- //
- // ink_mutex_destroy(&accessLock);
- // ink_hash_table_destroy(nodeRecords);
-}
-
-// overviewPage::checkForUpdates - updates node records as to whether peers
-// are up or down
-void
-overviewPage::checkForUpdates()
-{
- ClusterPeerInfo *tmp;
- InkHashTableEntry *entry;
- InkHashTableIteratorState iterator_state;
- overviewRecord *current;
- time_t currentTime;
- bool newHostAdded = false;
-
- // grok through the cluster communication stuff and update information
- // about hosts in the cluster
- //
- ink_mutex_acquire(&accessLock);
- ink_mutex_acquire(&(lmgmt->ccom->mutex));
- currentTime = time(NULL);
- for (entry = ink_hash_table_iterator_first(lmgmt->ccom->peers, &iterator_state); entry != NULL;
- entry = ink_hash_table_iterator_next(lmgmt->ccom->peers, &iterator_state)) {
- tmp = (ClusterPeerInfo *)ink_hash_table_entry_value(lmgmt->ccom->peers, entry);
-
- if (ink_hash_table_lookup(nodeRecords, (InkHashTableKey)tmp->inet_address, (InkHashTableValue *)¤t) == 0) {
- this->addRecord(tmp);
- newHostAdded = true;
- } else {
- current->updateStatus(currentTime, tmp);
- }
- }
- ink_mutex_release(&lmgmt->ccom->mutex);
-
- // If we added a new host we must resort sortRecords
- if (newHostAdded) {
- this->sortHosts();
- }
-
- ink_mutex_release(&accessLock);
-}
-
-
-// overrviewPage::sortHosts()
-//
-// resorts sortRecords, but always leaves the local node
-// as the first record
-//
-// accessLock must be held by callee
-void
-overviewPage::sortHosts()
-{
- void **array = sortRecords.getArray();
-
- qsort(array + 1, numHosts - 1, sizeof(void *), hostSortFunc);
-}
-
-// overviewPage::addRecord(ClusterPerrInfo* cpi)
-// Adds a new node record
-// Assuems that this->accessLock is already held
-//
-void
-overviewPage::addRecord(ClusterPeerInfo *cpi)
-{
- overviewRecord *newRec;
-
- ink_assert(cpi != NULL);
-
- newRec = new overviewRecord(cpi->inet_address, false, cpi);
- newRec->updateStatus(time(NULL), cpi);
-
- ink_hash_table_insert(nodeRecords, (InkHashTableKey)cpi->inet_address, (InkHashTableEntry *)newRec);
-
- sortRecords.addEntry(newRec);
- numHosts++;
-}
-
-// adds a record to nodeRecords for the local machine.
-// gets IP addr from lmgmt->ccom so cluster communtication
-// must be intialized before calling this function
-//
-//
-void
-overviewPage::addSelfRecord()
-{
- overviewRecord *newRec;
-
- ink_mutex_acquire(&accessLock);
-
- // We should not have been called before
- ink_assert(ourAddr == 0);
-
- // Find out what our cluster addr is from
- // from cluster com
- this->ourAddr = lmgmt->ccom->getIP();
-
- newRec = new overviewRecord(ourAddr, true);
- newRec->up = true;
-
- ink_hash_table_insert(nodeRecords, (InkHashTableKey) this->ourAddr, (InkHashTableEntry *)newRec);
-
- sortRecords.addEntry(newRec);
- numHosts++;
- ink_mutex_release(&accessLock);
-}
-
-// int overviewPage::getClusterHosts(Expanding Array* hosts)
-//
-// The names of all the cluster members are inserted
-// into parameter hosts. The callee is responsible
-// for freeing the strings
-//
-int
-overviewPage::getClusterHosts(ExpandingArray *hosts)
-{
- int number = 0;
-
- overviewRecord *current;
-
- ink_mutex_acquire(&accessLock);
- number = sortRecords.getNumEntries();
-
- for (int i = 0; i < number; i++) {
- current = (overviewRecord *)sortRecords[i];
- hosts->addEntry(ats_strdup(current->hostname));
- }
-
- ink_mutex_release(&accessLock);
- return number;
-}
-
-// overviewRecord* overviewPage::findNodeByName(const char* nodeName)
-//
-// Returns a pointer to node name nodeName
-// If node name is not found, returns NULL
-//
-// CALLEE MUST BE HOLDING this->accessLock
-//
-overviewRecord *
-overviewPage::findNodeByName(const char *nodeName)
-{
- overviewRecord *current = NULL;
- bool nodeFound = false;
-
- // Do a linear search of the nodes for this nodeName.
- // Yes, I know this is slow but the current word is ten
- // nodes would be a huge cluster so this should not
- // be a problem
- //
- for (int i = 0; i < numHosts; i++) {
- current = (overviewRecord *)sortRecords[i];
- if (strcmp(nodeName, current->hostname) == 0) {
- nodeFound = true;
- break;
- }
- }
-
- if (nodeFound == true) {
- return current;
- } else {
- return NULL;
- }
-}
-
-// MgmtString overviewPage::readString(const char* nodeName, char* *name, bool *found = NULL)
-//
-// Looks up a node record for a specific by nodeName
-// CALLEE deallocates the string with free()
-//
-MgmtString
-overviewPage::readString(const char *nodeName, const char *name, bool *found)
-{
- MgmtString r = NULL;
- // bool nodeFound = false;
- bool valueFound = false;
- overviewRecord *node;
-
- ink_mutex_acquire(&accessLock);
-
- node = this->findNodeByName(nodeName);
-
- if (node != NULL) {
- r = node->readString(name, &valueFound);
- }
- ink_mutex_release(&accessLock);
-
- if (found != NULL) {
- *found = valueFound;
- }
-
- return r;
-}
-
-// MgmtInt overviewPage::readInteger(const char* nodeName, char* *name, bool *found = NULL)
-//
-// Looks up a node record for a specific by nodeName
-//
-MgmtInt
-overviewPage::readInteger(const char *nodeName, const char *name, bool *found)
-{
- MgmtInt r = -1;
- // bool nodeFound = false;
- bool valueFound = false;
- overviewRecord *node;
-
- ink_mutex_acquire(&accessLock);
-
- node = this->findNodeByName(nodeName);
-
- if (node != NULL) {
- r = node->readInteger(name, &valueFound);
- }
- ink_mutex_release(&accessLock);
-
- if (found != NULL) {
- *found = valueFound;
- }
-
- return r;
-}
-
-// MgmtFloat overviewPage::readFloat(const char* nodeName, char* *name, bool *found = NULL)
-//
-// Looks up a node record for a specific by nodeName
-//
-RecFloat
-overviewPage::readFloat(const char *nodeName, const char *name, bool *found)
-{
- RecFloat r = -1.0;
- // bool nodeFound = false;
- bool valueFound = false;
- overviewRecord *node;
-
- ink_mutex_acquire(&accessLock);
-
- node = this->findNodeByName(nodeName);
-
- if (node != NULL) {
- r = node->readFloat(name, &valueFound);
- }
- ink_mutex_release(&accessLock);
-
- if (found != NULL) {
- *found = valueFound;
- }
-
- return r;
-}
-
-// int overviewPage::clusterSumData(RecDataT varType, const char* nodeVar,
-// RecData* sum)
-//
-// Sums nodeVar for every up node in the cluster and stores the
-// sum in *sum. Returns the number of nodes summed over
-//
-// CALLEE MUST HOLD this->accessLock
-//
-int
-overviewPage::clusterSumData(RecDataT varType, const char *nodeVar, RecData *sum)
-{
- int numUsed = 0;
- int numHosts_local = sortRecords.getNumEntries();
- overviewRecord *current;
- bool found;
- RecData recTmp;
-
- ink_assert(sum != NULL);
- RecDataClear(varType, sum);
-
- for (int i = 0; i < numHosts_local; i++) {
- current = (overviewRecord *)sortRecords[i];
- if (current->up == true) {
- numUsed++;
- recTmp = current->readData(varType, nodeVar, &found);
- *sum = RecDataAdd(varType, *sum, recTmp);
- if (found == false) {
- }
- }
- }
- return numUsed;
-}
-
-int
-overviewPage::varClusterDataFromName(RecDataT varType, char *nodeVar, RecData *sum)
-{
- int status = 0;
-
- ink_mutex_acquire(&accessLock);
-
- status = clusterSumData(varType, nodeVar, sum);
-
- ink_mutex_release(&accessLock);
-
- return (status);
-}
-
-// Moved from the now removed StatAggregation.cc
-void
-AgFloat_generic_scale_to_int(const char *processVar, const char *nodeVar, double factor)
-{
- MgmtFloat tmp;
-
- if (varFloatFromName(processVar, &tmp)) {
- tmp = tmp * factor;
- tmp = tmp + 0.5; // round up.
- varSetInt(nodeVar, (int)tmp);
- } else {
- varSetInt(nodeVar, -20);
- }
-}
-
-// char* overviewPage::resolvePeerHostname(char* peerIP)
-//
-// A locking interface to overviewPage::resolvePeerHostname_ml
-//
-char *
-overviewPage::resolvePeerHostname(const char *peerIP)
-{
- char *r;
-
- ink_mutex_acquire(&accessLock);
- r = this->resolvePeerHostname_ml(peerIP);
- ink_mutex_release(&accessLock);
-
- return r;
-}
-
-// char* overviewPage::resolvePeerHostname_ml(char* peerIP)
-//
-// Resolves the peer the hostname from its IP address
-// The hostname is resolved by finding the overviewRecord
-// Associated with the IP address and copying its hostname
-//
-// CALLEE frees storage
-// CALLEE is responsible for locking
-//
-char *
-overviewPage::resolvePeerHostname_ml(const char *peerIP)
-{
- unsigned long int ipAddr;
- InkHashTableValue lookup;
- overviewRecord *peerRecord;
- char *returnName = NULL;
-
- ipAddr = inet_addr(peerIP);
-
- // Check to see if our address is malformed
- if ((long int)ipAddr == -1) {
- return NULL;
- }
-
- if (ink_hash_table_lookup(nodeRecords, (InkHashTableKey)ipAddr, &lookup)) {
- peerRecord = (overviewRecord *)lookup;
- returnName = ats_strdup(peerRecord->hostname);
- }
-
- return returnName;
-}
-
-// int hostSortFunc(const void* arg1, const void* arg2)
-//
-// A compare function that we can to qsort that sorts
-// overviewRecord*
-//
-int
-hostSortFunc(const void *arg1, const void *arg2)
-{
- overviewRecord *rec1 = (overviewRecord *)*(void **)arg1;
- overviewRecord *rec2 = (overviewRecord *)*(void **)arg2;
-
- return strcmp(rec1->hostname, rec2->hostname);
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/mgmt/web2/WebOverview.h
----------------------------------------------------------------------
diff --git a/mgmt/web2/WebOverview.h b/mgmt/web2/WebOverview.h
deleted file mode 100644
index 928a446..0000000
--- a/mgmt/web2/WebOverview.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#ifndef _WEB_OVERVIEW_H_
-#define _WEB_OVERVIEW_H_
-
-#include "ink_hash_table.h"
-#include "ink_mutex.h"
-#include "WebGlobals.h"
-#include "TextBuffer.h"
-#include "List.h"
-
-#include "WebHttpContext.h"
-#include "WebHttpMessage.h"
-#include "ExpandingArray.h"
-#include "ClusterCom.h"
-
-#include "P_RecCore.h"
-
-/****************************************************************************
- *
- * WebOverview.h - code to overview page
- *
- *
- ****************************************************************************/
-
-//
-// There is one instance of the class overviewPage in the LocalManger
-// process. The overviewPage instance stores a record of type
-// overviewRecord for each node that has been seen in the cluster.
-// The node records contain a list of active alarms on that node.
-//
-// overviewPage is responsible for the synchronization issues for both
-// it self and all of its overviewRecords. Whenever updates are made
-// to instances of either class, overviewPage's accessLock must be held.
-//
-// Pointers to overviewRecords are stored in overviewPage::nodeRecords
-// hash table which is indexed on the nodes ip address (as an
-// unsigned long). A second mapping is also maintained in sortRecords.
-//
-//
-// Additional Notes
-//
-// These classes have expanded over time. overviewPage and
-// overviewRecord are now clearing houses of cluster information
-// for the UI.
-// To simplify the locking issues, pointer to overviewRecords should
-// NOT be returned by overviewPage. overviewRecords are internal
-// to overviewPage and any data needed from an overviewRecord
-// should be returned as a copy (or a const ptr)
-// through an accessor function
-
-// information about a specific node in the cluster
-class overviewRecord
-{
-public:
- overviewRecord(unsigned long inet_addr, bool local, ClusterPeerInfo *cpi = NULL);
-
- ~overviewRecord();
-
- void updateStatus(time_t currentTime, ClusterPeerInfo *cpi);
-
- bool up;
- bool localNode;
- char *hostname; // FQ hostname of the node
- unsigned long inetAddr; // IP address of the node
- RecInt readInteger(const char *name, bool *found);
- RecFloat readFloat(const char *name, bool *found);
- RecString readString(const char *name, bool *found);
- RecData readData(RecDataT varType, const char *name, bool *found);
- bool varFloatFromName(const char *varName, RecFloat *value);
-
-private:
- RecRecords node_rec_data; // a copy from ClusterPeerInfo
- int recordArraySize; // the size of node_data.recs
- int node_rec_first_ix; // Kludge, but store the first order ix for later use
- overviewRecord(const overviewRecord &);
-};
-
-// information about the entire cluster
-class overviewPage
-{
-public:
- overviewPage();
- ~overviewPage();
-
- void checkForUpdates();
- char *resolvePeerHostname(const char *peerIP);
- char *resolvePeerHostname_ml(const char *peerIP);
- int getClusterHosts(ExpandingArray *hosts);
- MgmtInt readInteger(const char *nodeName, const char *name, bool *found = NULL);
- MgmtFloat readFloat(const char *nodeName, const char *name, bool *found = NULL);
- MgmtString readString(const char *nodeName, const char *name, bool *found = NULL);
- void addSelfRecord();
-
- int varClusterDataFromName(RecDataT varType, char *nodeVar, RecData *sum);
-
-private:
- ink_mutex accessLock;
-
- // Private fcns
- overviewPage(const overviewPage &);
- void addRecord(ClusterPeerInfo *cpi);
- overviewRecord *findNodeByName(const char *nodeName);
- void addReading(MgmtInt reading, textBuffer *output, int nDigits, const char **gifs, const char **alts);
- void addLoadBar(textBuffer *output, MgmtInt load);
- void sortHosts();
- bool moreInfoButton(const char *submission, textBuffer *output);
- void addHostPanel(WebHttpContext *whc, overviewRecord *host);
-
- // Private variables
- InkHashTable *nodeRecords; // container for overviewRecords
- unsigned long ourAddr; // the IP address of this node
- ExpandingArray sortRecords; // A second, sorted container for nodeRecords
- int numHosts; // number of peers we know about including ourself
-
- int clusterSumData(RecDataT varType, const char *nodeVar, RecData *sum);
-};
-
-extern overviewPage *overviewGenerator; // global handle to overiewPage?
- // defn found in WebOverview.cc
-
-int hostSortFunc(const void *arg1, const void *arg2);
-
-#endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/mgmt/web2/WebUtils.cc
----------------------------------------------------------------------
diff --git a/mgmt/web2/WebUtils.cc b/mgmt/web2/WebUtils.cc
deleted file mode 100644
index 32664aa..0000000
--- a/mgmt/web2/WebUtils.cc
+++ /dev/null
@@ -1,114 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#include "ink_config.h"
-
-#include "ink_assert.h"
-#include "ink_sock.h"
-#include "WebUtils.h"
-#include "WebGlobals.h"
-#include "MgmtUtils.h"
-
-/****************************************************************************
- *
- * WebUtils.cc - Misc Utility Functions for the web server internface
- *
- *
- *
- ****************************************************************************/
-
-#include <openssl/ssl.h>
-
-ssize_t
-socket_write(SocketInfo socketD, const char *buf, size_t nbyte)
-{
- if (socketD.SSLcon != NULL) {
- return SSL_write((SSL *)socketD.SSLcon, (char *)buf, nbyte);
- } else {
- return write_socket(socketD.fd, buf, nbyte);
- }
- return -1;
-}
-
-ssize_t
-socket_read(SocketInfo socketD, char *buf, size_t nbyte)
-{
- if (socketD.SSLcon != NULL) {
- return SSL_read((SSL *)socketD.SSLcon, (char *)buf, nbyte);
- } else {
- return read_socket(socketD.fd, buf, nbyte);
- }
- return -1;
-}
-
-
-// int sigfdreadln(int fd, char *s, int len)
-//
-// An inefficient way to read a line from a socket
-// within the constrants of the Web Administration
-// interface
-// reads from the passed in file descriptor to a
-// new line or until all space in the buffer is exhausted
-// returns the number of characters read
-//
-// Intentially, stops if the read is interrupted by a signal
-// The reaper will interupt us with a signal if we
-// are stuck
-//
-// Returns -1 if the read fails
-//
-int
-sigfdrdln(SocketInfo socketD, char *s, int len)
-{
- char c;
- int result;
- char *bufStart = s;
-
- do {
- do {
- result = socket_read(socketD, &c, 1);
- } while (result < 0 && errno == EAGAIN);
-
- // If we are out of bytes or there is an
- // error, we are done
- if (result < 0 || result == 0) {
- c = '\n';
- }
-
- *s++ = c;
- len--;
- } while (c != '\n' && len > 1);
-
- if (c == '\n') {
- s--;
- *s = '\0';
- } else {
- *s = '\0';
- }
-
- if (result < 0) {
- return -1;
- } else {
- return (s - bufStart);
- }
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/mgmt/web2/WebUtils.h
----------------------------------------------------------------------
diff --git a/mgmt/web2/WebUtils.h b/mgmt/web2/WebUtils.h
deleted file mode 100644
index 9a94f54..0000000
--- a/mgmt/web2/WebUtils.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#ifndef _WEB_UTILS_H_
-#define _WEB_UTILS_H_
-
-/****************************************************************************
- *
- * WebUtils.h - Misc Utility Functions for the web server internface
- *
- ****************************************************************************/
-
-#include "ink_platform.h"
-#include "MgmtDefs.h"
-
-struct WebContext;
-
-/* Ugly Hack - declare
- * SSLcon as void* instead of SSL since this prevents us from
- * including ssl.h right here which creates a whole bunch of
- * nasty problem to MD5 conflicts with ink_code.h.
- */
-struct SocketInfo {
- int fd;
- void *SSLcon; /* Currently unused */
-};
-
-ssize_t socket_write(SocketInfo socketD, const char *buf, size_t nbyte);
-ssize_t socket_read(SocketInfo socketD, char *buf, size_t nbyte);
-int sigfdrdln(SocketInfo socketD, char *s, int len);
-
-#endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/proxy/http/HttpConfig.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.cc b/proxy/http/HttpConfig.cc
index e3c5e17..8aeb13a 100644
--- a/proxy/http/HttpConfig.cc
+++ b/proxy/http/HttpConfig.cc
@@ -1159,7 +1159,6 @@ HttpConfig::startup()
// Local Manager
HttpEstablishStaticConfigLongLong(c.autoconf_port, "proxy.config.admin.autoconf_port");
- HttpEstablishStaticConfigByte(c.autoconf_localhost_only, "proxy.config.admin.autoconf.localhost_only");
// Cluster time delta gets it own callback since it needs
// to use ink_atomic_swap
@@ -1417,7 +1416,6 @@ HttpConfig::reconfigure()
// Local Manager
params->autoconf_port = m_master.autoconf_port;
- params->autoconf_localhost_only = m_master.autoconf_localhost_only;
m_id = configProcessor.set(m_id, params);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/proxy/http/HttpConfig.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.h b/proxy/http/HttpConfig.h
index 3bbba9f..81b4dcb 100644
--- a/proxy/http/HttpConfig.h
+++ b/proxy/http/HttpConfig.h
@@ -752,7 +752,6 @@ public:
// Local Manager //
////////////////////
MgmtInt autoconf_port;
- MgmtByte autoconf_localhost_only;
private:
/////////////////////////////////////
@@ -854,7 +853,7 @@ inline HttpConfigParams::HttpConfigParams()
cluster_time_delta(0), redirection_enabled(0), redirection_host_no_port(0), number_of_redirections(1), post_copy_size(2048),
ignore_accept_mismatch(0), ignore_accept_language_mismatch(0), ignore_accept_encoding_mismatch(0),
ignore_accept_charset_mismatch(0), send_100_continue_response(0), disallow_post_100_continue(0), parser_allow_non_http(1),
- cache_open_write_fail_action(0), max_post_size(0), autoconf_port(0), autoconf_localhost_only(0)
+ cache_open_write_fail_action(0), max_post_size(0), autoconf_port(0)
{
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f84df26f/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 0a346cd..cad0468 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -709,11 +709,10 @@ HttpTransact::StartRemapRequest(State *s)
const char syntxt[] = "synthetic.txt";
- s->cop_test_page =
- (ptr_len_cmp(host, host_len, local_host_ip_str, sizeof(local_host_ip_str) - 1) == 0) &&
- (ptr_len_cmp(path, path_len, syntxt, sizeof(syntxt) - 1) == 0) && port == s->http_config_param->autoconf_port &&
- s->method == HTTP_WKSIDX_GET && s->orig_scheme == URL_WKSIDX_HTTP &&
- (!s->http_config_param->autoconf_localhost_only || ats_ip4_addr_cast(&s->client_info.addr.sa) == htonl(INADDR_LOOPBACK));
+ s->cop_test_page = (ptr_len_cmp(host, host_len, local_host_ip_str, sizeof(local_host_ip_str) - 1) == 0) &&
+ (ptr_len_cmp(path, path_len, syntxt, sizeof(syntxt) - 1) == 0) &&
+ port == s->http_config_param->autoconf_port && s->method == HTTP_WKSIDX_GET &&
+ s->orig_scheme == URL_WKSIDX_HTTP && ats_ip4_addr_cast(&s->client_info.addr.sa) == htonl(INADDR_LOOPBACK);
//////////////////////////////////////////////////////////////////
// FIX: this logic seems awfully convoluted and hard to follow; //