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
/****************************************************************************
28
This implements a user-customizable response message generation system.
30
The concept is simple. Error/response messages are classified into
31
several types, each given a name, such as "request/header_error".
33
The HttpBodyFactory can build a message body for each response type.
34
The user can create custom message body text for each type (stored
35
in a text file directory), containing templates with space-holders for
36
variables which are inline-substituted with curent values. The resulting
37
body is dynamically allocated and returned.
39
The major data types implemented in this file are:
41
HttpBodyFactory The main data structure which is the machine
42
that maintains configuration information, reads
43
user error message template files, and performs
44
the substitution to generate the message bodies.
46
HttpBodySet The data structure representing a set of
47
templates, including the templates and metadata.
49
HttpBodyTemplate The template loaded from the directory to be
50
instantiated with variables, producing a body.
53
****************************************************************************/
55
#ifndef _HttpBodyFactory_h_
56
#define _HttpBodyFactory_h_
59
#include <sys/types.h>
62
#include "HttpConfig.h"
63
#include "HttpCompat.h"
64
#include "HttpTransact.h"
67
#include "RawHashTable.h"
70
#define HTTP_BODY_TEMPLATE_MAGIC 0xB0DFAC00
71
#define HTTP_BODY_SET_MAGIC 0xB0DFAC55
72
#define HTTP_BODY_FACTORY_MAGIC 0xB0DFACFF
74
////////////////////////////////////////////////////////////////////////
76
// class HttpBodyTemplate
78
// An HttpBodyTemplate object represents a template with HTML
79
// text, and unexpanded log fields. The object also has methods
80
// to dump out the contents of the template, and to instantiate
81
// the template into a buffer given a context.
83
////////////////////////////////////////////////////////////////////////
85
class HttpBodyTemplate
92
int load_from_file(char *dir, char *file);
95
return (magic == HTTP_BODY_TEMPLATE_MAGIC);
97
char *build_instantiated_buffer(HttpTransact::State * context, int64_t *length_return);
101
char *template_buffer;
102
char *template_pathname;
106
////////////////////////////////////////////////////////////////////////
110
// An HttpBodySet object represents a set of body factory
111
// templates. It includes operators to get the hash table of
112
// templates, and the associated metadata for the set.
114
// The raw data members come from HttpBodySetRawData, which
115
// is defined in proxy/hdrs/HttpCompat.h
117
////////////////////////////////////////////////////////////////////////
119
class HttpBodySet:public HttpBodySetRawData
125
int init(char *set_name, char *dir);
128
return (magic == HTTP_BODY_SET_MAGIC);
131
HttpBodyTemplate *get_template_by_name(const char *name);
132
void set_template_by_name(const char *name, HttpBodyTemplate * t);
136
////////////////////////////////////////////////////////////////////////
138
// class HttpBodyFactory
140
// An HttpBodyFactory object is the main object which keeps track
141
// of all the response body templates, and which provides the
142
// methods to create response bodies.
144
// Once an HttpBodyFactory object is initialized, and the template
145
// data has been loaded, the HttpBodyFactory object allows the
146
// caller to make error message bodies w/fabricate_with_old_api
148
////////////////////////////////////////////////////////////////////////
150
class HttpBodyFactory
156
///////////////////////
157
// primary user APIs //
158
///////////////////////
159
char *fabricate_with_old_api(const char *type, HttpTransact::State * context,
160
int64_t max_buffer_length, int64_t *resulting_buffer_length,
161
char* content_language_out_buf,
162
size_t content_language_buf_size,
163
char* content_type_out_buf,
164
size_t content_type_buf_size,
165
HTTPStatus status_code, const char *reason_or_null, const char *format, va_list ap);
167
char *fabricate_with_old_api_build_va(const char *type, HttpTransact::State * context,
168
int64_t max_buffer_length, int64_t *resulting_buffer_length,
169
char* content_language_out_buf,
170
size_t content_language_buf_size,
171
char* content_type_out_buf,
172
size_t content_type_buf_size,
173
HTTPStatus status_code, const char *reason_or_null, const char *format, ...)
176
va_start(ap, format);
177
return (fabricate_with_old_api(type, context, max_buffer_length,
178
resulting_buffer_length,
179
content_language_out_buf, content_language_buf_size,
180
content_type_out_buf, content_type_buf_size,
181
status_code, reason_or_null, format, ap));
184
void dump_template_tables(FILE * fp = stderr);
189
char *fabricate(StrList * acpt_language_list,
190
StrList * acpt_charset_list,
191
const char *type, HttpTransact::State * context,
192
int64_t *resulting_buffer_length,
193
const char **content_language_return,
194
const char **content_charset_return, const char **set_return = NULL);
196
const char *determine_set_by_language(StrList * acpt_language_list, StrList * acpt_charset_list);
197
HttpBodyTemplate *find_template(const char *set, const char *type, HttpBodySet ** body_set_return);
198
bool is_response_suppressed(HttpTransact::State * context);
201
return (magic == HTTP_BODY_FACTORY_MAGIC);
205
ink_assert(is_sane());
209
////////////////////////////
210
// initialization methods //
211
////////////////////////////
212
void nuke_template_tables();
213
RawHashTable *load_sets_from_directory(char *set_dir);
214
HttpBodySet *load_body_set_from_directory(char *set_name, char *tmpl_dir);
216
/////////////////////////////////////////////////
217
// internal data structure concurrency control //
218
/////////////////////////////////////////////////
221
ink_mutex_acquire(&mutex);
225
ink_mutex_release(&mutex);
228
/////////////////////////////////////
229
// manager configuration variables //
230
/////////////////////////////////////
231
int enable_customizations; // 0:no custom,1:custom,2:language-targeted
232
bool enable_logging; // the user wants body factory logging
233
char *directory_of_template_sets; // root directory for template sets
234
int response_suppression_mode; // when to suppress responses
239
unsigned int magic; // magic for sanity checks/debugging
240
ink_mutex mutex; // prevents reconfig/read races
241
bool callbacks_established; // all config variables present
242
RawHashTable *table_of_sets; // sets of template hash tables