jk_ajp_common.c
来自「Tomcat 4.1与WebServer集成组件的源代码包.」· C语言 代码 · 共 1,483 行 · 第 1/4 页
C
1,483 行
/* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999-2001 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation <http://www.apache.org/>." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Jk", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact <apache@apache.org>. * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see <http://www.apache.org/>. * * * * ========================================================================= *//*************************************************************************** * Description: common stuff for bi-directional protocols ajp13/ajp14. * * Author: Gal Shachor <shachor@il.ibm.com> * * Author: Henri Gomez <hgomez@slib.fr> * * Version: $Revision: 1.33 $ * ***************************************************************************/#include "jk_global.h"#include "jk_util.h"#include "jk_ajp13.h"#include "jk_ajp14.h"#include "jk_ajp_common.h"#include "jk_connect.h"#ifdef AS400#include "util_ebcdic.h"#endifconst char *response_trans_headers[] = { "Content-Type", "Content-Language", "Content-Length", "Date", "Last-Modified", "Location", "Set-Cookie", "Set-Cookie2", "Servlet-Engine", "Status", "WWW-Authenticate"};static const char *long_res_header_for_sc(int sc) { const char *rc = NULL; if(sc <= SC_RES_HEADERS_NUM && sc > 0) { rc = response_trans_headers[sc - 1]; } return rc;}static int sc_for_req_method(const char *method, unsigned char *sc) { int rc = JK_TRUE; if(0 == strcmp(method, "GET")) { *sc = SC_M_GET; } else if(0 == strcmp(method, "POST")) { *sc = SC_M_POST; } else if(0 == strcmp(method, "HEAD")) { *sc = SC_M_HEAD; } else if(0 == strcmp(method, "PUT")) { *sc = SC_M_PUT; } else if(0 == strcmp(method, "DELETE")) { *sc = SC_M_DELETE; } else if(0 == strcmp(method, "OPTIONS")) { *sc = SC_M_OPTIONS; } else if(0 == strcmp(method, "TRACE")) { *sc = SC_M_TRACE; } else if(0 == strcmp(method, "PROPFIND")) { *sc = SC_M_PROPFIND; } else if(0 == strcmp(method, "PROPPATCH")) { *sc = SC_M_PROPPATCH; } else if(0 == strcmp(method, "MKCOL")) { *sc = SC_M_MKCOL; } else if(0 == strcmp(method, "COPY")) { *sc = SC_M_COPY; } else if(0 == strcmp(method, "MOVE")) { *sc = SC_M_MOVE; } else if(0 == strcmp(method, "LOCK")) { *sc = SC_M_LOCK; } else if(0 == strcmp(method, "UNLOCK")) { *sc = SC_M_UNLOCK; } else if(0 == strcmp(method, "ACL")) { *sc = SC_M_ACL; } else if(0 == strcmp(method, "REPORT")) { *sc = SC_M_REPORT; } else if(0 == strcmp(method, "VERSION-CONTROL")) { *sc = SC_M_VERSION_CONTROL; } else if(0 == strcmp(method, "CHECKIN")) { *sc = SC_M_CHECKIN; } else if(0 == strcmp(method, "CHECKOUT")) { *sc = SC_M_CHECKOUT; } else if(0 == strcmp(method, "UNCHECKOUT")) { *sc = SC_M_UNCHECKOUT; } else if(0 == strcmp(method, "SEARCH")) { *sc = SC_M_SEARCH; } else if(0 == strcmp(method, "MKWORKSPACE")) { *sc = SC_M_MKWORKSPACE; } else if(0 == strcmp(method, "UPDATE")) { *sc = SC_M_UPDATE; } else if(0 == strcmp(method, "LABEL")) { *sc = SC_M_LABEL; } else if(0 == strcmp(method, "MERGE")) { *sc = SC_M_MERGE; } else if(0 == strcmp(method, "BASELINE-CONTROL")) { *sc = SC_M_BASELINE_CONTROL; } else if(0 == strcmp(method, "MKACTIVITY")) { *sc = SC_M_MKACTIVITY; } else { rc = JK_FALSE; } return rc;}static int sc_for_req_header(const char *header_name, unsigned short *sc) { switch(header_name[0]) { case 'a': if('c' ==header_name[1] && 'c' ==header_name[2] && 'e' ==header_name[3] && 'p' ==header_name[4] && 't' ==header_name[5]) { if ('-' == header_name[6]) { if(!strcmp(header_name + 7, "charset")) { *sc = SC_ACCEPT_CHARSET; } else if(!strcmp(header_name + 7, "encoding")) { *sc = SC_ACCEPT_ENCODING; } else if(!strcmp(header_name + 7, "language")) { *sc = SC_ACCEPT_LANGUAGE; } else { return JK_FALSE; } } else if ('\0' == header_name[6]) { *sc = SC_ACCEPT; } else { return JK_FALSE; } } else if (!strcmp(header_name, "authorization")) { *sc = SC_AUTHORIZATION; } else { return JK_FALSE; } break; case 'c': if(!strcmp(header_name, "cookie")) { *sc = SC_COOKIE; } else if(!strcmp(header_name, "connection")) { *sc = SC_CONNECTION; } else if(!strcmp(header_name, "content-type")) { *sc = SC_CONTENT_TYPE; } else if(!strcmp(header_name, "content-length")) { *sc = SC_CONTENT_LENGTH; } else if(!strcmp(header_name, "cookie2")) { *sc = SC_COOKIE2; } else { return JK_FALSE; } break; case 'h': if(!strcmp(header_name, "host")) { *sc = SC_HOST; } else { return JK_FALSE; } break; case 'p': if(!strcmp(header_name, "pragma")) { *sc = SC_PRAGMA; } else { return JK_FALSE; } break; case 'r': if(!strcmp(header_name, "referer")) { *sc = SC_REFERER; } else { return JK_FALSE; } break; case 'u': if(!strcmp(header_name, "user-agent")) { *sc = SC_USER_AGENT; } else { return JK_FALSE; } break; default: return JK_FALSE; } return JK_TRUE;}/* * Message structure * *AJPV13_REQUEST/AJPV14_REQUEST= request_prefix (1) (byte) method (byte) protocol (string) req_uri (string) remote_addr (string) remote_host (string) server_name (string) server_port (short) is_ssl (boolean) num_headers (short) num_headers*(req_header_name header_value) ?context (byte)(string) ?servlet_path (byte)(string) ?remote_user (byte)(string) ?auth_type (byte)(string) ?query_string (byte)(string) ?jvm_route (byte)(string) ?ssl_cert (byte)(string) ?ssl_cipher (byte)(string) ?ssl_session (byte)(string) ?ssl_key_size (byte)(int) via JkOptions +ForwardKeySize request_terminator (byte) ?body content_length*(var binary) */static int ajp_marshal_into_msgb(jk_msg_buf_t *msg, jk_ws_service_t *s, jk_logger_t *l, ajp_endpoint_t *ae){ unsigned char method; unsigned i; jk_log(l, JK_LOG_DEBUG, "Into ajp_marshal_into_msgb\n"); if (!sc_for_req_method(s->method, &method)) { jk_log(l, JK_LOG_ERROR, "Error ajp_marshal_into_msgb - No such method %s\n", s->method); return JK_FALSE; } if (jk_b_append_byte(msg, JK_AJP13_FORWARD_REQUEST) || jk_b_append_byte(msg, method) || jk_b_append_string(msg, s->protocol) || jk_b_append_string(msg, s->req_uri) || jk_b_append_string(msg, s->remote_addr) || jk_b_append_string(msg, s->remote_host) || jk_b_append_string(msg, s->server_name) || jk_b_append_int(msg, (unsigned short)s->server_port) || jk_b_append_byte(msg, (unsigned char)(s->is_ssl)) || jk_b_append_int(msg, (unsigned short)(s->num_headers))) { jk_log(l, JK_LOG_ERROR, "Error ajp_marshal_into_msgb - Error appending the message begining\n"); return JK_FALSE; } for (i = 0 ; i < s->num_headers ; i++) { unsigned short sc; if (sc_for_req_header(s->headers_names[i], &sc)) { if (jk_b_append_int(msg, sc)) { jk_log(l, JK_LOG_ERROR, "Error ajp_marshal_into_msgb - Error appending the header name\n"); return JK_FALSE; } } else { if (jk_b_append_string(msg, s->headers_names[i])) { jk_log(l, JK_LOG_ERROR, "Error ajp_marshal_into_msgb - Error appending the header name\n"); return JK_FALSE; } } if (jk_b_append_string(msg, s->headers_values[i])) { jk_log(l, JK_LOG_ERROR, "Error ajp_marshal_into_msgb - Error appending the header value\n"); return JK_FALSE; } } if (s->secret) { if (jk_b_append_byte(msg, SC_A_SECRET) || jk_b_append_string(msg, s->secret)) { jk_log(l, JK_LOG_ERROR, "Error ajp_marshal_into_msgb - Error appending secret\n"); return JK_FALSE; } } if (s->remote_user) { if (jk_b_append_byte(msg, SC_A_REMOTE_USER) || jk_b_append_string(msg, s->remote_user)) { jk_log(l, JK_LOG_ERROR, "Error ajp_marshal_into_msgb - Error appending the remote user\n"); return JK_FALSE; } } if (s->auth_type) { if (jk_b_append_byte(msg, SC_A_AUTH_TYPE) || jk_b_append_string(msg, s->auth_type)) { jk_log(l, JK_LOG_ERROR, "Error ajp_marshal_into_msgb - Error appending the auth type\n"); return JK_FALSE; } } if (s->query_string) { if (jk_b_append_byte(msg, SC_A_QUERY_STRING) ||#ifdef AS400 jk_b_append_asciistring(msg, s->query_string)) {#else jk_b_append_string(msg, s->query_string)) {#endif jk_log(l, JK_LOG_ERROR, "Error ajp_marshal_into_msgb - Error appending the query string\n"); return JK_FALSE; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?