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

📄 nsapi.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
			buf[NS_BUF_SIZE]='\0';		}		php_register_variable("REQUEST_URI", buf, track_vars_array TSRMLS_CC);		strlcpy(buf, SG(request_info).request_uri, NS_BUF_SIZE);		if (rc->path_info) {			pos = strlen(SG(request_info).request_uri) - strlen(rc->path_info);			if (pos>=0 && pos<=NS_BUF_SIZE && rc->path_info) {				buf[pos] = '\0';			} else {				buf[0]='\0';			}		}		php_register_variable("SCRIPT_NAME", buf, track_vars_array TSRMLS_CC);	}	php_register_variable("SCRIPT_FILENAME", SG(request_info).path_translated, track_vars_array TSRMLS_CC);	/* special variables in error mode */	if (rc->http_error) {		sprintf(buf, "%d", rc->http_error);		php_register_variable("ERROR_TYPE", buf, track_vars_array TSRMLS_CC);	}}static void nsapi_log_message(char *message){	TSRMLS_FETCH();	nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);	log_error(LOG_INFORM, pblock_findval("fn", rc->pb), rc->sn, rc->rq, "%s", message);}static int php_nsapi_startup(sapi_module_struct *sapi_module){	if (php_module_startup(sapi_module, &nsapi_module_entry, 1)==FAILURE) {		return FAILURE;	}	return SUCCESS;}static sapi_module_struct nsapi_sapi_module = {	"nsapi",                                /* name */	"NSAPI",                                /* pretty name */	php_nsapi_startup,                      /* startup */	php_module_shutdown_wrapper,            /* shutdown */	NULL,                                   /* activate */	NULL,                                   /* deactivate */	sapi_nsapi_ub_write,                    /* unbuffered write */	NULL,                                   /* flush */	NULL,                                   /* get uid */	NULL,                                   /* getenv */	php_error,                              /* error handler */	sapi_nsapi_header_handler,              /* header handler */	sapi_nsapi_send_headers,                /* send headers handler */	NULL,                                   /* send header handler */	sapi_nsapi_read_post,                   /* read POST data */	sapi_nsapi_read_cookies,                /* read Cookies */	sapi_nsapi_register_server_variables,   /* register server variables */	nsapi_log_message,                      /* Log message */	NULL,                                   /* Block interruptions */	NULL,                                   /* Unblock interruptions */	STANDARD_SAPI_MODULE_PROPERTIES};static void nsapi_php_ini_entries(NSLS_D TSRMLS_DC){	struct pb_entry *entry;	register int i,j,ok;	for (i=0; i < NSG(pb)->hsize; i++) {		entry=NSG(pb)->ht[i];		while (entry) {			/* exclude standard entries given to "Service" which should not go into ini entries */			ok=1;			for (j=0; nsapi_exclude_from_ini_entries[j]; j++) {				ok&=(strcasecmp(entry->param->name, nsapi_exclude_from_ini_entries[j])!=0);			}			if (ok) {				/* change the ini entry */				if (zend_alter_ini_entry(entry->param->name, strlen(entry->param->name)+1,				 entry->param->value, strlen(entry->param->value),				 PHP_INI_SYSTEM, PHP_INI_STAGE_RUNTIME)==FAILURE) {					log_error(LOG_WARN, pblock_findval("fn", NSG(pb)), NSG(sn), NSG(rq), "Cannot change php.ini key \"%s\" to \"%s\"", entry->param->name, entry->param->value);				}			}			entry=entry->next;		}  	}}void NSAPI_PUBLIC php4_close(void *vparam){	if (nsapi_sapi_module.shutdown) {		nsapi_sapi_module.shutdown(&nsapi_sapi_module);	}	if (nsapi_sapi_module.php_ini_path_override) {		free(nsapi_sapi_module.php_ini_path_override);	}	#ifdef PHP_WIN32	if (nsapi_dll) {		free(nsapi_dll);		nsapi_dll = NULL;	}#endif		tsrm_shutdown();	log_error(LOG_INFORM, "php4_close", NULL, NULL, "Shutdown PHP Module");}/*********************************************************/ init SAF// Init fn="php4_init" [php_ini="/path/to/php.ini"] [server_lib="ns-httpdXX.dll"]/   Initialize the NSAPI module in magnus.conf// php_ini: gives path to php.ini file/ server_lib: (only Win32) gives name of DLL (without path) to look for/  servact_* functions//*********************************************************/int NSAPI_PUBLIC php4_init(pblock *pb, Session *sn, Request *rq){	php_core_globals *core_globals;	char *strval;	int threads=128; /* default for server */	/* fetch max threads from NSAPI and initialize TSRM with it */#if defined(pool_maxthreads)	threads=pool_maxthreads;	if (threads<1) {		threads=128; /* default for server */	}#endif	tsrm_startup(threads, 1, 0, NULL);	core_globals = ts_resource(core_globals_id);	/* look if php_ini parameter is given to php4_init */	if (strval = pblock_findval("php_ini", pb)) {		nsapi_sapi_module.php_ini_path_override = strdup(strval);	}	#ifdef PHP_WIN32	/* look if server_lib parameter is given to php4_init	 * (this disables the automatic search for the newest ns-httpdXX.dll) */	if (strval = pblock_findval("server_lib", pb)) {		nsapi_dll = strdup(strval);	}#endif		/* start SAPI */	sapi_startup(&nsapi_sapi_module);	nsapi_sapi_module.startup(&nsapi_sapi_module);	daemon_atrestart(&php4_close, NULL);	log_error(LOG_INFORM, pblock_findval("fn", pb), sn, rq, "Initialized PHP Module (%d threads exspected)", threads);	return REQ_PROCEED;}/*********************************************************/ normal use in Service directive:// Service fn="php4_execute" type=... method=... [inikey=inivalue inikey=inivalue...]// use in Service for a directory to supply a php-made directory listing instead of server default:// Service fn="php4_execute" type="magnus-internal/directory" script="/path/to/script.php" [inikey=inivalue inikey=inivalue...]// use in Error SAF to display php script as error page:// Error fn="php4_execute" code=XXX script="/path/to/script.php" [inikey=inivalue inikey=inivalue...]/ Error fn="php4_execute" reason="Reason" script="/path/to/script.php" [inikey=inivalue inikey=inivalue...]//*********************************************************/int NSAPI_PUBLIC php4_execute(pblock *pb, Session *sn, Request *rq){	int retval;	nsapi_request_context *request_context;	zend_file_handle file_handle = {0};	struct stat fst;	char *path_info;	char *query_string    = pblock_findval("query", rq->reqpb);	char *uri             = pblock_findval("uri", rq->reqpb);	char *request_method  = pblock_findval("method", rq->reqpb);	char *content_type    = pblock_findval("content-type", rq->headers);	char *content_length  = pblock_findval("content-length", rq->headers);	char *directive       = pblock_findval("Directive", pb);	int error_directive   = (directive && !strcasecmp(directive, "error"));	int fixed_script      = 1;	/* try to use script parameter -> Error or Service for directory listing */	char *path_translated = pblock_findval("script", pb);	TSRMLS_FETCH();	/* if script parameter is missing: normal use as Service SAF  */	if (!path_translated) {		path_translated = pblock_findval("path", rq->vars);		path_info       = pblock_findval("path-info", rq->vars);		fixed_script = 0;		if (error_directive) {			/* go to next error directive if script parameter is missing */			log_error(LOG_WARN, pblock_findval("fn", pb), sn, rq, "Missing 'script' parameter");			return REQ_NOACTION;		}	} else {		/* in error the path_info is the uri to the requested page */		path_info = pblock_findval("uri", rq->reqpb);	}	/* check if this uri was included in an other PHP script with nsapi_virtual()	   by looking for a request context in the current thread */	if (SG(server_context)) {		/* send 500 internal server error */		log_error(LOG_WARN, pblock_findval("fn", pb), sn, rq, "Cannot make nesting PHP requests with nsapi_virtual()");		if (error_directive) {			return REQ_NOACTION;		} else {			protocol_status(sn, rq, 500, NULL);			return REQ_ABORTED;		}	}	request_context = (nsapi_request_context *)MALLOC(sizeof(nsapi_request_context));	request_context->pb = pb;	request_context->sn = sn;	request_context->rq = rq;	request_context->read_post_bytes = 0;	request_context->fixed_script = fixed_script;	request_context->http_error = (error_directive) ? rq->status_num : 0;	request_context->path_info = nsapi_strdup(path_info);	SG(server_context) = request_context;	SG(request_info).query_string = nsapi_strdup(query_string);	SG(request_info).request_uri = nsapi_strdup(uri);	SG(request_info).request_method = nsapi_strdup(request_method);	SG(request_info).path_translated = nsapi_strdup(path_translated);	SG(request_info).content_type = nsapi_strdup(content_type);	SG(request_info).content_length = (content_length == NULL) ? 0 : strtoul(content_length, 0, 0);	SG(sapi_headers).http_response_code = (error_directive) ? rq->status_num : 200;	nsapi_php_ini_entries(NSLS_C TSRMLS_CC);	if (!PG(safe_mode)) php_handle_auth_data(pblock_findval("authorization", rq->headers) TSRMLS_CC);	file_handle.type = ZEND_HANDLE_FILENAME;	file_handle.filename = SG(request_info).path_translated;	file_handle.free_filename = 0;	file_handle.opened_path = NULL;	if (stat(SG(request_info).path_translated, &fst)==0 && S_ISREG(fst.st_mode)) {		if (php_request_startup(TSRMLS_C) == SUCCESS) {			php_execute_script(&file_handle TSRMLS_CC);			php_request_shutdown(NULL);			retval=REQ_PROCEED;		} else {			/* send 500 internal server error */			log_error(LOG_WARN, pblock_findval("fn", pb), sn, rq, "Cannot prepare PHP engine!");			if (error_directive) {				retval=REQ_NOACTION;			} else {				protocol_status(sn, rq, 500, NULL);				retval=REQ_ABORTED;			}		}	} else {		/* send 404 because file not found */		log_error(LOG_WARN, pblock_findval("fn", pb), sn, rq, "Cannot execute PHP script: %s (File not found)", SG(request_info).path_translated);		if (error_directive) {			retval=REQ_NOACTION;		} else {			protocol_status(sn, rq, 404, NULL);			retval=REQ_ABORTED;		}	}	nsapi_free(request_context->path_info);	nsapi_free(SG(request_info).query_string);	nsapi_free(SG(request_info).request_uri);	nsapi_free((void*)(SG(request_info).request_method));	nsapi_free(SG(request_info).path_translated);	nsapi_free((void*)(SG(request_info).content_type));	FREE(request_context);	SG(server_context) = NULL;	return retval;}/*********************************************************/ authentication// we have to make a 'fake' authenticator for netscape so it/ will pass authentication through to php, and allow us to/ check authentication with our scripts.// php4_auth_trans/   main function called from netscape server to authenticate/   a line in obj.conf:/		funcs=php4_auth_trans shlib="path/to/this/phpnsapi.dll"/	and:/		<Object ppath="path/to/be/authenticated/by/php/*">/		AuthTrans fn="php4_auth_trans"/*********************************************************/int NSAPI_PUBLIC php4_auth_trans(pblock * pb, Session * sn, Request * rq){	/* This is a DO NOTHING function that allows authentication	 * information	 * to be passed through to PHP scripts.	 */	return REQ_PROCEED;}/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */

⌨️ 快捷键说明

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