helly           Sun Dec 14 17:20:05 2003 EDT

  Modified files:              (Branch: PHP_4_3)
    /php-src/ext/dba    dba.c dba_flatfile.c 
    /php-src/ext/dba/tests      dba_handler.inc 
  Log:
  MFH: Synch (as far as possible) and fix #26304
  
  
Index: php-src/ext/dba/dba.c
diff -u php-src/ext/dba/dba.c:1.61.2.23 php-src/ext/dba/dba.c:1.61.2.24
--- php-src/ext/dba/dba.c:1.61.2.23     Thu Nov 13 14:09:24 2003
+++ php-src/ext/dba/dba.c       Sun Dec 14 17:20:04 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba.c,v 1.61.2.23 2003/11/13 19:09:24 helly Exp $ */
+/* $Id: dba.c,v 1.61.2.24 2003/12/14 22:20:04 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -27,7 +27,6 @@
 
 #if HAVE_DBA
 
-#include "ext/standard/flock_compat.h" 
 #include "php_ini.h"
 #include <stdio.h> 
 #include <fcntl.h>
@@ -38,6 +37,7 @@
 #include "php_dba.h"
 #include "ext/standard/info.h"
 #include "ext/standard/php_string.h"
+#include "ext/standard/flock_compat.h" 
 
 #include "php_gdbm.h"
 #include "php_ndbm.h"
@@ -651,22 +651,36 @@
                case 'c': 
                        modenr = DBA_CREAT; 
                        lock_mode = (lock_flag & DBA_LOCK_CREAT) ? LOCK_EX : 0;
+                       if (lock_mode) {
+                               if (lock_dbf) {
+                                       /* the create/append check will be done on the 
lock
+                                        * when the lib opens the file it is already 
created
+                                        */
+                                       file_mode = "r+b";       /* read & write, seek 
0 */
+                                       lock_file_mode = "a+b";  /* append */
+                               } else {
+                                       file_mode = "a+b";       /* append */
+                                       lock_file_mode = "w+b";  /* create/truncate */
+                               }
+                       } else {
                        file_mode = "a+b";
-                       if (!lock_mode || !lock_dbf) {
-                               break;
                        }
-                       /* When we lock the db file it will be created before the 
handler
-                        * even tries to open it, hence we must change to truncate 
mode.
+                       /* In case of the 'a+b' append mode, the handler is 
responsible 
+                        * to handle any rewind problems (see flatfile handler).
                         */
+                       break;
                case 'n':
                        modenr = DBA_TRUNC;
                        lock_mode = (lock_flag & DBA_LOCK_TRUNC) ? LOCK_EX : 0;
                        file_mode = "w+b";
                        break;
                default:
-                       modenr = 0;
-                       lock_mode = 0;
-                       file_mode = "";
+                       php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), 
Z_STRVAL_PP(args[1]), E_WARNING, "Illegal DBA mode");
+                       FREENOW;
+                       RETURN_FALSE;
+       }
+       if (!lock_file_mode) {
+               lock_file_mode = file_mode;
        }
        if (*pmode=='d' || *pmode=='l' || *pmode=='-') {
                pmode++; /* done already - skip here */
@@ -692,7 +706,7 @@
                        lock_mode |= LOCK_NB; /* test =: non blocking */
                }
        }
-       if (*pmode || !modenr) {
+       if (*pmode) {
                php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), 
Z_STRVAL_PP(args[1]), E_WARNING, "Illegal DBA mode");
                FREENOW;
                RETURN_FALSE;
@@ -724,7 +738,6 @@
        if (!error && lock_mode) {
                if (lock_dbf) {
                        info->lock.name = pestrdup(info->path, persistent);
-                       lock_file_mode = file_mode;
                } else {
                        spprintf(&info->lock.name, 0, "%s.lck", info->path);
                        if (!strcmp(file_mode, "r")) {
@@ -747,12 +760,6 @@
                        FREENOW;
                        RETURN_FALSE;
                }
-               if (php_stream_cast(info->lock.fp, PHP_STREAM_AS_FD, 
(void*)&info->lock.fd, 1) == FAILURE)      {
-                       dba_close(info TSRMLS_CC);
-                       /* stream operation already wrote an error message */
-                       FREENOW;
-                       RETURN_FALSE;
-               }
                if (php_flock(info->lock.fd, lock_mode)) {
                        error = "Unable to establish lock"; /* force failure exit */
                }
Index: php-src/ext/dba/dba_flatfile.c
diff -u php-src/ext/dba/dba_flatfile.c:1.8.2.3 php-src/ext/dba/dba_flatfile.c:1.8.2.4
--- php-src/ext/dba/dba_flatfile.c:1.8.2.3      Fri Jan 31 15:10:11 2003
+++ php-src/ext/dba/dba_flatfile.c      Sun Dec 14 17:20:04 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dba_flatfile.c,v 1.8.2.3 2003/01/31 20:10:11 helly Exp $ */
+/* $Id: dba_flatfile.c,v 1.8.2.4 2003/12/14 22:20:04 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -41,6 +41,17 @@
 
 DBA_OPEN_FUNC(flatfile)
 {
+       int fd, flags;
+
+       if (info->mode != DBA_READER) {
+               if (SUCCESS != php_stream_cast(info->fp, PHP_STREAM_AS_FD, (void*)&fd, 
1)) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not cast 
stream");
+                       return FAILURE;
+               }
+               flags = fcntl(fd, F_SETFL);
+               fcntl(fd, F_SETFL, flags & ~O_APPEND);
+       }
+
        info->dbf = pemalloc(sizeof(flatfile), info->flags&DBA_PERSISTENT);
        memset(info->dbf, 0, sizeof(flatfile));
 
@@ -53,8 +64,9 @@
 {
        FLATFILE_DATA;
 
-       if (dba->nextkey.dptr)
+       if (dba->nextkey.dptr) {
                efree(dba->nextkey.dptr);
+       }
        pefree(dba, info->flags&DBA_PERSISTENT);
 }
 
@@ -67,8 +79,10 @@
        FLATFILE_GKEY;
 
        gval = flatfile_fetch(dba, gkey TSRMLS_CC);
-       if(gval.dptr) {
-               if(newlen) *newlen = gval.dsize;
+       if (gval.dptr) {
+               if (newlen) {
+                       *newlen = gval.dsize;
+               }
                new = estrndup(gval.dptr, gval.dsize);
                efree(gval.dptr);
        }
@@ -104,7 +118,7 @@
        FLATFILE_GKEY;
        
        gval = flatfile_fetch(dba, gkey TSRMLS_CC);
-       if(gval.dptr) {
+       if (gval.dptr) {
                efree(gval.dptr);
                return SUCCESS;
        }
@@ -122,12 +136,14 @@
 {
        FLATFILE_DATA;
 
-       if (dba->nextkey.dptr)
+       if (dba->nextkey.dptr) {
                efree(dba->nextkey.dptr);
+       }
        dba->nextkey = flatfile_firstkey(dba TSRMLS_CC);
-       if(dba->nextkey.dptr) {
-               if(newlen) 
+       if (dba->nextkey.dptr) {
+               if (newlen)  {
                        *newlen = dba->nextkey.dsize;
+               }
                return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
        }
        return NULL;
@@ -137,15 +153,18 @@
 {
        FLATFILE_DATA;
        
-       if(!dba->nextkey.dptr) 
+       if (!dba->nextkey.dptr) {
                return NULL;
+       }
        
-       if (dba->nextkey.dptr)
+       if (dba->nextkey.dptr) {
                efree(dba->nextkey.dptr);
+       }
        dba->nextkey = flatfile_nextkey(dba TSRMLS_CC);
-       if(dba->nextkey.dptr) {
-               if(newlen) 
+       if (dba->nextkey.dptr) {
+               if (newlen) {
                        *newlen = dba->nextkey.dsize;
+               }
                return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
        }
        return NULL;
Index: php-src/ext/dba/tests/dba_handler.inc
diff -u php-src/ext/dba/tests/dba_handler.inc:1.7.2.3 
php-src/ext/dba/tests/dba_handler.inc:1.7.2.4
--- php-src/ext/dba/tests/dba_handler.inc:1.7.2.3       Thu Dec 26 23:47:45 2002
+++ php-src/ext/dba/tests/dba_handler.inc       Sun Dec 14 17:20:05 2003
@@ -36,7 +36,7 @@
                echo "Error creating database\n";
        }
        if ($handler != 'cdb') {
-               $db_writer = dba_open($db_filename, 'w'.$lock_flag, $handler);
+               $db_writer = dba_open($db_filename, 'c'.$lock_flag, $handler);
                if (($dba_reader = @dba_open($db_filename, 'r'.$lock_flag.($lock_flag 
? 't' : ''), $handler))===false) {
                        echo "Read during write: not allowed\n";
                } else {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to