Hello, I resubmit this patch again since i didn't get any reply from my previous post. Please get a look at it and, at least, let me know if you think this patch is useless... If not, it would be great if it can be merged before 22:00 ;)
Thanks, Christophe. -------- Original Message -------- Subject: [PATCH] add appname argument to sybase_connect Date: Mon, 04 Mar 2002 17:28:55 +0100 From: Christophe Sollet <[EMAIL PROTECTED]> Organization: Coleebris To: [EMAIL PROTECTED] Attached patch add an optional 'appname' argument to sybase_connect (both ct and db interface). The first goal of this patch is, obviously, to be able to set the appname to something more informative that just 'PHP 4.0' if your db server is php dedicaced. Futhermore, it's allow to make separate connections in the same script to the same db since the appname become part of the hashed details : It's needed when, for example, you have a connection inside a transaction and you have to make a query that can't be done inside this transaction. Without this patch, this sort of things is impossible in PHP (or you have to play with the case of the username to fool the hashed_details...). The patch is well tested with the ct interface (applied on our systems from several weeks) and poorly tested with the db interface (simple connect test). Could someone review it and commit it (it's against current CVS) ? Christophe. -- -------------------------- Christophe Sollet [EMAIL PROTECTED] http://www.coleebris.com Tél: 01.40.50.60.47 Fax: 01.40.50.67.66 --------------------------
Index: sybase_ct/php_sybase_ct.c =================================================================== RCS file: /repository/php4/ext/sybase_ct/php_sybase_ct.c,v retrieving revision 1.68 diff -u -r1.68 php_sybase_ct.c --- sybase_ct/php_sybase_ct.c 11 Dec 2001 15:30:42 -0000 1.68 +++ sybase_ct/php_sybase_ct.c 4 Mar 2002 15:00:26 -0000 @@ -371,7 +371,7 @@ } -static int php_sybase_do_connect_internal(sybase_link *sybase, char *host, char *user, char *passwd, char *charset) +static int php_sybase_do_connect_internal(sybase_link *sybase, char *host, char +*user, char *passwd, char *charset, char *appname) { CS_LOCALE *tmp_locale; TSRMLS_FETCH(); @@ -395,7 +395,11 @@ if (passwd) { ct_con_props(sybase->connection, CS_SET, CS_PASSWORD, passwd, CS_NULLTERM, NULL); } - ct_con_props(sybase->connection, CS_SET, CS_APPNAME, SybCtG(appname), CS_NULLTERM, NULL); + if (appname) { + ct_con_props(sybase->connection, CS_SET, CS_APPNAME, appname, +CS_NULLTERM, NULL); + } else { + ct_con_props(sybase->connection, CS_SET, CS_APPNAME, SybCtG(appname), +CS_NULLTERM, NULL); + } if (SybCtG(hostname)) { ct_con_props(sybase->connection, CS_SET, CS_HOSTNAME, SybCtG(hostname), CS_NULLTERM, NULL); @@ -442,17 +446,17 @@ static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) { - char *user, *passwd, *host, *charset; + char *user, *passwd, *host, *charset, *appname; char *hashed_details; int hashed_details_length; sybase_link *sybase_ptr; switch(ZEND_NUM_ARGS()) { case 0: /* defaults */ - host=user=passwd=charset=NULL; - hashed_details_length=6+4; + host=user=passwd=charset=appname=NULL; + hashed_details_length=6+5; hashed_details = (char *) emalloc(hashed_details_length+1); - strcpy(hashed_details, "sybase____"); + strcpy(hashed_details, "sybase_____"); break; case 1: { pval *yyhost; @@ -462,10 +466,10 @@ } convert_to_string(yyhost); host = Z_STRVAL_P(yyhost); - user=passwd=charset=NULL; - hashed_details_length = Z_STRLEN_P(yyhost)+6+4; + user=passwd=charset=appname=NULL; + hashed_details_length = Z_STRLEN_P(yyhost)+6+5; hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details, "sybase_%s___", Z_STRVAL_P(yyhost)); + sprintf(hashed_details, "sybase_%s____", +Z_STRVAL_P(yyhost)); } break; case 2: { @@ -478,10 +482,10 @@ convert_to_string(yyuser); host = Z_STRVAL_P(yyhost); user = Z_STRVAL_P(yyuser); - passwd=charset=NULL; - hashed_details_length = Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+6+4; + passwd=charset=appname=NULL; + hashed_details_length = +Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+6+5; hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details, "sybase_%s_%s__", Z_STRVAL_P(yyhost), Z_STRVAL_P(yyuser)); + sprintf(hashed_details, "sybase_%s_%s___", +Z_STRVAL_P(yyhost), Z_STRVAL_P(yyuser)); } break; case 3: { @@ -496,10 +500,10 @@ host = Z_STRVAL_P(yyhost); user = Z_STRVAL_P(yyuser); passwd = Z_STRVAL_P(yypasswd); - charset=NULL; - hashed_details_length = Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+Z_STRLEN_P(yypasswd)+6+4; + charset=appname=NULL; + hashed_details_length = +Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+Z_STRLEN_P(yypasswd)+6+5; hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details, "sybase_%s_%s_%s_", Z_STRVAL_P(yyhost), Z_STRVAL_P(yyuser), Z_STRVAL_P(yypasswd)); + sprintf(hashed_details, "sybase_%s_%s_%s__", +Z_STRVAL_P(yyhost), Z_STRVAL_P(yyuser), Z_STRVAL_P(yypasswd)); } break; case 4: { @@ -516,9 +520,31 @@ user = Z_STRVAL_P(yyuser); passwd = Z_STRVAL_P(yypasswd); charset = Z_STRVAL_P(yycharset); - hashed_details_length = Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+Z_STRLEN_P(yypasswd)+Z_STRLEN_P(yycharset)+6+4; + appname=NULL; + hashed_details_length = +Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+Z_STRLEN_P(yypasswd)+Z_STRLEN_P(yycharset)+6+5; + hashed_details = (char *) +emalloc(hashed_details_length+1); + sprintf(hashed_details, "sybase_%s_%s_%s_%s_", +Z_STRVAL_P(yyhost), Z_STRVAL_P(yyuser), Z_STRVAL_P(yypasswd), Z_STRVAL_P(yycharset)); + } + break; + case 5: { + pval *yyhost, *yyuser, *yypasswd, *yycharset, +*yyappname; + + if (getParameters(ht, 5, &yyhost, &yyuser, &yypasswd, +&yycharset, &yyappname) == FAILURE) { + RETURN_FALSE; + } + convert_to_string(yyhost); + convert_to_string(yyuser); + convert_to_string(yypasswd); + convert_to_string(yycharset); + convert_to_string(yyappname); + host = Z_STRVAL_P(yyhost); + user = Z_STRVAL_P(yyuser); + passwd = Z_STRVAL_P(yypasswd); + charset = Z_STRVAL_P(yycharset); + appname = Z_STRVAL_P(yyappname); + hashed_details_length = +Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+Z_STRLEN_P(yypasswd)+Z_STRLEN_P(yycharset)+Z_STRLEN_P(yyappname)+6+5; hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details, "sybase_%s_%s_%s_%s", Z_STRVAL_P(yyhost), Z_STRVAL_P(yyuser), Z_STRVAL_P(yypasswd), Z_STRVAL_P(yycharset)); + sprintf(hashed_details, "sybase_%s_%s_%s_%s_%s", +Z_STRVAL_P(yyhost), Z_STRVAL_P(yyuser), Z_STRVAL_P(yypasswd), Z_STRVAL_P(yycharset), +Z_STRVAL_P(yyappname)); } break; default: @@ -549,7 +575,7 @@ } sybase_ptr = (sybase_link *) malloc(sizeof(sybase_link)); - if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd, charset)) { + if (!php_sybase_do_connect_internal(sybase_ptr, host, user, +passwd, charset, appname)) { free(sybase_ptr); efree(hashed_details); RETURN_FALSE; @@ -603,7 +629,7 @@ * NULL before trying to use it elsewhere . . .) */ memcpy(&sybase, sybase_ptr, sizeof(sybase_link)); - if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd, charset)) { + if (!php_sybase_do_connect_internal(sybase_ptr, host, +user, passwd, charset, appname)) { memcpy(sybase_ptr, &sybase, sizeof(sybase_link)); efree(hashed_details); RETURN_FALSE; @@ -647,7 +673,7 @@ } sybase_ptr = (sybase_link *) emalloc(sizeof(sybase_link)); - if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd, charset)) { + if (!php_sybase_do_connect_internal(sybase_ptr, host, user, passwd, +charset, appname)) { efree(sybase_ptr); efree(hashed_details); RETURN_FALSE; @@ -684,7 +710,7 @@ } -/* {{{ proto int sybase_connect([string host [, string user [, string password [, string charset]]]]) +/* {{{ proto int sybase_connect([string host [, string user [, string password [, +string charset [, string appname]]]]]) Open Sybase server connection */ PHP_FUNCTION(sybase_connect) { @@ -693,7 +719,7 @@ /* }}} */ -/* {{{ proto int sybase_pconnect([string host [, string user [, string password [, string charset]]]]) +/* {{{ proto int sybase_pconnect([string host [, string user [, string password [, +string charset [, string appname]]]]]) Open persistent Sybase connection */ PHP_FUNCTION(sybase_pconnect) { Index: sybase/php_sybase_db.c =================================================================== RCS file: /repository/php4/ext/sybase/php_sybase_db.c,v retrieving revision 1.35 diff -u -r1.35 php_sybase_db.c --- sybase/php_sybase_db.c 11 Dec 2001 15:30:39 -0000 1.35 +++ sybase/php_sybase_db.c 4 Mar 2002 15:00:30 -0000 @@ -301,7 +301,7 @@ static void php_sybase_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent) { - char *user=NULL,*passwd=NULL,*host=NULL,*charset=NULL; + char *user=NULL,*passwd=NULL,*host=NULL,*charset=NULL,*appname=NULL; char *hashed_details; int hashed_details_length; sybase_link sybase,*sybase_ptr; @@ -320,9 +320,9 @@ } convert_to_string(yyhost); host = Z_STRVAL_P(yyhost); - hashed_details_length = Z_STRLEN_P(yyhost)+6+4; + hashed_details_length = Z_STRLEN_P(yyhost)+6+5; hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details,"sybase_%s___",Z_STRVAL_P(yyhost)); + +sprintf(hashed_details,"sybase_%s____",Z_STRVAL_P(yyhost)); } break; case 2: { @@ -335,9 +335,9 @@ convert_to_string(yyuser); host = Z_STRVAL_P(yyhost); user = Z_STRVAL_P(yyuser); - hashed_details_length = Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+6+4; + hashed_details_length = +Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+6+5; hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details,"sybase_%s_%s__",Z_STRVAL_P(yyhost),Z_STRVAL_P(yyuser)); + +sprintf(hashed_details,"sybase_%s_%s___",Z_STRVAL_P(yyhost),Z_STRVAL_P(yyuser)); } break; case 3: { @@ -352,9 +352,9 @@ host = Z_STRVAL_P(yyhost); user = Z_STRVAL_P(yyuser); passwd = Z_STRVAL_P(yypasswd); - hashed_details_length = Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+Z_STRLEN_P(yypasswd)+6+4; + hashed_details_length = +Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+Z_STRLEN_P(yypasswd)+6+5; hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details,"sybase_%s_%s_%s_",Z_STRVAL_P(yyhost),Z_STRVAL_P(yyuser),Z_STRVAL_P(yypasswd)); /* SAFE */ + +sprintf(hashed_details,"sybase_%s_%s_%s__",Z_STRVAL_P(yyhost),Z_STRVAL_P(yyuser),Z_STRVAL_P(yypasswd)); + /* SAFE */ } break; case 4: { @@ -371,9 +371,30 @@ user = Z_STRVAL_P(yyuser); passwd = Z_STRVAL_P(yypasswd); charset = Z_STRVAL_P(yycharset); - hashed_details_length = Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+Z_STRLEN_P(yypasswd)+Z_STRLEN_P(yycharset)+6+4; + hashed_details_length = +Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+Z_STRLEN_P(yypasswd)+Z_STRLEN_P(yycharset)+6+5; hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details,"sybase_%s_%s_%s_%s",Z_STRVAL_P(yyhost),Z_STRVAL_P(yyuser),Z_STRVAL_P(yypasswd),Z_STRVAL_P(yycharset)); /* SAFE */ + +sprintf(hashed_details,"sybase_%s_%s_%s_%s_",Z_STRVAL_P(yyhost),Z_STRVAL_P(yyuser),Z_STRVAL_P(yypasswd),Z_STRVAL_P(yycharset)); + /* SAFE */ + } + break; + case 5: { + pval *yyhost,*yyuser,*yypasswd,*yycharset, *yyappname; + + if (getParameters(ht, 5, &yyhost, &yyuser, &yypasswd, +&yycharset, &yyappname) == FAILURE) { + RETURN_FALSE; + } + convert_to_string(yyhost); + convert_to_string(yyuser); + convert_to_string(yypasswd); + convert_to_string(yycharset); + convert_to_string(yyappname); + host = Z_STRVAL_P(yyhost); + user = Z_STRVAL_P(yyuser); + passwd = Z_STRVAL_P(yypasswd); + charset = Z_STRVAL_P(yycharset); + appname = Z_STRVAL_P(yyappname); + hashed_details_length = +Z_STRLEN_P(yyhost)+Z_STRLEN_P(yyuser)+Z_STRLEN_P(yypasswd)+Z_STRLEN_P(yycharset)+Z_STRLEN_P(yyappname)+6+5; + hashed_details = (char *) +emalloc(hashed_details_length+1); + +sprintf(hashed_details,"sybase_%s_%s_%s_%s_%s",Z_STRVAL_P(yyhost),Z_STRVAL_P(yyuser),Z_STRVAL_P(yypasswd),Z_STRVAL_P(yycharset),Z_STRVAL_P(yyappname)); + /* SAFE */ } break; default: @@ -397,7 +418,12 @@ if (charset) { DBSETLCHARSET(sybase.login,charset); } - DBSETLAPP(sybase.login,php_sybase_module.appname); + if (appname) { + DBSETLAPP(sybase.login,appname); + } else { + DBSETLAPP(sybase.login,php_sybase_module.appname); + } + sybase.valid = 1; if (!php_sybase_module.allow_persistent) { @@ -549,7 +575,7 @@ } -/* {{{ proto int sybase_connect([string host [, string user [, string password [, string charset]]]]) +/* {{{ proto int sybase_connect([string host [, string user [, string password [, +string charset [, string appname]]]]]) Open Sybase server connection */ PHP_FUNCTION(sybase_connect) { @@ -557,7 +583,7 @@ } /* }}} */ -/* {{{ proto int sybase_pconnect([string host [, string user [, string password [, string charset]]]]) +/* {{{ proto int sybase_pconnect([string host [, string user [, string password [, +string charset [, string appname]]]]]) Open persistent Sybase connection */ PHP_FUNCTION(sybase_pconnect) {
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php