⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sablot.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
	zval        *retval;                     /* Return value from the sax comment function */	php_xslt    *handle = (php_xslt *) ctx;  /* A PHP-XSLT processor */    TSRMLS_FETCH();    	/* if no comment function exists, exit */	if (!XSLT_SAX(handle).comment) {		return;	}		/* Allocate and initialize arguments */	MAKE_STD_ZVAL(argv[0]);	MAKE_STD_ZVAL(argv[1]);		/* Argument 1: XSLT processor   (resource)	   Argument 2: Comment contents (string)	 */	ZVAL_RESOURCE(argv[0], handle->processor.idx);	zend_list_addref(handle->processor.idx);	ZVAL_STRING(argv[1], (char *) contents, 1);		/* Call the sax comment function */	xslt_call_function("sax comment", XSLT_SAX(handle).comment, handle->object,	                   2, argv, &retval);		/* Cleanup */	if (retval)		zval_ptr_dtor(&retval);}/* }}} *//* {{{ sax_pi()   Called when processing instructions are found */static SAX_RETURN sax_pi(void *ctx, SablotHandle processor,                         const char *target,                          const char *contents){	zval        *argv[3];                    /* Arguments to the sax processing instruction function */	zval        *retval;                     /* Return value from the sax processing instruction function */	php_xslt    *handle = (php_xslt *) ctx;  /* A PHP-XSLT processor */    TSRMLS_FETCH();    	/* If no processing instructions function exists, exit */	if (!XSLT_SAX(handle).pi) {		return;	}	/* Allocate and initialize arguments */	MAKE_STD_ZVAL(argv[0]);	MAKE_STD_ZVAL(argv[1]);	MAKE_STD_ZVAL(argv[2]);		/* Argument 1: XSLT processor     (resource)	   Argument 2: Target of the pi   (string)	   Argument 3: Contents of the pi (string)	 */	ZVAL_RESOURCE(argv[0], handle->processor.idx);	zend_list_addref(handle->processor.idx);	ZVAL_STRING(argv[1], (char *) target, 1);	ZVAL_STRING(argv[2], (char *) contents, 1);	/* Call processing instructions function */	xslt_call_function("sax processing instructions", XSLT_SAX(handle).pi, handle->object,	                   3, argv, &retval);	/* Cleanup */	if (retval)		zval_ptr_dtor(&retval);}/* }}} *//* {{{ sax_characters()   Called when characters are come upon */static SAX_RETURN sax_characters(void *ctx, SablotHandle processor,                                 const char *contents,                                  int length){	zval         *argv[2];                    /* Arguments to the sax characters function */	zval         *retval;                     /* Return value to the sax characters function */	php_xslt     *handle = (php_xslt *) ctx;  /* A PHP-XSLT processor */    TSRMLS_FETCH();    	/* If no characters function exists, exit */	if (!XSLT_SAX(handle).characters) {		return;	}		/* Allocate and initialize arguments */	MAKE_STD_ZVAL(argv[0]);	MAKE_STD_ZVAL(argv[1]);	/* Argument 1: XSLT processor (resource)	   Argument 2: Contents       (string)	 */	ZVAL_RESOURCE(argv[0], handle->processor.idx);	zend_list_addref(handle->processor.idx);	ZVAL_STRINGL(argv[1], (char *) contents, length, 1);	/* Call characters function */	xslt_call_function("sax characters", XSLT_SAX(handle).characters, handle->object,	                   2, argv, &retval);		/* Cleanup */	if (retval)		zval_ptr_dtor(&retval);}/* }}} *//* {{{ sax_enddoc()   Called when the document is finished being parsed */static SAX_RETURN sax_enddoc(void *ctx, SablotHandle processor){	zval        *argv[1];                    /* Arguments to the end document function */	zval        *retval;                     /* Return value from the end document function */	php_xslt    *handle = (php_xslt *) ctx;  /* A PHP-XSLT processor */    TSRMLS_FETCH();    	/* If no end document function exists, exit */	if (!XSLT_SAX(handle).doc_end) {		return;	}		/* Allocate and initialize arguments */	MAKE_STD_ZVAL(argv[0]);	/* Argument 1: XSLT Processor (resource)	 */	ZVAL_RESOURCE(argv[0], handle->processor.idx);	zend_list_addref(handle->processor.idx);		/* Call the function */	xslt_call_function("sax end doc", XSLT_SAX(handle).doc_end, handle->object,	                   1, argv, &retval);		/* Cleanup */	if (retval)		zval_ptr_dtor(&retval);}/* }}} *//* {{{ error_makecode()   Make the error code */static MH_ERROR error_makecode(void *user_data, SablotHandle proc, int severity, unsigned short facility, unsigned short code){	return 0;}/* }}} *//* {{{ error_log()   Called when its time to log data */static MH_ERROR error_log(void *user_data, SablotHandle proc, MH_ERROR code, MH_LEVEL level, char **fields){	php_xslt *handle = (php_xslt *) user_data;                                          /* A PHP-XSLT processor */	char     *errmsg  = NULL;                                                           /* Error message*/	char     *errtype = NULL;                                                           /* Error type */	char     *errline = NULL;                                                           /* Error line */	char     *msgbuf  = NULL;                                                           /* Message buffer */	char      msgformat[] = "Sablotron Message on line %s, level %s: %s\n"; /* Message format */	int       error = 0;                                                                /* Error container */    TSRMLS_FETCH();	if (!XSLT_LOG(handle).do_log)		return 0;		/* Parse the error array */	/* Loop through the error array */	if (fields) {		while (*fields) {			char *key;  /* Key to for the message */			char *val;  /* The message itself */			char *ptr;  /* Pointer to the location of the ':' (separator) */			int   pos;  /* Position of the ':' (separator) */			int   len;  /* Length of the string */			len = strlen(*fields);			/* Grab the separator's position */			ptr = strchr(*fields, ':');			if (!ptr) {				continue;			}			pos = ptr - *fields;			/* Allocate the key and value and copy the data onto them */			key = emalloc(pos + 1);			val = emalloc((len - pos) + 1);			strlcpy(key, *fields, pos + 1);			strlcpy(val, *fields + pos + 1, len - pos);			/* Check to see whether or not we want to save the data */			if (!strcmp(key, "msg")) {				errmsg = estrndup(val, len - pos);			}			else if (!strcmp(key, "type")) {				errtype = estrndup(val, len - pos);			}			else if (!strcmp(key, "line")) {				errline = estrndup(val, len - pos);			}			/* Haven't seen this yet, but turning it on during dev, to see				what we can encounter -- MRS			else {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got key %s with val %s", key, val);			}			*/						/* Cleanup */			if (key) efree(key);			if (val) efree(val);			/* Next key:value pair please :) */			fields++;		}	}		/* If no error line is given, then place none in the 	   file */	if (!errline) {		errline = estrndup("none", sizeof("none") - 1);	}		/* Default type is a log handle */	if (!errtype) {		errtype = estrndup("log", sizeof("log") - 1);	}		/* No error message, no cry */	if (!errmsg) {		errmsg = estrndup("unknown error", sizeof("unknown error") - 1);	}		/* Allocate the message buf and copy the data into it */	msgbuf = emalloc((sizeof(msgformat) - 6) +	                 strlen(errmsg) +	                 strlen(errline) +	                 strlen(errtype) + 1);	sprintf(msgbuf, msgformat, errline, errtype, errmsg);	/* If the error is serious enough, copy it to our error buffer 	   which will show up when someone calls the xslt_error() function */	if (level == MH_LEVEL_WARN  ||	    level == MH_LEVEL_ERROR ||	    level == MH_LEVEL_CRITICAL) {		XSLT_REG_ERRMSG(errmsg, handle);	}	/* If we haven't allocated and opened the file yet */	if (!XSLT_LOG(handle).fd) {		/* Lets open up a file */		if (XSLT_LOG(handle).path && strcmp(XSLT_LOG(handle).path, "php://stderr")) {			/* 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);			if (XSLT_LOG(handle).fd == -1) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot open log file, %s [%d]: %s",				          XSLT_LOG(handle).path, errno, strerror(errno));				XSLT_LOG(handle).fd = 0;			}		}		/* Default is stderr, or if the user provided "php://stderr" that's the		   stream */		else {			XSLT_LOG(handle).fd = 2;		}	}		/* Write the error to the file */	error = write(XSLT_LOG(handle).fd, msgbuf, strlen(msgbuf));	if (error == -1) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot write data to log file, %s, with fd, %d [%d]: %s",		          (XSLT_LOG(handle).path ? XSLT_LOG(handle).path : "stderr"),		          XSLT_LOG(handle).fd,		          errno,		          strerror(errno));		return 0;	}	/* Cleanup */	if (msgbuf)  efree(msgbuf);	if (errtype) efree(errtype);	if (errline) efree(errline);	if (errmsg)  efree(errmsg);		return 0;}/* }}} *//* {{{ error_print()   Print out an error message or call the error handler */static MH_ERROR error_print(void *user_data, SablotHandle proc, MH_ERROR code, MH_LEVEL level, char **fields){	php_xslt *handle = (php_xslt *) user_data;   /* A PHP-XSLT processor */		if (XSLT_ERROR(handle)) {		zval   *argv[4];   /* Arguments to the error function */		zval   *retval;    /* Return value from the error function */        TSRMLS_FETCH();        		/* Allocate and initialize */		MAKE_STD_ZVAL(argv[0]);		MAKE_STD_ZVAL(argv[1]);		MAKE_STD_ZVAL(argv[2]);		MAKE_STD_ZVAL(argv[3]);		array_init(argv[3]);		/* Argument 1: XSLT Processor (resource)		   Argument 2: Error level    (long)		   Argument 3: Error code     (long)		   Argument 4: Error messages (array)		 */		ZVAL_RESOURCE(argv[0], handle->processor.idx);		zend_list_addref(handle->processor.idx);		ZVAL_LONG(argv[1], level);		ZVAL_LONG(argv[2], code);		if (fields) {			while (*fields) {				char *key;  /* Key to for the message */				char *val;  /* The message itself */				char *ptr;  /* Pointer to the location of the ':' (separator) */				int   pos;  /* Position of the ':' (separator) */				int   len;  /* Length of the string */								len = strlen(*fields);							/* Grab the separator's position */				ptr = strchr(*fields, ':');				if (!ptr) {					continue;				}				pos = ptr - *fields;				/* Allocate the key and value and copy the data onto them */				key = emalloc(pos + 1);				val = emalloc((len - pos) + 1);				strlcpy(key, *fields, pos + 1);				strlcpy(val, *fields + pos + 1, len - pos);				/* Add it */								add_assoc_stringl_ex(argv[3], key, pos + 1, val, len - pos - 1, 1);				/* Cleanup */				efree(key);				efree(val);				/* Next field please */				fields++;			}		}		/* Call the function */		xslt_call_function("error handler", XSLT_ERROR(handle), handle->object,		                   4, argv, &retval);		/* Free up */		if (retval)			zval_ptr_dtor(&retval);	}	else {		char *errmsg  = NULL;                                  /* Error message */		char *errline = NULL;                                  /* Error line */		char *msgbuf  = NULL;                                  /* Message buffer */		char  msgformat[] = "Sablotron error on line %s: %s";  /* Message format */		/* If the error is not serious, exit out */		if (code == MH_LEVEL_WARN  || 		    code == MH_LEVEL_ERROR || 		    code == MH_LEVEL_CRITICAL) {			return 0;		}		/* Loop through and extract the error message and the 		   error line */		if (fields) {			while (fields && *fields) {				char *key;  /* Key to for the message */				char *val;  /* The message itself */				char *ptr;  /* Pointer to the location of the ':' (separator) */				int   pos;  /* Position of the ':' (separator) */				int   len;  /* Length of the string */							len = strlen(*fields);							/* Grab the separator's position */				ptr = strchr(*fields, ':');				if (!ptr) {					continue;				}				pos = ptr - *fields;							/* Allocate the key and value and copy the data onto them */				key = emalloc(pos + 1);				val = emalloc((len - pos) + 1);							strlcpy(key, *fields, pos + 1);				strlcpy(val, *fields + pos + 1, len - pos);							/* Check to see whether or not we want to save the data */				if (!strcmp(key, "msg")) {					errmsg = estrndup(val, len - pos);				}				else if (!strcmp(key, "line")) {					errline = estrndup(val, len - pos);				}				/* Cleanup */				if (key) efree(key);				if (val) efree(val);							/* Next key:value pair please :) */				fields++;			}		}				if (!errline) {			errline = estrndup("none", sizeof("none") - 1);		}		if (!errmsg) {			errmsg = estrndup("unkown error", sizeof("unkown error") - 1);		}		/* Allocate the message buffer and copy the data onto it */		msgbuf = emalloc((sizeof(msgformat) - 4) + strlen(errmsg) + strlen(errline) + 1);		sprintf(msgbuf, msgformat, errline, errmsg);		XSLT_REG_ERRMSG(errmsg, handle);		/* Output a warning */		php_error(E_WARNING, "%s", msgbuf);		/* Cleanup */		efree(msgbuf);		efree(errmsg);		efree(errline);	}	return(0);}/* }}} */#endif/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -