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