return ftp;
bail:
- if (ftp->fd != -1)
+ if (ftp->fd != -1) {
closesocket(ftp->fd);
+ }
efree(ftp);
return NULL;
}
void
ftp_gc(ftpbuf_t *ftp)
{
- if (ftp == NULL)
+ if (ftp == NULL) {
return;
-
+ }
if (ftp->pwd) {
efree(ftp->pwd);
}
int
ftp_quit(ftpbuf_t *ftp)
{
- if (ftp == NULL)
+ if (ftp == NULL) {
return 0;
+ }
- if (!ftp_putcmd(ftp, "QUIT", NULL))
+ if (!ftp_putcmd(ftp, "QUIT", NULL)) {
return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 221)
+ }
+ if (!ftp_getresp(ftp) || ftp->resp != 221) {
return 0;
+ }
if (ftp->pwd) {
efree(ftp->pwd);
if (ftp->use_ssl) {
ctx = SSL_CTX_new(SSLv23_client_method());
if (ctx == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "ftp_login: failed to create the SSL context");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to create the SSL context");
return 0;
}
ftp->ssl_handle = SSL_new(ctx);
if (ftp->ssl_handle == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "ftp_login: failed to create the SSL handle");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to create the SSL handle");
SSL_CTX_free(ctx);
return 0;
}
SSL_set_fd(ftp->ssl_handle, ftp->fd);
if (SSL_connect(ftp->ssl_handle) <= 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "ftp_login: SSL/TLS handshake failed");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL/TLS handshake failed");
SSL_shutdown(ftp->ssl_handle);
return 0;
}
const char*
ftp_syst(ftpbuf_t *ftp)
{
- char *syst, *end;
+ char *syst, *end;
- if (ftp == NULL)
+ if (ftp == NULL) {
return NULL;
+ }
/* default to cached value */
if (ftp->syst) {
const char*
ftp_pwd(ftpbuf_t *ftp)
{
- char *pwd, *end;
+ char *pwd, *end;
if (ftp == NULL) {
return NULL;
return 0;
}
- if (ftp->pwd)
+ if (ftp->pwd) {
efree(ftp->pwd);
+ }
if (!ftp_putcmd(ftp, "CWD", dir)) {
return 0;
return 0;
}
- if (ftp->pwd)
+ if (ftp->pwd) {
efree(ftp->pwd);
+ }
if (!ftp_putcmd(ftp, "CDUP", NULL)) {
return 0;
char*
ftp_mkdir(ftpbuf_t *ftp, const char *dir)
{
- char *mkd, *end;
+ char *mkd, *end;
if (ftp == NULL) {
return NULL;
int
ftp_type(ftpbuf_t *ftp, ftptype_t type)
{
- char typechar[2] = "?";
+ char typechar[2] = "?";
if (ftp == NULL) {
return 0;
lastch = *ptr;
}
} else if (rcvd != php_stream_write(outstream, data->buf, rcvd)) {
- goto bail;
+ goto bail;
}
}
- if (type == FTPTYPE_ASCII && lastch == '\r')
+ if (type == FTPTYPE_ASCII && lastch == '\r') {
php_stream_putc(outstream, '\r');
+ }
data = data_close(ftp, data);
ftp->data = NULL;
}
}
- if (!ftp_putcmd(ftp, "STOR", path))
+ if (!ftp_putcmd(ftp, "STOR", path)) {
goto bail;
- if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125))
+ }
+ if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) {
goto bail;
-
- if ((data = data_accept(data, ftp)) == NULL)
+ }
+ if ((data = data_accept(data, ftp)) == NULL) {
goto bail;
+ }
size = 0;
ptr = data->buf;
while (!php_stream_eof(instream) && (ch = php_stream_getc(instream))!=EOF) {
/* flush if necessary */
if (FTP_BUFSIZE - size < 2) {
- if (my_send(ftp, data->fd, data->buf, size) != size)
+ if (my_send(ftp, data->fd, data->buf, size) != size) {
goto bail;
+ }
ptr = data->buf;
size = 0;
}
{
char *buf;
- if (ftp == NULL) return 0;
+ if (ftp == NULL) {
+ return 0;
+ }
buf = ftp->inbuf;
ftp->resp = 0;
}
/* connect */
- ftp = ftp_open(host, (short)port, timeout_sec TSRMLS_CC);
- if (ftp == NULL) {
+ if (!(ftp = ftp_open(host, (short)port, timeout_sec TSRMLS_CC))) {
RETURN_FALSE;
}
}
/* connect */
- ftp = ftp_open(host, (short)port, timeout_sec TSRMLS_CC);
- if (ftp == NULL) {
+ if (!(ftp = ftp_open(host, (short)port, timeout_sec TSRMLS_CC))) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
- pwd = ftp_pwd(ftp);
- if (pwd == NULL) {
+ if (!(pwd = ftp_pwd(ftp))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
XTYPE(xtype, mode);
- instream = php_stream_fopen(local, "rb", NULL);
-
- if (instream == NULL) {
+ if (!(instream = php_stream_fopen(local, "rb", NULL))) {
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
XTYPE(xtype, mode);
- instream = php_stream_fopen(local, "rb", NULL);
-
- if (instream == NULL) {
+ if (!(instream = php_stream_fopen(local, "rb", NULL))) {
RETURN_FALSE;
}