Back to index

php5  5.3.10
php_var.h
Go to the documentation of this file.
00001 /* 
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author: Jani Lehtimäki <jkl@njet.net>                                |
00016    +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: php_var.h 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifndef PHP_VAR_H
00022 #define PHP_VAR_H
00023 
00024 #include "ext/standard/php_smart_str_public.h"
00025 
00026 PHP_FUNCTION(var_dump);
00027 PHP_FUNCTION(var_export);
00028 PHP_FUNCTION(debug_zval_dump);
00029 PHP_FUNCTION(serialize);
00030 PHP_FUNCTION(unserialize);
00031 PHP_FUNCTION(memory_get_usage);
00032 PHP_FUNCTION(memory_get_peak_usage);
00033 
00034 PHPAPI void php_var_dump(zval **struc, int level TSRMLS_DC);
00035 PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC);
00036 PHPAPI void php_var_export_ex(zval **struc, int level, smart_str *buf TSRMLS_DC);
00037 
00038 PHPAPI void php_debug_zval_dump(zval **struc, int level TSRMLS_DC);
00039 
00040 /* typdef HashTable php_serialize_data_t; */
00041 #define php_serialize_data_t HashTable
00042 
00043 struct php_unserialize_data {
00044        void *first;
00045        void *first_dtor;
00046 };
00047 
00048 typedef struct php_unserialize_data php_unserialize_data_t;
00049 
00050 PHPAPI void php_var_serialize(smart_str *buf, zval **struc, php_serialize_data_t *var_hash TSRMLS_DC);
00051 PHPAPI int php_var_unserialize(zval **rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC);
00052 
00053 #define PHP_VAR_SERIALIZE_INIT(var_hash) \
00054    zend_hash_init(&(var_hash), 10, NULL, NULL, 0)
00055 #define PHP_VAR_SERIALIZE_DESTROY(var_hash) \
00056    zend_hash_destroy(&(var_hash))
00057 
00058 #define PHP_VAR_UNSERIALIZE_INIT(var_hash) \
00059        (var_hash).first = 0; \
00060        (var_hash).first_dtor = 0
00061 #define PHP_VAR_UNSERIALIZE_DESTROY(var_hash) \
00062        var_destroy(&(var_hash))
00063 
00064 PHPAPI void var_replace(php_unserialize_data_t *var_hash, zval *ozval, zval **nzval);
00065 PHPAPI void var_push_dtor(php_unserialize_data_t *var_hash, zval **val);
00066 PHPAPI void var_destroy(php_unserialize_data_t *var_hash);
00067 
00068 #define PHP_VAR_UNSERIALIZE_ZVAL_CHANGED(var_hash, ozval, nzval) \
00069        var_replace((var_hash), (ozval), &(nzval))
00070        
00071 PHPAPI zend_class_entry *php_create_empty_class(char *class_name, int len);
00072 
00073 static inline int php_varname_check(char *name, int name_len, zend_bool silent TSRMLS_DC) /* {{{ */
00074 {
00075     if (name_len == sizeof("GLOBALS") - 1 && !memcmp(name, "GLOBALS", sizeof("GLOBALS") - 1)) {
00076               if (!silent) {
00077                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted GLOBALS variable overwrite");
00078               }
00079         return FAILURE;
00080     } else if (name[0] == '_' &&
00081             (
00082              (name_len == sizeof("_GET") - 1 && !memcmp(name, "_GET", sizeof("_GET") - 1)) ||
00083              (name_len == sizeof("_POST") - 1 && !memcmp(name, "_POST", sizeof("_POST") - 1)) ||
00084              (name_len == sizeof("_COOKIE") - 1 && !memcmp(name, "_COOKIE", sizeof("_COOKIE") - 1)) ||
00085              (name_len == sizeof("_ENV") - 1 && !memcmp(name, "_ENV", sizeof("_ENV") - 1)) ||
00086              (name_len == sizeof("_SERVER") - 1 && !memcmp(name, "_SERVER", sizeof("_SERVER") - 1)) ||
00087              (name_len == sizeof("_SESSION") - 1 && !memcmp(name, "_SESSION", sizeof("_SESSION") - 1)) ||
00088              (name_len == sizeof("_FILES") - 1  && !memcmp(name, "_FILES", sizeof("_FILES") - 1)) ||
00089              (name_len == sizeof("_REQUEST") -1 && !memcmp(name, "_REQUEST", sizeof("_REQUEST") - 1))
00090             )
00091             ) {
00092               if (!silent) {
00093                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted super-global (%s) variable overwrite", name);
00094               }
00095         return FAILURE;
00096     } else if (name[0] == 'H' &&
00097             (
00098              (name_len == sizeof("HTTP_POST_VARS") - 1 && !memcmp(name, "HTTP_POST_VARS", sizeof("HTTP_POST_VARS") - 1)) ||
00099              (name_len == sizeof("HTTP_GET_VARS") - 1 && !memcmp(name, "HTTP_GET_VARS", sizeof("HTTP_GET_VARS") - 1)) ||
00100              (name_len == sizeof("HTTP_COOKIE_VARS") - 1 && !memcmp(name, "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS") - 1)) ||
00101              (name_len == sizeof("HTTP_ENV_VARS") - 1 && !memcmp(name, "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS") - 1)) ||
00102              (name_len == sizeof("HTTP_SERVER_VARS") - 1 && !memcmp(name, "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS") - 1)) ||
00103              (name_len == sizeof("HTTP_SESSION_VARS") - 1 && !memcmp(name, "HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS") - 1)) ||
00104              (name_len == sizeof("HTTP_RAW_POST_DATA") - 1 && !memcmp(name, "HTTP_RAW_POST_DATA", sizeof("HTTP_RAW_POST_DATA") - 1)) ||
00105              (name_len == sizeof("HTTP_POST_FILES") - 1 && !memcmp(name, "HTTP_POST_FILES", sizeof("HTTP_POST_FILES") - 1))
00106             )
00107             ) {
00108               if (!silent) {
00109                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted long input array (%s) overwrite", name);
00110               }
00111         return FAILURE;
00112     }
00113        return SUCCESS;
00114 }
00115 /* }}} */
00116 
00117 #endif /* PHP_VAR_H */