# R:  [PATCH] OCI8 module - proposed patches (PART 1 of 2)

- Thread: https://externals.io/message/780
- Original archive: https://news-web.php.net/php.internals/780
- Started by SQUILLACE MASSIMO on 2003-04-08T08:45:51+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #780 — SQUILLACE MASSIMO — 2003-04-08T08:45:51+00:00

URL: https://externals.io/message/780#780

>    Nice patches, but could you please provide ones without
>    the whitespace changes? Now it's not very clear what you
>    have actually changed..
>    
>    --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
===================================================================
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 = 0, *psession = 0;
 	OCISvcCtx *svchp = 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 
 	   connections or not!
 	   
-	   but only as pesistent requested connections will be kept
between requests!
+	   but only as persistent requested connections will be kept
between requests!
 	*/
 
+	if (! exclusive) {
 	hashed_details = (char *) malloc(strlen(SAFE_STRING(username))+
 
strlen(SAFE_STRING(password))+
 
strlen(SAFE_STRING(server->dbname))+1);
@@ -2176,7 +2179,6 @@
 			SAFE_STRING(password),
 			SAFE_STRING(server->dbname));
 
-	if (! exclusive) {
 		zend_hash_find(OCI(user), hashed_details,
strlen(hashed_details)+1, (void **) &session);
 
 		if (session) {
@@ -2191,6 +2193,14 @@
 				/* breakthru to open */
 			}
 		}
+	} else {
+		gettimeofday((struct timeval *) &tv, (struct timezone *)
NULL);
+		sec = (int) tv.tv_sec;
+		usec = (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 = (char *) malloc(8+5+1); /* always
enough */
+		sprintf(hashed_details, "%08x%05x", tv.tv_sec,
tv.tv_usec);
 	}
 
 	session = calloc(1,sizeof(oci_session));
@@ -2676,7 +2686,7 @@
 		persistent = 0;
 	} else {
 		/* if our server-context is not persistent we can't */
-		persistent = server->persistent; 
+		persistent = (server->persistent) ? persistent : 0;
 	}
 
 	session =
_oci_open_session(server,username,password,persistent,exclusive,charset)
;


*-----------------*

? fourpatches.txt
Index: oci8.c
===================================================================
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
 
 #include "php.h"
+#include "php_ini.h"
 #include "ext/standard/info.h"
 
 /* #define HAVE_OCI8_TEMP_LOB 1 */
@@ -431,6 +432,15 @@
 #endif
 
 /* }}} */
+
+/* {{{ 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 */
 
 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
 
+	REGISTER_INI_ENTRIES();
+
 	le_stmt = zend_register_list_destructors_ex(_oci_stmt_list_dtor,
NULL, "oci8 statement", module_number);
 	le_conn =
zend_register_list_destructors_ex(php_oci_free_conn_list, NULL, "oci8
connection", module_number);
 	le_desc =
zend_register_list_destructors_ex(_oci_descriptor_list_dtor, NULL, "oci8
descriptor", module_number);
@@ -566,6 +578,22 @@
 /* ----------------------------------------------------------------- */
 
 
+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 @@
 
 	oci_debug("php_rinit_oci");
 
+	/* close all timed out connections (if check is enabled) */
+	if (-1 != OCI(connection_timeout)) {
+		OCI(current_timestamp) = 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;
 }
 
@@ -597,6 +632,8 @@
 
 PHP_MSHUTDOWN_FUNCTION(oci)
 {
+	UNREGISTER_INI_ENTRIES();
+
 	OCI(shutdown) = 1;
 
 	oci_debug("START php_mshutdown_oci");
@@ -649,6 +686,8 @@
 #endif
 	php_info_print_table_end();
 
+	DISPLAY_INI_ENTRIES();
+
 }
 
 /* }}} */
@@ -2153,6 +2192,8 @@
 	oci_session *session = 0, *psession = 0;
 	OCISvcCtx *svchp = 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 
 	   connections or not!
 	   
-	   but only as pesistent requested connections will be kept
between requests!
+	   but only as persistent requested connections will be kept
between requests!
 	*/
 
+	if (! exclusive) {
 	hashed_details = (char *) malloc(strlen(SAFE_STRING(username))+
 
strlen(SAFE_STRING(password))+
 
strlen(SAFE_STRING(server->dbname))+1);
@@ -2176,7 +2218,6 @@
 			SAFE_STRING(password),
 			SAFE_STRING(server->dbname));
 
-	if (! exclusive) {
 		zend_hash_find(OCI(user), hashed_details,
strlen(hashed_details)+1, (void **) &session);
 
 		if (session) {
@@ -2191,6 +2232,14 @@
 				/* breakthru to open */
 			}
 		}
+	} else {
+		gettimeofday((struct timeval *) &tv, (struct timezone *)
NULL);
+		sec = (int) tv.tv_sec;
+		usec = (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 = (char *) malloc(8+5+1); /* always
enough */
+		sprintf(hashed_details, "%08x%05x", tv.tv_sec,
tv.tv_usec);
 	}
 
 	session = calloc(1,sizeof(oci_session));
@@ -2627,6 +2676,7 @@
 	oci_server *server = 0;
 	oci_session *session = 0;
 	oci_connection *connection = 0;
+	int i, len;
 	
 	/* 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) == SUCCESS) {
@@ -2665,18 +2715,34 @@
 		goto CLEANUP;
 	}
 
+	/* if enabled in php.ini, convert credentials to uppercase */
+	if (OCI(credentials_toupper)) {
+		for (i = 0, len = strlen(SAFE_STRING(username)); i <
len; i++) {
+			username[i] = toupper(username[i]);
+		}
+		for (i = 0, len = strlen(SAFE_STRING(password)); i <
len; i++) {
+			password[i] = toupper(password[i]);
+		}
+		for (i = 0, len = strlen(SAFE_STRING(dbname)); i < len;
i++) {
+			dbname[i] = toupper(dbname[i]);
+		}
+	}
+
 	server = _oci_open_server(dbname,persistent);
 
 	if (! server) {
 		goto CLEANUP;
 	}
 
+	/* set/update server handle timestamp */
+	server->timestamp = time(NULL);
+
 	if (exclusive) {
 		/* exlusive session can never be persistent!*/
 		persistent = 0;
 	} else {
 		/* if our server-context is not persistent we can't */
-		persistent = server->persistent; 
+		persistent = (server->persistent) ? persistent : 0;
 	}
 
 	session =
_oci_open_session(server,username,password,persistent,exclusive,charset)
;
Index: php_oci8.h
===================================================================
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;
 	*/
 
+	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;
