From 098a43dbd07a48aa48b8ced771cd59b1279f7481 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sun, 8 Jan 2023 17:03:06 +0000 Subject: [PATCH] Introduce new INI API to get zend_string* value for an INI setting --- Zend/zend_ini.c | 40 ++++++++++++++++++++++++++++++++++++++++ Zend/zend_ini.h | 2 ++ 2 files changed, 42 insertions(+) diff --git a/Zend/zend_ini.c b/Zend/zend_ini.c index e2979e76444..1847a1e7ea0 100644 --- a/Zend/zend_ini.c +++ b/Zend/zend_ini.c @@ -519,6 +519,46 @@ ZEND_API char *zend_ini_string(const char *name, size_t name_length, int orig) / } /* }}} */ + +ZEND_API zend_string *zend_ini_str_ex(const char *name, size_t name_length, bool orig, bool *exists) /* {{{ */ +{ + zend_ini_entry *ini_entry; + + ini_entry = zend_hash_str_find_ptr(EG(ini_directives), name, name_length); + if (ini_entry) { + if (exists) { + *exists = 1; + } + + if (orig && ini_entry->modified) { + return ini_entry->orig_value ? ini_entry->orig_value : NULL; + } else { + return ini_entry->value ? ini_entry->value : NULL; + } + } else { + if (exists) { + *exists = 0; + } + return NULL; + } +} +/* }}} */ + +ZEND_API zend_string *zend_ini_str(const char *name, size_t name_length, bool orig) /* {{{ */ +{ + bool exists = 1; + zend_string *return_value; + + return_value = zend_ini_str_ex(name, name_length, orig, &exists); + if (!exists) { + return NULL; + } else if (!return_value) { + return_value = ZSTR_EMPTY_ALLOC(); + } + return return_value; +} +/* }}} */ + ZEND_API zend_string *zend_ini_get_value(zend_string *name) /* {{{ */ { zend_ini_entry *ini_entry; diff --git a/Zend/zend_ini.h b/Zend/zend_ini.h index ce5af258d87..ebc28de2cad 100644 --- a/Zend/zend_ini.h +++ b/Zend/zend_ini.h @@ -99,6 +99,8 @@ ZEND_API zend_long zend_ini_long(const char *name, size_t name_length, int orig) ZEND_API double zend_ini_double(const char *name, size_t name_length, int orig); ZEND_API char *zend_ini_string(const char *name, size_t name_length, int orig); ZEND_API char *zend_ini_string_ex(const char *name, size_t name_length, int orig, bool *exists); +ZEND_API zend_string *zend_ini_str(const char *name, size_t name_length, bool orig); +ZEND_API zend_string *zend_ini_str_ex(const char *name, size_t name_length, bool orig, bool *exists); ZEND_API zend_string *zend_ini_get_value(zend_string *name); ZEND_API bool zend_ini_parse_bool(zend_string *str);