PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/ftp - php_ftp.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 0 441 0.0 %
Date: 2014-04-16 Functions: 0 36 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andrew Skalski <askalski@chek.com>                          |
      16             :    |          Stefan Esser <sesser@php.net> (resume functions)            |
      17             :    +----------------------------------------------------------------------+
      18             :  */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : 
      26             : #include "php.h"
      27             : 
      28             : #if defined(NETWARE) && defined(USE_WINSOCK)
      29             : #include <novsock2.h>
      30             : #endif
      31             : 
      32             : #if HAVE_OPENSSL_EXT
      33             : # include <openssl/ssl.h>
      34             : #endif
      35             : 
      36             : #if HAVE_FTP
      37             : 
      38             : #include "ext/standard/info.h"
      39             : #include "ext/standard/file.h"
      40             : 
      41             : #include "php_ftp.h"
      42             : #include "ftp.h"
      43             : 
      44             : static int le_ftpbuf;
      45             : #define le_ftpbuf_name "FTP Buffer"
      46             : 
      47             : /* {{{ arginfo */
      48             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_connect, 0, 0, 1)
      49             :         ZEND_ARG_INFO(0, host)
      50             :         ZEND_ARG_INFO(0, port)
      51             :         ZEND_ARG_INFO(0, timeout)
      52             : ZEND_END_ARG_INFO()
      53             : 
      54             : #if HAVE_OPENSSL_EXT
      55             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_ssl_connect, 0, 0, 1)
      56             :         ZEND_ARG_INFO(0, host)
      57             :         ZEND_ARG_INFO(0, port)
      58             :         ZEND_ARG_INFO(0, timeout)
      59             : ZEND_END_ARG_INFO()
      60             : #endif
      61             : 
      62             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_login, 0)
      63             :         ZEND_ARG_INFO(0, ftp)
      64             :         ZEND_ARG_INFO(0, username)
      65             :         ZEND_ARG_INFO(0, password)
      66             : ZEND_END_ARG_INFO()
      67             : 
      68             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_pwd, 0)
      69             :         ZEND_ARG_INFO(0, ftp)
      70             : ZEND_END_ARG_INFO()
      71             : 
      72             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_cdup, 0)
      73             :         ZEND_ARG_INFO(0, ftp)
      74             : ZEND_END_ARG_INFO()
      75             : 
      76             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_chdir, 0)
      77             :         ZEND_ARG_INFO(0, ftp)
      78             :         ZEND_ARG_INFO(0, directory)
      79             : ZEND_END_ARG_INFO()
      80             : 
      81             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_exec, 0)
      82             :         ZEND_ARG_INFO(0, ftp)
      83             :         ZEND_ARG_INFO(0, command)
      84             : ZEND_END_ARG_INFO()
      85             : 
      86             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_raw, 0)
      87             :         ZEND_ARG_INFO(0, ftp)
      88             :         ZEND_ARG_INFO(0, command)
      89             : ZEND_END_ARG_INFO()
      90             : 
      91             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_mkdir, 0)
      92             :         ZEND_ARG_INFO(0, ftp)
      93             :         ZEND_ARG_INFO(0, directory)
      94             : ZEND_END_ARG_INFO()
      95             : 
      96             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_rmdir, 0)
      97             :         ZEND_ARG_INFO(0, ftp)
      98             :         ZEND_ARG_INFO(0, directory)
      99             : ZEND_END_ARG_INFO()
     100             : 
     101             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_chmod, 0)
     102             :         ZEND_ARG_INFO(0, ftp)
     103             :         ZEND_ARG_INFO(0, mode)
     104             :         ZEND_ARG_INFO(0, filename)
     105             : ZEND_END_ARG_INFO()
     106             : 
     107             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_alloc, 0, 0, 2)
     108             :         ZEND_ARG_INFO(0, ftp)
     109             :         ZEND_ARG_INFO(0, size)
     110             :         ZEND_ARG_INFO(1, response)
     111             : ZEND_END_ARG_INFO()
     112             : 
     113             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_nlist, 0)
     114             :         ZEND_ARG_INFO(0, ftp)
     115             :         ZEND_ARG_INFO(0, directory)
     116             : ZEND_END_ARG_INFO()
     117             : 
     118             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_rawlist, 0, 0, 2)
     119             :         ZEND_ARG_INFO(0, ftp)
     120             :         ZEND_ARG_INFO(0, directory)
     121             :         ZEND_ARG_INFO(0, recursive)
     122             : ZEND_END_ARG_INFO()
     123             : 
     124             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_systype, 0)
     125             :         ZEND_ARG_INFO(0, ftp)
     126             : ZEND_END_ARG_INFO()
     127             : 
     128             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_fget, 0, 0, 4)
     129             :         ZEND_ARG_INFO(0, ftp)
     130             :         ZEND_ARG_INFO(0, fp)
     131             :         ZEND_ARG_INFO(0, remote_file)
     132             :         ZEND_ARG_INFO(0, mode)
     133             :         ZEND_ARG_INFO(0, resumepos)
     134             : ZEND_END_ARG_INFO()
     135             : 
     136             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_fget, 0, 0, 4)
     137             :         ZEND_ARG_INFO(0, ftp)
     138             :         ZEND_ARG_INFO(0, fp)
     139             :         ZEND_ARG_INFO(0, remote_file)
     140             :         ZEND_ARG_INFO(0, mode)
     141             :         ZEND_ARG_INFO(0, resumepos)
     142             : ZEND_END_ARG_INFO()
     143             : 
     144             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_pasv, 0)
     145             :         ZEND_ARG_INFO(0, ftp)
     146             :         ZEND_ARG_INFO(0, pasv)
     147             : ZEND_END_ARG_INFO()
     148             : 
     149             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_get, 0, 0, 4)
     150             :         ZEND_ARG_INFO(0, ftp)
     151             :         ZEND_ARG_INFO(0, local_file)
     152             :         ZEND_ARG_INFO(0, remote_file)
     153             :         ZEND_ARG_INFO(0, mode)
     154             :         ZEND_ARG_INFO(0, resume_pos)
     155             : ZEND_END_ARG_INFO()
     156             : 
     157             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_get, 0, 0, 4)
     158             :         ZEND_ARG_INFO(0, ftp)
     159             :         ZEND_ARG_INFO(0, local_file)
     160             :         ZEND_ARG_INFO(0, remote_file)
     161             :         ZEND_ARG_INFO(0, mode)
     162             :         ZEND_ARG_INFO(0, resume_pos)
     163             : ZEND_END_ARG_INFO()
     164             : 
     165             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_nb_continue, 0)
     166             :         ZEND_ARG_INFO(0, ftp)
     167             : ZEND_END_ARG_INFO()
     168             : 
     169             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_fput, 0, 0, 4)
     170             :         ZEND_ARG_INFO(0, ftp)
     171             :         ZEND_ARG_INFO(0, remote_file)
     172             :         ZEND_ARG_INFO(0, fp)
     173             :         ZEND_ARG_INFO(0, mode)
     174             :         ZEND_ARG_INFO(0, startpos)
     175             : ZEND_END_ARG_INFO()
     176             : 
     177             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_fput, 0, 0, 4)
     178             :         ZEND_ARG_INFO(0, ftp)
     179             :         ZEND_ARG_INFO(0, remote_file)
     180             :         ZEND_ARG_INFO(0, fp)
     181             :         ZEND_ARG_INFO(0, mode)
     182             :         ZEND_ARG_INFO(0, startpos)
     183             : ZEND_END_ARG_INFO()
     184             : 
     185             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_put, 0, 0, 4)
     186             :         ZEND_ARG_INFO(0, ftp)
     187             :         ZEND_ARG_INFO(0, remote_file)
     188             :         ZEND_ARG_INFO(0, local_file)
     189             :         ZEND_ARG_INFO(0, mode)
     190             :         ZEND_ARG_INFO(0, startpos)
     191             : ZEND_END_ARG_INFO()
     192             : 
     193             : ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_nb_put, 0, 0, 4)
     194             :         ZEND_ARG_INFO(0, ftp)
     195             :         ZEND_ARG_INFO(0, remote_file)
     196             :         ZEND_ARG_INFO(0, local_file)
     197             :         ZEND_ARG_INFO(0, mode)
     198             :         ZEND_ARG_INFO(0, startpos)
     199             : ZEND_END_ARG_INFO()
     200             : 
     201             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_size, 0)
     202             :         ZEND_ARG_INFO(0, ftp)
     203             :         ZEND_ARG_INFO(0, filename)
     204             : ZEND_END_ARG_INFO()
     205             : 
     206             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_mdtm, 0)
     207             :         ZEND_ARG_INFO(0, ftp)
     208             :         ZEND_ARG_INFO(0, filename)
     209             : ZEND_END_ARG_INFO()
     210             : 
     211             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_rename, 0)
     212             :         ZEND_ARG_INFO(0, ftp)
     213             :         ZEND_ARG_INFO(0, src)
     214             :         ZEND_ARG_INFO(0, dest)
     215             : ZEND_END_ARG_INFO()
     216             : 
     217             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_delete, 0)
     218             :         ZEND_ARG_INFO(0, ftp)
     219             :         ZEND_ARG_INFO(0, file)
     220             : ZEND_END_ARG_INFO()
     221             : 
     222             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_site, 0)
     223             :         ZEND_ARG_INFO(0, ftp)
     224             :         ZEND_ARG_INFO(0, cmd)
     225             : ZEND_END_ARG_INFO()
     226             : 
     227             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_close, 0)
     228             :         ZEND_ARG_INFO(0, ftp)
     229             : ZEND_END_ARG_INFO()
     230             : 
     231             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_set_option, 0)
     232             :         ZEND_ARG_INFO(0, ftp)
     233             :         ZEND_ARG_INFO(0, option)
     234             :         ZEND_ARG_INFO(0, value)
     235             : ZEND_END_ARG_INFO()
     236             : 
     237             : ZEND_BEGIN_ARG_INFO(arginfo_ftp_get_option, 0)
     238             :         ZEND_ARG_INFO(0, ftp)
     239             :         ZEND_ARG_INFO(0, option)
     240             : ZEND_END_ARG_INFO()
     241             : 
     242             : /* }}} */
     243             : 
     244             : const zend_function_entry php_ftp_functions[] = {
     245             :         PHP_FE(ftp_connect,                     arginfo_ftp_connect)
     246             : #if HAVE_OPENSSL_EXT
     247             :         PHP_FE(ftp_ssl_connect,         arginfo_ftp_ssl_connect)
     248             : #endif  
     249             :         PHP_FE(ftp_login,                       arginfo_ftp_login)
     250             :         PHP_FE(ftp_pwd,                         arginfo_ftp_pwd)
     251             :         PHP_FE(ftp_cdup,                        arginfo_ftp_cdup)
     252             :         PHP_FE(ftp_chdir,                       arginfo_ftp_chdir)
     253             :         PHP_FE(ftp_exec,                        arginfo_ftp_exec)
     254             :         PHP_FE(ftp_raw,                         arginfo_ftp_raw)
     255             :         PHP_FE(ftp_mkdir,                       arginfo_ftp_mkdir)
     256             :         PHP_FE(ftp_rmdir,                       arginfo_ftp_rmdir)
     257             :         PHP_FE(ftp_chmod,                       arginfo_ftp_chmod)
     258             :         PHP_FE(ftp_alloc,                       arginfo_ftp_alloc)
     259             :         PHP_FE(ftp_nlist,                       arginfo_ftp_nlist)
     260             :         PHP_FE(ftp_rawlist,                     arginfo_ftp_rawlist)
     261             :         PHP_FE(ftp_systype,                     arginfo_ftp_systype)
     262             :         PHP_FE(ftp_pasv,                        arginfo_ftp_pasv)
     263             :         PHP_FE(ftp_get,                         arginfo_ftp_get)
     264             :         PHP_FE(ftp_fget,                        arginfo_ftp_fget)
     265             :         PHP_FE(ftp_put,                         arginfo_ftp_put)
     266             :         PHP_FE(ftp_fput,                        arginfo_ftp_fput)
     267             :         PHP_FE(ftp_size,                        arginfo_ftp_size)
     268             :         PHP_FE(ftp_mdtm,                        arginfo_ftp_mdtm)
     269             :         PHP_FE(ftp_rename,                      arginfo_ftp_rename)
     270             :         PHP_FE(ftp_delete,                      arginfo_ftp_delete)
     271             :         PHP_FE(ftp_site,                        arginfo_ftp_site)
     272             :         PHP_FE(ftp_close,                       arginfo_ftp_close)
     273             :         PHP_FE(ftp_set_option,          arginfo_ftp_set_option)
     274             :         PHP_FE(ftp_get_option,          arginfo_ftp_get_option)
     275             :         PHP_FE(ftp_nb_fget,                     arginfo_ftp_nb_fget)
     276             :         PHP_FE(ftp_nb_get,                      arginfo_ftp_nb_get)
     277             :         PHP_FE(ftp_nb_continue,         arginfo_ftp_nb_continue)
     278             :         PHP_FE(ftp_nb_put,                      arginfo_ftp_nb_put)
     279             :         PHP_FE(ftp_nb_fput,                     arginfo_ftp_nb_fput)
     280             :         PHP_FALIAS(ftp_quit, ftp_close, arginfo_ftp_close)
     281             :         PHP_FE_END
     282             : };
     283             : 
     284             : zend_module_entry php_ftp_module_entry = {
     285             :     STANDARD_MODULE_HEADER,
     286             :         "ftp",
     287             :         php_ftp_functions,
     288             :         PHP_MINIT(ftp),
     289             :         NULL,
     290             :         NULL,
     291             :         NULL,
     292             :         PHP_MINFO(ftp),
     293             :     NO_VERSION_YET,
     294             :         STANDARD_MODULE_PROPERTIES
     295             : };
     296             : 
     297             : #if COMPILE_DL_FTP
     298             : ZEND_GET_MODULE(php_ftp)
     299             : #endif
     300             : 
     301           0 : static void ftp_destructor_ftpbuf(zend_rsrc_list_entry *rsrc TSRMLS_DC)
     302             : {
     303           0 :         ftpbuf_t *ftp = (ftpbuf_t *)rsrc->ptr;
     304             : 
     305           0 :         ftp_close(ftp);
     306           0 : }
     307             : 
     308           0 : PHP_MINIT_FUNCTION(ftp)
     309             : {
     310           0 :         le_ftpbuf = zend_register_list_destructors_ex(ftp_destructor_ftpbuf, NULL, le_ftpbuf_name, module_number);
     311           0 :         REGISTER_LONG_CONSTANT("FTP_ASCII",  FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS);
     312           0 :         REGISTER_LONG_CONSTANT("FTP_TEXT",   FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS);
     313           0 :         REGISTER_LONG_CONSTANT("FTP_BINARY", FTPTYPE_IMAGE, CONST_PERSISTENT | CONST_CS);
     314           0 :         REGISTER_LONG_CONSTANT("FTP_IMAGE",  FTPTYPE_IMAGE, CONST_PERSISTENT | CONST_CS);
     315           0 :         REGISTER_LONG_CONSTANT("FTP_AUTORESUME", PHP_FTP_AUTORESUME, CONST_PERSISTENT | CONST_CS);
     316           0 :         REGISTER_LONG_CONSTANT("FTP_TIMEOUT_SEC", PHP_FTP_OPT_TIMEOUT_SEC, CONST_PERSISTENT | CONST_CS);
     317           0 :         REGISTER_LONG_CONSTANT("FTP_AUTOSEEK", PHP_FTP_OPT_AUTOSEEK, CONST_PERSISTENT | CONST_CS);
     318           0 :         REGISTER_LONG_CONSTANT("FTP_FAILED", PHP_FTP_FAILED, CONST_PERSISTENT | CONST_CS);
     319           0 :         REGISTER_LONG_CONSTANT("FTP_FINISHED", PHP_FTP_FINISHED, CONST_PERSISTENT | CONST_CS);
     320           0 :         REGISTER_LONG_CONSTANT("FTP_MOREDATA", PHP_FTP_MOREDATA, CONST_PERSISTENT | CONST_CS);
     321           0 :         return SUCCESS;
     322             : }
     323             : 
     324           0 : PHP_MINFO_FUNCTION(ftp)
     325             : {
     326           0 :         php_info_print_table_start();
     327           0 :         php_info_print_table_row(2, "FTP support", "enabled");
     328           0 :         php_info_print_table_end();
     329           0 : }
     330             : 
     331             : #define XTYPE(xtype, mode)      { \
     332             :                                                                 if (mode != FTPTYPE_ASCII && mode != FTPTYPE_IMAGE) { \
     333             :                                                                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Mode must be FTP_ASCII or FTP_BINARY"); \
     334             :                                                                         RETURN_FALSE; \
     335             :                                                                 } \
     336             :                                                                 xtype = mode; \
     337             :                                                         }
     338             : 
     339             : 
     340             : /* {{{ proto resource ftp_connect(string host [, int port [, int timeout]])
     341             :    Opens a FTP stream */
     342           0 : PHP_FUNCTION(ftp_connect)
     343             : {
     344             :         ftpbuf_t        *ftp;
     345             :         char            *host;
     346             :         int             host_len;
     347           0 :         long            port = 0;
     348           0 :         long            timeout_sec = FTP_DEFAULT_TIMEOUT;
     349             : 
     350           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &host, &host_len, &port, &timeout_sec) == FAILURE) {
     351           0 :                 return;
     352             :         }
     353             : 
     354           0 :         if (timeout_sec <= 0) {
     355           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Timeout has to be greater than 0");
     356           0 :                 RETURN_FALSE;
     357             :         }
     358             : 
     359             :         /* connect */
     360           0 :         if (!(ftp = ftp_open(host, (short)port, timeout_sec TSRMLS_CC))) {
     361           0 :                 RETURN_FALSE;
     362             :         }
     363             : 
     364             :         /* autoseek for resuming */
     365           0 :         ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
     366             : #if HAVE_OPENSSL_EXT
     367             :         /* disable ssl */
     368           0 :         ftp->use_ssl = 0;
     369             : #endif
     370             : 
     371           0 :         ZEND_REGISTER_RESOURCE(return_value, ftp, le_ftpbuf);
     372             : }
     373             : /* }}} */
     374             : 
     375             : #if HAVE_OPENSSL_EXT
     376             : /* {{{ proto resource ftp_ssl_connect(string host [, int port [, int timeout]])
     377             :    Opens a FTP-SSL stream */
     378           0 : PHP_FUNCTION(ftp_ssl_connect)
     379             : {
     380             :         ftpbuf_t        *ftp;
     381             :         char            *host;
     382             :         int             host_len;
     383           0 :         long            port = 0;
     384           0 :         long            timeout_sec = FTP_DEFAULT_TIMEOUT;
     385             : 
     386           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &host, &host_len, &port, &timeout_sec) == FAILURE) {
     387           0 :                 return;
     388             :         }
     389             : 
     390           0 :         if (timeout_sec <= 0) {
     391           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Timeout has to be greater than 0");
     392           0 :                 RETURN_FALSE;
     393             :         }
     394             : 
     395             :         /* connect */
     396           0 :         if (!(ftp = ftp_open(host, (short)port, timeout_sec TSRMLS_CC))) {
     397           0 :                 RETURN_FALSE;
     398             :         }
     399             : 
     400             :         /* autoseek for resuming */
     401           0 :         ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
     402             :         /* enable ssl */
     403           0 :         ftp->use_ssl = 1;
     404             : 
     405           0 :         ZEND_REGISTER_RESOURCE(return_value, ftp, le_ftpbuf);
     406             : }
     407             : /* }}} */
     408             : #endif
     409             : 
     410             : /* {{{ proto bool ftp_login(resource stream, string username, string password)
     411             :    Logs into the FTP server */
     412           0 : PHP_FUNCTION(ftp_login)
     413             : {
     414             :         zval            *z_ftp;
     415             :         ftpbuf_t        *ftp;
     416             :         char *user, *pass;
     417             :         int user_len, pass_len;
     418             : 
     419           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &z_ftp, &user, &user_len, &pass, &pass_len) == FAILURE) {
     420           0 :                 return;
     421             :         }
     422             : 
     423           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     424             : 
     425             :         /* log in */
     426           0 :         if (!ftp_login(ftp, user, pass TSRMLS_CC)) {
     427           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     428           0 :                 RETURN_FALSE;
     429             :         }
     430             : 
     431           0 :         RETURN_TRUE;
     432             : }
     433             : /* }}} */
     434             : 
     435             : /* {{{ proto string ftp_pwd(resource stream)
     436             :    Returns the present working directory */
     437           0 : PHP_FUNCTION(ftp_pwd)
     438             : {
     439             :         zval            *z_ftp;
     440             :         ftpbuf_t        *ftp;
     441             :         const char      *pwd;
     442             : 
     443           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
     444           0 :                 return;
     445             :         }
     446             : 
     447           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     448             : 
     449           0 :         if (!(pwd = ftp_pwd(ftp))) {
     450           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     451           0 :                 RETURN_FALSE;
     452             :         }
     453             : 
     454           0 :         RETURN_STRING((char*) pwd, 1);
     455             : }
     456             : /* }}} */
     457             : 
     458             : /* {{{ proto bool ftp_cdup(resource stream)
     459             :    Changes to the parent directory */
     460           0 : PHP_FUNCTION(ftp_cdup)
     461             : {
     462             :         zval            *z_ftp;
     463             :         ftpbuf_t        *ftp;
     464             : 
     465           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
     466           0 :                 return;
     467             :         }
     468             : 
     469           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     470             : 
     471           0 :         if (!ftp_cdup(ftp)) {
     472           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     473           0 :                 RETURN_FALSE;
     474             :         }
     475             : 
     476           0 :         RETURN_TRUE;
     477             : }
     478             : /* }}} */
     479             : 
     480             : /* {{{ proto bool ftp_chdir(resource stream, string directory)
     481             :    Changes directories */
     482           0 : PHP_FUNCTION(ftp_chdir)
     483             : {
     484             :         zval            *z_ftp;
     485             :         ftpbuf_t        *ftp;
     486             :         char            *dir;
     487             :         int                     dir_len;
     488             : 
     489           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
     490           0 :                 return;
     491             :         }
     492             : 
     493           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     494             : 
     495             :         /* change directories */
     496           0 :         if (!ftp_chdir(ftp, dir)) {
     497           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     498           0 :                 RETURN_FALSE;
     499             :         }
     500             : 
     501           0 :         RETURN_TRUE;
     502             : }
     503             : /* }}} */
     504             : 
     505             : /* {{{ proto bool ftp_exec(resource stream, string command)
     506             :    Requests execution of a program on the FTP server */
     507           0 : PHP_FUNCTION(ftp_exec)
     508             : {
     509             :         zval            *z_ftp;
     510             :         ftpbuf_t        *ftp;
     511             :         char            *cmd;
     512             :         int                     cmd_len;
     513             : 
     514           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
     515           0 :                 return;
     516             :         }
     517             : 
     518           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     519             : 
     520             :         /* execute serverside command */
     521           0 :         if (!ftp_exec(ftp, cmd)) {
     522           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     523           0 :                 RETURN_FALSE;
     524             :         }
     525             : 
     526           0 :         RETURN_TRUE;
     527             : }
     528             : /* }}} */
     529             : 
     530             : /* {{{ proto array ftp_raw(resource stream, string command)
     531             :    Sends a literal command to the FTP server */
     532           0 : PHP_FUNCTION(ftp_raw)
     533             : {
     534             :         zval            *z_ftp;
     535             :         ftpbuf_t        *ftp;
     536             :         char            *cmd;
     537             :         int                     cmd_len;
     538             : 
     539           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
     540           0 :                 return;
     541             :         }
     542             : 
     543           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     544             : 
     545             :         /* execute arbitrary ftp command */
     546           0 :         ftp_raw(ftp, cmd, return_value);
     547             : }
     548             : /* }}} */
     549             : 
     550             : /* {{{ proto string ftp_mkdir(resource stream, string directory)
     551             :    Creates a directory and returns the absolute path for the new directory or false on error */
     552           0 : PHP_FUNCTION(ftp_mkdir)
     553             : {
     554             :         zval            *z_ftp;
     555             :         ftpbuf_t        *ftp;
     556             :         char            *dir, *tmp;
     557             :         int             dir_len;
     558             : 
     559           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
     560           0 :                 return;
     561             :         }
     562             : 
     563           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     564             : 
     565             :         /* create directorie */
     566           0 :         if (NULL == (tmp = ftp_mkdir(ftp, dir))) {
     567           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     568           0 :                 RETURN_FALSE;
     569             :         }
     570             : 
     571           0 :         RETURN_STRING(tmp, 0);
     572             : }
     573             : /* }}} */
     574             : 
     575             : /* {{{ proto bool ftp_rmdir(resource stream, string directory)
     576             :    Removes a directory */
     577           0 : PHP_FUNCTION(ftp_rmdir)
     578             : {
     579             :         zval            *z_ftp;
     580             :         ftpbuf_t        *ftp;
     581             :         char            *dir;
     582             :         int             dir_len;
     583             : 
     584           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir, &dir_len) == FAILURE) {
     585           0 :                 return;
     586             :         }
     587             : 
     588           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     589             : 
     590             :         /* remove directorie */
     591           0 :         if (!ftp_rmdir(ftp, dir)) {
     592           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     593           0 :                 RETURN_FALSE;
     594             :         }
     595             : 
     596           0 :         RETURN_TRUE;
     597             : }
     598             : /* }}} */
     599             : 
     600             : /* {{{ proto int ftp_chmod(resource stream, int mode, string filename)
     601             :    Sets permissions on a file */
     602           0 : PHP_FUNCTION(ftp_chmod)
     603             : {
     604             :         zval            *z_ftp;
     605             :         ftpbuf_t        *ftp;
     606             :         char            *filename;
     607             :         int             filename_len;
     608             :         long            mode;
     609             : 
     610           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlp", &z_ftp, &mode, &filename, &filename_len) == FAILURE) {
     611           0 :                 RETURN_FALSE;
     612             :         }
     613             : 
     614           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     615             : 
     616           0 :         if (!ftp_chmod(ftp, mode, filename, filename_len)) {
     617           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     618           0 :                 RETURN_FALSE;
     619             :         }
     620             : 
     621           0 :         RETURN_LONG(mode);
     622             : }
     623             : /* }}} */
     624             : 
     625             : /* {{{ proto bool ftp_alloc(resource stream, int size[, &response])
     626             :    Attempt to allocate space on the remote FTP server */
     627           0 : PHP_FUNCTION(ftp_alloc)
     628             : {
     629           0 :         zval            *z_ftp, *zresponse = NULL;
     630             :         ftpbuf_t        *ftp;
     631             :         long            size, ret;
     632           0 :         char            *response = NULL;
     633             : 
     634           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z", &z_ftp, &size, &zresponse) == FAILURE) {
     635           0 :                 RETURN_FALSE;
     636             :         }
     637             : 
     638           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     639             : 
     640           0 :         ret = ftp_alloc(ftp, size, zresponse ? &response : NULL);
     641           0 :         if (response) {
     642           0 :                 zval_dtor(zresponse);
     643           0 :                 ZVAL_STRING(zresponse, response, 0);
     644             :         }
     645             : 
     646           0 :         if (!ret) {
     647           0 :                 RETURN_FALSE;
     648             :         }
     649             : 
     650           0 :         RETURN_TRUE;
     651             : }
     652             : /* }}} */
     653             : 
     654             : /* {{{ proto array ftp_nlist(resource stream, string directory)
     655             :    Returns an array of filenames in the given directory */
     656           0 : PHP_FUNCTION(ftp_nlist)
     657             : {
     658             :         zval            *z_ftp;
     659             :         ftpbuf_t        *ftp;
     660             :         char            **nlist, **ptr, *dir;
     661             :         int             dir_len;
     662             : 
     663           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &z_ftp, &dir, &dir_len) == FAILURE) {
     664           0 :                 return;
     665             :         }
     666             : 
     667           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     668             : 
     669             :         /* get list of files */
     670           0 :         if (NULL == (nlist = ftp_nlist(ftp, dir TSRMLS_CC))) {
     671           0 :                 RETURN_FALSE;
     672             :         }
     673             : 
     674           0 :         array_init(return_value);
     675           0 :         for (ptr = nlist; *ptr; ptr++) {
     676           0 :                 add_next_index_string(return_value, *ptr, 1);
     677             :         }
     678           0 :         efree(nlist);
     679             : }
     680             : /* }}} */
     681             : 
     682             : /* {{{ proto array ftp_rawlist(resource stream, string directory [, bool recursive])
     683             :    Returns a detailed listing of a directory as an array of output lines */
     684           0 : PHP_FUNCTION(ftp_rawlist)
     685             : {
     686             :         zval            *z_ftp;
     687             :         ftpbuf_t        *ftp;
     688             :         char            **llist, **ptr, *dir;
     689             :         int             dir_len;
     690           0 :         zend_bool       recursive = 0;
     691             : 
     692           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|b", &z_ftp, &dir, &dir_len, &recursive) == FAILURE) {
     693           0 :                 return;
     694             :         }
     695             : 
     696           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     697             : 
     698             :         /* get raw directory listing */
     699           0 :         if (NULL == (llist = ftp_list(ftp, dir, recursive TSRMLS_CC))) {
     700           0 :                 RETURN_FALSE;
     701             :         }
     702             : 
     703           0 :         array_init(return_value);
     704           0 :         for (ptr = llist; *ptr; ptr++) {
     705           0 :                 add_next_index_string(return_value, *ptr, 1);
     706             :         }
     707           0 :         efree(llist);
     708             : }
     709             : /* }}} */
     710             : 
     711             : /* {{{ proto string ftp_systype(resource stream)
     712             :    Returns the system type identifier */
     713           0 : PHP_FUNCTION(ftp_systype)
     714             : {
     715             :         zval            *z_ftp;
     716             :         ftpbuf_t        *ftp;
     717             :         const char      *syst;
     718             : 
     719           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
     720           0 :                 return;
     721             :         }
     722             : 
     723           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     724             : 
     725           0 :         if (NULL == (syst = ftp_syst(ftp))) {
     726           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     727           0 :                 RETURN_FALSE;
     728             :         }
     729             : 
     730           0 :         RETURN_STRING((char*) syst, 1);
     731             : }
     732             : /* }}} */
     733             : 
     734             : /* {{{ proto bool ftp_fget(resource stream, resource fp, string remote_file, int mode[, int resumepos])
     735             :    Retrieves a file from the FTP server and writes it to an open file */
     736           0 : PHP_FUNCTION(ftp_fget)
     737             : {
     738             :         zval            *z_ftp, *z_file;
     739             :         ftpbuf_t        *ftp;
     740             :         ftptype_t       xtype;
     741             :         php_stream      *stream;
     742             :         char            *file;
     743             :         int             file_len;
     744           0 :         long            mode, resumepos=0;
     745             : 
     746           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrsl|l", &z_ftp, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) {
     747           0 :                 return;
     748             :         }
     749             : 
     750           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     751           0 :         php_stream_from_zval(stream, &z_file);
     752           0 :         XTYPE(xtype, mode);
     753             : 
     754             :         /* ignore autoresume if autoseek is switched off */
     755           0 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     756           0 :                 resumepos = 0;
     757             :         }
     758             : 
     759           0 :         if (ftp->autoseek && resumepos) {
     760             :                 /* if autoresume is wanted seek to end */
     761           0 :                 if (resumepos == PHP_FTP_AUTORESUME) {
     762           0 :                         php_stream_seek(stream, 0, SEEK_END);
     763           0 :                         resumepos = php_stream_tell(stream);
     764             :                 } else {
     765           0 :                         php_stream_seek(stream, resumepos, SEEK_SET);
     766             :                 }
     767             :         }
     768             : 
     769           0 :         if (!ftp_get(ftp, stream, file, xtype, resumepos TSRMLS_CC)) {
     770           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     771           0 :                 RETURN_FALSE;
     772             :         }
     773             : 
     774           0 :         RETURN_TRUE;
     775             : }
     776             : /* }}} */
     777             : 
     778             : /* {{{ proto int ftp_nb_fget(resource stream, resource fp, string remote_file, int mode[, int resumepos])
     779             :    Retrieves a file from the FTP server asynchronly and writes it to an open file */
     780           0 : PHP_FUNCTION(ftp_nb_fget)
     781             : {
     782             :         zval            *z_ftp, *z_file;
     783             :         ftpbuf_t        *ftp;
     784             :         ftptype_t       xtype;
     785             :         php_stream      *stream;
     786             :         char            *file;
     787             :         int             file_len;
     788           0 :         long            mode, resumepos=0, ret;
     789             : 
     790           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrsl|l", &z_ftp, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) {
     791           0 :                 return;
     792             :         }
     793             : 
     794           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     795           0 :         php_stream_from_zval(stream, &z_file);
     796           0 :         XTYPE(xtype, mode);
     797             : 
     798             :         /* ignore autoresume if autoseek is switched off */
     799           0 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     800           0 :                 resumepos = 0;
     801             :         }
     802             : 
     803           0 :         if (ftp->autoseek && resumepos) {
     804             :                 /* if autoresume is wanted seek to end */
     805           0 :                 if (resumepos == PHP_FTP_AUTORESUME) {
     806           0 :                         php_stream_seek(stream, 0, SEEK_END);
     807           0 :                         resumepos = php_stream_tell(stream);
     808             :                 } else {
     809           0 :                         php_stream_seek(stream, resumepos, SEEK_SET);
     810             :                 }
     811             :         }
     812             : 
     813             :         /* configuration */
     814           0 :         ftp->direction = 0;   /* recv */
     815           0 :         ftp->closestream = 0; /* do not close */
     816             : 
     817           0 :         if ((ret = ftp_nb_get(ftp, stream, file, xtype, resumepos TSRMLS_CC)) == PHP_FTP_FAILED) {
     818           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     819           0 :                 RETURN_LONG(ret);
     820             :         }
     821             : 
     822           0 :         RETURN_LONG(ret);
     823             : }
     824             : /* }}} */
     825             : 
     826             : /* {{{ proto bool ftp_pasv(resource stream, bool pasv)
     827             :    Turns passive mode on or off */
     828           0 : PHP_FUNCTION(ftp_pasv)
     829             : {
     830             :         zval            *z_ftp;
     831             :         ftpbuf_t        *ftp;
     832             :         zend_bool       pasv;
     833             : 
     834           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &z_ftp, &pasv) == FAILURE) {
     835           0 :                 return;
     836             :         }
     837             : 
     838           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     839             : 
     840           0 :         if (!ftp_pasv(ftp, pasv ? 1 : 0)) {
     841           0 :                 RETURN_FALSE;
     842             :         }
     843             : 
     844           0 :         RETURN_TRUE;
     845             : }
     846             : /* }}} */
     847             : 
     848             : /* {{{ proto bool ftp_get(resource stream, string local_file, string remote_file, int mode[, int resume_pos])
     849             :    Retrieves a file from the FTP server and writes it to a local file */
     850           0 : PHP_FUNCTION(ftp_get)
     851             : {
     852             :         zval            *z_ftp;
     853             :         ftpbuf_t        *ftp;
     854             :         ftptype_t       xtype;
     855             :         php_stream      *outstream;
     856             :         char            *local, *remote;
     857             :         int             local_len, remote_len;
     858           0 :         long            mode, resumepos=0;
     859             : 
     860           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rppl|l", &z_ftp, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) {
     861           0 :                 return;
     862             :         }
     863             : 
     864           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     865           0 :         XTYPE(xtype, mode);
     866             : 
     867             :         /* ignore autoresume if autoseek is switched off */
     868           0 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     869           0 :                 resumepos = 0;
     870             :         }
     871             : 
     872             : #ifdef PHP_WIN32
     873             :         mode = FTPTYPE_IMAGE;
     874             : #endif
     875             : 
     876           0 :         if (ftp->autoseek && resumepos) {
     877           0 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt+" : "rb+", REPORT_ERRORS, NULL);
     878           0 :                 if (outstream == NULL) {
     879           0 :                         outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     880             :                 }
     881           0 :                 if (outstream != NULL) {
     882             :                         /* if autoresume is wanted seek to end */
     883           0 :                         if (resumepos == PHP_FTP_AUTORESUME) {
     884           0 :                                 php_stream_seek(outstream, 0, SEEK_END);
     885           0 :                                 resumepos = php_stream_tell(outstream);
     886             :                         } else {
     887           0 :                                 php_stream_seek(outstream, resumepos, SEEK_SET);
     888             :                         }
     889             :                 }
     890             :         } else {
     891           0 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     892             :         }
     893             : 
     894           0 :         if (outstream == NULL)  {
     895           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error opening %s", local);
     896           0 :                 RETURN_FALSE;
     897             :         }
     898             : 
     899           0 :         if (!ftp_get(ftp, outstream, remote, xtype, resumepos TSRMLS_CC)) {
     900           0 :                 php_stream_close(outstream);
     901           0 :                 VCWD_UNLINK(local);
     902           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     903           0 :                 RETURN_FALSE;
     904             :         }
     905             : 
     906           0 :         php_stream_close(outstream);
     907           0 :         RETURN_TRUE;
     908             : }
     909             : /* }}} */
     910             : 
     911             : /* {{{ proto int ftp_nb_get(resource stream, string local_file, string remote_file, int mode[, int resume_pos])
     912             :    Retrieves a file from the FTP server nbhronly and writes it to a local file */
     913           0 : PHP_FUNCTION(ftp_nb_get)
     914             : {
     915             :         zval            *z_ftp;
     916             :         ftpbuf_t        *ftp;
     917             :         ftptype_t       xtype;
     918             :         php_stream      *outstream;
     919             :         char            *local, *remote;
     920             :         int             local_len, remote_len, ret;
     921           0 :         long            mode, resumepos=0;
     922             : 
     923           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl|l", &z_ftp, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) {
     924           0 :                 return;
     925             :         }
     926             : 
     927           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     928           0 :         XTYPE(xtype, mode);
     929             : 
     930             :         /* ignore autoresume if autoseek is switched off */
     931           0 :         if (!ftp->autoseek && resumepos == PHP_FTP_AUTORESUME) {
     932           0 :                 resumepos = 0;
     933             :         }
     934             : #ifdef PHP_WIN32
     935             :         mode = FTPTYPE_IMAGE;
     936             : #endif
     937           0 :         if (ftp->autoseek && resumepos) {
     938           0 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt+" : "rb+", REPORT_ERRORS, NULL);
     939           0 :                 if (outstream == NULL) {
     940           0 :                         outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     941             :                 }
     942           0 :                 if (outstream != NULL) {
     943             :                         /* if autoresume is wanted seek to end */
     944           0 :                         if (resumepos == PHP_FTP_AUTORESUME) {
     945           0 :                                 php_stream_seek(outstream, 0, SEEK_END);
     946           0 :                                 resumepos = php_stream_tell(outstream);
     947             :                         } else {
     948           0 :                                 php_stream_seek(outstream, resumepos, SEEK_SET);
     949             :                         }
     950             :                 }
     951             :         } else {
     952           0 :                 outstream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "wt" : "wb", REPORT_ERRORS, NULL);
     953             :         }
     954             : 
     955           0 :         if (outstream == NULL)  {
     956           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error opening %s", local);
     957           0 :                 RETURN_FALSE;
     958             :         }
     959             : 
     960             :         /* configuration */
     961           0 :         ftp->direction = 0;   /* recv */
     962           0 :         ftp->closestream = 1; /* do close */
     963             : 
     964           0 :         if ((ret = ftp_nb_get(ftp, outstream, remote, xtype, resumepos TSRMLS_CC)) == PHP_FTP_FAILED) {
     965           0 :                 php_stream_close(outstream);
     966           0 :                 ftp->stream = NULL;
     967           0 :                 VCWD_UNLINK(local);
     968           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
     969           0 :                 RETURN_LONG(PHP_FTP_FAILED);
     970             :         }
     971             : 
     972           0 :         if (ret == PHP_FTP_FINISHED){
     973           0 :                 php_stream_close(outstream);
     974           0 :                 ftp->stream = NULL;
     975             :         }
     976             : 
     977           0 :         RETURN_LONG(ret);
     978             : }
     979             : /* }}} */
     980             : 
     981             : /* {{{ proto int ftp_nb_continue(resource stream)
     982             :    Continues retrieving/sending a file nbronously */
     983           0 : PHP_FUNCTION(ftp_nb_continue)
     984             : {
     985             :         zval            *z_ftp;
     986             :         ftpbuf_t        *ftp;
     987             :         long            ret;
     988             : 
     989           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
     990           0 :                 return;
     991             :         }
     992             : 
     993           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
     994             : 
     995           0 :         if (!ftp->nb) {
     996           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "no nbronous transfer to continue.");
     997           0 :                 RETURN_LONG(PHP_FTP_FAILED);
     998             :         }
     999             : 
    1000           0 :         if (ftp->direction) {
    1001           0 :                 ret=ftp_nb_continue_write(ftp TSRMLS_CC);
    1002             :         } else {
    1003           0 :                 ret=ftp_nb_continue_read(ftp TSRMLS_CC);
    1004             :         }
    1005             : 
    1006           0 :         if (ret != PHP_FTP_MOREDATA && ftp->closestream) {
    1007           0 :                 php_stream_close(ftp->stream);
    1008           0 :                 ftp->stream = NULL;
    1009             :         }
    1010             : 
    1011           0 :         if (ret == PHP_FTP_FAILED) {
    1012           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1013             :         }
    1014             : 
    1015           0 :         RETURN_LONG(ret);
    1016             : }
    1017             : /* }}} */
    1018             : 
    1019             : /* {{{ proto bool ftp_fput(resource stream, string remote_file, resource fp, int mode[, int startpos])
    1020             :    Stores a file from an open file to the FTP server */
    1021           0 : PHP_FUNCTION(ftp_fput)
    1022             : {
    1023             :         zval            *z_ftp, *z_file;
    1024             :         ftpbuf_t        *ftp;
    1025             :         ftptype_t       xtype;
    1026             :         int             remote_len;
    1027           0 :         long            mode, startpos=0;
    1028             :         php_stream      *stream;
    1029             :         char            *remote;
    1030             : 
    1031           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl|l", &z_ftp, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) {
    1032           0 :                 return;
    1033             :         }
    1034             : 
    1035           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1036           0 :         php_stream_from_zval(stream, &z_file);
    1037           0 :         XTYPE(xtype, mode);
    1038             : 
    1039             :         /* ignore autoresume if autoseek is switched off */
    1040           0 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1041           0 :                 startpos = 0;
    1042             :         }
    1043             : 
    1044           0 :         if (ftp->autoseek && startpos) {
    1045             :                 /* if autoresume is wanted ask for remote size */
    1046           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1047           0 :                         startpos = ftp_size(ftp, remote);
    1048           0 :                         if (startpos < 0) {
    1049           0 :                                 startpos = 0;
    1050             :                         }
    1051             :                 }
    1052           0 :                 if (startpos) {
    1053           0 :                         php_stream_seek(stream, startpos, SEEK_SET);
    1054             :                 }
    1055             :         }
    1056             : 
    1057           0 :         if (!ftp_put(ftp, remote, stream, xtype, startpos TSRMLS_CC)) {
    1058           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1059           0 :                 RETURN_FALSE;
    1060             :         }
    1061             : 
    1062           0 :         RETURN_TRUE;
    1063             : }
    1064             : /* }}} */
    1065             : 
    1066             : /* {{{ proto int ftp_nb_fput(resource stream, string remote_file, resource fp, int mode[, int startpos])
    1067             :    Stores a file from an open file to the FTP server nbronly */
    1068           0 : PHP_FUNCTION(ftp_nb_fput)
    1069             : {
    1070             :         zval            *z_ftp, *z_file;
    1071             :         ftpbuf_t        *ftp;
    1072             :         ftptype_t       xtype;
    1073             :         int             remote_len, ret;
    1074           0 :         long            mode, startpos=0;
    1075             :         php_stream      *stream;
    1076             :         char            *remote;
    1077             : 
    1078           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl|l", &z_ftp, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) {
    1079           0 :                 return;
    1080             :         }
    1081             : 
    1082           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1083           0 :         php_stream_from_zval(stream, &z_file);
    1084           0 :         XTYPE(xtype, mode);
    1085             : 
    1086             :         /* ignore autoresume if autoseek is switched off */
    1087           0 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1088           0 :                 startpos = 0;
    1089             :         }
    1090             : 
    1091           0 :         if (ftp->autoseek && startpos) {
    1092             :                 /* if autoresume is wanted ask for remote size */
    1093           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1094           0 :                         startpos = ftp_size(ftp, remote);
    1095           0 :                         if (startpos < 0) {
    1096           0 :                                 startpos = 0;
    1097             :                         }
    1098             :                 }
    1099           0 :                 if (startpos) {
    1100           0 :                         php_stream_seek(stream, startpos, SEEK_SET);
    1101             :                 }
    1102             :         }
    1103             : 
    1104             :         /* configuration */
    1105           0 :         ftp->direction = 1;   /* send */
    1106           0 :         ftp->closestream = 0; /* do not close */
    1107             : 
    1108           0 :         if (((ret = ftp_nb_put(ftp, remote, stream, xtype, startpos TSRMLS_CC)) == PHP_FTP_FAILED)) {
    1109           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1110           0 :                 RETURN_LONG(ret);
    1111             :         }
    1112             : 
    1113           0 :         RETURN_LONG(ret);
    1114             : }
    1115             : /* }}} */
    1116             : 
    1117             : 
    1118             : /* {{{ proto bool ftp_put(resource stream, string remote_file, string local_file, int mode[, int startpos])
    1119             :    Stores a file on the FTP server */
    1120           0 : PHP_FUNCTION(ftp_put)
    1121             : {
    1122             :         zval            *z_ftp;
    1123             :         ftpbuf_t        *ftp;
    1124             :         ftptype_t       xtype;
    1125             :         char            *remote, *local;
    1126             :         long            remote_len, local_len;
    1127           0 :         long            mode, startpos=0;
    1128             :         php_stream      *instream;
    1129             : 
    1130           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rppl|l", &z_ftp, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) {
    1131           0 :                 return;
    1132             :         }
    1133             : 
    1134           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1135           0 :         XTYPE(xtype, mode);
    1136             : 
    1137           0 :         if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) {
    1138           0 :                 RETURN_FALSE;
    1139             :         }
    1140             : 
    1141             :         /* ignore autoresume if autoseek is switched off */
    1142           0 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1143           0 :                 startpos = 0;
    1144             :         }
    1145             : 
    1146           0 :         if (ftp->autoseek && startpos) {
    1147             :                 /* if autoresume is wanted ask for remote size */
    1148           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1149           0 :                         startpos = ftp_size(ftp, remote);
    1150           0 :                         if (startpos < 0) {
    1151           0 :                                 startpos = 0;
    1152             :                         }
    1153             :                 }
    1154           0 :                 if (startpos) {
    1155           0 :                         php_stream_seek(instream, startpos, SEEK_SET);
    1156             :                 }
    1157             :         }
    1158             : 
    1159           0 :         if (!ftp_put(ftp, remote, instream, xtype, startpos TSRMLS_CC)) {
    1160           0 :                 php_stream_close(instream);
    1161           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1162           0 :                 RETURN_FALSE;
    1163             :         }
    1164           0 :         php_stream_close(instream);
    1165             : 
    1166           0 :         RETURN_TRUE;
    1167             : }
    1168             : /* }}} */
    1169             : 
    1170             : 
    1171             : /* {{{ proto int ftp_nb_put(resource stream, string remote_file, string local_file, int mode[, int startpos])
    1172             :    Stores a file on the FTP server */
    1173           0 : PHP_FUNCTION(ftp_nb_put)
    1174             : {
    1175             :         zval            *z_ftp;
    1176             :         ftpbuf_t        *ftp;
    1177             :         ftptype_t       xtype;
    1178             :         char            *remote, *local;
    1179             :         int             remote_len, local_len;
    1180           0 :         long            mode, startpos=0, ret;
    1181             :         php_stream      *instream;
    1182             : 
    1183           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rppl|l", &z_ftp, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) {
    1184           0 :                 return;
    1185             :         }
    1186             : 
    1187           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1188           0 :         XTYPE(xtype, mode);
    1189             : 
    1190           0 :         if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) {
    1191           0 :                 RETURN_FALSE;
    1192             :         }
    1193             : 
    1194             :         /* ignore autoresume if autoseek is switched off */
    1195           0 :         if (!ftp->autoseek && startpos == PHP_FTP_AUTORESUME) {
    1196           0 :                 startpos = 0;
    1197             :         }
    1198             : 
    1199           0 :         if (ftp->autoseek && startpos) {
    1200             :                 /* if autoresume is wanted ask for remote size */
    1201           0 :                 if (startpos == PHP_FTP_AUTORESUME) {
    1202           0 :                         startpos = ftp_size(ftp, remote);
    1203           0 :                         if (startpos < 0) {
    1204           0 :                                 startpos = 0;
    1205             :                         }
    1206             :                 }
    1207           0 :                 if (startpos) {
    1208           0 :                         php_stream_seek(instream, startpos, SEEK_SET);
    1209             :                 }
    1210             :         }
    1211             : 
    1212             :         /* configuration */
    1213           0 :         ftp->direction = 1;   /* send */
    1214           0 :         ftp->closestream = 1; /* do close */
    1215             : 
    1216           0 :         ret = ftp_nb_put(ftp, remote, instream, xtype, startpos TSRMLS_CC);
    1217             : 
    1218           0 :         if (ret != PHP_FTP_MOREDATA) {
    1219           0 :                 php_stream_close(instream);
    1220           0 :                 ftp->stream = NULL;
    1221             :         }
    1222             : 
    1223           0 :         if (ret == PHP_FTP_FAILED) {
    1224           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1225             :         }
    1226             : 
    1227           0 :         RETURN_LONG(ret);
    1228             : }
    1229             : /* }}} */
    1230             : 
    1231             : /* {{{ proto int ftp_size(resource stream, string filename)
    1232             :    Returns the size of the file, or -1 on error */
    1233           0 : PHP_FUNCTION(ftp_size)
    1234             : {
    1235             :         zval            *z_ftp;
    1236             :         ftpbuf_t        *ftp;
    1237             :         char            *file;
    1238             :         int             file_len;
    1239             : 
    1240           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &z_ftp, &file, &file_len) == FAILURE) {
    1241           0 :                 return;
    1242             :         }
    1243             : 
    1244           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1245             : 
    1246             :         /* get file size */
    1247           0 :         RETURN_LONG(ftp_size(ftp, file));
    1248             : }
    1249             : /* }}} */
    1250             : 
    1251             : /* {{{ proto int ftp_mdtm(resource stream, string filename)
    1252             :    Returns the last modification time of the file, or -1 on error */
    1253           0 : PHP_FUNCTION(ftp_mdtm)
    1254             : {
    1255             :         zval            *z_ftp;
    1256             :         ftpbuf_t        *ftp;
    1257             :         char            *file;
    1258             :         int             file_len;
    1259             : 
    1260           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &z_ftp, &file, &file_len) == FAILURE) {
    1261           0 :                 return;
    1262             :         }
    1263             : 
    1264           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1265             : 
    1266             :         /* get file mod time */
    1267           0 :         RETURN_LONG(ftp_mdtm(ftp, file));
    1268             : }
    1269             : /* }}} */
    1270             : 
    1271             : /* {{{ proto bool ftp_rename(resource stream, string src, string dest)
    1272             :    Renames the given file to a new path */
    1273           0 : PHP_FUNCTION(ftp_rename)
    1274             : {
    1275             :         zval            *z_ftp;
    1276             :         ftpbuf_t        *ftp;
    1277             :         char            *src, *dest;
    1278             :         int             src_len, dest_len;
    1279             : 
    1280           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &z_ftp, &src, &src_len, &dest, &dest_len) == FAILURE) {
    1281           0 :                 return;
    1282             :         }
    1283             : 
    1284           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1285             : 
    1286             :         /* rename the file */
    1287           0 :         if (!ftp_rename(ftp, src, dest)) {
    1288           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1289           0 :                 RETURN_FALSE;
    1290             :         }
    1291             : 
    1292           0 :         RETURN_TRUE;
    1293             : }
    1294             : /* }}} */
    1295             : 
    1296             : /* {{{ proto bool ftp_delete(resource stream, string file)
    1297             :    Deletes a file */
    1298           0 : PHP_FUNCTION(ftp_delete)
    1299             : {
    1300             :         zval            *z_ftp;
    1301             :         ftpbuf_t        *ftp;
    1302             :         char            *file;
    1303             :         int             file_len;
    1304             : 
    1305           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &file, &file_len) == FAILURE) {
    1306           0 :                 return;
    1307             :         }
    1308             : 
    1309           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1310             : 
    1311             :         /* delete the file */
    1312           0 :         if (!ftp_delete(ftp, file)) {
    1313           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1314           0 :                 RETURN_FALSE;
    1315             :         }
    1316             : 
    1317           0 :         RETURN_TRUE;
    1318             : }
    1319             : /* }}} */
    1320             : 
    1321             : /* {{{ proto bool ftp_site(resource stream, string cmd)
    1322             :    Sends a SITE command to the server */
    1323           0 : PHP_FUNCTION(ftp_site)
    1324             : {
    1325             :         zval            *z_ftp;
    1326             :         ftpbuf_t        *ftp;
    1327             :         char            *cmd;
    1328             :         int             cmd_len;
    1329             : 
    1330           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) {
    1331           0 :                 return;
    1332             :         }
    1333             : 
    1334           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1335             : 
    1336             :         /* send the site command */
    1337           0 :         if (!ftp_site(ftp, cmd)) {
    1338           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    1339           0 :                 RETURN_FALSE;
    1340             :         }
    1341             : 
    1342           0 :         RETURN_TRUE;
    1343             : }
    1344             : /* }}} */
    1345             : 
    1346             : /* {{{ proto bool ftp_close(resource stream)
    1347             :    Closes the FTP stream */
    1348           0 : PHP_FUNCTION(ftp_close)
    1349             : {
    1350             :         zval            *z_ftp;
    1351             :         ftpbuf_t        *ftp;
    1352             : 
    1353           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == FAILURE) {
    1354           0 :                 return;
    1355             :         }
    1356             : 
    1357           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1358             : 
    1359           0 :         ftp_quit(ftp);
    1360             : 
    1361           0 :         RETURN_BOOL(zend_list_delete(Z_LVAL_P(z_ftp)) == SUCCESS);
    1362             : }
    1363             : /* }}} */
    1364             : 
    1365             : /* {{{ proto bool ftp_set_option(resource stream, int option, mixed value)
    1366             :    Sets an FTP option */
    1367           0 : PHP_FUNCTION(ftp_set_option)
    1368             : {
    1369             :         zval            *z_ftp, *z_value;
    1370             :         long            option;
    1371             :         ftpbuf_t        *ftp;
    1372             : 
    1373           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &z_ftp, &option, &z_value) == FAILURE) {
    1374           0 :                 return;
    1375             :         }
    1376             : 
    1377           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1378             : 
    1379           0 :         switch (option) {
    1380             :                 case PHP_FTP_OPT_TIMEOUT_SEC:
    1381           0 :                         if (Z_TYPE_P(z_value) != IS_LONG) {
    1382           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Option TIMEOUT_SEC expects value of type long, %s given",
    1383             :                                         zend_zval_type_name(z_value));
    1384           0 :                                 RETURN_FALSE;
    1385             :                         }
    1386           0 :                         if (Z_LVAL_P(z_value) <= 0) {
    1387           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Timeout has to be greater than 0");
    1388           0 :                                 RETURN_FALSE;
    1389             :                         }
    1390           0 :                         ftp->timeout_sec = Z_LVAL_P(z_value);
    1391           0 :                         RETURN_TRUE;
    1392             :                         break;
    1393             :                 case PHP_FTP_OPT_AUTOSEEK:
    1394           0 :                         if (Z_TYPE_P(z_value) != IS_BOOL) {
    1395           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Option AUTOSEEK expects value of type boolean, %s given",
    1396             :                                         zend_zval_type_name(z_value));
    1397           0 :                                 RETURN_FALSE;
    1398             :                         }
    1399           0 :                         ftp->autoseek = Z_LVAL_P(z_value);
    1400           0 :                         RETURN_TRUE;
    1401             :                         break;
    1402             :                 default:
    1403           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option '%ld'", option);
    1404           0 :                         RETURN_FALSE;
    1405             :                         break;
    1406             :         }
    1407             : }
    1408             : /* }}} */
    1409             : 
    1410             : /* {{{ proto mixed ftp_get_option(resource stream, int option)
    1411             :    Gets an FTP option */
    1412           0 : PHP_FUNCTION(ftp_get_option)
    1413             : {
    1414             :         zval            *z_ftp;
    1415             :         long            option;
    1416             :         ftpbuf_t        *ftp;
    1417             : 
    1418           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &z_ftp, &option) == FAILURE) {
    1419           0 :                 return;
    1420             :         }
    1421             : 
    1422           0 :         ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
    1423             : 
    1424           0 :         switch (option) {
    1425             :                 case PHP_FTP_OPT_TIMEOUT_SEC:
    1426           0 :                         RETURN_LONG(ftp->timeout_sec);
    1427             :                         break;
    1428             :                 case PHP_FTP_OPT_AUTOSEEK:
    1429           0 :                         RETURN_BOOL(ftp->autoseek);
    1430             :                         break;
    1431             :                 default:
    1432           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option '%ld'", option);
    1433           0 :                         RETURN_FALSE;
    1434             :                         break;
    1435             :         }
    1436             : }
    1437             : /* }}} */
    1438             : 
    1439             : #endif /* HAVE_FTP */
    1440             : 
    1441             : /*
    1442             :  * Local variables:
    1443             :  * tab-width: 4
    1444             :  * c-basic-offset: 4
    1445             :  * indent-tabs-mode: t
    1446             :  * End:
    1447             :  */

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:47:47 +0000 (2 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.