diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 3dc401a4bffbb..f37ee68617616 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -68,41 +68,37 @@ * it sends the string "cmd args\r\n" if args is non-null, or * "cmd\r\n" if args is null */ -static int ftp_putcmd( ftpbuf_t *ftp, - const char *cmd, - const size_t cmd_len, - const char *args, - const size_t args_len); +static bool ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *args, const size_t args_len); /* wrapper around send/recv to handle timeouts */ -static int my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len); -static int my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len); -static int my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen); +static int my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len); +static int my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len); +static int my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen); /* reads a line the socket , returns true on success, false on error */ -static int ftp_readline(ftpbuf_t *ftp); +static bool ftp_readline(ftpbuf_t *ftp); /* reads an ftp response, returns true on success, false on error */ -static int ftp_getresp(ftpbuf_t *ftp); +static bool ftp_getresp(ftpbuf_t *ftp); /* sets the ftp transfer type */ -static int ftp_type(ftpbuf_t *ftp, ftptype_t type); +static bool ftp_type(ftpbuf_t *ftp, ftptype_t type); /* opens up a data stream */ -static databuf_t* ftp_getdata(ftpbuf_t *ftp); +static databuf_t* ftp_getdata(ftpbuf_t *ftp); /* accepts the data connection, returns updated data buffer */ -static databuf_t* data_accept(databuf_t *data, ftpbuf_t *ftp); +static databuf_t* data_accept(databuf_t *data, ftpbuf_t *ftp); /* closes the data connection, no-op if already closed */ -static void data_close(ftpbuf_t *ftp); +static void data_close(ftpbuf_t *ftp); /* generic file lister */ -static char** ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t path_len); +static char** ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t path_len); #ifdef HAVE_FTP_SSL /* shuts down a TLS/SSL connection */ -static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle); +static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle); #endif /* IP and port conversion box */ @@ -112,9 +108,7 @@ union ipbox { unsigned char c[8]; }; -/* {{{ ftp_open */ -ftpbuf_t* -ftp_open(const char *host, short port, zend_long timeout_sec) +ftpbuf_t* ftp_open(const char *host, short port, zend_long timeout_sec) { ftpbuf_t *ftp; socklen_t size; @@ -158,14 +152,11 @@ ftp_open(const char *host, short port, zend_long timeout_sec) efree(ftp); return NULL; } -/* }}} */ -/* {{{ ftp_close */ -ftpbuf_t* -ftp_close(ftpbuf_t *ftp) +void ftp_close(ftpbuf_t *ftp) { if (ftp == NULL) { - return NULL; + return; } #ifdef HAVE_FTP_SSL if (ftp->last_ssl_session) { @@ -186,13 +177,9 @@ ftp_close(ftpbuf_t *ftp) } ftp_gc(ftp); efree(ftp); - return NULL; } -/* }}} */ -/* {{{ ftp_gc */ -void -ftp_gc(ftpbuf_t *ftp) +void ftp_gc(ftpbuf_t *ftp) { if (ftp == NULL) { return; @@ -206,21 +193,18 @@ ftp_gc(ftpbuf_t *ftp) ftp->syst = NULL; } } -/* }}} */ -/* {{{ ftp_quit */ -int -ftp_quit(ftpbuf_t *ftp) +bool ftp_quit(ftpbuf_t *ftp) { if (ftp == NULL) { - return 0; + return false; } if (!ftp_putcmd(ftp, "QUIT", sizeof("QUIT")-1, NULL, (size_t) 0)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 221) { - return 0; + return false; } if (ftp->pwd) { @@ -228,9 +212,8 @@ ftp_quit(ftpbuf_t *ftp) ftp->pwd = NULL; } - return 1; + return true; } -/* }}} */ #ifdef HAVE_FTP_SSL static int ftp_ssl_new_session_cb(SSL *ssl, SSL_SESSION *sess) @@ -248,9 +231,7 @@ static int ftp_ssl_new_session_cb(SSL *ssl, SSL_SESSION *sess) } #endif -/* {{{ ftp_login */ -int -ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pass_len) +bool ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pass_len) { #ifdef HAVE_FTP_SSL SSL_CTX *ctx = NULL; @@ -259,28 +240,28 @@ ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pa bool retry; #endif if (ftp == NULL) { - return 0; + return false; } #ifdef HAVE_FTP_SSL if (ftp->use_ssl && !ftp->ssl_active) { if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "TLS", sizeof("TLS")-1)) { - return 0; + return false; } if (!ftp_getresp(ftp)) { - return 0; + return false; } if (ftp->resp != 234) { if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "SSL", sizeof("SSL")-1)) { - return 0; + return false; } if (!ftp_getresp(ftp)) { - return 0; + return false; } if (ftp->resp != 334) { - return 0; + return false; } else { ftp->old_ssl = 1; ftp->use_ssl_for_data = 1; @@ -290,7 +271,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pa ctx = SSL_CTX_new(SSLv23_client_method()); if (ctx == NULL) { php_error_docref(NULL, E_WARNING, "Failed to create the SSL context"); - return 0; + return false; } ssl_ctx_options &= ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS; @@ -307,7 +288,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pa if (ftp->ssl_handle == NULL) { php_error_docref(NULL, E_WARNING, "Failed to create the SSL handle"); - return 0; + return false; } SSL_set_fd(ftp->ssl_handle, ftp->fd); @@ -319,11 +300,11 @@ ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pa /* TODO check if handling other error codes would make sense */ switch (err) { case SSL_ERROR_NONE: - retry = 0; + retry = false; break; case SSL_ERROR_ZERO_RETURN: - retry = 0; + retry = false; SSL_shutdown(ftp->ssl_handle); break; @@ -346,28 +327,28 @@ ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pa php_error_docref(NULL, E_WARNING, "SSL/TLS handshake failed"); SSL_shutdown(ftp->ssl_handle); SSL_free(ftp->ssl_handle); - return 0; + return false; } } while (retry); - ftp->ssl_active = 1; + ftp->ssl_active = true; if (!ftp->old_ssl) { /* set protection buffersize to zero */ if (!ftp_putcmd(ftp, "PBSZ", sizeof("PBSZ")-1, "0", sizeof("0")-1)) { - return 0; + return false; } if (!ftp_getresp(ftp)) { - return 0; + return false; } /* enable data conn encryption */ if (!ftp_putcmd(ftp, "PROT", sizeof("PROT")-1, "P", sizeof("P")-1)) { - return 0; + return false; } if (!ftp_getresp(ftp)) { - return 0; + return false; } ftp->use_ssl_for_data = (ftp->resp >= 200 && ftp->resp <=299); @@ -376,33 +357,30 @@ ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pa #endif if (!ftp_putcmd(ftp, "USER", sizeof("USER")-1, user, user_len)) { - return 0; + return false; } if (!ftp_getresp(ftp)) { - return 0; + return false; } if (ftp->resp == 230) { - return 1; + return true; } if (ftp->resp != 331) { - return 0; + return false; } if (!ftp_putcmd(ftp, "PASS", sizeof("PASS")-1, pass, pass_len)) { - return 0; + return false; } if (!ftp_getresp(ftp)) { - return 0; + return false; } return (ftp->resp == 230); } -/* }}} */ -/* {{{ ftp_reinit */ -int -ftp_reinit(ftpbuf_t *ftp) +bool ftp_reinit(ftpbuf_t *ftp) { if (ftp == NULL) { - return 0; + return false; } ftp_gc(ftp); @@ -410,19 +388,16 @@ ftp_reinit(ftpbuf_t *ftp) ftp->nb = 0; if (!ftp_putcmd(ftp, "REIN", sizeof("REIN")-1, NULL, (size_t) 0)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 220) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ ftp_syst */ -const char* -ftp_syst(ftpbuf_t *ftp) +const char* ftp_syst(ftpbuf_t *ftp) { char *syst, *end; @@ -453,11 +428,8 @@ ftp_syst(ftpbuf_t *ftp) } return ftp->syst; } -/* }}} */ -/* {{{ ftp_pwd */ -const char* -ftp_pwd(ftpbuf_t *ftp) +const char* ftp_pwd(ftpbuf_t *ftp) { char *pwd, *end; @@ -486,29 +458,23 @@ ftp_pwd(ftpbuf_t *ftp) return ftp->pwd; } -/* }}} */ -/* {{{ ftp_exec */ -int -ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) +bool ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) { if (ftp == NULL) { - return 0; + return false; } if (!ftp_putcmd(ftp, "SITE EXEC", sizeof("SITE EXEC")-1, cmd, cmd_len)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 200) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ ftp_raw */ -void -ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value) +void ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value) { if (ftp == NULL || cmd == NULL) { RETURN_NULL(); @@ -524,14 +490,11 @@ ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value } } } -/* }}} */ -/* {{{ ftp_chdir */ -int -ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) +bool ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) { if (ftp == NULL) { - return 0; + return false; } if (ftp->pwd) { @@ -540,21 +503,18 @@ ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) } if (!ftp_putcmd(ftp, "CWD", sizeof("CWD")-1, dir, dir_len)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 250) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ ftp_cdup */ -int -ftp_cdup(ftpbuf_t *ftp) +bool ftp_cdup(ftpbuf_t *ftp) { if (ftp == NULL) { - return 0; + return false; } if (ftp->pwd) { @@ -563,18 +523,15 @@ ftp_cdup(ftpbuf_t *ftp) } if (!ftp_putcmd(ftp, "CDUP", sizeof("CDUP")-1, NULL, (size_t) 0)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 250) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ ftp_mkdir */ -zend_string* -ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) +zend_string* ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) { char *mkd, *end; zend_string *ret; @@ -601,80 +558,71 @@ ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) return ret; } -/* }}} */ -/* {{{ ftp_rmdir */ -int -ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) +bool ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) { if (ftp == NULL) { - return 0; + return false; } if (!ftp_putcmd(ftp, "RMD", sizeof("RMD")-1, dir, dir_len)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 250) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ ftp_chmod */ -int -ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len) +bool ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const size_t filename_len) { char *buffer; size_t buffer_len; - if (ftp == NULL || filename_len <= 0) { - return 0; + if (ftp == NULL || filename_len == 0) { + return false; } buffer_len = spprintf(&buffer, 0, "CHMOD %o %s", mode, filename); if (!buffer) { - return 0; + return false; } if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, buffer, buffer_len)) { efree(buffer); - return 0; + return false; } efree(buffer); if (!ftp_getresp(ftp) || ftp->resp != 200) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ ftp_alloc */ -int -ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) +bool ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) { char buffer[64]; int buffer_len; if (ftp == NULL || size <= 0) { - return 0; + return false; } buffer_len = snprintf(buffer, sizeof(buffer) - 1, ZEND_LONG_FMT, size); if (buffer_len < 0) { - return 0; + return false; } if (!ftp_putcmd(ftp, "ALLO", sizeof("ALLO")-1, buffer, buffer_len)) { - return 0; + return false; } if (!ftp_getresp(ftp)) { - return 0; + return false; } if (response) { @@ -682,41 +630,29 @@ ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) } if (ftp->resp < 200 || ftp->resp >= 300) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ ftp_nlist */ -char** -ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len) +char** ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len) { return ftp_genlist(ftp, "NLST", sizeof("NLST")-1, path, path_len); } -/* }}} */ -/* {{{ ftp_list */ -char** -ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive) +char** ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive) { return ftp_genlist(ftp, ((recursive) ? "LIST -R" : "LIST"), ((recursive) ? sizeof("LIST -R")-1 : sizeof("LIST")-1), path, path_len); } -/* }}} */ -/* {{{ ftp_mlsd */ -char** -ftp_mlsd(ftpbuf_t *ftp, const char *path, const size_t path_len) +char** ftp_mlsd(ftpbuf_t *ftp, const char *path, const size_t path_len) { return ftp_genlist(ftp, "MLSD", sizeof("MLSD")-1, path, path_len); } -/* }}} */ - -/* {{{ ftp_mlsd_parse_line */ -int -ftp_mlsd_parse_line(HashTable *ht, const char *input) { +zend_result ftp_mlsd_parse_line(HashTable *ht, const char *input) +{ zval zstr; const char *end = input + strlen(input); @@ -755,42 +691,36 @@ ftp_mlsd_parse_line(HashTable *ht, const char *input) { return SUCCESS; } -/* }}} */ -/* {{{ ftp_type */ -int -ftp_type(ftpbuf_t *ftp, ftptype_t type) +static bool ftp_type(ftpbuf_t *ftp, ftptype_t type) { const char *typechar; if (ftp == NULL) { - return 0; + return false; } if (type == ftp->type) { - return 1; + return true; } if (type == FTPTYPE_ASCII) { typechar = "A"; } else if (type == FTPTYPE_IMAGE) { typechar = "I"; } else { - return 0; + return false; } if (!ftp_putcmd(ftp, "TYPE", sizeof("TYPE")-1, typechar, 1)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 200) { - return 0; + return false; } ftp->type = type; - return 1; + return true; } -/* }}} */ -/* {{{ ftp_pasv */ -int -ftp_pasv(ftpbuf_t *ftp, int pasv) +bool ftp_pasv(ftpbuf_t *ftp, int pasv) { char *ptr; union ipbox ipbox; @@ -800,21 +730,21 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) struct sockaddr_in *sin; if (ftp == NULL) { - return 0; + return false; } if (pasv && ftp->pasv == 2) { - return 1; + return true; } ftp->pasv = 0; if (!pasv) { - return 1; + return true; } n = sizeof(ftp->pasvaddr); memset(&ftp->pasvaddr, 0, n); sa = (struct sockaddr *) &ftp->pasvaddr; if (getpeername(ftp->fd, sa, &n) < 0) { - return 0; + return false; } #ifdef HAVE_IPV6 @@ -824,16 +754,16 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) /* try EPSV first */ if (!ftp_putcmd(ftp, "EPSV", sizeof("EPSV")-1, NULL, (size_t) 0)) { - return 0; + return false; } if (!ftp_getresp(ftp)) { - return 0; + return false; } if (ftp->resp == 229) { /* parse out the port */ for (ptr = ftp->inbuf; *ptr && *ptr != '('; ptr++); if (!*ptr) { - return 0; + return false; } delimiter = *++ptr; for (n = 0; *ptr && n < 3; ptr++) { @@ -844,10 +774,10 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) sin6->sin6_port = htons((unsigned short) strtoul(ptr, &endptr, 10)); if (ptr == endptr || *endptr != delimiter) { - return 0; + return false; } ftp->pasv = 2; - return 1; + return true; } } @@ -855,16 +785,16 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) #endif if (!ftp_putcmd(ftp, "PASV", sizeof("PASV")-1, NULL, (size_t) 0)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 227) { - return 0; + return false; } /* parse out the IP and port */ for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++); n = sscanf(ptr, "%lu,%lu,%lu,%lu,%lu,%lu", &b[0], &b[1], &b[2], &b[3], &b[4], &b[5]); if (n != 6) { - return 0; + return false; } for (n = 0; n < 6; n++) { ipbox.c[n] = (unsigned char) b[n]; @@ -877,20 +807,17 @@ ftp_pasv(ftpbuf_t *ftp, int pasv) ftp->pasv = 2; - return 1; + return true; } -/* }}} */ -/* {{{ ftp_get */ -int -ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos) +bool ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos) { databuf_t *data = NULL; size_t rcvd; char arg[MAX_LENGTH_OF_LONG]; if (ftp == NULL) { - return 0; + return false; } if (!ftp_type(ftp, type)) { goto bail; @@ -967,12 +894,11 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t pat goto bail; } - return 1; + return true; bail: data_close(ftp); - return 0; + return false; } -/* }}} */ static zend_result ftp_send_stream_to_data_socket(ftpbuf_t *ftp, databuf_t *data, php_stream *instream, ftptype_t type, bool send_once_and_return) { @@ -1047,15 +973,13 @@ static zend_result ftp_send_stream_to_data_socket(ftpbuf_t *ftp, databuf_t *data return SUCCESS; } -/* {{{ ftp_put */ -int -ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos) +bool ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos) { databuf_t *data = NULL; char arg[MAX_LENGTH_OF_LONG]; if (ftp == NULL) { - return 0; + return false; } if (!ftp_type(ftp, type)) { goto bail; @@ -1097,22 +1021,18 @@ ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *inst if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250 && ftp->resp != 200)) { goto bail; } - return 1; + return true; bail: data_close(ftp); - return 0; + return false; } -/* }}} */ - -/* {{{ ftp_append */ -int -ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type) +bool ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type) { - databuf_t *data = NULL; + databuf_t *data = NULL; if (ftp == NULL) { - return 0; + return false; } if (!ftp_type(ftp, type)) { goto bail; @@ -1141,16 +1061,13 @@ ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *i if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250 && ftp->resp != 200)) { goto bail; } - return 1; + return true; bail: data_close(ftp); - return 0; + return false; } -/* }}} */ -/* {{{ ftp_size */ -zend_long -ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len) +zend_long ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len) { if (ftp == NULL) { return -1; @@ -1166,11 +1083,8 @@ ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len) } return ZEND_ATOL(ftp->inbuf); } -/* }}} */ -/* {{{ ftp_mdtm */ -time_t -ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len) +time_t ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len) { time_t stamp; struct tm *gmt, tmbuf; @@ -1213,116 +1127,97 @@ ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len) return stamp; } -/* }}} */ -/* {{{ ftp_delete */ -int -ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len) +bool ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len) { if (ftp == NULL) { - return 0; + return false; } if (!ftp_putcmd(ftp, "DELE", sizeof("DELE")-1, path, path_len)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 250) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ ftp_rename */ -int -ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t dest_len) +bool ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t dest_len) { if (ftp == NULL) { - return 0; + return false; } if (!ftp_putcmd(ftp, "RNFR", sizeof("RNFR")-1, src, src_len)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 350) { - return 0; + return false; } if (!ftp_putcmd(ftp, "RNTO", sizeof("RNTO")-1, dest, dest_len)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp != 250) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ ftp_site */ -int -ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) +bool ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) { if (ftp == NULL) { - return 0; + return false; } if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, cmd, cmd_len)) { - return 0; + return false; } if (!ftp_getresp(ftp) || ftp->resp < 200 || ftp->resp >= 300) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ - -/* static functions */ -/* {{{ ftp_putcmd */ -int -ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *args, const size_t args_len) +static bool ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *args, const size_t args_len) { - int size; - char *data; + int size; + char data[FTP_BUFSIZE]; if (strpbrk(cmd, "\r\n")) { - return 0; + return false; } /* build the output buffer */ if (args && args[0]) { /* "cmd args\r\n\0" */ if (cmd_len + args_len + 4 > FTP_BUFSIZE) { - return 0; + return false; } if (strpbrk(args, "\r\n")) { return 0; } - size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s %s\r\n", cmd, args); + size = slprintf(data, sizeof(data), "%s %s\r\n", cmd, args); } else { /* "cmd\r\n\0" */ if (cmd_len + 3 > FTP_BUFSIZE) { - return 0; + return false; } - size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s\r\n", cmd); + size = slprintf(data, sizeof(data), "%s\r\n", cmd); } - data = ftp->outbuf; - /* Clear the inbuf and extra-lines buffer */ ftp->inbuf[0] = '\0'; ftp->extra = NULL; if (my_send(ftp, ftp->fd, data, size) != size) { - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ ftp_readline */ -int -ftp_readline(ftpbuf_t *ftp) +static bool ftp_readline(ftpbuf_t *ftp) { - long size, rcvd; - char *data, *eol; + long size, rcvd; + char *data, *eol; /* shift the extra to the front */ size = FTP_BUFSIZE; @@ -1347,42 +1242,39 @@ ftp_readline(ftpbuf_t *ftp) if ((ftp->extralen = --rcvd) == 0) { ftp->extra = NULL; } - return 1; + return true; } else if (*eol == '\n') { *eol = 0; ftp->extra = eol + 1; if ((ftp->extralen = --rcvd) == 0) { ftp->extra = NULL; } - return 1; + return true; } } data = eol; if ((rcvd = my_recv(ftp, ftp->fd, data, size)) < 1) { *data = 0; - return 0; + return false; } } while (size); *data = 0; - return 0; + return false; } -/* }}} */ -/* {{{ ftp_getresp */ -int -ftp_getresp(ftpbuf_t *ftp) +static bool ftp_getresp(ftpbuf_t *ftp) { if (ftp == NULL) { - return 0; + return false; } ftp->resp = 0; while (1) { if (!ftp_readline(ftp)) { - return 0; + return false; } /* Break out when the end-tag is found */ @@ -1393,7 +1285,7 @@ ftp_getresp(ftpbuf_t *ftp) /* translate the tag */ if (!isdigit(ftp->inbuf[0]) || !isdigit(ftp->inbuf[1]) || !isdigit(ftp->inbuf[2])) { - return 0; + return false; } ftp->resp = 100 * (ftp->inbuf[0] - '0') + 10 * (ftp->inbuf[1] - '0') + (ftp->inbuf[2] - '0'); @@ -1403,9 +1295,8 @@ ftp_getresp(ftpbuf_t *ftp) if (ftp->extra) { ftp->extra -= 4; } - return 1; + return true; } -/* }}} */ static ssize_t my_send_wrapper_with_restart(php_socket_t fd, const void *buf, size_t size, int flags) { ssize_t n; @@ -1423,7 +1314,7 @@ static ssize_t my_recv_wrapper_with_restart(php_socket_t fd, void *buf, size_t s return n; } -int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { +static int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { #ifdef HAVE_FTP_SSL int err; bool retry = 0; @@ -1506,9 +1397,7 @@ static int my_poll(php_socket_t fd, int events, int timeout) { return n; } -/* {{{ my_send */ -int -my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) +static int my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) { zend_long size, sent; int n; @@ -1541,13 +1430,10 @@ my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) return len; } -/* }}} */ -/* {{{ my_recv */ -int -my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) +static int my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) { - int n, nr_bytes; + int n, nr_bytes; #ifdef HAVE_FTP_SSL int err; bool retry = 0; @@ -1620,13 +1506,10 @@ my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) #endif return (nr_bytes); } -/* }}} */ -/* {{{ data_available */ -int -data_available(ftpbuf_t *ftp, php_socket_t s) +static bool data_available(ftpbuf_t *ftp, php_socket_t s) { - int n; + int n; n = my_poll(s, PHP_POLLREADABLE, 1000); if (n < 1) { @@ -1639,17 +1522,15 @@ data_available(ftpbuf_t *ftp, php_socket_t s) #endif } php_error_docref(NULL, E_WARNING, "%s", php_socket_strerror(errno, buf, sizeof buf)); - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ data_writeable */ -int -data_writeable(ftpbuf_t *ftp, php_socket_t s) + +static bool data_writeable(ftpbuf_t *ftp, php_socket_t s) { - int n; + int n; n = my_poll(s, POLLOUT, 1000); if (n < 1) { @@ -1662,18 +1543,15 @@ data_writeable(ftpbuf_t *ftp, php_socket_t s) #endif } php_error_docref(NULL, E_WARNING, "%s", php_socket_strerror(errno, buf, sizeof buf)); - return 0; + return false; } - return 1; + return true; } -/* }}} */ -/* {{{ my_accept */ -int -my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen) +static int my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen) { - int n; + int n; n = my_poll(s, PHP_POLLREADABLE, ftp->timeout_sec * 1000); if (n < 1) { @@ -1691,11 +1569,8 @@ my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrl return accept(s, addr, addrlen); } -/* }}} */ -/* {{{ ftp_getdata */ -databuf_t* -ftp_getdata(ftpbuf_t *ftp) +static databuf_t* ftp_getdata(ftpbuf_t *ftp) { int fd = -1; databuf_t *data; @@ -1824,14 +1699,11 @@ ftp_getdata(ftpbuf_t *ftp) efree(data); return NULL; } -/* }}} */ -/* {{{ data_accept */ -databuf_t* -data_accept(databuf_t *data, ftpbuf_t *ftp) +static databuf_t* data_accept(databuf_t *data, ftpbuf_t *ftp) { php_sockaddr_storage addr; - socklen_t size; + socklen_t size; #ifdef HAVE_FTP_SSL SSL_CTX *ctx; @@ -1937,9 +1809,7 @@ data_accept(databuf_t *data, ftpbuf_t *ftp) return data; } -/* }}} */ -/* {{{ ftp_ssl_shutdown */ #ifdef HAVE_FTP_SSL static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) { /* In TLS 1.3 it's common to receive session tickets after the handshake has completed. We need to train @@ -2000,10 +1870,8 @@ static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) { (void)SSL_free(ssl_handle); } #endif -/* }}} */ -/* {{{ data_close */ -void data_close(ftpbuf_t *ftp) +static void data_close(ftpbuf_t *ftp) { ZEND_ASSERT(ftp != NULL); databuf_t *data = ftp->data; @@ -2033,11 +1901,8 @@ void data_close(ftpbuf_t *ftp) ftp->data = NULL; efree(data); } -/* }}} */ -/* {{{ ftp_genlist */ -char** -ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t path_len) +static char** ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t path_len) { php_stream *tmpstream = NULL; databuf_t *data = NULL; @@ -2137,14 +2002,11 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *pa efree(ret); return NULL; } -/* }}} */ -/* {{{ ftp_nb_get */ -int -ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos) +int ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos) { - databuf_t *data = NULL; - char arg[MAX_LENGTH_OF_LONG]; + databuf_t *data = NULL; + char arg[MAX_LENGTH_OF_LONG]; if (ftp == NULL) { return PHP_FTP_FAILED; @@ -2203,11 +2065,8 @@ ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t data_close(ftp); return PHP_FTP_FAILED; } -/* }}} */ -/* {{{ ftp_nb_continue_read */ -int -ftp_nb_continue_read(ftpbuf_t *ftp) +int ftp_nb_continue_read(ftpbuf_t *ftp) { databuf_t *data = NULL; char *ptr; @@ -2265,11 +2124,8 @@ ftp_nb_continue_read(ftpbuf_t *ftp) data_close(ftp); return PHP_FTP_FAILED; } -/* }}} */ -/* {{{ ftp_nb_put */ -int -ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos) +int ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos) { databuf_t *data = NULL; char arg[MAX_LENGTH_OF_LONG]; @@ -2317,12 +2173,8 @@ ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *i data_close(ftp); return PHP_FTP_FAILED; } -/* }}} */ - -/* {{{ ftp_nb_continue_write */ -int -ftp_nb_continue_write(ftpbuf_t *ftp) +int ftp_nb_continue_write(ftpbuf_t *ftp) { /* check if we can write more data */ if (!data_writeable(ftp, ftp->data->fd)) { @@ -2349,4 +2201,3 @@ ftp_nb_continue_write(ftpbuf_t *ftp) ftp->nb = 0; return PHP_FTP_FAILED; } -/* }}} */ diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h index 94abc588ca857..241f92f57ec35 100644 --- a/ext/ftp/ftp.h +++ b/ext/ftp/ftp.h @@ -60,7 +60,6 @@ typedef struct ftpbuf char inbuf[FTP_BUFSIZE]; /* last response text */ char *extra; /* extra characters */ int extralen; /* number of extra chars */ - char outbuf[FTP_BUFSIZE]; /* command output buffer */ char *pwd; /* cached pwd */ char *syst; /* cached system type */ ftptype_t type; /* current transfer type */ @@ -92,42 +91,42 @@ typedef struct ftpbuf /* open a FTP connection, returns ftpbuf (NULL on error) * port is the ftp port in network byte order, or 0 for the default */ -ftpbuf_t* ftp_open(const char *host, short port, zend_long timeout_sec); +ftpbuf_t* ftp_open(const char *host, short port, zend_long timeout_sec); /* quits from the ftp session (it still needs to be closed) * return true on success, false on error */ -int ftp_quit(ftpbuf_t *ftp); +bool ftp_quit(ftpbuf_t *ftp); /* frees up any cached data held in the ftp buffer */ -void ftp_gc(ftpbuf_t *ftp); +void ftp_gc(ftpbuf_t *ftp); /* close the FTP connection and return NULL */ -ftpbuf_t* ftp_close(ftpbuf_t *ftp); +void ftp_close(ftpbuf_t *ftp); /* logs into the FTP server, returns true on success, false on error */ -int ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pass_len); +bool ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pass_len); /* reinitializes the connection, returns true on success, false on error */ -int ftp_reinit(ftpbuf_t *ftp); +bool ftp_reinit(ftpbuf_t *ftp); /* returns the remote system type (NULL on error) */ -const char* ftp_syst(ftpbuf_t *ftp); +const char* ftp_syst(ftpbuf_t *ftp); /* returns the present working directory (NULL on error) */ -const char* ftp_pwd(ftpbuf_t *ftp); +const char* ftp_pwd(ftpbuf_t *ftp); /* exec a command [special features], return true on success, false on error */ -int ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len); +bool ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len); /* send a raw ftp command, return response as a hashtable, NULL on error */ -void ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value); +void ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value); /* changes directories, return true on success, false on error */ -int ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); +bool ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); /* changes to parent directory, return true on success, false on error */ -int ftp_cdup(ftpbuf_t *ftp); +bool ftp_cdup(ftpbuf_t *ftp); /* creates a directory, return the directory name on success, NULL on error. * the return value must be freed @@ -135,95 +134,94 @@ int ftp_cdup(ftpbuf_t *ftp); zend_string* ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); /* removes a directory, return true on success, false on error */ -int ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); +bool ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len); /* Set permissions on a file */ -int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len); +bool ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const size_t filename_len); /* Allocate space on remote server with ALLO command * Many servers will respond with 202 Allocation not necessary, * however some servers will not accept STOR or APPE until ALLO is confirmed. * If response is passed, it is estrdup()ed from ftp->inbuf and must be freed * or assigned to a zval returned to the user */ -int ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response); +bool ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response); /* returns a NULL-terminated array of filenames in the given path * or NULL on error. the return array must be freed (but don't * free the array elements) */ -char** ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len); +char** ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len); /* returns a NULL-terminated array of lines returned by the ftp * LIST command for the given path or NULL on error. the return * array must be freed (but don't * free the array elements) */ -char** ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive); +char** ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive); /* populates a hashtable with the facts contained in one line of * an MLSD response. */ -int ftp_mlsd_parse_line(HashTable *ht, const char *input); +zend_result ftp_mlsd_parse_line(HashTable *ht, const char *input); /* returns a NULL-terminated array of lines returned by the ftp * MLSD command for the given path or NULL on error. the return * array must be freed (but don't * free the array elements) */ -char** ftp_mlsd(ftpbuf_t *ftp, const char *path, const size_t path_len); +char** ftp_mlsd(ftpbuf_t *ftp, const char *path, const size_t path_len); /* switches passive mode on or off * returns true on success, false on error */ -int ftp_pasv(ftpbuf_t *ftp, int pasv); +bool ftp_pasv(ftpbuf_t *ftp, int pasv); /* retrieves a file and saves its contents to outfp * returns true on success, false on error */ -int ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos); +bool ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos); /* stores the data from a file, socket, or process as a file on the remote server * returns true on success, false on error */ -int ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos); +bool ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos); /* append the data from a file, socket, or process as a file on the remote server * returns true on success, false on error */ -int ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type); +bool ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type); /* returns the size of the given file, or -1 on error */ -zend_long ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len); +zend_long ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len); /* returns the last modified time of the given file, or -1 on error */ -time_t ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len); +time_t ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len); /* renames a file on the server */ -int ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t dest_len); +bool ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t dest_len); /* deletes the file from the server */ -int ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len); +bool ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len); /* sends a SITE command to the server */ -int ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len); +bool ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len); /* retrieves part of a file and saves its contents to outfp * returns true on success, false on error */ -int ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos); +int ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos); /* stores the data from a file, socket, or process as a file on the remote server * returns true on success, false on error */ -int ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos); +int ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos); /* continues a previous nb_(f)get command */ -int ftp_nb_continue_read(ftpbuf_t *ftp); +int ftp_nb_continue_read(ftpbuf_t *ftp); /* continues a previous nb_(f)put command */ -int ftp_nb_continue_write(ftpbuf_t *ftp); - +int ftp_nb_continue_write(ftpbuf_t *ftp); #endif diff --git a/ext/ftp/ftp.stub.php b/ext/ftp/ftp.stub.php index beab97f2d98e4..6560dd8930186 100644 --- a/ext/ftp/ftp.stub.php +++ b/ext/ftp/ftp.stub.php @@ -132,7 +132,7 @@ function ftp_close(FTP\Connection $ftp): bool {} function ftp_quit(FTP\Connection $ftp): bool {} /** @param int|bool $value */ - function ftp_set_option(FTP\Connection $ftp, int $option, $value): bool {} + function ftp_set_option(FTP\Connection $ftp, int $option, $value): true {} function ftp_get_option(FTP\Connection $ftp, int $option): int|bool {} } diff --git a/ext/ftp/ftp_arginfo.h b/ext/ftp/ftp_arginfo.h index e28a549f9d670..77bc47df03f69 100644 --- a/ext/ftp/ftp_arginfo.h +++ b/ext/ftp/ftp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 072486274a3361dee3655cfd046a293cfb8a2757 */ + * Stub hash: 29606d7114a0698b8ae231173a624b17c196ffec */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_ftp_connect, 0, 1, FTP\\Connection, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) @@ -182,7 +182,7 @@ ZEND_END_ARG_INFO() #define arginfo_ftp_quit arginfo_ftp_cdup -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_set_option, 0, 3, _IS_BOOL, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_set_option, 0, 3, IS_TRUE, 0) ZEND_ARG_OBJ_INFO(0, ftp, FTP\\Connection, 0) ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0) ZEND_ARG_INFO(0, value) diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index 17dc94b728eba..fb771a66d73e4 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -162,7 +162,7 @@ PHP_FUNCTION(ftp_connect) ftp->usepasvaddress = FTP_DEFAULT_USEPASVADDRESS; #ifdef HAVE_FTP_SSL /* disable ssl */ - ftp->use_ssl = 0; + ftp->use_ssl = false; #endif object_init_ex(return_value, php_ftp_ce); @@ -198,7 +198,7 @@ PHP_FUNCTION(ftp_ssl_connect) ftp->autoseek = FTP_DEFAULT_AUTOSEEK; ftp->usepasvaddress = FTP_DEFAULT_USEPASVADDRESS; /* enable ssl */ - ftp->use_ssl = 1; + ftp->use_ssl = true; object_init_ex(return_value, php_ftp_ce); ftp_object_from_zend_object(Z_OBJ_P(return_value))->ftp = ftp; @@ -390,7 +390,7 @@ PHP_FUNCTION(ftp_rmdir) } GET_FTPBUF(ftp, z_ftp); - /* remove directorie */ + /* remove directories */ if (!ftp_rmdir(ftp, dir, dir_len)) { if (*ftp->inbuf) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); @@ -432,7 +432,7 @@ PHP_FUNCTION(ftp_alloc) { zval *z_ftp, *zresponse = NULL; ftpbuf_t *ftp; - zend_long size, ret; + zend_long size; zend_string *response = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol|z", &z_ftp, php_ftp_ce, &size, &zresponse) == FAILURE) { @@ -440,17 +440,13 @@ PHP_FUNCTION(ftp_alloc) } GET_FTPBUF(ftp, z_ftp); - ret = ftp_alloc(ftp, size, zresponse ? &response : NULL); + bool ret = ftp_alloc(ftp, size, zresponse ? &response : NULL); if (response) { ZEND_TRY_ASSIGN_REF_STR(zresponse, response); } - if (!ret) { - RETURN_FALSE; - } - - RETURN_TRUE; + RETURN_BOOL(ret); } /* }}} */ @@ -797,8 +793,8 @@ PHP_FUNCTION(ftp_nb_get) } /* configuration */ - ftp->direction = 0; /* recv */ - ftp->closestream = 1; /* do close */ + ftp->direction = false; /* recv */ + ftp->closestream = true; /* do close */ if ((ret = ftp_nb_get(ftp, outstream, remote, remote_len, xtype, resumepos)) == PHP_FTP_FAILED) { php_stream_close(outstream); @@ -950,8 +946,8 @@ PHP_FUNCTION(ftp_nb_fput) } /* configuration */ - ftp->direction = 1; /* send */ - ftp->closestream = 0; /* do not close */ + ftp->direction = true; /* send */ + ftp->closestream = false; /* do not close */ if (((ret = ftp_nb_put(ftp, remote, remote_len, stream, xtype, startpos)) == PHP_FTP_FAILED)) { if (*ftp->inbuf) { @@ -1091,8 +1087,8 @@ PHP_FUNCTION(ftp_nb_put) } /* configuration */ - ftp->direction = 1; /* send */ - ftp->closestream = 1; /* do close */ + ftp->direction = true; /* send */ + ftp->closestream = true; /* do close */ ret = ftp_nb_put(ftp, remote, remote_len, instream, xtype, startpos);