⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aolserver.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		snprintf(buf, NS_BUF_SIZE, "HTTP_%s", key);				for(p = buf + 5; (c = *p); p++) {			c = toupper(c);			if(c < 'A' || c > 'Z') {				c = '_';			}			*p = c;		}		ADD_STRINGX(buf, value);	}		snprintf(buf, NS_BUF_SIZE, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion());	ADD_STRING("SERVER_SOFTWARE");	snprintf(buf, NS_BUF_SIZE, "HTTP/%1.1f", NSG(conn)->request->version);	ADD_STRING("SERVER_PROTOCOL");	ADD_STRINGX("REQUEST_METHOD", NSG(conn)->request->method);	if(NSG(conn)->request->query)		ADD_STRINGX("QUERY_STRING", NSG(conn)->request->query);		ADD_STRINGX("SERVER_BUILDDATE", Ns_InfoBuildDate());	ADD_STRINGX("REMOTE_ADDR", Ns_ConnPeer(NSG(conn)));	snprintf(buf, NS_BUF_SIZE, "%d", Ns_ConnPeerPort(NSG(conn)));	ADD_STRING("REMOTE_PORT");	snprintf(buf, NS_BUF_SIZE, "%d", Ns_ConnPort(NSG(conn)));	ADD_STRING("SERVER_PORT");	tmp = Ns_ConnHost(NSG(conn));	if (tmp)		ADD_STRINGX("SERVER_NAME", tmp);	ADD_STRINGX("PATH_TRANSLATED", SG(request_info).path_translated);	ADD_STRINGX("REQUEST_URI", SG(request_info).request_uri);	ADD_STRINGX("PHP_SELF", SG(request_info).request_uri);	ADD_STRINGX("GATEWAY_INTERFACE", "CGI/1.1");	snprintf(buf, NS_BUF_SIZE, "%d", Ns_InfoBootTime());	ADD_STRING("SERVER_BOOTTIME");}/* this structure is static (as in "it does not change") */static sapi_module_struct aolserver_sapi_module = {	"aolserver",	"AOLserver",	php_ns_startup,							/* startup */	php_module_shutdown_wrapper,			/* shutdown */	NULL,									/* activate */	NULL,									/* deactivate */	php_ns_sapi_ub_write,					/* unbuffered write */	NULL,									/* flush */	NULL,									/* get uid */	NULL,									/* getenv */	php_error,								/* error handler */	php_ns_sapi_header_handler,				/* header handler */	php_ns_sapi_send_headers,				/* send headers handler */	NULL,									/* send header handler */	php_ns_sapi_read_post,					/* read POST data */	php_ns_sapi_read_cookies,				/* read Cookies */	php_ns_sapi_register_variables,	NULL,									/* Log message */	NULL,									/* php.ini path override */	NULL,									/* Block interruptions */	NULL,									/* Unblock interruptions */	STANDARD_SAPI_MODULE_PROPERTIES};/* * php_ns_module_main() is called by the per-request handler and * "executes" the script */static intphp_ns_module_main(TSRMLS_D){	zend_file_handle file_handle = {0};	file_handle.type = ZEND_HANDLE_FILENAME;	file_handle.filename = SG(request_info).path_translated;	file_handle.free_filename = 0;	file_handle.opened_path = NULL;		php_ns_config(global_context, 0);	if (php_request_startup(TSRMLS_C) == FAILURE) {		return NS_ERROR;	}		php_execute_script(&file_handle TSRMLS_CC);	php_request_shutdown(NULL);	return NS_OK;}/* * php_ns_request_ctor() initializes the per-request data structure * and fills it with data provided by the web server */static void php_ns_request_ctor(TSRMLS_D){	char *server;	Ns_DString ds;	char *root;	int index;	char *tmp;		server = Ns_ConnServer(NSG(conn));	#define safe_strdup(x) ((x)?strdup((x)):NULL)	SG(request_info).query_string = safe_strdup(NSG(conn->request->query));	Ns_DStringInit(&ds);	Ns_UrlToFile(&ds, server, NSG(conn->request->url));		/* path_translated is the absolute path to the file */	SG(request_info).path_translated = safe_strdup(Ns_DStringValue(&ds));	Ns_DStringFree(&ds);	root = Ns_PageRoot(server);	SG(request_info).request_uri = strdup(SG(request_info).path_translated + strlen(root));	SG(request_info).request_method = NSG(conn)->request->method;	SG(request_info).content_length = Ns_ConnContentLength(NSG(conn));	index = Ns_SetIFind(NSG(conn)->headers, "content-type");	SG(request_info).content_type = index == -1 ? NULL : 		Ns_SetValue(NSG(conn)->headers, index);	SG(sapi_headers).http_response_code = 200;	tmp = Ns_ConnAuthUser(NSG(conn));	if (tmp)		tmp = estrdup(tmp);	SG(request_info).auth_user = tmp;	tmp = Ns_ConnAuthPasswd(NSG(conn));	if (tmp)		tmp = estrdup(tmp);	SG(request_info).auth_password = tmp;	NSG(data_avail) = SG(request_info).content_length;}/* * php_ns_request_dtor() destroys all data associated with * the per-request structure  */static voidphp_ns_request_dtor(TSRMLS_D){	free(SG(request_info).path_translated);	if (SG(request_info).query_string)		free(SG(request_info).query_string);	free(SG(request_info).request_uri);}/* * The php_ns_request_handler() is called per request and handles * everything for one request. */static intphp_ns_request_handler(void *context, Ns_Conn *conn){	int status = NS_OK;	TSRMLS_FETCH();		NSG(conn) = conn;		SG(server_context) = global_context;	php_ns_request_ctor(TSRMLS_C);		status = php_ns_module_main(TSRMLS_C);		php_ns_request_dtor(TSRMLS_C);	return status;}/* * php_ns_config() fetches the configuration data. * * It understands the "map" and "php_value" command. */static void php_ns_config(php_ns_context *ctx, char global){	int i;	char *path;	Ns_Set *set;	path = Ns_ConfigGetPath(ctx->ns_server, ctx->ns_module, NULL);	set = Ns_ConfigGetSection(path);	for (i = 0; set && i < Ns_SetSize(set); i++) {		char *key = Ns_SetKey(set, i);		char *value = Ns_SetValue(set, i);		if (global && !strcasecmp(key, "map")) {			Ns_Log(Notice, "Registering PHP for \"%s\"", value);			Ns_RegisterRequest(ctx->ns_server, "GET", value, php_ns_request_handler, NULL, ctx, 0);			Ns_RegisterRequest(ctx->ns_server, "POST", value, php_ns_request_handler, NULL, ctx, 0);			Ns_RegisterRequest(ctx->ns_server, "HEAD", value, php_ns_request_handler, NULL, ctx, 0);	/* 	 * Deactivated for now. The ini system will cause random crashes when 	 * accessed from here (since there are no locks to protect the global 	 * known_directives) 	 */		} else if (!global && !strcasecmp(key, "php_value")) {			Ns_Log(Notice, "php_value has been deactivated temporarily. Please use a php.ini file to pass directives to PHP. Thanks.");#if 0			char *val;			val = strchr(value, ' ');			if (val) {				char *new_key;								new_key = estrndup(value, val - value);								do { 					val++; 				} while(*val == ' ');				Ns_Log(Debug, "PHP configuration option '%s=%s'", new_key, val);				zend_alter_ini_entry(new_key, strlen(new_key) + 1, val, 						strlen(val) + 1, PHP_INI_SYSTEM, PHP_INI_STAGE_RUNTIME);								efree(new_key);			}#endif		}			}}	/* * php_ns_server_shutdown() performs the last steps before the * server exits. Shutdowns basic services and frees memory */static voidphp_ns_server_shutdown(void *context){	php_ns_context *ctx = (php_ns_context *) context;		ctx->sapi_module->shutdown(ctx->sapi_module);	sapi_shutdown();	tsrm_shutdown();	free(ctx->ns_module);	free(ctx->ns_server);	free(ctx);}/* * Ns_ModuleInit() is called by AOLserver once at startup * * This functions allocates basic structures and initializes * basic services. */int Ns_ModuleInit(char *server, char *module){	php_ns_context *ctx;		tsrm_startup(1, 1, 0, NULL);	sapi_startup(&aolserver_sapi_module);	sapi_module.startup(&aolserver_sapi_module);		/* TSRM is used to allocate a per-thread structure */	ts_allocate_id(&ns_globals_id, sizeof(ns_globals_struct), NULL, NULL);		/* the context contains data valid for all threads */	ctx = malloc(sizeof *ctx);	ctx->sapi_module = &aolserver_sapi_module;	ctx->ns_server = strdup(server);	ctx->ns_module = strdup(module);		/* read the configuration */	php_ns_config(ctx, 1);	global_context = ctx;	/* register shutdown handler */	Ns_RegisterServerShutdown(server, php_ns_server_shutdown, ctx);	return NS_OK;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -