Lines Matching refs:ftp

71 static int		ftp_putcmd(	ftpbuf_t *ftp,
78 static int my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len);
79 static int my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len);
80 static int my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen);
83 static int ftp_readline(ftpbuf_t *ftp);
86 static int ftp_getresp(ftpbuf_t *ftp);
89 static int ftp_type(ftpbuf_t *ftp, ftptype_t type);
92 static databuf_t* ftp_getdata(ftpbuf_t *ftp);
95 static databuf_t* data_accept(databuf_t *data, ftpbuf_t *ftp);
98 static void data_close(ftpbuf_t *ftp);
101 static char** ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, …
105 static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle);
119 ftpbuf_t *ftp; in ftp_open() local
125 ftp = ecalloc(1, sizeof(*ftp)); in ftp_open()
130 ftp->fd = php_network_connect_socket_to_host(host, in ftp_open()
133 if (ftp->fd == -1) { in ftp_open()
138 ftp->timeout_sec = timeout_sec; in ftp_open()
139 ftp->nb = 0; in ftp_open()
141 size = sizeof(ftp->localaddr); in ftp_open()
142 memset(&ftp->localaddr, 0, size); in ftp_open()
143 if (getsockname(ftp->fd, (struct sockaddr*) &ftp->localaddr, &size) != 0) { in ftp_open()
148 if (!ftp_getresp(ftp) || ftp->resp != 220) { in ftp_open()
152 return ftp; in ftp_open()
155 if (ftp->fd != -1) { in ftp_open()
156 closesocket(ftp->fd); in ftp_open()
158 efree(ftp); in ftp_open()
165 ftp_close(ftpbuf_t *ftp) in ftp_close() argument
167 if (ftp == NULL) { in ftp_close()
171 if (ftp->last_ssl_session) { in ftp_close()
172 SSL_SESSION_free(ftp->last_ssl_session); in ftp_close()
175 data_close(ftp); in ftp_close()
176 if (ftp->stream && ftp->closestream) { in ftp_close()
177 php_stream_close(ftp->stream); in ftp_close()
179 if (ftp->fd != -1) { in ftp_close()
181 if (ftp->ssl_active) { in ftp_close()
182 ftp_ssl_shutdown(ftp, ftp->fd, ftp->ssl_handle); in ftp_close()
185 closesocket(ftp->fd); in ftp_close()
187 ftp_gc(ftp); in ftp_close()
188 efree(ftp); in ftp_close()
195 ftp_gc(ftpbuf_t *ftp) in ftp_gc() argument
197 if (ftp == NULL) { in ftp_gc()
200 if (ftp->pwd) { in ftp_gc()
201 efree(ftp->pwd); in ftp_gc()
202 ftp->pwd = NULL; in ftp_gc()
204 if (ftp->syst) { in ftp_gc()
205 efree(ftp->syst); in ftp_gc()
206 ftp->syst = NULL; in ftp_gc()
213 ftp_quit(ftpbuf_t *ftp) in ftp_quit() argument
215 if (ftp == NULL) { in ftp_quit()
219 if (!ftp_putcmd(ftp, "QUIT", sizeof("QUIT")-1, NULL, (size_t) 0)) { in ftp_quit()
222 if (!ftp_getresp(ftp) || ftp->resp != 221) { in ftp_quit()
226 if (ftp->pwd) { in ftp_quit()
227 efree(ftp->pwd); in ftp_quit()
228 ftp->pwd = NULL; in ftp_quit()
238 ftpbuf_t *ftp = SSL_get_app_data(ssl); in ftp_ssl_new_session_cb() local
241 if (ftp->last_ssl_session) { in ftp_ssl_new_session_cb()
242 SSL_SESSION_free(ftp->last_ssl_session); in ftp_ssl_new_session_cb()
244 ftp->last_ssl_session = SSL_get1_session(ssl); in ftp_ssl_new_session_cb()
253 ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pa… in ftp_login() argument
261 if (ftp == NULL) { in ftp_login()
266 if (ftp->use_ssl && !ftp->ssl_active) { in ftp_login()
267 if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "TLS", sizeof("TLS")-1)) { in ftp_login()
270 if (!ftp_getresp(ftp)) { in ftp_login()
274 if (ftp->resp != 234) { in ftp_login()
275 if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "SSL", sizeof("SSL")-1)) { in ftp_login()
278 if (!ftp_getresp(ftp)) { in ftp_login()
282 if (ftp->resp != 334) { in ftp_login()
285 ftp->old_ssl = 1; in ftp_login()
286 ftp->use_ssl_for_data = 1; in ftp_login()
304 ftp->ssl_handle = SSL_new(ctx); in ftp_login()
305 SSL_set_app_data(ftp->ssl_handle, ftp); /* Needed for ftp_ssl_new_session_cb */ in ftp_login()
308 if (ftp->ssl_handle == NULL) { in ftp_login()
313 SSL_set_fd(ftp->ssl_handle, ftp->fd); in ftp_login()
316 res = SSL_connect(ftp->ssl_handle); in ftp_login()
317 err = SSL_get_error(ftp->ssl_handle, res); in ftp_login()
327 SSL_shutdown(ftp->ssl_handle); in ftp_login()
335 p.fd = ftp->fd; in ftp_login()
347 SSL_shutdown(ftp->ssl_handle); in ftp_login()
348 SSL_free(ftp->ssl_handle); in ftp_login()
353 ftp->ssl_active = 1; in ftp_login()
355 if (!ftp->old_ssl) { in ftp_login()
358 if (!ftp_putcmd(ftp, "PBSZ", sizeof("PBSZ")-1, "0", sizeof("0")-1)) { in ftp_login()
361 if (!ftp_getresp(ftp)) { in ftp_login()
366 if (!ftp_putcmd(ftp, "PROT", sizeof("PROT")-1, "P", sizeof("P")-1)) { in ftp_login()
369 if (!ftp_getresp(ftp)) { in ftp_login()
373 ftp->use_ssl_for_data = (ftp->resp >= 200 && ftp->resp <=299); in ftp_login()
378 if (!ftp_putcmd(ftp, "USER", sizeof("USER")-1, user, user_len)) { in ftp_login()
381 if (!ftp_getresp(ftp)) { in ftp_login()
384 if (ftp->resp == 230) { in ftp_login()
387 if (ftp->resp != 331) { in ftp_login()
390 if (!ftp_putcmd(ftp, "PASS", sizeof("PASS")-1, pass, pass_len)) { in ftp_login()
393 if (!ftp_getresp(ftp)) { in ftp_login()
396 return (ftp->resp == 230); in ftp_login()
402 ftp_reinit(ftpbuf_t *ftp) in ftp_reinit() argument
404 if (ftp == NULL) { in ftp_reinit()
408 ftp_gc(ftp); in ftp_reinit()
410 ftp->nb = 0; in ftp_reinit()
412 if (!ftp_putcmd(ftp, "REIN", sizeof("REIN")-1, NULL, (size_t) 0)) { in ftp_reinit()
415 if (!ftp_getresp(ftp) || ftp->resp != 220) { in ftp_reinit()
425 ftp_syst(ftpbuf_t *ftp) in ftp_syst() argument
429 if (ftp == NULL) { in ftp_syst()
434 if (ftp->syst) { in ftp_syst()
435 return ftp->syst; in ftp_syst()
437 if (!ftp_putcmd(ftp, "SYST", sizeof("SYST")-1, NULL, (size_t) 0)) { in ftp_syst()
440 if (!ftp_getresp(ftp) || ftp->resp != 215) { in ftp_syst()
443 syst = ftp->inbuf; in ftp_syst()
450 ftp->syst = estrdup(syst); in ftp_syst()
454 return ftp->syst; in ftp_syst()
460 ftp_pwd(ftpbuf_t *ftp) in ftp_pwd() argument
464 if (ftp == NULL) { in ftp_pwd()
469 if (ftp->pwd) { in ftp_pwd()
470 return ftp->pwd; in ftp_pwd()
472 if (!ftp_putcmd(ftp, "PWD", sizeof("PWD")-1, NULL, (size_t) 0)) { in ftp_pwd()
475 if (!ftp_getresp(ftp) || ftp->resp != 257) { in ftp_pwd()
479 if ((pwd = strchr(ftp->inbuf, '"')) == NULL) { in ftp_pwd()
485 ftp->pwd = estrndup(pwd, end - pwd); in ftp_pwd()
487 return ftp->pwd; in ftp_pwd()
493 ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) in ftp_exec() argument
495 if (ftp == NULL) { in ftp_exec()
498 if (!ftp_putcmd(ftp, "SITE EXEC", sizeof("SITE EXEC")-1, cmd, cmd_len)) { in ftp_exec()
501 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_exec()
511 ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value) in ftp_raw() argument
513 if (ftp == NULL || cmd == NULL) { in ftp_raw()
516 if (!ftp_putcmd(ftp, cmd, cmd_len, NULL, (size_t) 0)) { in ftp_raw()
520 while (ftp_readline(ftp)) { in ftp_raw()
521 add_next_index_string(return_value, ftp->inbuf); in ftp_raw()
522 …if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] ==… in ftp_raw()
531 ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_chdir() argument
533 if (ftp == NULL) { in ftp_chdir()
537 if (ftp->pwd) { in ftp_chdir()
538 efree(ftp->pwd); in ftp_chdir()
539 ftp->pwd = NULL; in ftp_chdir()
542 if (!ftp_putcmd(ftp, "CWD", sizeof("CWD")-1, dir, dir_len)) { in ftp_chdir()
545 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_chdir()
554 ftp_cdup(ftpbuf_t *ftp) in ftp_cdup() argument
556 if (ftp == NULL) { in ftp_cdup()
560 if (ftp->pwd) { in ftp_cdup()
561 efree(ftp->pwd); in ftp_cdup()
562 ftp->pwd = NULL; in ftp_cdup()
565 if (!ftp_putcmd(ftp, "CDUP", sizeof("CDUP")-1, NULL, (size_t) 0)) { in ftp_cdup()
568 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_cdup()
577 ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_mkdir() argument
582 if (ftp == NULL) { in ftp_mkdir()
585 if (!ftp_putcmd(ftp, "MKD", sizeof("MKD")-1, dir, dir_len)) { in ftp_mkdir()
588 if (!ftp_getresp(ftp) || ftp->resp != 257) { in ftp_mkdir()
592 if ((mkd = strchr(ftp->inbuf, '"')) == NULL) { in ftp_mkdir()
608 ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_rmdir() argument
610 if (ftp == NULL) { in ftp_rmdir()
613 if (!ftp_putcmd(ftp, "RMD", sizeof("RMD")-1, dir, dir_len)) { in ftp_rmdir()
616 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_rmdir()
625 ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len) in ftp_chmod() argument
630 if (ftp == NULL || filename_len <= 0) { in ftp_chmod()
640 if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, buffer, buffer_len)) { in ftp_chmod()
647 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_chmod()
657 ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) in ftp_alloc() argument
662 if (ftp == NULL || size <= 0) { in ftp_alloc()
672 if (!ftp_putcmd(ftp, "ALLO", sizeof("ALLO")-1, buffer, buffer_len)) { in ftp_alloc()
676 if (!ftp_getresp(ftp)) { in ftp_alloc()
681 *response = zend_string_init(ftp->inbuf, strlen(ftp->inbuf), 0); in ftp_alloc()
684 if (ftp->resp < 200 || ftp->resp >= 300) { in ftp_alloc()
694 ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_nlist() argument
696 return ftp_genlist(ftp, "NLST", sizeof("NLST")-1, path, path_len); in ftp_nlist()
702 ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive) in ftp_list() argument
704 …return ftp_genlist(ftp, ((recursive) ? "LIST -R" : "LIST"), ((recursive) ? sizeof("LIST -R")-1 : s… in ftp_list()
710 ftp_mlsd(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_mlsd() argument
712 return ftp_genlist(ftp, "MLSD", sizeof("MLSD")-1, path, path_len); in ftp_mlsd()
762 ftp_type(ftpbuf_t *ftp, ftptype_t type) in ftp_type() argument
766 if (ftp == NULL) { in ftp_type()
769 if (type == ftp->type) { in ftp_type()
779 if (!ftp_putcmd(ftp, "TYPE", sizeof("TYPE")-1, typechar, 1)) { in ftp_type()
782 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_type()
785 ftp->type = type; in ftp_type()
793 ftp_pasv(ftpbuf_t *ftp, int pasv) in ftp_pasv() argument
802 if (ftp == NULL) { in ftp_pasv()
805 if (pasv && ftp->pasv == 2) { in ftp_pasv()
808 ftp->pasv = 0; in ftp_pasv()
812 n = sizeof(ftp->pasvaddr); in ftp_pasv()
813 memset(&ftp->pasvaddr, 0, n); in ftp_pasv()
814 sa = (struct sockaddr *) &ftp->pasvaddr; in ftp_pasv()
816 if (getpeername(ftp->fd, sa, &n) < 0) { in ftp_pasv()
826 if (!ftp_putcmd(ftp, "EPSV", sizeof("EPSV")-1, NULL, (size_t) 0)) { in ftp_pasv()
829 if (!ftp_getresp(ftp)) { in ftp_pasv()
832 if (ftp->resp == 229) { in ftp_pasv()
834 for (ptr = ftp->inbuf; *ptr && *ptr != '('; ptr++); in ftp_pasv()
849 ftp->pasv = 2; in ftp_pasv()
857 if (!ftp_putcmd(ftp, "PASV", sizeof("PASV")-1, NULL, (size_t) 0)) { in ftp_pasv()
860 if (!ftp_getresp(ftp) || ftp->resp != 227) { in ftp_pasv()
864 for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++); in ftp_pasv()
873 if (ftp->usepasvaddress) { in ftp_pasv()
878 ftp->pasv = 2; in ftp_pasv()
886 ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t ty… in ftp_get() argument
892 if (ftp == NULL) { in ftp_get()
895 if (!ftp_type(ftp, type)) { in ftp_get()
899 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_get()
909 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_get()
912 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_get()
917 if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { in ftp_get()
920 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_get()
924 if ((data = data_accept(data, ftp)) == NULL) { in ftp_get()
928 while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_get()
964 data_close(ftp); in ftp_get()
966 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_get()
972 data_close(ftp); in ftp_get()
977 static zend_result ftp_send_stream_to_data_socket(ftpbuf_t *ftp, databuf_t *data, php_stream *instr… in ftp_send_stream_to_data_socket() argument
1010 if (UNEXPECTED(my_send(ftp, data->fd, data->buf, send_size) != send_size)) { in ftp_send_stream_to_data_socket()
1025 if (UNEXPECTED(my_send(ftp, data->fd, data->buf, send_size) != send_size)) { in ftp_send_stream_to_data_socket()
1038 if (UNEXPECTED(my_send(ftp, data->fd, data->buf, size) != size)) { in ftp_send_stream_to_data_socket()
1052 ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t typ… in ftp_put() argument
1057 if (ftp == NULL) { in ftp_put()
1060 if (!ftp_type(ftp, type)) { in ftp_put()
1063 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_put()
1073 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_put()
1076 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_put()
1081 if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { in ftp_put()
1084 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_put()
1087 if ((data = data_accept(data, ftp)) == NULL) { in ftp_put()
1091 if (ftp_send_stream_to_data_socket(ftp, data, instream, type, false) != SUCCESS) { in ftp_put()
1095 data_close(ftp); in ftp_put()
1097 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250 && ftp->resp != 200)) { in ftp_put()
1102 data_close(ftp); in ftp_put()
1110 ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t … in ftp_append() argument
1114 if (ftp == NULL) { in ftp_append()
1117 if (!ftp_type(ftp, type)) { in ftp_append()
1120 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_append()
1123 ftp->data = data; in ftp_append()
1125 if (!ftp_putcmd(ftp, "APPE", sizeof("APPE")-1, path, path_len)) { in ftp_append()
1128 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_append()
1131 if ((data = data_accept(data, ftp)) == NULL) { in ftp_append()
1135 if (ftp_send_stream_to_data_socket(ftp, data, instream, type, false) != SUCCESS) { in ftp_append()
1139 data_close(ftp); in ftp_append()
1141 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250 && ftp->resp != 200)) { in ftp_append()
1146 data_close(ftp); in ftp_append()
1153 ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_size() argument
1155 if (ftp == NULL) { in ftp_size()
1158 if (!ftp_type(ftp, FTPTYPE_IMAGE)) { in ftp_size()
1161 if (!ftp_putcmd(ftp, "SIZE", sizeof("SIZE")-1, path, path_len)) { in ftp_size()
1164 if (!ftp_getresp(ftp) || ftp->resp != 213) { in ftp_size()
1167 return ZEND_ATOL(ftp->inbuf); in ftp_size()
1173 ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_mdtm() argument
1181 if (ftp == NULL) { in ftp_mdtm()
1184 if (!ftp_putcmd(ftp, "MDTM", sizeof("MDTM")-1, path, path_len)) { in ftp_mdtm()
1187 if (!ftp_getresp(ftp) || ftp->resp != 213) { in ftp_mdtm()
1191 for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++); in ftp_mdtm()
1220 ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_delete() argument
1222 if (ftp == NULL) { in ftp_delete()
1225 if (!ftp_putcmd(ftp, "DELE", sizeof("DELE")-1, path, path_len)) { in ftp_delete()
1228 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_delete()
1238 ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t des… in ftp_rename() argument
1240 if (ftp == NULL) { in ftp_rename()
1243 if (!ftp_putcmd(ftp, "RNFR", sizeof("RNFR")-1, src, src_len)) { in ftp_rename()
1246 if (!ftp_getresp(ftp) || ftp->resp != 350) { in ftp_rename()
1249 if (!ftp_putcmd(ftp, "RNTO", sizeof("RNTO")-1, dest, dest_len)) { in ftp_rename()
1252 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_rename()
1261 ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) in ftp_site() argument
1263 if (ftp == NULL) { in ftp_site()
1266 if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, cmd, cmd_len)) { in ftp_site()
1269 if (!ftp_getresp(ftp) || ftp->resp < 200 || ftp->resp >= 300) { in ftp_site()
1281 ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *args, const size_t arg… in ftp_putcmd() argument
1298 size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s %s\r\n", cmd, args); in ftp_putcmd()
1304 size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s\r\n", cmd); in ftp_putcmd()
1307 data = ftp->outbuf; in ftp_putcmd()
1310 ftp->inbuf[0] = '\0'; in ftp_putcmd()
1311 ftp->extra = NULL; in ftp_putcmd()
1313 if (my_send(ftp, ftp->fd, data, size) != size) { in ftp_putcmd()
1322 ftp_readline(ftpbuf_t *ftp) in ftp_readline() argument
1330 if (ftp->extra) { in ftp_readline()
1331 memmove(ftp->inbuf, ftp->extra, ftp->extralen); in ftp_readline()
1332 rcvd = ftp->extralen; in ftp_readline()
1335 data = ftp->inbuf; in ftp_readline()
1342 ftp->extra = eol + 1; in ftp_readline()
1344 ftp->extra++; in ftp_readline()
1347 if ((ftp->extralen = --rcvd) == 0) { in ftp_readline()
1348 ftp->extra = NULL; in ftp_readline()
1353 ftp->extra = eol + 1; in ftp_readline()
1354 if ((ftp->extralen = --rcvd) == 0) { in ftp_readline()
1355 ftp->extra = NULL; in ftp_readline()
1362 if ((rcvd = my_recv(ftp, ftp->fd, data, size)) < 1) { in ftp_readline()
1375 ftp_getresp(ftpbuf_t *ftp) in ftp_getresp() argument
1377 if (ftp == NULL) { in ftp_getresp()
1380 ftp->resp = 0; in ftp_getresp()
1384 if (!ftp_readline(ftp)) { in ftp_getresp()
1389 …if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] ==… in ftp_getresp()
1395 if (!isdigit(ftp->inbuf[0]) || !isdigit(ftp->inbuf[1]) || !isdigit(ftp->inbuf[2])) { in ftp_getresp()
1399 ftp->resp = 100 * (ftp->inbuf[0] - '0') + 10 * (ftp->inbuf[1] - '0') + (ftp->inbuf[2] - '0'); in ftp_getresp()
1401 memmove(ftp->inbuf, ftp->inbuf + 4, FTP_BUFSIZE - 4); in ftp_getresp()
1403 if (ftp->extra) { in ftp_getresp()
1404 ftp->extra -= 4; in ftp_getresp()
1410 int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { in single_send() argument
1418 if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) { in single_send()
1419 handle = ftp->ssl_handle; in single_send()
1420 fd = ftp->fd; in single_send()
1421 } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) { in single_send()
1422 handle = ftp->data->ssl_handle; in single_send()
1423 fd = ftp->data->fd; in single_send()
1470 my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) in my_send() argument
1477 n = php_pollfd_for_ms(s, POLLOUT, ftp->timeout_sec * 1000); in my_send()
1492 sent = single_send(ftp, s, buf, size); in my_send()
1507 my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) in my_recv() argument
1516 n = php_pollfd_for_ms(s, PHP_POLLREADABLE, ftp->timeout_sec * 1000); in my_recv()
1531 if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) { in my_recv()
1532 handle = ftp->ssl_handle; in my_recv()
1533 fd = ftp->fd; in my_recv()
1534 } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) { in my_recv()
1535 handle = ftp->data->ssl_handle; in my_recv()
1536 fd = ftp->data->fd; in my_recv()
1586 data_available(ftpbuf_t *ftp, php_socket_t s) in data_available() argument
1609 data_writeable(ftpbuf_t *ftp, php_socket_t s) in data_writeable() argument
1633 my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen) in my_accept() argument
1637 n = php_pollfd_for_ms(s, PHP_POLLREADABLE, ftp->timeout_sec * 1000); in my_accept()
1657 ftp_getdata(ftpbuf_t *ftp) in ftp_getdata() argument
1671 if (ftp->pasv && !ftp_pasv(ftp, 1)) { in ftp_getdata()
1678 data->type = ftp->type; in ftp_getdata()
1680 sa = (struct sockaddr *) &ftp->localaddr; in ftp_getdata()
1688 if (ftp->pasv) { in ftp_getdata()
1690 ftp->pasv = 1; in ftp_getdata()
1694 size = php_sockaddr_size(&ftp->pasvaddr); in ftp_getdata()
1695 tv.tv_sec = ftp->timeout_sec; in ftp_getdata()
1697 if (php_connect_nonb(fd, (struct sockaddr*) &ftp->pasvaddr, size, &tv) == -1) { in ftp_getdata()
1704 ftp->data = data; in ftp_getdata()
1748 if (!ftp_putcmd(ftp, "EPRT", sizeof("EPRT")-1, eprtarg, eprtarg_len)) { in ftp_getdata()
1752 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_getdata()
1756 ftp->data = data; in ftp_getdata()
1769 if (!ftp_putcmd(ftp, "PORT", sizeof("PORT")-1, arg, arg_len)) { in ftp_getdata()
1772 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_getdata()
1776 ftp->data = data; in ftp_getdata()
1790 data_accept(databuf_t *data, ftpbuf_t *ftp) in data_accept() argument
1806 data->fd = my_accept(ftp, data->listener, (struct sockaddr*) &addr, &size); in data_accept()
1819 if (ftp->use_ssl && ftp->use_ssl_for_data) { in data_accept()
1820 ctx = SSL_get_SSL_CTX(ftp->ssl_handle); in data_accept()
1834 if (ftp->old_ssl) { in data_accept()
1835 SSL_copy_session_id(data->ssl_handle, ftp->ssl_handle); in data_accept()
1839 session = ftp->last_ssl_session; in data_accept()
1847 SSL_set_app_data(data->ssl_handle, ftp); /* Needed for ftp_ssl_new_session_cb */ in data_accept()
1903 static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) { in ftp_ssl_shutdown() argument
1922 while (!done && data_available(ftp, fd)) { in ftp_ssl_shutdown()
1965 void data_close(ftpbuf_t *ftp) in data_close() argument
1967 ZEND_ASSERT(ftp != NULL); in data_close()
1968 databuf_t *data = ftp->data; in data_close()
1976 ftp_ssl_shutdown(ftp, data->listener, data->ssl_handle); in data_close()
1986 ftp_ssl_shutdown(ftp, data->fd, data->ssl_handle); in data_close()
1992 ftp->data = NULL; in data_close()
1999 ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t pa… in ftp_genlist() argument
2017 if (!ftp_type(ftp, FTPTYPE_ASCII)) { in ftp_genlist()
2021 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_genlist()
2024 ftp->data = data; in ftp_genlist()
2026 if (!ftp_putcmd(ftp, cmd, cmd_len, path, path_len)) { in ftp_genlist()
2029 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125 && ftp->resp != 226)) { in ftp_genlist()
2034 if (ftp->resp == 226) { in ftp_genlist()
2035 data_close(ftp); in ftp_genlist()
2041 if ((data = data_accept(data, ftp)) == NULL) { in ftp_genlist()
2047 while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_genlist()
2063 data_close(ftp); in ftp_genlist()
2086 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_genlist()
2093 data_close(ftp); in ftp_genlist()
2103 ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t… in ftp_nb_get() argument
2108 if (ftp == NULL) { in ftp_nb_get()
2112 if (ftp->data != NULL) { in ftp_nb_get()
2115 data_close(ftp); in ftp_nb_get()
2116 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_get()
2121 if (!ftp_type(ftp, type)) { in ftp_nb_get()
2125 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_nb_get()
2135 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_nb_get()
2138 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_nb_get()
2143 if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { in ftp_nb_get()
2146 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_nb_get()
2150 if ((data = data_accept(data, ftp)) == NULL) { in ftp_nb_get()
2154 ftp->data = data; in ftp_nb_get()
2155 ftp->stream = outstream; in ftp_nb_get()
2156 ftp->lastch = 0; in ftp_nb_get()
2157 ftp->nb = 1; in ftp_nb_get()
2159 return (ftp_nb_continue_read(ftp)); in ftp_nb_get()
2162 data_close(ftp); in ftp_nb_get()
2169 ftp_nb_continue_read(ftpbuf_t *ftp) in ftp_nb_continue_read() argument
2177 data = ftp->data; in ftp_nb_continue_read()
2180 if (!data_available(ftp, data->fd)) { in ftp_nb_continue_read()
2184 type = ftp->type; in ftp_nb_continue_read()
2186 lastch = ftp->lastch; in ftp_nb_continue_read()
2187 if ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_nb_continue_read()
2195 php_stream_putc(ftp->stream, '\r'); in ftp_nb_continue_read()
2198 php_stream_putc(ftp->stream, *ptr); in ftp_nb_continue_read()
2202 } else if (rcvd != php_stream_write(ftp->stream, data->buf, rcvd)) { in ftp_nb_continue_read()
2206 ftp->lastch = lastch; in ftp_nb_continue_read()
2211 php_stream_putc(ftp->stream, '\r'); in ftp_nb_continue_read()
2214 data_close(ftp); in ftp_nb_continue_read()
2216 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_continue_read()
2220 ftp->nb = 0; in ftp_nb_continue_read()
2223 ftp->nb = 0; in ftp_nb_continue_read()
2224 data_close(ftp); in ftp_nb_continue_read()
2231 ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t … in ftp_nb_put() argument
2236 if (ftp == NULL) { in ftp_nb_put()
2239 if (!ftp_type(ftp, type)) { in ftp_nb_put()
2242 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_nb_put()
2251 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_nb_put()
2254 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_nb_put()
2259 if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { in ftp_nb_put()
2262 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_nb_put()
2265 if ((data = data_accept(data, ftp)) == NULL) { in ftp_nb_put()
2268 ftp->data = data; in ftp_nb_put()
2269 ftp->stream = instream; in ftp_nb_put()
2270 ftp->lastch = 0; in ftp_nb_put()
2271 ftp->nb = 1; in ftp_nb_put()
2273 return (ftp_nb_continue_write(ftp)); in ftp_nb_put()
2276 data_close(ftp); in ftp_nb_put()
2284 ftp_nb_continue_write(ftpbuf_t *ftp) in ftp_nb_continue_write() argument
2287 if (!data_writeable(ftp, ftp->data->fd)) { in ftp_nb_continue_write()
2291 if (ftp_send_stream_to_data_socket(ftp, ftp->data, ftp->stream, ftp->type, true) != SUCCESS) { in ftp_nb_continue_write()
2295 if (!php_stream_eof(ftp->stream)) { in ftp_nb_continue_write()
2299 data_close(ftp); in ftp_nb_continue_write()
2301 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_continue_write()
2304 ftp->nb = 0; in ftp_nb_continue_write()
2307 data_close(ftp); in ftp_nb_continue_write()
2308 ftp->nb = 0; in ftp_nb_continue_write()