📄 nsapi.c
字号:
/* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Jayakumar Muthukumarasamy <jk@kasenna.com> | | Uwe Schindler <uwe@thetaphi.de> | +----------------------------------------------------------------------+*//* $Id: nsapi.c,v 1.28.2.32.2.2 2007/01/01 09:46:52 sebastian Exp $ *//* * PHP includes */#define NSAPI 1#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "php_variables.h"#include "ext/standard/info.h"#include "php_ini.h"#include "php_globals.h"#include "SAPI.h"#include "php_main.h"#include "php_version.h"#include "TSRM.h"#include "ext/standard/php_standard.h"#include <sys/types.h>#include <sys/stat.h>#ifndef RTLD_DEFAULT#define RTLD_DEFAULT NULL#endif/* * If neither XP_UNIX not XP_WIN32 is defined use PHP_WIN32 */#if !defined(XP_UNIX) && !defined(XP_WIN32)#ifdef PHP_WIN32#define XP_WIN32#else#define XP_UNIX#endif#endif/* * NSAPI includes */#include "nsapi.h"#include "base/pblock.h"#include "base/session.h"#include "frame/req.h"#include "frame/protocol.h" /* protocol_start_response */#include "base/util.h" /* is_mozilla, getline */#include "frame/log.h" /* log_error */#define NSLS_D struct nsapi_request_context *request_context#define NSLS_DC , NSLS_D#define NSLS_C request_context#define NSLS_CC , NSLS_C#define NSG(v) (request_context->v)#define NS_BUF_SIZE 2048/* * ZTS needs to be defined for NSAPI to work */#if !defined(ZTS)#error "NSAPI module needs ZTS to be defined"#endif/* * Structure to encapsulate the NSAPI request in SAPI */typedef struct nsapi_request_context { pblock *pb; Session *sn; Request *rq; int read_post_bytes; char *path_info; int fixed_script; /* 0 if script is from URI, 1 if script is from "script" parameter */ short http_error; /* 0 in normal mode; for errors the HTTP error code */} nsapi_request_context;/* * Mappings between NSAPI names and environment variables. This * mapping was obtained from the sample programs at the iplanet * website. */typedef struct nsapi_equiv { const char *env_var; const char *nsapi_eq;} nsapi_equiv;static nsapi_equiv nsapi_reqpb[] = { { "QUERY_STRING", "query" }, { "REQUEST_LINE", "clf-request" }, { "REQUEST_METHOD", "method" }, { "PHP_SELF", "uri" }, { "SERVER_PROTOCOL", "protocol" }};static size_t nsapi_reqpb_size = sizeof(nsapi_reqpb)/sizeof(nsapi_reqpb[0]);static nsapi_equiv nsapi_vars[] = { { "AUTH_TYPE", "auth-type" }, { "CLIENT_CERT", "auth-cert" }, { "REMOTE_USER", "auth-user" }};static size_t nsapi_vars_size = sizeof(nsapi_vars)/sizeof(nsapi_vars[0]);static nsapi_equiv nsapi_client[] = { { "HTTPS_KEYSIZE", "keysize" }, { "HTTPS_SECRETSIZE", "secret-keysize" }, { "REMOTE_ADDR", "ip" }, { "REMOTE_HOST", "ip" }};static size_t nsapi_client_size = sizeof(nsapi_client)/sizeof(nsapi_client[0]);/* this parameters to "Service"/"Error" are NSAPI ones which should not be php.ini keys and are excluded */static char *nsapi_exclude_from_ini_entries[] = { "fn", "type", "method", "directive", "code", "reason", "script", "bucket", NULL };static char *nsapi_strdup(char *str){ if (str != NULL) { return STRDUP(str); } return NULL;}static void nsapi_free(void *addr){ if (addr != NULL) { FREE(addr); }}/*******************//* PHP module part *//*******************/PHP_MINIT_FUNCTION(nsapi);PHP_MSHUTDOWN_FUNCTION(nsapi);PHP_RINIT_FUNCTION(nsapi);PHP_RSHUTDOWN_FUNCTION(nsapi);PHP_MINFO_FUNCTION(nsapi);PHP_FUNCTION(nsapi_virtual);PHP_FUNCTION(nsapi_request_headers);PHP_FUNCTION(nsapi_response_headers);ZEND_BEGIN_MODULE_GLOBALS(nsapi) long read_timeout;ZEND_END_MODULE_GLOBALS(nsapi)ZEND_DECLARE_MODULE_GLOBALS(nsapi)#define NSAPI_G(v) TSRMG(nsapi_globals_id, zend_nsapi_globals *, v)/* {{{ nsapi_functions[] * * Every user visible function must have an entry in nsapi_functions[]. */function_entry nsapi_functions[] = { PHP_FE(nsapi_virtual, NULL) /* Make subrequest */ PHP_FALIAS(virtual, nsapi_virtual, NULL) /* compatibility */ PHP_FE(nsapi_request_headers, NULL) /* get request headers */ PHP_FALIAS(getallheaders, nsapi_request_headers, NULL) /* compatibility */ PHP_FALIAS(apache_request_headers, nsapi_request_headers, NULL) /* compatibility */ PHP_FE(nsapi_response_headers, NULL) /* get response headers */ PHP_FALIAS(apache_response_headers, nsapi_response_headers, NULL) /* compatibility */ {NULL, NULL, NULL}};/* }}} *//* {{{ nsapi_module_entry */zend_module_entry nsapi_module_entry = { STANDARD_MODULE_HEADER, "nsapi", nsapi_functions, PHP_MINIT(nsapi), PHP_MSHUTDOWN(nsapi), NULL, NULL, PHP_MINFO(nsapi), NO_VERSION_YET, STANDARD_MODULE_PROPERTIES};/* }}} *//* {{{ PHP_INI */PHP_INI_BEGIN() STD_PHP_INI_ENTRY("nsapi.read_timeout", "60", PHP_INI_ALL, OnUpdateInt, read_timeout, zend_nsapi_globals, nsapi_globals)PHP_INI_END()/* }}} *//* newer servers hide this functions from the programmer so redefine the functions dynamically thanks to Chris Elving from Sun for the function declarations */typedef int (*nsapi_servact_prototype)(Session *sn, Request *rq);nsapi_servact_prototype nsapi_servact_uri2path = NULL;nsapi_servact_prototype nsapi_servact_pathchecks = NULL;nsapi_servact_prototype nsapi_servact_fileinfo = NULL;nsapi_servact_prototype nsapi_servact_service = NULL;#ifdef PHP_WIN32/* The following dll-names for nsapi are in use at this time. The undocumented * servact_* functions are always in the newest one, older ones are supported by * the server only by wrapping the function table nothing else. So choose * the newest one found in process space for dynamic linking */static char *nsapi_dlls[] = { "ns-httpd40.dll", "ns-httpd36.dll", "ns-httpd35.dll", "ns-httpd30.dll", NULL };/* if user specifies an other dll name by server_lib parameter * it is placed in the following variable and only this DLL is * checked for the servact_* functions */char *nsapi_dll = NULL;#endif/* {{{ php_nsapi_init_dynamic_symbols */static void php_nsapi_init_dynamic_symbols(void){#if defined(servact_uri2path) && defined(servact_pathchecks) && defined(servact_fileinfo) && defined(servact_service) /* use functions from nsapi.h if available */ nsapi_servact_uri2path = &servact_uri2path; nsapi_servact_pathchecks = &servact_pathchecks; nsapi_servact_fileinfo = &servact_fileinfo; nsapi_servact_service = &servact_service;#else /* find address of internal NSAPI functions */#ifdef PHP_WIN32 register int i; DL_HANDLE module = NULL; if (nsapi_dll) { /* try user specified server_lib */ module = GetModuleHandle(nsapi_dll); if (!module) { log_error(LOG_WARN, "php4_init", NULL, NULL, "Cannot find DLL specified by server_lib parameter: %s", nsapi_dll); } } else { /* find a LOADED dll module from nsapi_dlls */ for (i=0; nsapi_dlls[i]; i++) { if (module = GetModuleHandle(nsapi_dlls[i])) { break; } } } if (!module) return;#else DL_HANDLE module = RTLD_DEFAULT;#endif nsapi_servact_uri2path = (nsapi_servact_prototype)DL_FETCH_SYMBOL(module, "INTservact_uri2path"); nsapi_servact_pathchecks = (nsapi_servact_prototype)DL_FETCH_SYMBOL(module, "INTservact_pathchecks"); nsapi_servact_fileinfo = (nsapi_servact_prototype)DL_FETCH_SYMBOL(module, "INTservact_fileinfo"); nsapi_servact_service = (nsapi_servact_prototype)DL_FETCH_SYMBOL(module, "INTservact_service"); if (!(nsapi_servact_uri2path && nsapi_servact_pathchecks && nsapi_servact_fileinfo && nsapi_servact_service)) { /* not found - could be cause they are undocumented */ nsapi_servact_uri2path = NULL; nsapi_servact_pathchecks = NULL; nsapi_servact_fileinfo = NULL; nsapi_servact_service = NULL; }#endif}/* }}} *//* {{{ php_nsapi_init_globals */static void php_nsapi_init_globals(zend_nsapi_globals *nsapi_globals){ nsapi_globals->read_timeout = 60;}/* }}} *//* {{{ PHP_MINIT_FUNCTION */PHP_MINIT_FUNCTION(nsapi){ php_nsapi_init_dynamic_symbols(); ZEND_INIT_MODULE_GLOBALS(nsapi, php_nsapi_init_globals, NULL); REGISTER_INI_ENTRIES(); return SUCCESS;}/* }}} *//* {{{ PHP_MSHUTDOWN_FUNCTION */PHP_MSHUTDOWN_FUNCTION(nsapi){ UNREGISTER_INI_ENTRIES(); return SUCCESS;}/* }}} *//* {{{ PHP_MINFO_FUNCTION */PHP_MINFO_FUNCTION(nsapi){ php_info_print_table_start(); php_info_print_table_row(2, "NSAPI Module Revision", "$Revision: 1.28.2.32.2.2 $"); php_info_print_table_row(2, "Server Software", system_version()); php_info_print_table_row(2, "Sub-requests with nsapi_virtual()", (nsapi_servact_service)?((zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0))?"not supported with zlib.output_compression":"enabled"):"not supported on this platform" ); php_info_print_table_end(); DISPLAY_INI_ENTRIES();}/* }}} *//* {{{ proto bool nsapi_virtual(string uri) Perform an NSAPI sub-request *//* This function is equivalent to <!--#include virtual...--> * in SSI. It does an NSAPI sub-request. It is useful * for including CGI scripts or .shtml files, or anything else * that you'd parse through webserver. */PHP_FUNCTION(nsapi_virtual){ pval **uri; int rv; char *value; Request *rq; nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &uri) == FAILURE) { WRONG_PARAM_COUNT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -