1999-09-25 00:32:25 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP version 4.0 |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Copyright (c) 1997, 1998, 1999 The PHP Group |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 2.0 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
|
|
|
| http://www.php.net/license/2_0.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> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1999-09-25 16:51:18 +00:00
|
|
|
/* conflict between PHP and aolserver */
|
|
|
|
#define Debug php_Debug
|
1999-09-25 00:32:25 +00:00
|
|
|
#include "php.h"
|
1999-09-25 16:51:18 +00:00
|
|
|
#undef Debug
|
1999-09-25 00:32:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_AOLSERVER
|
|
|
|
|
|
|
|
#include "php_ini.h"
|
|
|
|
#include "php_globals.h"
|
|
|
|
#include "SAPI.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
#include "ns.h"
|
|
|
|
|
|
|
|
#include "php_version.h"
|
|
|
|
|
|
|
|
int Ns_ModuleVersion = 1;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
sapi_module_struct *sapi_module;
|
|
|
|
Ns_DString content_type;
|
|
|
|
Ns_Conn *conn;
|
1999-09-25 16:06:55 +00:00
|
|
|
char *ns_server;
|
|
|
|
char *ns_module;
|
|
|
|
} php_ns_context;
|
|
|
|
|
|
|
|
static void php_ns_config(php_ns_context *ctx);
|
1999-09-25 00:32:25 +00:00
|
|
|
|
|
|
|
static int
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_sapi_ub_write(const char *str, uint str_length)
|
1999-09-25 00:32:25 +00:00
|
|
|
{
|
|
|
|
Ns_DString dstr;
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_context *ctx;
|
1999-09-25 00:32:25 +00:00
|
|
|
SLS_FETCH();
|
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
ctx = (php_ns_context *) SG(server_context);
|
1999-09-25 00:32:25 +00:00
|
|
|
|
|
|
|
Ns_DStringInit(&dstr);
|
|
|
|
Ns_DStringNAppend(&dstr, (char *) str, str_length);
|
|
|
|
Ns_ConnSendDString(ctx->conn, &dstr);
|
|
|
|
Ns_DStringFree(&dstr);
|
|
|
|
|
|
|
|
return str_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers SLS_DC)
|
1999-09-25 00:32:25 +00:00
|
|
|
{
|
|
|
|
char *header_name, *header_content;
|
|
|
|
char *p;
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_context *ctx = (php_ns_context *) SG(server_context);
|
1999-09-25 00:32:25 +00:00
|
|
|
|
|
|
|
header_name = sapi_header->header;
|
|
|
|
header_content = p = strchr(header_name, ':');
|
|
|
|
|
|
|
|
if(!p) return 0;
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
do {
|
|
|
|
header_content++;
|
|
|
|
} while(*header_content == ' ');
|
|
|
|
|
|
|
|
if(!strcasecmp(header_name, "Content-type")) {
|
|
|
|
Ns_ConnSetTypeHeader(ctx->conn, header_content);
|
|
|
|
} else {
|
|
|
|
Ns_ConnSetHeaders(ctx->conn, header_name, header_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
*p = ':';
|
|
|
|
|
|
|
|
efree(sapi_header->header);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_sapi_send_headers(sapi_headers_struct *sapi_headers SLS_DC)
|
1999-09-25 00:32:25 +00:00
|
|
|
{
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_context *ctx;
|
1999-09-25 00:32:25 +00:00
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
ctx = (php_ns_context *) SG(server_context);
|
1999-09-25 15:37:02 +00:00
|
|
|
Ns_ConnFlushHeaders(ctx->conn, SG(sapi_headers).http_response_code);
|
1999-09-25 00:32:25 +00:00
|
|
|
return SAPI_HEADER_SENT_SUCCESSFULLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_sapi_read_post(char *buf, uint count_bytes SLS_DC)
|
1999-09-25 00:32:25 +00:00
|
|
|
{
|
|
|
|
uint total_read = 0;
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_context *ctx = (php_ns_context *) SG(server_context);
|
1999-09-25 00:32:25 +00:00
|
|
|
|
1999-09-25 15:37:02 +00:00
|
|
|
total_read = Ns_ConnRead(ctx->conn, buf, count_bytes);
|
|
|
|
|
|
|
|
if(total_read == NS_ERROR) {
|
|
|
|
total_read = -1;
|
|
|
|
}
|
|
|
|
|
1999-09-25 00:32:25 +00:00
|
|
|
return total_read;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_sapi_read_cookies(SLS_D)
|
1999-09-25 00:32:25 +00:00
|
|
|
{
|
1999-09-25 16:51:18 +00:00
|
|
|
Ns_Set *headers;
|
|
|
|
char *http_cookie;
|
|
|
|
php_ns_context *ctx = (php_ns_context *) SG(server_context);
|
|
|
|
|
|
|
|
headers = Ns_ConnHeaders(conn);
|
|
|
|
|
|
|
|
if(headers) {
|
|
|
|
http_cookie = Ns_SetGet(headers, "HTTP_COOKIE");
|
|
|
|
}
|
|
|
|
|
|
|
|
return http_cookie;
|
1999-09-25 00:32:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static sapi_module_struct sapi_module = {
|
|
|
|
"PHP Language",
|
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
php_module_startup, /* startup */
|
1999-09-25 00:32:25 +00:00
|
|
|
php_module_shutdown_wrapper, /* shutdown */
|
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_sapi_ub_write, /* unbuffered write */
|
1999-09-25 00:32:25 +00:00
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
php_error, /* error handler */
|
1999-09-25 00:32:25 +00:00
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_sapi_header_handler, /* header handler */
|
|
|
|
php_ns_sapi_send_headers, /* send headers handler */
|
|
|
|
NULL, /* send header handler */
|
1999-09-25 00:32:25 +00:00
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_sapi_read_post, /* read POST data */
|
|
|
|
php_ns_sapi_read_cookies, /* read Cookies */
|
1999-09-25 00:32:25 +00:00
|
|
|
|
|
|
|
STANDARD_SAPI_MODULE_PROPERTIES
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_module_main(php_ns_context *ctx SLS_DC)
|
1999-09-25 00:32:25 +00:00
|
|
|
{
|
|
|
|
zend_file_handle file_handle;
|
1999-09-25 01:06:33 +00:00
|
|
|
CLS_FETCH();
|
|
|
|
ELS_FETCH();
|
|
|
|
PLS_FETCH();
|
1999-09-25 00:32:25 +00:00
|
|
|
|
|
|
|
file_handle.type = ZEND_HANDLE_FILENAME;
|
|
|
|
file_handle.filename = SG(request_info).path_translated;
|
|
|
|
|
|
|
|
php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC);
|
|
|
|
php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC);
|
|
|
|
php_request_shutdown(NULL);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_request_ctor(php_ns_context *ctx SLS_DC)
|
1999-09-25 00:32:25 +00:00
|
|
|
{
|
|
|
|
char *server;
|
|
|
|
Ns_DString ds;
|
|
|
|
char *root;
|
|
|
|
|
|
|
|
server = Ns_ConnServer(ctx->conn);
|
|
|
|
|
|
|
|
SG(server_context) = ctx;
|
1999-09-25 01:06:33 +00:00
|
|
|
SG(request_info).query_string = ctx->conn->request->query;
|
1999-09-25 00:32:25 +00:00
|
|
|
|
|
|
|
Ns_DStringInit(&ds);
|
|
|
|
Ns_UrlToFile(&ds, server, ctx->conn->request->url);
|
|
|
|
SG(request_info).path_translated = strdup(Ns_DStringValue(&ds));
|
|
|
|
Ns_DStringFree(&ds);
|
|
|
|
root = Ns_PageRoot(server);
|
|
|
|
SG(request_info).request_uri = SG(request_info).path_translated + strlen(root);
|
1999-09-25 01:06:33 +00:00
|
|
|
SG(request_info).request_method = ctx->conn->request->method;
|
1999-09-25 00:32:25 +00:00
|
|
|
SG(request_info).content_length = Ns_ConnContentLength(ctx->conn);
|
|
|
|
Ns_DStringInit(&ctx->content_type);
|
|
|
|
Ns_ConnCopyToDString(ctx->conn, SG(request_info).content_length, &ctx->content_type);
|
|
|
|
SG(request_info).content_type = Ns_DStringValue(&ctx->content_type);
|
|
|
|
SG(request_info).auth_user = NULL;
|
|
|
|
SG(request_info).auth_password = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_request_dtor(php_ns_context *ctx SLS_DC)
|
1999-09-25 00:32:25 +00:00
|
|
|
{
|
|
|
|
free(SG(request_info).path_translated);
|
|
|
|
Ns_DStringFree(&ctx->content_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_request_handler(void *context, Ns_Conn *conn)
|
1999-09-25 00:32:25 +00:00
|
|
|
{
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_context *ctx = (php_ns_context *) context;
|
1999-09-25 00:32:25 +00:00
|
|
|
int status = NS_OK;
|
|
|
|
SLS_FETCH();
|
|
|
|
|
|
|
|
ctx->conn = conn;
|
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_request_ctor(ctx SLS_CC);
|
1999-09-25 00:32:25 +00:00
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
status = php_ns_module_main(ctx SLS_CC);
|
1999-09-25 00:32:25 +00:00
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_request_dtor(ctx SLS_CC);
|
1999-09-25 00:32:25 +00:00
|
|
|
|
|
|
|
ctx->conn = NULL;
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
static void
|
|
|
|
php_ns_config(php_ns_context *ctx)
|
1999-09-25 01:06:33 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *path;
|
|
|
|
Ns_Set *set;
|
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
path = Ns_ConfigPath(ctx->ns_server, ctx->ns_module, NULL);
|
1999-09-25 01:06:33 +00:00
|
|
|
set = Ns_ConfigGetSection(path);
|
|
|
|
|
|
|
|
for(i = 0; set && i < Ns_SetSize(set); i++) {
|
1999-09-25 15:37:02 +00:00
|
|
|
char *key = Ns_SetKey(set, i);
|
|
|
|
char *value = Ns_SetValue(set, i);
|
1999-09-25 01:06:33 +00:00
|
|
|
|
|
|
|
if(!strcasecmp(key, "map")) {
|
1999-09-25 15:37:02 +00:00
|
|
|
Ns_Log(Notice, "Registering PHP for \"%s\"", value);
|
1999-09-25 16:06:55 +00:00
|
|
|
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);
|
1999-09-25 15:37:02 +00:00
|
|
|
} else if(!strcasecmp(key, "php_value")) {
|
|
|
|
char *val;
|
|
|
|
|
|
|
|
val = strchr(value, ' ');
|
|
|
|
if(val) {
|
1999-09-25 16:06:55 +00:00
|
|
|
char *new_key;
|
1999-09-25 15:37:02 +00:00
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
new_key = estrndup(value, val - value);
|
1999-09-25 15:37:02 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
val++;
|
|
|
|
} while(*val == ' ');
|
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
Ns_Log(Debug, "PHP configuration option '%s=%s'", new_key, val);
|
|
|
|
php_alter_ini_entry(new_key, strlen(new_key) + 1, val,
|
|
|
|
strlen(val) + 1, PHP_INI_SYSTEM);
|
|
|
|
|
|
|
|
efree(new_key);
|
1999-09-25 15:37:02 +00:00
|
|
|
}
|
1999-09-25 01:06:33 +00:00
|
|
|
}
|
1999-09-25 15:37:02 +00:00
|
|
|
|
1999-09-25 01:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
static void
|
|
|
|
php_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);
|
|
|
|
}
|
|
|
|
|
1999-09-25 00:32:25 +00:00
|
|
|
int Ns_ModuleInit(char *server, char *module)
|
|
|
|
{
|
1999-09-25 16:06:55 +00:00
|
|
|
php_ns_context *ctx;
|
1999-09-25 00:32:25 +00:00
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
tsrm_startup(1, 1, 0);
|
1999-09-25 00:32:25 +00:00
|
|
|
sapi_startup(&sapi_module);
|
|
|
|
sapi_module.startup(&sapi_module);
|
|
|
|
|
|
|
|
ctx = malloc(sizeof *ctx);
|
|
|
|
ctx->sapi_module = &sapi_module;
|
1999-09-25 16:06:55 +00:00
|
|
|
ctx->ns_server = strdup(server);
|
|
|
|
ctx->ns_module = strdup(module);
|
|
|
|
|
|
|
|
php_ns_config(ctx);
|
1999-09-25 00:32:25 +00:00
|
|
|
|
1999-09-25 16:06:55 +00:00
|
|
|
Ns_RegisterServerShutdown(server, php_ns_server_shutdown, ctx);
|
1999-09-25 00:32:25 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|