sas Thu Nov 6 09:27:35 2003 EDT Modified files: (Branch: PHP_4_3) /php-src/ext/oci8 oci8.c Log: Fix a format string Nuke a sprintf (slooow) And embed the charset as part of the hashed details (persistent conn key), because the function otherwise happily returns incompatible connections. (e.g. US7ASCII vs. UTF8; the client-side charset is not alterable once a connection has been established.) Index: php-src/ext/oci8/oci8.c diff -u php-src/ext/oci8/oci8.c:1.183.2.5 php-src/ext/oci8/oci8.c:1.183.2.6 --- php-src/ext/oci8/oci8.c:1.183.2.5 Fri May 2 04:43:25 2003 +++ php-src/ext/oci8/oci8.c Thu Nov 6 09:27:34 2003 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: oci8.c,v 1.183.2.5 2003/05/02 08:43:25 thies Exp $ */ +/* $Id: oci8.c,v 1.183.2.6 2003/11/06 14:27:34 sas Exp $ */ /* TODO list: * @@ -641,7 +641,7 @@ php_info_print_table_start(); php_info_print_table_row(2, "OCI8 Support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.183.2.5 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.183.2.6 $"); #ifndef PHP_WIN32 php_info_print_table_row(2, "Oracle Version", PHP_OCI8_VERSION ); php_info_print_table_row(2, "Compile-time ORACLE_HOME", PHP_OCI8_DIR ); @@ -1278,7 +1278,7 @@ descr = oci_get_desc(column->descid TSRMLS_CC); if (! descr) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to find my descriptor %d",column->data); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to find my descriptor %p",column->data); return -1; } @@ -2148,11 +2148,13 @@ */ +#include "ext/standard/php_smart_str.h" + static oci_session *_oci_open_session(oci_server* server,char *username,char *password,int persistent,int exclusive,char *charset) { oci_session *session = 0, *psession = 0; OCISvcCtx *svchp = 0; - char *hashed_details; + smart_str hashed_details = {0}; #ifdef HAVE_OCI_9_2 ub2 charsetid = 0; #endif @@ -2164,27 +2166,55 @@ 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! */ - hashed_details = (char *) malloc(strlen(SAFE_STRING(username))+ - strlen(SAFE_STRING(password))+ - strlen(SAFE_STRING(server->dbname))+1); - - sprintf(hashed_details,"%s%s%s", - SAFE_STRING(username), - SAFE_STRING(password), - SAFE_STRING(server->dbname)); +#if defined(HAVE_OCI_9_2) + if (*charset) { + smart_str_appends_ex(&hashed_details, charset, 1); + } else { + size_t rsize; + + /* Safe, charsetid is initialized to 0 */ + CALL_OCI(OCINlsEnvironmentVariableGet(&charsetid, + 2, + OCI_NLS_CHARSET_ID, + 0, + &rsize)); + + smart_str_append_long_ex(&hashed_details, charsetid, 1); + + charsetid = 0; + } +#else + { + char *nls_lang = getenv("NLS_LANG"); + + /* extract charset from NLS_LANG=LANUAGE_TERRITORY.CHARSET */ + if (nls_lang) { + char *p = strchr(nls_lang, '.'); + + if (p) { + smart_str_appends_ex(&hashed_details, p + 1, 1); + } + } + } +#endif + + smart_str_appends_ex(&hashed_details, SAFE_STRING(username), 1); + smart_str_appends_ex(&hashed_details, SAFE_STRING(password), 1); + smart_str_appends_ex(&hashed_details, SAFE_STRING(server->dbname), 1); + smart_str_0(&hashed_details); if (! exclusive) { - zend_hash_find(OCI(user), hashed_details, strlen(hashed_details)+1, (void **) &session); + zend_hash_find(OCI(user), hashed_details.c, hashed_details.len+1, (void **) &session); if (session) { if (session->is_open) { if (persistent) { session->persistent = 1; } - free(hashed_details); + smart_str_free_ex(&hashed_details, 1); return session; } else { _oci_close_session(session); @@ -2200,7 +2230,7 @@ } session->persistent = persistent; - session->hashed_details = hashed_details; + session->hashed_details = hashed_details.c; session->server = server; session->exclusive = exclusive;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php