Browse Source

merged r541:559 from trunk

git-svn-id: svn://svn.lighttpd.net/xcache/branches/1.3@625 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
1.3
Xuefer 12 years ago
parent
commit
a8d5bf679d
  1. 3
      ChangeLog
  2. 1
      NEWS
  3. 2
      admin/common.php
  4. 24
      admin/mkpassword.php
  5. 4
      admin/xcache.php
  6. 15
      coverager.c
  7. 13
      mem.c
  8. 2
      mmap.c
  9. 15
      processor/processor.m4
  10. 66
      utils.c
  11. 10
      utils.h
  12. 61
      xcache.c
  13. 10
      xcache.h

3
ChangeLog

@ -1,11 +1,12 @@
1.3.0 2009-??-??
== ChangeLog ==
* PHP 5.3 Supported
* fixed #138: no segv if cache is not initialized correctly
* default to 64M for xcache.size in xcache.ini
* could not show module info in admin page when XCache is the last module
* wrong http auth realm
* coverager: font-size and newline fix for firefox
* PHP 5.3 Supported
* admin page is now magic quote gpc aware
1.2.2 2007-12-29
== ChangeLog ==

1
NEWS

@ -3,6 +3,7 @@
* PHP 5.3 Supported
* many cacher/coverager bug fixes
* improved admin pages
* admin page is now magic quote gpc aware
1.2.2 2007-12-29
========

2
admin/common.php

@ -91,7 +91,7 @@ error_reporting(E_ALL);
ini_set('display_errors', 'On');
define('REQUEST_TIME', time());
if (get_magic_quotes_gpc()) {
if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc()) {
$mqs = (bool) ini_get('magic_quotes_sybase');
$_GET = stripaddslashes_array($_GET, $mqs);
$_POST = stripaddslashes_array($_POST, $mqs);

24
admin/mkpassword.php

@ -0,0 +1,24 @@
<html>
<head>
<title>Simple MD5 password generator</title>
</head>
<body>
<h1>Simple MD5 password generator</h1>
<form method="post">
<fieldset>
md5: <input type="password" name="password"> <input type="submit"><br>
<div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$md5 = md5(@ $_POST['password']);
$offs = mt_rand(0 + 1, 31 - 1);
$md5_1 = substr($md5, 0, $offs);
$md5_2 = substr($md5, $offs);
echo "Result: <span>$md5_1</span><span>$md5_2</span>";
}
?>
</div>
</fieldset>
</form>
</body>
</html>

4
admin/xcache.php

@ -129,8 +129,8 @@ function calc_total(&$total, $data)
}
else {
switch ($k) {
case 'his_by_hour':
case 'his_by_second':
case 'hits_by_hour':
case 'hits_by_second':
foreach ($data[$k] as $kk => $vv) {
$total[$k][$kk] += $vv;
}

15
coverager.c

@ -1,3 +1,7 @@
#if 0
#define XCACHE_DEBUG
#endif
#include <stdio.h>
#include "xcache.h"
#include "ext/standard/flock_compat.h"
@ -18,10 +22,6 @@ typedef HashTable *coverager_t;
static char *xc_coveragedump_dir = NULL;
static zend_compile_file_t *old_compile_file = NULL;
#if 0
#define DEBUG
#endif
/* dumper */
static void xc_destroy_coverage(void *pDest) /* {{{ */
{
@ -245,7 +245,11 @@ void xc_coverager_request_init(TSRMLS_D) /* {{{ */
{
if (XG(coverager)) {
xc_coverager_enable(TSRMLS_C);
#ifdef ZEND_COMPILE_EXTENDED_INFO
CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
#else
CG(extended_info) = 1;
#endif
}
else {
XG(coverage_enabled) = 0;
@ -469,8 +473,9 @@ int xc_coverager_init(int module_number TSRMLS_DC) /* {{{ */
zend_compile_file = xc_compile_file_for_coverage;
if (cfg_get_string("xcache.coveragedump_directory", &xc_coveragedump_dir) == SUCCESS && xc_coveragedump_dir) {
int len;
xc_coveragedump_dir = pestrdup(xc_coveragedump_dir, 1);
int len = strlen(xc_coveragedump_dir);
len = strlen(xc_coveragedump_dir);
if (len) {
if (xc_coveragedump_dir[len - 1] == '/') {
xc_coveragedump_dir[len - 1] = '\0';

13
mem.c

@ -1,10 +1,16 @@
#ifdef TEST
#include <limits.h>
#include <stdio.h>
# define XCACHE_DEBUG
#else
#include <php.h>
#endif
#ifdef XCACHE_DEBUG
# define ALLOC_DEBUG_BLOCK_CHECK
#endif
#include <assert.h>
#include <stdlib.h>
#include <string.h>
@ -14,13 +20,6 @@
#include "align.h"
#include "utils.h"
#ifdef TEST
# define DEBUG
#endif
#ifdef DEBUG
# define ALLOC_DEBUG_BLOCK_CHECK
#endif
#if 0
#undef ALLOC_DEBUG_BLOCK_CHECK
#endif

2
mmap.c

@ -198,7 +198,7 @@ static XC_SHM_INIT(xc_mmap_init) /* {{{ */
if (shm->ptr == XCACHE_MAP_FAILED) {
perror(shm->name);
errstr = "Failed creating file mappping";
errstr = "Failed creating file mapping";
shm->ptr = NULL;
goto err;
}

15
processor/processor.m4

@ -505,7 +505,12 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
dnl readonly_protection=on
dnl main op_array && have early binding
zend_uint ii;
if (!processor->readonly_protection && !(src == processor->xce_src->data.php->op_array && processor->xce_src->data.php->have_early_binding)) {
#ifdef ZEND_COMPILE_DELAYED_BINDING
zend_bool need_early_binding = 0;
#else
zend_bool need_early_binding = processor->xce_src->data.php->have_early_binding;
#endif
if (!processor->readonly_protection && !(src == processor->xce_src->data.php->op_array && need_early_binding)) {
/* really fast shallow copy */
memcpy(dst, src, sizeof(src[0]));
dst->refcount[0] = 1000;
@ -632,6 +637,9 @@ DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
DISPATCH(int, doc_comment_len)
PROC_ZSTRING_L(, doc_comment, doc_comment_len)
#endif
#ifdef ZEND_COMPILE_DELAYED_BINDING
DISPATCH(zend_uint, early_binding);
#endif
/* reserved */
DONE(reserved)
@ -729,7 +737,9 @@ DEF_STRUCT_P_FUNC(`xc_classinfo_t', , `dnl {{{
#else
STRUCT(zend_class_entry, cest)
#endif
#ifndef ZEND_COMPILE_DELAYED_BINDING
DISPATCH(int, oplineno)
#endif
')
dnl }}}
#ifdef ZEND_ENGINE_2_1
@ -782,7 +792,10 @@ DEF_STRUCT_P_FUNC(`xc_entry_data_php_t', , `dnl {{{
STRUCT_ARRAY(autoglobal_cnt, xc_autoglobal_t, autoglobals)
')
#endif
#ifndef ZEND_COMPILE_DELAYED_BINDING
DISPATCH(zend_bool, have_early_binding)
#endif
DISPATCH(zend_bool, have_references)
')
dnl }}}
DEF_STRUCT_P_FUNC(`xc_entry_data_var_t', , `dnl {{{

66
utils.c

@ -499,9 +499,11 @@ ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int op
cest, sizeof(xc_cest_t),
ZESW(&stored_ce_ptr, NULL)
);
#ifndef ZEND_COMPILE_DELAYED_BINDING
if (oplineno != -1) {
xc_do_early_binding(CG(active_op_array), CG(class_table), oplineno TSRMLS_CC);
}
#endif
}
else if (zend_u_hash_quick_add(CG(class_table), type, key, len, h,
cest, sizeof(xc_cest_t),
@ -525,6 +527,52 @@ ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int op
#define TG(x) (sandbox->tmp_##x)
#define OG(x) (sandbox->orig_##x)
/* }}} */
<<<<<<< .working
=======
#ifdef E_STRICT
static void xc_sandbox_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) /* {{{ */
{
xc_compilererror_t *compilererror;
xc_sandbox_t *sandbox;
TSRMLS_FETCH();
sandbox = (xc_sandbox_t *) XG(sandbox);
assert(sandbox != NULL);
if (type != E_STRICT) {
/* give up, and user handler is not supported in this case */
zend_uint i;
zend_uint orig_lineno = CG(zend_lineno);
zend_error_cb = sandbox->orig_zend_error_cb;
for (i = 0; i < sandbox->compilererror_cnt; i ++) {
compilererror = &sandbox->compilererrors[i];
CG(zend_lineno) = compilererror->lineno;
zend_error(E_STRICT, "%s", compilererror->error);
}
CG(zend_lineno) = orig_lineno;
sandbox->compilererror_cnt = 0;
sandbox->orig_zend_error_cb(type, error_filename, error_lineno, format, args);
return;
}
if (sandbox->compilererror_cnt <= sandbox->compilererror_size) {
if (sandbox->compilererror_size) {
sandbox->compilererror_size += 16;
sandbox->compilererrors = erealloc(sandbox->compilererrors, sandbox->compilererror_size * sizeof(sandbox->compilererrors));
}
else {
sandbox->compilererror_size = 16;
sandbox->compilererrors = emalloc(sandbox->compilererror_size * sizeof(sandbox->compilererrors));
}
}
compilererror = &sandbox->compilererrors[sandbox->compilererror_cnt++];
compilererror->lineno = error_lineno;
compilererror->error_len = vspprintf(&compilererror->error, 0, format, args);
}
/* }}} */
#endif
>>>>>>> .merge-right.r559
#ifdef ZEND_ENGINE_2_1
static zend_bool xc_auto_global_callback(char *name, uint name_len TSRMLS_DC) /* {{{ */
{
@ -624,6 +672,14 @@ xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /
EG(user_error_handler_error_reporting) &= ~E_STRICT;
#endif
#ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES
sandbox->orig_compiler_options = CG(compiler_options);
/* Using ZEND_COMPILE_IGNORE_INTERNAL_CLASSES for ZEND_FETCH_CLASS_RT_NS_CHECK
*/
CG(compiler_options) |= ZEND_COMPILE_IGNORE_INTERNAL_CLASSES | ZEND_COMPILE_DELAYED_BINDING;
#endif
XG(sandbox) = (void *) sandbox;
return sandbox;
}
/* }}} */
@ -635,7 +691,7 @@ static void xc_early_binding_cb(zend_op *opline, int oplineno, void *data TSRMLS
/* }}} */
static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */
{
int i;
zend_uint i;
Bucket *b;
#ifdef HAVE_XCACHE_CONSTANT
@ -678,9 +734,13 @@ static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t instal
#endif
if (install != XC_InstallNoBinding) {
#ifdef ZEND_COMPILE_DELAYED_BINDING
zend_do_delayed_early_binding(CG(active_op_array) TSRMLS_CC);
#else
xc_undo_pass_two(CG(active_op_array) TSRMLS_CC);
xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC);
xc_redo_pass_two(CG(active_op_array) TSRMLS_CC);
#endif
}
i = 1;
@ -734,6 +794,10 @@ void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_D
EG(user_error_handler_error_reporting) = sandbox->orig_user_error_handler_error_reporting;
#endif
#ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES
CG(compiler_options) = sandbox->orig_compiler_options;
#endif
if (sandbox->alloc) {
efree(sandbox);
}

10
utils.h

@ -1,7 +1,7 @@
#include "php.h"
#include "xcache.h"
#ifdef DEBUG
#ifdef XCACHE_DEBUG
# define IFDEBUG(x) (x)
int xc_vtrace(const char *fmt, va_list args);
int xc_trace(const char *fmt, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
@ -24,7 +24,7 @@ static inline int TRACE(const char *fmt, ...)
# undef NDEBUG
# undef inline
# define inline
#else /* DEBUG */
#else /* XCACHE_DEBUG */
# ifdef ZEND_WIN32
static inline int TRACE_DUMMY(const char *fmt, ...)
@ -40,7 +40,7 @@ static inline int TRACE_DUMMY(const char *fmt, ...)
# ifndef NDEBUG
# define NDEBUG
# endif
#endif /* DEBUG */
#endif /* XCACHE_DEBUG */
#include <assert.h>
typedef struct {
@ -100,6 +100,10 @@ typedef struct {
#ifdef E_STRICT
int orig_user_error_handler_error_reporting;
#endif
#ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES
zend_uint orig_compiler_options;
#endif
} xc_sandbox_t;
typedef enum _xc_install_action_t {

61
xcache.c

@ -1,6 +1,6 @@
#if 0
#define DEBUG
#define XCACHE_DEBUG
#endif
#if 0
@ -22,6 +22,9 @@
#include "SAPI.h"
#include "xcache.h"
#ifdef ZEND_ENGINE_2_1
#include "ext/date/php_date.h"
#endif
#include "optimizer.h"
#include "coverager.h"
#include "disassembler.h"
@ -651,8 +654,13 @@ static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRM
}
new_cest_ptrs[i] =
#endif
#ifdef ZEND_COMPILE_DELAYED_BINDING
xc_install_class(xce->name.str.val, &ci->cest, -1,
UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC);
#else
xc_install_class(xce->name.str.val, &ci->cest, ci->oplineno,
UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC);
#endif
}
#ifdef ZEND_ENGINE_2_1
@ -749,7 +757,7 @@ static int xc_stat(const char *filename, const char *include_path, struct stat *
/* }}} */
#define HASH(i) (i)
#define HASH_USTR_L(t, s, l) HASH(zend_u_inline_hash_func(t, s, (l + 1) * sizeof(UChar)))
#define HASH_ZSTR_L(t, s, l) HASH(zend_u_inline_hash_func(t, s, (l + 1) * sizeof(UChar)))
#define HASH_STR_L(s, l) HASH(zend_inline_hash_func(s, l + 1))
#define HASH_STR(s) HASH_STR_L(s, strlen(s) + 1)
#define HASH_NUM(n) HASH(n)
@ -765,7 +773,7 @@ static inline xc_hash_value_t xc_hash_fold(xc_hash_value_t hvalue, const xc_hash
/* }}} */
static inline xc_hash_value_t xc_entry_hash_name(xc_entry_t *xce TSRMLS_DC) /* {{{ */
{
return UNISW(NOTHING, UG(unicode) ? HASH_USTR_L(xce->name_type, xce->name.uni.val, xce->name.uni.len) :)
return UNISW(NOTHING, UG(unicode) ? HASH_ZSTR_L(xce->name_type, xce->name.uni.val, xce->name.uni.len) :)
HASH_STR_L(xce->name.str.val, xce->name.str.len);
}
/* }}} */
@ -892,6 +900,7 @@ static inline xc_hash_value_t xc_php_hash_md5(xc_entry_data_php_t *php TSRMLS_DC
return HASH_STR_S(php->md5, sizeof(php->md5));
}
/* }}} */
#ifndef ZEND_COMPILE_DELAYED_BINDING
static void xc_cache_early_binding_class_cb(zend_op *opline, int oplineno, void *data TSRMLS_DC) /* {{{ */
{
char *class_name;
@ -919,6 +928,7 @@ static void xc_cache_early_binding_class_cb(zend_op *opline, int oplineno, void
}
}
/* }}} */
#endif
static zend_op_array *xc_check_initial_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
{
XG(initial_compile_file_called) = 1;
@ -937,7 +947,6 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
char *filename;
char opened_path_buffer[MAXPATHLEN];
int old_constinfo_cnt, old_funcinfo_cnt, old_classinfo_cnt;
int i;
if (!xc_initized) {
assert(0);
@ -1179,16 +1188,22 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
#endif
}
/* }}} */
#ifndef ZEND_COMPILE_DELAYED_BINDING
/* {{{ find inherited classes that should be early-binding */
php.have_early_binding = 0;
for (i = 0; i < php.classinfo_cnt; i ++) {
php.classinfos[i].oplineno = -1;
{
int i;
for (i = 0; i < php.classinfo_cnt; i ++) {
php.classinfos[i].oplineno = -1;
}
}
xc_undo_pass_two(php.op_array TSRMLS_CC);
xc_foreach_early_binding_class(php.op_array, xc_cache_early_binding_class_cb, (void *) &php TSRMLS_CC);
xc_redo_pass_two(php.op_array TSRMLS_CC);
/* }}} */
#endif
#ifdef SHOW_DPRINT
xc_dprint(&xce, 0 TSRMLS_CC);
#endif
@ -1710,11 +1725,13 @@ static int xcache_admin_auth_check(TSRMLS_D) /* {{{ */
}
if (admin_user == NULL || admin_pass == NULL) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "xcache.admin.user and xcache.admin.pass is required");
php_error_docref(XCACHE_WIKI_URL "/InstallAdministration" TSRMLS_CC, E_ERROR,
"xcache.admin.user and/or xcache.admin.pass settings is not configured."
" Make sure you've modified the correct php ini file for your php used in webserver.");
zend_bailout();
}
if (strlen(admin_pass) != 32) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "unexpect %lu bytes of xcache.admin.pass, expected 32 bytes, the password after md5()", (unsigned long) strlen(admin_pass));
php_error_docref(NULL TSRMLS_CC, E_ERROR, "xcache.admin.pass is %lu chars unexpectedly, it is supposed to be the password after md5() which should be 32 chars", (unsigned long) strlen(admin_pass));
zend_bailout();
}
@ -1763,7 +1780,22 @@ static int xcache_admin_auth_check(TSRMLS_D) /* {{{ */
#define STR "WWW-authenticate: Basic Realm=\"XCache Administration\""
sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC);
#undef STR
ZEND_PUTS("XCache Auth Failed. User and Password is case sense\n");
#define STR "Content-type: text/html; charset=UTF-8"
sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC);
#undef STR
ZEND_PUTS("<html>\n");
ZEND_PUTS("<head><title>XCache Authentication Failed</title></head>\n");
ZEND_PUTS("<body>\n");
ZEND_PUTS("<h1>XCache Authentication Failed</h1>\n");
ZEND_PUTS("<p>You're not authorized to access this page due to wrong username and/or password you typed.<br />The following check points is suggested:</p>\n");
ZEND_PUTS("<ul>\n");
ZEND_PUTS("<li>Be aware that `Username' and `Password' is case sense. Check capslock status led on your keyboard, and punch left/right Shift keys once for each</li>\n");
ZEND_PUTS("<li>Make sure the md5 password is generated correctly. You may use <a href=\"mkpassword.php\">mkpassword.php</a></li>\n");
ZEND_PUTS("<li>Reload browser cache by pressing F5 and/or Ctrl+F5, or simply clear browser cache after you've updated username/password in php ini.</li>\n");
ZEND_PUTS("</ul>\n");
ZEND_PUTS("Check <a href=\"" XCACHE_WIKI_URL "/InstallAdministration\">XCache wiki page</a> for more information.\n");
ZEND_PUTS("</body>\n");
ZEND_PUTS("</html>\n");
zend_bailout();
return 0;
@ -2559,9 +2591,14 @@ static PHP_MINFO_FUNCTION(xcache)
php_info_print_table_row(2, "Version", XCACHE_VERSION);
php_info_print_table_row(2, "Modules Built", XCACHE_MODULES);
php_info_print_table_row(2, "Readonly Protection", xc_readonly_protection ? "enabled" : "N/A");
#ifdef ZEND_ENGINE_2_1
ptr = php_format_date("Y-m-d H:i:s", sizeof("Y-m-d H:i:s") - 1, xc_init_time, 1 TSRMLS_CC);
php_info_print_table_row(2, "Cache Init Time", ptr);
efree(ptr);
#else
snprintf(buf, sizeof(buf), "%lu", (long unsigned) xc_init_time);
php_info_print_table_row(2, "Cache Init Time", buf);
#endif
#ifdef ZTS
snprintf(buf, sizeof(buf), "%lu.%lu", xc_init_instance_id, xc_init_instance_subid);
@ -2804,7 +2841,11 @@ static PHP_MINIT_FUNCTION(xcache)
}
xc_initized = 1;
xc_init_time = time(NULL);
#ifdef PHP_WIN32
xc_init_instance_id = GetCurrentProcessId();
#else
xc_init_instance_id = getpid();
#endif
#ifdef ZTS
xc_init_instance_subid = tsrm_thread_id();
#endif
@ -2978,7 +3019,7 @@ ZEND_DLEXPORT int xcache_zend_startup(zend_extension *extension) /* {{{ */
xc_llist_unlink(&zend_extensions, xc_llist_zend_extension);
ext = (zend_extension *) zend_llist_get_last_ex(&zend_extensions, &lpos);
assert(ext && ext != xc_llist_zend_extension);
assert(ext && ext != (zend_extension *) xc_llist_zend_extension->data);
xc_last_ext_startup = ext->startup;
ext->startup = xc_zend_startup_last;
}

10
xcache.h

@ -5,6 +5,7 @@
#define XCACHE_AUTHOR "mOo"
#define XCACHE_COPYRIGHT "Copyright (c) 2005-2009"
#define XCACHE_URL "http://xcache.lighttpd.net"
#define XCACHE_WIKI_URL XCACHE_URL "/wiki"
#include <php.h>
#include <zend_compile.h>
@ -38,7 +39,10 @@
# define ZESW(v1, v2) v2
#endif
#ifdef ALLOCA_FLAG
#ifdef do_alloca_with_limit
# define my_do_alloca(size, use_heap) do_alloca_with_limit(size, use_heap)
# define my_free_alloca(size, use_heap) free_alloca_with_limit(size, use_heap)
#elif defined(ALLOCA_FLAG)
# define my_do_alloca(size, use_heap) do_alloca(size, use_heap)
# define my_free_alloca(size, use_heap) free_alloca(size, use_heap)
#else
@ -237,7 +241,9 @@ typedef struct {
zend_uint key_size;
ulong h;
xc_cest_t cest;
#ifndef ZEND_COMPILE_DELAYED_BINDING
int oplineno;
#endif
} xc_classinfo_t;
/* }}} */
#ifdef HAVE_XCACHE_CONSTANT
@ -298,7 +304,9 @@ typedef struct {
zend_uint classinfo_cnt;
xc_classinfo_t *classinfos;
#ifndef ZEND_COMPILE_DELAYED_BINDING
zend_bool have_early_binding;
#endif
#ifdef ZEND_ENGINE_2_1
zend_uint autoglobal_cnt;

Loading…
Cancel
Save