Package: php4 Version: 4:4.3.8-9 Severity: wishlist Tags: patch Hello,
In order to access Hylafax or any other service that uses non standard or non PHP supported FTP commands, it would be useful to backport the function ftp_raw from PHP5.0 The patch attached just includes the related functions from PHP5 source code. It seems to be a quite straight-forward operation. I have done it locally and everything seems to work ok. -- System Information: Debian Release: 3.1 APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.8-2-k7 Locale: LANG=es_ES, LC_CTYPE=es_ES (charmap=ISO-8859-1) Versions of packages php4 depends on: ii php4-cgi 4:4.3.10-15zmteftpraw25 server-side, HTML-embedded scripti ii php4-common 4:4.3.10-15zmteftpraw25 Common files for packages built fr -- debconf information excluded
diff -Nru php4-4.3.10/ext/ftp/ftp.c php4-4.3.10_patched/ext/ftp/ftp.c --- php4-4.3.10/ext/ftp/ftp.c 2005-06-02 10:55:06.000000000 +0200 +++ php4-4.3.10_patched/ext/ftp/ftp.c 2005-06-02 10:46:22.000000000 +0200 @@ -421,6 +421,26 @@ } /* }}} */ +/* {{{ ftp_raw + */ +void +ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value) +{ + if (ftp == NULL || cmd == NULL) { + RETURN_NULL(); + } + if (!ftp_putcmd(ftp, cmd, NULL)) { + RETURN_NULL(); + } + array_init(return_value); + while (ftp_readline(ftp)) { + add_next_index_string(return_value, ftp->inbuf, 1); + if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] == ' ') { + return; + } + } +} + /* {{{ ftp_chdir */ int diff -Nru php4-4.3.10/ext/ftp/ftp.h php4-4.3.10_patched/ext/ftp/ftp.h --- php4-4.3.10/ext/ftp/ftp.h 2003-06-27 18:42:50.000000000 +0200 +++ php4-4.3.10_patched/ext/ftp/ftp.h 2005-06-02 10:44:41.000000000 +0200 @@ -121,6 +121,9 @@ /* exec a command [special features], return true on success, false on error */ int ftp_exec(ftpbuf_t *ftp, const char *cmd); +/* send a raw ftp command, return response as a hashtable, NULL on error */ +void ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value); + /* changes directories, return true on success, false on error */ int ftp_chdir(ftpbuf_t *ftp, const char *dir); diff -Nru php4-4.3.10/ext/ftp/php_ftp.c php4-4.3.10_patched/ext/ftp/php_ftp.c --- php4-4.3.10/ext/ftp/php_ftp.c 2005-06-02 10:55:06.000000000 +0200 +++ php4-4.3.10_patched/ext/ftp/php_ftp.c 2005-06-02 10:49:08.000000000 +0200 @@ -56,6 +56,7 @@ PHP_FE(ftp_cdup, NULL) PHP_FE(ftp_chdir, NULL) PHP_FE(ftp_exec, NULL) + PHP_FE(ftp_raw, NULL) PHP_FE(ftp_mkdir, NULL) PHP_FE(ftp_rmdir, NULL) PHP_FE(ftp_nlist, NULL) @@ -332,6 +333,28 @@ } /* }}} */ +/* {{{ proto array ftp_raw(resource stream, string command) + Sends a literal command to the FTP server */ +PHP_FUNCTION(ftp_raw) +{ + zval *z_ftp; + ftpbuf_t *ftp; + char *cmd; + int cmd_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf); + + /* execute arbitrary ftp command */ + ftp_raw(ftp, cmd, return_value); +} +/* }}} */ + + + /* {{{ proto string ftp_mkdir(resource stream, string directory) Creates a directory and returns the absolute path for the new directory or false on error */ PHP_FUNCTION(ftp_mkdir) diff -Nru php4-4.3.10/ext/ftp/php_ftp.h php4-4.3.10_patched/ext/ftp/php_ftp.h --- php4-4.3.10/ext/ftp/php_ftp.h 2003-06-27 18:42:50.000000000 +0200 +++ php4-4.3.10_patched/ext/ftp/php_ftp.h 2005-06-02 10:50:09.000000000 +0200 @@ -43,6 +43,7 @@ PHP_FUNCTION(ftp_cdup); PHP_FUNCTION(ftp_chdir); PHP_FUNCTION(ftp_exec); +PHP_FUNCTION(ftp_raw); PHP_FUNCTION(ftp_mkdir); PHP_FUNCTION(ftp_rmdir); PHP_FUNCTION(ftp_nlist);