[PHPLIB-DEV] cvs commit From: kk (phplib-dev <email protected>)
Date: 10/27/99

From: kk
Date: Wed Oct 27 12:42:04 1999
Modified files:
      php-lib/CHANGES
      php-lib/php/ct_sql.inc
      php-lib/php/local.inc
      php-lib/php/session.inc

Log message:
Adressing the cache problems discussed on the list, by changing
the default allowcache back to "no". Some changes to ct_sql.inc,
which should make the code faster and more flexible.

Index: php-lib/CHANGES
diff -u php-lib/CHANGES:1.116 php-lib/CHANGES:1.117
--- php-lib/CHANGES:1.116 Wed Oct 27 08:38:30 1999
+++ php-lib/CHANGES Wed Oct 27 12:41:33 1999
@@ -1,7 +1,12 @@
-$Id: CHANGES,v 1.116 1999/10/27 06:38:30 kk Exp $
+$Id: CHANGES,v 1.117 1999/10/27 10:41:33 kk Exp $
 
 27-Oct-1999 kk
   - Killed all references to shonline.de, I hope.
+ - Andrzej Piasecki <robin <email protected>> requested a default
+ allowcache setting in local.inc. Done.
+ - Teodor Cimpoesu <teo <email protected>> streamlined ct_sql.inc.
+ - default should be allowcache = "no" in Session, or else we
+ get support problems. Sorry about that.
 
 26-Oct-1999 cg
   - Addition of ct_dba.inc, a container for dbm files with database
Index: php-lib/php/ct_sql.inc
diff -u php-lib/php/ct_sql.inc:1.14 php-lib/php/ct_sql.inc:1.15
--- php-lib/php/ct_sql.inc:1.14 Thu Aug 26 12:51:07 1999
+++ php-lib/php/ct_sql.inc Wed Oct 27 12:41:33 1999
@@ -6,7 +6,7 @@
 ##
 ## Copyright (c) 1998,1999 Sascha Schumann <sascha <email protected>>
 ##
-## $Id: ct_sql.inc,v 1.14 1999/08/26 10:51:07 kk Exp $
+## $Id: ct_sql.inc,v 1.15 1999/10/27 10:41:33 kk Exp $
 ##
 ## PHPLIB Data Storage Container using a SQL database
 ##
@@ -21,6 +21,10 @@
   var $database_class = "DB_Sql";
   var $database_lock_semaphore = "";
 
+ var $enc_methods = array(
+ "base64" => array("enc" => "base64_encode", "dec" => "base64_decode"),
+ "slashes" => array("enc" => "addslashes", "dec" => "stripslashes")
+ );
   var $encoding_mode = "base64";
 
   ## end of configuration
@@ -60,21 +64,12 @@
   function ac_store($id, $name, $str) {
     $ret = true;
 
- switch ( $this->encoding_mode ) {
- case "slashes":
- $str = addslashes($name . ":" . $str);
- break;
-
- case "base64":
- default:
- $str = base64_encode($name . ":" . $str);
- };
-
+ #encode > string='method:result'
+ $cmd = $this->enc_methods[$this->encoding_mode]["enc"];
+ $str = sprintf("%s:%s", $this->encoding_mode, $cmd($str));
+
     $name = addslashes($name);
 
- ## update duration of visit
- global $HTTP_REFERER, $HTTP_USER_AGENT, $REMOTE_ADDR;
-
     $now = date("YmdHis", time());
     $uquery = sprintf("update %s set val='%s', changed='%s' where sid='%s' and name='%s'",
       $this->database_table,
@@ -89,8 +84,10 @@
       $str,
       $now);
 
+ # This may look wierd, but SELECTing first and then doing the
+ # right thing would nonatomic (in MySQL, where we cannot SELECT
+ # FOR UPDATE). This is nonatomic, too, but keeps the window small.
     $this->db->query($uquery);
-
     if ( $this->db->affected_rows() == 0
       && !$this->db->query($iquery)) {
         $ret = false;
@@ -106,38 +103,26 @@
   }
 
   function ac_get_value($id, $name) {
- $this->db->query(sprintf("select val from %s where sid = '%s' and name = '%s'",
- $this->database_table,
- $id,
- addslashes($name)));
- if ($this->db->next_record()) {
- $str = $this->db->f("val");
- $str2 = base64_decode( $str );
-
- if ( ereg("^".$name.":.*", $str2) ) {
- $str = ereg_replace("^".$name.":", "", $str2 );
- } else {
-
- $str3 = stripslashes( $str );
-
- if ( ereg("^".$name.":.*", $str3) ) {
- $str = ereg_replace("^".$name.":", "", $str3 );
- } else {
-
- switch ( $this->encoding_mode ) {
- case "slashes":
- $str = stripslashes($str);
- break;
-
- case "base64":
- default:
- $str = base64_decode($str);
- }
- }
- };
- return $str;
- };
- return "";
+
+ $str = '';
+ $this->db->query( sprintf(
+ "SELECT val FROM %s WHERE sid = '%s' AND name = '%s'",
+ $this->database_table, $id, addslashes($name)) );
+
+ if ( $this->db->next_record() ) {
+
+ $str = $this->db->f('val');
+
+ # get encoding method from (method:value) pair
+ $colon_pos = strpos($str,':');
+ $str_method = substr ( $str , 0 , $colon_pos );
+ $str_value = substr ( $str , $colon_pos + 1 );
+
+ $cmd = $this->enc_methods[$str_method]["dec"];
+ $str = $cmd($str_value);
+ }
+
+ return $str;
   }
 
   function ac_newid($str, $name) {
@@ -146,6 +131,17 @@
 
   function ac_halt($s) {
     $this->db->halt($s);
+ }
+
+ ## provide your own encoding/decoding method(s)
+ function set_enc_meth($name, $enc_func, $dec_func) {
+ if (!isset($this->enc_methods[$name])) {
+ $this->enc_methods[$name] = array ('enc'=> $enc_func, 'dec'=> $dec_func) ;
+ }
+ }
+
+ function get_enc_meth($name) {
+ return $this->enc_methods[$name];
   }
 }
 ?>
Index: php-lib/php/local.inc
diff -u php-lib/php/local.inc:1.23 php-lib/php/local.inc:1.24
--- php-lib/php/local.inc:1.23 Wed Aug 25 13:40:48 1999
+++ php-lib/php/local.inc Wed Oct 27 12:41:33 1999
@@ -5,7 +5,7 @@
  * Copyright (c) 1998,1999 SH Online Dienst GmbH
  * Boris Erdmann, Kristian Koehntopp
  *
- * $Id: local.inc,v 1.23 1999/08/25 11:40:48 kk Exp $
+ * $Id: local.inc,v 1.24 1999/10/27 10:41:33 kk Exp $
  *
  */
 
@@ -54,8 +54,9 @@
   var $mode = "cookie"; ## We propagate session IDs with cookies
   var $fallback_mode = "get";
   var $lifetime = 0; ## 0 = do session cookies, else minutes
- var $that_class = "Example_CT_Sql"; ## name of data storage container
+ var $that_class = "Example_CT_Sql"; ## name of data storage container
   var $gc_probability = 5;
+ var $allowcache = "no"; ## "public", "private", or "no"
 }
 
 class Example_User extends User {
Index: php-lib/php/session.inc
diff -u php-lib/php/session.inc:1.49 php-lib/php/session.inc:1.50
--- php-lib/php/session.inc:1.49 Wed Oct 27 08:38:31 1999
+++ php-lib/php/session.inc Wed Oct 27 12:41:33 1999
@@ -5,7 +5,7 @@
  * Copyright (c) 1998,1999 SH Online Dienst GmbH
  * Boris Erdmann, Kristian Koehntopp
  *
- * $Id: session.inc,v 1.49 1999/10/27 06:38:31 kk Exp $
+ * $Id: session.inc,v 1.50 1999/10/27 10:41:33 kk Exp $
  *
  */
 
@@ -30,7 +30,7 @@
   var $secure_auto_init = 1; ## Set to 0 only, if all pages call
                                       ## page_close() guaranteed.
 
- var $allowcache = "private"; ## Set this to 'private' to allow private
+ var $allowcache = "no"; ## Set this to 'private' to allow private
                                       ## caching; set this to 'public' to allow
                                       ## public caching; set this to 'no' to
                                       ## never cache the page.

-
PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
the body, not the subject, of your message.