[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c sqlite.c

2004-03-07 Thread Ilia Alshanetsky
iliaa   Sun Mar  7 16:57:51 2004 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c sqlite.c 
  Log:
  Corrected string escape calculation.
  
  
http://cvs.php.net/diff.php/php-src/ext/sqlite/sess_sqlite.c?r1=1.14r2=1.15ty=u
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.14 php-src/ext/sqlite/sess_sqlite.c:1.15
--- php-src/ext/sqlite/sess_sqlite.c:1.14   Sat Mar  6 13:11:59 2004
+++ php-src/ext/sqlite/sess_sqlite.cSun Mar  7 16:57:50 2004
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.14 2004/03/06 18:11:59 iliaa Exp $ */
+/* $Id: sess_sqlite.c,v 1.15 2004/03/07 21:57:50 iliaa Exp $ */
 
 #include php.h
 
@@ -142,7 +142,7 @@

t = time(NULL);
 
-   binary = emalloc(1 + 5 + vallen * (256 / 253));
+   binary = emalloc(1 + 5 + vallen * ((float) 256 / (float) 253));
binlen = sqlite_encode_binary((const unsigned char*)val, vallen, binary);

rv = sqlite_exec_printf(db, REPLACE INTO session_data VALUES('%q', '%q', 
%d), NULL, NULL, error, key, binary, t);
http://cvs.php.net/diff.php/php-src/ext/sqlite/sqlite.c?r1=1.128r2=1.129ty=u
Index: php-src/ext/sqlite/sqlite.c
diff -u php-src/ext/sqlite/sqlite.c:1.128 php-src/ext/sqlite/sqlite.c:1.129
--- php-src/ext/sqlite/sqlite.c:1.128   Sat Mar  6 13:29:54 2004
+++ php-src/ext/sqlite/sqlite.c Sun Mar  7 16:57:50 2004
@@ -17,7 +17,7 @@
|  Marcus Boerger [EMAIL PROTECTED]  |
+--+
 
-   $Id: sqlite.c,v 1.128 2004/03/06 18:29:54 iliaa Exp $ 
+   $Id: sqlite.c,v 1.129 2004/03/07 21:57:50 iliaa Exp $ 
 */
 
 #ifdef HAVE_CONFIG_H
@@ -1054,7 +1054,7 @@
 {
php_info_print_table_start();
php_info_print_table_header(2, SQLite support, enabled);
-   php_info_print_table_row(2, PECL Module version, PHP_SQLITE_MODULE_VERSION  
$Id: sqlite.c,v 1.128 2004/03/06 18:29:54 iliaa Exp $);
+   php_info_print_table_row(2, PECL Module version, PHP_SQLITE_MODULE_VERSION  
$Id: sqlite.c,v 1.129 2004/03/07 21:57:50 iliaa Exp $);
php_info_print_table_row(2, SQLite Library, sqlite_libversion());
php_info_print_table_row(2, SQLite Encoding, sqlite_libencoding());
php_info_print_table_end();
@@ -2611,7 +2611,7 @@
/* binary string */
int enclen;

-   ret = emalloc( 1 + 5 + stringlen * (256 / 253) );
+   ret = emalloc( 1 + 5 + stringlen * ((float) 256 / (float) 253) );
ret[0] = '\x01';
enclen = php_sqlite_encode_binary(string, stringlen, ret+1);
RETVAL_STRINGL(ret, enclen+1, 0);
@@ -2841,7 +2841,7 @@
int enclen;
char *ret;

-   ret = emalloc( 1 + 5 + datalen * (256 / 253) );
+   ret = emalloc( 1 + 5 + datalen * ((float) 256 / (float) 253) );
ret[0] = '\x01';
enclen = php_sqlite_encode_binary(data, datalen, ret+1);
RETVAL_STRINGL(ret, enclen+1, 0);

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



Re: [PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c sqlite.c

2004-03-07 Thread Andi Gutmans
Why not just do (256.0 / 253.0)?

At 09:57 PM 3/7/2004 +, Ilia Alshanetsky wrote:
iliaa   Sun Mar  7 16:57:51 2004 EDT

  Modified files:
/php-src/ext/sqlite sess_sqlite.c sqlite.c
  Log:
  Corrected string escape calculation.
http://cvs.php.net/diff.php/php-src/ext/sqlite/sess_sqlite.c?r1=1.14r2=1.15ty=u
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.14 
php-src/ext/sqlite/sess_sqlite.c:1.15
--- php-src/ext/sqlite/sess_sqlite.c:1.14   Sat Mar  6 13:11:59 2004
+++ php-src/ext/sqlite/sess_sqlite.cSun Mar  7 16:57:50 2004
@@ -17,7 +17,7 @@
+--+
  */

-/* $Id: sess_sqlite.c,v 1.14 2004/03/06 18:11:59 iliaa Exp $ */
+/* $Id: sess_sqlite.c,v 1.15 2004/03/07 21:57:50 iliaa Exp $ */
 #include php.h

@@ -142,7 +142,7 @@

t = time(NULL);

-   binary = emalloc(1 + 5 + vallen * (256 / 253));
+   binary = emalloc(1 + 5 + vallen * ((float) 256 / (float) 253));
binlen = sqlite_encode_binary((const unsigned char*)val, vallen, 
binary);

rv = sqlite_exec_printf(db, REPLACE INTO session_data 
VALUES('%q', '%q', %d), NULL, NULL, error, key, binary, t);
http://cvs.php.net/diff.php/php-src/ext/sqlite/sqlite.c?r1=1.128r2=1.129ty=u
Index: php-src/ext/sqlite/sqlite.c
diff -u php-src/ext/sqlite/sqlite.c:1.128 php-src/ext/sqlite/sqlite.c:1.129
--- php-src/ext/sqlite/sqlite.c:1.128   Sat Mar  6 13:29:54 2004
+++ php-src/ext/sqlite/sqlite.c Sun Mar  7 16:57:50 2004
@@ -17,7 +17,7 @@
|  Marcus Boerger [EMAIL PROTECTED]  |
+--+

-   $Id: sqlite.c,v 1.128 2004/03/06 18:29:54 iliaa Exp $
+   $Id: sqlite.c,v 1.129 2004/03/07 21:57:50 iliaa Exp $
 */
 #ifdef HAVE_CONFIG_H
@@ -1054,7 +1054,7 @@
 {
php_info_print_table_start();
php_info_print_table_header(2, SQLite support, enabled);
-   php_info_print_table_row(2, PECL Module version, 
PHP_SQLITE_MODULE_VERSION  $Id: sqlite.c,v 1.128 2004/03/06 18:29:54 
iliaa Exp $);
+   php_info_print_table_row(2, PECL Module version, 
PHP_SQLITE_MODULE_VERSION  $Id: sqlite.c,v 1.129 2004/03/07 21:57:50 
iliaa Exp $);
php_info_print_table_row(2, SQLite Library, sqlite_libversion());
php_info_print_table_row(2, SQLite Encoding, sqlite_libencoding());
php_info_print_table_end();
@@ -2611,7 +2611,7 @@
/* binary string */
int enclen;

-   ret = emalloc( 1 + 5 + stringlen * (256 / 253) );
+   ret = emalloc( 1 + 5 + stringlen * ((float) 256 / (float) 
253) );
ret[0] = '\x01';
enclen = php_sqlite_encode_binary(string, stringlen, ret+1);
RETVAL_STRINGL(ret, enclen+1, 0);
@@ -2841,7 +2841,7 @@
int enclen;
char *ret;

-   ret = emalloc( 1 + 5 + datalen * (256 / 253) );
+   ret = emalloc( 1 + 5 + datalen * ((float) 256 / (float) 
253) );
ret[0] = '\x01';
enclen = php_sqlite_encode_binary(data, datalen, ret+1);
RETVAL_STRINGL(ret, enclen+1, 0);

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


Re: [PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c sqlite.c

2004-03-07 Thread Ilia Alshanetsky
On March 07, 2004 05:03 pm, Andi Gutmans wrote:
 Why not just do (256.0 / 253.0)?

I think an intentional cast is less likely to be removed then a seemingly 
pointless .0. However, I don't feel strongly about either approach and if you 
insist the code can be changed.

Ilia

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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2004-03-07 Thread Sascha Schumann
sas Sun Mar  7 17:35:27 2004 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  Avoid using floating point arithmetic and rely on safe_emalloc
  for the multiplication.
  
  The actual size requirement is spelled out as:
  
  ** The result is written into a preallocated output buffer out.
  ** out must be able to hold at least 2 +(257*n)/254 bytes.
  ** In other words, the output will be expanded by as much as 3
  ** bytes for every 254 bytes of input plus 2 bytes of fixed overhead.
  ** (This is approximately 2 + 1.0118*n or about a 1.2% size increase.)
  
  
http://cvs.php.net/diff.php/php-src/ext/sqlite/sess_sqlite.c?r1=1.15r2=1.16ty=u
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.15 php-src/ext/sqlite/sess_sqlite.c:1.16
--- php-src/ext/sqlite/sess_sqlite.c:1.15   Sun Mar  7 16:57:50 2004
+++ php-src/ext/sqlite/sess_sqlite.cSun Mar  7 17:35:26 2004
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.15 2004/03/07 21:57:50 iliaa Exp $ */
+/* $Id: sess_sqlite.c,v 1.16 2004/03/07 22:35:26 sas Exp $ */
 
 #include php.h
 
@@ -142,7 +142,7 @@

t = time(NULL);
 
-   binary = emalloc(1 + 5 + vallen * ((float) 256 / (float) 253));
+   binary = safe_emalloc(1 + vallen / 254, 257, 3);
binlen = sqlite_encode_binary((const unsigned char*)val, vallen, binary);

rv = sqlite_exec_printf(db, REPLACE INTO session_data VALUES('%q', '%q', 
%d), NULL, NULL, error, key, binary, t);

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



Re: [PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c sqlite.c

2004-03-07 Thread Andi Gutmans
I don't insist. I just think it's nicer. But it's a matter of taste so it's 
your choice.

At 05:09 PM 3/7/2004 -0500, Ilia Alshanetsky wrote:
On March 07, 2004 05:03 pm, Andi Gutmans wrote:
 Why not just do (256.0 / 253.0)?
I think an intentional cast is less likely to be removed then a seemingly
pointless .0. However, I don't feel strongly about either approach and if you
insist the code can be changed.
Ilia

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


[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2004-03-06 Thread Ilia Alshanetsky
iliaa   Sat Mar  6 13:11:59 2004 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  Fixed possible crash due to an integer overflow.
  
  
http://cvs.php.net/diff.php/php-src/ext/sqlite/sess_sqlite.c?r1=1.13r2=1.14ty=u
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.13 php-src/ext/sqlite/sess_sqlite.c:1.14
--- php-src/ext/sqlite/sess_sqlite.c:1.13   Tue Jan 13 00:23:07 2004
+++ php-src/ext/sqlite/sess_sqlite.cSat Mar  6 13:11:59 2004
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.13 2004/01/13 05:23:07 john Exp $ */
+/* $Id: sess_sqlite.c,v 1.14 2004/03/06 18:11:59 iliaa Exp $ */
 
 #include php.h
 
@@ -142,7 +142,7 @@

t = time(NULL);
 
-   binary = emalloc((256 * vallen + 1262) / 253);
+   binary = emalloc(1 + 5 + vallen * (256 / 253));
binlen = sqlite_encode_binary((const unsigned char*)val, vallen, binary);

rv = sqlite_exec_printf(db, REPLACE INTO session_data VALUES('%q', '%q', 
%d), NULL, NULL, error, key, binary, t);
@@ -177,7 +177,7 @@
 
/* because SQLite does not actually clear the deleted data from the database 
 * we need to occassionaly do so manually to prevent the sessions database 
-* from endlessly growing.
+* from growing endlessly.
 */
if ((int) ((float) PS(gc_divisor) * PS(gc_divisor) * 
php_combined_lcg(TSRMLS_C))  PS(gc_probability)) {
rv = sqlite_exec_printf(db, VACUUM, NULL, NULL, NULL);

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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2004-01-12 Thread Ilia Alshanetsky
iliaa   Mon Jan 12 17:48:59 2004 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  Fixed a bug that would cause the sqlite session database to grow endlessly.
  
  
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.11 php-src/ext/sqlite/sess_sqlite.c:1.12
--- php-src/ext/sqlite/sess_sqlite.c:1.11   Thu Jan  8 03:17:29 2004
+++ php-src/ext/sqlite/sess_sqlite.cMon Jan 12 17:48:58 2004
@@ -17,13 +17,14 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.11 2004/01/08 08:17:29 andi Exp $ */
+/* $Id: sess_sqlite.c,v 1.12 2004/01/12 22:48:58 iliaa Exp $ */
 
 #include php.h
 
 #if HAVE_PHP_SESSION
 
 #include ext/session/php_session.h
+#include ext/standard/php_lcg.h
 #include sqlite.h
 #define SQLITE_RETVAL(__r) ((__r) == SQLITE_OK ? SUCCESS : FAILURE)
 #define PS_SQLITE_DATA sqlite *db = (sqlite*)PS_GET_MOD_DATA()
@@ -173,7 +174,14 @@
rv = sqlite_exec_printf(db, 
DELETE FROM session_data WHERE (%d - updated)  %d, 
NULL, NULL, NULL, t, maxlifetime);
-   
+
+   /* because SQLite does not actually clear the deleted data from the database 
+* we need to occassionaly do so manually to prevent the sessions database 
+* from endlessly growing.
+*/
+   if ((int) ((float) PS(gc_divisor) * PS(gc_divisor) * 
php_combined_lcg(TSRMLS_C))  PS(gc_probability) {
+   rv = sqlite_exec_printf(db, VACUUM, NULL, NULL, NULL);
+   }
return SQLITE_RETVAL(rv);
 }
 

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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2004-01-12 Thread John Coggeshall
johnTue Jan 13 00:23:08 2004 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  Whoops... Ilia forgot a ')'
  
  
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.12 php-src/ext/sqlite/sess_sqlite.c:1.13
--- php-src/ext/sqlite/sess_sqlite.c:1.12   Mon Jan 12 17:48:58 2004
+++ php-src/ext/sqlite/sess_sqlite.cTue Jan 13 00:23:07 2004
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.12 2004/01/12 22:48:58 iliaa Exp $ */
+/* $Id: sess_sqlite.c,v 1.13 2004/01/13 05:23:07 john Exp $ */
 
 #include php.h
 
@@ -179,7 +179,7 @@
 * we need to occassionaly do so manually to prevent the sessions database 
 * from endlessly growing.
 */
-   if ((int) ((float) PS(gc_divisor) * PS(gc_divisor) * 
php_combined_lcg(TSRMLS_C))  PS(gc_probability) {
+   if ((int) ((float) PS(gc_divisor) * PS(gc_divisor) * 
php_combined_lcg(TSRMLS_C))  PS(gc_probability)) {
rv = sqlite_exec_printf(db, VACUUM, NULL, NULL, NULL);
}
return SQLITE_RETVAL(rv);

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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2003-07-02 Thread Marcus Boerger
helly   Wed Jul  2 17:40:55 2003 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  funny fixes
  
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.9 php-src/ext/sqlite/sess_sqlite.c:1.10
--- php-src/ext/sqlite/sess_sqlite.c:1.9Tue Jul  1 23:12:06 2003
+++ php-src/ext/sqlite/sess_sqlite.cWed Jul  2 17:40:54 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.9 2003/07/02 03:12:06 sterling Exp $ */
+/* $Id: sess_sqlite.c,v 1.10 2003/07/02 21:40:54 helly Exp $ */
 
 #include php.h
 
@@ -151,7 +151,7 @@
}
efree(binary);
 
-   SQLITE_RETVAL(rv);
+   return SQLITE_RETVAL(rv);
 }
 
 PS_DESTROY_FUNC(sqlite) 
@@ -161,7 +161,7 @@
 
rv = sqlite_exec_printf(db, DELETE FROM session_data WHERE sess_id='%q', 
NULL, NULL, NULL, key);

-   SQLITE_RETVAL(rv);return rv == SQLITE_OK ? SUCCESS : FAILURE;
+   return SQLITE_RETVAL(rv);
 }
 
 PS_GC_FUNC(sqlite) 
@@ -174,7 +174,7 @@
DELETE FROM session_data WHERE (%d - updated)  %d, 
NULL, NULL, NULL, t, maxlifetime);

-   SQLITE_RETVAL(rv);
+   return SQLITE_RETVAL(rv);
 }
 
 #endif /* HAVE_PHP_SESSION */



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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2003-07-01 Thread Wez Furlong
wez Tue Jul  1 09:09:57 2003 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  WS
  
  
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.1 php-src/ext/sqlite/sess_sqlite.c:1.2
--- php-src/ext/sqlite/sess_sqlite.c:1.1Tue Jul  1 09:07:37 2003
+++ php-src/ext/sqlite/sess_sqlite.cTue Jul  1 09:09:57 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.1 2003/07/01 13:07:37 wez Exp $ */
+/* $Id: sess_sqlite.c,v 1.2 2003/07/01 13:09:57 wez Exp $ */
 
 #include php.h
 #include ext/session/php_session.h
@@ -71,9 +71,9 @@
 
 PS_OPEN_FUNC(sqlite) 
 {
-char *filepath;
+   char *filepath;
char *errmsg = NULL;
-int spath_len, sname_len, fp_len;
+   int spath_len, sname_len, fp_len;
sqlite *db;
 
/* TODO: do we need a safe_mode check here? */
@@ -86,14 +86,14 @@
 
/* allow up to 1 minute when busy */
sqlite_busy_timeout(db, 6);
-
-/* This will fail if the table already exists, but that's not a big problem. I'm
-unclear as to how to check for a table's existence in SQLite -- that would be 
better here. */
-sqlite_exec(db, CREATE_TBL_QUERY, NULL, NULL, NULL);
-
-PS_SET_MOD_DATA(db);
 
-return SUCCESS;
+   /* This will fail if the table already exists, but that's not a big problem. 
I'm
+  unclear as to how to check for a table's existence in SQLite -- that would 
be better here. */
+   sqlite_exec(db, CREATE_TBL_QUERY, NULL, NULL, NULL);
+
+   PS_SET_MOD_DATA(db);
+
+   return SUCCESS;
 }
 
 PS_CLOSE_FUNC(sqlite) 



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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c sqlite.c

2003-07-01 Thread Marcus Boerger
helly   Tue Jul  1 13:55:32 2003 EDT

  Modified files:  
/php-src/ext/sqlite sqlite.c sess_sqlite.c 
  Log:
  Fix warnings and allow builds without ext/session
  
Index: php-src/ext/sqlite/sqlite.c
diff -u php-src/ext/sqlite/sqlite.c:1.68 php-src/ext/sqlite/sqlite.c:1.69
--- php-src/ext/sqlite/sqlite.c:1.68Tue Jul  1 09:26:49 2003
+++ php-src/ext/sqlite/sqlite.c Tue Jul  1 13:55:32 2003
@@ -17,7 +17,7 @@
|  Marcus Boerger [EMAIL PROTECTED]  |
+--+
 
-   $Id: sqlite.c,v 1.68 2003/07/01 13:26:49 wez Exp $ 
+   $Id: sqlite.c,v 1.69 2003/07/01 17:55:32 helly Exp $ 
 */
 
 #ifdef HAVE_CONFIG_H
@@ -58,8 +58,10 @@
 
 ZEND_DECLARE_MODULE_GLOBALS(sqlite)
 
+#if HAVE_PHP_SESSION
 extern ps_module ps_mod_sqlite;
 #define ps_sqlite_ptr ps_mod_sqlite
+#endif
 
 extern int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out);
 extern int sqlite_decode_binary(const unsigned char *in, unsigned char *out);
@@ -882,7 +884,9 @@
 
REGISTER_INI_ENTRIES();
 
+#if HAVE_PHP_SESSION
php_session_register_module(ps_sqlite_ptr);
+#endif

le_sqlite_db = zend_register_list_destructors_ex(php_sqlite_db_dtor, NULL, 
sqlite database, module_number);
le_sqlite_pdb = zend_register_list_destructors_ex(NULL, php_sqlite_db_dtor, 
sqlite database (persistent), module_number);
@@ -944,7 +948,7 @@
 {
php_info_print_table_start();
php_info_print_table_header(2, SQLite support, enabled);
-   php_info_print_table_row(2, PECL Module version, PHP_SQLITE_MODULE_VERSION  
$Id: sqlite.c,v 1.68 2003/07/01 13:26:49 wez Exp $);
+   php_info_print_table_row(2, PECL Module version, PHP_SQLITE_MODULE_VERSION  
$Id: sqlite.c,v 1.69 2003/07/01 17:55:32 helly Exp $);
php_info_print_table_row(2, SQLite Library, sqlite_libversion());
php_info_print_table_row(2, SQLite Encoding, sqlite_libencoding());
php_info_print_table_end();
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.2 php-src/ext/sqlite/sess_sqlite.c:1.3
--- php-src/ext/sqlite/sess_sqlite.c:1.2Tue Jul  1 09:09:57 2003
+++ php-src/ext/sqlite/sess_sqlite.cTue Jul  1 13:55:32 2003
@@ -17,9 +17,12 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.2 2003/07/01 13:09:57 wez Exp $ */
+/* $Id: sess_sqlite.c,v 1.3 2003/07/01 17:55:32 helly Exp $ */
 
 #include php.h
+
+#if HAVE_PHP_SESSION
+
 #include ext/session/php_session.h
 #include sqlite.h
 
@@ -71,9 +74,7 @@
 
 PS_OPEN_FUNC(sqlite) 
 {
-   char *filepath;
char *errmsg = NULL;
-   int spath_len, sname_len, fp_len;
sqlite *db;
 
/* TODO: do we need a safe_mode check here? */
@@ -202,6 +203,8 @@
return SQLITE_OK == sqlite_exec_printf(db, GC_QUERY, NULL, NULL, NULL, t, 
maxlifetime) ?
SUCCESS : FAILURE;
 }
+
+#endif /* HAVE_PHP_SESSION */
 
 /*
  * Local variables:



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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2003-07-01 Thread Sterling Hughes
sterlingTue Jul  1 20:03:41 2003 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  make this actually work.
  
  
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.3 php-src/ext/sqlite/sess_sqlite.c:1.4
--- php-src/ext/sqlite/sess_sqlite.c:1.3Tue Jul  1 13:55:32 2003
+++ php-src/ext/sqlite/sess_sqlite.cTue Jul  1 20:03:41 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.3 2003/07/01 17:55:32 helly Exp $ */
+/* $Id: sess_sqlite.c,v 1.4 2003/07/02 00:03:41 sterling Exp $ */
 
 #include php.h
 
@@ -88,6 +88,8 @@
/* allow up to 1 minute when busy */
sqlite_busy_timeout(db, 6);
 
+   /* sqlite_exec(db, PRAGMA default_synchronous = OFF, NULL, NULL, NULL); */
+   
/* This will fail if the table already exists, but that's not a big problem. 
I'm
   unclear as to how to check for a table's existence in SQLite -- that would 
be better here. */
sqlite_exec(db, CREATE_TBL_QUERY, NULL, NULL, NULL);
@@ -110,11 +112,15 @@
 {
PS_SQLITE_DATA;
char *query;
+   const char *tail;
sqlite_vm *vm;
int colcount, result;
const char **rowdata, **colnames;
char *error;
 
+   *val = NULL;
+   *vallen = 0;
+   
if (!ps_sqlite_valid_key(key)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, SQLite: The session id 
contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,');
return FAILURE;
@@ -126,7 +132,7 @@
return FAILURE;
}
 
-   if (sqlite_compile(db, query, NULL, vm, error) != SQLITE_OK) {
+   if (sqlite_compile(db, query, tail, vm, error) != SQLITE_OK) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, SQLite: Could not compile 
session read query: %s, error);
sqlite_freemem(error);
sqlite_freemem(query);
@@ -135,10 +141,7 @@
 
switch ((result = sqlite_step(vm, colcount, rowdata, colnames))) {
case SQLITE_ROW:
-   if (rowdata[0] == NULL) {
-   *vallen = 0;
-   *val = NULL;
-   } else {
+   if (rowdata[0] != NULL) {
*vallen = strlen(rowdata[0]);
*val = emalloc(*vallen);
*vallen = sqlite_decode_binary(rowdata[0], *val);
@@ -146,7 +149,7 @@
}
break;
default:
-   php_error_docref(NULL TSRMLS_CC, E_WARNING, SQLite: session 
read query failed: %s, error);
+   //php_error_docref(NULL TSRMLS_CC, E_WARNING, SQLite: session 
read query failed: %s, error);
sqlite_freemem(error);
error = NULL;
}



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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2003-07-01 Thread Sterling Hughes
sterlingTue Jul  1 20:04:58 2003 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  no c++ style comments
  
  
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.4 php-src/ext/sqlite/sess_sqlite.c:1.5
--- php-src/ext/sqlite/sess_sqlite.c:1.4Tue Jul  1 20:03:41 2003
+++ php-src/ext/sqlite/sess_sqlite.cTue Jul  1 20:04:58 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.4 2003/07/02 00:03:41 sterling Exp $ */
+/* $Id: sess_sqlite.c,v 1.5 2003/07/02 00:04:58 sterling Exp $ */
 
 #include php.h
 
@@ -149,7 +149,6 @@
}
break;
default:
-   //php_error_docref(NULL TSRMLS_CC, E_WARNING, SQLite: session 
read query failed: %s, error);
sqlite_freemem(error);
error = NULL;
}



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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2003-07-01 Thread Sterling Hughes
sterlingTue Jul  1 20:43:00 2003 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  set synching to off
  cleanup some silly code
  
  
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.5 php-src/ext/sqlite/sess_sqlite.c:1.6
--- php-src/ext/sqlite/sess_sqlite.c:1.5Tue Jul  1 20:04:58 2003
+++ php-src/ext/sqlite/sess_sqlite.cTue Jul  1 20:43:00 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.5 2003/07/02 00:04:58 sterling Exp $ */
+/* $Id: sess_sqlite.c,v 1.6 2003/07/02 00:43:00 sterling Exp $ */
 
 #include php.h
 
@@ -25,17 +25,11 @@
 
 #include ext/session/php_session.h
 #include sqlite.h
-
+#define SQLITE_RETVAL(__r) ((__r) == SQLITE_OK ? SUCCESS : FAILURE)
 #define PS_SQLITE_DATA sqlite *db = (sqlite*)PS_GET_MOD_DATA()
 extern int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out);
 extern int sqlite_decode_binary(const unsigned char *in, unsigned char *out);
 
-#define CREATE_TBL_QUERY   CREATE TABLE session_data(sess_id TEXT PRIMARY KEY, 
value TEXT, updated INTEGER)
-#define INSERT_QUERY   REPLACE INTO session_data VALUES('%q', '%q', %d)
-#define SELECT_QUERY   SELECT value FROM session_data WHERE sess_id='%q' 
LIMIT 1
-#define GC_QUERY   DELETE FROM session_data WHERE (%d - updated) 
 %d
-#define DELETE_QUERY   DELETE FROM session_data WHERE sess_id='%q'
-
 PS_FUNCS(sqlite);
 
 ps_module ps_mod_sqlite = {
@@ -88,11 +82,15 @@
/* allow up to 1 minute when busy */
sqlite_busy_timeout(db, 6);
 
-   /* sqlite_exec(db, PRAGMA default_synchronous = OFF, NULL, NULL, NULL); */
+   sqlite_exec(db, PRAGMA default_synchronous = OFF, NULL, NULL, NULL);

/* This will fail if the table already exists, but that's not a big problem. 
I'm
   unclear as to how to check for a table's existence in SQLite -- that would 
be better here. */
-   sqlite_exec(db, CREATE_TBL_QUERY, NULL, NULL, NULL);
+   sqlite_exec(db, 
+   CREATE TABLE session_data (
+  sess_id TEXT PRIMARY KEY, 
+   value TEXT, updated INTEGER 
+   ), NULL, NULL, NULL);
 
PS_SET_MOD_DATA(db);
 
@@ -126,7 +124,7 @@
return FAILURE;
}
 
-   query = sqlite_mprintf(SELECT_QUERY, key);
+   query = sqlite_mprintf(SELECT value FROM session_data WHERE sess_id='%q' 
LIMIT 1, key);
if (query == NULL) {
/* no memory */
return FAILURE;
@@ -168,42 +166,47 @@
 {
PS_SQLITE_DATA;
char *error;
-   int result = SUCCESS;
time_t t;
char *binary;
int binlen;
+   int rv;

t = time(NULL);
 
binary = emalloc((256 * vallen + 1262) / 253);
binlen = sqlite_encode_binary((const unsigned char*)val, vallen, binary);

-   if (SQLITE_OK != sqlite_exec_printf(db, INSERT_QUERY, NULL, NULL, error, key, 
binary, t)) {
+   rv = sqlite_exec_printf(db, REPLACE INTO session_data VALUES('%q', '%q', 
%d), NULL, NULL, error, key, binary, t);
+   if (rv != SQLITE_OK) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, SQLite: session write 
query failed: %s, error);
sqlite_freemem(error);
-   result = FAILURE;
}
-
efree(binary);
 
-   return result;
+   SQLITE_RETVAL(rv);
 }
 
 PS_DESTROY_FUNC(sqlite) 
 {
+   int rv;
PS_SQLITE_DATA;
 
-   return SQLITE_OK == sqlite_exec_printf(db, DELETE_QUERY, NULL, NULL, NULL, 
key) ?
-   SUCCESS : FAILURE;
+   rv = sqlite_exec_printf(db, DELETE FROM session_data WHERE sess_id='%q', 
NULL, NULL, NULL, key);
+   
+   SQLITE_RETVAL(rv);return rv == SQLITE_OK ? SUCCESS : FAILURE;
 }
 
 PS_GC_FUNC(sqlite) 
 {
PS_SQLITE_DATA;
+   int rv;
time_t t = time(NULL);
 
-   return SQLITE_OK == sqlite_exec_printf(db, GC_QUERY, NULL, NULL, NULL, t, 
maxlifetime) ?
-   SUCCESS : FAILURE;
+   rv = sqlite_exec_printf(db, 
+   DELETE FROM session_data WHERE (%d - updated)  %d, 
+   NULL, NULL, NULL, t, maxlifetime);
+   
+   SQLITE_RETVAL(rv);
 }
 
 #endif /* HAVE_PHP_SESSION */



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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2003-07-01 Thread Sterling Hughes
sterlingTue Jul  1 20:45:16 2003 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  ws fix
  
  
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.6 php-src/ext/sqlite/sess_sqlite.c:1.7
--- php-src/ext/sqlite/sess_sqlite.c:1.6Tue Jul  1 20:43:00 2003
+++ php-src/ext/sqlite/sess_sqlite.cTue Jul  1 20:45:15 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.6 2003/07/02 00:43:00 sterling Exp $ */
+/* $Id: sess_sqlite.c,v 1.7 2003/07/02 00:45:15 sterling Exp $ */
 
 #include php.h
 
@@ -88,7 +88,7 @@
   unclear as to how to check for a table's existence in SQLite -- that would 
be better here. */
sqlite_exec(db, 
CREATE TABLE session_data (
-  sess_id TEXT PRIMARY KEY, 
+   sess_id TEXT PRIMARY KEY, 
value TEXT, updated INTEGER 
), NULL, NULL, NULL);
 



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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2003-07-01 Thread Sterling Hughes
sterlingTue Jul  1 20:56:32 2003 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  not necessary, already assumed binary safe (it has to be under the current
  session architecture), and anything else is fair play
  
  
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.7 php-src/ext/sqlite/sess_sqlite.c:1.8
--- php-src/ext/sqlite/sess_sqlite.c:1.7Tue Jul  1 20:45:15 2003
+++ php-src/ext/sqlite/sess_sqlite.cTue Jul  1 20:56:32 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.7 2003/07/02 00:45:15 sterling Exp $ */
+/* $Id: sess_sqlite.c,v 1.8 2003/07/02 00:56:32 sterling Exp $ */
 
 #include php.h
 
@@ -36,36 +36,6 @@
PS_MOD(sqlite)
 };
 
-/* If you change the logic here, please also update the error message in
- * ps_sqlite_open() appropriately (code taken from ps_files_valid_key()) */
-
-static int ps_sqlite_valid_key(const char *key)
-{
-   size_t len;
-   const char *p;
-   char c;
-   int ret = 1;
-
-   for (p = key; (c = *p); p++) {
-   /* valid characters are a..z,A..Z,0..9 */
-   if (!((c = 'a'  c = 'z')
-   || (c = 'A'  c = 'Z')
-   || (c = '0'  c = '9')
-   || c == ','
-   || c == '-')) {
-   ret = 0;
-   break;
-   }
-   }
-
-   len = p - key;
-   
-   if (len == 0)
-   ret = 0;
-   
-   return ret;
-}
-
 PS_OPEN_FUNC(sqlite) 
 {
char *errmsg = NULL;
@@ -119,11 +89,6 @@
*val = NULL;
*vallen = 0;

-   if (!ps_sqlite_valid_key(key)) {
-   php_error_docref(NULL TSRMLS_CC, E_WARNING, SQLite: The session id 
contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,');
-   return FAILURE;
-   }
-
query = sqlite_mprintf(SELECT value FROM session_data WHERE sess_id='%q' 
LIMIT 1, key);
if (query == NULL) {
/* no memory */



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



[PHP-CVS] cvs: php-src /ext/sqlite sess_sqlite.c

2003-07-01 Thread Sterling Hughes
sterlingTue Jul  1 23:12:06 2003 EDT

  Modified files:  
/php-src/ext/sqlite sess_sqlite.c 
  Log:
  further improve the performance and clean up
  
  
Index: php-src/ext/sqlite/sess_sqlite.c
diff -u php-src/ext/sqlite/sess_sqlite.c:1.8 php-src/ext/sqlite/sess_sqlite.c:1.9
--- php-src/ext/sqlite/sess_sqlite.c:1.8Tue Jul  1 20:56:32 2003
+++ php-src/ext/sqlite/sess_sqlite.cTue Jul  1 23:12:06 2003
@@ -17,7 +17,7 @@
+--+
  */
 
-/* $Id: sess_sqlite.c,v 1.8 2003/07/02 00:56:32 sterling Exp $ */
+/* $Id: sess_sqlite.c,v 1.9 2003/07/02 03:12:06 sterling Exp $ */
 
 #include php.h
 
@@ -44,7 +44,8 @@
/* TODO: do we need a safe_mode check here? */
db = sqlite_open(save_path, 0666, errmsg);
if (db == NULL) {
-   php_error_docref(NULL TSRMLS_CC, E_WARNING, SQLite: failed to 
open/create session database `%s' - %s, save_path, errmsg);
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, 
+   SQLite: failed to open/create session database `%s' - 
%s, save_path, errmsg);
sqlite_freemem(errmsg);
return FAILURE;
}
@@ -53,13 +54,15 @@
sqlite_busy_timeout(db, 6);
 
sqlite_exec(db, PRAGMA default_synchronous = OFF, NULL, NULL, NULL);
-   
+   sqlite_exec(db, PRAGMA count_changes = OFF, NULL, NULL, NULL);
+
/* This will fail if the table already exists, but that's not a big problem. 
I'm
   unclear as to how to check for a table's existence in SQLite -- that would 
be better here. */
sqlite_exec(db, 
CREATE TABLE session_data (
-   sess_id TEXT PRIMARY KEY, 
-   value TEXT, updated INTEGER 
+   sess_id PRIMARY KEY, 
+   value TEXT, 
+   updated INTEGER 
), NULL, NULL, NULL);
 
PS_SET_MOD_DATA(db);



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