Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:780 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11870 invoked from network); 8 Apr 2003 08:46:01 -0000 Received: from unknown (HELO mail.sogei.it) (195.223.91.164) by pb1.pair.com with SMTP; 8 Apr 2003 08:46:01 -0000 Received: from mailfilter01.domus.ad.sogei.it (mailfilter01.sogei.it [26.2.193.99]) by mail.sogei.it (8.11.4/8.8.4) with SMTP id h385GgW16636 for ; Tue, 8 Apr 2003 07:16:42 +0200 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 Date: Tue, 8 Apr 2003 10:45:51 +0200 Message-ID: <7410A5117CDC9C4CA07FBC870D65A50D111CE7@MAILBOX01.domus.ad.sogei.it> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PHP-DEV] [PATCH] OCI8 module - proposed patches (PART 1 of 2) Thread-Index: AcL9XUz6AVfJvrIXQtm19y464Qr/wAAS+cZA To: "Jani Taskinen" Cc: Subject: R: [PHP-DEV] [PATCH] OCI8 module - proposed patches (PART 1 of 2) From: msquillace@sogei.it ("SQUILLACE MASSIMO") > Nice patches, but could you please provide ones without > the whitespace changes? Now it's not very clear what you > have actually changed.. > =20 > --Jani Sure. I followed the instructions in README.SUBMITTING_PATCH and only had "diff -u" in my .cvsrc. Now I have "diff -uw" and hope this is what you expect. Massimo *-----------------* ? twobugs.txt Index: oci8.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /repository/php4/ext/oci8/oci8.c,v retrieving revision 1.205 diff -u -w -r1.205 oci8.c --- oci8.c 18 Mar 2003 12:06:00 -0000 1.205 +++ oci8.c 8 Apr 2003 07:24:46 -0000 @@ -2153,6 +2153,8 @@ oci_session *session =3D 0, *psession =3D 0; OCISvcCtx *svchp =3D 0; char *hashed_details; + struct timeval tv; + int sec, usec; #ifdef HAVE_OCI9 ub2 charsetid; #endif @@ -2164,9 +2166,10 @@ we will reuse authenticated users within a request no matter if the user requested a persistent=20 connections or not! =20 - but only as pesistent requested connections will be kept between requests! + but only as persistent requested connections will be kept between requests! */ =20 + if (! exclusive) { hashed_details =3D (char *) malloc(strlen(SAFE_STRING(username))+ =20 strlen(SAFE_STRING(password))+ =20 strlen(SAFE_STRING(server->dbname))+1); @@ -2176,7 +2179,6 @@ SAFE_STRING(password), SAFE_STRING(server->dbname)); =20 - if (! exclusive) { zend_hash_find(OCI(user), hashed_details, strlen(hashed_details)+1, (void **) &session); =20 if (session) { @@ -2191,6 +2193,14 @@ /* breakthru to open */ } } + } else { + gettimeofday((struct timeval *) &tv, (struct timezone *) NULL); + sec =3D (int) tv.tv_sec; + usec =3D (int) (tv.tv_usec % 1000000); + /* The max value usec can have is 0xF423F, so we use only five hex + digits for usec and eigth hex digits for sec. */ + hashed_details =3D (char *) malloc(8+5+1); /* always enough */ + sprintf(hashed_details, "%08x%05x", tv.tv_sec, tv.tv_usec); } =20 session =3D calloc(1,sizeof(oci_session)); @@ -2676,7 +2686,7 @@ persistent =3D 0; } else { /* if our server-context is not persistent we can't */ - persistent =3D server->persistent;=20 + persistent =3D (server->persistent) ? persistent : 0; } =20 session =3D _oci_open_session(server,username,password,persistent,exclusive,charset) ; *-----------------* ? fourpatches.txt Index: oci8.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /repository/php4/ext/oci8/oci8.c,v retrieving revision 1.205 diff -u -w -r1.205 oci8.c --- oci8.c 18 Mar 2003 12:06:00 -0000 1.205 +++ oci8.c 8 Apr 2003 07:20:12 -0000 @@ -59,6 +59,7 @@ #endif =20 #include "php.h" +#include "php_ini.h" #include "ext/standard/info.h" =20 /* #define HAVE_OCI8_TEMP_LOB 1 */ @@ -431,6 +432,15 @@ #endif =20 /* }}} */ + +/* {{{ PHP_INI + */ +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY_EX("oci8.connection_timeout", "-1", PHP_INI_SYSTEM, OnUpdateInt, connection_timeout, php_oci_globals, oci_globals, display_link_numbers) + STD_PHP_INI_BOOLEAN("oci8.credentials_toupper", "0", PHP_INI_SYSTEM, OnUpdateBool, credentials_toupper, php_oci_globals, oci_globals) +PHP_INI_END() +/* }}} */ + /* {{{ startup, shutdown and info functions */ =20 static void php_oci_init_globals(php_oci_globals *oci_globals_p TSRMLS_DC) @@ -495,6 +505,8 @@ php_oci_init_globals(&oci_globals TSRMLS_CC); #endif =20 + REGISTER_INI_ENTRIES(); + le_stmt =3D zend_register_list_destructors_ex(_oci_stmt_list_dtor, NULL, "oci8 statement", module_number); le_conn =3D zend_register_list_destructors_ex(php_oci_free_conn_list, NULL, "oci8 connection", module_number); le_desc =3D zend_register_list_destructors_ex(_oci_descriptor_list_dtor, NULL, "oci8 descriptor", module_number); @@ -566,6 +578,22 @@ /* ----------------------------------------------------------------- */ =20 =20 +static int _session_rcleanup(oci_session *session TSRMLS_DC) +{ + if ((OCI(current_timestamp) - OCI(connection_timeout)) > session->server->timestamp) { + _oci_close_session(session); + } + return 0; +} + +static int _server_rcleanup(oci_server *server TSRMLS_DC) +{ + if ((OCI(current_timestamp) - OCI(connection_timeout)) > server->timestamp) { + _oci_close_server(server); + } + return 0; +} + PHP_RINIT_FUNCTION(oci) { /* XXX NYI @@ -578,6 +606,13 @@ =20 oci_debug("php_rinit_oci"); =20 + /* close all timed out connections (if check is enabled) */ + if (-1 !=3D OCI(connection_timeout)) { + OCI(current_timestamp) =3D time(NULL); + zend_hash_apply(OCI(user), (apply_func_t)_session_rcleanup TSRMLS_CC); + zend_hash_apply(OCI(server), (apply_func_t)_server_rcleanup TSRMLS_CC); + } + return SUCCESS; } =20 @@ -597,6 +632,8 @@ =20 PHP_MSHUTDOWN_FUNCTION(oci) { + UNREGISTER_INI_ENTRIES(); + OCI(shutdown) =3D 1; =20 oci_debug("START php_mshutdown_oci"); @@ -649,6 +686,8 @@ #endif php_info_print_table_end(); =20 + DISPLAY_INI_ENTRIES(); + } =20 /* }}} */ @@ -2153,6 +2192,8 @@ oci_session *session =3D 0, *psession =3D 0; OCISvcCtx *svchp =3D 0; char *hashed_details; + struct timeval tv; + int sec, usec; #ifdef HAVE_OCI9 ub2 charsetid; #endif @@ -2164,9 +2205,10 @@ we will reuse authenticated users within a request no matter if the user requested a persistent=20 connections or not! =20 - but only as pesistent requested connections will be kept between requests! + but only as persistent requested connections will be kept between requests! */ =20 + if (! exclusive) { hashed_details =3D (char *) malloc(strlen(SAFE_STRING(username))+ =20 strlen(SAFE_STRING(password))+ =20 strlen(SAFE_STRING(server->dbname))+1); @@ -2176,7 +2218,6 @@ SAFE_STRING(password), SAFE_STRING(server->dbname)); =20 - if (! exclusive) { zend_hash_find(OCI(user), hashed_details, strlen(hashed_details)+1, (void **) &session); =20 if (session) { @@ -2191,6 +2232,14 @@ /* breakthru to open */ } } + } else { + gettimeofday((struct timeval *) &tv, (struct timezone *) NULL); + sec =3D (int) tv.tv_sec; + usec =3D (int) (tv.tv_usec % 1000000); + /* The max value usec can have is 0xF423F, so we use only five hex + digits for usec and eigth hex digits for sec. */ + hashed_details =3D (char *) malloc(8+5+1); /* always enough */ + sprintf(hashed_details, "%08x%05x", tv.tv_sec, tv.tv_usec); } =20 session =3D calloc(1,sizeof(oci_session)); @@ -2627,6 +2676,7 @@ oci_server *server =3D 0; oci_session *session =3D 0; oci_connection *connection =3D 0; + int i, len; =09 /* if a forth parameter is handed over, it is the charset identifier (but is only used in Oracle 9i+) */ if (zend_get_parameters_ex(4, &userParam, &passParam, &dbParam, &charParam) =3D=3D SUCCESS) { @@ -2665,18 +2715,34 @@ goto CLEANUP; } =20 + /* if enabled in php.ini, convert credentials to uppercase */ + if (OCI(credentials_toupper)) { + for (i =3D 0, len =3D strlen(SAFE_STRING(username)); i < len; i++) { + username[i] =3D toupper(username[i]); + } + for (i =3D 0, len =3D strlen(SAFE_STRING(password)); i < len; i++) { + password[i] =3D toupper(password[i]); + } + for (i =3D 0, len =3D strlen(SAFE_STRING(dbname)); i < len; i++) { + dbname[i] =3D toupper(dbname[i]); + } + } + server =3D _oci_open_server(dbname,persistent); =20 if (! server) { goto CLEANUP; } =20 + /* set/update server handle timestamp */ + server->timestamp =3D time(NULL); + if (exclusive) { /* exlusive session can never be persistent!*/ persistent =3D 0; } else { /* if our server-context is not persistent we can't */ - persistent =3D server->persistent;=20 + persistent =3D (server->persistent) ? persistent : 0; } =20 session =3D _oci_open_session(server,username,password,persistent,exclusive,charset) ; Index: php_oci8.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /repository/php4/ext/oci8/php_oci8.h,v retrieving revision 1.28 diff -u -w -r1.28 php_oci8.h --- php_oci8.h 18 Mar 2003 12:06:01 -0000 1.28 +++ php_oci8.h 8 Apr 2003 07:20:12 -0000 @@ -55,6 +55,7 @@ int num; int persistent; int is_open; + time_t timestamp; char *dbname; OCIServer *pServer; #if 0 @@ -182,6 +183,10 @@ long num_links; */ =20 + long connection_timeout; /* from php.ini */ + int credentials_toupper; /* from php.ini */ + time_t current_timestamp; /* set by PHP_RINIT_FUNCTION */ + HashTable *server; HashTable *user; =20