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 2011/03/03 04:30:54 UTC
svn commit: r1076511 - in /trafficserver/traffic/trunk: mgmt/preparse/
proxy/ proxy/api/ts/ proxy/hdrs/ proxy/http/ proxy/http/remap/
Author: zwoop
Date: Thu Mar 3 03:30:53 2011
New Revision: 1076511
URL: http://svn.apache.org/viewvc?rev=1076511&view=rev
Log:
TS-675 Make redirect and reverse maps work again.
This restores the old functionality, but also cleans up
the code a fair amount. It's still suboptimal, but better.
Modified:
trafficserver/traffic/trunk/mgmt/preparse/RemapReadConfig.cc
trafficserver/traffic/trunk/proxy/InkAPI.cc
trafficserver/traffic/trunk/proxy/ReverseProxy.cc
trafficserver/traffic/trunk/proxy/ReverseProxy.h
trafficserver/traffic/trunk/proxy/api/ts/ts.h.in
trafficserver/traffic/trunk/proxy/hdrs/HdrHeap.cc
trafficserver/traffic/trunk/proxy/hdrs/URL.h
trafficserver/traffic/trunk/proxy/http/HttpTransact.cc
trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc
trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc
trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.h
Modified: trafficserver/traffic/trunk/mgmt/preparse/RemapReadConfig.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/mgmt/preparse/RemapReadConfig.cc?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/mgmt/preparse/RemapReadConfig.cc (original)
+++ trafficserver/traffic/trunk/mgmt/preparse/RemapReadConfig.cc Thu Mar 3 03:30:53 2011
@@ -113,12 +113,9 @@ parseRemapFile(int fd)
fromScheme = fromURL.scheme_get(&fromSchemeLen);
toScheme = toURL.scheme_get(&toSchemeLen);
- if ((fromScheme != URL_SCHEME_HTTP
- && fromScheme != URL_SCHEME_HTTPS
- && fromScheme != URL_SCHEME_MMS && fromScheme != URL_SCHEME_RTSP) ||
- (toScheme != URL_SCHEME_HTTP
- && toScheme != URL_SCHEME_HTTPS && toScheme != URL_SCHEME_MMS && toScheme != URL_SCHEME_RTSP)) {
- err = "Only http, https, mms, and rtsp remappings are supported";
+ if ((fromScheme != URL_SCHEME_HTTP && fromScheme != URL_SCHEME_HTTPS) ||
+ (toScheme != URL_SCHEME_HTTP && toScheme != URL_SCHEME_HTTPS)) {
+ err = "Only http and https remappings are supported";
goto FAIL;
}
// Check to see if we have a complete URL, if not
Modified: trafficserver/traffic/trunk/proxy/InkAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/InkAPI.cc?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/InkAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/InkAPI.cc Thu Mar 3 03:30:53 2011
@@ -106,10 +106,15 @@ tsapi const char *TS_URL_SCHEME_MAILTO;
tsapi const char *TS_URL_SCHEME_NEWS;
tsapi const char *TS_URL_SCHEME_NNTP;
tsapi const char *TS_URL_SCHEME_PROSPERO;
-tsapi const char *TS_URL_SCHEME_RTSP;
-tsapi const char *TS_URL_SCHEME_RTSPU;
tsapi const char *TS_URL_SCHEME_TELNET;
+tsapi const char *TS_URL_SCHEME_TUNNEL;
tsapi const char *TS_URL_SCHEME_WAIS;
+tsapi const char *TS_URL_SCHEME_PNM;
+tsapi const char *TS_URL_SCHEME_RTSP;
+tsapi const char *TS_URL_SCHEME_RTSPU;
+tsapi const char *TS_URL_SCHEME_MMS;
+tsapi const char *TS_URL_SCHEME_MMSU;
+tsapi const char *TS_URL_SCHEME_MMST;
/* URL schemes string lengths */
tsapi int TS_URL_LEN_FILE;
@@ -122,7 +127,14 @@ tsapi int TS_URL_LEN_NEWS;
tsapi int TS_URL_LEN_NNTP;
tsapi int TS_URL_LEN_PROSPERO;
tsapi int TS_URL_LEN_TELNET;
+tsapi int TS_URL_LEN_TUNNEL;
tsapi int TS_URL_LEN_WAIS;
+tsapi int TS_URL_LEN_PNM;
+tsapi int TS_URL_LEN_RTSP;
+tsapi int TS_URL_LEN_RTSPU;
+tsapi int TS_URL_LEN_MMS;
+tsapi int TS_URL_LEN_MMSU;
+tsapi int TS_URL_LEN_MMST;
/* MIME fields */
tsapi const char *TS_MIME_FIELD_ACCEPT;
Modified: trafficserver/traffic/trunk/proxy/ReverseProxy.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ReverseProxy.cc?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ReverseProxy.cc (original)
+++ trafficserver/traffic/trunk/proxy/ReverseProxy.cc Thu Mar 3 03:30:53 2011
@@ -93,19 +93,34 @@ init_reverse_proxy()
// odd ball configs, for example if you use the "CONNECT" method, or if you set
// set proxy.config.url_remap.url_remap_mode to "2" (which is a completely undocumented "feature").
bool
-request_url_remap(HttpTransact::State * s, HTTPHdr * request_header, char **redirect_url, char **orig_url, char *tag,
+request_url_remap(HttpTransact::State * s, HTTPHdr * request_header, char **redirect_url, char **orig_url,
unsigned int filter_mask)
{
NOWARN_UNUSED(s);
NOWARN_UNUSED(request_header);
NOWARN_UNUSED(redirect_url);
NOWARN_UNUSED(orig_url);
- NOWARN_UNUSED(tag);
NOWARN_UNUSED(filter_mask);
return false;
// return rewrite_table ? rewrite_table->Remap(s, request_header, redirect_url, orig_url, tag, filter_mask) : false;
}
+/**
+ This function is used to figure out if a URL needs to be remapped
+ according to the rules in remap.config.
+*/
+mapping_type
+request_url_remap_redirect(HTTPHdr *request_header, URL *redirect_url, char **orig_url)
+{
+ return rewrite_table ? rewrite_table->Remap_redirect(request_header, redirect_url, orig_url) : NONE;
+}
+
+bool
+response_url_remap(HTTPHdr *response_header)
+{
+ return rewrite_table ? rewrite_table->ReverseMap(response_header) : false;
+}
+
//
//
Modified: trafficserver/traffic/trunk/proxy/ReverseProxy.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ReverseProxy.h?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ReverseProxy.h (original)
+++ trafficserver/traffic/trunk/proxy/ReverseProxy.h Thu Mar 3 03:30:53 2011
@@ -57,10 +57,11 @@ int init_reverse_proxy();
// Both Return true if a remapping was made and false otherwise
// ebalsa@ Y! -- this happens in the remapProcessor now for the reverse proxy case (not CDN or BlindTunnel)
-bool request_url_remap(HttpTransact::State * s,
- HTTPHdr * request_header,
- char **redirect_url,
- char **orig_url, char *tag = NULL, unsigned int filter_mask = URL_REMAP_FILTER_NONE);
+bool request_url_remap(HttpTransact::State *s, HTTPHdr *request_header, char **redirect_url, char **orig_url,
+ unsigned int filter_mask = URL_REMAP_FILTER_NONE);
+
+mapping_type request_url_remap_redirect(HTTPHdr *request_header, URL *redirect_url, char **orig_url);
+bool response_url_remap(HTTPHdr *response_header);
// Reload Functions
void reloadUrlRewrite();
Modified: trafficserver/traffic/trunk/proxy/api/ts/ts.h.in
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/api/ts/ts.h.in?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/api/ts/ts.h.in (original)
+++ trafficserver/traffic/trunk/proxy/api/ts/ts.h.in Thu Mar 3 03:30:53 2011
@@ -665,7 +665,14 @@ extern "C"
extern tsapi const char* TS_URL_SCHEME_NNTP;
extern tsapi const char* TS_URL_SCHEME_PROSPERO;
extern tsapi const char* TS_URL_SCHEME_TELNET;
+ extern tsapi const char* TS_URL_SCHEME_TUNNEL;
extern tsapi const char* TS_URL_SCHEME_WAIS;
+ extern tsapi const char* TS_URL_SCHEME_PNM;
+ extern tsapi const char* TS_URL_SCHEME_RTSP;
+ extern tsapi const char* TS_URL_SCHEME_RTSPU;
+ extern tsapi const char* TS_URL_SCHEME_MMS;
+ extern tsapi const char* TS_URL_SCHEME_MMSU;
+ extern tsapi const char* TS_URL_SCHEME_MMST;
/* --------------------------------------------------------------------------
URL scheme string lengths */
Modified: trafficserver/traffic/trunk/proxy/hdrs/HdrHeap.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/hdrs/HdrHeap.cc?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/hdrs/HdrHeap.cc (original)
+++ trafficserver/traffic/trunk/proxy/hdrs/HdrHeap.cc Thu Mar 3 03:30:53 2011
@@ -91,7 +91,6 @@ obj_describe(HdrHeapObjImpl * obj, bool
inline void
HdrHeap::init()
{
-
m_data_start = m_free_start = ((char *) this) + HDR_HEAP_HDR_SIZE;
m_magic = HDR_BUF_MAGIC_ALIVE;
m_writeable = true;
@@ -122,7 +121,6 @@ HdrHeap::init()
HdrHeap *
new_HdrHeap(int size)
{
-
HdrHeap *h;
if (size <= HDR_HEAP_DEFAULT_SIZE) {
size = HDR_HEAP_DEFAULT_SIZE;
@@ -146,7 +144,6 @@ new_HdrHeap(int size)
HdrStrHeap *
new_HdrStrHeap(int requested_size)
{
-
// The callee is asking for a string heap to be created
// that can allocate at least size bytes. As such we,
// need to include the size of the string heap header in
@@ -185,7 +182,6 @@ new_HdrStrHeap(int requested_size)
void
HdrHeap::destroy()
{
-
if (m_next) {
m_next->destroy();
}
@@ -205,7 +201,6 @@ HdrHeap::destroy()
HdrHeapObjImpl *
HdrHeap::allocate_obj(int nbytes, int type)
{
-
char *new_space;
HdrHeapObjImpl *obj;
@@ -222,7 +217,6 @@ HdrHeap::allocate_obj(int nbytes, int ty
while (1) {
-
if ((unsigned) nbytes <= (h->m_free_size)) {
new_space = h->m_free_start;
h->m_free_start += nbytes;
@@ -259,7 +253,6 @@ HdrHeap::deallocate_obj(HdrHeapObjImpl *
char *
HdrHeap::allocate_str(int nbytes)
{
-
int last_size = 0;
char *new_space = NULL;
ink_assert(m_writeable);
@@ -320,14 +313,12 @@ FAILED:
char *
HdrHeap::expand_str(const char *old_str, int old_len, int new_len)
{
-
char *rw_ptr = (char *) m_read_write_heap.m_ptr;
if (rw_ptr) {
// First check to see the old string is in this read-write string
// heap
if (old_str >= rw_ptr + STR_HEAP_HDR_SIZE && old_str < rw_ptr + m_read_write_heap->m_heap_size) {
-
// We're in the heap. Try to grow the string
char *r = m_read_write_heap->expand((char *) old_str, old_len, new_len);
if (r) {
@@ -362,7 +353,6 @@ HdrHeap::duplicate_str(const char *str,
int
HdrHeap::demote_rw_str_heap()
{
-
// First, see if we have any open slots for read
// only heaps
for (int i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
@@ -395,7 +385,6 @@ HdrHeap::demote_rw_str_heap()
void
HdrHeap::coalesce_str_heaps(int incoming_size)
{
-
int new_heap_size = incoming_size;
ink_assert(incoming_size >= 0);
ink_assert(m_writeable);
@@ -438,7 +427,6 @@ HdrHeap::coalesce_str_heaps(int incoming
void
HdrHeap::evacuate_from_str_heaps(HdrStrHeap * new_heap)
{
-
// printf("Str Evac\n");
// Loop over the objects in heap and call the evacuation
// function in each one
@@ -483,7 +471,6 @@ HdrHeap::evacuate_from_str_heaps(HdrStrH
void
HdrHeap::sanity_check_strs()
{
-
int num_heaps = 0;
struct HeapCheck heaps[HDR_BUF_RONLY_HEAPS + 1];
@@ -499,7 +486,6 @@ HdrHeap::sanity_check_strs()
for (int i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
if (m_ronly_heap[i].m_heap_start != NULL) {
-
heaps[num_heaps].start = m_ronly_heap[i].m_heap_start;
heaps[num_heaps].end = m_ronly_heap[i].m_heap_start + m_ronly_heap[i].m_heap_len;
num_heaps++;
@@ -555,7 +541,6 @@ HdrHeap::sanity_check_strs()
int
HdrHeap::marshal_length()
{
-
int len;
// If there is more than one HdrHeap block, we'll
@@ -590,7 +575,6 @@ HdrHeap::marshal_length()
static uint32_t
compute_checksum(void *buf, int len)
{
-
uint32_t cksum = 0;
while (len > 4) {
@@ -623,7 +607,6 @@ compute_checksum(void *buf, int len)
int
HdrHeap::marshal(char *buf, int len)
{
-
ink_assert((((uintptr_t) buf) & HDR_PTR_ALIGNMENT_MASK) == 0);
HdrHeap *marshal_hdr = (HdrHeap *) buf;
@@ -731,7 +714,6 @@ HdrHeap::marshal(char *buf, int len)
for (i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
if (m_ronly_heap[i].m_heap_start != NULL) {
-
if (m_ronly_heap[i].m_heap_len > len) {
goto Failed;
}
@@ -832,7 +814,6 @@ Failed:
bool
HdrHeap::check_marshalled(uint32_t buf_length)
{
-
if (this->m_magic != HDR_BUF_MAGIC_MARSHALED) {
return false;
}
@@ -987,7 +968,6 @@ HdrHeap::unmarshal(int buf_length, int o
inline int
HdrHeap::attach_str_heap(char *h_start, int h_len, RefCountObj * h_ref_obj, int *index)
{
-
// Loop over existing entries to see if this one is already present
for (int z = 0; z < *index; z++) {
if (m_ronly_heap[z].m_heap_start == h_start) {
@@ -1025,7 +1005,6 @@ HdrHeap::attach_str_heap(char *h_start,
void
HdrHeap::inherit_string_heaps(const HdrHeap * inherit_from)
{
-
// if heaps are the same, this is a no-op
if (inherit_from == (const HdrHeap *) this)
return;
@@ -1076,7 +1055,6 @@ HdrHeap::inherit_string_heaps(const HdrH
// are put into the heap
coalesce_str_heaps(inherit_str_size);
} else {
-
// Copy over read/write string heap if it exists
if (inherit_from->m_read_write_heap) {
int str_size = inherit_from->m_read_write_heap->m_heap_size -
@@ -1107,7 +1085,6 @@ HdrHeap::inherit_string_heaps(const HdrH
void
HdrHeap::dump_heap(int len)
{
-
int count = 0;
char *tmp = (char *) this;
char *end;
@@ -1147,7 +1124,6 @@ HdrHeap::dump_heap(int len)
void
HdrStrHeap::free()
{
-
if (m_heap_size == HDR_STR_HEAP_DEFAULT_SIZE) {
strHeapAllocator.free_void(this);
} else {
@@ -1183,7 +1159,6 @@ HdrStrHeap::allocate(int nbytes)
char *
HdrStrHeap::expand(char *ptr, int old_size, int new_size)
{
-
unsigned int expand_size = new_size - old_size;
ink_assert(ptr >= ((char *) this) + STR_HEAP_HDR_SIZE);
@@ -1217,7 +1192,6 @@ struct StrTest
static void
hdr_heap_test_verify(StrTest * str_test, int n)
{
-
for (int i = 0; i < n; i++) {
char *ptr = str_test[i].ptr;
int len = str_test[i].len;
@@ -1240,7 +1214,6 @@ hdr_heap_test_verify(StrTest * str_test,
void
hdr_heap_test()
{
-
Note("Starting hdr heap test");
HdrHeap *h = new_HdrHeap();
Modified: trafficserver/traffic/trunk/proxy/hdrs/URL.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/hdrs/URL.h?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/hdrs/URL.h (original)
+++ trafficserver/traffic/trunk/proxy/hdrs/URL.h Thu Mar 3 03:30:53 2011
@@ -77,12 +77,12 @@ struct URLImpl:public HdrHeapObjImpl
// 8 bytes + 1 bit, will result in padding
// Marshaling Functions
- int marshal(MarshalXlate * str_xlate, int num_xlate);
+ int marshal(MarshalXlate *str_xlate, int num_xlate);
void unmarshal(intptr_t offset);
- void move_strings(HdrStrHeap * new_heap);
+ void move_strings(HdrStrHeap *new_heap);
// Sanity Check Functions
- void check_strings(HeapCheck * heaps, int num_heaps);
+ void check_strings(HeapCheck *heaps, int num_heaps);
};
@@ -148,62 +148,62 @@ extern int url_hash_method;
/* Private */
-void url_adjust(MarshalXlate * str_xlate, int num_xlate);
+void url_adjust(MarshalXlate *str_xlate, int num_xlate);
/* Public */
void url_init();
-URLImpl *url_create(HdrHeap * heap);
-void url_clear(URLImpl * url_impl);
-void url_nuke_proxy_stuff(URLImpl * d_url);
-
-URLImpl *url_copy(URLImpl * s_url, HdrHeap * s_heap, HdrHeap * d_heap, bool inherit_strs = true);
-void url_copy_onto(URLImpl * s_url, HdrHeap * s_heap, URLImpl * d_url, HdrHeap * d_heap, bool inherit_strs = true);
-void url_copy_onto_as_server_url(URLImpl * s_url, HdrHeap * s_heap,
- URLImpl * d_url, HdrHeap * d_heap, bool inherit_strs = true);
-
-int url_print(URLImpl * u, char *buf, int bufsize, int *bufindex, int *dumpoffset);
-void url_describe(HdrHeapObjImpl * raw, bool recurse);
-
-int url_length_get(URLImpl * url);
-char *url_string_get(URLImpl * url, Arena * arena, int *length, HdrHeap * heap);
-void url_clear_string_ref(URLImpl * url);
-char *url_string_get_ref(HdrHeap * heap, URLImpl * url, int *length);
-void url_called_set(URLImpl * url);
-char *url_string_get_buf(URLImpl * url, char *dstbuf, int dstbuf_size, int *length);
-
-const char *url_scheme_get(URLImpl * url, int *length);
-void url_MD5_get(URLImpl * url, INK_MD5 * md5);
-void url_host_MD5_get(URLImpl * url, INK_MD5 * md5);
-const char *url_scheme_set(HdrHeap * heap, URLImpl * url,
+URLImpl *url_create(HdrHeap *heap);
+void url_clear(URLImpl *url_impl);
+void url_nuke_proxy_stuff(URLImpl *d_url);
+
+URLImpl *url_copy(URLImpl *s_url, HdrHeap *s_heap, HdrHeap *d_heap, bool inherit_strs = true);
+void url_copy_onto(URLImpl *s_url, HdrHeap *s_heap, URLImpl *d_url, HdrHeap *d_heap, bool inherit_strs = true);
+void url_copy_onto_as_server_url(URLImpl *s_url, HdrHeap *s_heap,
+ URLImpl *d_url, HdrHeap *d_heap, bool inherit_strs = true);
+
+int url_print(URLImpl *u, char *buf, int bufsize, int *bufindex, int *dumpoffset);
+void url_describe(HdrHeapObjImpl *raw, bool recurse);
+
+int url_length_get(URLImpl *url);
+char *url_string_get(URLImpl *url, Arena *arena, int *length, HdrHeap *heap);
+void url_clear_string_ref(URLImpl *url);
+char *url_string_get_ref(HdrHeap *heap, URLImpl *url, int *length);
+void url_called_set(URLImpl *url);
+char *url_string_get_buf(URLImpl *url, char *dstbuf, int dstbuf_size, int *length);
+
+const char *url_scheme_get(URLImpl *url, int *length);
+void url_MD5_get(URLImpl *url, INK_MD5 *md5);
+void url_host_MD5_get(URLImpl *url, INK_MD5 *md5);
+const char *url_scheme_set(HdrHeap *heap, URLImpl *url,
const char *value, int value_wks_idx, int length, bool copy_string);
/* Internet specific */
-void url_user_set(HdrHeap * heap, URLImpl * url, const char *value, int length, bool copy_string);
-void url_password_set(HdrHeap * heap, URLImpl * url, const char *value, int length, bool copy_string);
-void url_host_set(HdrHeap * heap, URLImpl * url, const char *value, int length, bool copy_string);
-void url_port_set(HdrHeap * heap, URLImpl * url, unsigned int port);
+void url_user_set(HdrHeap *heap, URLImpl *url, const char *value, int length, bool copy_string);
+void url_password_set(HdrHeap *heap, URLImpl *url, const char *value, int length, bool copy_string);
+void url_host_set(HdrHeap *heap, URLImpl *url, const char *value, int length, bool copy_string);
+void url_port_set(HdrHeap *heap, URLImpl *url, unsigned int port);
/* HTTP specific */
-void url_path_set(HdrHeap * heap, URLImpl * url, const char *value, int length, bool copy_string);
+void url_path_set(HdrHeap *heap, URLImpl *url, const char *value, int length, bool copy_string);
-void url_type_set(URLImpl * url, unsigned int type);
+void url_type_set(URLImpl *url, unsigned int type);
/* HTTP specific */
-void url_params_set(HdrHeap * heap, URLImpl * url, const char *value, int length, bool copy_string);
-void url_query_set(HdrHeap * heap, URLImpl * url, const char *value, int length, bool copy_string);
-void url_fragment_set(HdrHeap * heap, URLImpl * url, const char *value, int length, bool copy_string);
+void url_params_set(HdrHeap *heap, URLImpl *url, const char *value, int length, bool copy_string);
+void url_query_set(HdrHeap *heap, URLImpl *url, const char *value, int length, bool copy_string);
+void url_fragment_set(HdrHeap *heap, URLImpl *url, const char *value, int length, bool copy_string);
-MIMEParseResult url_parse(HdrHeap * heap, URLImpl * url, const char **start, const char *end, bool copy_strings);
-MIMEParseResult url_parse_no_path_component_breakdown(HdrHeap * heap, URLImpl * url,
+MIMEParseResult url_parse(HdrHeap *heap, URLImpl *url, const char **start, const char *end, bool copy_strings);
+MIMEParseResult url_parse_no_path_component_breakdown(HdrHeap *heap, URLImpl *url,
const char **start, const char *end, bool copy_strings);
-MIMEParseResult url_parse_internet(HdrHeap * heap, URLImpl * url,
+MIMEParseResult url_parse_internet(HdrHeap *heap, URLImpl *url,
const char **start, const char *end, bool copy_strings);
-MIMEParseResult url_parse_http(HdrHeap * heap, URLImpl * url, const char **start, const char *end, bool copy_strings);
-MIMEParseResult url_parse_http_no_path_component_breakdown(HdrHeap * heap, URLImpl * url,
+MIMEParseResult url_parse_http(HdrHeap *heap, URLImpl *url, const char **start, const char *end, bool copy_strings);
+MIMEParseResult url_parse_http_no_path_component_breakdown(HdrHeap *heap, URLImpl *url,
const char **start, const char *end, bool copy_strings);
-char *url_unescapify(Arena * arena, const char *str, int length);
+char *url_unescapify(Arena *arena, const char *str, int length);
inline int
url_canonicalize_port(int type, int port)
@@ -220,16 +220,16 @@ url_canonicalize_port(int type, int port
class URL:public HdrHeapSDKHandle
{
public:
- URLImpl * m_url_impl;
+ URLImpl *m_url_impl;
URL();
~URL();
int valid() const;
- void create(HdrHeap * h);
- void copy(const URL * url);
- void copy_shallow(const URL * url);
+ void create(HdrHeap *h);
+ void copy(const URL *url);
+ void copy_shallow(const URL *url);
void clear();
void reset();
// Note that URL::destroy() is inherited from HdrHeapSDKHandle.
@@ -239,11 +239,11 @@ public:
int length_get();
void clear_string_ref();
- char *string_get(Arena * arena, int *length = NULL);
+ char *string_get(Arena *arena, int *length = NULL);
char *string_get_ref(int *length = NULL);
char *string_get_buf(char *dstbuf, int dsbuf_size, int *length = NULL);
- void MD5_get(INK_MD5 * md5);
- void host_MD5_get(INK_MD5 * md5);
+ void MD5_get(INK_MD5 *md5);
+ void host_MD5_get(INK_MD5 *md5);
const char *scheme_get(int *length);
int scheme_get_wksidx();
@@ -277,7 +277,7 @@ public:
MIMEParseResult parse_no_path_component_breakdown(const char *str, int length);
public:
- static char *unescapify(Arena * arena, const char *str, int length);
+ static char *unescapify(Arena *arena, const char *str, int length);
private:
@@ -290,14 +290,17 @@ private:
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
-inline URL::URL():m_url_impl(NULL)
+inline
+URL::URL()
+ : m_url_impl(NULL)
{
}
/*-------------------------------------------------------------------------
-------------------------------------------------------------------------*/
-inline URL::~URL()
+inline
+URL::~URL()
{
}
@@ -314,7 +317,7 @@ URL::valid() const
-------------------------------------------------------------------------*/
inline void
-URL::create(HdrHeap * heap)
+URL::create(HdrHeap *heap)
{
if (heap) {
m_heap = heap;
@@ -329,7 +332,7 @@ URL::create(HdrHeap * heap)
-------------------------------------------------------------------------*/
inline void
-URL::copy(const URL * url)
+URL::copy(const URL *url)
{
ink_debug_assert(url->valid());
url_copy_onto(url->m_url_impl, url->m_heap, m_url_impl, m_heap);
@@ -339,7 +342,7 @@ URL::copy(const URL * url)
-------------------------------------------------------------------------*/
inline void
-URL::copy_shallow(const URL * url)
+URL::copy_shallow(const URL *url)
{
ink_debug_assert(url->valid());
this->set(url);
@@ -396,7 +399,7 @@ URL::length_get()
-------------------------------------------------------------------------*/
inline char *
-URL::string_get(Arena * arena_or_null_for_malloc, int *length)
+URL::string_get(Arena *arena_or_null_for_malloc, int *length)
{
ink_debug_assert(valid());
return url_string_get(m_url_impl, arena_or_null_for_malloc, length, m_heap);
@@ -430,7 +433,7 @@ URL::string_get_buf(char *dstbuf, int ds
-------------------------------------------------------------------------*/
inline void
-URL::MD5_get(INK_MD5 * md5)
+URL::MD5_get(INK_MD5 *md5)
{
ink_debug_assert(valid());
url_MD5_get(m_url_impl, md5);
@@ -440,7 +443,7 @@ URL::MD5_get(INK_MD5 * md5)
-------------------------------------------------------------------------*/
inline void
-URL::host_MD5_get(INK_MD5 * md5)
+URL::host_MD5_get(INK_MD5 *md5)
{
ink_debug_assert(valid());
url_host_MD5_get(m_url_impl, md5);
@@ -717,7 +720,7 @@ URL::parse_no_path_component_breakdown(c
-------------------------------------------------------------------------*/
inline char *
-URL::unescapify(Arena * arena, const char *str, int length)
+URL::unescapify(Arena *arena, const char *str, int length)
{
return url_unescapify(arena, str, length);
}
Modified: trafficserver/traffic/trunk/proxy/http/HttpTransact.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpTransact.cc?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpTransact.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpTransact.cc Thu Mar 3 03:30:53 2011
@@ -506,6 +506,7 @@ how_to_open_connection(HttpTransact::Sta
s->hdr_info.server_request.url_set(s->hdr_info.client_request.url_get());
// TODO yeah, not sure everything here is correct with redirects
+ // This probably doesn't work properly, since request_url_remap() is broken.
if (request_url_remap(s, &s->hdr_info.server_request, &remap_redirect, &s->unmapped_request_url)) {
ink_assert(!remap_redirect); // should not redirect in this code
HttpTransact::initialize_state_variables_for_origin_server(s, &s->hdr_info.server_request, true);
@@ -632,7 +633,8 @@ HttpTransact::HandleBlindTunnel(State* s
bool url_remap_success = false;
char *remap_redirect = NULL;
- // TODO take a look at this
+ // TODO: take a look at this
+ // This probably doesn't work properly, since request_url_remap() is broken.
if (url_remap_mode == URL_REMAP_DEFAULT || url_remap_mode == URL_REMAP_ALL) {
url_remap_success = request_url_remap(s, &s->hdr_info.client_request, &remap_redirect, &s->unmapped_request_url);
}
@@ -939,6 +941,16 @@ HttpTransact::EndRemapRequest(State* s)
s->server_info.is_transparent = s->state_machine->ua_session->get_netvc()->get_is_other_side_transparent();
done:
+ /**
+ * Since we don't want to return 404 Not Found error if there's
+ * redirect rule, the function to do redirect is moved before
+ * sending the 404 error.
+ **/
+ if (handleIfRedirect(s)) {
+ Debug("http_trans", "END HttpTransact::RemapRequest");
+ TRANSACT_RETURN(PROXY_INTERNAL_CACHE_NOOP, NULL);
+ }
+
if (s->reverse_proxy) {
Debug("url_rewrite", "s->reverse_proxy is true");
} else {
@@ -1087,6 +1099,55 @@ HttpTransact::ModifyRequest(State* s)
TRANSACT_RETURN(HTTP_API_READ_REQUEST_HDR, HttpTransact::StartRemapRequest);
}
+// This function is supposed to figure out if this transaction is
+// susceptible to a redirection as specified by remap.config
+bool
+HttpTransact::handleIfRedirect(State *s)
+{
+ int answer;
+ URL redirect_url;
+
+ answer = request_url_remap_redirect(&s->hdr_info.client_request, &redirect_url, &s->unmapped_request_url);
+ if ((answer == PERMANENT_REDIRECT) || (answer == TEMPORARY_REDIRECT)) {
+ int remap_redirect_len;
+ char *remap_redirect;
+
+ remap_redirect = redirect_url.string_get_ref(&remap_redirect_len);
+ if (answer == TEMPORARY_REDIRECT) {
+ if ((s->client_info).http_version.m_version == HTTP_VERSION(1, 1)) {
+ build_error_response(s, (HTTPStatus) 307,
+ /* which is HTTP/1.1 for HTTP_STATUS_MOVED_TEMPORARILY */
+ "Redirect", "redirect#moved_temporarily",
+ "%s <a href=\"%s\">%s</a>. %s",
+ "The document you requested is now",
+ remap_redirect, remap_redirect, "Please update your documents and bookmarks accordingly");
+ } else {
+ build_error_response(s,
+ HTTP_STATUS_MOVED_TEMPORARILY,
+ "Redirect",
+ "redirect#moved_temporarily",
+ "%s <a href=\"%s\">%s</a>. %s",
+ "The document you requested is now",
+ remap_redirect, remap_redirect, "Please update your documents and bookmarks accordingly");
+ }
+ } else {
+ build_error_response(s,
+ HTTP_STATUS_MOVED_PERMANENTLY,
+ "Redirect",
+ "redirect#moved_permanently",
+ "%s <a href=\"%s\">%s</a>. %s",
+ "The document you requested is now",
+ remap_redirect, remap_redirect, "Please update your documents and bookmarks accordingly");
+ }
+ s->hdr_info.client_response.value_set(MIME_FIELD_LOCATION, MIME_LEN_LOCATION, remap_redirect, remap_redirect_len);
+ redirect_url.destroy();
+ return true;
+ }
+
+ return false;
+}
+
+
void
HttpTransact::HandleRequest(State* s)
{
@@ -7957,6 +8018,13 @@ HttpTransact::build_response(State* s, H
HttpTransactHeaders::convert_response(outgoing_version, outgoing_response);
+ // process reverse mappings on the location header
+ HTTPStatus outgoing_status = outgoing_response->status_get();
+
+ if ((outgoing_status != 200) && (((outgoing_status >= 300) && (outgoing_status < 400)) || (outgoing_status == 201))) {
+ response_url_remap(outgoing_response);
+ }
+
if (s->http_config_param->enable_http_stats) {
if (s->hdr_info.server_response.valid() && s->http_config_param->wuts_enabled) {
int reason_len;
Modified: trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/RemapProcessor.cc Thu Mar 3 03:30:53 2011
@@ -41,7 +41,7 @@ RemapProcessor::start(int num_threads)
*/
bool
-RemapProcessor::setup_for_remap(HttpTransact::State * s)
+RemapProcessor::setup_for_remap(HttpTransact::State *s)
{
Debug("url_rewrite", "setting up for remap: %x", s);
URL *request_url = NULL;
@@ -49,7 +49,6 @@ RemapProcessor::setup_for_remap(HttpTran
HTTPHdr *request_header = &s->hdr_info.client_request;
char **redirect_url = &s->remap_redirect;
char **orig_url = &s->unmapped_request_url;
- char *tag = NULL;
const char *request_host;
int request_host_len;
int request_port;
@@ -84,7 +83,7 @@ RemapProcessor::setup_for_remap(HttpTran
Debug("url_rewrite", "[lookup] attempting %s lookup", proxy_request ? "proxy" : "normal");
- mapping_found = rewrite_table->forwardMappingLookup(request_url, request_port, request_host, request_host_len, s->url_map, tag);
+ mapping_found = rewrite_table->forwardMappingLookup(request_url, request_port, request_host, request_host_len, s->url_map);
if (!proxy_request) { // do extra checks on a server request
@@ -99,7 +98,7 @@ RemapProcessor::setup_for_remap(HttpTran
// If there's no host, we've already done this.
if (!mapping_found && rewrite_table->nohost_rules && request_host_len) {
Debug("url_rewrite", "[lookup] nothing matched");
- mapping_found = rewrite_table->forwardMappingLookup(request_url, 0, "", 0, s->url_map, tag);
+ mapping_found = rewrite_table->forwardMappingLookup(request_url, 0, "", 0, s->url_map);
}
if (mapping_found && orig_url) {
@@ -122,7 +121,7 @@ RemapProcessor::setup_for_remap(HttpTran
}
bool
-RemapProcessor::finish_remap(HttpTransact::State * s)
+RemapProcessor::finish_remap(HttpTransact::State *s)
{
url_mapping *map = NULL;
HTTPHdr *request_header = &s->hdr_info.client_request;
@@ -274,7 +273,7 @@ RemapProcessor::finish_remap(HttpTransac
}
Action *
-RemapProcessor::perform_remap(Continuation * cont, HttpTransact::State * s)
+RemapProcessor::perform_remap(Continuation *cont, HttpTransact::State *s)
{
Debug("url_rewrite", "Beginning RemapProcessor::perform_remap");
HTTPHdr *request_header = &s->hdr_info.client_request;
Modified: trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.cc Thu Mar 3 03:30:53 2011
@@ -712,9 +712,8 @@ UrlRewrite::PrintTable(InkHashTable * h_
*/
url_mapping *
UrlRewrite::_tableLookup(InkHashTable * h_table, URL * request_url,
- int request_port, char *request_host, int request_host_len, char *tag)
+ int request_port, char *request_host, int request_host_len)
{
- NOWARN_UNUSED(tag);
UrlMappingPathIndex *ht_entry;
url_mapping *um = NULL;
int ht_result;
@@ -729,9 +728,130 @@ UrlRewrite::_tableLookup(InkHashTable *
}
+// This is only used for redirects and reverse rules, and the homepageredirect flag
+// can never be set. The end result is that request_url is modified per remap container.
+void
+UrlRewrite::_doRemap(UrlMappingContainer &mapping_container, URL *request_url)
+{
+ const char *requestPath;
+ int requestPathLen;
+
+ url_mapping *mapPtr = mapping_container.getMapping();
+ URL *map_from = &mapPtr->fromURL;
+ int fromPathLen;
+
+ URL *map_to = mapping_container.getToURL();
+ const char *toHost;
+ const char *toPath;
+ int toPathLen;
+ int toHostLen;
+
+ requestPath = request_url->path_get(&requestPathLen);
+ map_from->path_get(&fromPathLen);
+
+ toHost = map_to->host_get(&toHostLen);
+ toPath = map_to->path_get(&toPathLen);
+
+ Debug("url_rewrite", "_doRemap(): Remapping rule id: %d matched", mapPtr->map_id);
+
+ request_url->host_set(toHost, toHostLen);
+ request_url->port_set(map_to->port_get_raw());
+
+ // Extra byte is potentially needed for prefix path '/'.
+ // Added an extra 3 so that TS wouldn't crash in the field.
+ // Allocate a large buffer to avoid problems.
+ // Need to figure out why we need the 3 bytes or 512 bytes.
+ char newPath[(requestPathLen - fromPathLen) + toPathLen + 8]; // Should be +3, little extra padding won't hurt
+ int newPathLen = 0;
+
+ *newPath = 0;
+ if (toPath) {
+ memcpy(newPath, toPath, toPathLen);
+ newPathLen += toPathLen;
+ }
+
+ // We might need to insert a trailing slash in the new portion of the path
+ // if more will be added and none is present and one will be needed.
+ if (!fromPathLen && requestPathLen && toPathLen && *(newPath + newPathLen - 1) != '/') {
+ *(newPath + newPathLen) = '/';
+ newPathLen++;
+ }
+
+ if (requestPath) {
+ //avoid adding another trailing slash if the requestPath already had one and so does the toPath
+ if (requestPathLen < fromPathLen) {
+ if (toPathLen && requestPath[requestPathLen - 1] == '/' && toPath[toPathLen - 1] == '/') {
+ fromPathLen++;
+ }
+ } else {
+ if (toPathLen && requestPath[fromPathLen] == '/' && toPath[toPathLen - 1] == '/') {
+ fromPathLen++;
+ }
+ }
+
+ // copy the end of the path past what has been mapped
+ if ((requestPathLen - fromPathLen) > 0) {
+ memcpy(newPath + newPathLen, requestPath + fromPathLen, requestPathLen - fromPathLen);
+ newPathLen += (requestPathLen - fromPathLen);
+ }
+ }
+
+ // Skip any leading / in the path when setting the new URL path
+ if (*newPath == '/') {
+ request_url->path_set(newPath + 1, newPathLen - 1);
+ } else {
+ request_url->path_set(newPath, newPathLen);
+ }
+}
+
+
+/** Used to do the backwards lookups. */
+bool
+UrlRewrite::ReverseMap(HTTPHdr *response_header)
+{
+ const char *location_hdr;
+ URL location_url;
+ int loc_length;
+ bool remap_found = false;
+ const char *host;
+ int host_len;
+ char *new_loc_hdr;
+ int new_loc_length;
+
+ if (unlikely(num_rules_reverse == 0)) {
+ ink_assert(reverse_mappings.empty());
+ return false;
+ }
+
+ location_hdr = response_header->value_get(MIME_FIELD_LOCATION, MIME_LEN_LOCATION, &loc_length);
+
+ if (location_hdr == NULL) {
+ Debug("url_rewrite", "Reverse Remap called with empty location header");
+ return false;
+ }
+
+ location_url.create(NULL);
+ location_url.parse(location_hdr, loc_length);
+
+ host = location_url.host_get(&host_len);
+
+ UrlMappingContainer reverse_mapping(response_header->m_heap);
+
+ if (reverseMappingLookup(&location_url, location_url.port_get(), host, host_len, reverse_mapping)) {
+ remap_found = true;
+ _doRemap(reverse_mapping, &location_url);
+ new_loc_hdr = location_url.string_get_ref(&new_loc_length);
+ response_header->value_set(MIME_FIELD_LOCATION, MIME_LEN_LOCATION, new_loc_hdr, new_loc_length);
+ }
+
+ location_url.destroy();
+ return remap_found;
+}
+
+
/** Perform fast ACL filtering. */
void
-UrlRewrite::PerformACLFiltering(HttpTransact::State * s, url_mapping * map)
+UrlRewrite::PerformACLFiltering(HttpTransact::State *s, url_mapping * map)
{
if (unlikely(!s || s->acl_filtering_performed || !s->client_connection_enabled))
return;
@@ -782,6 +902,108 @@ UrlRewrite::PerformACLFiltering(HttpTran
}
/**
+ Determines if a redirect is to occur and if so, figures out what the
+ redirect is. This was plaguiarized from UrlRewrite::Remap. redirect_url
+ ought to point to the new, mapped URL when the function exits.
+*/
+mapping_type
+UrlRewrite::Remap_redirect(HTTPHdr *request_header, URL *redirect_url, char **orig_url)
+{
+ URL *request_url;
+ mapping_type mappingType;
+ const char *host = NULL;
+ int host_len = 0, request_port = 0;
+ bool prt, trt; // existence of permanent and temporary redirect tables, respectively
+
+ prt = (num_rules_redirect_permanent != 0);
+ trt = (num_rules_redirect_temporary != 0);
+
+ if (prt + trt == 0)
+ return NONE;
+
+ // Since are called before request validity checking
+ // occurs, make sure that we have both a valid request
+ // header and a valid URL
+ //
+ if (request_header == NULL) {
+ Debug("url_rewrite", "request_header was invalid. UrlRewrite::Remap_redirect bailing out.");
+ return NONE;
+ }
+ request_url = request_header->url_get();
+ if (!request_url->valid()) {
+ Debug("url_rewrite", "request_url was invalid. UrlRewrite::Remap_redirect bailing out.");
+ return NONE;
+ }
+
+ host = request_url->host_get(&host_len);
+ request_port = request_url->port_get();
+
+ if (host_len == 0 && reverse_proxy != 0) { // Server request. Use the host header to figure out where
+ // it goes. Host header parsing is same as in ::Remap
+ int host_hdr_len;
+ const char *host_hdr = request_header->value_get(MIME_FIELD_HOST, MIME_LEN_HOST, &host_hdr_len);
+
+ if (!host_hdr) {
+ host_hdr = "";
+ host_hdr_len = 0;
+ }
+
+ const char *tmp = (const char *) memchr(host_hdr, ':', host_hdr_len);
+
+ if (tmp == NULL) {
+ host_len = host_hdr_len;
+ } else {
+ host_len = tmp - host_hdr;
+ request_port = ink_atoi(tmp + 1, host_hdr_len - host_len);
+
+ // If atoi fails, try the default for the
+ // protocol
+ if (request_port == 0) {
+ request_port = request_url->port_get();
+ }
+ }
+
+ host = host_hdr;
+ }
+ // Temporary Redirects have precedence over Permanent Redirects
+ // the rationale behind this is that network administrators might
+ // want quick redirects and not want to worry about all the existing
+ // permanent rules
+ mappingType = NONE;
+
+ UrlMappingContainer redirect_mapping(request_header->m_heap);
+
+ if (trt) {
+ if (temporaryRedirectLookup(request_url, request_port, host, host_len, redirect_mapping)) {
+ mappingType = TEMPORARY_REDIRECT;
+ }
+ }
+ if ((mappingType == NONE) && prt) {
+ if (permanentRedirectLookup(request_url, request_port, host, host_len, redirect_mapping)) {
+ mappingType = PERMANENT_REDIRECT;
+ }
+ }
+
+ if (mappingType != NONE) {
+ ink_assert((mappingType == PERMANENT_REDIRECT) || (mappingType == TEMPORARY_REDIRECT));
+ *orig_url = NULL;
+
+ // Make a copy of the request url so that we can munge it
+ // for the redirect
+ redirect_url->create(NULL);
+ redirect_url->copy(request_url);
+
+ // Perform the actual URL rewrite
+ _doRemap(redirect_mapping, redirect_url);
+
+ return mappingType;
+ }
+ ink_assert(mappingType == NONE);
+
+ return NONE;
+}
+
+/**
Returns the length of the URL.
Will replace the terminator with a '/' if this is a full URL and
@@ -1056,14 +1278,10 @@ UrlRewrite::BuildTable()
// includes support for FILE scheme
if ((fromScheme != URL_SCHEME_HTTP && fromScheme != URL_SCHEME_HTTPS &&
fromScheme != URL_SCHEME_FILE &&
- fromScheme != URL_SCHEME_RTSP && fromScheme != URL_SCHEME_TUNNEL &&
- fromScheme != URL_SCHEME_MMS && fromScheme != URL_SCHEME_MMSU &&
- fromScheme != URL_SCHEME_MMST) ||
+ fromScheme != URL_SCHEME_TUNNEL) ||
(toScheme != URL_SCHEME_HTTP && toScheme != URL_SCHEME_HTTPS &&
- toScheme != URL_SCHEME_RTSP &&
- toScheme != URL_SCHEME_TUNNEL && toScheme != URL_SCHEME_MMS &&
- toScheme != URL_SCHEME_MMSU && toScheme != URL_SCHEME_MMST)) {
- errStr = "Only http, https, rtsp, mms, and tunnel remappings are supported";
+ toScheme != URL_SCHEME_TUNNEL)) {
+ errStr = "Only http, https, and tunnel remappings are supported";
goto MAP_ERROR;
}
// Check if a tag is specified.
@@ -1245,84 +1463,6 @@ UrlRewrite::BuildTable()
}
}
- // For a remap rule like "map mms://proxy.com/ mms://origin_server/"
- // or "reverse_map mms://origin_server/ mms://proxy.com/",
- // we convert proxy.com to its IPv4 addr and gives a new remap rule
- // with the IPv4 addr.
- if ((maptype == FORWARD_MAP || maptype == FORWARD_MAP_REFERER) &&
- (fromScheme == URL_SCHEME_MMS ||
- (fromScheme == URL_SCHEME_HTTP && new_mapping->tag && strncmp(new_mapping->tag, "WMT", 3) == 0)) &&
- (fromHost_lower[0]<'0' || fromHost_lower[0]> '9')) {
- ink_gethostbyname_r_data d;
- struct hostent *h;
- h = ink_gethostbyname_r(fromHost_lower, &d);
- // We only handle IPv4 addresses which are 4-byte long.
- if ((h != NULL) && (h->h_length == 4)) {
- char ipv4_name[128];
- url_mapping *u_mapping;
- for (int i = 0; h->h_addr_list[i] != NULL; i++) {
- ipv4_name[0] = '\0';
- int ip_len;
- ip_len = snprintf(ipv4_name, sizeof(ipv4_name), "%hhu.%hhu.%hhu.%hhu",
- (unsigned char) h->h_addr_list[i][0],
- (unsigned char) h->h_addr_list[i][1],
- (unsigned char) h->h_addr_list[i][2], (unsigned char) h->h_addr_list[i][3]);
- if (ip_len > 0 && ip_len < (int) sizeof(ipv4_name)) {
- // Create a new url mapping with the IPv4 address.
- u_mapping = NEW(new url_mapping);
- u_mapping->fromURL.create(NULL);
- u_mapping->fromURL.copy(&new_mapping->fromURL);
- u_mapping->fromURL.host_set(ipv4_name, strlen(ipv4_name));
- u_mapping->_default_to_url.create(NULL);
- u_mapping->_default_to_url.copy(&new_mapping->_default_to_url);
- if (bti.paramv[3] != NULL)
- u_mapping->tag = xstrdup(&(bti.paramv[3][0]));
- if (!TableInsert(forward_mappings.hash_lookup, u_mapping, ipv4_name)) {
- goto MAP_WARNING;
- }
- num_rules_forward++;
- SetHomePageRedirectFlag(u_mapping, u_mapping->_default_to_url);
- }
- }
- }
- }
- if (maptype == REVERSE_MAP && fromScheme == URL_SCHEME_MMS && (toHost[0]<'0' || toHost[0]> '9')) {
- ink_gethostbyname_r_data d;
- struct hostent *h;
- char *toHost_null_ended = xstrndup(toHost, toHostLen);
-
- h = ink_gethostbyname_r(toHost_null_ended, &d);
- // We only handle IPv4 addresses which are 4-byte long.
- if ((h != NULL) && (h->h_length == 4)) {
- char ipv4_name[128];
- url_mapping *u_mapping;
- for (int i = 0; h->h_addr_list[i] != NULL; i++) {
- ipv4_name[0] = '\0';
- int ip_len;
- ip_len = snprintf(ipv4_name, sizeof(ipv4_name), "%hhu.%hhu.%hhu.%hhu",
- (unsigned char) h->h_addr_list[i][0],
- (unsigned char) h->h_addr_list[i][1],
- (unsigned char) h->h_addr_list[i][2], (unsigned char) h->h_addr_list[i][3]);
- if (ip_len > 0 && ip_len < (int) sizeof(ipv4_name)) { // Create a new url mapping with the IPv4 address.
- u_mapping = NEW(new url_mapping);
- u_mapping->fromURL.create(NULL);
- u_mapping->fromURL.copy(&new_mapping->fromURL);
- u_mapping->_default_to_url.create(NULL);
- u_mapping->_default_to_url.copy(&new_mapping->_default_to_url);
- u_mapping->_default_to_url.host_set(ipv4_name, strlen(ipv4_name));
- if (bti.paramv[3] != NULL)
- u_mapping->tag = xstrdup(&(bti.paramv[3][0]));
- if (!TableInsert(reverse_mappings.hash_lookup, u_mapping, fromHost_lower)) {
- goto MAP_WARNING;
- }
- num_rules_reverse++;
- u_mapping->homePageRedirect = false;
- }
- }
- }
- xfree(toHost_null_ended);
- }
-
// Check "remap" plugin options and load .so object
if ((bti.remap_optflg & REMAP_OPTFLG_PLUGIN) != 0 && (maptype == FORWARD_MAP || maptype == FORWARD_MAP_REFERER)) {
if ((check_remap_option(bti.argv, bti.argc, REMAP_OPTFLG_PLUGIN, &tok_count) & REMAP_OPTFLG_PLUGIN) != 0) {
@@ -1671,7 +1811,7 @@ UrlRewrite::load_remap_plugin(char *argv
bool
UrlRewrite::_mappingLookup(MappingsStore &mappings, URL *request_url,
int request_port, const char *request_host, int request_host_len,
- UrlMappingContainer &mapping_container, char *tag)
+ UrlMappingContainer &mapping_container)
{
char request_host_lower[TSREMAP_RRI_MAX_HOST_SIZE];
@@ -1690,7 +1830,7 @@ UrlRewrite::_mappingLookup(MappingsStore
bool retval = false;
int rank_ceiling = -1;
url_mapping *mapping = _tableLookup(mappings.hash_lookup, request_url, request_port, request_host_lower,
- request_host_len, tag);
+ request_host_len);
if (mapping != NULL) {
rank_ceiling = mapping->getRank();
Debug("url_rewrite", "Found 'simple' mapping with rank %d", rank_ceiling);
@@ -1698,7 +1838,7 @@ UrlRewrite::_mappingLookup(MappingsStore
retval = true;
}
if (_regexMappingLookup(mappings.regex_list, request_url, request_port, request_host_lower, request_host_len,
- tag, rank_ceiling, mapping_container)) {
+ rank_ceiling, mapping_container)) {
Debug("url_rewrite", "Using regex mapping with rank %d", (mapping_container.getMapping())->getRank());
retval = true;
}
@@ -1756,10 +1896,9 @@ UrlRewrite::_expandSubstitutions(int *ma
bool
UrlRewrite::_regexMappingLookup(RegexMappingList ®ex_mappings, URL *request_url, int request_port,
- const char *request_host, int request_host_len, char *tag, int rank_ceiling,
+ const char *request_host, int request_host_len, int rank_ceiling,
UrlMappingContainer &mapping_container)
{
- NOWARN_UNUSED(tag);
bool retval = false;
RegexMappingList::iterator list_iter;
Modified: trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.h?rev=1076511&r1=1076510&r2=1076511&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.h (original)
+++ trafficserver/traffic/trunk/proxy/http/remap/UrlRewrite.h Thu Mar 3 03:30:53 2011
@@ -73,6 +73,8 @@ public:
UrlRewrite(const char *file_var_in);
~UrlRewrite();
int BuildTable();
+ mapping_type Remap_redirect(HTTPHdr * request_header, URL *redirect_url, char **orig_url);
+ bool ReverseMap(HTTPHdr *response_header);
void SetReverseFlag(int flag);
void Print();
// private:
@@ -127,28 +129,28 @@ public:
MappingsStore temporary_redirects;
bool forwardMappingLookup(URL *request_url, int request_port, const char *request_host,
- int request_host_len, UrlMappingContainer &mapping_container, char *tag = NULL)
+ int request_host_len, UrlMappingContainer &mapping_container)
{
return _mappingLookup(forward_mappings, request_url, request_port, request_host, request_host_len,
- mapping_container, tag);
+ mapping_container);
}
bool reverseMappingLookup(URL *request_url, int request_port, const char *request_host,
- int request_host_len, UrlMappingContainer &mapping_container, char *tag = NULL)
+ int request_host_len, UrlMappingContainer &mapping_container)
{
return _mappingLookup(reverse_mappings, request_url, request_port, request_host, request_host_len,
- mapping_container, tag);
+ mapping_container);
}
bool permanentRedirectLookup(URL *request_url, int request_port, const char *request_host,
- int request_host_len, UrlMappingContainer &mapping_container, char *tag = NULL)
+ int request_host_len, UrlMappingContainer &mapping_container)
{
return _mappingLookup(permanent_redirects, request_url, request_port, request_host, request_host_len,
- mapping_container, tag);
+ mapping_container);
}
bool temporaryRedirectLookup(URL *request_url, int request_port, const char *request_host,
- int request_host_len, UrlMappingContainer &mapping_container, char *tag = NULL)
+ int request_host_len, UrlMappingContainer &mapping_container)
{
return _mappingLookup(temporary_redirects, request_url, request_port, request_host, request_host_len,
- mapping_container, tag);
+ mapping_container);
}
int UrlWhack(char *toWhack, int *origLength);
@@ -177,12 +179,13 @@ public:
remap_plugin_info *remap_pi_list;
private:
+ void _doRemap(UrlMappingContainer &mapping_container, URL *request_url);
bool _mappingLookup(MappingsStore &mappings, URL *request_url, int request_port, const char *request_host,
- int request_host_len, UrlMappingContainer &mapping_container, char *tag);
+ int request_host_len, UrlMappingContainer &mapping_container);
url_mapping *_tableLookup(InkHashTable * h_table, URL * request_url, int request_port, char *request_host,
- int request_host_len, char *tag);
+ int request_host_len);
bool _regexMappingLookup(RegexMappingList ®ex_mappings, URL * request_url, int request_port, const char *request_host,
- int request_host_len, char *tag, int rank_ceiling,
+ int request_host_len, int rank_ceiling,
UrlMappingContainer &mapping_container);
int _expandSubstitutions(int *matches_info, const RegexMapping ®_map, const char *matched_string, char *dest_buf,
int dest_buf_size);