xref: /PHP-7.4/ext/dom/domexception.c (revision 92ac598a)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 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 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "php.h"
25 #if HAVE_LIBXML && HAVE_DOM
26 #include "php_dom.h"
27 
28 /*
29 * class DOMException
30 *
31 * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-17189187
32 * Since:
33 */
34 
35 extern zend_class_entry *dom_domexception_class_entry;
36 
37 const zend_function_entry php_dom_domexception_class_functions[] = {
38 	PHP_FE_END
39 };
40 
php_dom_throw_error_with_message(int error_code,char * error_message,int strict_error)41 void php_dom_throw_error_with_message(int error_code, char *error_message, int strict_error) /* {{{ */
42 {
43 	if (strict_error == 1) {
44 		zend_throw_exception(dom_domexception_class_entry, error_message, error_code);
45 	} else {
46 		php_libxml_issue_error(E_WARNING, error_message);
47 	}
48 }
49 /* }}} */
50 
51 /* {{{ php_dom_throw_error */
php_dom_throw_error(int error_code,int strict_error)52 void php_dom_throw_error(int error_code, int strict_error)
53 {
54 	char *error_message;
55 
56 	switch (error_code)
57 	{
58 		case INDEX_SIZE_ERR:
59 			error_message = "Index Size Error";
60 			break;
61 		case DOMSTRING_SIZE_ERR:
62 			error_message = "DOM String Size Error";
63 			break;
64 		case HIERARCHY_REQUEST_ERR:
65 			error_message = "Hierarchy Request Error";
66 			break;
67 		case WRONG_DOCUMENT_ERR:
68 			error_message = "Wrong Document Error";
69 			break;
70 		case INVALID_CHARACTER_ERR:
71 			error_message = "Invalid Character Error";
72 			break;
73 		case NO_DATA_ALLOWED_ERR:
74 			error_message = "No Data Allowed Error";
75 			break;
76 		case NO_MODIFICATION_ALLOWED_ERR:
77 			error_message = "No Modification Allowed Error";
78 			break;
79 		case NOT_FOUND_ERR:
80 			error_message = "Not Found Error";
81 			break;
82 		case NOT_SUPPORTED_ERR:
83 			error_message = "Not Supported Error";
84 			break;
85 		case INUSE_ATTRIBUTE_ERR:
86 			error_message = "Inuse Attribute Error";
87 			break;
88 		case INVALID_STATE_ERR:
89 			error_message = "Invalid State Error";
90 			break;
91 		case SYNTAX_ERR:
92 			error_message = "Syntax Error";
93 			break;
94 		case INVALID_MODIFICATION_ERR:
95 			error_message = "Invalid Modification Error";
96 			break;
97 		case NAMESPACE_ERR:
98 			error_message = "Namespace Error";
99 			break;
100 		case INVALID_ACCESS_ERR:
101 			error_message = "Invalid Access Error";
102 			break;
103 		case VALIDATION_ERR:
104 			error_message = "Validation Error";
105 			break;
106 		default:
107 			error_message = "Unhandled Error";
108 	}
109 
110 	php_dom_throw_error_with_message(error_code, error_message, strict_error);
111 }
112 /* }}} end php_dom_throw_error */
113 
114 #endif /* HAVE_LIBXML && HAVE_DOM */
115