/* Free processor */
static void free_processor(zend_rsrc_list_entry *);
-/* Create an XSLT array */
-static void make_xslt_array(zval **, char ***);
-static void free_xslt_array(char **);
-
/* Scheme handler functions */
static int scheme_getall(void *, SablotHandle, const char *, const char *, char **, int *);
static int scheme_freememory(void *, SablotHandle, char *);
}
/* Comment handlers, called when a comment is reached */
else if (strcasecmp(string_key, "comment") == 0) {
- assign_xslt_handler(&XSLT_SAX(handle).comment, handler);
+ xslt_assign_handler(&XSLT_SAX(handle).comment, handler);
}
/* Processing instructions handler called when processing instructions
(<? ?>) */
else if (strcasecmp(string_key, "pi") == 0) {
- assign_xslt_handler(&XSLT_SAX(handle).pi, handler);
+ xslt_assign_handler(&XSLT_SAX(handle).pi, handler);
}
/* Character handler, called when data is found */
else if (strcasecmp(string_key, "character") == 0) {
- assign_xslt_handler(&XSLT_SAX(handle).characters, handler);
+ xslt_assign_handler(&XSLT_SAX(handle).characters, handler);
}
/* Invalid handler name, tsk, tsk, tsk :) */
else {
}
/* Actually assign the handlers, yippy! */
- assign_xslt_handler(&assign_handle, handler);
+ xslt_assign_handler(&assign_handle, handler);
}
}
/* }}} */
}
ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
- assign_xslt_handler(&XSLT_ERROR(handle), error_func);
+ xslt_assign_handler(&XSLT_ERROR(handle), error_func);
}
/* }}} */
/* Translate a PHP array into a Sablotron array */
if (argc > 4) {
char **p;
- make_xslt_array(args_p, &args);
+ xslt_make_array(args_p, &args);
for (p = args; *p != NULL; p += 2) {
php_printf("%s: %s\n\n\n", *p, *(p + 1));
}
if (argc > 5) {
- make_xslt_array(params_p, ¶ms);
+ xslt_make_array(params_p, ¶ms);
}
/* Perform transformation */
if (error) {
XSLT_ERRNO(handle) = error;
- if (params) free_xslt_array(params);
- if (args) free_xslt_array(args);
+ if (params) xslt_free_array(params);
+ if (args) xslt_free_array(args);
RETURN_FALSE;
}
XSLT_ERRNO(handle) = error;
/* Cleanup */
- if (params) free_xslt_array(params);
- if (args) free_xslt_array(args);
+ if (params) xslt_free_array(params);
+ if (args) xslt_free_array(args);
RETURN_FALSE;
}
}
/* Cleanup */
- if (params) free_xslt_array(params);
- if (args) free_xslt_array(args);
+ if (params) xslt_free_array(params);
+ if (args) xslt_free_array(args);
}
/* }}} */
}
/* Free Scheme handlers */
- free_xslt_handler(XSLT_SCHEME(handle).get_all);
- free_xslt_handler(XSLT_SCHEME(handle).open);
- free_xslt_handler(XSLT_SCHEME(handle).get);
- free_xslt_handler(XSLT_SCHEME(handle).put);
- free_xslt_handler(XSLT_SCHEME(handle).close);
+ xslt_free_handler(XSLT_SCHEME(handle).get_all);
+ xslt_free_handler(XSLT_SCHEME(handle).open);
+ xslt_free_handler(XSLT_SCHEME(handle).get);
+ xslt_free_handler(XSLT_SCHEME(handle).put);
+ xslt_free_handler(XSLT_SCHEME(handle).close);
/* Free SAX handlers */
- free_xslt_handler(XSLT_SAX(handle).doc_start);
- free_xslt_handler(XSLT_SAX(handle).element_start);
- free_xslt_handler(XSLT_SAX(handle).element_end);
- free_xslt_handler(XSLT_SAX(handle).namespace_start);
- free_xslt_handler(XSLT_SAX(handle).namespace_end);
- free_xslt_handler(XSLT_SAX(handle).comment);
- free_xslt_handler(XSLT_SAX(handle).pi);
- free_xslt_handler(XSLT_SAX(handle).characters);
- free_xslt_handler(XSLT_SAX(handle).doc_end);
+ xslt_free_handler(XSLT_SAX(handle).doc_start);
+ xslt_free_handler(XSLT_SAX(handle).element_start);
+ xslt_free_handler(XSLT_SAX(handle).element_end);
+ xslt_free_handler(XSLT_SAX(handle).namespace_start);
+ xslt_free_handler(XSLT_SAX(handle).namespace_end);
+ xslt_free_handler(XSLT_SAX(handle).comment);
+ xslt_free_handler(XSLT_SAX(handle).pi);
+ xslt_free_handler(XSLT_SAX(handle).characters);
+ xslt_free_handler(XSLT_SAX(handle).doc_end);
/* Free error handler */
- free_xslt_handler(XSLT_ERROR(handle));
+ xslt_free_handler(XSLT_ERROR(handle));
/* Free error message, if any */
if (XSLT_ERRSTR(handle)) {
/* Grab handler 1 */
if (zend_hash_index_find(Z_ARRVAL_PP(handler), 0, (void **) ¤t) == SUCCESS) {
- assign_xslt_handler(handler1, current);
+ xslt_assign_handler(handler1, current);
}
else {
php_error(E_WARNING, "Wrong format of arguments to xslt_set_sax_handlers()");
/* Grab handler 2 */
if (zend_hash_index_find(Z_ARRVAL_PP(handler), 1, (void **) ¤t) == SUCCESS) {
- assign_xslt_handler(handler2, current);
+ xslt_assign_handler(handler2, current);
}
else {
php_error(E_WARNING, "Wrong format of arguments to xslt_set_sax_handlers()");
}
/* }}} */
-/* {{{ free_xslt_array()
- Free an XSLT-Sablotron array */
-static void free_xslt_array(char **arr)
-{
- char **p;
-
- /* Free the individual elements */
- for (p = arr; *p != NULL; p++) {
- efree(*p);
- }
-
- /* Free the entire array */
- efree(arr);
-}
-/* }}} */
-
-/* {{{ make_xslt_array()
- Translate a PHP array into an xslt (char **) array */
-static void make_xslt_array(zval **zval_ar, char ***xslt_ar)
-{
- zval **current; /* The current element we are processing */
- HashTable *php_ar; /* The actual array to loop through (derived from the passed zval) */
- int idx = 0; /* The current element of the xslt_ar to assign data to */
-
- /* Grab the PHP array from the zval */
- php_ar = HASH_OF(*zval_ar);
- if (!php_ar) {
- php_error(E_WARNING, "Array expected");
- return;
- }
-
- /* Allocate the xslt array */
- *xslt_ar = emalloc(sizeof(char *) * (zend_hash_num_elements(php_ar) + 2));
-
- /* Loop through the array element by element */
- for (zend_hash_internal_pointer_reset(php_ar);
- zend_hash_get_current_data(php_ar, (void **) ¤t) == SUCCESS;
- zend_hash_move_forward(php_ar)) {
- char *string_key = NULL;
- ulong num_key;
-
- SEPARATE_ZVAL(current);
- convert_to_string_ex(current);
-
- zend_hash_get_current_key(php_ar, &string_key, &num_key, 1);
-
- /* Akin to an associative array, first element key, second element is
- the value */
- (*xslt_ar)[idx++] = estrdup(string_key);
- (*xslt_ar)[idx++] = estrndup(Z_STRVAL_PP(current), Z_STRLEN_PP(current));
- }
-
- (*xslt_ar)[idx] = NULL;
-}
-/* }}} */
-
/* {{{ scheme_getall()
The getall scheme handler */
static int scheme_getall(void *user_data, SablotHandle proc, const char *scheme, const char *rest, char **buffer, int *byte_count)
ZVAL_STRING(argv[1], (char *) scheme, 1);
ZVAL_STRING(argv[2], (char *) rest, 1);
- call_xslt_function("scheme get all", XSLT_SCHEME(handle).get_all,
+ xslt_call_function("scheme get all", XSLT_SCHEME(handle).get_all,
3, argv, &retval);
/* Save the return value in the buffer (copying it) */
ZVAL_STRING(argv[2], (char *) rest, 1);
/* Call the function */
- call_xslt_function("scheme open", XSLT_SCHEME(handle).open,
+ xslt_call_function("scheme open", XSLT_SCHEME(handle).open,
3, argv, &retval);
/* Return value is a resource pointer to an open file */
ZVAL_STRINGL(argv[2], buffer, *byte_count, 0);
/* Call the function */
- call_xslt_function("scheme get", XSLT_SCHEME(handle).get,
+ xslt_call_function("scheme get", XSLT_SCHEME(handle).get,
3, argv, &retval);
/* Returns the number of bytes read */
ZVAL_STRINGL(argv[2], (char *) buffer, *byte_count, 1);
/* Call the scheme put function already */
- call_xslt_function("scheme put", XSLT_SCHEME(handle).put,
+ xslt_call_function("scheme put", XSLT_SCHEME(handle).put,
3, argv, &retval);
/* The return value is the number of bytes written */
zend_list_addref(fd);
/* Call the scheme handler close function */
- call_xslt_function("scheme close", XSLT_SCHEME(handle).close,
+ xslt_call_function("scheme close", XSLT_SCHEME(handle).close,
2, argv, &retval);
/* Free everything up */
zend_list_addref(handle->processor.idx);
/* Call the Sax start doc function */
- call_xslt_function("sax start doc", XSLT_SAX(handle).doc_start,
+ xslt_call_function("sax start doc", XSLT_SAX(handle).doc_start,
1, argv, &retval);
/* Cleanup */
}
/* Call the sax element start function */
- call_xslt_function("sax start element", XSLT_SAX(handle).element_start,
+ xslt_call_function("sax start element", XSLT_SAX(handle).element_start,
3, argv, &retval);
/* Cleanup */
ZVAL_STRING(argv[1], (char *) name, 1);
/* Call the sax end element function */
- call_xslt_function("sax end element", XSLT_SAX(handle).element_end,
+ xslt_call_function("sax end element", XSLT_SAX(handle).element_end,
2, argv, &retval);
/* Cleanup */
ZVAL_STRING(argv[2], (char *) uri, 1);
/* Call the sax start namespace function */
- call_xslt_function("sax start namespace", XSLT_SAX(handle).namespace_start,
+ xslt_call_function("sax start namespace", XSLT_SAX(handle).namespace_start,
3, argv, &retval);
/* Cleanup */
ZVAL_STRING(argv[1], (char *) prefix, 1);
/* Call the sax end namespace function */
- call_xslt_function("sax end namespace", XSLT_SAX(handle).namespace_end,
+ xslt_call_function("sax end namespace", XSLT_SAX(handle).namespace_end,
2, argv, &retval);
/* Cleanup */
ZVAL_STRING(argv[1], (char *) contents, 1);
/* Call the sax comment function */
- call_xslt_function("sax comment", XSLT_SAX(handle).comment,
+ xslt_call_function("sax comment", XSLT_SAX(handle).comment,
2, argv, &retval);
/* Cleanup */
ZVAL_STRING(argv[2], (char *) contents, 1);
/* Call processing instructions function */
- call_xslt_function("sax processing instructions", XSLT_SAX(handle).pi,
+ xslt_call_function("sax processing instructions", XSLT_SAX(handle).pi,
3, argv, &retval);
/* Cleanup */
ZVAL_STRINGL(argv[1], (char *) contents, length, 1);
/* Call characters function */
- call_xslt_function("sax characters", XSLT_SAX(handle).characters,
+ xslt_call_function("sax characters", XSLT_SAX(handle).characters,
2, argv, &retval);
/* Cleanup */
zend_list_addref(handle->processor.idx);
/* Call the function */
- call_xslt_function("sax end doc", XSLT_SAX(handle).doc_end,
+ xslt_call_function("sax end doc", XSLT_SAX(handle).doc_end,
1, argv, &retval);
/* Cleanup */
/* open for append */
XSLT_LOG(handle).fd = open(XSLT_LOG(handle).path,
O_WRONLY|O_CREAT|O_APPEND,
- S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR);
+ S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR);
if (XSLT_LOG(handle).fd < 0) {
php_error(E_WARNING, "Cannot open log file, %s [%d]: %s",
XSLT_LOG(handle).path, errno, strerror(errno));
}
/* Call the function */
- call_xslt_function("error handler", XSLT_ERROR(handle),
+ xslt_call_function("error handler", XSLT_ERROR(handle),
4, argv, &retval);
/* Free up */
}
/* }}} */
-static char *find_xslt_argument(const char **argv, const char *key)
+/* {{{ find_xslt_argument()
+ Find and return an xslt argument from the argument buffer */
+static char *_find_xslt_argument(const char **argv, const char *key)
{
- char **ptr;
- char *return_value;
+ char **ptr; /* Pointer to the passed char ** array */
+ char *return_value = NULL; /* Value to return from the function */
+ /* Loop through the array searching for the value */
ptr = (char **) argv;
while (ptr && *ptr) {
+ /* If we have a match, save the value and exit out */
if (! strcmp(*ptr, key)) {
return_value = estrdup(*ptr);
- return return_value;
+ break;
}
ptr++;
}
- if (! return_value) {
- return NULL;
+ return return_value;
+}
+/* }}} */
+
+/* {{{ xslt_make_array()
+ Make an XSLT array (char **) from a zval array (HashTable *) */
+extern void xslt_make_array(zval **zarr, char ***carr)
+{
+ zval **current;
+ HashTable *arr;
+ int idx = 0;
+
+ arr = HASH_OF(*zarr);
+ if (! arr) {
+ php_error(E_WARNING, "Invalid argument or parameter array to %s",
+ get_active_function_name());
+ return;
+ }
+
+ *carr = emalloc((zend_hash_num_elements(arr) * 2) + 1);
+
+ for (zend_hash_internal_pointer_reset(arr);
+ zend_hash_get_current_data(arr, (void **) ¤t) == SUCCESS;
+ zend_hash_move_forward(arr)) {
+ char *string_key = NULL;
+ ulong num_key;
+ int type;
+
+ SEPARATE_ZVAL(current);
+ convert_to_string_ex(current);
+
+ type = zend_hash_get_current_key(arr, &string_key, &num_key, 0);
+ if (type == HASH_KEY_IS_LONG) {
+ php_error(E_WARNING, "Invalid argument or parameter array to %s",
+ get_active_function_name());
+ return;
+ }
+
+ (*carr)[idx++] = estrdup(string_key);
+ (*carr)[idx++] = estrndup(Z_STRVAL_PP(current), Z_STRLEN_PP(current));
}
+
+ (*carr)[idx] = NULL;
}
+/* }}} */
+
+/* {{{ xslt_free_array()
+ Free an xslt array built by xslt_make_array() */
+extern void xslt_free_array(char **arr)
+{
+ char **ptr = arr;
+
+ while (*ptr != NULL) {
+ efree(*ptr);
+ ptr++;
+ }
+
+ efree(arr);
+}
+/* }}} */
-/* {{{ parse_xslt_arguments()
+/* {{{ xslt_parse_arguments()
Parse an XSLT argument buffer */
-extern xslt_args *parse_xslt_arguments(char *xml,
+extern xslt_args *xslt_parse_arguments(char *xml,
char *xsl,
char *result,
char **argv)
{
- xslt_args *return_value;
+ xslt_args *return_value; /* The value to return from the function */
return_value = emalloc(sizeof(xslt_args));
char *key = xml + 5;
return_value->xml.type = XSLT_IS_DATA;
- return_value->xml.ptr = find_xslt_argument((const char **) argv,
- (const char *) key);
+ return_value->xml.ptr = _find_xslt_argument((const char **) argv,
+ (const char *) key);
}
else {
return_value->xml.type = XSLT_IS_FILE;
char *key = xsl + 5;
return_value->xsl.type = XSLT_IS_DATA;
- return_value->xsl.ptr = find_xslt_argument((const char **) argv,
- (const char *) key);
+ return_value->xsl.ptr = _find_xslt_argument((const char **) argv,
+ (const char *) key);
}
else {
return_value->xsl.type = XSLT_IS_FILE;
char *key = result + 5;
return_value->result.type = XSLT_IS_DATA;
- return_value->result.ptr = find_xslt_argument((const char **) argv,
- (const char *) key);
+ return_value->result.ptr = _find_xslt_argument((const char **) argv,
+ (const char *) key);
}
else {
return_value->result.type = XSLT_IS_FILE;
/* {{{ free_xslt_arguments()
Free's an XSLT argument list returned from parse_xslt_arguments() */
-extern void free_xslt_arguments(xslt_args *to_free)
+extern void xslt_free_arguments(xslt_args *to_free)
{
if (to_free->xml.ptr) {
efree(to_free->xml.ptr);
/* {{{ call_xslt_function()
Call an XSLT handler */
-extern void call_xslt_function(char *name,
+extern void xslt_call_function(char *name,
struct xslt_function *fptr,
int argc,
zval **argv,
/* }}} */
-extern void free_xslt_handler(struct xslt_function *func)
+extern void xslt_free_handler(struct xslt_function *func)
{
if (!func) {
return;
efree(func);
}
-extern void assign_xslt_handler(struct xslt_function **func, zval **zfunc)
+extern void xslt_assign_handler(struct xslt_function **func, zval **zfunc)
{
char error[] = "Invalid function passed to %s";