📄 jk_nsapi_plugin.c
字号:
/* ========================================================================= * * * * 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: NSAPI plugin for Netscape servers * * Author: Gal Shachor <shachor@il.ibm.com> * * Version: $Revision: 1.8 $ * ***************************************************************************/#include "jk_global.h"#include "jk_util.h"#include "jk_map.h"#include "jk_pool.h"#include "jk_service.h"#include "jk_worker.h"#include "nsapi.h"#define URI_PATTERN "path"#define DEFAULT_WORKER_NAME ("ajp13")struct nsapi_private_data { jk_pool_t p; int request_started; pblock *pb; Session *sn; Request *rq;};typedef struct nsapi_private_data nsapi_private_data_t;static int init_on_other_thread_is_done = JK_FALSE;static int init_on_other_thread_is_ok = JK_FALSE;static jk_logger_t *logger = NULL;static jk_worker_env_t worker_env;#ifdef NETWAREint (*PR_IsSocketSecure)(SYS_NETFD *csd); /* pointer to PR_IsSocketSecure function */#endifstatic int JK_METHOD start_response(jk_ws_service_t *s, int status, const char *reason, const char * const *header_names, const char * const *header_values, unsigned num_of_headers);static int JK_METHOD ws_read(jk_ws_service_t *s, void *b, unsigned l, unsigned *a);static int JK_METHOD ws_write(jk_ws_service_t *s, const void *b, unsigned l);NSAPI_PUBLIC int jk_init(pblock *pb, Session *sn, Request *rq);NSAPI_PUBLIC void jk_term(void *p);NSAPI_PUBLIC int jk_service(pblock *pb, Session *sn, Request *rq);static int init_ws_service(nsapi_private_data_t *private_data, jk_ws_service_t *s);static int setup_http_headers(nsapi_private_data_t *private_data, jk_ws_service_t *s);static void init_workers_on_other_threads(void *init_d) { jk_map_t *init_map = (jk_map_t *)init_d; /* we add the URI->WORKER MAP since workers using AJP14 will feed it */ /* but where are they here in Netscape ? */ if(wc_open(init_map, &worker_env, logger)) { init_on_other_thread_is_ok = JK_TRUE; } else { jk_log(logger, JK_LOG_EMERG, "In init_workers_on_other_threads, failed\n"); } init_on_other_thread_is_done = JK_TRUE;}static int JK_METHOD start_response(jk_ws_service_t *s, int status, const char *reason, const char * const *header_names, const char * const *header_values, unsigned num_of_headers){ if(s && s->ws_private) { nsapi_private_data_t *p = s->ws_private; if(!p->request_started) { unsigned i; p->request_started = JK_TRUE; /* Remove "old" content type */ param_free(pblock_remove("content-type", p->rq->srvhdrs)); if(num_of_headers) { for (i = 0 ; i < (int)num_of_headers ; i++) { pblock_nvinsert(header_names[i], header_values[i], p->rq->srvhdrs); } } else { pblock_nvinsert("content-type", "text/plain", p->rq->srvhdrs); } protocol_status(p->sn, p->rq, status, (char *)reason); protocol_start_response(p->sn, p->rq); } return JK_TRUE; } return JK_FALSE;}static int JK_METHOD ws_read(jk_ws_service_t *s, void *b, unsigned l, unsigned *a){ if(s && s->ws_private && b && a) { nsapi_private_data_t *p = s->ws_private; *a = 0; if(l) { char *buf = b; unsigned i; netbuf *inbuf = p->sn->inbuf;/* Until we get a service pack for NW5.1 and earlier that has the latest *//* Enterprise Server, we have to go through the else version of this code*/#if defined(netbuf_getbytes) && !defined(NETWARE) i = netbuf_getbytes(inbuf, b, l); if(NETBUF_EOF == i || NETBUF_ERROR == i) { return JK_FALSE; }#else int ch; for(i = 0 ; i < l ; i++) { ch = netbuf_getc(inbuf); /* * IO_EOF is 0 (zero) which is a very reasonable byte * when it comes to binary data. So we are not breaking * out of the read loop when reading it. * * We are protected from an infinit loop by the Java part of * Tomcat. */ if(IO_ERROR == ch) { break; } buf[i] = ch; } if(0 == i) { return JK_FALSE; }#endif *a = i; } return JK_TRUE; } return JK_FALSE;}static int JK_METHOD ws_write(jk_ws_service_t *s, const void *b, unsigned l){ if(s && s->ws_private && b) { nsapi_private_data_t *p = s->ws_private; if(l) { if(!p->request_started) { start_response(s, 200, NULL, NULL, NULL, 0); } if(net_write(p->sn->csd, (char *)b, (int)l) == IO_ERROR) { return JK_FALSE; } } return JK_TRUE; } return JK_FALSE;}NSAPI_PUBLIC int jk_init(pblock *pb, Session *sn, Request *rq){ char *worker_prp_file = pblock_findval(JK_WORKER_FILE_TAG, pb); char *log_level_str = pblock_findval(JK_LOG_LEVEL_TAG, pb); char *log_file = pblock_findval(JK_LOG_FILE_TAG, pb); int rc = REQ_ABORTED; jk_map_t *init_map; fprintf(stderr, "In jk_init.\n Worker file = %s.\n Log level = %s.\n Log File = %s\n",worker_prp_file, log_level_str, log_file);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -