-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDeepTrace_constants.c
88 lines (76 loc) · 3.2 KB
/
DeepTrace_constants.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* +------------------------------------------------------------------------+
* | DeepTrace (Website: http://www.snapserv.net/) |
* +------------------------------------------------------------------------+
* | Copyright (c) 2012-2013 P. Mathis ([email protected]) |
* | Y. Khalil ([email protected]) |
* +------------------------------------------------------------------------+
* | Licensed under the Apache License, Version 2.0 (the "License"); |
* | you may not use this file except in compliance with the License. |
* | You may obtain a copy of the License at |
* | |
* | http://www.apache.org/licenses/LICENSE-2.0 |
* | |
* | Unless required by applicable law or agreed to in writing, software |
* | distributed under the License is distributed on an "AS IS" BASIS, |
* | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
* | implied. See the License for the specific language governing |
* | permissions and limitations under the License. |
* +------------------------------------------------------------------------+
*/
#include "php_DeepTrace.h"
/* {{{ proto bool dt_remove_constant(string constantName)
Deletes a PHP constant */
PHP_FUNCTION(dt_remove_constant)
{
DEEPTRACE_DECL_STRING_PARAM(constantName);
char *lcase;
zend_bool caseSensitive;
zend_constant *constant;
ulong hash;
if(UNEXPECTED(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", DEEPTRACE_STRING_PARAM(constantName)) == FAILURE)) {
RETURN_FALSE;
}
/* Find constant in hash table */
if(zend_hash_find(EG(zend_constants), constantName, constantName_len + 1, (void **) &constant) == FAILURE) {
lcase = zend_str_tolower_dup(constantName, constantName_len);
/* Check if case-sensitive constant exists */
if(zend_hash_find(EG(zend_constants), lcase, constantName_len + 1, (void **) &constant) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Constant '%s' not found.", constantName);
efree(lcase);
RETURN_FALSE;
}
/* Check if constant is case-sensitive */
if(constant->flags & CONST_CS) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Constant '%s' is case-sensitive.", constantName);
efree(lcase);
RETURN_FALSE;
}
efree(lcase);
}
/* Output safety warning for persistent constants */
if(constant->flags & CONST_PERSISTENT) {
#ifdef DEEPTRACE_NOTICES
php_error_docref(NULL TSRMLS_CC, E_NOTICE,
"Constant '%s' is persistent. You can, but you should not touch it.", constantName);
#endif
}
/* Get constant name and hash */
caseSensitive = (constant->flags & CONST_CS) == 0;
if(caseSensitive) {
constantName = zend_str_tolower_dup(constant->name, constant->name_len);
} else {
constantName = constant->name;
}
hash = zend_inline_hash_func(constantName, constant->name_len);
/* Delete constant in hash table */
if(UNEXPECTED(zend_hash_quick_del(EG(zend_constants), constantName, constant->name_len, hash) == FAILURE)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can not remove constant '%s'.", constantName);
if(caseSensitive) efree(constantName);
RETURN_FALSE;
}
DeepTrace_clear_all_functions_runtime_cache(TSRMLS_C);
if(caseSensitive) efree(constantName);
RETURN_TRUE;
}
/* }}} */