Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13694 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24064 invoked by uid 1010); 3 Nov 2004 01:29:50 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 24039 invoked from network); 3 Nov 2004 01:29:50 -0000 Received: from unknown (HELO outmta-1.esr.lvcm.net) (24.234.0.14) by pb1.pair.com with SMTP; 3 Nov 2004 01:29:50 -0000 Received: from localhost (localhost [127.0.0.1]) by outmta-1.esr.lvcm.net (Postfix) with ESMTP id 930AF2400D; Tue, 2 Nov 2004 17:29:49 -0800 (PST) Received: from outmta-1.esr.lvcm.net ([127.0.0.1]) by localhost (outmta-1.esr.lvcm.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 29949-04; Tue, 2 Nov 2004 17:29:49 -0800 (PST) Received: from node10.11434.com (ip68-227-60-95.lv.lv.cox.net [68.227.60.95]) by outmta-1.esr.lvcm.net (Postfix) with ESMTP id 415772403C; Tue, 2 Nov 2004 17:29:49 -0800 (PST) To: Sascha Schumann , internals@lists.php.net Date: Tue, 2 Nov 2004 17:30:11 -0800 User-Agent: KMail/1.7.1 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_jSDiBZyI7Ht+3gQ" Message-ID: <200411021730.11759.rodric@rodric.org> X-Virus-Scanned: by amavisd-new at lvcm.net Subject: [PATCH] Exposing bin_to_readable From: rodric@rodric.org (Rodric Glaser) --Boundary-00=_jSDiBZyI7Ht+3gQ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello! Please consider exposing the wonderful bin_to_readable function. Thanks, Rodric --Boundary-00=_jSDiBZyI7Ht+3gQ Content-Type: text/plain; charset="us-ascii"; name="session_bin2readable.patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="session_bin2readable.patch.txt" --- release/php-5.0.2/ext/session/php_session.h 2004-11-02 16:32:48.606283463 -0800 +++ php-5.0.2/ext/session/php_session.h 2004-11-02 16:38:55.086850260 -0800 @@ -149,6 +149,7 @@ PHP_FUNCTION(session_set_cookie_params); PHP_FUNCTION(session_get_cookie_params); PHP_FUNCTION(session_write_close); +PHP_FUNCTION(session_bin2readable); #ifdef ZTS #define PS(v) TSRMG(ps_globals_id, php_ps_globals *, v) --- release/php-5.0.2/ext/session/session.c 2004-11-02 16:32:48.568292112 -0800 +++ php-5.0.2/ext/session/session.c 2004-11-02 17:13:00.792147738 -0800 @@ -76,6 +76,7 @@ PHP_FE(session_set_cookie_params, NULL) PHP_FE(session_get_cookie_params, NULL) PHP_FE(session_write_close, NULL) + PHP_FE(session_bin2readable, NULL) PHP_FALIAS(session_commit, session_write_close, NULL) {NULL, NULL, NULL} }; @@ -1715,6 +1716,37 @@ } } +/* {{{ proto string session_bin2readable(string bin, [ int hash_bits_per_char ]) + Convert binary to a URL safe string */ +PHP_FUNCTION(session_bin2readable) +{ + int j, n; + zval **bin, **hash_bits; + char *buf; + + if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || + zend_get_parameters_ex(ZEND_NUM_ARGS(), &bin, &hash_bits) == FAILURE) + WRONG_PARAM_COUNT; + + convert_to_string_ex(bin); + + if (ZEND_NUM_ARGS() == 2) { + convert_to_long_ex(hash_bits); + n = Z_BVAL_PP(hash_bits); + } + + if (ZEND_NUM_ARGS() == 1 || (n < 4 || n > 6)) { + n = 6; + } + + buf = emalloc(Z_STRLEN_PP(bin)*(8-n)); + + j = (int) (bin_to_readable(Z_STRVAL_PP(bin), Z_STRLEN_PP(bin), buf, n) - buf); + + RETVAL_STRING(buf,j); +} +/* }}} */ + /* {{{ proto void session_write_close(void) Write session data and end session */ PHP_FUNCTION(session_write_close) --Boundary-00=_jSDiBZyI7Ht+3gQ--