diff options
Diffstat (limited to 'ext/dba')
37 files changed, 650 insertions, 782 deletions
diff --git a/ext/dba/README b/ext/dba/README index 0c22830e54..a79413f100 100755 --- a/ext/dba/README +++ b/ext/dba/README @@ -39,7 +39,7 @@ inifile This is available since PHP 4.3.3 to be able to modify php.ini As the functions dba_firstkey() and dba_nextkey() return string representations of the key there is a new function dba_key_split() available since PHP 5 which allows to convert the string keys into - array keys without loosing FALSE. + array keys without losing FALSE. qdbm This is available since PHP 5.0.0. The qdbm library can be loaded from http://qdbm.sourceforge.net. diff --git a/ext/dba/config.w32 b/ext/dba/config.w32 index 4f3514e62f..4abba8dbf4 100644 --- a/ext/dba/config.w32 +++ b/ext/dba/config.w32 @@ -4,7 +4,7 @@ ARG_WITH("dba", "DBA support", "no"); if (PHP_DBA != "no") { - if (CHECK_LIB("libdb31s.lib", "dba", PHP_DBA) && + if (CHECK_LIB("libdb31s.lib;libdb61.lib", "dba", PHP_DBA) && CHECK_HEADER_ADD_INCLUDE("db.h", "CFLAGS_DBA")) { EXTENSION("dba", "dba.c dba_cdb.c dba_db1.c dba_db2.c dba_db3.c dba_dbm.c dba_flatfile.c dba_gdbm.c dba_ndbm.c dba_inifile.c"); ADD_SOURCES("ext/dba/libcdb", "cdb.c cdb_make.c uint32.c", "dba"); diff --git a/ext/dba/dba.c b/ext/dba/dba.c index bad12d0a50..fd4522b9d6 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -28,12 +28,12 @@ #if HAVE_DBA #include "php_ini.h" -#include <stdio.h> +#include <stdio.h> #include <fcntl.h> #ifdef HAVE_SYS_FILE_H #include <sys/file.h> #endif - + #include "php_dba.h" #include "ext/standard/info.h" #include "ext/standard/php_string.h" @@ -157,7 +157,7 @@ PHP_MINFO_FUNCTION(dba); ZEND_BEGIN_MODULE_GLOBALS(dba) char *default_handler; dba_handler *default_hptr; -ZEND_END_MODULE_GLOBALS(dba) +ZEND_END_MODULE_GLOBALS(dba) ZEND_DECLARE_MODULE_GLOBALS(dba) @@ -165,20 +165,20 @@ ZEND_DECLARE_MODULE_GLOBALS(dba) #define DBA_G(v) TSRMG(dba_globals_id, zend_dba_globals *, v) #else #define DBA_G(v) (dba_globals.v) -#endif +#endif static PHP_GINIT_FUNCTION(dba); zend_module_entry dba_module_entry = { STANDARD_MODULE_HEADER, "dba", - dba_functions, - PHP_MINIT(dba), + dba_functions, + PHP_MINIT(dba), PHP_MSHUTDOWN(dba), NULL, NULL, PHP_MINFO(dba), - NO_VERSION_YET, + PHP_DBA_VERSION, PHP_MODULE_GLOBALS(dba), PHP_GINIT(dba), NULL, @@ -200,42 +200,43 @@ ZEND_GET_MODULE(dba) /* these are used to get the standard arguments */ /* {{{ php_dba_myke_key */ -static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS_DC) +static size_t php_dba_make_key(zval *key, char **key_str, char **key_free) { if (Z_TYPE_P(key) == IS_ARRAY) { - zval **group, **name; + zval *group, *name; HashPosition pos; size_t len; - + if (zend_hash_num_elements(Z_ARRVAL_P(key)) != 2) { - php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Key does not have exactly two elements: (key, name)"); - return -1; + php_error_docref(NULL, E_RECOVERABLE_ERROR, "Key does not have exactly two elements: (key, name)"); + return 0; } zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(key), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_P(key), (void **) &group, &pos); + group = zend_hash_get_current_data_ex(Z_ARRVAL_P(key), &pos); zend_hash_move_forward_ex(Z_ARRVAL_P(key), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_P(key), (void **) &name, &pos); + name = zend_hash_get_current_data_ex(Z_ARRVAL_P(key), &pos); convert_to_string_ex(group); convert_to_string_ex(name); - if (Z_STRLEN_PP(group) == 0) { - *key_str = Z_STRVAL_PP(name); + if (Z_STRLEN_P(group) == 0) { + *key_str = Z_STRVAL_P(name); *key_free = NULL; - return Z_STRLEN_PP(name); + return Z_STRLEN_P(name); } - len = spprintf(key_str, 0, "[%s]%s", Z_STRVAL_PP(group), Z_STRVAL_PP(name)); + len = spprintf(key_str, 0, "[%s]%s", Z_STRVAL_P(group), Z_STRVAL_P(name)); *key_free = *key_str; return len; } else { - zval tmp = *key; + zval tmp; int len; - zval_copy_ctor(&tmp); + ZVAL_COPY(&tmp, key); convert_to_string(&tmp); - *key_free = *key_str = estrndup(Z_STRVAL(tmp), Z_STRLEN(tmp)); len = Z_STRLEN(tmp); - - zval_dtor(&tmp); + if (len) { + *key_free = *key_str = estrndup(Z_STRVAL(tmp), Z_STRLEN(tmp)); + } + zval_ptr_dtor(&tmp); return len; } } @@ -245,10 +246,10 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS zval *key; \ char *key_str, *key_free; \ size_t key_len; \ - if (zend_parse_parameters(ac TSRMLS_CC, "zr", &key, &id) == FAILURE) { \ + if (zend_parse_parameters(ac, "zr", &key, &id) == FAILURE) { \ return; \ } \ - if ((key_len = php_dba_make_key(key, &key_str, &key_free TSRMLS_CC)) == 0) {\ + if ((key_len = php_dba_make_key(key, &key_str, &key_free)) == 0) {\ RETURN_FALSE; \ } @@ -256,31 +257,39 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS zval *key; \ char *key_str, *key_free; \ size_t key_len; \ - long skip = 0; \ + zend_long skip = 0; \ switch(ac) { \ case 2: \ - if (zend_parse_parameters(ac TSRMLS_CC, "zr", &key, &id) == FAILURE) { \ + if (zend_parse_parameters(ac, "zr", &key, &id) == FAILURE) { \ return; \ } \ break; \ case 3: \ - if (zend_parse_parameters(ac TSRMLS_CC, "zlr", &key, &skip, &id) == FAILURE) { \ + if (zend_parse_parameters(ac, "zlr", &key, &skip, &id) == FAILURE) { \ return; \ } \ break; \ default: \ WRONG_PARAM_COUNT; \ } \ - if ((key_len = php_dba_make_key(key, &key_str, &key_free TSRMLS_CC)) == 0) {\ + if ((key_len = php_dba_make_key(key, &key_str, &key_free)) == 0) {\ RETURN_FALSE; \ } #define DBA_FETCH_RESOURCE(info, id) \ - ZEND_FETCH_RESOURCE2(info, dba_info *, id, -1, "DBA identifier", le_db, le_pdb); + if ((info = (dba_info *)zend_fetch_resource2(Z_RES_P(id), "DBA identifier", le_db, le_pdb)) == NULL) { \ + RETURN_FALSE; \ + } + +#define DBA_FETCH_RESOURCE_WITH_ID(info, id) \ + if ((info = (dba_info *)zend_fetch_resource2(Z_RES_P(id), "DBA identifier", le_db, le_pdb)) == NULL) { \ + DBA_ID_DONE; \ + RETURN_FALSE; \ + } -#define DBA_ID_GET2 DBA_ID_PARS; DBA_GET2; DBA_FETCH_RESOURCE(info, &id) -#define DBA_ID_GET2_3 DBA_ID_PARS; DBA_GET2_3; DBA_FETCH_RESOURCE(info, &id) +#define DBA_ID_GET2 DBA_ID_PARS; DBA_GET2; DBA_FETCH_RESOURCE_WITH_ID(info, id) +#define DBA_ID_GET2_3 DBA_ID_PARS; DBA_GET2_3; DBA_FETCH_RESOURCE_WITH_ID(info, id) #define DBA_ID_DONE \ if (key_free) efree(key_free) @@ -298,14 +307,14 @@ static size_t php_dba_make_key(zval *key, char **key_str, char **key_free TSRMLS /* check whether the user has write access */ #define DBA_WRITE_CHECK \ if(info->mode != DBA_WRITER && info->mode != DBA_TRUNC && info->mode != DBA_CREAT) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "You cannot perform a modification to a database without proper access"); \ + php_error_docref(NULL, E_WARNING, "You cannot perform a modification to a database without proper access"); \ RETURN_FALSE; \ } /* the same check, but with a call to DBA_ID_DONE before returning */ #define DBA_WRITE_CHECK_WITH_ID \ if(info->mode != DBA_WRITER && info->mode != DBA_TRUNC && info->mode != DBA_CREAT) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "You cannot perform a modification to a database without proper access"); \ + php_error_docref(NULL, E_WARNING, "You cannot perform a modification to a database without proper access"); \ DBA_ID_DONE; \ RETURN_FALSE; \ } @@ -387,7 +396,7 @@ static int le_pdb; /* }}} */ /* {{{ dba_fetch_resource -PHPAPI void dba_fetch_resource(dba_info **pinfo, zval **id TSRMLS_DC) +PHPAPI void dba_fetch_resource(dba_info **pinfo, zval **id) { dba_info *info; DBA_ID_FETCH @@ -406,25 +415,25 @@ PHPAPI dba_handler *dba_get_handler(const char* handler_name) */ /* }}} */ -/* {{{ dba_close - */ -static void dba_close(dba_info *info TSRMLS_DC) +/* {{{ dba_close + */ +static void dba_close(dba_info *info) { if (info->hnd) { - info->hnd->close(info TSRMLS_CC); + info->hnd->close(info); } if (info->path) { pefree(info->path, info->flags&DBA_PERSISTENT); } - if (info->fp && info->fp!=info->lock.fp) { - if(info->flags&DBA_PERSISTENT) { + if (info->fp && info->fp != info->lock.fp) { + if (info->flags & DBA_PERSISTENT) { php_stream_pclose(info->fp); } else { php_stream_close(info->fp); } } if (info->lock.fp) { - if(info->flags&DBA_PERSISTENT) { + if (info->flags & DBA_PERSISTENT) { php_stream_pclose(info->lock.fp); } else { php_stream_close(info->lock.fp); @@ -439,28 +448,36 @@ static void dba_close(dba_info *info TSRMLS_DC) /* {{{ dba_close_rsrc */ -static void dba_close_rsrc(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void dba_close_rsrc(zend_resource *rsrc) { - dba_info *info = (dba_info *)rsrc->ptr; + dba_info *info = (dba_info *)rsrc->ptr; - dba_close(info TSRMLS_CC); + dba_close(info); } /* }}} */ /* {{{ dba_close_pe_rsrc_deleter */ -int dba_close_pe_rsrc_deleter(zend_rsrc_list_entry *le, void *pDba TSRMLS_DC) +int dba_close_pe_rsrc_deleter(zval *el, void *pDba) { - return le->ptr == pDba; + if (Z_RES_P(el)->ptr == pDba) { + if (Z_DELREF_P(el) == 0) { + return ZEND_HASH_APPLY_REMOVE; + } else { + return ZEND_HASH_APPLY_KEEP | ZEND_HASH_APPLY_STOP; + } + } else { + return ZEND_HASH_APPLY_KEEP; + } } /* }}} */ /* {{{ dba_close_pe_rsrc */ -static void dba_close_pe_rsrc(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void dba_close_pe_rsrc(zend_resource *rsrc) { - dba_info *info = (dba_info *)rsrc->ptr; + dba_info *info = (dba_info *)rsrc->ptr; /* closes the resource by calling dba_close_rsrc() */ - zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) dba_close_pe_rsrc_deleter, info TSRMLS_CC); + zend_hash_apply_with_argument(&EG(persistent_list), dba_close_pe_rsrc_deleter, info); } /* }}} */ @@ -470,26 +487,26 @@ ZEND_INI_MH(OnUpdateDefaultHandler) { dba_handler *hptr; - if (!strlen(new_value)) { + if (!ZSTR_LEN(new_value)) { DBA_G(default_hptr) = NULL; - return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); } - for (hptr = handler; hptr->name && strcasecmp(hptr->name, new_value); hptr++); + for (hptr = handler; hptr->name && strcasecmp(hptr->name, ZSTR_VAL(new_value)); hptr++); if (!hptr->name) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such handler: %s", new_value); + php_error_docref(NULL, E_WARNING, "No such handler: %s", ZSTR_VAL(new_value)); return FAILURE; } DBA_G(default_hptr) = hptr; - return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); } PHP_INI_BEGIN() STD_PHP_INI_ENTRY("dba.default_handler", DBA_DEFAULT, PHP_INI_ALL, OnUpdateDefaultHandler, default_handler, zend_dba_globals, dba_globals) PHP_INI_END() /* }}} */ - + /* {{{ PHP_GINIT_FUNCTION */ static PHP_GINIT_FUNCTION(dba) @@ -519,7 +536,7 @@ PHP_MSHUTDOWN_FUNCTION(dba) } /* }}} */ -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" /* {{{ PHP_MINFO_FUNCTION */ @@ -535,9 +552,9 @@ PHP_MINFO_FUNCTION(dba) php_info_print_table_start(); php_info_print_table_row(2, "DBA support", "enabled"); - if (handlers.c) { + if (handlers.s) { smart_str_0(&handlers); - php_info_print_table_row(2, "Supported handlers", handlers.c); + php_info_print_table_row(2, "Supported handlers", ZSTR_VAL(handlers.s)); smart_str_free(&handlers); } else { php_info_print_table_row(2, "Supported handlers", "none"); @@ -551,7 +568,7 @@ PHP_MINFO_FUNCTION(dba) */ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode) { - int val_len; + size_t val_len; zval *id; dba_info *info = NULL; int ac = ZEND_NUM_ARGS(); @@ -560,19 +577,19 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode) char *key_str, *key_free; size_t key_len; - if (zend_parse_parameters(ac TSRMLS_CC, "zsr", &key, &val, &val_len, &id) == FAILURE) { + if (zend_parse_parameters(ac, "zsr", &key, &val, &val_len, &id) == FAILURE) { return; } - if ((key_len = php_dba_make_key(key, &key_str, &key_free TSRMLS_CC)) == 0) { + if ((key_len = php_dba_make_key(key, &key_str, &key_free)) == 0) { RETURN_FALSE; } - DBA_FETCH_RESOURCE(info, &id); + DBA_FETCH_RESOURCE_WITH_ID(info, id); DBA_WRITE_CHECK_WITH_ID; - if (info->hnd->update(info, key_str, key_len, val, val_len, mode TSRMLS_CC) == SUCCESS) { + if (info->hnd->update(info, key_str, key_len, val, val_len, mode) == SUCCESS) { DBA_ID_DONE; RETURN_TRUE; } @@ -582,22 +599,22 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode) } /* }}} */ -#define FREENOW if(args) efree(args); if(key) efree(key) +#define FREENOW if(args) {int i; for (i=0; i<ac; i++) { zval_ptr_dtor(&args[i]); } efree(args);} if(key) efree(key) /* {{{ php_find_dbm */ -dba_info *php_dba_find(const char* path TSRMLS_DC) +dba_info *php_dba_find(const char* path) { - zend_rsrc_list_entry *le; + zend_resource *le; dba_info *info; int numitems, i; numitems = zend_hash_next_free_element(&EG(regular_list)); for (i=1; i<numitems; i++) { - if (zend_hash_index_find(&EG(regular_list), i, (void **) &le)==FAILURE) { + if ((le = zend_hash_index_find_ptr(&EG(regular_list), i)) == NULL) { continue; } - if (Z_TYPE_P(le) == le_db || Z_TYPE_P(le) == le_pdb) { + if (le->type == le_db || le->type == le_pdb) { info = (dba_info *)(le->ptr); if (!strcmp(info->path, path)) { return (dba_info *)(le->ptr); @@ -613,7 +630,7 @@ dba_info *php_dba_find(const char* path TSRMLS_DC) */ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) { - zval ***args = (zval ***) NULL; + zval *args = NULL; int ac = ZEND_NUM_ARGS(); dba_mode_t modenr; dba_info *info, *other; @@ -625,67 +642,68 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) char *file_mode; char mode[4], *pmode, *lock_file_mode = NULL; int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0; - char *opened_path = NULL; + zend_string *opened_path = NULL; char *lock_name; - - if(ac < 2) { + + if (ac < 2) { WRONG_PARAM_COUNT; } - + /* we pass additional args to the respective handler */ - args = safe_emalloc(ac, sizeof(zval *), 0); + args = safe_emalloc(ac, sizeof(zval), 0); if (zend_get_parameters_array_ex(ac, args) != SUCCESS) { - FREENOW; + efree(args); WRONG_PARAM_COUNT; } - + /* we only take string arguments */ for (i = 0; i < ac; i++) { - convert_to_string_ex(args[i]); - keylen += Z_STRLEN_PP(args[i]); + ZVAL_STR(&args[i], zval_get_string(&args[i])); + keylen += Z_STRLEN(args[i]); } if (persistent) { - zend_rsrc_list_entry *le; - + zend_resource *le; + /* calculate hash */ key = safe_emalloc(keylen, 1, 1); key[keylen] = '\0'; keylen = 0; - + for(i = 0; i < ac; i++) { - memcpy(key+keylen, Z_STRVAL_PP(args[i]), Z_STRLEN_PP(args[i])); - keylen += Z_STRLEN_PP(args[i]); + memcpy(key+keylen, Z_STRVAL(args[i]), Z_STRLEN(args[i])); + keylen += Z_STRLEN(args[i]); } /* try to find if we already have this link in our persistent list */ - if (zend_hash_find(&EG(persistent_list), key, keylen+1, (void **) &le) == SUCCESS) { + if ((le = zend_hash_str_find_ptr(&EG(persistent_list), key, keylen)) != NULL) { FREENOW; - - if (Z_TYPE_P(le) != le_pdb) { + + if (le->type != le_pdb) { RETURN_FALSE; } - + info = (dba_info *)le->ptr; - ZEND_REGISTER_RESOURCE(return_value, info, le_pdb); + GC_REFCOUNT(le)++; + RETURN_RES(zend_register_resource(info, le_pdb)); return; } } - + if (ac==2) { hptr = DBA_G(default_hptr); if (!hptr) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "No default handler selected"); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "No default handler selected"); FREENOW; RETURN_FALSE; } } else { - for (hptr = handler; hptr->name && strcasecmp(hptr->name, Z_STRVAL_PP(args[2])); hptr++); + for (hptr = handler; hptr->name && strcasecmp(hptr->name, Z_STRVAL(args[2])); hptr++); } if (!hptr->name) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "No such handler: %s", Z_STRVAL_PP(args[2])); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "No such handler: %s", Z_STRVAL(args[2])); FREENOW; RETURN_FALSE; } @@ -702,7 +720,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) * * t: test open database, warning if locked */ - strlcpy(mode, Z_STRVAL_PP(args[1]), sizeof(mode)); + strlcpy(mode, Z_STRVAL(args[1]), sizeof(mode)); pmode = &mode[0]; if (pmode[0] && (pmode[1]=='d' || pmode[1]=='l' || pmode[1]=='-')) { /* force lock on db file or lck file or disable locking */ switch (pmode[1]) { @@ -716,13 +734,13 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) case 'l': lock_flag = DBA_LOCK_ALL; if ((hptr->flags & DBA_LOCK_ALL) == 0) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_NOTICE, "Handler %s does locking internally", hptr->name); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_NOTICE, "Handler %s does locking internally", hptr->name); } break; default: case '-': if ((hptr->flags & DBA_LOCK_ALL) == 0) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Locking cannot be disabled for handler %s", hptr->name); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "Locking cannot be disabled for handler %s", hptr->name); FREENOW; RETURN_FALSE; } @@ -734,18 +752,18 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) lock_dbf = 1; } switch (*pmode++) { - case 'r': - modenr = DBA_READER; + case 'r': + modenr = DBA_READER; lock_mode = (lock_flag & DBA_LOCK_READER) ? LOCK_SH : 0; file_mode = "r"; break; - case 'w': - modenr = DBA_WRITER; + case 'w': + modenr = DBA_WRITER; lock_mode = (lock_flag & DBA_LOCK_WRITER) ? LOCK_EX : 0; file_mode = "r+b"; break; - case 'c': - modenr = DBA_CREAT; + case 'c': + modenr = DBA_CREAT; lock_mode = (lock_flag & DBA_LOCK_CREAT) ? LOCK_EX : 0; if (lock_mode) { if (lock_dbf) { @@ -761,7 +779,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) } else { file_mode = "a+b"; } - /* In case of the 'a+b' append mode, the handler is responsible + /* In case of the 'a+b' append mode, the handler is responsible * to handle any rewind problems (see flatfile handler). */ break; @@ -771,7 +789,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) file_mode = "w+b"; break; default: - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Illegal DBA mode"); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "Illegal DBA mode"); FREENOW; RETURN_FALSE; } @@ -784,17 +802,17 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (*pmode=='t') { pmode++; if (!lock_flag) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "You cannot combine modifiers - (no lock) and t (test lock)"); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "You cannot combine modifiers - (no lock) and t (test lock)"); FREENOW; RETURN_FALSE; } if (!lock_mode) { if ((hptr->flags & DBA_LOCK_ALL) == 0) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Handler %s uses its own locking which doesn't support mode modifier t (test lock)", hptr->name); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "Handler %s uses its own locking which doesn't support mode modifier t (test lock)", hptr->name); FREENOW; RETURN_FALSE; } else { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Handler %s doesn't uses locking for this mode which makes modifier t (test lock) obsolete", hptr->name); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "Handler %s doesn't uses locking for this mode which makes modifier t (test lock) obsolete", hptr->name); FREENOW; RETURN_FALSE; } @@ -803,14 +821,14 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) } } if (*pmode) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Illegal DBA mode"); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "Illegal DBA mode"); FREENOW; RETURN_FALSE; } - + info = pemalloc(sizeof(dba_info), persistent); memset(info, 0, sizeof(dba_info)); - info->path = pestrdup(Z_STRVAL_PP(args[0]), persistent); + info->path = pestrdup(Z_STRVAL(args[0]), persistent); info->mode = modenr; info->argc = ac - 3; info->argv = args + 3; @@ -822,7 +840,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) * the problem is some systems would allow read during write */ if (hptr->flags & DBA_LOCK_ALL) { - if ((other = php_dba_find(info->path TSRMLS_CC)) != NULL) { + if ((other = php_dba_find(info->path)) != NULL) { if ( ( (lock_mode&LOCK_EX) && (other->lock.mode&(LOCK_EX|LOCK_SH)) ) || ( (other->lock.mode&LOCK_EX) && (lock_mode&(LOCK_EX|LOCK_SH)) ) ) { @@ -833,7 +851,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (!error && lock_mode) { if (lock_dbf) { - lock_name = Z_STRVAL_PP(args[0]); + lock_name = Z_STRVAL(args[0]); } else { spprintf(&lock_name, 0, "%s.lck", info->path); if (!strcmp(file_mode, "r")) { @@ -846,13 +864,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* when not in read mode or failed to open .lck file read only. now try again in create(write) mode and log errors */ lock_file_mode = "a+b"; } else { - if (!persistent) { - info->lock.name = opened_path; - } else { - if (opened_path) { - info->lock.name = pestrdup(opened_path, persistent); - efree(opened_path); - } + if (opened_path) { + info->lock.name = pestrndup(ZSTR_VAL(opened_path), ZSTR_LEN(opened_path), persistent); + zend_string_release(opened_path); } } } @@ -862,22 +876,18 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (lock_dbf) { /* replace the path info with the real path of the opened file */ pefree(info->path, persistent); - info->path = pestrdup(opened_path, persistent); + info->path = pestrndup(ZSTR_VAL(opened_path), ZSTR_LEN(opened_path), persistent); } /* now store the name of the lock */ - if (!persistent) { - info->lock.name = opened_path; - } else { - info->lock.name = pestrdup(opened_path, persistent); - efree(opened_path); - } + info->lock.name = pestrndup(ZSTR_VAL(opened_path), ZSTR_LEN(opened_path), persistent); + zend_string_release(opened_path); } } if (!lock_dbf) { efree(lock_name); } if (!info->lock.fp) { - dba_close(info TSRMLS_CC); + dba_close(info); /* stream operation already wrote an error message */ FREENOW; RETURN_FALSE; @@ -898,18 +908,18 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) info->fp = php_stream_open_wrapper(info->path, file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|persistent_flag, NULL); } if (!info->fp) { - dba_close(info TSRMLS_CC); + dba_close(info); /* stream operation already wrote an error message */ FREENOW; RETURN_FALSE; } if (hptr->flags & (DBA_NO_APPEND|DBA_CAST_AS_FD)) { - /* Needed because some systems do not allow to write to the original + /* Needed because some systems do not allow to write to the original * file contents with O_APPEND being set. */ if (SUCCESS != php_stream_cast(info->fp, PHP_STREAM_AS_FD, (void*)&info->fd, 1)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not cast stream"); - dba_close(info TSRMLS_CC); + php_error_docref(NULL, E_WARNING, "Could not cast stream"); + dba_close(info); FREENOW; RETURN_FALSE; #ifdef F_SETFL @@ -918,13 +928,13 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) fcntl(info->fd, F_SETFL, flags & ~O_APPEND); #endif } - + } } - if (error || hptr->open(info, &error TSRMLS_CC) != SUCCESS) { - dba_close(info TSRMLS_CC); - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Driver initialization failed for handler: %s%s%s", hptr->name, error?": ":"", error?error:""); + if (error || hptr->open(info, &error) != SUCCESS) { + dba_close(info); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "Driver initialization failed for handler: %s%s%s", hptr->name, error?": ":"", error?error:""); FREENOW; RETURN_FALSE; } @@ -934,19 +944,18 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) info->argv = NULL; if (persistent) { - zend_rsrc_list_entry new_le; + zval new_le; - Z_TYPE(new_le) = le_pdb; - new_le.ptr = info; - if (zend_hash_update(&EG(persistent_list), key, keylen+1, &new_le, sizeof(zend_rsrc_list_entry), NULL) == FAILURE) { - dba_close(info TSRMLS_CC); - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Could not register persistent resource"); + ZVAL_NEW_PERSISTENT_RES(&new_le, -1, info, le_pdb); + if (zend_hash_str_update(&EG(persistent_list), key, keylen, &new_le) == NULL) { + dba_close(info); + php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "Could not register persistent resource"); FREENOW; RETURN_FALSE; } } - ZEND_REGISTER_RESOURCE(return_value, info, (persistent ? le_pdb : le_db)); + RETVAL_RES(zend_register_resource(info, (persistent ? le_pdb : le_db))); FREENOW; } /* }}} */ @@ -975,13 +984,13 @@ PHP_FUNCTION(dba_close) zval *id; dba_info *info = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &id) == FAILURE) { return; } - DBA_FETCH_RESOURCE(info, &id); + DBA_FETCH_RESOURCE(info, id); - zend_list_delete(Z_RESVAL_P(id)); + zend_list_close(Z_RES_P(id)); } /* }}} */ @@ -991,7 +1000,7 @@ PHP_FUNCTION(dba_exists) { DBA_ID_GET2; - if(info->hnd->exists(info, key_str, key_len TSRMLS_CC) == SUCCESS) { + if(info->hnd->exists(info, key_str, key_len) == SUCCESS) { DBA_ID_DONE; RETURN_TRUE; } @@ -1011,31 +1020,33 @@ PHP_FUNCTION(dba_fetch) if (ac==3) { if (!strcmp(info->hnd->name, "cdb")) { if (skip < 0) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Handler %s accepts only skip values greater than or equal to zero, using skip=0", info->hnd->name); + php_error_docref(NULL, E_NOTICE, "Handler %s accepts only skip values greater than or equal to zero, using skip=0", info->hnd->name); skip = 0; } } else if (!strcmp(info->hnd->name, "inifile")) { - /* "-1" is compareable to 0 but allows a non restrictive + /* "-1" is compareable to 0 but allows a non restrictive * access which is fater. For example 'inifile' uses this * to allow faster access when the key was already found * using firstkey/nextkey. However explicitly setting the - * value to 0 ensures the first value. + * value to 0 ensures the first value. */ if (skip < -1) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Handler %s accepts only skip value -1 and greater, using skip=0", info->hnd->name); + php_error_docref(NULL, E_NOTICE, "Handler %s accepts only skip value -1 and greater, using skip=0", info->hnd->name); skip = 0; } } else { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Handler %s does not support optional skip parameter, the value will be ignored", info->hnd->name); - skip = 0; + php_error_docref(NULL, E_NOTICE, "Handler %s does not support optional skip parameter, the value will be ignored", info->hnd->name); + skip = 0; } } else { - skip = 0; + skip = 0; } - if((val = info->hnd->fetch(info, key_str, key_len, skip, &len TSRMLS_CC)) != NULL) { + if((val = info->hnd->fetch(info, key_str, key_len, skip, &len)) != NULL) { DBA_ID_DONE; - RETURN_STRINGL(val, len, 0); - } + RETVAL_STRINGL(val, len); + efree(val); + return; + } DBA_ID_DONE; RETURN_FALSE; } @@ -1047,26 +1058,26 @@ PHP_FUNCTION(dba_key_split) { zval *zkey; char *key, *name; - int key_len; + size_t key_len; if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "z", &zkey) == SUCCESS) { - if (Z_TYPE_P(zkey) == IS_NULL || (Z_TYPE_P(zkey) == IS_BOOL && !Z_LVAL_P(zkey))) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "z", &zkey) == SUCCESS) { + if (Z_TYPE_P(zkey) == IS_NULL || (Z_TYPE_P(zkey) == IS_FALSE)) { RETURN_BOOL(0); } } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { RETURN_BOOL(0); } array_init(return_value); if (key[0] == '[' && (name = strchr(key, ']')) != NULL) { - add_next_index_stringl(return_value, key+1, name - (key + 1), 1); - add_next_index_stringl(return_value, name+1, key_len - (name - key + 1), 1); + add_next_index_stringl(return_value, key+1, name - (key + 1)); + add_next_index_stringl(return_value, name+1, key_len - (name - key + 1)); } else { - add_next_index_stringl(return_value, "", 0, 1); - add_next_index_stringl(return_value, key, key_len, 1); + add_next_index_stringl(return_value, "", 0); + add_next_index_stringl(return_value, key, key_len); } } /* }}} */ @@ -1080,16 +1091,19 @@ PHP_FUNCTION(dba_firstkey) zval *id; dba_info *info = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &id) == FAILURE) { return; } - DBA_FETCH_RESOURCE(info, &id); + DBA_FETCH_RESOURCE(info, id); - fkey = info->hnd->firstkey(info, &len TSRMLS_CC); + fkey = info->hnd->firstkey(info, &len); - if (fkey) - RETURN_STRINGL(fkey, len, 0); + if (fkey) { + RETVAL_STRINGL(fkey, len); + efree(fkey); + return; + } RETURN_FALSE; } @@ -1104,16 +1118,19 @@ PHP_FUNCTION(dba_nextkey) zval *id; dba_info *info = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &id) == FAILURE) { return; } - DBA_FETCH_RESOURCE(info, &id); + DBA_FETCH_RESOURCE(info, id); - nkey = info->hnd->nextkey(info, &len TSRMLS_CC); + nkey = info->hnd->nextkey(info, &len); - if (nkey) - RETURN_STRINGL(nkey, len, 0); + if (nkey) { + RETVAL_STRINGL(nkey, len); + efree(nkey); + return; + } RETURN_FALSE; } @@ -1125,10 +1142,10 @@ PHP_FUNCTION(dba_nextkey) PHP_FUNCTION(dba_delete) { DBA_ID_GET2; - + DBA_WRITE_CHECK_WITH_ID; - - if(info->hnd->delete(info, key_str, key_len TSRMLS_CC) == SUCCESS) + + if(info->hnd->delete(info, key_str, key_len) == SUCCESS) { DBA_ID_DONE; RETURN_TRUE; @@ -1139,7 +1156,7 @@ PHP_FUNCTION(dba_delete) /* }}} */ /* {{{ proto bool dba_insert(string key, string value, resource handle) - If not inifile: Insert value as key, return false, if key exists already + If not inifile: Insert value as key, return false, if key exists already If inifile: Add vakue as key (next instance of key) */ PHP_FUNCTION(dba_insert) { @@ -1163,15 +1180,15 @@ PHP_FUNCTION(dba_optimize) zval *id; dba_info *info = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &id) == FAILURE) { return; } - DBA_FETCH_RESOURCE(info, &id); + DBA_FETCH_RESOURCE(info, id); DBA_WRITE_CHECK; - if (info->hnd->optimize(info TSRMLS_CC) == SUCCESS) { + if (info->hnd->optimize(info) == SUCCESS) { RETURN_TRUE; } @@ -1186,13 +1203,13 @@ PHP_FUNCTION(dba_sync) zval *id; dba_info *info = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &id) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &id) == FAILURE) { return; } - DBA_FETCH_RESOURCE(info, &id); + DBA_FETCH_RESOURCE(info, id); - if (info->hnd->sync(info TSRMLS_CC) == SUCCESS) { + if (info->hnd->sync(info) == SUCCESS) { RETURN_TRUE; } @@ -1207,7 +1224,7 @@ PHP_FUNCTION(dba_handlers) dba_handler *hptr; zend_bool full_info = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &full_info) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &full_info) == FAILURE) { RETURN_FALSE; } @@ -1215,9 +1232,12 @@ PHP_FUNCTION(dba_handlers) for(hptr = handler; hptr->name; hptr++) { if (full_info) { - add_assoc_string(return_value, hptr->name, hptr->info(hptr, NULL TSRMLS_CC), 0); + // TODO: avoid reallocation ??? + char *str = hptr->info(hptr, NULL); + add_assoc_string(return_value, hptr->name, str); + efree(str); } else { - add_next_index_string(return_value, hptr->name, 1); + add_next_index_string(return_value, hptr->name); } } } @@ -1227,8 +1247,8 @@ PHP_FUNCTION(dba_handlers) List opened databases */ PHP_FUNCTION(dba_list) { - ulong numitems, i; - zend_rsrc_list_entry *le; + zend_ulong numitems, i; + zend_resource *le; dba_info *info; if (zend_parse_parameters_none() == FAILURE) { @@ -1239,12 +1259,12 @@ PHP_FUNCTION(dba_list) numitems = zend_hash_next_free_element(&EG(regular_list)); for (i=1; i<numitems; i++) { - if (zend_hash_index_find(&EG(regular_list), i, (void **) &le)==FAILURE) { + if ((le = zend_hash_index_find_ptr(&EG(regular_list), i)) == NULL) { continue; } - if (Z_TYPE_P(le) == le_db || Z_TYPE_P(le) == le_pdb) { + if (le->type == le_db || le->type == le_pdb) { info = (dba_info *)(le->ptr); - add_index_string(return_value, i, info->path, 1); + add_index_string(return_value, i, info->path); } } } diff --git a/ext/dba/dba.dsp b/ext/dba/dba.dsp deleted file mode 100644 index ddfd1485a9..0000000000 --- a/ext/dba/dba.dsp +++ /dev/null @@ -1,213 +0,0 @@ -# Microsoft Developer Studio Project File - Name="dba" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=dba - Win32 Debug_TS Berkeley DB3
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "dba.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "dba.mak" CFG="dba - Win32 Debug_TS Berkeley DB3"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "dba - Win32 Release_TS Berkeley DB3" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "dba - Win32 Debug_TS Berkeley DB3" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "dba - Win32 Release_TS Berkeley DB3"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS"
-# PROP BASE Intermediate_Dir "Release_TS"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_DB3=1 /D DB3_INCLUDE_FILE="db.h" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=0 /D DBA_DB3=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_FLATFILE=1 /D DBA_CDB=1 /D DBA_CDB_MAKE=1 /D DBA_CDB_BUILTIN=1 /D DBA_INIFILE=1 /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "NDEBUG"
-# ADD RSC /l 0x407 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 php5ts.lib libdb31s.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_dba.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-# ADD LINK32 php5ts.lib libdb31s.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_dba.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-
-!ELSEIF "$(CFG)" == "dba - Win32 Debug_TS Berkeley DB3"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D "DBA_DB3" /D DB3_INCLUDE_FILE="db.h" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "DBA_DB3" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_FLATFILE=1 /D DBA_CDB=1 /D DBA_CDB_MAKE=1 /D DBA_CDB_BUILTIN=1 /D DBA_INIFILE=1 /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "_DEBUG"
-# ADD RSC /l 0x407 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 php5ts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_dba.dll" /pdbtype:sept /libpath:"..\..\Debug_TS"
-# ADD LINK32 php5ts_debug.lib libdb31s.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_dba.dll" /pdbtype:sept /libpath:"..\..\Debug_TS"
-
-!ENDIF
-
-# Begin Target
-
-# Name "dba - Win32 Release_TS Berkeley DB3"
-# Name "dba - Win32 Debug_TS Berkeley DB3"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\libcdb\cdb.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\libcdb\cdb_make.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_cdb.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_db2.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_db3.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_dbm.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_flatfile.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_gdbm.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_inifile.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_ndbm.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\libflatfile\flatfile.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\libinifile\inifile.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\libcdb\uint32.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\libcdb\cdb.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\libcdb\cdb_make.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\libflatfile\flatfile.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_cdb.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_db2.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_db3.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_dba.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_dbm.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_flatfile.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_gdbm.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_inifile.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_ndbm.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\libcdb\uint32.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\libinifile\inifile.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/ext/dba/dba_cdb.c b/ext/dba/dba_cdb.c index 63a0c9609d..7e2c51ddc0 100644 --- a/ext/dba/dba_cdb.c +++ b/ext/dba/dba_cdb.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -72,7 +72,7 @@ DBA_OPEN_FUNC(cdb) dba_info *pinfo = (dba_info *) info; switch (info->mode) { - case DBA_READER: + case DBA_READER: #if DBA_CDB_BUILTIN make = 0; file = info->fp; @@ -94,7 +94,7 @@ DBA_OPEN_FUNC(cdb) *error = "Update operations are not supported"; return FAILURE; /* not supported */ #endif - default: + default: *error = "Currently not supported"; return FAILURE; } @@ -104,16 +104,16 @@ DBA_OPEN_FUNC(cdb) #if DBA_CDB_BUILTIN if (make) { - cdb_make_start(&cdb->m, file TSRMLS_CC); + cdb_make_start(&cdb->m, file); } else { - cdb_init(&cdb->c, file TSRMLS_CC); + cdb_init(&cdb->c, file); } cdb->make = make; #else cdb_init(&cdb->c, file); #endif cdb->file = file; - + pinfo->dbf = cdb; return SUCCESS; } @@ -125,9 +125,9 @@ DBA_CLOSE_FUNC(cdb) /* cdb_free does not close associated file */ #if DBA_CDB_BUILTIN if (cdb->make) { - cdb_make_finish(&cdb->m TSRMLS_CC); + cdb_make_finish(&cdb->m); } else { - cdb_free(&cdb->c TSRMLS_CC); + cdb_free(&cdb->c); } #else cdb_free(&cdb->c); @@ -137,9 +137,9 @@ DBA_CLOSE_FUNC(cdb) } #if DBA_CDB_BUILTIN -# define php_cdb_read(cdb, buf, len, pos) cdb_read(cdb, buf, len, pos TSRMLS_CC) -# define php_cdb_findnext(cdb, key, len) cdb_findnext(cdb, key, len TSRMLS_CC) -# define php_cdb_find(cdb, key, len) cdb_find(cdb, key, len TSRMLS_CC) +# define php_cdb_read(cdb, buf, len, pos) cdb_read(cdb, buf, len, pos) +# define php_cdb_findnext(cdb, key, len) cdb_findnext(cdb, key, len) +# define php_cdb_find(cdb, key, len) cdb_find(cdb, key, len) #else # define php_cdb_read(cdb, buf, len, pos) cdb_read(cdb, buf, len, pos) # define php_cdb_findnext(cdb, key, len) cdb_findnext(cdb, key, len) @@ -151,7 +151,7 @@ DBA_FETCH_FUNC(cdb) CDB_INFO; unsigned int len; char *new_entry = NULL; - + #if DBA_CDB_BUILTIN if (cdb->make) return NULL; /* database was opened writeonly */ @@ -164,16 +164,16 @@ DBA_FETCH_FUNC(cdb) } len = cdb_datalen(&cdb->c); new_entry = safe_emalloc(len, 1, 1); - + if (php_cdb_read(&cdb->c, new_entry, len, cdb_datapos(&cdb->c)) == -1) { efree(new_entry); return NULL; } new_entry[len] = 0; - if (newlen) + if (newlen) *newlen = len; } - + return new_entry; } @@ -186,7 +186,7 @@ DBA_UPDATE_FUNC(cdb) return FAILURE; /* database was opened readonly */ if (!mode) return FAILURE; /* cdb_make dosn't know replace */ - if (cdb_make_add(&cdb->m, key, keylen, val, vallen TSRMLS_CC) != -1) + if (cdb_make_add(&cdb->m, key, keylen, val, vallen) != -1) return SUCCESS; #endif return FAILURE; @@ -222,15 +222,15 @@ DBA_DELETE_FUNC(cdb) if (cdb_file_read(cdb->file, buf, n) < n) return NULL; \ } while (0) -/* {{{ cdb_file_lseek +/* {{{ cdb_file_lseek php_stream_seek does not return actual position */ #if DBA_CDB_BUILTIN -int cdb_file_lseek(php_stream *fp, off_t offset, int whence TSRMLS_DC) { +int cdb_file_lseek(php_stream *fp, off_t offset, int whence) { php_stream_seek(fp, offset, whence); return php_stream_tell(fp); } #else -int cdb_file_lseek(int fd, off_t offset, int whence TSRMLS_DC) { +int cdb_file_lseek(int fd, off_t offset, int whence) { return lseek(fd, offset, whence); } #endif @@ -238,7 +238,7 @@ int cdb_file_lseek(int fd, off_t offset, int whence TSRMLS_DC) { #define CSEEK(n) do { \ if (n >= cdb->eod) return NULL; \ - if (cdb_file_lseek(cdb->file, (off_t)n, SEEK_SET TSRMLS_CC) != (off_t) n) return NULL; \ + if (cdb_file_lseek(cdb->file, (off_t)n, SEEK_SET) != (off_t) n) return NULL; \ } while (0) @@ -257,13 +257,13 @@ DBA_FIRSTKEY_FUNC(cdb) cdb->eod = -1; CSEEK(0); CREAD(4); - + /* Total length of file in bytes */ uint32_unpack(buf, &cdb->eod); - + CSEEK(2048); CREAD(8); - + /* The first four bytes contain the length of the key */ uint32_unpack(buf, &klen); uint32_unpack(buf + 4, &dlen); @@ -279,7 +279,7 @@ DBA_FIRSTKEY_FUNC(cdb) /* header + klenlen + dlenlen + klen + dlen */ cdb->pos = 2048 + 4 + 4 + klen + dlen; - + return key; } @@ -299,7 +299,7 @@ DBA_NEXTKEY_FUNC(cdb) CREAD(8); uint32_unpack(buf, &klen); uint32_unpack(buf + 4, &dlen); - + key = safe_emalloc(klen, 1, 1); if (cdb_file_read(cdb->file, key, klen) < klen) { efree(key); @@ -308,9 +308,9 @@ DBA_NEXTKEY_FUNC(cdb) key[klen] = '\0'; if (newlen) *newlen = klen; } - + cdb->pos += 8 + klen + dlen; - + return key; } diff --git a/ext/dba/dba_db1.c b/ext/dba/dba_db1.c index 393137733c..4e3691f9cb 100644 --- a/ext/dba/dba_db1.c +++ b/ext/dba/dba_db1.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -51,8 +51,8 @@ DBA_OPEN_FUNC(db1) int filemode = 0644; if (info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); + convert_to_long_ex(&info->argv[0]); + filemode = Z_LVAL(info->argv[0]); } gmode = 0; diff --git a/ext/dba/dba_db2.c b/ext/dba/dba_db2.c index 3c30ab4bdb..71c323d6e8 100644 --- a/ext/dba/dba_db2.c +++ b/ext/dba/dba_db2.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -60,11 +60,11 @@ DBA_OPEN_FUNC(db2) type = info->mode == DBA_READER ? DB_UNKNOWN : info->mode == DBA_TRUNC ? DB_BTREE : s ? DB_BTREE : DB_UNKNOWN; - + gmode = info->mode == DBA_READER ? DB_RDONLY : - (info->mode == DBA_CREAT && s) ? DB_CREATE : + (info->mode == DBA_CREAT && s) ? DB_CREATE : (info->mode == DBA_CREAT && !s) ? 0 : - info->mode == DBA_WRITER ? 0 : + info->mode == DBA_WRITER ? 0 : info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1; if (gmode == -1) { @@ -72,8 +72,8 @@ DBA_OPEN_FUNC(db2) } if (info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); + convert_to_long_ex(&info->argv[0]); + filemode = Z_LVAL(info->argv[0]); } if (db_open(info->path, type, gmode, filemode, NULL, NULL, &dbp)) { @@ -89,8 +89,8 @@ DBA_OPEN_FUNC(db2) DBA_CLOSE_FUNC(db2) { DB2_DATA; - - if (dba->cursor) + + if (dba->cursor) dba->cursor->c_close(dba->cursor); dba->dbp->close(dba->dbp, 0); pefree(dba, info->flags&DBA_PERSISTENT); @@ -101,7 +101,7 @@ DBA_FETCH_FUNC(db2) DBT gval = {0}; DB2_DATA; DB2_GKEY; - + if (dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { return NULL; } @@ -115,11 +115,11 @@ DBA_UPDATE_FUNC(db2) DBT gval = {0}; DB2_DATA; DB2_GKEY; - + gval.data = (char *) val; gval.size = vallen; - if (dba->dbp->put(dba->dbp, NULL, &gkey, &gval, + if (dba->dbp->put(dba->dbp, NULL, &gkey, &gval, mode == 1 ? DB_NOOVERWRITE : 0)) { return FAILURE; } @@ -131,7 +131,7 @@ DBA_EXISTS_FUNC(db2) DBT gval = {0}; DB2_DATA; DB2_GKEY; - + if (dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { return FAILURE; } @@ -164,7 +164,7 @@ DBA_FIRSTKEY_FUNC(db2) } /* we should introduce something like PARAM_PASSTHRU... */ - return dba_nextkey_db2(info, newlen TSRMLS_CC); + return dba_nextkey_db2(info, newlen); } DBA_NEXTKEY_FUNC(db2) diff --git a/ext/dba/dba_db3.c b/ext/dba/dba_db3.c index 2d0ad86873..0bf055597a 100644 --- a/ext/dba/dba_db3.c +++ b/ext/dba/dba_db3.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -35,11 +35,14 @@ #include <db.h> #endif -static void php_dba_db3_errcall_fcn(const char *errpfx, char *msg) +static void php_dba_db3_errcall_fcn( +#if (DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3)) + const DB_ENV *dbenv, +#endif + const char *errpfx, const char *msg) { - TSRMLS_FETCH(); - - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s%s", errpfx?errpfx:"", msg); + + php_error_docref(NULL, E_NOTICE, "%s%s", errpfx?errpfx:"", msg); } #define DB3_DATA dba_db3_data *dba = info->dbf @@ -69,11 +72,11 @@ DBA_OPEN_FUNC(db3) type = info->mode == DBA_READER ? DB_UNKNOWN : info->mode == DBA_TRUNC ? DB_BTREE : s ? DB_BTREE : DB_UNKNOWN; - + gmode = info->mode == DBA_READER ? DB_RDONLY : - (info->mode == DBA_CREAT && s) ? DB_CREATE : + (info->mode == DBA_CREAT && s) ? DB_CREATE : (info->mode == DBA_CREAT && !s) ? 0 : - info->mode == DBA_WRITER ? 0 : + info->mode == DBA_WRITER ? 0 : info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1; if (gmode == -1) { @@ -81,8 +84,8 @@ DBA_OPEN_FUNC(db3) } if (info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); + convert_to_long_ex(&info->argv[0]); + filemode = Z_LVAL(info->argv[0]); } #ifdef DB_FCNTL_LOCKING @@ -91,14 +94,19 @@ DBA_OPEN_FUNC(db3) if ((err=db_create(&dbp, NULL, 0)) == 0) { dbp->set_errcall(dbp, php_dba_db3_errcall_fcn); - if ((err=dbp->open(dbp, info->path, NULL, type, gmode, filemode)) == 0) { + if( +#if (DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)) + (err=dbp->open(dbp, 0, info->path, NULL, type, gmode, filemode)) == 0) { +#else + (err=dbp->open(dbp, info->path, NULL, type, gmode, filemode)) == 0) { +#endif dba_db3_data *data; data = pemalloc(sizeof(*data), info->flags&DBA_PERSISTENT); data->dbp = dbp; data->cursor = NULL; info->dbf = data; - + return SUCCESS; } else { dbp->close(dbp, 0); @@ -114,7 +122,7 @@ DBA_OPEN_FUNC(db3) DBA_CLOSE_FUNC(db3) { DB3_DATA; - + if (dba->cursor) dba->cursor->c_close(dba->cursor); dba->dbp->close(dba->dbp, 0); pefree(dba, info->flags&DBA_PERSISTENT); @@ -126,7 +134,7 @@ DBA_FETCH_FUNC(db3) char *new = NULL; DB3_DATA; DB3_GKEY; - + memset(&gval, 0, sizeof(gval)); if (!dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { if (newlen) *newlen = gval.size; @@ -140,12 +148,12 @@ DBA_UPDATE_FUNC(db3) DBT gval; DB3_DATA; DB3_GKEY; - + memset(&gval, 0, sizeof(gval)); gval.data = (char *) val; gval.size = vallen; - if (!dba->dbp->put(dba->dbp, NULL, &gkey, &gval, + if (!dba->dbp->put(dba->dbp, NULL, &gkey, &gval, mode == 1 ? DB_NOOVERWRITE : 0)) { return SUCCESS; } @@ -157,7 +165,7 @@ DBA_EXISTS_FUNC(db3) DBT gval; DB3_DATA; DB3_GKEY; - + memset(&gval, 0, sizeof(gval)); if (!dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { return SUCCESS; @@ -187,7 +195,7 @@ DBA_FIRSTKEY_FUNC(db3) } /* we should introduce something like PARAM_PASSTHRU... */ - return dba_nextkey_db3(info, newlen TSRMLS_CC); + return dba_nextkey_db3(info, newlen); } DBA_NEXTKEY_FUNC(db3) @@ -195,7 +203,7 @@ DBA_NEXTKEY_FUNC(db3) DB3_DATA; DBT gkey, gval; char *nkey = NULL; - + memset(&gkey, 0, sizeof(gkey)); memset(&gval, 0, sizeof(gval)); diff --git a/ext/dba/dba_db4.c b/ext/dba/dba_db4.c index 2dfb33a485..f48bd1b68d 100644 --- a/ext/dba/dba_db4.c +++ b/ext/dba/dba_db4.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -38,17 +38,16 @@ static void php_dba_db4_errcall_fcn( #if (DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3)) - const DB_ENV *dbenv, + const DB_ENV *dbenv, #endif const char *errpfx, const char *msg) { - TSRMLS_FETCH(); #if (DB_VERSION_MAJOR == 5 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 8)) /* Bug 51086, Berkeley DB 4.8.26 */ /* This code suppresses a BDB 4.8+ error message, thus keeping PHP test compatibility */ { - const char *function = get_active_function_name(TSRMLS_C); + const char *function = get_active_function_name(); if (function && (!strcmp(function,"dba_popen") || !strcmp(function,"dba_open")) && (!strncmp(msg, "fop_read_meta", sizeof("fop_read_meta")-1) || !strncmp(msg, "BDB0004 fop_read_meta", sizeof("BDB0004 fop_read_meta")-1))) { @@ -57,7 +56,7 @@ static void php_dba_db4_errcall_fcn( } #endif - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s%s", errpfx?errpfx:"", msg); + php_error_docref(NULL, E_NOTICE, "%s%s", errpfx?errpfx:"", msg); } #define DB4_DATA dba_db4_data *dba = info->dbf @@ -88,11 +87,11 @@ DBA_OPEN_FUNC(db4) type = info->mode == DBA_READER ? DB_UNKNOWN : info->mode == DBA_TRUNC ? DB_BTREE : s ? DB_BTREE : DB_UNKNOWN; - + gmode = info->mode == DBA_READER ? DB_RDONLY : - (info->mode == DBA_CREAT && s) ? DB_CREATE : + (info->mode == DBA_CREAT && s) ? DB_CREATE : (info->mode == DBA_CREAT && !s) ? 0 : - info->mode == DBA_WRITER ? 0 : + info->mode == DBA_WRITER ? 0 : info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1; #else if (!s && !check_stat.st_size) { @@ -102,10 +101,10 @@ DBA_OPEN_FUNC(db4) type = info->mode == DBA_READER ? DB_UNKNOWN : (info->mode == DBA_TRUNC || info->mode == DBA_CREAT) ? DB_BTREE : s ? DB_BTREE : DB_UNKNOWN; - + gmode = info->mode == DBA_READER ? DB_RDONLY : - info->mode == DBA_CREAT ? DB_CREATE : - info->mode == DBA_WRITER ? 0 : + info->mode == DBA_CREAT ? DB_CREATE : + info->mode == DBA_WRITER ? 0 : info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1; #endif @@ -118,8 +117,8 @@ DBA_OPEN_FUNC(db4) } if (info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); + convert_to_long_ex(&info->argv[0]); + filemode = Z_LVAL(info->argv[0]); } if ((err=db_create(&dbp, NULL, 0)) == 0) { @@ -136,7 +135,7 @@ DBA_OPEN_FUNC(db4) data->dbp = dbp; data->cursor = NULL; info->dbf = data; - + return SUCCESS; } else { dbp->close(dbp, 0); @@ -152,7 +151,7 @@ DBA_OPEN_FUNC(db4) DBA_CLOSE_FUNC(db4) { DB4_DATA; - + if (dba->cursor) dba->cursor->c_close(dba->cursor); dba->dbp->close(dba->dbp, 0); pefree(dba, info->flags&DBA_PERSISTENT); @@ -164,7 +163,7 @@ DBA_FETCH_FUNC(db4) char *new = NULL; DB4_DATA; DB4_GKEY; - + memset(&gval, 0, sizeof(gval)); if (info->flags & DBA_PERSISTENT) { gval.flags |= DB_DBT_MALLOC; @@ -184,12 +183,12 @@ DBA_UPDATE_FUNC(db4) DBT gval; DB4_DATA; DB4_GKEY; - + memset(&gval, 0, sizeof(gval)); gval.data = (char *) val; gval.size = vallen; - if (!dba->dbp->put(dba->dbp, NULL, &gkey, &gval, + if (!dba->dbp->put(dba->dbp, NULL, &gkey, &gval, mode == 1 ? DB_NOOVERWRITE : 0)) { return SUCCESS; } @@ -201,9 +200,9 @@ DBA_EXISTS_FUNC(db4) DBT gval; DB4_DATA; DB4_GKEY; - + memset(&gval, 0, sizeof(gval)); - + if (info->flags & DBA_PERSISTENT) { gval.flags |= DB_DBT_MALLOC; } @@ -239,7 +238,7 @@ DBA_FIRSTKEY_FUNC(db4) } /* we should introduce something like PARAM_PASSTHRU... */ - return dba_nextkey_db4(info, newlen TSRMLS_CC); + return dba_nextkey_db4(info, newlen); } DBA_NEXTKEY_FUNC(db4) @@ -247,7 +246,7 @@ DBA_NEXTKEY_FUNC(db4) DB4_DATA; DBT gkey, gval; char *nkey = NULL; - + memset(&gkey, 0, sizeof(gkey)); memset(&gval, 0, sizeof(gval)); diff --git a/ext/dba/dba_dbm.c b/ext/dba/dba_dbm.c index 01087f8af0..c7fc04e56f 100644 --- a/ext/dba/dba_dbm.c +++ b/ext/dba/dba_dbm.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -60,10 +60,10 @@ DBA_OPEN_FUNC(dbm) int filemode = 0644; if(info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); + convert_to_long_ex(&info->argv[0]); + filemode = Z_LVAL(info->argv[0]); } - + if(info->mode == DBA_TRUNC) { char buf[MAXPATHLEN]; @@ -123,7 +123,7 @@ DBA_UPDATE_FUNC(dbm) gval.dptr = (char *) val; gval.dsize = vallen; - + return (store(gkey, gval) == -1 ? FAILURE : SUCCESS); } @@ -131,7 +131,7 @@ DBA_EXISTS_FUNC(dbm) { datum gval; DBM_GKEY; - + gval = fetch(gkey); if(gval.dptr) { return SUCCESS; @@ -166,9 +166,9 @@ DBA_NEXTKEY_FUNC(dbm) DBM_DATA; datum gkey; char *nkey = NULL; - + if(!dba->nextkey.dptr) return NULL; - + gkey = nextkey(dba->nextkey); if(gkey.dptr) { if(newlen) *newlen = gkey.dsize; @@ -195,7 +195,7 @@ DBA_INFO_FUNC(dbm) #if DBA_GDBM if (!strcmp(DBM_VERSION, "GDBM")) { - return dba_info_gdbm(hnd, info TSRMLS_CC); + return dba_info_gdbm(hnd, info); } #endif return estrdup(DBM_VERSION); diff --git a/ext/dba/dba_flatfile.c b/ext/dba/dba_flatfile.c index 993948474d..6cab2aebaf 100644 --- a/ext/dba/dba_flatfile.c +++ b/ext/dba/dba_flatfile.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -67,7 +67,7 @@ DBA_FETCH_FUNC(flatfile) FLATFILE_DATA; FLATFILE_GKEY; - gval = flatfile_fetch(dba, gkey TSRMLS_CC); + gval = flatfile_fetch(dba, gkey); if (gval.dptr) { if (newlen) { *newlen = gval.dsize; @@ -86,17 +86,17 @@ DBA_UPDATE_FUNC(flatfile) FLATFILE_GKEY; gval.dptr = (char *) val; gval.dsize = vallen; - - switch(flatfile_store(dba, gkey, gval, mode==1 ? FLATFILE_INSERT : FLATFILE_REPLACE TSRMLS_CC)) { + + switch(flatfile_store(dba, gkey, gval, mode==1 ? FLATFILE_INSERT : FLATFILE_REPLACE)) { case 0: return SUCCESS; case 1: return FAILURE; case -1: - php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible"); + php_error_docref1(NULL, key, E_WARNING, "Operation not possible"); return FAILURE; default: - php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "Unknown return value"); + php_error_docref2(NULL, key, val, E_WARNING, "Unknown return value"); return FAILURE; } } @@ -106,8 +106,8 @@ DBA_EXISTS_FUNC(flatfile) datum gval; FLATFILE_DATA; FLATFILE_GKEY; - - gval = flatfile_fetch(dba, gkey TSRMLS_CC); + + gval = flatfile_fetch(dba, gkey); if (gval.dptr) { efree(gval.dptr); return SUCCESS; @@ -119,7 +119,7 @@ DBA_DELETE_FUNC(flatfile) { FLATFILE_DATA; FLATFILE_GKEY; - return(flatfile_delete(dba, gkey TSRMLS_CC) == -1 ? FAILURE : SUCCESS); + return(flatfile_delete(dba, gkey) == -1 ? FAILURE : SUCCESS); } DBA_FIRSTKEY_FUNC(flatfile) @@ -129,7 +129,7 @@ DBA_FIRSTKEY_FUNC(flatfile) if (dba->nextkey.dptr) { efree(dba->nextkey.dptr); } - dba->nextkey = flatfile_firstkey(dba TSRMLS_CC); + dba->nextkey = flatfile_firstkey(dba); if (dba->nextkey.dptr) { if (newlen) { *newlen = dba->nextkey.dsize; @@ -142,15 +142,15 @@ DBA_FIRSTKEY_FUNC(flatfile) DBA_NEXTKEY_FUNC(flatfile) { FLATFILE_DATA; - + if (!dba->nextkey.dptr) { return NULL; } - + if (dba->nextkey.dptr) { efree(dba->nextkey.dptr); } - dba->nextkey = flatfile_nextkey(dba TSRMLS_CC); + dba->nextkey = flatfile_nextkey(dba); if (dba->nextkey.dptr) { if (newlen) { *newlen = dba->nextkey.dsize; diff --git a/ext/dba/dba_gdbm.c b/ext/dba/dba_gdbm.c index 4bd6f5d748..3e8e09b55f 100644 --- a/ext/dba/dba_gdbm.c +++ b/ext/dba/dba_gdbm.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -46,20 +46,20 @@ DBA_OPEN_FUNC(gdbm) int filemode = 0644; gmode = info->mode == DBA_READER ? GDBM_READER : - info->mode == DBA_WRITER ? GDBM_WRITER : - info->mode == DBA_CREAT ? GDBM_WRCREAT : + info->mode == DBA_WRITER ? GDBM_WRITER : + info->mode == DBA_CREAT ? GDBM_WRCREAT : info->mode == DBA_TRUNC ? GDBM_NEWDB : -1; - - if(gmode == -1) + + if(gmode == -1) return FAILURE; /* not possible */ if(info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); + convert_to_long_ex(&info->argv[0]); + filemode = Z_LVAL(info->argv[0]); } dbf = gdbm_open(info->path, 0, gmode, filemode, NULL); - + if(dbf) { info->dbf = pemalloc(sizeof(dba_gdbm_data), info->flags&DBA_PERSISTENT); memset(info->dbf, 0, sizeof(dba_gdbm_data)); @@ -73,7 +73,7 @@ DBA_OPEN_FUNC(gdbm) DBA_CLOSE_FUNC(gdbm) { GDBM_DATA; - + if(dba->nextkey.dptr) free(dba->nextkey.dptr); gdbm_close(dba->dbf); pefree(dba, info->flags&DBA_PERSISTENT); @@ -110,10 +110,10 @@ DBA_UPDATE_FUNC(gdbm) case 1: return FAILURE; case -1: - php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", gdbm_strerror(gdbm_errno)); + php_error_docref2(NULL, key, val, E_WARNING, "%s", gdbm_strerror(gdbm_errno)); return FAILURE; default: - php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "Unknown return value"); + php_error_docref2(NULL, key, val, E_WARNING, "Unknown return value"); return FAILURE; } } @@ -130,7 +130,7 @@ DBA_DELETE_FUNC(gdbm) { GDBM_DATA; GDBM_GKEY; - + return gdbm_delete(dba->dbf, gkey) == -1 ? FAILURE : SUCCESS; } @@ -143,7 +143,7 @@ DBA_FIRSTKEY_FUNC(gdbm) if(dba->nextkey.dptr) { free(dba->nextkey.dptr); } - + gkey = gdbm_firstkey(dba->dbf); if(gkey.dptr) { key = estrndup(gkey.dptr, gkey.dsize); @@ -162,7 +162,7 @@ DBA_NEXTKEY_FUNC(gdbm) datum gkey; if(!dba->nextkey.dptr) return NULL; - + gkey = gdbm_nextkey(dba->dbf, dba->nextkey); free(dba->nextkey.dptr); if(gkey.dptr) { @@ -182,7 +182,7 @@ DBA_OPTIMIZE_FUNC(gdbm) return SUCCESS; } -DBA_SYNC_FUNC(gdbm) +DBA_SYNC_FUNC(gdbm) { GDBM_DATA; diff --git a/ext/dba/dba_inifile.c b/ext/dba/dba_inifile.c index f0a74fe701..afd1b2b6f6 100644 --- a/ext/dba/dba_inifile.c +++ b/ext/dba/dba_inifile.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -42,7 +42,7 @@ #define INIFILE_GKEY \ key_type ini_key; \ if (!key) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "No key specified"); \ + php_error_docref(NULL, E_WARNING, "No key specified"); \ return 0; \ } \ ini_key = inifile_key_split((char*)key) /* keylen not needed here */ @@ -52,7 +52,7 @@ DBA_OPEN_FUNC(inifile) { - info->dbf = inifile_alloc(info->fp, info->mode == DBA_READER, info->flags&DBA_PERSISTENT TSRMLS_CC); + info->dbf = inifile_alloc(info->fp, info->mode == DBA_READER, info->flags&DBA_PERSISTENT); return info->dbf ? SUCCESS : FAILURE; } @@ -71,7 +71,7 @@ DBA_FETCH_FUNC(inifile) INIFILE_DATA; INIFILE_GKEY; - ini_val = inifile_fetch(dba, &ini_key, skip TSRMLS_CC); + ini_val = inifile_fetch(dba, &ini_key, skip); *newlen = ini_val.value ? strlen(ini_val.value) : 0; INIFILE_DONE; return ini_val.value; @@ -84,18 +84,18 @@ DBA_UPDATE_FUNC(inifile) INIFILE_DATA; INIFILE_GKEY; - + ini_val.value = val; - + if (mode == 1) { - res = inifile_append(dba, &ini_key, &ini_val TSRMLS_CC); + res = inifile_append(dba, &ini_key, &ini_val); } else { - res = inifile_replace(dba, &ini_key, &ini_val TSRMLS_CC); + res = inifile_replace(dba, &ini_key, &ini_val); } INIFILE_DONE; switch(res) { case -1: - php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible"); + php_error_docref1(NULL, key, E_WARNING, "Operation not possible"); return FAILURE; default: case 0: @@ -111,8 +111,8 @@ DBA_EXISTS_FUNC(inifile) INIFILE_DATA; INIFILE_GKEY; - - ini_val = inifile_fetch(dba, &ini_key, 0 TSRMLS_CC); + + ini_val = inifile_fetch(dba, &ini_key, 0); INIFILE_DONE; if (ini_val.value) { inifile_val_free(&ini_val); @@ -124,21 +124,22 @@ DBA_EXISTS_FUNC(inifile) DBA_DELETE_FUNC(inifile) { int res; + zend_bool found = 0; INIFILE_DATA; INIFILE_GKEY; - res = inifile_delete(dba, &ini_key TSRMLS_CC); + res = inifile_delete_ex(dba, &ini_key, &found); INIFILE_DONE; - return (res == -1 ? FAILURE : SUCCESS); + return (res == -1 || !found ? FAILURE : SUCCESS); } DBA_FIRSTKEY_FUNC(inifile) { INIFILE_DATA; - if (inifile_firstkey(dba TSRMLS_CC)) { + if (inifile_firstkey(dba)) { char *result = inifile_key_string(&dba->curr.key); *newlen = strlen(result); return result; @@ -150,12 +151,12 @@ DBA_FIRSTKEY_FUNC(inifile) DBA_NEXTKEY_FUNC(inifile) { INIFILE_DATA; - + if (!dba->curr.key.group && !dba->curr.key.name) { return NULL; } - if (inifile_nextkey(dba TSRMLS_CC)) { + if (inifile_nextkey(dba)) { char *result = inifile_key_string(&dba->curr.key); *newlen = strlen(result); return result; diff --git a/ext/dba/dba_ndbm.c b/ext/dba/dba_ndbm.c index 9e56cb57b6..d0ad35b8c4 100644 --- a/ext/dba/dba_ndbm.c +++ b/ext/dba/dba_ndbm.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -59,12 +59,12 @@ DBA_OPEN_FUNC(ndbm) } if(info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); + convert_to_long_ex(&info->argv[0]); + filemode = Z_LVAL(info->argv[0]); } dbf = dbm_open(info->path, gmode, filemode); - + pinfo->dbf = dbf; return SUCCESS; } diff --git a/ext/dba/dba_qdbm.c b/ext/dba/dba_qdbm.c index 9d963871c1..472e4abb15 100644 --- a/ext/dba/dba_qdbm.c +++ b/ext/dba/dba_qdbm.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -102,7 +102,7 @@ DBA_UPDATE_FUNC(qdbm) } if (dpecode != DP_EKEEP) { - php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", dperrmsg(dpecode)); + php_error_docref2(NULL, key, val, E_WARNING, "%s", dperrmsg(dpecode)); } return FAILURE; diff --git a/ext/dba/dba_tcadb.c b/ext/dba/dba_tcadb.c index 6c1c18ffac..99bf39da85 100644 --- a/ext/dba/dba_tcadb.c +++ b/ext/dba/dba_tcadb.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -34,7 +34,7 @@ #define TCADB_DATA dba_tcadb_data *dba = info->dbf typedef struct { - TCADB *tcadb; + TCADB *tcadb; } dba_tcadb_data; DBA_OPEN_FUNC(tcadb) @@ -115,14 +115,14 @@ DBA_UPDATE_FUNC(tcadb) return FAILURE; } } - + result = tcadbput(dba->tcadb, key, keylen, val, vallen); if (result) { return SUCCESS; } - php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "Error updating data"); + php_error_docref2(NULL, key, val, E_WARNING, "Error updating data"); return FAILURE; } diff --git a/ext/dba/libcdb/cdb.c b/ext/dba/libcdb/cdb.c index 2b0c194e65..72ecea30ff 100644 --- a/ext/dba/libcdb/cdb.c +++ b/ext/dba/libcdb/cdb.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -43,18 +43,18 @@ #endif /* {{{ cdb_match */ -static int cdb_match(struct cdb *c, char *key, unsigned int len, uint32 pos TSRMLS_DC) +static int cdb_match(struct cdb *c, char *key, unsigned int len, uint32 pos) { char buf[32]; unsigned int n; while (len > 0) { n = sizeof(buf); - if (n > len) + if (n > len) n = len; - if (cdb_read(c, buf, n, pos TSRMLS_CC) == -1) + if (cdb_read(c, buf, n, pos) == -1) return -1; - if (memcmp(buf, key, n)) + if (memcmp(buf, key, n)) return 0; pos += n; key += n; @@ -79,29 +79,29 @@ uint32 cdb_hash(char *buf, unsigned int len) /* }}} */ /* {{{ cdb_free */ -void cdb_free(struct cdb *c TSRMLS_DC) +void cdb_free(struct cdb *c) { } /* }}} */ /* {{{ cdb_findstart */ -void cdb_findstart(struct cdb *c TSRMLS_DC) +void cdb_findstart(struct cdb *c) { c->loop = 0; } /* }}} */ /* {{{ cdb_init */ -void cdb_init(struct cdb *c, php_stream *fp TSRMLS_DC) +void cdb_init(struct cdb *c, php_stream *fp) { - cdb_free(c TSRMLS_CC); - cdb_findstart(c TSRMLS_CC); + cdb_free(c); + cdb_findstart(c); c->fp = fp; } /* }}} */ /* {{{ cdb_read */ -int cdb_read(struct cdb *c, char *buf, unsigned int len, uint32 pos TSRMLS_DC) +int cdb_read(struct cdb *c, char *buf, unsigned int len, uint32 pos) { if (php_stream_seek(c->fp, pos, SEEK_SET) == -1) { errno = EPROTO; @@ -112,7 +112,7 @@ int cdb_read(struct cdb *c, char *buf, unsigned int len, uint32 pos TSRMLS_DC) do { r = php_stream_read(c->fp, buf, len); } while ((r == -1) && (errno == EINTR)); - if (r == -1) + if (r == -1) return -1; if (r == 0) { errno = EPROTO; @@ -126,7 +126,7 @@ int cdb_read(struct cdb *c, char *buf, unsigned int len, uint32 pos TSRMLS_DC) /* }}} */ /* {{{ cdb_findnext */ -int cdb_findnext(struct cdb *c, char *key, unsigned int len TSRMLS_DC) +int cdb_findnext(struct cdb *c, char *key, unsigned int len) { char buf[8]; uint32 pos; @@ -134,10 +134,10 @@ int cdb_findnext(struct cdb *c, char *key, unsigned int len TSRMLS_DC) if (!c->loop) { u = cdb_hash(key, len); - if (cdb_read(c, buf, 8, (u << 3) & 2047 TSRMLS_CC) == -1) + if (cdb_read(c, buf, 8, (u << 3) & 2047) == -1) return -1; uint32_unpack(buf + 4,&c->hslots); - if (!c->hslots) + if (!c->hslots) return 0; uint32_unpack(buf, &c->hpos); c->khash = u; @@ -148,22 +148,22 @@ int cdb_findnext(struct cdb *c, char *key, unsigned int len TSRMLS_DC) } while (c->loop < c->hslots) { - if (cdb_read(c, buf, 8, c->kpos TSRMLS_CC) == -1) + if (cdb_read(c, buf, 8, c->kpos) == -1) return -1; uint32_unpack(buf + 4, &pos); - if (!pos) + if (!pos) return 0; c->loop += 1; c->kpos += 8; - if (c->kpos == c->hpos + (c->hslots << 3)) + if (c->kpos == c->hpos + (c->hslots << 3)) c->kpos = c->hpos; uint32_unpack(buf, &u); if (u == c->khash) { - if (cdb_read(c, buf, 8, pos TSRMLS_CC) == -1) + if (cdb_read(c, buf, 8, pos) == -1) return -1; uint32_unpack(buf, &u); if (u == len) - switch(cdb_match(c, key, len, pos + 8 TSRMLS_CC)) { + switch(cdb_match(c, key, len, pos + 8)) { case -1: return -1; case 1: @@ -179,15 +179,15 @@ int cdb_findnext(struct cdb *c, char *key, unsigned int len TSRMLS_DC) /* }}} */ /* {{{ cdb_find */ -int cdb_find(struct cdb *c, char *key, unsigned int len TSRMLS_DC) +int cdb_find(struct cdb *c, char *key, unsigned int len) { - cdb_findstart(c TSRMLS_CC); - return cdb_findnext(c, key, len TSRMLS_CC); + cdb_findstart(c); + return cdb_findnext(c, key, len); } /* }}} */ /* {{{ cdb_version */ -char *cdb_version() +char *cdb_version() { return "0.75, $Id$"; } diff --git a/ext/dba/libcdb/cdb.h b/ext/dba/libcdb/cdb.h index bd0a51eab8..18f55d5a6a 100644 --- a/ext/dba/libcdb/cdb.h +++ b/ext/dba/libcdb/cdb.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -40,14 +40,14 @@ struct cdb { uint32 cdb_hash(char *, unsigned int); -void cdb_free(struct cdb * TSRMLS_DC); -void cdb_init(struct cdb *, php_stream *fp TSRMLS_DC); +void cdb_free(struct cdb *); +void cdb_init(struct cdb *, php_stream *fp); -int cdb_read(struct cdb *, char *, unsigned int, uint32 TSRMLS_DC); +int cdb_read(struct cdb *, char *, unsigned int, uint32); -void cdb_findstart(struct cdb * TSRMLS_DC); -int cdb_findnext(struct cdb *, char *, unsigned int TSRMLS_DC); -int cdb_find(struct cdb *, char *, unsigned int TSRMLS_DC); +void cdb_findstart(struct cdb *); +int cdb_findnext(struct cdb *, char *, unsigned int); +int cdb_find(struct cdb *, char *, unsigned int); #define cdb_datapos(c) ((c)->dpos) #define cdb_datalen(c) ((c)->dlen) diff --git a/ext/dba/libcdb/cdb_make.c b/ext/dba/libcdb/cdb_make.c index e9b9adf7a0..b1e33abb9b 100644 --- a/ext/dba/libcdb/cdb_make.c +++ b/ext/dba/libcdb/cdb_make.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -38,7 +38,7 @@ #include "uint32.h" /* {{{ cdb_make_write */ -static int cdb_make_write(struct cdb_make *c, char *buf, uint32 sz TSRMLS_DC) { +static int cdb_make_write(struct cdb_make *c, char *buf, uint32 sz) { return php_stream_write(c->fp, buf, sz) == sz ? 0 : -1; } @@ -56,7 +56,7 @@ static int cdb_posplus(struct cdb_make *c, uint32 len) /* }}} */ /* {{{ cdb_make_start */ -int cdb_make_start(struct cdb_make *c, php_stream * f TSRMLS_DC) +int cdb_make_start(struct cdb_make *c, php_stream * f) { c->head = 0; c->split = 0; @@ -65,7 +65,7 @@ int cdb_make_start(struct cdb_make *c, php_stream * f TSRMLS_DC) c->fp = f; c->pos = sizeof(c->final); if (php_stream_seek(f, c->pos, SEEK_SET) == -1) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Fseek failed"); + php_error_docref(NULL, E_NOTICE, "Fseek failed"); return -1; } return php_stream_tell(c->fp); @@ -73,7 +73,7 @@ int cdb_make_start(struct cdb_make *c, php_stream * f TSRMLS_DC) /* }}} */ /* {{{ cdb_make_addend */ -int cdb_make_addend(struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32 h TSRMLS_DC) +int cdb_make_addend(struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32 h) { struct cdb_hplist *head; @@ -101,7 +101,7 @@ int cdb_make_addend(struct cdb_make *c, unsigned int keylen, unsigned int datale /* }}} */ /* {{{ cdb_make_addbegin */ -int cdb_make_addbegin(struct cdb_make *c, unsigned int keylen, unsigned int datalen TSRMLS_DC) +int cdb_make_addbegin(struct cdb_make *c, unsigned int keylen, unsigned int datalen) { char buf[8]; @@ -116,26 +116,26 @@ int cdb_make_addbegin(struct cdb_make *c, unsigned int keylen, unsigned int data uint32_pack(buf, keylen); uint32_pack(buf + 4, datalen); - if (cdb_make_write(c, buf, 8 TSRMLS_CC) != 0) + if (cdb_make_write(c, buf, 8) != 0) return -1; return 0; } /* {{{ cdb_make_add */ -int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen TSRMLS_DC) +int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen) { - if (cdb_make_addbegin(c, keylen, datalen TSRMLS_CC) == -1) + if (cdb_make_addbegin(c, keylen, datalen) == -1) return -1; - if (cdb_make_write(c, key, keylen TSRMLS_CC) != 0) + if (cdb_make_write(c, key, keylen) != 0) return -1; - if (cdb_make_write(c, data, datalen TSRMLS_CC) != 0) + if (cdb_make_write(c, data, datalen) != 0) return -1; - return cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen) TSRMLS_CC); + return cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen)); } /* }}} */ /* {{{ cdb_make_finish */ -int cdb_make_finish(struct cdb_make *c TSRMLS_DC) +int cdb_make_finish(struct cdb_make *c) { char buf[8]; int i; @@ -211,7 +211,7 @@ int cdb_make_finish(struct cdb_make *c TSRMLS_DC) for (u = 0;u < len;++u) { uint32_pack(buf, c->hash[u].h); uint32_pack(buf + 4, c->hash[u].p); - if (cdb_make_write(c, buf, 8 TSRMLS_CC) != 0) + if (cdb_make_write(c, buf, 8) != 0) return -1; if (cdb_posplus(c, 8) == -1) return -1; @@ -231,14 +231,14 @@ int cdb_make_finish(struct cdb_make *c TSRMLS_DC) php_stream_rewind(c->fp); if (php_stream_tell(c->fp) != 0) return -1; - if (cdb_make_write(c, c->final, sizeof(c->final) TSRMLS_CC) != 0) + if (cdb_make_write(c, c->final, sizeof(c->final)) != 0) return -1; return php_stream_flush(c->fp); } /* }}} */ /* {{{ cdb_make_version */ -char *cdb_make_version() +char *cdb_make_version() { return "0.75, $Id$"; } diff --git a/ext/dba/libcdb/cdb_make.h b/ext/dba/libcdb/cdb_make.h index 2c72629bf3..cc043d961b 100644 --- a/ext/dba/libcdb/cdb_make.h +++ b/ext/dba/libcdb/cdb_make.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -54,11 +54,11 @@ struct cdb_make { php_stream * fp; }; -int cdb_make_start(struct cdb_make *, php_stream * TSRMLS_DC); -int cdb_make_addbegin(struct cdb_make *, unsigned int, unsigned int TSRMLS_DC); -int cdb_make_addend(struct cdb_make *, unsigned int, unsigned int, uint32 TSRMLS_DC); -int cdb_make_add(struct cdb_make *, char *, unsigned int, char *, unsigned int TSRMLS_DC); -int cdb_make_finish(struct cdb_make * TSRMLS_DC); +int cdb_make_start(struct cdb_make *, php_stream *); +int cdb_make_addbegin(struct cdb_make *, unsigned int, unsigned int); +int cdb_make_addend(struct cdb_make *, unsigned int, unsigned int, uint32); +int cdb_make_add(struct cdb_make *, char *, unsigned int, char *, unsigned int); +int cdb_make_finish(struct cdb_make *); char *cdb_make_version(); #endif diff --git a/ext/dba/libcdb/uint32.c b/ext/dba/libcdb/uint32.c index 52648fd2d0..4ce38876c3 100644 --- a/ext/dba/libcdb/uint32.c +++ b/ext/dba/libcdb/uint32.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ diff --git a/ext/dba/libcdb/uint32.h b/ext/dba/libcdb/uint32.h index b43d140037..450938efdf 100644 --- a/ext/dba/libcdb/uint32.h +++ b/ext/dba/libcdb/uint32.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ diff --git a/ext/dba/libflatfile/flatfile.c b/ext/dba/libflatfile/flatfile.c index 6de5fe322d..9d4be74593 100644 --- a/ext/dba/libflatfile/flatfile.c +++ b/ext/dba/libflatfile/flatfile.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -47,30 +47,30 @@ /* {{{ flatfile_store */ -int flatfile_store(flatfile *dba, datum key_datum, datum value_datum, int mode TSRMLS_DC) { +int flatfile_store(flatfile *dba, datum key_datum, datum value_datum, int mode) { if (mode == FLATFILE_INSERT) { - if (flatfile_findkey(dba, key_datum TSRMLS_CC)) { + if (flatfile_findkey(dba, key_datum)) { return 1; } php_stream_seek(dba->fp, 0L, SEEK_END); - php_stream_printf(dba->fp TSRMLS_CC, "%zu\n", key_datum.dsize); + php_stream_printf(dba->fp, "%zu\n", key_datum.dsize); php_stream_flush(dba->fp); if (php_stream_write(dba->fp, key_datum.dptr, key_datum.dsize) < key_datum.dsize) { return -1; } - php_stream_printf(dba->fp TSRMLS_CC, "%zu\n", value_datum.dsize); + php_stream_printf(dba->fp, "%zu\n", value_datum.dsize); php_stream_flush(dba->fp); if (php_stream_write(dba->fp, value_datum.dptr, value_datum.dsize) < value_datum.dsize) { return -1; } } else { /* FLATFILE_REPLACE */ - flatfile_delete(dba, key_datum TSRMLS_CC); - php_stream_printf(dba->fp TSRMLS_CC, "%zu\n", key_datum.dsize); + flatfile_delete(dba, key_datum); + php_stream_printf(dba->fp, "%zu\n", key_datum.dsize); php_stream_flush(dba->fp); if (php_stream_write(dba->fp, key_datum.dptr, key_datum.dsize) < key_datum.dsize) { return -1; } - php_stream_printf(dba->fp TSRMLS_CC, "%zu\n", value_datum.dsize); + php_stream_printf(dba->fp, "%zu\n", value_datum.dsize); if (php_stream_write(dba->fp, value_datum.dptr, value_datum.dsize) < value_datum.dsize) { return -1; } @@ -83,11 +83,11 @@ int flatfile_store(flatfile *dba, datum key_datum, datum value_datum, int mode T /* {{{ flatfile_fetch */ -datum flatfile_fetch(flatfile *dba, datum key_datum TSRMLS_DC) { +datum flatfile_fetch(flatfile *dba, datum key_datum) { datum value_datum = {NULL, 0}; char buf[16]; - if (flatfile_findkey(dba, key_datum TSRMLS_CC)) { + if (flatfile_findkey(dba, key_datum)) { if (php_stream_gets(dba->fp, buf, sizeof(buf))) { value_datum.dsize = atoi(buf); value_datum.dptr = safe_emalloc(value_datum.dsize, 1, 1); @@ -103,7 +103,7 @@ datum flatfile_fetch(flatfile *dba, datum key_datum TSRMLS_DC) { /* {{{ flatfile_delete */ -int flatfile_delete(flatfile *dba, datum key_datum TSRMLS_DC) { +int flatfile_delete(flatfile *dba, datum key_datum) { char *key = key_datum.dptr; size_t size = key_datum.dsize; size_t buf_size = FLATFILE_BLOCK_SIZE; @@ -134,7 +134,7 @@ int flatfile_delete(flatfile *dba, datum key_datum TSRMLS_DC) { php_stream_seek(dba->fp, 0L, SEEK_END); efree(buf); return SUCCESS; - } + } /* read in the length of the value */ if (!php_stream_gets(dba->fp, buf, 15)) { @@ -150,12 +150,12 @@ int flatfile_delete(flatfile *dba, datum key_datum TSRMLS_DC) { } efree(buf); return FAILURE; -} +} /* }}} */ /* {{{ flatfile_findkey */ -int flatfile_findkey(flatfile *dba, datum key_datum TSRMLS_DC) { +int flatfile_findkey(flatfile *dba, datum key_datum) { size_t buf_size = FLATFILE_BLOCK_SIZE; char *buf = emalloc(buf_size); size_t num; @@ -180,7 +180,7 @@ int flatfile_findkey(flatfile *dba, datum key_datum TSRMLS_DC) { ret = 1; break; } - } + } if (!php_stream_gets(dba->fp, buf, 15)) { break; } @@ -198,7 +198,7 @@ int flatfile_findkey(flatfile *dba, datum key_datum TSRMLS_DC) { /* {{{ flatfile_firstkey */ -datum flatfile_firstkey(flatfile *dba TSRMLS_DC) { +datum flatfile_firstkey(flatfile *dba) { datum res; size_t num; size_t buf_size = FLATFILE_BLOCK_SIZE; @@ -241,7 +241,7 @@ datum flatfile_firstkey(flatfile *dba TSRMLS_DC) { /* {{{ flatfile_nextkey */ -datum flatfile_nextkey(flatfile *dba TSRMLS_DC) { +datum flatfile_nextkey(flatfile *dba) { datum res; size_t num; size_t buf_size = FLATFILE_BLOCK_SIZE; @@ -280,15 +280,15 @@ datum flatfile_nextkey(flatfile *dba TSRMLS_DC) { res.dptr = NULL; res.dsize = 0; return res; -} +} /* }}} */ /* {{{ flatfile_version */ -char *flatfile_version() +char *flatfile_version() { return "1.0, $Id$"; } -/* }}} */ +/* }}} */ /* * Local variables: diff --git a/ext/dba/libflatfile/flatfile.h b/ext/dba/libflatfile/flatfile.h index a0846b325f..803dec1505 100644 --- a/ext/dba/libflatfile/flatfile.h +++ b/ext/dba/libflatfile/flatfile.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -37,12 +37,12 @@ typedef struct { #define FLATFILE_INSERT 1 #define FLATFILE_REPLACE 0 -int flatfile_store(flatfile *dba, datum key_datum, datum value_datum, int mode TSRMLS_DC); -datum flatfile_fetch(flatfile *dba, datum key_datum TSRMLS_DC); -int flatfile_delete(flatfile *dba, datum key_datum TSRMLS_DC); -int flatfile_findkey(flatfile *dba, datum key_datum TSRMLS_DC); -datum flatfile_firstkey(flatfile *dba TSRMLS_DC); -datum flatfile_nextkey(flatfile *dba TSRMLS_DC); +int flatfile_store(flatfile *dba, datum key_datum, datum value_datum, int mode); +datum flatfile_fetch(flatfile *dba, datum key_datum); +int flatfile_delete(flatfile *dba, datum key_datum); +int flatfile_findkey(flatfile *dba, datum key_datum); +datum flatfile_firstkey(flatfile *dba); +datum flatfile_nextkey(flatfile *dba); char *flatfile_version(); #endif diff --git a/ext/dba/libinifile/inifile.c b/ext/dba/libinifile/inifile.c index 95ac9a8ea6..857251902f 100644 --- a/ext/dba/libinifile/inifile.c +++ b/ext/dba/libinifile/inifile.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -40,11 +40,11 @@ */ /* {{{ inifile_version */ -char *inifile_version() +char *inifile_version() { return "1.0, $Id$"; } -/* }}} */ +/* }}} */ /* {{{ inifile_free_key */ void inifile_key_free(key_type *key) @@ -79,17 +79,17 @@ void inifile_line_free(line_type *ln) /* }}} */ /* {{{ inifile_alloc */ -inifile * inifile_alloc(php_stream *fp, int readonly, int persistent TSRMLS_DC) +inifile * inifile_alloc(php_stream *fp, int readonly, int persistent) { inifile *dba; if (!readonly) { if (!php_stream_truncate_supported(fp)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't truncate this stream"); + php_error_docref(NULL, E_WARNING, "Can't truncate this stream"); return NULL; } } - + dba = pemalloc(sizeof(inifile), persistent); memset(dba, 0, sizeof(inifile)); dba->fp = fp; @@ -114,7 +114,7 @@ key_type inifile_key_split(const char *group_name) { key_type key; char *name; - + if (group_name[0] == '[' && (name = strchr(group_name, ']')) != NULL) { key.group = estrndup(group_name+1, name - (group_name + 1)); key.name = estrdup(name+1); @@ -146,7 +146,7 @@ static char *etrim(const char *str) { char *val; size_t l; - + if (!str) { return NULL; } @@ -164,7 +164,7 @@ static char *etrim(const char *str) /* {{{ inifile_findkey */ -static int inifile_read(inifile *dba, line_type *ln TSRMLS_DC) { +static int inifile_read(inifile *dba, line_type *ln) { char *fline; char *pos; @@ -224,10 +224,10 @@ static int inifile_read(inifile *dba, line_type *ln TSRMLS_DC) { * 1 = GROUP-EQUAL,NAME-DIFFERENT * 2 = DIFFERENT */ -static int inifile_key_cmp(const key_type *k1, const key_type *k2 TSRMLS_DC) +static int inifile_key_cmp(const key_type *k1, const key_type *k2) { assert(k1->group && k1->name && k2->group && k2->name); - + if (!strcasecmp(k1->group, k2->group)) { if (!strcasecmp(k1->name, k2->name)) { return 0; @@ -242,12 +242,12 @@ static int inifile_key_cmp(const key_type *k1, const key_type *k2 TSRMLS_DC) /* {{{ inifile_fetch */ -val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC) { +val_type inifile_fetch(inifile *dba, const key_type *key, int skip) { line_type ln = {{NULL,NULL},{NULL}}; val_type val; int res, grp_eq = 0; - if (skip == -1 && dba->next.key.group && dba->next.key.name && !inifile_key_cmp(&dba->next.key, key TSRMLS_CC)) { + if (skip == -1 && dba->next.key.group && dba->next.key.name && !inifile_key_cmp(&dba->next.key, key)) { /* we got position already from last fetch */ php_stream_seek(dba->fp, dba->next.pos, SEEK_SET); ln.key.group = estrdup(dba->next.key.group); @@ -260,8 +260,8 @@ val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC) { if (skip == -1) { skip = 0; } - while(inifile_read(dba, &ln TSRMLS_CC)) { - if (!(res=inifile_key_cmp(&ln.key, key TSRMLS_CC))) { + while(inifile_read(dba, &ln)) { + if (!(res=inifile_key_cmp(&ln.key, key))) { if (!skip) { val.value = estrdup(ln.val.value ? ln.val.value : ""); /* allow faster access by updating key read into next */ @@ -286,36 +286,36 @@ val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC) { /* {{{ inifile_firstkey */ -int inifile_firstkey(inifile *dba TSRMLS_DC) { +int inifile_firstkey(inifile *dba) { inifile_line_free(&dba->curr); dba->curr.pos = 0; - return inifile_nextkey(dba TSRMLS_CC); + return inifile_nextkey(dba); } /* }}} */ /* {{{ inifile_nextkey */ -int inifile_nextkey(inifile *dba TSRMLS_DC) { +int inifile_nextkey(inifile *dba) { line_type ln = {{NULL,NULL},{NULL}}; /*inifile_line_free(&dba->next); ??? */ php_stream_seek(dba->fp, dba->curr.pos, SEEK_SET); ln.key.group = estrdup(dba->curr.key.group ? dba->curr.key.group : ""); - inifile_read(dba, &ln TSRMLS_CC); + inifile_read(dba, &ln); inifile_line_free(&dba->curr); dba->curr = ln; return ln.key.group || ln.key.name; -} +} /* }}} */ /* {{{ inifile_truncate */ -static int inifile_truncate(inifile *dba, size_t size TSRMLS_DC) +static int inifile_truncate(inifile *dba, size_t size) { int res; if ((res=php_stream_truncate_set_size(dba->fp, size)) != 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in ftruncate: %d", res); + php_error_docref(NULL, E_WARNING, "Error in ftruncate: %d", res); return FAILURE; } php_stream_seek(dba->fp, size, SEEK_SET); @@ -326,7 +326,7 @@ static int inifile_truncate(inifile *dba, size_t size TSRMLS_DC) /* {{{ inifile_find_group * if found pos_grp_start points to "[group_name]" */ -static int inifile_find_group(inifile *dba, const key_type *key, size_t *pos_grp_start TSRMLS_DC) +static int inifile_find_group(inifile *dba, const key_type *key, size_t *pos_grp_start) { int ret = FAILURE; @@ -340,8 +340,8 @@ static int inifile_find_group(inifile *dba, const key_type *key, size_t *pos_grp line_type ln = {{NULL,NULL},{NULL}}; res = 1; - while(inifile_read(dba, &ln TSRMLS_CC)) { - if ((res=inifile_key_cmp(&ln.key, key TSRMLS_CC)) < 2) { + while(inifile_read(dba, &ln)) { + if ((res=inifile_key_cmp(&ln.key, key)) < 2) { ret = SUCCESS; break; } @@ -363,15 +363,15 @@ static int inifile_find_group(inifile *dba, const key_type *key, size_t *pos_grp * only valid after a call to inifile_find_group * if any next group is found pos_grp_start points to "[group_name]" or whitespace before that */ -static int inifile_next_group(inifile *dba, const key_type *key, size_t *pos_grp_start TSRMLS_DC) +static int inifile_next_group(inifile *dba, const key_type *key, size_t *pos_grp_start) { int ret = FAILURE; line_type ln = {{NULL,NULL},{NULL}}; *pos_grp_start = php_stream_tell(dba->fp); ln.key.group = estrdup(key->group); - while(inifile_read(dba, &ln TSRMLS_CC)) { - if (inifile_key_cmp(&ln.key, key TSRMLS_CC) == 2) { + while(inifile_read(dba, &ln)) { + if (inifile_key_cmp(&ln.key, key) == 2) { ret = SUCCESS; break; } @@ -384,29 +384,29 @@ static int inifile_next_group(inifile *dba, const key_type *key, size_t *pos_grp /* {{{ inifile_copy_to */ -static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifile **ini_copy TSRMLS_DC) +static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifile **ini_copy) { php_stream *fp; - + if (pos_start == pos_end) { *ini_copy = NULL; return SUCCESS; } if ((fp = php_stream_temp_create(0, 64 * 1024)) == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not create temporary stream"); + php_error_docref(NULL, E_WARNING, "Could not create temporary stream"); *ini_copy = NULL; return FAILURE; } - if ((*ini_copy = inifile_alloc(fp, 1, 0 TSRMLS_CC)) == NULL) { + if ((*ini_copy = inifile_alloc(fp, 1, 0)) == NULL) { /* writes error */ return FAILURE; } php_stream_seek(dba->fp, pos_start, SEEK_SET); if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp, pos_end - pos_start, NULL)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy group [%zu - %zu] to temporary stream", pos_start, pos_end); + php_error_docref(NULL, E_WARNING, "Could not copy group [%zu - %zu] to temporary stream", pos_start, pos_end); return FAILURE; - } + } return SUCCESS; } /* }}} */ @@ -414,7 +414,7 @@ static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifi /* {{{ inifile_filter * copy from to dba while ignoring key name (group must equal) */ -static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRMLS_DC) +static int inifile_filter(inifile *dba, inifile *from, const key_type *key, zend_bool *found) { size_t pos_start = 0, pos_next = 0, pos_curr; int ret = SUCCESS; @@ -422,14 +422,17 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML php_stream_seek(from->fp, 0, SEEK_SET); php_stream_seek(dba->fp, 0, SEEK_END); - while(inifile_read(from, &ln TSRMLS_CC)) { - switch(inifile_key_cmp(&ln.key, key TSRMLS_CC)) { + while(inifile_read(from, &ln)) { + switch(inifile_key_cmp(&ln.key, key)) { case 0: + if (found) { + *found = (zend_bool) 1; + } pos_curr = php_stream_tell(from->fp); if (pos_start != pos_next) { php_stream_seek(from->fp, pos_start, SEEK_SET); if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start); + php_error_docref(NULL, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start); ret = FAILURE; } php_stream_seek(from->fp, pos_curr, SEEK_SET); @@ -448,7 +451,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML if (pos_start != pos_next) { php_stream_seek(from->fp, pos_start, SEEK_SET); if (SUCCESS != php_stream_copy_to_stream_ex(from->fp, dba->fp, pos_next - pos_start, NULL)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start); + php_error_docref(NULL, E_WARNING, "Could not copy [%zu - %zu] from temporary stream", pos_next, pos_start); ret = FAILURE; } } @@ -459,7 +462,7 @@ static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRML /* {{{ inifile_delete_replace_append */ -static int inifile_delete_replace_append(inifile *dba, const key_type *key, const val_type *value, int append TSRMLS_DC) +static int inifile_delete_replace_append(inifile *dba, const key_type *key, const val_type *value, int append, zend_bool *found) { size_t pos_grp_start=0, pos_grp_next; inifile *ini_tmp = NULL; @@ -471,7 +474,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons * 3) If not append: Copy group to ini_tmp * 4) Open temp_stream and copy remainder * 5) Truncate stream - * 6) If not append AND key.name given: Filtered copy back from ini_tmp + * 6) If not append AND key.name given: Filtered copy back from ini_tmp * to stream. Otherwise the user wanted to delete the group. * 7) Append value if given * 8) Append temporary stream @@ -480,36 +483,36 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons assert(!append || (key->name && value)); /* missuse */ /* 1 - 3 */ - inifile_find_group(dba, key, &pos_grp_start TSRMLS_CC); - inifile_next_group(dba, key, &pos_grp_next TSRMLS_CC); + inifile_find_group(dba, key, &pos_grp_start); + inifile_next_group(dba, key, &pos_grp_next); if (append) { ret = SUCCESS; } else { - ret = inifile_copy_to(dba, pos_grp_start, pos_grp_next, &ini_tmp TSRMLS_CC); + ret = inifile_copy_to(dba, pos_grp_start, pos_grp_next, &ini_tmp); } /* 4 */ if (ret == SUCCESS) { fp_tmp = php_stream_temp_create(0, 64 * 1024); if (!fp_tmp) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not create temporary stream"); + php_error_docref(NULL, E_WARNING, "Could not create temporary stream"); ret = FAILURE; } else { php_stream_seek(dba->fp, 0, SEEK_END); if (pos_grp_next != (size_t)php_stream_tell(dba->fp)) { php_stream_seek(dba->fp, pos_grp_next, SEEK_SET); if (SUCCESS != php_stream_copy_to_stream_ex(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL, NULL)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy remainder to temporary stream"); + php_error_docref(NULL, E_WARNING, "Could not copy remainder to temporary stream"); ret = FAILURE; } } } } - + /* 5 */ if (ret == SUCCESS) { if (!value || (key->name && strlen(key->name))) { - ret = inifile_truncate(dba, append ? pos_grp_next : pos_grp_start TSRMLS_CC); /* writes error on fail */ + ret = inifile_truncate(dba, append ? pos_grp_next : pos_grp_start); /* writes error on fail */ } } @@ -517,7 +520,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons if (key->name && strlen(key->name)) { /* 6 */ if (!append && ini_tmp) { - ret = inifile_filter(dba, ini_tmp, key TSRMLS_CC); + ret = inifile_filter(dba, ini_tmp, key, found); } /* 7 */ @@ -526,13 +529,13 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons */ if (value) { if (pos_grp_start == pos_grp_next && key->group && strlen(key->group)) { - php_stream_printf(dba->fp TSRMLS_CC, "[%s]\n", key->group); + php_stream_printf(dba->fp, "[%s]\n", key->group); } - php_stream_printf(dba->fp TSRMLS_CC, "%s=%s\n", key->name, value->value ? value->value : ""); + php_stream_printf(dba->fp, "%s=%s\n", key->name, value->value ? value->value : ""); } } - - /* 8 */ + + /* 8 */ /* important: do not query ret==SUCCESS again: inifile_filter might fail but * however next operation must be done. */ @@ -540,7 +543,7 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons php_stream_seek(fp_tmp, 0, SEEK_SET); php_stream_seek(dba->fp, 0, SEEK_END); if (SUCCESS != php_stream_copy_to_stream_ex(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL, NULL)) { - php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Could not copy from temporary stream - ini file truncated"); + php_error_docref(NULL, E_RECOVERABLE_ERROR, "Could not copy from temporary stream - ini file truncated"); ret = FAILURE; } } @@ -562,25 +565,41 @@ static int inifile_delete_replace_append(inifile *dba, const key_type *key, cons /* {{{ inifile_delete */ -int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC) +int inifile_delete(inifile *dba, const key_type *key) { - return inifile_delete_replace_append(dba, key, NULL, 0 TSRMLS_CC); -} + return inifile_delete_replace_append(dba, key, NULL, 0, NULL); +} +/* }}} */ + +/* {{{ inifile_delete_ex + */ +int inifile_delete_ex(inifile *dba, const key_type *key, zend_bool *found) +{ + return inifile_delete_replace_append(dba, key, NULL, 0, found); +} /* }}} */ /* {{{ inifile_relace */ -int inifile_replace(inifile *dba, const key_type *key, const val_type *value TSRMLS_DC) +int inifile_replace(inifile *dba, const key_type *key, const val_type *value) +{ + return inifile_delete_replace_append(dba, key, value, 0, NULL); +} +/* }}} */ + +/* {{{ inifile_replace_ex + */ +int inifile_replace_ex(inifile *dba, const key_type *key, const val_type *value, zend_bool *found) { - return inifile_delete_replace_append(dba, key, value, 0 TSRMLS_CC); + return inifile_delete_replace_append(dba, key, value, 0, found); } /* }}} */ /* {{{ inifile_append */ -int inifile_append(inifile *dba, const key_type *key, const val_type *value TSRMLS_DC) +int inifile_append(inifile *dba, const key_type *key, const val_type *value) { - return inifile_delete_replace_append(dba, key, value, 1 TSRMLS_CC); + return inifile_delete_replace_append(dba, key, value, 1, NULL); } /* }}} */ diff --git a/ext/dba/libinifile/inifile.h b/ext/dba/libinifile/inifile.h index 4e6623deb2..d24ab734a5 100644 --- a/ext/dba/libinifile/inifile.h +++ b/ext/dba/libinifile/inifile.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -45,12 +45,14 @@ typedef struct { line_type next; } inifile; -val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC); -int inifile_firstkey(inifile *dba TSRMLS_DC); -int inifile_nextkey(inifile *dba TSRMLS_DC); -int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC); -int inifile_replace(inifile *dba, const key_type *key, const val_type *val TSRMLS_DC); -int inifile_append(inifile *dba, const key_type *key, const val_type *val TSRMLS_DC); +val_type inifile_fetch(inifile *dba, const key_type *key, int skip); +int inifile_firstkey(inifile *dba); +int inifile_nextkey(inifile *dba); +int inifile_delete(inifile *dba, const key_type *key); +int inifile_delete_ex(inifile *dba, const key_type *key, zend_bool *found); +int inifile_replace(inifile *dba, const key_type *key, const val_type *val); +int inifile_replace_ex(inifile *dba, const key_type *key, const val_type *val, zend_bool *found); +int inifile_append(inifile *dba, const key_type *key, const val_type *val); char *inifile_version(); key_type inifile_key_split(const char *group_name); @@ -60,7 +62,7 @@ void inifile_key_free(key_type *key); void inifile_val_free(val_type *val); void inifile_line_free(line_type *ln); -inifile * inifile_alloc(php_stream *fp, int readonly, int persistent TSRMLS_DC); +inifile * inifile_alloc(php_stream *fp, int readonly, int persistent); void inifile_free(inifile *dba, int persistent); #endif diff --git a/ext/dba/php_dba.h b/ext/dba/php_dba.h index c2d3eca655..a0d291a66d 100644 --- a/ext/dba/php_dba.h +++ b/ext/dba/php_dba.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -21,9 +21,12 @@ #ifndef PHP_DBA_H #define PHP_DBA_H +#include "php_version.h" +#define PHP_DBA_VERSION PHP_VERSION + #if HAVE_DBA -typedef enum { +typedef enum { /* do not allow 0 here */ DBA_READER = 1, DBA_WRITER, @@ -46,10 +49,10 @@ typedef struct dba_info { int fd; /* arg[cv] are only available when the dba_open handler is called! */ int argc; - zval ***argv; + zval *argv; /* private */ int flags; /* whether and how dba did locking and other flags*/ - struct dba_handler *hnd; + struct dba_handler *hnd; dba_lock lock; } dba_info; @@ -74,44 +77,44 @@ extern zend_module_entry dba_module_entry; typedef struct dba_handler { char *name; /* handler name */ int flags; /* whether and how dba does locking and other flags*/ - int (*open)(dba_info *, char **error TSRMLS_DC); - void (*close)(dba_info * TSRMLS_DC); - char* (*fetch)(dba_info *, char *, int, int, int * TSRMLS_DC); - int (*update)(dba_info *, char *, int, char *, int, int TSRMLS_DC); - int (*exists)(dba_info *, char *, int TSRMLS_DC); - int (*delete)(dba_info *, char *, int TSRMLS_DC); - char* (*firstkey)(dba_info *, int * TSRMLS_DC); - char* (*nextkey)(dba_info *, int * TSRMLS_DC); - int (*optimize)(dba_info * TSRMLS_DC); - int (*sync)(dba_info * TSRMLS_DC); - char* (*info)(struct dba_handler *hnd, dba_info * TSRMLS_DC); + int (*open)(dba_info *, char **error); + void (*close)(dba_info *); + char* (*fetch)(dba_info *, char *, int, int, int *); + int (*update)(dba_info *, char *, int, char *, int, int); + int (*exists)(dba_info *, char *, int); + int (*delete)(dba_info *, char *, int); + char* (*firstkey)(dba_info *, int *); + char* (*nextkey)(dba_info *, int *); + int (*optimize)(dba_info *); + int (*sync)(dba_info *); + char* (*info)(struct dba_handler *hnd, dba_info *); /* dba_info==NULL: Handler info, dba_info!=NULL: Database info */ } dba_handler; /* common prototypes which must be supplied by modules */ #define DBA_OPEN_FUNC(x) \ - int dba_open_##x(dba_info *info, char **error TSRMLS_DC) + int dba_open_##x(dba_info *info, char **error) #define DBA_CLOSE_FUNC(x) \ - void dba_close_##x(dba_info *info TSRMLS_DC) + void dba_close_##x(dba_info *info) #define DBA_FETCH_FUNC(x) \ - char *dba_fetch_##x(dba_info *info, char *key, int keylen, int skip, int *newlen TSRMLS_DC) + char *dba_fetch_##x(dba_info *info, char *key, int keylen, int skip, int *newlen) #define DBA_UPDATE_FUNC(x) \ - int dba_update_##x(dba_info *info, char *key, int keylen, char *val, int vallen, int mode TSRMLS_DC) + int dba_update_##x(dba_info *info, char *key, int keylen, char *val, int vallen, int mode) #define DBA_EXISTS_FUNC(x) \ - int dba_exists_##x(dba_info *info, char *key, int keylen TSRMLS_DC) + int dba_exists_##x(dba_info *info, char *key, int keylen) #define DBA_DELETE_FUNC(x) \ - int dba_delete_##x(dba_info *info, char *key, int keylen TSRMLS_DC) + int dba_delete_##x(dba_info *info, char *key, int keylen) #define DBA_FIRSTKEY_FUNC(x) \ - char *dba_firstkey_##x(dba_info *info, int *newlen TSRMLS_DC) + char *dba_firstkey_##x(dba_info *info, int *newlen) #define DBA_NEXTKEY_FUNC(x) \ - char *dba_nextkey_##x(dba_info *info, int *newlen TSRMLS_DC) + char *dba_nextkey_##x(dba_info *info, int *newlen) #define DBA_OPTIMIZE_FUNC(x) \ - int dba_optimize_##x(dba_info *info TSRMLS_DC) + int dba_optimize_##x(dba_info *info) #define DBA_SYNC_FUNC(x) \ - int dba_sync_##x(dba_info *info TSRMLS_DC) + int dba_sync_##x(dba_info *info) #define DBA_INFO_FUNC(x) \ - char *dba_info_##x(dba_handler *hnd, dba_info *info TSRMLS_DC) + char *dba_info_##x(dba_handler *hnd, dba_info *info) #define DBA_FUNCS(x) \ DBA_OPEN_FUNC(x); \ @@ -126,8 +129,6 @@ typedef struct dba_handler { DBA_SYNC_FUNC(x); \ DBA_INFO_FUNC(x) -#define VALLEN(p) Z_STRVAL_PP(p), Z_STRLEN_PP(p) - PHP_FUNCTION(dba_open); PHP_FUNCTION(dba_popen); PHP_FUNCTION(dba_close); diff --git a/ext/dba/php_tcadb.h b/ext/dba/php_tcadb.h index 6c18dfe34f..200bfeb1fd 100644 --- a/ext/dba/php_tcadb.h +++ b/ext/dba/php_tcadb.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ diff --git a/ext/dba/tests/bug62490.phpt b/ext/dba/tests/bug62490.phpt new file mode 100644 index 0000000000..325dd34554 --- /dev/null +++ b/ext/dba/tests/bug62490.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #62490 (dba_delete returns true on missing item (inifile)) +--SKIPIF-- +<?php +$handler = "inifile"; +include "skipif.inc"; +?> +--FILE-- +<?php +$handler = "inifile"; +include "test.inc"; + +$dba = dba_open($db_filename, "n", $handler) + or die; +for ($i = 0; $i < 3; ++$i) { + echo "insert $i:"; + var_dump(dba_insert("a", $i, $dba)); +} + +echo "exists:"; +var_dump(dba_exists("a", $dba)); +echo "delete:"; +var_dump(dba_delete("a", $dba)); +echo "exists:"; +var_dump(dba_exists("a", $dba)); +echo "delete:"; +var_dump(dba_delete("a", $dba)); + +?> +===DONE=== +--CLEAN-- +<?php +include "clean.inc"; +?> +--EXPECT-- +insert 0:bool(true) +insert 1:bool(true) +insert 2:bool(true) +exists:bool(true) +delete:bool(true) +exists:bool(false) +delete:bool(false) +===DONE=== diff --git a/ext/dba/tests/bug72157.phpt b/ext/dba/tests/bug72157.phpt new file mode 100644 index 0000000000..7b3217012a --- /dev/null +++ b/ext/dba/tests/bug72157.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #72157 (use-after-free caused by dba_open) +--SKIPIF-- +<?php + require_once(dirname(__FILE__) .'/skipif.inc'); +?> +--FILE-- +<?php +$var0 = fopen(__FILE__,"r"); +$var5 = dba_open(null,$var0); +$var5 = dba_open(null,$var0); +$var5 = dba_open(null,$var0); +$var5 = dba_open($var0,$var0); +?> +--EXPECTF-- +Warning: dba_open(,Resource id #5): Illegal DBA mode in %sbug72157.php on line %d + +Warning: dba_open(,Resource id #5): Illegal DBA mode in %sbug72157.php on line %d + +Warning: dba_open(,Resource id #5): Illegal DBA mode in %sbug72157.php on line %d + +Warning: dba_open(Resource id #5,Resource id #5): Illegal DBA mode in %sbug72157.php on line %d diff --git a/ext/dba/tests/dba015.phpt b/ext/dba/tests/dba015.phpt index 9f560c5b2f..dbb683dcec 100644 --- a/ext/dba/tests/dba015.phpt +++ b/ext/dba/tests/dba015.phpt @@ -53,8 +53,6 @@ echo dba_fetch("key2", $db_file1), "\n"; <?php require(dirname(__FILE__) .'/clean.inc'); ?> ---XFAIL-- -Test 6 crashes in flatfile_findkey with dba pointer of NULL, bug http://bugs.php.net/bug.php?id=51278 --EXPECTF-- database handler: flatfile Test 1 diff --git a/ext/dba/tests/dba_db4_003.phpt b/ext/dba/tests/dba_db4_003.phpt index 7e8568c085..8708170fc1 100644 --- a/ext/dba/tests/dba_db4_003.phpt +++ b/ext/dba/tests/dba_db4_003.phpt @@ -39,8 +39,6 @@ require(dirname(__FILE__) .'/clean.inc'); database handler: db4 int(14) -Notice: dba_open(): %stest0.dbm: unexpected file type or format in %sdba_db4_003.php on line %d - Warning: dba_open(%stest0.dbm,c): Driver initialization failed for handler: db4: Invalid argument in %sdba_db4_003.php on line %d Error creating %stest0.dbm Dummy contents diff --git a/ext/dba/tests/dba_db4_007.phpt b/ext/dba/tests/dba_db4_007.phpt index bd95e0bec7..027d0af032 100644 --- a/ext/dba/tests/dba_db4_007.phpt +++ b/ext/dba/tests/dba_db4_007.phpt @@ -35,7 +35,5 @@ require(dirname(__FILE__) .'/clean.inc'); database handler: db4 int(14) -Notice: dba_popen(): %stest0.dbm: unexpected file type or format in %sdba_db4_007.php on line %d - Warning: dba_popen(%stest0.dbm,c): Driver initialization failed for handler: db4: Invalid argument in %sdba_db4_007.php on line %d Error creating %stest0.dbm diff --git a/ext/dba/tests/dba_db4_010.phpt b/ext/dba/tests/dba_db4_010.phpt deleted file mode 100644 index fb31f05835..0000000000 --- a/ext/dba/tests/dba_db4_010.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -DBA DB4 magic_quotes_runtime Test ---SKIPIF-- -<?php -$handler = "db4"; -require_once(dirname(__FILE__) .'/skipif.inc'); -die("info $HND handler used"); -?> ---FILE-- -<?php -$handler = "db4"; -require_once(dirname(__FILE__) .'/test.inc'); -echo "database handler: $handler\n"; -if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - ini_set('magic_quotes_runtime', 0); - dba_insert("key1", '"', $db_file); - var_dump(dba_fetch("key1", $db_file)); - ini_set('magic_quotes_runtime', 1); - var_dump(dba_fetch("key1", $db_file)); - dba_replace("key1", '\"', $db_file); - var_dump(dba_fetch("key1", $db_file)); - ini_set('magic_quotes_runtime', 0); - var_dump(dba_fetch("key1", $db_file)); - dba_close($db_file); -} else { - echo "Error creating database\n"; -} -?> ---CLEAN-- -<?php -require(dirname(__FILE__) .'/clean.inc'); -?> ---EXPECTF-- -database handler: db4 -string(1) """ -string(2) "\"" -string(2) "\"" -string(1) """ diff --git a/ext/dba/tests/dba_handler.inc b/ext/dba/tests/dba_handler.inc index 0f348bc01e..9792f00829 100644 --- a/ext/dba/tests/dba_handler.inc +++ b/ext/dba/tests/dba_handler.inc @@ -82,7 +82,7 @@ do { dba_close($dba_reader); } if (($db_file = dba_popen($db_filename, 'r'.($lock_flag==''?'':'-'), $handler))!==FALSE) { - if ($handler == 'dbm') { + if ($handler == 'dbm' || $handler == "tcadb") { dba_close($db_file); } } diff --git a/ext/dba/tests/dba_inifile.phpt b/ext/dba/tests/dba_inifile.phpt index 5975d25f4d..ae06aee09f 100644 --- a/ext/dba/tests/dba_inifile.phpt +++ b/ext/dba/tests/dba_inifile.phpt @@ -12,6 +12,10 @@ DBA INIFILE handler test require_once dirname(__FILE__) .'/dba_handler.inc'; ?> ===DONE=== +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECT-- database handler: inifile 3NYNYY @@ -19,7 +23,7 @@ Content String 2 Content 2 replaced Read during write: not allowed "key number 6" written -Failed to write "key number 6" 2nd time +"key number 6" written 2nd time Content 2 replaced 2nd time The 6th value array(3) { @@ -36,7 +40,7 @@ Content String 2 Content 2 replaced Read during write: not allowed "key number 6" written -Failed to write "key number 6" 2nd time +"key number 6" written 2nd time Content 2 replaced 2nd time The 6th value array(3) { diff --git a/ext/dba/tests/dba_tcadb.phpt b/ext/dba/tests/dba_tcadb.phpt index 28b6dd8f0b..f75aa813d4 100644 --- a/ext/dba/tests/dba_tcadb.phpt +++ b/ext/dba/tests/dba_tcadb.phpt @@ -16,6 +16,12 @@ DBA TCADB handler test require_once dirname(__FILE__) .'/dba_handler.inc'; ?> ===DONE=== +--CLEAN-- +<?php +$db_filename = $db_file = dirname(__FILE__) .'/test0.tch'; +@unlink($db_filename); +@unlink($db_filename.'.lck'); +?> --EXPECT-- database handler: tcadb 3NYNYY |