CVS update: php3/functions
| From: | ssb | Date: | Wed, 21 Oct 1998 11:03:10 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1931@lists.php.net to get a copy of this message | ||
Date: Wednesday October 21, 1998 @ 7:03
Author: ssb
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv2210
Modified Files:
xml.c php3_xml.h
Log Message:
add more handlers
Index: php3/functions/xml.c
diff -c php3/functions/xml.c:1.1 php3/functions/xml.c:1.2
*** php3/functions/xml.c:1.1 Tue Oct 20 20:13:44 1998
--- php3/functions/xml.c Wed Oct 21 07:03:09 1998
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: xml.c,v 1.1 1998/10/21 00:13:44 ssb Exp $ */
#include "php.h"
#include "internal_functions.h"
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: xml.c,v 1.2 1998/10/21 11:03:09 ssb Exp $ */
#include "php.h"
#include "internal_functions.h"
***************
*** 43,48 ****
--- 43,49 ----
/* Short-term TODO list:
* - Fix the expat library so you can install your own memory manager
* functions
+ * - Implement XML_ExternalEntityParserCreate()
*/
/* Long-term TODO list:
***************
*** 109,115 ****
# endif /* COMPILE_DL */
/* }}} */
! /* {{{ startup/shutdown/info/internal function prototypes */
int php3_minit_xml(INIT_FUNC_ARGS);
int php3_rinit_xml(INIT_FUNC_ARGS);
--- 110,116 ----
# endif /* COMPILE_DL */
/* }}} */
! /* {{{ function prototypes */
int php3_minit_xml(INIT_FUNC_ARGS);
int php3_rinit_xml(INIT_FUNC_ARGS);
***************
*** 121,128 ****
--- 122,141 ----
static char *php3i_pvalstrcpy(pval *);
static void xml_destroy_parser(xml_parser *);
static void xml_set_handler(char **, pval *);
+ static void xml_call_handler(xml_parser *, char *, pval *, pval *);
+ static pval *php3i_longpval(long);
+ static pval *php3i_stringpval(const char *);
+ static pval *php3i_xmlcharpval(const XML_Char *, int);
+ static int php3i_xmlcharlen(const XML_Char *);
+
void php3i_xml_startElementHandler(void *, const char *, const char **);
void php3i_xml_endElementHandler(void *, const char *);
+ void php3i_xml_characterDataHandler(void *, const XML_Char *, int);
+ void php3i_xml_processingInstructionHandler(void *, const XML_Char *, const XML_Char *);
+ void php3i_xml_defaultHandler(void *, const XML_Char *, int);
+ void php3i_xml_unparsedEntityDeclHandler(void *, const XML_Char *, const XML_Char *, const
XML_Char *, const XML_Char *, const XML_Char *);
+ void php3i_xml_notationDeclHandler(void *, const XML_Char *, const XML_Char *, const XML_Char *,
const XML_Char *);
+ int php3i_xml_externalEntityRefHandler(XML_Parser, const XML_Char *, const XML_Char *, const
XML_Char *, const XML_Char *);
/* }}} */
/* {{{ extension definition structures */
***************
*** 130,135 ****
--- 143,154 ----
function_entry xml_functions[] = {
PHP_FE(xml_parsercreate, NULL)
PHP_FE(xml_setelementhandler, NULL)
+ PHP_FE(xml_setcharacterdatahandler, NULL)
+ PHP_FE(xml_setprocessinginstructionhandler, NULL)
+ PHP_FE(xml_setdefaulthandler, NULL)
+ PHP_FE(xml_setunparsedentitydeclhandler, NULL)
+ PHP_FE(xml_setnotationdeclhandler, NULL)
+ PHP_FE(xml_setexternalentityrefhandler, NULL)
PHP_FE(xml_parse, NULL)
PHP_FE(xml_geterrorcode, NULL)
PHP_FE(xml_errorstring, NULL)
***************
*** 315,320 ****
--- 334,450 ----
}
/* }}} */
+ /* {{{ xml_call_handler() */
+
+ static void
+ xml_call_handler(xml_parser *parser, char *nameBuf, pval *data, pval *arg3)
+ {
+ XML_TLS_VARS;
+
+ if (nameBuf) {
+ pval retval, *args[3], func;
+ int argc;
+
+ if (arg3) {
+ args[3] = arg3;
+ argc = 3;
+ } else {
+ argc = 2;
+ }
+ func.type = IS_STRING;
+ func.value.str.val = nameBuf;
+ func.value.str.len = strlen(nameBuf);
+ args[0] = php3i_longpval(parser->index);
+ args[1] = data;
+ if (call_user_function(&GLOBAL(function_table), NULL, &func, &retval, argc, args) ==
SUCCESS) {
+ pval_destructor(&retval);
+ }
+ pval_destructor(args[0]);
+ pval_destructor(args[1]);
+ efree(args[0]);
+ efree(args[1]);
+ if (arg3) {
+ pval_destructor(args[2]);
+ efree(args[2]);
+ }
+ }
+ }
+
+ /* }}} */
+ /* {{{ php3i_longpval() */
+
+ static pval *php3i_longpval(long value)
+ {
+ pval *ret = emalloc(sizeof(pval));
+
+ ret->type = IS_LONG;
+ ret->value.lval = value;
+ return ret;
+ }
+
+ /* }}} */
+ /* {{{ php3i_stringpval() */
+
+ static pval *php3i_stringpval(const char *str)
+ {
+ pval *ret = emalloc(sizeof(pval));
+ int len = strlen(str);
+
+ ret->type = IS_STRING;
+ ret->value.str.len = len;
+ ret->value.str.val = estrndup(str, len);
+ return ret;
+ }
+
+ /* }}} */
+ /* {{{ php3i_xmlcharpval() */
+
+ static pval *php3i_xmlcharpval(const XML_Char *s, int len)
+ {
+ pval *ret = NULL;
+
+ if (len == 0) {
+ len = php3i_xmlcharlen(s);
+ }
+ if (sizeof(XML_Char) == 1) {
+ ret = emalloc(len);
+ ret->type = IS_STRING;
+ ret->value.str.len = len;
+ ret->value.str.val = emalloc(len);
+ memcpy(ret->value.str.val, s, len);
+ } else {
+ /* XXX this is still not tested! */
+ int pos = 0, added, i;
+ char * buf = emalloc(len * 4); /* the maximum UTF-8 encoded size */
+
+ for (i = 0; i < len; i++) {
+ added = XmlUtf8Encode((int)s[i], &buf[pos]);
+ pos += added;
+ }
+ buf = erealloc(buf, pos);
+ ret = emalloc(sizeof(pval));
+ ret->type = IS_STRING;
+ ret->value.str.len = pos;
+ ret->value.str.val = buf;
+ }
+ return ret;
+ }
+
+ /* }}} */
+ /* {{{ php3i_xmlcharlen() */
+
+ static int php3i_xmlcharlen(const XML_Char *s)
+ {
+ int len = 0;
+
+ while (*s) {
+ len++;
+ s++;
+ }
+ return len;
+ }
+
+ /* }}} */
/* {{{ php3i_pvalstrcpy() */
static char *php3i_pvalstrcpy(pval *val) {
***************
*** 328,359 ****
}
/* }}} */
! /* {{{ php3i_xml_startElementHandler */
void php3i_xml_startElementHandler(void *userData, const char *name,
const char **attributes)
{
- pval retval, *args[3], func;
xml_parser *parser = (xml_parser *)userData;
XML_TLS_VARS;
! if (parser->startElementHandler) {
char *key, *value;
- args[0] = (pval *)emalloc(sizeof(pval));
- args[1] = (pval *)emalloc(sizeof(pval));
- args[2] = (pval *)emalloc(sizeof(pval));
-
func.type = IS_STRING;
func.value.str.val = parser->startElementHandler;
func.value.str.len = strlen(func.value.str.val);
!
! args[0]->type = IS_LONG;
! args[0]->value.lval = parser->index;
! args[1]->type = IS_STRING;
! args[1]->value.str.val = (char *)name;
! args[1]->value.str.len = strlen(name);
!
array_init(args[2]);
while (attributes && *attributes) {
key = (char *)attributes[0];
--- 458,481 ----
}
/* }}} */
! /* {{{ php3i_xml_startElementHandler() */
void php3i_xml_startElementHandler(void *userData, const char *name,
const char **attributes)
{
xml_parser *parser = (xml_parser *)userData;
XML_TLS_VARS;
! if (parser && parser->startElementHandler) {
! pval retval, func, *args[3];
char *key, *value;
func.type = IS_STRING;
func.value.str.val = parser->startElementHandler;
func.value.str.len = strlen(func.value.str.val);
! args[0] = php3i_longpval(parser->index);
! args[1] = php3i_stringpval(name);
! args[2] = emalloc(sizeof(pval));
array_init(args[2]);
while (attributes && *attributes) {
key = (char *)attributes[0];
***************
*** 361,407 ****
add_assoc_string(args[2], key, value, 1);
attributes += 2;
}
!
! call_user_function(&GLOBAL(function_table), NULL, &func, &retval, 3, args);
! _php3_hash_destroy(args[2]->value.ht);
! efree(args[2]->value.ht);
! efree(args[2]);
efree(args[0]);
efree(args[1]);
}
}
/* }}} */
! /* {{{ php3i_xml_endElementHandler */
void php3i_xml_endElementHandler(void *userData, const char *name)
{
- pval retval, *args[2], func;
xml_parser *parser = (xml_parser *)userData;
XML_TLS_VARS;
! if (parser->endElementHandler) {
! args[0] = (pval *)emalloc(sizeof(pval));
! args[1] = (pval *)emalloc(sizeof(pval));
func.type = IS_STRING;
func.value.str.val = parser->endElementHandler;
func.value.str.len = strlen(func.value.str.val);
! args[0]->type = IS_LONG;
! args[0]->value.lval = parser->index;
! args[1]->type = IS_STRING;
! args[1]->value.str.val = (char *)name;
! args[1]->value.str.len = strlen(name);
! call_user_function(&GLOBAL(function_table), NULL, &func, &retval, 2, args);
efree(args[0]);
efree(args[1]);
}
}
/* }}} */
/* }}} */
/************************* EXTENSION FUNCTIONS *************************/
/* {{{ int XML_ParserCreate() */
--- 483,730 ----
add_assoc_string(args[2], key, value, 1);
attributes += 2;
}
! if (call_user_function(&GLOBAL(function_table), NULL, &func, &retval, 3, args) ==
SUCCESS) {
! pval_destructor(&retval);
! }
! pval_destructor(args[0]);
! pval_destructor(args[1]);
! pval_destructor(args[2]);
efree(args[0]);
efree(args[1]);
+ efree(args[2]);
}
}
/* }}} */
! /* {{{ php3i_xml_endElementHandler() */
void php3i_xml_endElementHandler(void *userData, const char *name)
{
xml_parser *parser = (xml_parser *)userData;
XML_TLS_VARS;
! if (parser && parser->endElementHandler) {
! pval retval, func, *args[2];
!
func.type = IS_STRING;
func.value.str.val = parser->endElementHandler;
func.value.str.len = strlen(func.value.str.val);
+ args[0] = php3i_longpval(parser->index);
+ args[1] = php3i_stringpval(name);
+ if (call_user_function(&GLOBAL(function_table), NULL, &func, &retval, 2, args) ==
SUCCESS) {
+ pval_destructor(&retval);
+ }
+ pval_destructor(args[0]);
+ pval_destructor(args[1]);
+ efree(args[0]);
+ efree(args[1]);
+ }
+ }
+
+ /* }}} */
+ /* {{{ php3i_xml_characterDataHandler() */
+
+ void php3i_xml_characterDataHandler(void *userData, const XML_Char *s, int len)
+ {
+ xml_parser *parser = (xml_parser *)userData;
+ XML_TLS_VARS;
! if (parser && parser->characterDataHandler) {
! pval retval, func, *args[2];
!
! func.type = IS_STRING;
! func.value.str.val = parser->characterDataHandler;
! func.value.str.len = strlen(func.value.str.val);
! args[0] = php3i_longpval(parser->index);
! args[1] = php3i_xmlcharpval(s, len);
! if (call_user_function(&GLOBAL(function_table), NULL, &func, &retval, 2, args) ==
SUCCESS) {
! pval_destructor(&retval);
! }
! pval_destructor(args[0]);
! pval_destructor(args[1]);
efree(args[0]);
efree(args[1]);
}
}
/* }}} */
+ /* {{{ php3i_xml_processingInstructionHandler() */
+
+ void php3i_xml_processingInstructionHandler(void *userData,
+ const XML_Char *target,
+ const XML_Char *data)
+ {
+ xml_parser *parser = (xml_parser *)userData;
+ XML_TLS_VARS;
+
+ if (parser && parser->processingInstructionHandler) {
+ pval retval, func, *args[3];
+ func.type = IS_STRING;
+ func.value.str.val = parser->processingInstructionHandler;
+ func.value.str.len = strlen(func.value.str.val);
+ args[0] = php3i_longpval(parser->index);
+ args[1] = php3i_xmlcharpval(target, 0);
+ args[2] = php3i_xmlcharpval(data, 0);
+ if (call_user_function(&GLOBAL(function_table), NULL, &func, &retval, 3, args) ==
SUCCESS) {
+ pval_destructor(&retval);
+ }
+ pval_destructor(args[0]);
+ pval_destructor(args[1]);
+ pval_destructor(args[3]);
+ efree(args[0]);
+ efree(args[1]);
+ efree(args[2]);
+ }
+ }
+
+ /* }}} */
+ /* {{{ php3i_xml_defaultHandler() */
+
+ void php3i_xml_defaultHandler(void *userData, const XML_Char *s, int len)
+ {
+ xml_parser *parser = (xml_parser *)userData;
+ XML_TLS_VARS;
+
+ if (parser && parser->defaultHandler) {
+ pval retval, func, *args[2];
+
+ func.type = IS_STRING;
+ func.value.str.val = parser->defaultHandler;
+ func.value.str.len = strlen(func.value.str.val);
+ args[0] = php3i_longpval(parser->index);
+ args[1] = php3i_xmlcharpval(s, len);
+ if (call_user_function(&GLOBAL(function_table), NULL, &func, &retval, 2, args) ==
SUCCESS) {
+ pval_destructor(&retval);
+ }
+ pval_destructor(args[0]);
+ pval_destructor(args[1]);
+ efree(args[0]);
+ efree(args[1]);
+ }
+ }
+
/* }}} */
+ /* {{{ php3i_xml_unparsedEntityDeclHandler() */
+
+ void php3i_xml_unparsedEntityDeclHandler(void *userData,
+ const XML_Char *entityName,
+ const XML_Char *base,
+ const XML_Char *systemId,
+ const XML_Char *publicId,
+ const XML_Char *notationName)
+ {
+ xml_parser *parser = (xml_parser *)userData;
+ XML_TLS_VARS;
+
+ if (parser && parser->unparsedEntityDeclHandler) {
+ pval retval, func, *args[5];
+
+ func.type = IS_STRING;
+ func.value.str.val = parser->unparsedEntityDeclHandler;
+ func.value.str.len = strlen(func.value.str.val);
+ args[0] = php3i_xmlcharpval(entityName, 0);
+ args[1] = php3i_xmlcharpval(base, 0);
+ args[2] = php3i_xmlcharpval(systemId, 0);
+ args[3] = php3i_xmlcharpval(publicId, 0);
+ args[4] = php3i_xmlcharpval(notationName, 0);
+ if (call_user_function(&GLOBAL(function_table), NULL, &func, &retval, 5, args) ==
SUCCESS) {
+ pval_destructor(&retval);
+ }
+ pval_destructor(args[0]);
+ pval_destructor(args[1]);
+ pval_destructor(args[2]);
+ pval_destructor(args[3]);
+ pval_destructor(args[4]);
+ efree(args[0]);
+ efree(args[1]);
+ efree(args[2]);
+ efree(args[3]);
+ efree(args[4]);
+ }
+ }
+ /* }}} */
+ /* {{{ php3i_xml_notationDeclHandler() */
+
+ void
+ php3i_xml_notationDeclHandler(void *userData,
+ const XML_Char *notationName,
+ const XML_Char *base,
+ const XML_Char *systemId,
+ const XML_Char *publicId)
+ {
+ xml_parser *parser = (xml_parser *)userData;
+ XML_TLS_VARS;
+
+ if (parser && parser->notationDeclHandler) {
+ pval retval, func, *args[4];
+
+ func.type = IS_STRING;
+ func.value.str.val = parser->notationDeclHandler;
+ func.value.str.len = strlen(func.value.str.val);
+ args[0] = php3i_xmlcharpval(notationName, 0);
+ args[1] = php3i_xmlcharpval(base, 0);
+ args[2] = php3i_xmlcharpval(systemId, 0);
+ args[3] = php3i_xmlcharpval(publicId, 0);
+ if (call_user_function(&GLOBAL(function_table), NULL, &func, &retval, 4, args) ==
SUCCESS) {
+ pval_destructor(&retval);
+ }
+ pval_destructor(args[0]);
+ pval_destructor(args[1]);
+ pval_destructor(args[2]);
+ pval_destructor(args[3]);
+ efree(args[0]);
+ efree(args[1]);
+ efree(args[2]);
+ efree(args[3]);
+ }
+ }
+
+ /* }}} */
+ /* {{{ php3i_xml_externalEntityRefHandler() */
+
+ int
+ php3i_xml_externalEntityRefHandler(XML_Parser parserPtr,
+ const XML_Char *openEntityNames,
+ const XML_Char *base,
+ const XML_Char *systemId,
+ const XML_Char *publicId)
+ {
+ xml_parser *parser = XML_GetUserData(parserPtr);
+ int ret = 1; /* don't abort if no handler is set */
+ XML_TLS_VARS;
+
+ if (parser && parser->externalEntityRefHandler) {
+ pval retval, func, *args[4];
+
+ func.type = IS_STRING;
+ func.value.str.val = parser->externalEntityRefHandler;
+ func.value.str.len = strlen(func.value.str.val);
+ args[0] = php3i_xmlcharpval(openEntityNames, 0);
+ args[1] = php3i_xmlcharpval(base, 0);
+ args[2] = php3i_xmlcharpval(systemId, 0);
+ args[3] = php3i_xmlcharpval(publicId, 0);
+ if (call_user_function(&GLOBAL(function_table), NULL, &func, &retval, 4, args) ==
SUCCESS) {
+ convert_to_long(&retval);
+ ret = (int)retval.value.lval;
+ }
+ pval_destructor(args[0]);
+ pval_destructor(args[1]);
+ pval_destructor(args[2]);
+ pval_destructor(args[3]);
+ efree(args[0]);
+ efree(args[1]);
+ efree(args[2]);
+ efree(args[3]);
+ }
+ return ret;
+ }
+
+ /* }}} */
+
+ /* }}} */
+
/************************* EXTENSION FUNCTIONS *************************/
/* {{{ int XML_ParserCreate() */
***************
*** 419,426 ****
parser = ecalloc(sizeof(xml_parser), 1);
parser->parser = XML_ParserCreate(NULL);
XML_SetUserData(parser->parser, parser);
! XML_SetElementHandler(parser->parser, php3i_xml_startElementHandler,
! php3i_xml_endElementHandler);
id = php3_list_insert(parser, XML_GLOBAL(php3_xml_module).le_xml_parser);
parser = xml_get_parser(id, "XML_ParserCreate", list);
parser->index = id;
--- 742,754 ----
parser = ecalloc(sizeof(xml_parser), 1);
parser->parser = XML_ParserCreate(NULL);
XML_SetUserData(parser->parser, parser);
! XML_SetElementHandler(parser->parser, php3i_xml_startElementHandler,
php3i_xml_endElementHandler);
! XML_SetCharacterDataHandler(parser->parser, php3i_xml_characterDataHandler);
! XML_SetProcessingInstructionHandler(parser->parser, php3i_xml_processingInstructionHandler);
! XML_SetDefaultHandler(parser->parser, php3i_xml_defaultHandler);
! XML_SetUnparsedEntityDeclHandler(parser->parser, php3i_xml_unparsedEntityDeclHandler);
! XML_SetNotationDeclHandler(parser->parser, php3i_xml_notationDeclHandler);
! XML_SetExternalEntityRefHandler(parser->parser, php3i_xml_externalEntityRefHandler);
id = php3_list_insert(parser, XML_GLOBAL(php3_xml_module).le_xml_parser);
parser = xml_get_parser(id, "XML_ParserCreate", list);
parser->index = id;
***************
*** 454,460 ****
}
/* }}} */
-
/* {{{ int XML_SetCharacterDataHandler(int pind, string hdl) */
PHP_FUNCTION(xml_setcharacterdatahandler)
--- 782,787 ----
***************
*** 587,593 ****
}
/* }}} */
-
/* {{{ int XML_Parse(int pind, string data[, int isFinal]) */
PHP_FUNCTION(xml_parse)
--- 914,919 ----
Index: php3/functions/php3_xml.h
diff -c php3/functions/php3_xml.h:1.1 php3/functions/php3_xml.h:1.2
*** php3/functions/php3_xml.h:1.1 Tue Oct 20 20:13:45 1998
--- php3/functions/php3_xml.h Wed Oct 21 07:03:09 1998
***************
*** 34,39 ****
--- 34,40 ----
# define _PHP_XML_H
# endif
+ #include <xml/xmltok.h>
#include <xml/xmlparse.h>
typedef struct {
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net