Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "RemapPlugins.h"
00025
00026 ClassAllocator<RemapPlugins> pluginAllocator("RemapPluginsAlloc");
00027
00028 TSRemapStatus
00029 RemapPlugins::run_plugin(remap_plugin_info* plugin)
00030 {
00031 TSRemapStatus plugin_retcode;
00032 TSRemapRequestInfo rri;
00033 url_mapping *map = _s->url_map.getMapping();
00034 URL * map_from = _s->url_map.getFromURL();
00035 URL * map_to = _s->url_map.getToURL();
00036
00037
00038
00039 rri.requestBufp = reinterpret_cast<TSMBuffer>(_request_header);
00040 rri.requestHdrp = reinterpret_cast<TSMLoc>(_request_header->m_http);
00041
00042
00043 rri.mapFromUrl = reinterpret_cast<TSMLoc>(map_from->m_url_impl);
00044 rri.mapToUrl = reinterpret_cast<TSMLoc>(map_to->m_url_impl);
00045 rri.requestUrl = reinterpret_cast<TSMLoc>(_request_url->m_url_impl);
00046
00047 rri.redirect = 0;
00048
00049
00050
00051
00052
00053 #if 0
00054 if (_cur == 0) {
00055 rri.remap_from_host = map_from->host_get(&rri.remap_from_host_size);
00056 rri.remap_from_port = map_from->port_get();
00057 rri.remap_from_path = map_from->path_get(&rri.remap_from_path_size);
00058 rri.from_scheme = map_from->scheme_get(&rri.from_scheme_len);
00059 } else {
00060 rri.remap_from_host = _request_url->host_get(&rri.remap_from_host_size);
00061 rri.remap_from_port = _request_url->port_get();
00062 rri.remap_from_path = _request_url->path_get(&rri.remap_from_path_size);
00063 rri.from_scheme = _request_url->scheme_get(&rri.from_scheme_len);
00064 }
00065 #endif
00066
00067 void* ih = map->get_instance(_cur);
00068
00069
00070 if (_s && _cur == 0) {
00071 _s->fp_tsremap_os_response = plugin->fp_tsremap_os_response;
00072 _s->remap_plugin_instance = ih;
00073 }
00074
00075 plugin_retcode = plugin->fp_tsremap_do_remap(ih, _s ? reinterpret_cast<TSHttpTxn>(_s->state_machine) : NULL, &rri);
00076
00077 if (plugin_retcode < 0)
00078 plugin_retcode = TSREMAP_NO_REMAP;
00079
00080
00081 if ((TSREMAP_DID_REMAP == plugin_retcode || TSREMAP_DID_REMAP_STOP == plugin_retcode) && rri.redirect)
00082 _s->remap_redirect = _request_url->string_get(NULL);
00083
00084 return plugin_retcode;
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 int
00097 RemapPlugins::run_single_remap()
00098 {
00099
00100 url_mapping * map = _s->url_map.getMapping();
00101 remap_plugin_info * plugin = map->get_plugin(_cur);
00102 TSRemapStatus plugin_retcode = TSREMAP_NO_REMAP;
00103
00104 Debug("url_rewrite", "running single remap rule id %d for the %d%s time",
00105 map->map_id, _cur, _cur == 1 ? "st" : _cur == 2 ? "nd" : _cur == 3 ? "rd" : "th");
00106
00107
00108
00109 if (plugin) {
00110 plugin_retcode = run_plugin(plugin);
00111 }
00112
00113 _cur++;
00114
00115
00116 if (_s->remap_redirect) {
00117 return 1;
00118 }
00119
00120 if (TSREMAP_NO_REMAP == plugin_retcode || TSREMAP_NO_REMAP_STOP == plugin_retcode) {
00121
00122
00123
00124
00125
00126 if ((_cur == 1) && (HTTP_WKSIDX_CONNECT != _s->hdr_info.client_request.method_get_wksidx())) {
00127 Debug("url_rewrite", "plugin did not change host, port or path, copying from mapping rule");
00128 url_rewrite_remap_request(_s->url_map, _request_url);
00129 }
00130 }
00131
00132 if (TSREMAP_NO_REMAP_STOP == plugin_retcode || TSREMAP_DID_REMAP_STOP == plugin_retcode) {
00133 Debug("url_rewrite", "breaking remap plugin chain since last plugin said we should stop");
00134 return 1;
00135 }
00136
00137 if (_cur > MAX_REMAP_PLUGIN_CHAIN) {
00138 Error("called %s more than %u times; stopping this remap insanity now", __func__, MAX_REMAP_PLUGIN_CHAIN);
00139 return 1;
00140 }
00141
00142 if (_cur >= map->_plugin_count) {
00143
00144 Debug("url_rewrite", "completed all remap plugins for rule id %d", map->map_id);
00145 return 1;
00146 }
00147
00148 Debug("url_rewrite", "completed single remap, attempting another via immediate callback");
00149 return 0;
00150 }
00151
00152 int
00153 RemapPlugins::run_remap(int event, Event* e)
00154 {
00155 Debug("url_rewrite", "Inside RemapPlugins::run_remap with cur = %d", _cur);
00156
00157 ink_assert(action.continuation);
00158 ink_assert(action.continuation);
00159
00160 int ret = 0;
00161
00162
00163 if (action.cancelled) {
00164 mutex.clear();
00165 pluginAllocator.free(this);
00166 return EVENT_DONE;
00167 }
00168
00169 switch (event) {
00170 case EVENT_IMMEDIATE:
00171 Debug("url_rewrite", "handling immediate event inside RemapPlugins::run_remap");
00172 ret = run_single_remap();
00173
00174
00175
00176
00177
00178
00179 if (ret) {
00180 action.continuation->handleEvent(EVENT_REMAP_COMPLETE, NULL);
00181 mutex.clear();
00182 action.mutex.clear();
00183 mutex = NULL;
00184 action.mutex = NULL;
00185
00186 pluginAllocator.free(this);
00187 return EVENT_DONE;
00188 } else {
00189 e->schedule_imm(event);
00190 return EVENT_CONT;
00191 }
00192
00193 break;
00194 default:
00195 ink_assert(!"unknown event type");
00196 break;
00197 };
00198 return EVENT_DONE;
00199 }