📄 aolserver.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: Sascha Schumann <sascha@schumann.cx> | +----------------------------------------------------------------------+ *//* * TODO: * - write documentation * - CGI/1.1 conformance *//* $Id: aolserver.c,v 1.72.2.4.6.2 2007/01/01 09:46:51 sebastian Exp $ *//* conflict between PHP and AOLserver headers */#define Debug php_Debug#include "php.h"#undef Debug#ifdef HAVE_AOLSERVER#ifndef ZTS#error AOLserver module is only useable in thread-safe mode#endif#include "ext/standard/info.h"#define SECTION(name) PUTS("<h2>" name "</h2>\n")#define NS_BUF_SIZE 511#include "php_ini.h"#include "php_globals.h"#include "SAPI.h"#include "php_main.h"#include "php_variables.h"#include "ns.h"#include "php_version.h"/* This symbol is used by AOLserver to tell the API version we expect */int Ns_ModuleVersion = 1;#define NSG(v) TSRMG(ns_globals_id, ns_globals_struct *, v)/* php_ns_context is per-server (thus only once at all) */typedef struct { sapi_module_struct *sapi_module; char *ns_server; char *ns_module;} php_ns_context;/* ns_globals_struct is per-thread */typedef struct { Ns_Conn *conn; size_t data_avail;} ns_globals_struct;/* TSRM id */static int ns_globals_id;/* global context */static php_ns_context *global_context;static void php_ns_config(php_ns_context *ctx, char global);/* * php_ns_sapi_ub_write() writes data to the client connection. */static intphp_ns_sapi_ub_write(const char *str, uint str_length TSRMLS_DC){ int n; uint sent = 0; while (str_length > 0) { n = Ns_ConnWrite(NSG(conn), (void *) str, str_length); if (n == -1) php_handle_aborted_connection(); str += n; sent += n; str_length -= n; } return sent;}/* * php_ns_sapi_header_handler() sets a HTTP reply header to be * sent to the client. */static intphp_ns_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC){ char *header_name, *header_content; char *p; header_name = sapi_header->header; header_content = p = strchr(header_name, ':'); if (p) { *p = '\0'; do { header_content++; } while (*header_content == ' '); if (!strcasecmp(header_name, "Content-type")) { Ns_ConnSetTypeHeader(NSG(conn), header_content); } else { Ns_ConnSetHeaders(NSG(conn), header_name, header_content); } *p = ':'; } sapi_free_header(sapi_header); return 0;}/* * php_ns_sapi_send_headers() flushes the headers to the client. * Called before real content is sent by PHP. */static intphp_ns_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC){ if(SG(sapi_headers).send_default_content_type) { Ns_ConnSetRequiredHeaders(NSG(conn), "text/html", 0); } Ns_ConnFlushHeaders(NSG(conn), SG(sapi_headers).http_response_code); return SAPI_HEADER_SENT_SUCCESSFULLY;}/* * php_ns_sapi_read_post() reads a specified number of bytes from * the client. Used for POST/PUT requests. */static intphp_ns_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC){ uint max_read; uint total_read = 0; max_read = MIN(NSG(data_avail), count_bytes); total_read = Ns_ConnRead(NSG(conn), buf, max_read); if(total_read == NS_ERROR) { total_read = -1; } else { NSG(data_avail) -= total_read; } return total_read;}/* * php_ns_sapi_read_cookies() returns the Cookie header from * the HTTP request header */ static char *php_ns_sapi_read_cookies(TSRMLS_D){ int i; char *http_cookie = NULL; i = Ns_SetIFind(NSG(conn->headers), "cookie"); if(i != -1) { http_cookie = Ns_SetValue(NSG(conn->headers), i); } return http_cookie;}static void php_info_aolserver(ZEND_MODULE_INFO_FUNC_ARGS){ char buf[512]; int uptime = Ns_InfoUptime(); int i; php_info_print_table_start(); php_info_print_table_row(2, "SAPI module version", "$Id: aolserver.c,v 1.72.2.4.6.2 2007/01/01 09:46:51 sebastian Exp $"); php_info_print_table_row(2, "Build date", Ns_InfoBuildDate()); php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile()); php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog()); php_info_print_table_row(2, "Installation path", Ns_InfoHomePath()); php_info_print_table_row(2, "Hostname of server", Ns_InfoHostname()); php_info_print_table_row(2, "Source code label", Ns_InfoLabel()); php_info_print_table_row(2, "Server platform", Ns_InfoPlatform()); snprintf(buf, 511, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion()); php_info_print_table_row(2, "Server version", buf); snprintf(buf, 511, "%d day(s), %02d:%02d:%02d", uptime / 86400, (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60); php_info_print_table_row(2, "Server uptime", buf); php_info_print_table_end(); SECTION("HTTP Headers Information"); php_info_print_table_start(); php_info_print_table_colspan_header(2, "HTTP Request Headers"); php_info_print_table_row(2, "HTTP Request", NSG(conn)->request->line); for (i = 0; i < Ns_SetSize(NSG(conn)->headers); i++) { php_info_print_table_row(2, Ns_SetKey(NSG(conn)->headers, i), Ns_SetValue(NSG(conn)->headers, i)); } php_info_print_table_colspan_header(2, "HTTP Response Headers"); for (i = 0; i < Ns_SetSize(NSG(conn)->outputheaders); i++) { php_info_print_table_row(2, Ns_SetKey(NSG(conn)->outputheaders, i), Ns_SetValue(NSG(conn)->outputheaders, i)); } php_info_print_table_end();}PHP_FUNCTION(getallheaders);static function_entry aolserver_functions[] = { PHP_FE(getallheaders, NULL) {NULL, NULL, NULL}};static zend_module_entry php_aolserver_module = { STANDARD_MODULE_HEADER, "AOLserver", aolserver_functions, NULL, NULL, NULL, NULL, php_info_aolserver, NULL, STANDARD_MODULE_PROPERTIES};PHP_FUNCTION(getallheaders){ int i; if (array_init(return_value) == FAILURE) { RETURN_FALSE; } for (i = 0; i < Ns_SetSize(NSG(conn->headers)); i++) { char *key = Ns_SetKey(NSG(conn->headers), i); char *value = Ns_SetValue(NSG(conn->headers), i); add_assoc_string(return_value, key, value, 1); }}static intphp_ns_startup(sapi_module_struct *sapi_module){ if (php_module_startup(sapi_module, &php_aolserver_module, 1) == FAILURE) { return FAILURE; } else { return SUCCESS; }}/* * php_ns_sapi_register_variables() populates the php script environment * with a number of variables. HTTP_* variables are created for * the HTTP header data, so that a script can access these. */#define ADD_STRINGX(name, buf) \ php_register_variable(name, buf, track_vars_array TSRMLS_CC)#define ADD_STRING(name) \ ADD_STRINGX(name, buf)static voidphp_ns_sapi_register_variables(zval *track_vars_array TSRMLS_DC){ int i; char buf[NS_BUF_SIZE + 1]; char *tmp; for(i = 0; i < Ns_SetSize(NSG(conn->headers)); i++) { char *key = Ns_SetKey(NSG(conn->headers), i); char *value = Ns_SetValue(NSG(conn->headers), i); char *p; char c;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -