summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSterling Hughes <sterling@php.net>2000-12-11 14:49:49 +0000
committerSterling Hughes <sterling@php.net>2000-12-11 14:49:49 +0000
commit888e41a8341a8fbff06f32a4807c10c7188f21b2 (patch)
tree740ac001259e2939cae27872e7846bdc3e5dd5fe
parent02e8c41b24370c449a8ea3082d584452fce06664 (diff)
downloadphp-git-888e41a8341a8fbff06f32a4807c10c7188f21b2.tar.gz
Merge with HEAD
-rw-r--r--ext/sablot/php_sablot.h15
-rw-r--r--ext/sablot/sablot.c119
2 files changed, 87 insertions, 47 deletions
diff --git a/ext/sablot/php_sablot.h b/ext/sablot/php_sablot.h
index cd5b045669..79f9566b13 100644
--- a/ext/sablot/php_sablot.h
+++ b/ext/sablot/php_sablot.h
@@ -37,6 +37,9 @@ PHP_MINIT_FUNCTION(sablot);
PHP_MINFO_FUNCTION(sablot);
PHP_MSHUTDOWN_FUNCTION(sablot);
+/* Request functions */
+PHP_RSHUTDOWN_FUNCTION(sablot);
+
/* Output transformation functions */
PHP_FUNCTION(xslt_output_begintransform);
PHP_FUNCTION(xslt_output_endtransform);
@@ -65,6 +68,7 @@ struct _php_sablot_error {
char *value;
struct _php_sablot_error *next;
};
+
typedef struct _php_sablot_error php_sablot_error;
@@ -102,6 +106,7 @@ typedef struct {
php_sablot_error errors_start;
char *output_transform_file; /* For output transformations */
int last_errno; /* Global last_errno, if no handle is found */
+ SablotHandle processor;
} php_sablot_globals;
@@ -109,10 +114,18 @@ typedef struct {
#define SABLOTG(v) (sablot_globals->v)
#define SABLOTLS_FETCH() php_sablot_globals *sablot_globals = ts_resource(sablot_globals_id)
#define SABLOTG_HANDLE (*sablot_globals)
+#define SABLOTLS_C sablot_globals
+#define SABLOTLS_CC , SABLOTLS_C
+#define SABLOTLS_D php_sablot_globals *sablot_globals
+#define SABLOTLS_DC , SABLOTLS_D
#else
#define SABLOTG(v) (sablot_globals.v)
#define SABLOTG_HANDLE sablot_globals
#define SABLOTLS_FETCH()
+#define SABLOTLS_C
+#define SABLOTLS_CC
+#define SABLOTLS_D
+#define SABLOTLS_DC
#endif
#else
@@ -126,4 +139,4 @@ typedef struct {
* tab-width: 4
* c-basic-offset: 4
* End:
- */ \ No newline at end of file
+ */
diff --git a/ext/sablot/sablot.c b/ext/sablot/sablot.c
index 8dcb10de43..78c6f9b56c 100644
--- a/ext/sablot/sablot.c
+++ b/ext/sablot/sablot.c
@@ -31,8 +31,7 @@
#include "ext/standard/php_output.h"
#include "php_sablot.h"
-static int le_sablot;
-static SablotHandle processor;
+static int le_sablot;
/* Functions related to PHP's list handling */
static void _php_sablot_free_processor(zend_rsrc_list_entry *rsrc);
@@ -68,37 +67,37 @@ static zval *_php_sablot_resource_zval(long);
/* ERROR Macros */
-#define SABLOT_FREE_ERROR_HANDLE(__handle) \
- if ((__handle).errors) { \
+#define SABLOT_FREE_ERROR_HANDLE(__handle) \
+ if ((__handle).errors) { \
(__handle).errors = (__handle).errors_start.next; \
- while ((__handle).errors) { \
- S_FREE((__handle).errors->key); \
- S_FREE((__handle).errors->value); \
- (__handle).errors = (__handle).errors->next; \
- } \
- S_FREE((__handle).errors); \
+ while ((__handle).errors) { \
+ S_FREE((__handle).errors->key); \
+ S_FREE((__handle).errors->value); \
+ (__handle).errors = (__handle).errors->next; \
+ } \
+ S_FREE((__handle).errors); \
}
/* Sablotron Basic Api macro's */
-#define SABLOT_BASIC_CREATE_PROCESSOR() \
- if (processor == NULL) { \
- int ret = 0; \
- \
- ret = SablotCreateProcessor(&processor); \
- if (ret) { \
- SABLOTG(last_errno) = ret; \
- return; \
- } \
- \
- ret = SablotRegHandler(processor, HLR_MESSAGE, (void *)&mh, (void *)NULL); \
- if (ret) { \
- SABLOTG(last_errno) = ret; \
- return; \
- } \
- }
-
-#define SABLOT_BASIC_HANDLE processor
+#define SABLOT_BASIC_CREATE_PROCESSOR() \
+ if (SABLOTG(processor) == NULL) { \
+ int ret = 0; \
+ \
+ ret = SablotCreateProcessor(&SABLOTG(processor)); \
+ if (ret) { \
+ SABLOTG(last_errno) = (int) ret; \
+ return; \
+ } \
+ \
+ ret = SablotRegHandler(SABLOTG(processor), HLR_MESSAGE, (void *)&mh, (void *)NULL); \
+ if (ret) { \
+ SABLOTG(last_errno) = (int) ret; \
+ return; \
+ } \
+ }
+
+#define SABLOT_BASIC_HANDLE SABLOTG(processor)
/**
* SAX Handler structure, this defines the different functions to be
@@ -161,9 +160,9 @@ zend_module_entry sablot_module_entry = {
"sablot",
sablot_functions,
PHP_MINIT(sablot),
- PHP_MSHUTDOWN(sablot),
- NULL,
+ PHP_MSHUTDOWN(sablot),
NULL,
+ PHP_RSHUTDOWN(sablot),
PHP_MINFO(sablot),
STANDARD_MODULE_PROPERTIES
};
@@ -172,26 +171,48 @@ zend_module_entry sablot_module_entry = {
ZEND_GET_MODULE(sablot)
#endif
+static void php_sablot_init_globals(SABLOTLS_D)
+{
+ SABLOTG(processor) = NULL;
+ SABLOTG(errors) = NULL;
+ SABLOTG(errorHandler) = NULL;
+}
+
/* MINIT and MINFO Functions */
PHP_MINIT_FUNCTION(sablot)
{
+#ifdef ZTS
+ sablot_globals_id = ts_allocate_id(sizeof(php_sablot_globals), (ts_allocate_ctor)php_sablot_init_globals, NULL);
+#else
+ php_sablot_init_globals(SABLOTLS_C);
+#endif
+
le_sablot = zend_register_list_destructors_ex(_php_sablot_free_processor, NULL, "Sablotron XSLT", module_number);
- processor = NULL;
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(sablot)
{
- if (processor) {
- SablotUnregHandler(processor, HLR_MESSAGE, NULL, NULL);
- SablotDestroyProcessor(processor);
+ SABLOTLS_FETCH();
+ if (SABLOTG(processor)) {
+ SablotUnregHandler(SABLOTG(processor), HLR_MESSAGE, NULL, NULL);
+ SablotDestroyProcessor(SABLOTG(processor));
}
return SUCCESS;
}
+PHP_RSHUTDOWN_FUNCTION(sablot)
+{
+ SABLOTLS_FETCH();
+
+ SABLOT_FREE_ERROR_HANDLE(SABLOTG_HANDLE);
+
+ return SUCCESS;
+}
+
PHP_MINFO_FUNCTION(sablot)
{
php_info_print_table_start();
@@ -785,7 +806,6 @@ PHP_FUNCTION(xslt_set_sax_handler)
RETURN_FALSE;
}
-
if (!strcasecmp("document", string_key)) {
_php_sablot_handler_pair(handle,
&handle->startDocHandler, &handle->endDocHandler,
@@ -1166,24 +1186,24 @@ static MH_ERROR _php_sablot_error(void *userData, SablotHandle p, MH_ERROR code,
zval **argv = NULL,
*errorHandler;
- php_sablot_error *errors,
- errors_start;
+ php_sablot_error *errors;
php_sablot *handle = NULL;
char *sep = NULL;
int isAdvanced = 0,
argc = 0,
+ i,
idx,
len;
SABLOTLS_FETCH();
-
+
if (userData == NULL) {
SABLOT_FREE_ERROR_HANDLE(SABLOTG_HANDLE);
SABLOTG(errors_start).next = NULL;
- SABLOTG(errors) = &SABLOTG(errors_start);
+ SABLOTG(errors) = &SABLOTG(errors_start);
errors = SABLOTG(errors);
errorHandler = SABLOTG(errorHandler);
@@ -1193,7 +1213,7 @@ static MH_ERROR _php_sablot_error(void *userData, SablotHandle p, MH_ERROR code,
SABLOT_FREE_ERROR_HANDLE(*handle);
handle->errors_start.next = NULL;
- handle->errors = &errors_start;
+ handle->errors = &handle->errors_start;
errors = handle->errors;
errorHandler = handle->errorHandler;
@@ -1216,6 +1236,7 @@ static MH_ERROR _php_sablot_error(void *userData, SablotHandle p, MH_ERROR code,
memcpy(errors->key, fields[0], idx);
memcpy(errors->value, fields[0] + idx + 1, len - idx - 1);
+ errors->key[idx] = '\0';
errors->value[len - idx - 1] = '\0';
errors->next = NULL;
@@ -1223,9 +1244,9 @@ static MH_ERROR _php_sablot_error(void *userData, SablotHandle p, MH_ERROR code,
}
if (isAdvanced)
- handle->last_errno = (int)code;
+ handle->last_errno = (int) code;
else
- SABLOTG(last_errno) = (int)code;
+ SABLOTG(last_errno) = (int) code;
if (errorHandler) {
zval *retval;
@@ -1249,7 +1270,7 @@ static MH_ERROR _php_sablot_error(void *userData, SablotHandle p, MH_ERROR code,
array_init(argv[3]);
errors = handle->errors_start.next;
- while (errors->next) {
+ while (errors) {
add_assoc_string(argv[3], errors->key, errors->value, 1);
errors = errors->next;
}
@@ -1271,12 +1292,19 @@ static MH_ERROR _php_sablot_error(void *userData, SablotHandle p, MH_ERROR code,
zval_dtor(retval);
efree(retval);
+
+ for (i = 1; i < argc; i++) {
+ zval_del_ref(&argv[i]);
+ }
} else {
- _php_sablot_standard_error(errors, isAdvanced ? handle->errors_start : SABLOTG(errors_start), code, level);
+ if (level == MH_LEVEL_CRITICAL ||
+ level == MH_LEVEL_ERROR ||
+ level == MH_LEVEL_WARN) {
+ _php_sablot_standard_error(errors, isAdvanced ? handle->errors_start : SABLOTG(errors_start), code, level);
+ }
}
return(0);
-
}
/* }}} */
@@ -1288,7 +1316,6 @@ static void _php_sablot_standard_error(php_sablot_error *errors, php_sablot_erro
SABLOTLS_FETCH();
errors = errors_start.next;
-
while (errors) {
len = pos + strlen(errors->key) + sizeof(": ") + strlen(errors->value) + sizeof("\n");