xref: /PHP-7.2/ext/dom/domexception.c (revision 7a7ec01a)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2018 The PHP Group                                |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Christian Stocker <chregu@php.net>                          |
16    |          Rob Richards <rrichards@php.net>                            |
17    +----------------------------------------------------------------------+
18 */
19 
20 /* $Id$ */
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include "php.h"
27 #if HAVE_LIBXML && HAVE_DOM
28 #include "php_dom.h"
29 
30 /*
31 * class DOMException
32 *
33 * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-17189187
34 * Since:
35 */
36 
37 extern zend_class_entry *dom_domexception_class_entry;
38 
39 const zend_function_entry php_dom_domexception_class_functions[] = {
40 	PHP_FE_END
41 };
42 
php_dom_throw_error_with_message(int error_code,char * error_message,int strict_error)43 void php_dom_throw_error_with_message(int error_code, char *error_message, int strict_error) /* {{{ */
44 {
45 	if (strict_error == 1) {
46 		zend_throw_exception(dom_domexception_class_entry, error_message, error_code);
47 	} else {
48 		php_libxml_issue_error(E_WARNING, error_message);
49 	}
50 }
51 /* }}} */
52 
53 /* {{{ php_dom_throw_error */
php_dom_throw_error(int error_code,int strict_error)54 void php_dom_throw_error(int error_code, int strict_error)
55 {
56 	char *error_message;
57 
58 	switch (error_code)
59 	{
60 		case INDEX_SIZE_ERR:
61 			error_message = "Index Size Error";
62 			break;
63 		case DOMSTRING_SIZE_ERR:
64 			error_message = "DOM String Size Error";
65 			break;
66 		case HIERARCHY_REQUEST_ERR:
67 			error_message = "Hierarchy Request Error";
68 			break;
69 		case WRONG_DOCUMENT_ERR:
70 			error_message = "Wrong Document Error";
71 			break;
72 		case INVALID_CHARACTER_ERR:
73 			error_message = "Invalid Character Error";
74 			break;
75 		case NO_DATA_ALLOWED_ERR:
76 			error_message = "No Data Allowed Error";
77 			break;
78 		case NO_MODIFICATION_ALLOWED_ERR:
79 			error_message = "No Modification Allowed Error";
80 			break;
81 		case NOT_FOUND_ERR:
82 			error_message = "Not Found Error";
83 			break;
84 		case NOT_SUPPORTED_ERR:
85 			error_message = "Not Supported Error";
86 			break;
87 		case INUSE_ATTRIBUTE_ERR:
88 			error_message = "Inuse Attribute Error";
89 			break;
90 		case INVALID_STATE_ERR:
91 			error_message = "Invalid State Error";
92 			break;
93 		case SYNTAX_ERR:
94 			error_message = "Syntax Error";
95 			break;
96 		case INVALID_MODIFICATION_ERR:
97 			error_message = "Invalid Modification Error";
98 			break;
99 		case NAMESPACE_ERR:
100 			error_message = "Namespace Error";
101 			break;
102 		case INVALID_ACCESS_ERR:
103 			error_message = "Invalid Access Error";
104 			break;
105 		case VALIDATION_ERR:
106 			error_message = "Validation Error";
107 			break;
108 		default:
109 			error_message = "Unhandled Error";
110 	}
111 
112 	php_dom_throw_error_with_message(error_code, error_message, strict_error);
113 }
114 /* }}} end php_dom_throw_error */
115 
116 #endif /* HAVE_LIBXML && HAVE_DOM */
117 
118 /*
119  * Local variables:
120  * tab-width: 4
121  * c-basic-offset: 4
122  * End:
123  * vim600: noet sw=4 ts=4 fdm=marker
124  * vim<600: noet sw=4 ts=4
125  */
126