[MPlayer-cvslog] CVS: main/libmpdemux stream_ftp.c,1.6,1.7

Guillaume Poirier CVS syncmail at mplayerhq.hu
Fri Oct 14 14:35:33 CEST 2005


CVS change done by Guillaume Poirier CVS

Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var2/tmp/cvs-serv26495/libmpdemux

Modified Files:
	stream_ftp.c 
Log Message:
Make FtpSendCmd() function more user friendly by making it append the necessary "\r\n" line break (instead of the caller)
Patch by Zuxy Meng < zuxy POIS meng AH gmail POIS com >
Original thread:
Date: Oct 14, 2005 1:01 PM
Subject: [MPlayer-dev-eng] [PATCH] More user friendly ftp error

Index: stream_ftp.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream_ftp.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- stream_ftp.c	13 Oct 2005 18:33:56 -0000	1.6
+++ stream_ftp.c	14 Oct 2005 12:35:30 -0000	1.7
@@ -172,6 +172,7 @@
 static int FtpSendCmd(const char *cmd, struct stream_priv_s *nControl,char* rsp)
 {
   int l = strlen(cmd);
+  int hascrlf = cmd[l - 2] == '\r' && cmd[l - 1] == '\n';
 
   mp_msg(MSGT_STREAM,MSGL_V, "[ftp] > %s",cmd);
   while(l > 0) {
@@ -186,7 +187,10 @@
     l -= s;
   }
     
-  return readresp(nControl,rsp);
+  if (hascrlf)  
+    return readresp(nControl,rsp);
+  else
+    return FtpSendCmd("\r\n", nControl, rsp);
 }
 
 static int FtpOpenPort(struct stream_priv_s* p) {
@@ -195,7 +199,7 @@
   char* par,str[128];
   int num[6];
 
-  resp = FtpSendCmd("PASV\r\n",p,rsp_txt);
+  resp = FtpSendCmd("PASV",p,rsp_txt);
   if(resp != 2) {
     mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command 'PASV' failed: %s\n",rsp_txt);
     return 0;
@@ -298,7 +302,7 @@
     }
     // Send the ABOR command
     // Ignore the return code as sometimes it fail with "nothing to abort"
-    FtpSendCmd("ABOR\r\n",p,rsp_txt);
+    FtpSendCmd("ABOR",p,rsp_txt);
   }
 
   // Open a new connection
@@ -307,7 +311,7 @@
   if(!s->fd) return 0;
 
   if(newpos > 0) {
-    snprintf(str,255,"REST %"PRId64"\r\n", (int64_t)newpos);
+    snprintf(str,255,"REST %"PRId64, (int64_t)newpos);
 
     resp = FtpSendCmd(str,p,rsp_txt);
     if(resp != 3) {
@@ -317,7 +321,7 @@
   }
 
   // Get the file
-  snprintf(str,255,"RETR %s\r\n",p->filename);
+  snprintf(str,255,"RETR %s",p->filename);
   resp = FtpSendCmd(str,p,rsp_txt);
 
   if(resp != 1) {
@@ -340,7 +344,7 @@
     s->fd = 0;
   }
 
-  FtpSendCmd("QUIT\r\n",p,NULL);
+  FtpSendCmd("QUIT",p,NULL);
 
   if(p->handle) closesocket(p->handle);
   if(p->buf) free(p->buf);
@@ -387,12 +391,12 @@
   }
 
   // Login
-  snprintf(str,255,"USER %s\r\n",p->user);
+  snprintf(str,255,"USER %s",p->user);
   resp = FtpSendCmd(str,p,rsp_txt);
 
   // password needed
   if(resp == 3) {
-    snprintf(str,255,"PASS %s\r\n",p->pass);
+    snprintf(str,255,"PASS %s",p->pass);
     resp = FtpSendCmd(str,p,rsp_txt);
     if(resp != 2) {
       mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] command '%s' failed: %s\n",str,rsp_txt);
@@ -406,7 +410,7 @@
   }
     
   // Set the transfert type
-  resp = FtpSendCmd("TYPE I\r\n",p,rsp_txt);
+  resp = FtpSendCmd("TYPE I",p,rsp_txt);
   if(resp != 2) {
     mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command 'TYPE I' failed: %s\n",rsp_txt);
     close_f(stream);
@@ -414,7 +418,7 @@
   }
 
   // Get the filesize
-  snprintf(str,255,"SIZE %s\r\n",p->filename);
+  snprintf(str,255,"SIZE %s",p->filename);
   resp = FtpSendCmd(str,p,rsp_txt);
   if(resp != 2) {
     mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command '%s' failed: %s\n",str,rsp_txt);
@@ -431,7 +435,7 @@
   }
 
   // Get the file
-  snprintf(str,255,"RETR %s\r\n",p->filename);
+  snprintf(str,255,"RETR %s",p->filename);
   resp = FtpSendCmd(str,p,rsp_txt);
 
   if(resp != 1) {




More information about the MPlayer-cvslog mailing list