3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
/****************************************************************************
29
****************************************************************************/
31
#include "ink_config.h"
32
#include "ProxyConfig.h"
33
#include "StatPages.h"
35
#include "MatcherUtils.h"
37
#define MAX_STAT_PAGES 32
41
StatPagesManager statPagesManager;
47
} stat_pages[MAX_STAT_PAGES];
49
static volatile int n_stat_pages = 0;
52
StatPagesManager::init()
54
REC_EstablishStaticConfigInt32(m_enabled, "proxy.config.http_ui_enabled");
58
StatPagesManager::register_http(const char *module, StatPagesFunc func)
60
ink_release_assert(n_stat_pages < MAX_STAT_PAGES);
62
stat_pages[n_stat_pages].module = (char *) xmalloc(strlen(module) + 3);
63
snprintf(stat_pages[n_stat_pages].module, strlen(module) + 3, "{%s}", module);
64
stat_pages[n_stat_pages++].func = func;
68
StatPagesManager::handle_http(Continuation * cont, HTTPHdr * header, int client_ip)
70
NOWARN_UNUSED(client_ip);
71
URL *url = header->url_get();
73
if (((m_enabled == 1 || m_enabled == 3) && is_cache_inspector_page(url)) ||
74
((m_enabled == 2 || m_enabled == 3) && is_stat_page(url) && !is_cache_inspector_page(url))) {
80
h = url->host_get(&host_len);
81
ink_strncpy(host, h, host_len >= 1023 ? 1024 : host_len + 1);
82
host_len = unescapifyStr(host);
84
for (i = 0; i < n_stat_pages; i++) {
85
if (ptr_len_cmp(host, host_len, stat_pages[i].module) == 0) {
86
return stat_pages[i].func(cont, header);
91
cont->handleEvent(STAT_PAGE_FAILURE, 0);
92
return ACTION_RESULT_DONE;
95
bool StatPagesManager::is_stat_page(URL * url)
98
const char *h = url->host_get(&length);
101
if (h == NULL || length < 2)
104
ink_strncpy(host, h, length >= 1023 ? 1024 : length + 1);
105
length = unescapifyStr(host);
107
if ((host[0] == '{') && (host[length - 1] == '}'))
113
bool StatPagesManager::is_cache_inspector_page(URL * url)
116
const char *h = url->host_get(&length);
119
if (h == NULL || length < 2)
122
ink_strncpy(host, h, length >= 1023 ? 1024 : length + 1);
124
length = unescapifyStr(host);
126
if (strncmp(host, "{cache}", length) == 0)
134
BaseStatPagesHandler::resp_clear()
146
BaseStatPagesHandler::resp_add(const char *fmt, ...)
154
length = vsnprintf(buf, 16384, fmt, args);
157
size = response_size;
161
while ((response_length + length + 1) > size) {
165
if (size != response_size) {
167
response = (char *) xmalloc(size);
169
response = (char *) xrealloc(response, size);
171
response_size = size;
174
memcpy(&response[response_length], buf, length + 1);
175
response_length += length;
179
BaseStatPagesHandler::resp_add_sep()
181
resp_add("<hr width=\"100%%\">\n");
185
BaseStatPagesHandler::resp_begin(const char *title)
189
"<head><title>%s</title></head>\n"
190
"<body text=\"#000000\" bgcolor=\"#ffffff\" link=\"#0000ee\" vlink=\"#551a8b\" alink=\"#ff0000\">\n", title);
194
BaseStatPagesHandler::resp_end()
196
resp_add("</body>\n" "</html>\n");
200
BaseStatPagesHandler::resp_begin_numbered()
206
BaseStatPagesHandler::resp_end_numbered()
212
BaseStatPagesHandler::resp_begin_unnumbered()
218
BaseStatPagesHandler::resp_end_unnumbered()
224
BaseStatPagesHandler::resp_begin_item()
230
BaseStatPagesHandler::resp_end_item()
236
BaseStatPagesHandler::resp_begin_table(int border, int columns, int percent)
238
resp_add("<table border=%d cols=%d width=\"%d%%\">\n", border, columns, percent);
242
BaseStatPagesHandler::resp_end_table()
244
resp_add("</table>\n");
248
BaseStatPagesHandler::resp_begin_row()
254
BaseStatPagesHandler::resp_end_row()
260
BaseStatPagesHandler::resp_begin_column(int percent, const char *align)
263
resp_add("<td %s%s>\n", align ? "align=" : "", align ? align : "");
265
resp_add("<td width=\"%d%%\" %s%s>\n", percent, align ? "align=" : "", align ? align : "");
270
BaseStatPagesHandler::resp_end_column()