From: Stig Bakken Date: Wed, 21 Apr 1999 23:37:47 +0000 (+0000) Subject: moved db X-Git-Tag: BEFORE_PHP4_APACHE_MODULE_CHANGE~222 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f582bec9db6bd87426fee28e7992a0ffc8b01598;p=php moved db --- diff --git a/Makefile.in b/Makefile.in index 3e2e8345b4..fe84a47bbb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -69,7 +69,7 @@ OBJS = main.o internal_functions.o snprintf.o php3_sprintf.o \ php_ini.o FUNCTIONS_SOURCE = functions/fhttpd.c \ - functions/crypt.c functions/db.c functions/dl.c \ + functions/crypt.c functions/dl.c \ functions/head.c functions/imap.c functions/mime.c \ functions/pgsql.c functions/post.c functions/sybase.c \ functions/sybase-ct.c functions/xml.c \ diff --git a/acconfig.h.in b/acconfig.h.in index d007973430..53b5a83720 100644 --- a/acconfig.h.in +++ b/acconfig.h.in @@ -54,12 +54,6 @@ /* in GET/POST/Cookie data */ #define MAGIC_QUOTES 1 -/* Define if you have an ndbm compatible library (-ldbm). */ -#define NDBM 0 - -/* Define if you have the gdbm library (-lgdbm). */ -#define GDBM 0 - /* Define both of these if you want the bundled REGEX library */ #define REGEX 0 #define HSREGEX 0 diff --git a/acinclude.m4 b/acinclude.m4 index 78ab84b136..c3feedb11b 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -16,25 +16,6 @@ AC_DEFUN(AC_MISSING_FCLOSE_DECL,[ ]) ]) -# Checks for libraries. -# Prefer gdbm, Berkeley DB and ndbm/dbm, in that order -AC_DEFUN(AC_PREFERRED_DB_LIB,[ - AC_CHECK_LIB(gdbm, gdbm_open,[AC_DEFINE(GDBM) DBM_TYPE=gdbm; DBM_LIB=-lgdbm], - [AC_CHECK_LIB(db, dbm_open,[AC_DEFINE(NDBM) DBM_TYPE=ndbm; DBM_LIB=-ldb], - [AC_CHECK_LIB(c, dbm_open,[AC_DEFINE(NDBM) DBM_TYPE=ndbm; DBM_LIB=], - [AC_CHECK_LIB(dbm, dbm_open,[AC_DEFINE(NDBM) DBM_TYPE=ndbm; DBM_LIB=-ldbm], - [DBM_TYPE=""])])])]) - AC_MSG_CHECKING([preferred dbm library]) - if test "a$DBM_TYPE" = a; then - AC_MSG_RESULT(none found) - AC_MSG_WARN(No dbm library found - using built-in flatfile support) - else - AC_MSG_RESULT($DBM_TYPE chosen) - fi - AC_SUBST(DBM_LIB) - AC_SUBST(DBM_TYPE) -]) - dnl dnl Check for broken sprintf() dnl diff --git a/configure.in.in b/configure.in.in index ba199c9b4d..055b170b9d 100644 --- a/configure.in.in +++ b/configure.in.in @@ -150,8 +150,6 @@ fi INCLUDES="" AC_SUBST(INCLUDES) -AC_PREFERRED_DB_LIB - AC_CHECK_LIB(nsl, gethostname, [ LIBS="-lnsl $LIBS" AC_DEFINE(HAVE_LIBNSL) ], []) @@ -210,24 +208,6 @@ fi AC_MISSING_FCLOSE_DECL dnl QNX requires unix.h to allow functions in libunix to work properly AC_CHECK_HEADERS(fcntl.h unistd.h crypt.h sys/file.h memory.h pwd.h grp.h sys/socket.h sys/wait.h syslog.h string.h sys/varargs.h stdarg.h sys/time.h signal.h netinet/in.h dlfcn.h limits.h sys/types.h unix.h arpa/inet.h) -if test "$DBM_LIB" = "-lgdbm"; then - AC_CHECK_HEADER(gdbm.h, [ GDBM_INCLUDE="" ], [ - AC_MSG_RESULT("Try /usr/local/include/gdbm.h"); - AC_CHECK_HEADER(/usr/local/include/gdbm.h, [ GDBM_INCLUDE="-I/usr/local/include" ],[ - AC_MSG_RESULT("Try /opt/local/include/gdbm.h"); - AC_CHECK_HEADER(/opt/local/include/gdbm.h, [ GDBM_INCLUDE="-I/opt/local/include" ],[ - dnl if in /usr/pkg/include, do not add anything. See above. - AC_MSG_RESULT("Try /usr/pkg/include/gdbm.h"); - AC_CHECK_HEADER(/usr/pkg/include/gdbm.h, [ GDBM_INCLUDE="" ],[ - AC_MSG_RESULT("Giving up - You need to install gdbm.h somewhere"); - exit - ]) - ]) - ]) - ]) - INCLUDES="$INCLUDES $GDBM_INCLUDES" -dnl## AC_SUBST(GDBM_INCLUDE) -fi dnl Checks for typedefs, structures, and compiler characteristics. AC_STRUCT_TM diff --git a/ext/db/Makefile.am b/ext/db/Makefile.am new file mode 100644 index 0000000000..c9dbfa4872 --- /dev/null +++ b/ext/db/Makefile.am @@ -0,0 +1,6 @@ +# $Id$ + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpext_db.a +libphpext_db_a_SOURCES=db.c + diff --git a/ext/db/config.h.stub b/ext/db/config.h.stub new file mode 100644 index 0000000000..e952d61fac --- /dev/null +++ b/ext/db/config.h.stub @@ -0,0 +1,5 @@ +/* Define if you have an ndbm compatible library (-ldbm). */ +#define NDBM 0 + +/* Define if you have the gdbm library (-lgdbm). */ +#define GDBM 0 diff --git a/ext/db/config.m4 b/ext/db/config.m4 new file mode 100644 index 0000000000..9aad420958 --- /dev/null +++ b/ext/db/config.m4 @@ -0,0 +1,47 @@ +dnl $Id$ +dnl config.m4 for extension db +dnl don't forget to call PHP_EXTENSION(db) + +divert(1) + +# Checks for libraries. +# Prefer gdbm, Berkeley DB and ndbm/dbm, in that order +AC_DEFUN(AC_PREFERRED_DB_LIB,[ + AC_CHECK_LIB(gdbm, gdbm_open,[AC_DEFINE(GDBM) DBM_TYPE=gdbm; DBM_LIB=-lgdbm], + [AC_CHECK_LIB(db, dbm_open,[AC_DEFINE(NDBM) DBM_TYPE=ndbm; DBM_LIB=-ldb], + [AC_CHECK_LIB(c, dbm_open,[AC_DEFINE(NDBM) DBM_TYPE=ndbm; DBM_LIB=], + [AC_CHECK_LIB(dbm, dbm_open,[AC_DEFINE(NDBM) DBM_TYPE=ndbm; DBM_LIB=-ldbm], + [DBM_TYPE=""])])])]) + AC_MSG_CHECKING([preferred dbm library]) + if test "a$DBM_TYPE" = a; then + AC_MSG_RESULT(none found) + AC_MSG_WARN(No dbm library found - using built-in flatfile support) + else + AC_MSG_RESULT($DBM_TYPE chosen) + fi + AC_SUBST(DBM_LIB) + AC_SUBST(DBM_TYPE) +]) + +AC_PREFERRED_DB_LIB + +divert(3) + +if test "$DBM_LIB" = "-lgdbm"; then + AC_CHECK_HEADER(gdbm.h, [ GDBM_INCLUDE="" ], [ + AC_MSG_RESULT("Try /usr/local/include/gdbm.h"); + AC_CHECK_HEADER(/usr/local/include/gdbm.h, [ GDBM_INCLUDE="-I/usr/local/include" ],[ + AC_MSG_RESULT("Try /opt/local/include/gdbm.h"); + AC_CHECK_HEADER(/opt/local/include/gdbm.h, [ GDBM_INCLUDE="-I/opt/local/include" ],[ + dnl if in /usr/pkg/include, do not add anything. See above. + AC_MSG_RESULT("Try /usr/pkg/include/gdbm.h"); + AC_CHECK_HEADER(/usr/pkg/include/gdbm.h, [ GDBM_INCLUDE="" ],[ + AC_MSG_RESULT("Giving up - You need to install gdbm.h somewhere"); + exit + ]) + ]) + ]) + ]) + INCLUDES="$INCLUDES $GDBM_INCLUDES" +dnl## AC_SUBST(GDBM_INCLUDE) +fi diff --git a/ext/db/db.c b/ext/db/db.c new file mode 100644 index 0000000000..d5400c819e --- /dev/null +++ b/ext/db/db.c @@ -0,0 +1,1176 @@ +/* + +----------------------------------------------------------------------+ + | PHP HTML Embedded Scripting Language Version 3.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + +----------------------------------------------------------------------+ + | This program is free software; you can redistribute it and/or modify | + | it under the terms of one of the following licenses: | + | | + | A) the GNU General Public License as published by the Free Software | + | Foundation; either version 2 of the License, or (at your option) | + | any later version. | + | | + | B) the PHP License as published by the PHP Development Team and | + | included in the distribution in the file: LICENSE | + | | + | This program is distributed in the hope that it will be useful, | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | GNU General Public License for more details. | + | | + | You should have received a copy of both licenses referred to here. | + | If you did not, or have any questions about PHP licensing, please | + | contact core@php.net. | + +----------------------------------------------------------------------+ + | Authors: Rasmus Lerdorf | + | Jim Winstead | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ +#define IS_EXT_MODULE +#if COMPILE_DL +#ifdef PHP_31 +# include "../phpdl.h" +#else +# ifdef THREAD_SAFE +# undef THREAD_SAFE +# endif +# include "dl/phpdl.h" +#endif +#endif + +#if 0 + +#include "php.h" +#include "php_globals.h" +#include "safe_mode.h" +#include "fopen-wrappers.h" + +#include +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +#ifdef PHP_31 +#include "os/nt/flock.h" +#else +#if WIN32|WINNT +#include "win32/flock.h" +#else +#include +#endif +#endif + +#if HAVE_FCNTL_H +#include +#endif + +#if GDBM +#include + +#define DBM_TYPE GDBM_FILE +#define DBM_MODE_TYPE int +#define DBM_WRITE_MODE GDBM_WRITER +#define DBM_CREATE_MODE GDBM_WRCREAT +#define DBM_NEW_MODE GDBM_NEWDB +#define DBM_DEFAULT_MODE GDBM_READER +#define DBM_OPEN(filename, mode) gdbm_open(filename, 512, mode, 0666, 0) +#define DBM_CLOSE(dbf) gdbm_close(dbf) +#define DBM_STORE(dbf, key, value, mode) gdbm_store(dbf, key, value, mode) +#define DBM_FETCH(dbf, key) gdbm_fetch(dbf, key) +#define DBM_EXISTS(dbf, key) gdbm_exists(dbf, key) +#define DBM_DELETE(dbf, key) gdbm_delete(dbf, key) +#define DBM_FIRSTKEY(dbf) gdbm_firstkey(dbf) +#define DBM_NEXTKEY(dbf, key) gdbm_nextkey(dbf, key) + +#define DBM_INSERT GDBM_INSERT +#define DBM_REPLACE GDBM_REPLACE +#endif + +#if NDBM && !GDBM +#if BSD2 +#define DB_DBM_HSEARCH 1 +#include +#else +#include +#endif + +#define DBM_TYPE DBM * +#define DBM_MODE_TYPE int +#define DBM_WRITE_MODE O_RDWR +#define DBM_CREATE_MODE O_RDWR | O_APPEND | O_CREAT +#define DBM_NEW_MODE O_RDWR | O_CREAT | O_TRUNC +#define DBM_DEFAULT_MODE O_RDONLY +#define DBM_OPEN(filename, mode) dbm_open(filename, mode, 0666) +#define DBM_CLOSE(dbf) dbm_close(dbf) +#define DBM_STORE(dbf, key, value, mode) dbm_store(dbf, key, value, mode) +#define DBM_FETCH(dbf, key) dbm_fetch(dbf, key) +#define DBM_EXISTS(dbf, key) _php3_dbm_exists(dbf, key) +#define DBM_DELETE(dbf, key) dbm_delete(dbf, key) +#define DBM_FIRSTKEY(dbf) dbm_firstkey(dbf) +#define DBM_NEXTKEY(dbf, key) dbm_nextkey(dbf) + +static int _php3_dbm_exists(DBM *dbf, datum key_datum) { + datum value_datum; + int ret; + + value_datum = dbm_fetch(dbf, key_datum); + if (value_datum.dptr) + ret = 1; + else + ret = 0; + return ret; +} +#endif + +#if !NDBM && !GDBM +#define DBM_TYPE FILE * + +#define DBM_MODE_TYPE char * +#define DBM_WRITE_MODE "r+b" +#define DBM_CREATE_MODE "a+b" +#define DBM_NEW_MODE "w+b" +#define DBM_DEFAULT_MODE "r" +#define DBM_OPEN(filename, mode) fopen(filename, mode) +#define DBM_CLOSE(dbf) fclose(dbf) +#define DBM_STORE(dbf, key, value, mode) flatfile_store(dbf, key, value, mode) +#define DBM_FETCH(dbf, key) flatfile_fetch(dbf, key) +#define DBM_EXISTS(dbf, key) flatfile_findkey(dbf, key) +#define DBM_DELETE(dbf, key) flatfile_delete(dbf, key) +#define DBM_FIRSTKEY(dbf) flatfile_firstkey(dbf) +#define DBM_NEXTKEY(dbf, key) flatfile_nextkey(dbf) + +#define DBM_INSERT 0 +#define DBM_REPLACE 1 + +typedef struct { + char *dptr; + int dsize; +} datum; + +int flatfile_store(FILE *dbf, datum key, datum value, int mode); +datum flatfile_fetch(FILE *dbf, datum key); +int flatfile_findkey(FILE *dbf, datum key); +int flatfile_delete(FILE *dbf, datum key); +datum flatfile_firstkey(FILE *dbf); +datum flatfile_nextkey(FILE *dbf); +#ifdef PHP_31 +#include "php3_db.h" +#include "ext/standard/php3_string.h" +#else +#endif + +#endif +#include "db.h" +#include "ext/standard/php3_string.h" + +#if THREAD_SAFE +DWORD DbmTls; +static int numthreads=0; + +typedef struct dbm_global_struct{ + int le_db; +}dbm_global_struct; + +#define DBM_GLOBAL(a) dbm_globals->a +#define DBM_TLS_VARS dbm_global_struct *dbm_globals = TlsGetValue(DbmTls); + +#else +static int le_db; +#define DBM_GLOBAL(a) a +#define DBM_TLS_VARS +#endif + +/*needed for blocking calls in windows*/ +void *dbm_mutex; + +dbm_info *_php3_finddbm(pval *id,HashTable *list) +{ + list_entry *le; + dbm_info *info; + int numitems, i; + int info_type; + DBM_TLS_VARS; + + if (id->type == IS_STRING) { + numitems = _php3_hash_num_elements(list); + for (i=1; i<=numitems; i++) { + if (_php3_hash_index_find(list, i, (void **) &le)==FAILURE) { + continue; + } + if (le->type == DBM_GLOBAL(le_db)) { + info = (dbm_info *)(le->ptr); + if (!strcmp(info->filename, id->value.str.val)) { + return (dbm_info *)(le->ptr); + } + } + } + } + + /* didn't find it as a database filename, try as a number */ + convert_to_long(id); + info = php3_list_find(id->value.lval, &info_type); + if (info_type != DBM_GLOBAL(le_db)) + return NULL; + return info; +} + +static char *php3_get_info_db(void) +{ + static char temp1[128]; + static char temp[256]; + + temp1[0]='\0'; + temp[0]='\0'; + +#ifdef DB_VERSION_STRING /* using sleepycat dbm */ + strcat(temp,DB_VERSION_STRING); +#endif + +#if GDBM + sprintf(temp1,"%s",gdbm_version); + strcat(temp,temp1); +#endif + +#if NDBM && !GDBM + strcat(temp,"ndbm support enabled"); +#endif + +#if !GDBM && !NDBM + strcat(temp,"flat file support enabled"); +#endif + +#if NFS_HACK + strcat(temp,"NFS hack in effect"); +#endif + + if (!*temp) + strcat(temp,"No database support"); + + return temp; +} + + +void php3_info_db(void) +{ + php3_printf(php3_get_info_db()); +} + +void php3_dblist(INTERNAL_FUNCTION_PARAMETERS) +{ + char *str = php3_get_info_db(); + RETURN_STRING(str,1); +} + + +void php3_dbmopen(INTERNAL_FUNCTION_PARAMETERS) { + pval *filename, *mode; + dbm_info *info=NULL; + int ret; + DBM_TLS_VARS; + + if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&mode)==FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_string(filename); + convert_to_string(mode); + + info = _php3_dbmopen(filename->value.str.val, mode->value.str.val); + if (info) { + ret = php3_list_insert(info, DBM_GLOBAL(le_db)); + RETURN_LONG(ret); + } else { + RETURN_FALSE; + } +} + +dbm_info *_php3_dbmopen(char *filename, char *mode) { + dbm_info *info; + int ret, lock=0; + char *lockfn = NULL; + int lockfd = 0; + +#if NFS_HACK + int last_try = 0; + struct stat sb; + int retries = 0; +#endif + + DBM_TYPE dbf=NULL; + DBM_MODE_TYPE imode; + + if (filename == NULL) { + php3_error(E_WARNING, "NULL filename passed to _php3_dbmopen()"); + return NULL; + } + + if (PG(safe_mode) && (!_php3_checkuid(filename, 2))) { + return NULL; + } + + if (_php3_check_open_basedir(filename)) { + return NULL; + } + + switch (*mode) { + case 'w': + imode = DBM_WRITE_MODE; + lock = 1; + break; + case 'c': + imode = DBM_CREATE_MODE; + lock = 1; + break; + case 'n': + imode = DBM_NEW_MODE; + lock = 1; + break; + default: + imode = DBM_DEFAULT_MODE; + lock = 0; + break; + } + + if (lock) { + lockfn = emalloc(strlen(filename) + 5); + strcpy(lockfn, filename); + strcat(lockfn, ".lck"); + +#if NFS_HACK + while((last_try = stat(lockfn,&sb))==0) { + retries++; + sleep(1); + if (retries>30) break; + } + if (last_try!=0) { + lockfd = open(lockfn,O_RDWR|O_CREAT,0644); + close(lockfd); + } else { + php3_error(E_WARNING, "File appears to be locked [%s]\n",lockfn); + return -1; + } +#else /* NFS_HACK */ + + lockfd = open(lockfn,O_RDWR|O_CREAT,0644); + + if (lockfd) { + flock(lockfd,LOCK_EX); + close(lockfd); + } else { + php3_error(E_WARNING, "Unable to establish lock: %s",filename); + } +#endif /* else NFS_HACK */ + + } + + dbf = DBM_OPEN(filename, imode); + +#if !NDBM && !GDBM + if (dbf) { + setvbuf(dbf, NULL, _IONBF, 0); + } +#endif + + if (dbf) { + info = (dbm_info *)emalloc(sizeof(dbm_info)); + if (!info) { + php3_error(E_ERROR, "problem allocating memory!"); + return NULL; + } + + info->filename = estrdup(filename); + info->lockfn = lockfn; + info->lockfd = lockfd; + info->dbf = dbf; + + return info; + } else { +#if GDBM + php3_error(E_WARNING, "dbmopen_gdbm(%s): %d [%s], %d [%s]",filename,gdbm_errno,gdbm_strerror(gdbm_errno),errno,strerror(errno)); + if (gdbm_errno) + ret = gdbm_errno; + else if (errno) + ret = errno; + else + ret = -1; +#else +#if NDBM +#if DEBUG + php3_error(E_WARNING, "dbmopen_ndbm(%s): errno = %d [%s]\n",filename,errno,strerror(errno)); +#endif + if (errno) ret=errno; + else ret = -1; +#else +#if DEBUG + php3_error(E_WARNING, "dbmopen_flatfile(%s): errno = %d [%s]\n",filename,errno,strerror(errno)); +#endif + if (errno) ret=errno; + else ret = -1; +#endif +#endif + +#if NFS_HACK + if (lockfn) { + unlink(lockfn); + } +#endif + if (lockfn) efree(lockfn); + } + + return NULL; +} + +void php3_dbmclose(INTERNAL_FUNCTION_PARAMETERS) { + pval *id; + + if (ARG_COUNT(ht) != 1 || getParameters(ht,1,&id)==FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(id); + + if (php3_list_delete(id->value.lval) == SUCCESS) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} + +int _php3_dbmclose(dbm_info *info) { + int ret = 0; + DBM_TYPE dbf; + int lockfd; + + dbf = info->dbf; + +#if NFS_HACK + unlink(info->lockfn); +#else + if (info->lockfn) { + lockfd = open(info->lockfn,O_RDWR,0644); + flock(lockfd,LOCK_UN); + close(lockfd); + } +#endif + + if (dbf) + DBM_CLOSE(dbf); + + /* free the memory used by the dbm_info struct */ + if (info->filename) efree(info->filename); + if (info->lockfn) efree(info->lockfn); + efree(info); + + return(ret); +} + +/* + * ret = -1 means that database was opened for read-only + * ret = 0 success + * ret = 1 key already exists - nothing done + */ +void php3_dbminsert(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *id, *key, *value; + dbm_info *info; + int ret; + + if (ARG_COUNT(ht)!=3||getParameters(ht,3,&id,&key,&value) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string(key); + convert_to_string(value); + + info = _php3_finddbm(id,list); + if (!info) { + php3_error(E_WARNING, "not a valid database identifier %d", id->value.lval); + RETURN_FALSE; + } + + ret = _php3_dbminsert(info, key->value.str.val, value->value.str.val); + RETURN_LONG(ret); +} + +int _php3_dbminsert(dbm_info *info, char *key, char *value) { + datum key_datum, value_datum; + int ret; + DBM_TYPE dbf; + + _php3_stripslashes(key,NULL); + _php3_stripslashes(value,NULL); + + value_datum.dptr = estrdup(value); + value_datum.dsize = strlen(value); + + key_datum.dptr = estrdup(key); + key_datum.dsize = strlen(key); +#if GDBM_FIX + key_datum.dsize++; +#endif + + dbf = info->dbf; + if (!dbf) { + php3_error(E_WARNING, "Unable to locate dbm file"); + return 1; + } + + ret = DBM_STORE(dbf, key_datum, value_datum, DBM_INSERT); + + /* free the memory */ + efree(key_datum.dptr); efree(value_datum.dptr); + + return(ret); +} + +void php3_dbmreplace(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *id, *key, *value; + dbm_info *info; + int ret; + + if (ARG_COUNT(ht)!=3||getParameters(ht,3,&id,&key,&value) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string(key); + convert_to_string(value); + + info = _php3_finddbm(id,list); + if (!info) { + php3_error(E_WARNING, "not a valid database identifier %d", id->value.lval); + RETURN_FALSE; + } + + ret = _php3_dbmreplace(info, key->value.str.val, value->value.str.val); + RETURN_LONG(ret); +} + +int _php3_dbmreplace(dbm_info *info, char *key, char *value) { + DBM_TYPE dbf; + int ret; + datum key_datum, value_datum; + PLS_FETCH(); + + if (PG(magic_quotes_runtime)) { + _php3_stripslashes(key,NULL); + _php3_stripslashes(value,NULL); + } + + value_datum.dptr = estrdup(value); + value_datum.dsize = strlen(value); + + key_datum.dptr = estrdup(key); + key_datum.dsize = strlen(key); +#if GDBM_FIX + key_datum.dsize++; +#endif + + dbf = info->dbf; + if (!dbf) { + php3_error(E_WARNING, "Unable to locate dbm file"); + return 1; + } + + ret = DBM_STORE(dbf, key_datum, value_datum, DBM_REPLACE); + + /* free the memory */ + efree(key_datum.dptr); efree(value_datum.dptr); + + return(ret); +} + +void php3_dbmfetch(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *id, *key; + dbm_info *info; + + if (ARG_COUNT(ht)!=2||getParameters(ht,2,&id,&key)==FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string(key); + + info = _php3_finddbm(id,list); + if (!info) { + php3_error(E_WARNING, "not a valid database identifier %d", id->value.lval); + RETURN_FALSE; + } + + return_value->value.str.val = _php3_dbmfetch(info, key->value.str.val); + if (return_value->value.str.val) { + return_value->value.str.len = strlen(return_value->value.str.val); + return_value->type = IS_STRING; + } else { + RETURN_FALSE; + } +} + +char *_php3_dbmfetch(dbm_info *info, char *key) { + datum key_datum, value_datum; + char *ret; + DBM_TYPE dbf; + PLS_FETCH(); + + key_datum.dptr = key; + key_datum.dsize = strlen(key); +#if GDBM_FIX + key_datum.dsize++; +#endif + value_datum.dptr = NULL; + value_datum.dsize = 0; + + dbf = info->dbf; + if (!dbf) { + php3_error(E_WARNING, "Unable to locate dbm file"); + return(NULL); + } + + value_datum = DBM_FETCH(dbf, key_datum); + + if (value_datum.dptr) { + ret = (char *)emalloc(sizeof(char) * value_datum.dsize + 1); + strncpy(ret, value_datum.dptr, value_datum.dsize); + ret[value_datum.dsize] = '\0'; + +#if GDBM +/* all but NDBM use malloc to allocate the content blocks, so we need to free it */ + free(value_datum.dptr); +#else +# if !NDBM + efree(value_datum.dptr); +# endif +#endif + } + else + ret = NULL; + + if (ret && PG(magic_quotes_runtime)) { + ret = _php3_addslashes(ret, value_datum.dsize, NULL, 1); + } + return(ret); +} + + +void php3_dbmexists(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *id, *key; + dbm_info *info; + int ret; + + if (ARG_COUNT(ht)!=2||getParameters(ht,2,&id,&key)==FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string(key); + + info = _php3_finddbm(id,list); + if (!info) { + php3_error(E_WARNING, "not a valid database identifier %d", id->value.lval); + RETURN_FALSE; + } + + ret = _php3_dbmexists(info, key->value.str.val); + RETURN_LONG(ret); +} + +int _php3_dbmexists(dbm_info *info, char *key) { + datum key_datum; + int ret; + DBM_TYPE dbf; + + key_datum.dptr = key; + key_datum.dsize = strlen(key); +#if GDBM_FIX + key_datum.dsize++; +#endif + + dbf = info->dbf; + if (!dbf) { + php3_error(E_WARNING, "Unable to locate dbm file"); + return(0); + } + + ret = DBM_EXISTS(dbf, key_datum); + + return(ret); +} + +void php3_dbmdelete(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *id, *key; + dbm_info *info; + int ret; + + if (ARG_COUNT(ht)!=2||getParameters(ht,2,&id,&key)==FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string(key); + + info = _php3_finddbm(id,list); + if (!info) { + php3_error(E_WARNING, "not a valid database identifier %d", id->value.lval); + RETURN_FALSE; + } + + ret = _php3_dbmdelete(info, key->value.str.val); + RETURN_LONG(ret); +} + +int _php3_dbmdelete(dbm_info *info, char *key) { + datum key_datum; + int ret; + DBM_TYPE dbf; + + key_datum.dptr = key; + key_datum.dsize = strlen(key); +#if GDBM_FIX + key_datum.dsize++; +#endif + + dbf = info->dbf; + if (!dbf) { + php3_error(E_WARNING, "Unable to locate dbm file"); + return(0); + } + + ret = DBM_DELETE(dbf, key_datum); + return(ret); +} + +void php3_dbmfirstkey(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *id; + dbm_info *info; + char *ret; + + if (ARG_COUNT(ht)!=1||getParameters(ht,1,&id)==FAILURE) { + WRONG_PARAM_COUNT; + } + + info = _php3_finddbm(id,list); + if (!info) { + php3_error(E_WARNING, "not a valid database identifier %d", id->value.lval); + RETURN_FALSE; + } + + ret = _php3_dbmfirstkey(info); + if (!ret) { + RETURN_FALSE; + } else { + return_value->value.str.val = ret; + return_value->value.str.len = strlen(ret); + return_value->type = IS_STRING; + } +} + +char *_php3_dbmfirstkey(dbm_info *info) { + datum ret_datum; + char *ret; + DBM_TYPE dbf; + + dbf = info->dbf; + if (!dbf) { + php3_error(E_WARNING, "Unable to locate dbm file"); + return(NULL); + } + + /* explicitly zero-out ret_datum */ + ret_datum.dptr = NULL; + ret_datum.dsize = 0; + + ret_datum = DBM_FIRSTKEY(dbf); + + if (!ret_datum.dptr) + return NULL; + + ret = (char *)emalloc((ret_datum.dsize + 1) * sizeof(char)); + strncpy(ret, ret_datum.dptr, ret_datum.dsize); + ret[ret_datum.dsize] = '\0'; + +#if !NDBM & !GDBM + efree(ret_datum.dptr); +#endif + + return (ret); +} + +void php3_dbmnextkey(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *id, *key; + dbm_info *info; + char *ret; + + if (ARG_COUNT(ht)!=2||getParameters(ht,2,&id,&key)==FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string(key); + + info = _php3_finddbm(id,list); + if (!info) { + php3_error(E_WARNING, "not a valid database identifier %d", id->value.lval); + RETURN_FALSE; + } + + ret = _php3_dbmnextkey(info, key->value.str.val); + if (!ret) { + RETURN_FALSE; + } else { + return_value->value.str.val = ret; + return_value->value.str.len = strlen(ret); + return_value->type = IS_STRING; + } +} + +char *_php3_dbmnextkey(dbm_info *info, char *key) { + datum key_datum, ret_datum; + char *ret; + DBM_TYPE dbf; + PLS_FETCH(); + + key_datum.dptr = key; + key_datum.dsize = strlen(key); +#if GDBM_FIX + key_datum.dsize++; +#endif + + dbf = info->dbf; + if (!dbf) { + php3_error(E_WARNING, "Unable to locate dbm file"); + return(NULL); + } + + /* explicitly zero-out ret_datum */ + ret_datum.dptr = NULL; + ret_datum.dsize = 0; + + ret_datum = DBM_NEXTKEY(dbf, key_datum); + + if (ret_datum.dptr) { + ret = (char *)emalloc(sizeof(char) * ret_datum.dsize + 1); + strncpy(ret, ret_datum.dptr, ret_datum.dsize); + ret[ret_datum.dsize] = '\0'; +#if GDBM +/* GDBM uses malloc to allocate the value_datum block, so we need to free it */ + free(ret_datum.dptr); +#else +# if !NDBM + efree(ret_datum.dptr); +# endif +#endif + } + else ret=NULL; + + if (ret && PG(magic_quotes_runtime)) { + ret = _php3_addslashes(ret, ret_datum.dsize, NULL, 1); + } + return(ret); +} + + +#if !GDBM && !NDBM +static long CurrentFlatFilePos = 0L; + +int flatfile_store(FILE *dbf, datum key_datum, datum value_datum, int mode) { + int ret; + + if (mode == DBM_INSERT) { + if (flatfile_findkey(dbf, key_datum)) { + return 1; + } + fseek(dbf,0L,SEEK_END); + fprintf(dbf,"%d\n",key_datum.dsize); + fflush(dbf); + ret = write(fileno(dbf),key_datum.dptr,key_datum.dsize); + fprintf(dbf,"%d\n",value_datum.dsize); + fflush(dbf); + ret = write(fileno(dbf),value_datum.dptr,value_datum.dsize); + } else { /* DBM_REPLACE */ + flatfile_delete(dbf,key_datum); + fprintf(dbf,"%d\n",key_datum.dsize); + fflush(dbf); + ret = write(fileno(dbf),key_datum.dptr,key_datum.dsize); + fprintf(dbf,"%d\n",value_datum.dsize); + ret = write(fileno(dbf),value_datum.dptr,value_datum.dsize); + } + + if (ret>0) + ret=0; + return ret; +} + +datum flatfile_fetch(FILE *dbf, datum key_datum) { + datum value_datum = {NULL, 0}; + int num=0, buf_size=1024; + char *buf; + + if (flatfile_findkey(dbf,key_datum)) { + buf = emalloc((buf_size+1) * sizeof(char)); + if (fgets(buf, 15, dbf)) { + num = atoi(buf); + if (num > buf_size) { + buf_size+=num; + buf = emalloc((buf_size+1)*sizeof(char)); + } + read(fileno(dbf),buf,num); + value_datum.dptr = buf; + value_datum.dsize = num; + } + } + return value_datum; +} + +int flatfile_delete(FILE *dbf, datum key_datum) { + char *key = key_datum.dptr; + int size = key_datum.dsize; + + char *buf; + int num, buf_size = 1024; + long pos; + + rewind(dbf); + + buf = emalloc((buf_size + 1)*sizeof(char)); + while(!feof(dbf)) { + /* read in the length of the key name */ + if (!fgets(buf, 15, dbf)) + break; + num = atoi(buf); + if (num > buf_size) { + buf_size += num; + if (buf) efree(buf); + buf = emalloc((buf_size+1)*sizeof(char)); + } + pos = ftell(dbf); + + /* read in the key name */ + num = fread(buf, sizeof(char), num, dbf); + if (num<0) break; + *(buf+num) = '\0'; + + if (size == num && !memcmp(buf, key, size)) { + fseek(dbf, pos, SEEK_SET); + fputc(0, dbf); + fflush(dbf); + fseek(dbf, 0L, SEEK_END); + if (buf) efree(buf); + return SUCCESS; + } + + /* read in the length of the value */ + if (!fgets(buf,15,dbf)) + break; + num = atoi(buf); + if (num > buf_size) { + buf_size+=num; + if (buf) efree(buf); + buf = emalloc((buf_size+1)*sizeof(char)); + } + /* read in the value */ + num = fread(buf, sizeof(char), num, dbf); + if (num<0) + break; + } + if (buf) efree(buf); + return FAILURE; +} + +int flatfile_findkey(FILE *dbf, datum key_datum) { + char *buf = NULL; + int num; + int buf_size=1024; + int ret=0; + void *key = key_datum.dptr; + int size = key_datum.dsize; + + rewind(dbf); + buf = emalloc((buf_size+1)*sizeof(char)); + while (!feof(dbf)) { + if (!fgets(buf,15,dbf)) break; + num = atoi(buf); + if (num > buf_size) { + if (buf) efree(buf); + buf_size+=num; + buf = emalloc((buf_size+1)*sizeof(char)); + } + num = fread(buf, sizeof(char), num, dbf); + if (num<0) break; + *(buf+num) = '\0'; + if (size == num) { + if (!memcmp(buf,key,size)) { + ret = 1; + break; + } + } + if (!fgets(buf,15,dbf)) + break; + num = atoi(buf); + if (num > buf_size) { + if (buf) efree(buf); + buf_size+=num; + buf = emalloc((buf_size+1)*sizeof(char)); + } + num = fread(buf, sizeof(char), num, dbf); + if (num<0) break; + *(buf+num) = '\0'; + } + if (buf) efree(buf); + return(ret); +} + +datum flatfile_firstkey(FILE *dbf) { + datum buf; + int num; + int buf_size=1024; + + rewind(dbf); + buf.dptr = emalloc((buf_size+1)*sizeof(char)); + while(!feof(dbf)) { + if (!fgets(buf.dptr,15,dbf)) break; + num = atoi(buf.dptr); + if (num > buf_size) { + buf_size+=num; + if (buf.dptr) efree(buf.dptr); + buf.dptr = emalloc((buf_size+1)*sizeof(char)); + } + num=read(fileno(dbf),buf.dptr,num); + if (num<0) break; + buf.dsize = num; + if (*(buf.dptr)!=0) { + CurrentFlatFilePos = ftell(dbf); + return(buf); + } + if (!fgets(buf.dptr,15,dbf)) break; + num = atoi(buf.dptr); + if (num > buf_size) { + buf_size+=num; + if (buf.dptr) efree(buf.dptr); + buf.dptr = emalloc((buf_size+1)*sizeof(char)); + } + num=read(fileno(dbf),buf.dptr,num); + if (num<0) break; + } + if (buf.dptr) efree(buf.dptr); + buf.dptr = NULL; + return(buf); +} + +datum flatfile_nextkey(FILE *dbf) { + datum buf; + int num; + int buf_size=1024; + + fseek(dbf,CurrentFlatFilePos,SEEK_SET); + buf.dptr = emalloc((buf_size+1)*sizeof(char)); + while(!feof(dbf)) { + if (!fgets(buf.dptr,15,dbf)) break; + num = atoi(buf.dptr); + if (num > buf_size) { + buf_size+=num; + if (buf.dptr) efree(buf.dptr); + buf.dptr = emalloc((buf_size+1)*sizeof(char)); + } + num=read(fileno(dbf),buf.dptr,num); + if (num<0) break; + if (!fgets(buf.dptr,15,dbf)) break; + num = atoi(buf.dptr); + if (num > buf_size) { + buf_size+=num; + if (buf.dptr) efree(buf.dptr); + buf.dptr = emalloc((buf_size+1)*sizeof(char)); + } + num=read(fileno(dbf),buf.dptr,num); + if (num<0) break; + buf.dsize = num; + if (*(buf.dptr)!=0) { + CurrentFlatFilePos = ftell(dbf); + return(buf); + } + } + if (buf.dptr) efree(buf.dptr); + buf.dptr = NULL; + return(buf); +} +#endif + + +int php3_minit_db(INIT_FUNC_ARGS) +{ +#if defined(THREAD_SAFE) + dbm_global_struct *dbm_globals; + PHP3_MUTEX_ALLOC(dbm_mutex); + PHP3_MUTEX_LOCK(dbm_mutex); + numthreads++; + if (numthreads==1){ + if (!PHP3_TLS_PROC_STARTUP(DbmTls)){ + PHP3_MUTEX_UNLOCK(dbm_mutex); + PHP3_MUTEX_FREE(dbm_mutex); + return FAILURE; + } + } + PHP3_MUTEX_UNLOCK(dbm_mutex); + if(!PHP3_TLS_THREAD_INIT(DbmTls,dbm_globals,dbm_global_struct)){ + PHP3_MUTEX_FREE(dbm_mutex); + return FAILURE; + } +#endif + + DBM_GLOBAL(le_db) = register_list_destructors(_php3_dbmclose,NULL); + return SUCCESS; +} + +static int php3_mend_db(void){ + DBM_TLS_VARS; +#ifdef THREAD_SAFE + PHP3_TLS_THREAD_FREE(dbm_globals); + PHP3_MUTEX_LOCK(dbm_mutex); + numthreads--; + if (numthreads<1) { + PHP3_TLS_PROC_SHUTDOWN(DbmTls); + PHP3_MUTEX_UNLOCK(dbm_mutex); + PHP3_MUTEX_FREE(dbm_mutex); + return SUCCESS; + } + PHP3_MUTEX_UNLOCK(dbm_mutex); +#endif + return SUCCESS; +} + +int php3_rinit_db(INIT_FUNC_ARGS) { +#if !GDBM && !NDBM + CurrentFlatFilePos = 0L; +#endif + return SUCCESS; +} + + +function_entry dbm_functions[] = { + {"dblist", php3_dblist, NULL}, + {"dbmopen", php3_dbmopen, NULL}, + {"dbmclose", php3_dbmclose, NULL}, + {"dbminsert", php3_dbminsert, NULL}, + {"dbmfetch", php3_dbmfetch, NULL}, + {"dbmreplace", php3_dbmreplace, NULL}, + {"dbmexists", php3_dbmexists, NULL}, + {"dbmdelete", php3_dbmdelete, NULL}, + {"dbmfirstkey", php3_dbmfirstkey, NULL}, + {"dbmnextkey", php3_dbmnextkey, NULL}, + {NULL,NULL,NULL} +}; + +php3_module_entry dbm_module_entry = { + "DBM", dbm_functions, php3_minit_db, php3_mend_db, php3_rinit_db, NULL, php3_info_db, STANDARD_MODULE_PROPERTIES +}; + +#if COMPILE_DL +DLEXPORT php3_module_entry *get_module(void) { return &dbm_module_entry; } +#endif + +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/ext/db/db.h b/ext/db/db.h new file mode 100644 index 0000000000..acda632ac8 --- /dev/null +++ b/ext/db/db.h @@ -0,0 +1,94 @@ +/* + +----------------------------------------------------------------------+ + | PHP HTML Embedded Scripting Language Version 3.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + +----------------------------------------------------------------------+ + | This program is free software; you can redistribute it and/or modify | + | it under the terms of one of the following licenses: | + | | + | A) the GNU General Public License as published by the Free Software | + | Foundation; either version 2 of the License, or (at your option) | + | any later version. | + | | + | B) the PHP License as published by the PHP Development Team and | + | included in the distribution in the file: LICENSE | + | | + | This program is distributed in the hope that it will be useful, | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | GNU General Public License for more details. | + | | + | You should have received a copy of both licenses referred to here. | + | If you did not, or have any questions about PHP licensing, please | + | contact core@php.net. | + +----------------------------------------------------------------------+ + | Authors: Rasmus Lerdorf | + | Jim Winstead | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + + +#ifndef _PHP3_DB_H +#define _PHP3_DB_H + + +#ifndef DLEXPORT +#define DLEXPORT +#endif + + +extern php3_module_entry dbm_module_entry; +#define dbm_module_ptr &dbm_module_entry + + + +typedef struct dbm_info { + char *filename; + char *lockfn; + int lockfd; + void *dbf; +} dbm_info; + +/* + we're not going to bother with flatfile on win32 + because the dbm module will be external, and we + do not want flatfile compiled staticly +*/ +#if defined(MSVC5) && !defined(COMPILE_DL) +#undef dbm_module_ptr +#define dbm_module_ptr NULL +#endif + +dbm_info *_php3_finddbm(pval *id,HashTable *list); +int _php3_dbmclose(dbm_info *info); +dbm_info *_php3_dbmopen(char *filename, char *mode); +int _php3_dbminsert(dbm_info *info, char *key, char *value); +char *_php3_dbmfetch(dbm_info *info, char *key); +int _php3_dbmreplace(dbm_info *info, char *key, char *value); +int _php3_dbmexists(dbm_info *info, char *key); +int _php3_dbmdelete(dbm_info *info, char *key); +char *_php3_dbmfirstkey(dbm_info *info); +char *_php3_dbmnextkey(dbm_info *info, char *key); + +/* db file functions */ +extern int php3_minit_db(INIT_FUNC_ARGS); +extern int php3_rinit_db(INIT_FUNC_ARGS); +extern void php3_info_db(void); +extern void php3_dblist(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_dbmopen(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_dbmclose(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_dbminsert(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_dbmfetch(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_dbmreplace(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_dbmexists(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_dbmdelete(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_dbmfirstkey(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_dbmnextkey(INTERNAL_FUNCTION_PARAMETERS); + +#undef dbm_module_ptr +#define dbm_module_ptr NULL + +#endif /* _PHP3_DB_H */ diff --git a/ext/hyperwave/debug.h b/ext/hyperwave/debug.h new file mode 100644 index 0000000000..7b6756a5ab --- /dev/null +++ b/ext/hyperwave/debug.h @@ -0,0 +1,194 @@ +/**************************************************************************** +* +* Copyright (C) 1991 Kendall Bennett. +* All rights reserved. +* +* Filename: $RCSfile$ +* Version: $Revision$ +* +* Language: ANSI C +* Environment: any +* +* Description: General header file for portable code. +* +* $Id$ +* +* Revision History: +* ----------------- +* +* $Log$ +* Revision 1.1.1.1 1999/04/07 21:03:29 zeev +* PHP 4.0 +* +* Revision 1.1.1.1 1999/03/17 04:29:10 andi +* PHP4 +* +* Revision 1.1.1.1 1998/12/21 07:56:22 andi +* Trying to start the zend CVS tree +* +* Revision 1.1 1998/08/12 09:29:16 steinm +* First version of Hyperwave module. +* +* Revision 1.6 92/03/15 12:51:48 kjb +* Added MK_FP macro and ushort typedef. +* +* Revision 1.5 91/10/28 03:17:33 kjb +* Ported to the Iris. +* +* Revision 1.4 91/09/26 15:29:02 kjb +* Added stuff for the SGI Iris 4D. +* +* Revision 1.3 91/09/26 10:07:04 kjb +* Added general typedef stuff. +* +* Revision 1.2 91/09/03 18:19:14 ROOT_DOS +* Added a few defines that are supplied by for UNIX compatibility. +* +* Revision 1.1 91/08/16 13:19:06 ROOT_DOS +* Initial revision +* +****************************************************************************/ + +#ifndef __DEBUG_H +#define __DEBUG_H + +#ifdef DEBUG +# define D(x) x +#else +# define D(x) +#endif + +#define PRIVATE static +#define PUBLIC + +#ifdef __MSDOS__ /* Compiling for MSDOS */ +# define MS(x) x +# define UX(x) +# define IR(x) +# define _8086 /* We know we have an 8086 type processor */ +#if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__) +# define LDATA +# define NULL 0L +#else +# define NULL 0 +#endif +#else __MSDOS__ +#ifdef __IRIS4D__ /* Compiling for the SGI Iris 4D */ +# define MS(x) +# define UX(x) x /* The Iris is a UNIX machine */ +# define IR(x) x +# define O_BINARY 0 /* no binary input mode in UNIX open() */ +# define MAXFILE 255 /* These are defined in , but */ +# define MAXDIR 255 /* on UNIX machines, we just define */ +# define MAXPATH 255 /* them all to be the same size */ +# define far /* Near and far do not exist under */ +# define near /* UNIX or the Iris. */ +# define NULL ((void *)0) +#else __IRIS4D__ /* Assume UNIX compilation */ +# define MS(x) +# define UX(x) x +# define IR(x) +# define O_BINARY 0 /* no binary input mode in UNIX open() */ +# define MAXFILE 255 /* These are defined in , but */ +# define MAXDIR 255 /* on UNIX machines, we just define */ +# define MAXPATH 255 /* them all to be the same size */ +# define far /* Near and far do not exist under */ +# define near /* UNIX or the Iris. */ +# ifndef NULL +# define NULL ((void *)0) +# endif +#endif __IRIS4D__ +#endif __MSDOS__ + +/**************************************************************************** +* +* SEG(p) Evaluates to the segment portion of an 8086 address. +* OFF(p) Evaluates to the offset portion of an 8086 address. +* FP(s,o) Creates a far pointer given a segment offset pair. +* PHYS(p) Evaluates to a long holding a physical address +* +****************************************************************************/ + +#ifdef _8086 +# define SEG(p) ( ((unsigned *)&(void far *)(p))[1] ) +# define OFF(p) ( (unsigned)(p) ) +# define FP(s,o) ( (void far *)( ((unsigned long)s << 16) + \ + (unsigned long)o )) +# define PHYS(p) ( (unsigned long)OFF(p) + \ + ((unsigned long)SEG(p) << 4)) +#else +# define PHYS(p) (p) +#endif _8086 + +/**************************************************************************** +* +* NUMELE(array) Evaluates to the array size in elements +* LASTELE(array) Evaluates to a pointer to the last element +* INBOUNDS(array,p) Evaluates to true if p points into the array +* RANGE(a,b,c) Evaluates to true if a <= b <= c +* max(a,b) Evaluates to a or b, whichever is larger +* min(a,b) Evaluates to a or b, whichever is smaller +* ABS(a) Evaluates to the absolute value of a +* NBITS(type) Returns the number of bits in a variable of the +* indicated type +* MAXINT Evaluates to the value of the largest signed integer +* +****************************************************************************/ + +#define NUMELE(a) (sizeof(a)/sizeof(*(a))) +#define LASTELE(a) ((a) + (NUMELE(a)-1)) +#ifdef LDATA +#define TOOHIGH(a,p) ((long)PHYS(p) - (long)PHYS(a) > (long)(NUMELE(a)-1)) +#define TOOLOW(a,p) ((long)PHYS(p) - (long)PHYS(a) < 0) +#else +#define TOOHIGH(a,p) ((long)(p) - (long)(a) > (long)(NUMELE(a)-1)) +#define TOOLOW(a,p) ((long)(p) - (long)(a) < 0) +#endif +#define INBOUNDS(a,p) ( ! (TOOHIGH(a,p) || TOOLOW(a,p)) ) + +#define _IS(t,x) (((t)1 << (x)) != 0) /* Evaluates true if the width of */ + /* variable of type t is < x. */ + /* The != 0 assures that the */ + /* answer is 1 or 0 */ + +#define NBITS(t) (4 * (1 + _IS(t,4) + _IS(t,8) + _IS(t,12) + _IS(t,16) \ + + _IS(t,20) + _IS(t,24) + _IS(t,28) + _IS(t,32))) + +#define MAXINT (((unsigned)~0) >> 1) + +#ifndef MAX +# define MAX(a,b) ( ((a) > (b)) ? (a) : (b)) +#endif +#ifndef MIN +# define MIN(a,b) ( ((a) < (b)) ? (a) : (b)) +#endif +#ifndef ABS +# define ABS(a) ((a) >= 0 ? (a) : -(a)) +#endif + +#define RANGE(a,b,c) ( (a) <= (b) && (b) <= (c) ) + +/* General typedefs */ + +#ifndef __GENDEFS +#define __GENDEFS +typedef void *ptr; +typedef void near *nearptr; +typedef void far *farptr; +/*typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned int uint; +typedef unsigned long ulong;*/ +typedef int bool; +#endif __GENDEFS + +/* Boolean truth values */ + +#define false 0 +#define true 1 +#define FALSE 0 +#define TRUE 1 +#define NO 0 +#define YES 1 + +#endif __DEBUG_H diff --git a/internal_functions.c b/internal_functions.c index 06c44f944e..1f2ea82a03 100644 --- a/internal_functions.c +++ b/internal_functions.c @@ -63,7 +63,7 @@ #include "functions/post.h" #include "ext/hyperwave/hw.h" #include "ext/filepro/filepro.h" -#include "functions/db.h" +#include "ext/db/db.h" #include "dl/snmp/php3_snmp.h" #include "functions/php3_zlib.h" #include "ext/com/php3_COM.h"