• R/O
  • SSH
  • HTTPS

liboftp: Commit


Commit MetaInfo

Revisión50 (tree)
Tiempo2009-12-03 00:13:30
Autorhirohitohigashi

Log Message

add error check

Cambiar Resumen

Diferencia incremental

--- trunk/ftp_timeout.c (revision 49)
+++ trunk/ftp_timeout.c (revision 50)
@@ -42,7 +42,7 @@
4242 struct timeval tval;
4343
4444 ftp->timeout_sec = sec;
45- if( ftp->socket <= 0 ) {
45+ if( ftp->socket < 0 ) {
4646 return LIBOFTP_NOERROR;
4747 }
4848
--- trunk/ftp_cd.c (revision 49)
+++ trunk/ftp_cd.c (revision 50)
@@ -40,6 +40,8 @@
4040 char str1[512];
4141 int res;
4242
43+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
44+
4345 /*
4446 * send CWD command
4547 */
--- trunk/ftp_pwd.c (revision 49)
+++ trunk/ftp_pwd.c (revision 50)
@@ -42,6 +42,8 @@
4242 int res;
4343 char *p1, *p2;
4444
45+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
46+
4547 /*
4648 * send PWD command
4749 */
--- trunk/ftp_open.c (revision 49)
+++ trunk/ftp_open.c (revision 50)
@@ -65,6 +65,7 @@
6565 int ftp_initialize( LIBOFTP *ftp )
6666 {
6767 memset( ftp, 0, sizeof( LIBOFTP ) );
68+ ftp->socket = -1;
6869 ftp->timeout_sec = 10; /* default timeout */
6970
7071 return LIBOFTP_NOERROR;
@@ -87,6 +88,7 @@
8788 struct hostent *p_hostent;
8889 int res;
8990
91+ if( ftp->socket >= 0 ) return LIBOFTP_ERROR;
9092 if( port == 0 ) port = 21;
9193
9294 /*
@@ -109,7 +111,7 @@
109111 if( ftp->socket < 0 ) {
110112 DEBUGPRINT1( "can't create socket. %s\n", strerror(errno) );
111113 copy_strerror();
112- ftp->socket = 0;
114+ ftp->socket = -1;
113115 return LIBOFTP_ERROR_OS;
114116 }
115117
@@ -117,7 +119,7 @@
117119 DEBUGPRINT1( "can't connect socket. %s\n", strerror(errno) );
118120 copy_strerror();
119121 close( ftp->socket );
120- ftp->socket = 0;
122+ ftp->socket = -1;
121123 return LIBOFTP_ERROR_OS;
122124 }
123125
@@ -124,7 +126,7 @@
124126 res = ftp_timeout( ftp, ftp->timeout_sec );
125127 if( res < 0 ) {
126128 close( ftp->socket );
127- ftp->socket = 0;
129+ ftp->socket = -1;
128130 return res;
129131 }
130132
@@ -135,7 +137,7 @@
135137 if( res != 220 ) { /* 220: Service ready for new user. */
136138 DEBUGPRINT1( "Illegal response. %d\n", res );
137139 close( ftp->socket );
138- ftp->socket = 0;
140+ ftp->socket = -1;
139141 return res < 0? res: LIBOFTP_ERROR_PROTOCOL;
140142 }
141143
--- trunk/ftp_put_buffer.c (revision 49)
+++ trunk/ftp_put_buffer.c (revision 50)
@@ -49,6 +49,8 @@
4949 const char *p = buf;
5050 int n, res;
5151
52+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
53+
5254 /*
5355 * 送信準備
5456 */
--- trunk/ftp_delete.c (revision 49)
+++ trunk/ftp_delete.c (revision 50)
@@ -40,6 +40,8 @@
4040 char str1[512];
4141 int res;
4242
43+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
44+
4345 /*
4446 * send DELE command
4547 */
--- trunk/ftp_site.c (revision 49)
+++ trunk/ftp_site.c (revision 50)
@@ -40,6 +40,8 @@
4040 char str1[512];
4141 int res;
4242
43+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
44+
4345 /*
4446 * send SITE command
4547 */
--- trunk/ftp_mkdir.c (revision 49)
+++ trunk/ftp_mkdir.c (revision 50)
@@ -40,6 +40,8 @@
4040 char str1[512];
4141 int res;
4242
43+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
44+
4345 /*
4446 * send MKD command
4547 */
--- trunk/ftp_put_descriptor.c (revision 49)
+++ trunk/ftp_put_descriptor.c (revision 50)
@@ -39,6 +39,8 @@
3939 {
4040 int data_socket;
4141
42+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
43+
4244 if( ftp->flag_passive ) {
4345 data_socket = ftp_getready_pasv( ftp, "STOR", fname );
4446 } else {
@@ -61,6 +63,8 @@
6163 {
6264 int data_socket;
6365
66+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
67+
6468 if( ftp->flag_passive ) {
6569 data_socket = ftp_getready_pasv( ftp, "APPE", fname );
6670 } else {
@@ -88,6 +92,8 @@
8892 */
8993 close( desc );
9094
95+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
96+
9197 /*
9298 * receive response.
9399 */
--- trunk/ftp_rename.c (revision 49)
+++ trunk/ftp_rename.c (revision 50)
@@ -41,6 +41,8 @@
4141 char str1[512];
4242 int res;
4343
44+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
45+
4446 /*
4547 * send RNFR command
4648 */
--- trunk/ftp_put_file.c (revision 49)
+++ trunk/ftp_put_file.c (revision 50)
@@ -51,6 +51,8 @@
5151 char buf[TRANSFER_SEGMENT_SIZE];
5252 int res;
5353
54+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
55+
5456 /*
5557 * ローカルファイルオープン
5658 */
--- trunk/ftp_get_buffer.c (revision 49)
+++ trunk/ftp_get_buffer.c (revision 50)
@@ -49,6 +49,8 @@
4949 char *p = buf;
5050 int res;
5151
52+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
53+
5254 /*
5355 * 受信準備
5456 */
--- trunk/ftp_get_descriptor.c (revision 49)
+++ trunk/ftp_get_descriptor.c (revision 50)
@@ -39,6 +39,8 @@
3939 {
4040 int data_socket;
4141
42+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
43+
4244 if( ftp->flag_passive ) {
4345 data_socket = ftp_getready_pasv( ftp, "RETR", fname );
4446 } else {
@@ -67,6 +69,8 @@
6769 */
6870 close( desc );
6971
72+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
73+
7074 /*
7175 * receive response.
7276 */
--- trunk/ftp_rmdir.c (revision 49)
+++ trunk/ftp_rmdir.c (revision 50)
@@ -40,6 +40,8 @@
4040 char str1[512];
4141 int res;
4242
43+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
44+
4345 /*
4446 * send RMD command
4547 */
--- trunk/ftp_get_file.c (revision 49)
+++ trunk/ftp_get_file.c (revision 50)
@@ -52,6 +52,7 @@
5252 int fd;
5353 char buf[TRANSFER_SEGMENT_SIZE];
5454
55+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
5556
5657 /*
5758 * ローカルファイルオープン
--- trunk/ftp_user.c (revision 49)
+++ trunk/ftp_user.c (revision 50)
@@ -43,6 +43,8 @@
4343 char str1[256];
4444 int res;
4545
46+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
47+
4648 /*
4749 * send user name.
4850 */
@@ -98,5 +100,3 @@
98100
99101 return LIBOFTP_NOERROR;
100102 }
101-
102-
--- trunk/ftp_type.c (revision 49)
+++ trunk/ftp_type.c (revision 50)
@@ -44,6 +44,8 @@
4444 char str1[256];
4545 int res;
4646
47+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
48+
4749 if( strcmp( type, "ascii" ) == 0 ) {
4850 snprintf( str1, sizeof(str1)-1, "TYPE A\r\n" );
4951 ftp->data_type = ASCII;
--- trunk/ftp_quit.c (revision 49)
+++ trunk/ftp_quit.c (revision 50)
@@ -39,6 +39,8 @@
3939 char str1[] = "QUIT\r\n";
4040 int res;
4141
42+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
43+
4244 /*
4345 * send QUIT command
4446 */
@@ -61,7 +63,7 @@
6163 */
6264 CLOSE:
6365 close( ftp->socket );
64- ftp->socket = 0;
66+ ftp->socket = -1;
6567
6668 return res;
6769 }
--- trunk/ftp_reset.c (revision 49)
+++ trunk/ftp_reset.c (revision 50)
@@ -39,6 +39,8 @@
3939 int ret;
4040 int i;
4141
42+ if( ftp->socket < 0 ) return LIBOFTP_ERROR;
43+
4244 /*
4345 * send "CRLF" only
4446 */
Show on old repository browser