sas             Mon Feb 10 19:53:32 2003 EDT

  Modified files:              (Branch: PHP_4)
    /php4/ext/session   mod_files.c php_session.h session.c 
  Log:
  MFH
  
Index: php4/ext/session/mod_files.c
diff -u php4/ext/session/mod_files.c:1.83.2.3.2.1 
php4/ext/session/mod_files.c:1.83.2.3.2.2
--- php4/ext/session/mod_files.c:1.83.2.3.2.1   Fri Jan 24 18:59:16 2003
+++ php4/ext/session/mod_files.c        Mon Feb 10 19:53:32 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: mod_files.c,v 1.83.2.3.2.1 2003/01/24 23:59:16 sas Exp $ */
+/* $Id: mod_files.c,v 1.83.2.3.2.2 2003/02/11 00:53:32 sas Exp $ */
 
 #include "php.h"
 
@@ -56,6 +56,7 @@
        size_t basedir_len;
        size_t dirdepth;
        size_t st_size;
+       int filemode;
 } ps_files;
 
 ps_module ps_mod_files = {
@@ -152,7 +153,8 @@
                
                data->lastkey = estrdup(key);
                
-               data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, 0600);
+               data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, 
+                               data->filemode);
                
                if (data->fd != -1) {
                        flock(data->fd, LOCK_EX);
@@ -226,23 +228,54 @@
 PS_OPEN_FUNC(files)
 {
        ps_files *data;
-       char *p;
-
-       data = ecalloc(sizeof(*data), 1);
-       PS_SET_MOD_DATA(data);
+       const char *p, *last;
+       const char *argv[3];
+       int argc = 0;
+       size_t dirdepth = 0;
+       int filemode = 0600;
+
+       /* split up input parameter */
+       last = save_path;
+       p = strchr(save_path, ';');
+       while (p) {
+               argv[argc++] = last;
+               last = ++p;
+               p = strchr(p, ';');
+               if (argc > 1) break;
+       }
+       argv[argc++] = last;
 
-       data->fd = -1;
-       if ((p = strchr(save_path, ';'))) {
+       if (argc > 1) {
                errno = 0;
-               data->dirdepth = (size_t) strtol(save_path, NULL, 10);
+               dirdepth = (size_t) strtol(argv[0], NULL, 10);
                if (errno == ERANGE) {
-                       efree(data);
+                       php_error(E_WARNING, 
+                                       "The first parameter in session.save_path is 
+invalid");
+                       return FAILURE;
+               }
+       }
+       
+       if (argc > 2) {
+               errno = 0;
+               filemode = strtol(argv[1], NULL, 8);
+               if (errno == ERANGE || filemode < 0 || filemode > 07777) {
+                       php_error(E_WARNING, 
+                                       "The second parameter in session.save_path is 
+invalid");
                        return FAILURE;
                }
-               save_path = p + 1;
        }
+       save_path = argv[argc - 1];
+
+       data = emalloc(sizeof(*data));
+       memset(data, 0, sizeof(*data));
+       
+       data->fd = -1;
+       data->dirdepth = dirdepth;
+       data->filemode = filemode;
        data->basedir_len = strlen(save_path);
        data->basedir = estrndup(save_path, data->basedir_len);
+       
+       PS_SET_MOD_DATA(data);
        
        return SUCCESS;
 }
Index: php4/ext/session/php_session.h
diff -u php4/ext/session/php_session.h:1.84.2.1.2.1 
php4/ext/session/php_session.h:1.84.2.1.2.2
--- php4/ext/session/php_session.h:1.84.2.1.2.1 Fri Jan 24 18:59:16 2003
+++ php4/ext/session/php_session.h      Mon Feb 10 19:53:32 2003
@@ -35,14 +35,14 @@
 char *php_session_create_id(PS_CREATE_SID_ARGS);
 
 typedef struct ps_module_struct {
-       const char *name;
-       int (*open)(PS_OPEN_ARGS);
-       int (*close)(PS_CLOSE_ARGS);
-       int (*read)(PS_READ_ARGS);
-       int (*write)(PS_WRITE_ARGS);
-       int (*destroy)(PS_DESTROY_ARGS);
-       int (*gc)(PS_GC_ARGS);
-       char *(*create_sid)(PS_CREATE_SID_ARGS);
+       const char *s_name;
+       int (*s_open)(PS_OPEN_ARGS);
+       int (*s_close)(PS_CLOSE_ARGS);
+       int (*s_read)(PS_READ_ARGS);
+       int (*s_write)(PS_WRITE_ARGS);
+       int (*s_destroy)(PS_DESTROY_ARGS);
+       int (*s_gc)(PS_GC_ARGS);
+       char *(*s_create_sid)(PS_CREATE_SID_ARGS);
 } ps_module;
 
 #define PS_GET_MOD_DATA() *mod_data
Index: php4/ext/session/session.c
diff -u php4/ext/session/session.c:1.336.2.5.2.1 
php4/ext/session/session.c:1.336.2.5.2.2
--- php4/ext/session/session.c:1.336.2.5.2.1    Fri Jan 24 18:59:16 2003
+++ php4/ext/session/session.c  Mon Feb 10 19:53:32 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: session.c,v 1.336.2.5.2.1 2003/01/24 23:59:16 sas Exp $ */
+/* $Id: session.c,v 1.336.2.5.2.2 2003/02/11 00:53:32 sas Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -678,7 +678,7 @@
 
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "The ini setting 
hash_bits_per_character is out of range (should be 4, 5, or 6) - using 4 for now");
        }
-       j = bin_to_readable(digest, digest_len, buf, PS(hash_bits_per_character)) - 
buf;
+       j = (int) (bin_to_readable(digest, digest_len, buf, 
+PS(hash_bits_per_character)) - buf);
        
        if (newlen) 
                *newlen = j;
@@ -696,14 +696,14 @@
        }
 
        /* Open session handler first */
-       if (PS(mod)->open(&PS(mod_data), PS(save_path), PS(session_name) TSRMLS_CC) == 
FAILURE) {
+       if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name) TSRMLS_CC) 
+== FAILURE) {
                php_error_docref(NULL TSRMLS_CC, E_ERROR, "Failed to initialize 
session module");
                return;
        }
        
        /* If there is no ID, use session module to create one */
        if (!PS(id))
-               PS(id) = PS(mod)->create_sid(&PS(mod_data), NULL TSRMLS_CC);
+               PS(id) = PS(mod)->s_create_sid(&PS(mod_data), NULL TSRMLS_CC);
        
        /* Read data */
        /* Question: if you create a SID here, should you also try to read data?
@@ -712,7 +712,7 @@
         * session information
         */
        php_session_track_init(TSRMLS_C);
-       if (PS(mod)->read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == SUCCESS) {
+       if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == 
+SUCCESS) {
                php_session_decode(val, vallen TSRMLS_CC);
                efree(val);
        }
@@ -780,10 +780,10 @@
 
                        val = php_session_encode(&vallen TSRMLS_CC);
                        if (val) {
-                               ret = PS(mod)->write(&PS(mod_data), PS(id), val, 
vallen TSRMLS_CC);
+                               ret = PS(mod)->s_write(&PS(mod_data), PS(id), val, 
+vallen TSRMLS_CC);
                                efree(val);
                        } else {
-                               ret = PS(mod)->write(&PS(mod_data), PS(id), "", 0 
TSRMLS_CC);
+                               ret = PS(mod)->s_write(&PS(mod_data), PS(id), "", 0 
+TSRMLS_CC);
                        }
                }
 
@@ -791,12 +791,12 @@
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write 
session data (%s). Please "
                                        "verify that the current setting of 
session.save_path "
                                        "is correct (%s)",
-                                       PS(mod)->name,
+                                       PS(mod)->s_name,
                                        PS(save_path));
        }
        
        if (PS(mod_data))
-               PS(mod)->close(&PS(mod_data) TSRMLS_CC);
+               PS(mod)->s_close(&PS(mod_data) TSRMLS_CC);
 }
 
 static char *month_names[] = {
@@ -991,7 +991,7 @@
        int i;
 
        for (i = 0, mod = ps_modules; i < MAX_MODULES; i++, mod++)
-               if (*mod && !strcasecmp(name, (*mod)->name)) {
+               if (*mod && !strcasecmp(name, (*mod)->s_name)) {
                        ret = *mod;
                        break;
                }
@@ -1147,7 +1147,7 @@
 
                nrand = (int) ((float) PS(gc_dividend) * php_combined_lcg(TSRMLS_C));
                if (nrand < PS(gc_probability)) {
-                       PS(mod)->gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels 
TSRMLS_CC);
+                       PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels 
+TSRMLS_CC);
 #if 0
                        if (nrdels != -1)
                                php_error_docref(NULL TSRMLS_CC, E_NOTICE, "purged %d 
expired session objects\n", nrdels);
@@ -1165,7 +1165,7 @@
                return FAILURE;
        }
 
-       if (PS(mod)->destroy(&PS(mod_data), PS(id) TSRMLS_CC) == FAILURE) {
+       if (PS(mod)->s_destroy(&PS(mod_data), PS(id) TSRMLS_CC) == FAILURE) {
                retval = FAILURE;
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session object 
destruction failed");
        }
@@ -1259,7 +1259,7 @@
        if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
                WRONG_PARAM_COUNT;
        
-       old = safe_estrdup(PS(mod)->name);
+       old = safe_estrdup(PS(mod)->s_name);
 
        if (ac == 1) {
                ps_module *tempmod;
@@ -1268,7 +1268,7 @@
                tempmod = _php_find_ps_module(Z_STRVAL_PP(p_name) TSRMLS_CC);
                if (tempmod) {
                        if (PS(mod_data))
-                               PS(mod)->close(&PS(mod_data) TSRMLS_CC);
+                               PS(mod)->s_close(&PS(mod_data) TSRMLS_CC);
                        PS(mod) = tempmod;
                        PS(mod_data) = NULL;
                } else {
@@ -1621,7 +1621,7 @@
 static void php_rshutdown_session_globals(TSRMLS_D)
 {
        if (PS(mod_data)) {
-               PS(mod)->close(&PS(mod_data) TSRMLS_CC);
+               PS(mod)->s_close(&PS(mod_data) TSRMLS_CC);
        }
        if (PS(id)) {
                efree(PS(id));
@@ -1720,8 +1720,8 @@
        int i;
        
        for (i = 0, mod = ps_modules; i < MAX_MODULES; i++, mod++) {
-               if (*mod && (*mod)->name) {
-                       smart_str_appends(&handlers, (*mod)->name);
+               if (*mod && (*mod)->s_name) {
+                       smart_str_appends(&handlers, (*mod)->s_name);
                        smart_str_appendc(&handlers, ' ');
                }
        }



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

Reply via email to