cvs: php4 /sapi/caudium caudium.c
| From: | David Hedbor | Date: | Fri, 03 Nov 2000 00:29:06 +0000 |
| Subject: | cvs: php4 /sapi/caudium caudium.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-2439@lists.php.net to get a copy of this message | ||
neotron Thu Nov 2 16:29:06 2000 EDT
Modified files:
/php4/sapi/caudium caudium.c
Log:
Use V_CHDIR_FILE instead of doing the job of that function myself and
added a define to disable the use of threads for debugging purposes.
@Support for the Caudium webserver (http://caudium.net/) added. It's based
@on the Roxen SAPI module. Many bugs have been identified and fixed. (David)
Index: php4/sapi/caudium/caudium.c
diff -u php4/sapi/caudium/caudium.c:1.2 php4/sapi/caudium/caudium.c:1.3
--- php4/sapi/caudium/caudium.c:1.2 Thu Nov 2 12:05:24 2000
+++ php4/sapi/caudium/caudium.c Thu Nov 2 16:29:05 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: caudium.c,v 1.2 2000/11/02 20:05:24 neotron Exp $ */
+/* $Id: caudium.c,v 1.3 2000/11/03 00:29:05 neotron Exp $ */
#include "php.h"
#ifdef HAVE_CAUDIUM
@@ -37,7 +37,10 @@
*
*/
#define NO_PIKE_SHORTHAND
-
+/* Define to run w/o th_farm. This allows for A LOT easier
+ * debugging due to stupid gdb...
+ */
+/*#define TEST_NO_THREADS*/
#include <fdlib.h>
#include <program.h>
#include <pike_types.h>
@@ -208,7 +211,8 @@
* interpreter for better threading.
*/
-static int php_caudium_low_ub_write(const char *str, uint str_length) {
+INLINE static int
+php_caudium_low_ub_write(const char *str, uint str_length) {
int sent_bytes = 0;
struct pike_string *to_write = NULL;
PLS_FETCH();
@@ -234,7 +238,8 @@
/*
* php_caudium_sapi_ub_write() calls php_caudium_low_ub_write in a Pike thread
- * safe manner.
+ * safe manner or writes directly to the output FD if RXML post-parsing is
+ * disabled.
*/
static int
@@ -257,6 +262,7 @@
/* This means the connection is closed. Dead. Gone. *sniff* */
PG(connection_status) = PHP_CONNECTION_ABORTED;
zend_bailout();
+ THIS->written += sent_bytes;
return sent_bytes;
case EINTR:
case EWOULDBLOCK:
@@ -277,20 +283,21 @@
/* php_caudium_set_header() sets a header in the header mapping. Called in a
* thread safe manner from php_caudium_sapi_header_handler.
*/
-static void php_caudium_set_header(char *header_name, char *value, char *p)
+INLINE static void
+php_caudium_set_header(char *header_name, char *value, char *p)
{
struct svalue hsval;
struct pike_string *hval, *ind, *hind;
struct mapping *headermap;
- struct svalue *s_headermap;
+ struct svalue *s_headermap, *soldval;
GET_THIS();
- hval = make_shared_string(value);
+ // hval = make_shared_string(value);
ind = make_shared_string(" _headers");
hind = make_shared_binary_string(header_name,
(int)(p - header_name));
s_headermap = low_mapping_string_lookup(REQUEST_DATA, ind);
- if(!s_headermap)
+ if(!s_headermap || s_headermap->type != PIKE_T_MAPPING)
{
struct svalue mappie;
mappie.type = PIKE_T_MAPPING;
@@ -298,11 +305,23 @@
mappie.u.mapping = headermap;
mapping_string_insert(REQUEST_DATA, ind, &mappie);
free_mapping(headermap);
- } else
+ hval = make_shared_string(value);
+ } else {
headermap = s_headermap->u.mapping;
-
+#if 0
+ soldval = low_mapping_string_lookup(s_headermap, hind);
+ if(soldval != NULL &&
+ soldval->u.type == PIKE_T_STRING &&
+ soldval->u.string->size_shift == 0) {
+ /* Existing, valid header. Prepend.*/
+ hval = make_shared_string(value);
+ }
+#endif
+ hval = make_shared_string(value);
+ }
hsval.type = PIKE_T_STRING;
hsval.u.string = hval;
+
mapping_string_insert(headermap, hind, &hsval);
free_string(hval);
@@ -337,7 +356,7 @@
* Called before real content is sent by PHP.
*/
-static int
+INLINE static int
php_caudium_low_send_headers(sapi_headers_struct *sapi_headers SLS_DC)
{
PLS_FETCH();
@@ -426,7 +445,7 @@
{
/* char buf[512]; */
php_info_print_table_start();
- php_info_print_table_row(2, "SAPI module version", "$Id: caudium.c,v 1.2
2000/11/02 20:05:24 neotron Exp $");
+ php_info_print_table_row(2, "SAPI module version", "$Id: caudium.c,v 1.3
2000/11/03 00:29:05 neotron 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());
@@ -499,16 +518,7 @@
* with a number of variables. HTTP_* variables are created for
* the HTTP header data, so that a script can access these.
*/
-#define ADD_STRING(name) \
- MAKE_STD_ZVAL(pval); \
- pval->type = IS_STRING; \
- pval->value.str.len = strlen(buf); \
- pval->value.str.val = estrndup(buf, pval->value.str.len); \
- zend_hash_update(&EG(symbol_table), name, sizeof(name), \
- &pval, sizeof(zval *), NULL)
-
-static void
-php_caudium_hash_environment(CLS_D ELS_DC PLS_DC SLS_DC)
+static void php_caudium_hash_environment(CLS_D ELS_DC PLS_DC SLS_DC)
{
int i;
char buf[512];
@@ -577,6 +587,7 @@
THIS->request_data = ureq->request_data;
free(ureq);
// current_thread = th_self();
+#ifndef TEST_NO_THREADS
mt_lock(&interpreter_lock);
init_interpreter();
#if PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION < 1
@@ -600,7 +611,7 @@
num_threads++;
thread_table_insert(Pike_interpreter.thread_id);
#endif
-
+#endif
SG(request_info).query_string = lookup_string_header("QUERY_STRING", 0);
SG(server_context) = (void *)1; /* avoid server_context == NULL */
@@ -630,26 +641,21 @@
* Pike threads to run. We wait since the above would otherwise require
* a lot of unlock/lock.
*/
+#ifndef TEST_NO_THREADS
SWAP_OUT_CURRENT_THREAD();
mt_unlock(&interpreter_lock);
-
+#endif
+ /* Change virtual work directory */
+
#ifdef VIRTUAL_DIR
/* Change virtual directory, if the feature is enabled, which is
* almost a requirement for PHP in Roxen. Might want to fail if it
- * isn't.
+ * isn't. Not a problem though, since it's on by default when using ZTS.
*/
- dir = malloc(len = THIS->filename->len);
- strcpy(dir, THIS->filename->str);
- while(--len >= 0 && dir[len] != '/')
- ;
- if(len > 0) {
- dir[len] = '\0';
- }
- V_CHDIR(dir);
- free(dir);
+ V_CHDIR_FILE(THIS->filename->str);
#endif
-
+
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.filename = THIS->filename->str;
file_handle.free_filename = 0;
@@ -674,6 +680,7 @@
free_struct(SLS_C);
}, "positive run response");
}
+#ifndef TEST_NO_THREADS
mt_lock(&interpreter_lock);
SWAP_IN_CURRENT_THREAD();
#if PIKE_MAJOR_VERSION == 7 && PIKE_MINOR_VERSION < 1
@@ -692,6 +699,7 @@
cleanup_interpret();
num_threads--;
mt_unlock(&interpreter_lock);
+#endif
}
/*
@@ -738,8 +746,11 @@
THIS->my_fd = fd;
} else
THIS->my_fd = 0;
+#ifdef TEST_NO_THREADS
+ php_caudium_module_main(THIS);
+#else
th_farm((void (*)(void *))php_caudium_module_main, THIS);
-
+#endif
pop_n_elems(args);
}