]> granicus.if.org Git - curl/commitdiff
Based on a patch by Armel Asselin, the FTP code no longer re-issues the TYPE
authorDaniel Stenberg <daniel@haxx.se>
Sat, 19 Aug 2006 21:18:36 +0000 (21:18 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 19 Aug 2006 21:18:36 +0000 (21:18 +0000)
command on subsequent requests on a re-used connection unless it has to.

23 files changed:
CHANGES
RELEASE-NOTES
lib/content_encoding.c
lib/content_encoding.h
lib/file.c
lib/ftp.c
lib/http.c
lib/http_chunks.c
lib/ldap.c
lib/sendf.c
lib/sendf.h
lib/telnet.c
lib/tftp.c
lib/transfer.c
lib/url.c
lib/urldata.h
tests/data/test146
tests/data/test149
tests/data/test210
tests/data/test211
tests/data/test212
tests/data/test215
tests/data/test216

diff --git a/CHANGES b/CHANGES
index 74c321984f46b8d28dedab59491dad021c2e2b9a..470039344856c2afb8e5a5b98a0a04608d17a082 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,9 @@
                                   Changelog
 
 Daniel (19 August 2006)
+- Based on a patch by Armel Asselin, the FTP code no longer re-issues the TYPE
+  command on subsequent requests on a re-used connection unless it has to.
+
 - Armel Asselin fixed a crash in the FTP code when using SINGLECWD mode and
   files in the root directory.
 
index 49698e5245d6e5a3a8d73ed2014b1aab086c5ea4..756515a8fbc574c2e365996cf8b4361c30657a18 100644 (file)
@@ -11,6 +11,7 @@ Curl and libcurl 7.15.6
 
 This release includes the following changes:
 
+ o (FTP) libcurl avoids sending TYPE if the desired type was already set
  o CURLOPT_PREQUOTE works even when CURLOPT_NOBODY is set true
 
 This release includes the following bugfixes:
index bcd5b838aed7702040a8de30c90bf4faea5b423c..97f834177437f5956b42dcc98d9d175fbc64e255 100644 (file)
@@ -62,9 +62,9 @@ enum zlibState {
 };
 
 static CURLcode
-process_zlib_error(struct SessionHandle *data,
- z_stream *z)
+process_zlib_error(struct connectdata *conn, z_stream *z)
 {
+  struct SessionHandle *data = conn->data;
   if (z->msg)
     failf (data, "Error while processing content unencoding: %s",
            z->msg);
@@ -84,7 +84,7 @@ exit_zlib(z_stream *z, bool *zlib_init, CURLcode result)
 }
 
 static CURLcode
-inflate_stream(struct SessionHandle *data,
+inflate_stream(struct connectdata *conn,
                struct Curl_transfer_keeper *k)
 {
   int allow_restart = 1;
@@ -113,7 +113,7 @@ inflate_stream(struct SessionHandle *data,
     if (status == Z_OK || status == Z_STREAM_END) {
       allow_restart = 0;
       if(DSIZ - z->avail_out) {
-        result = Curl_client_write(data, CLIENTWRITE_BODY, decomp,
+        result = Curl_client_write(conn, CLIENTWRITE_BODY, decomp,
                                    DSIZ - z->avail_out);
         /* if !CURLE_OK, clean up, return */
         if (result) {
@@ -128,7 +128,7 @@ inflate_stream(struct SessionHandle *data,
         if (inflateEnd(z) == Z_OK)
           return exit_zlib(z, &k->zlib_init, result);
         else
-          return exit_zlib(z, &k->zlib_init, process_zlib_error(data, z));
+          return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
       }
 
       /* Done with these bytes, exit */
@@ -143,7 +143,7 @@ inflate_stream(struct SessionHandle *data,
 
       inflateReset(z);
       if (inflateInit2(z, -MAX_WBITS) != Z_OK) {
-        return process_zlib_error(data, z);
+        return process_zlib_error(conn, z);
       }
       z->next_in = orig_in;
       z->avail_in = nread;
@@ -152,14 +152,14 @@ inflate_stream(struct SessionHandle *data,
     }
     else {                      /* Error; exit loop, handle below */
       free(decomp);
-      return exit_zlib(z, &k->zlib_init, process_zlib_error(data, z));
+      return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
     }
   }
   /* Will never get here */
 }
 
 CURLcode
-Curl_unencode_deflate_write(struct SessionHandle *data,
+Curl_unencode_deflate_write(struct connectdata *conn,
                             struct Curl_transfer_keeper *k,
                             ssize_t nread)
 {
@@ -173,7 +173,7 @@ Curl_unencode_deflate_write(struct SessionHandle *data,
     z->next_in = NULL;
     z->avail_in = 0;
     if (inflateInit(z) != Z_OK)
-      return process_zlib_error(data, z);
+      return process_zlib_error(conn, z);
     k->zlib_init = ZLIB_INIT;
   }
 
@@ -182,7 +182,7 @@ Curl_unencode_deflate_write(struct SessionHandle *data,
   z->avail_in = (uInt)nread;
 
   /* Now uncompress the data */
-  return inflate_stream(data, k);
+  return inflate_stream(conn, k);
 }
 
 #ifdef OLD_ZLIB_SUPPORT
@@ -272,7 +272,7 @@ static enum {
 #endif
 
 CURLcode
-Curl_unencode_gzip_write(struct SessionHandle *data,
+Curl_unencode_gzip_write(struct connectdata *conn,
                          struct Curl_transfer_keeper *k,
                          ssize_t nread)
 {
@@ -289,14 +289,14 @@ Curl_unencode_gzip_write(struct SessionHandle *data,
     if (strcmp(zlibVersion(), "1.2.0.4") >= 0) {
         /* zlib ver. >= 1.2.0.4 supports transparent gzip decompressing */
         if (inflateInit2(z, MAX_WBITS+32) != Z_OK) {
-          return process_zlib_error(data, z);
+          return process_zlib_error(conn, z);
         }
         k->zlib_init = ZLIB_INIT_GZIP; /* Transparent gzip decompress state */
 
     } else {
         /* we must parse the gzip header ourselves */
         if (inflateInit2(z, -MAX_WBITS) != Z_OK) {
-          return process_zlib_error(data, z);
+          return process_zlib_error(conn, z);
         }
         k->zlib_init = ZLIB_INIT;   /* Initial call state */
     }
@@ -307,7 +307,7 @@ Curl_unencode_gzip_write(struct SessionHandle *data,
      z->next_in = (Bytef *)k->str;
      z->avail_in = (uInt)nread;
      /* Now uncompress the data */
-     return inflate_stream(data, k);
+     return inflate_stream(conn, k);
   }
 
 #ifndef OLD_ZLIB_SUPPORT
@@ -360,7 +360,7 @@ Curl_unencode_gzip_write(struct SessionHandle *data,
 
     case GZIP_BAD:
     default:
-      return exit_zlib(z, &k->zlib_init, process_zlib_error(data, z));
+      return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
     }
 
   }
@@ -398,7 +398,7 @@ Curl_unencode_gzip_write(struct SessionHandle *data,
     case GZIP_BAD:
     default:
       free(z->next_in);
-      return exit_zlib(z, &k->zlib_init, process_zlib_error(data, z));
+      return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
     }
 
   }
@@ -418,7 +418,7 @@ Curl_unencode_gzip_write(struct SessionHandle *data,
   }
 
   /* We've parsed the header, now uncompress the data */
-  return inflate_stream(data, k);
+  return inflate_stream(conn, k);
 #endif
 }
 #endif /* HAVE_LIBZ */
index 6f01c69e8cf7b04799f2250b44091047598ae2fc..b31669be4b0d9384f1aeb243dd3d30808287de34 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
 #define ALL_CONTENT_ENCODINGS "identity"
 #endif
 
-CURLcode Curl_unencode_deflate_write(struct SessionHandle *data,
+CURLcode Curl_unencode_deflate_write(struct connectdata *conn,
                                      struct Curl_transfer_keeper *k,
                                      ssize_t nread);
 
 CURLcode
-Curl_unencode_gzip_write(struct SessionHandle *data,
+Curl_unencode_gzip_write(struct connectdata *conn,
                          struct Curl_transfer_keeper *k,
                          ssize_t nread);
index 7415d8a7876a7aeadb0fb34394a013b095241744..7ac53f19b4e5d96183b95ca64f75c8a29ea5b98f 100644 (file)
@@ -311,11 +311,11 @@ CURLcode Curl_file(struct connectdata *conn, bool *done)
     CURLcode result;
     snprintf(buf, sizeof(data->state.buffer),
              "Content-Length: %" FORMAT_OFF_T "\r\n", expected_size);
-    result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
+    result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);
     if(result)
       return result;
 
-    result = Curl_client_write(data, CLIENTWRITE_BOTH,
+    result = Curl_client_write(conn, CLIENTWRITE_BOTH,
                                (char *)"Accept-ranges: bytes\r\n", 0);
     if(result)
       return result;
@@ -339,7 +339,7 @@ CURLcode Curl_file(struct connectdata *conn, bool *done)
                tm->tm_hour,
                tm->tm_min,
                tm->tm_sec);
-      result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
+      result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);
     }
     return result;
   }
@@ -377,7 +377,7 @@ CURLcode Curl_file(struct connectdata *conn, bool *done)
 
     bytecount += nread;
 
-    res = Curl_client_write(data, CLIENTWRITE_BODY, buf, nread);
+    res = Curl_client_write(conn, CLIENTWRITE_BODY, buf, nread);
     if(res)
       return res;
 
index e7d8b2269a964fc8206a9616b846bb024868a87e..62c941e5d535313d7cb46606e8778891982421f9 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -132,6 +132,10 @@ static CURLcode ftp_state_post_rest(struct connectdata *conn);
 static CURLcode ftp_state_post_cwd(struct connectdata *conn);
 static CURLcode ftp_state_quote(struct connectdata *conn,
                                 bool init, ftpstate instate);
+static CURLcode ftp_nb_type(struct connectdata *conn,
+                                       bool ascii, ftpstate state);
+static int ftp_need_type(struct connectdata *conn,
+                                        bool ascii);
 
 /* easy-to-use macro: */
 #define FTPSENDF(x,y,z) if((result = Curl_ftpsendf(x,y,z))) return result
@@ -339,7 +343,7 @@ static CURLcode ftp_readresp(curl_socket_t sockfd,
            * for "headers". The response lines can be seen as a kind of
            * headers.
            */
-          result = Curl_client_write(data, CLIENTWRITE_HEADER,
+          result = Curl_client_write(conn, CLIENTWRITE_HEADER,
                                      ftp->linestart_resp, perline);
           if(result)
             return result;
@@ -570,7 +574,7 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
              * for "headers". The response lines can be seen as a kind of
              * headers.
              */
-            result = Curl_client_write(data, CLIENTWRITE_HEADER,
+            result = Curl_client_write(conn, CLIENTWRITE_HEADER,
                                        line_start, perline);
             if(result)
               return result;
@@ -1313,7 +1317,8 @@ static CURLcode ftp_state_post_mdtm(struct connectdata *conn)
   /* If we have selected NOBODY and HEADER, it means that we only want file
      information. Which in FTP can't be much more than the file size and
      date. */
-  if(conn->bits.no_body && data->set.include_header && ftp->file) {
+  if(conn->bits.no_body && data->set.include_header && ftp->file &&
+     ftp_need_type(conn, data->set.prefer_ascii)) {
     /* The SIZE command is _not_ RFC 959 specified, and therefor many servers
        may not support it! It is however the only way we have to get a file's
        size! */
@@ -1322,11 +1327,9 @@ static CURLcode ftp_state_post_mdtm(struct connectdata *conn)
 
     /* Some servers return different sizes for different modes, and thus we
        must set the proper type before we check the size */
-    NBFTPSENDF(conn, "TYPE %c",
-               data->set.ftp_ascii?'A':'I');
-    state(conn, FTP_TYPE);
-    /* keep track of our current transfer type */
-    data->ftp_in_ascii_mode = data->set.ftp_ascii;
+    result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_TYPE);
+    if (result)
+      return result;
   }
   else
     result = ftp_state_post_type(conn);
@@ -1828,7 +1831,7 @@ static CURLcode ftp_state_mdtm_resp(struct connectdata *conn,
                  tm->tm_hour,
                  tm->tm_min,
                  tm->tm_sec);
-        result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
+        result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);
         if(result)
           return result;
       } /* end of a ridiculous amount of conditionals */
@@ -2003,7 +2006,7 @@ static CURLcode ftp_state_size_resp(struct connectdata *conn,
     if(-1 != filesize) {
       snprintf(buf, sizeof(data->state.buffer),
                "Content-Length: %" FORMAT_OFF_T "\r\n", filesize);
-      result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0);
+      result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);
       if(result)
         return result;
     }
@@ -2030,7 +2033,7 @@ static CURLcode ftp_state_rest_resp(struct connectdata *conn,
   case FTP_REST:
   default:
     if (ftpcode == 350) {
-      result = Curl_client_write(conn->data, CLIENTWRITE_BOTH,
+      result = Curl_client_write(conn, CLIENTWRITE_BOTH,
                                (char *)"Accept-ranges: bytes\r\n", 0);
       if(result)
         return result;
@@ -2141,7 +2144,7 @@ static CURLcode ftp_state_get_resp(struct connectdata *conn,
      */
 
     if((instate != FTP_LIST) &&
-       !data->set.ftp_ascii &&
+       !data->set.prefer_ascii &&
        (ftp->downloadsize < 1)) {
       /*
        * It seems directory listings either don't show the size or very
@@ -3095,7 +3098,7 @@ static CURLcode ftp_transfertype(struct connectdata *conn,
   ssize_t nread;
   CURLcode result;
 
-  FTPSENDF(conn, "TYPE %s", ascii?"A":"I");
+  FTPSENDF(conn, "TYPE %c", ascii?'A':'I');
 
   result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
   if(result)
@@ -3107,8 +3110,49 @@ static CURLcode ftp_transfertype(struct connectdata *conn,
     return ascii? CURLE_FTP_COULDNT_SET_ASCII:CURLE_FTP_COULDNT_SET_BINARY;
   }
   /* keep track of our current transfer type */
-  data->ftp_in_ascii_mode = ascii;
+  conn->proto.ftp->transfertype = ascii?'A':'I';
+
+  return CURLE_OK;
+}
+
+
+/***********************************************************************
+ *
+ * ftp_need_type()
+ *
+ * Returns TRUE if we in the current situation should send TYPE
+ */
+static int ftp_need_type(struct connectdata *conn,
+                         bool ascii_wanted)
+{
+  return conn->proto.ftp->transfertype != (ascii_wanted?'A':'I');
+}
+
+/***********************************************************************
+ *
+ * ftp_nb_type()
+ *
+ * Set TYPE. We only deal with ASCII or BINARY so this function
+ * sets one of them.
+ * If the transfer type is not sent, simulate on OK response in newstate
+ */
+static CURLcode ftp_nb_type(struct connectdata *conn,
+                            bool ascii, ftpstate newstate)
+{
+  struct FTP *ftp = conn->proto.ftp;
+  CURLcode result;
+  int want = ascii?'A':'I';
 
+  if (ftp->transfertype == want) {
+    state(conn, newstate);
+    return ftp_state_type_resp(conn, 200, newstate);
+  }
+
+  NBFTPSENDF(conn, "TYPE %c", want);
+  state(conn, newstate);
+
+  /* keep track of our current transfer type */
+  ftp->transfertype = want;
   return CURLE_OK;
 }
 
@@ -3207,10 +3251,10 @@ CURLcode Curl_ftp_nextconnect(struct connectdata *conn)
     /* a transfer is about to take place */
 
     if(data->set.upload) {
-      NBFTPSENDF(conn, "TYPE %c", data->set.ftp_ascii?'A':'I');
-      state(conn, FTP_STOR_TYPE);
-      /* keep track of our current transfer type */
-      data->ftp_in_ascii_mode = data->set.ftp_ascii;
+      result = ftp_nb_type(conn, data->set.prefer_ascii,
+                                      FTP_STOR_TYPE);
+      if (result)
+        return result;
     }
     else {
       /* download */
@@ -3223,16 +3267,14 @@ CURLcode Curl_ftp_nextconnect(struct connectdata *conn)
         /* The specified path ends with a slash, and therefore we think this
            is a directory that is requested, use LIST. But before that we
            need to set ASCII transfer mode. */
-        NBFTPSENDF(conn, "TYPE A", NULL);
-        state(conn, FTP_LIST_TYPE);
-        /* keep track of our current transfer type */
-        data->ftp_in_ascii_mode = 1;
+        result = ftp_nb_type(conn, 1, FTP_LIST_TYPE);
+        if (result)
+          return result;
       }
       else {
-        NBFTPSENDF(conn, "TYPE %c", data->set.ftp_ascii?'A':'I');
-        state(conn, FTP_RETR_TYPE);
-        /* keep track of our current transfer type */
-        data->ftp_in_ascii_mode = data->set.ftp_ascii;
+        result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_RETR_TYPE);
+        if (result)
+          return result;
       }
     }
     result = ftp_easy_statemach(conn);
@@ -3621,11 +3663,11 @@ static CURLcode ftp_3rdparty_pretransfer(struct connectdata *conn)
   sec_conn->xfertype = SOURCE3RD;
 
   /* sets transfer type */
-  result = ftp_transfertype(conn, data->set.ftp_ascii);
+  result = ftp_transfertype(conn, data->set.prefer_ascii);
   if (result)
     return result;
 
-  result = ftp_transfertype(sec_conn, data->set.ftp_ascii);
+  result = ftp_transfertype(sec_conn, data->set.prefer_ascii);
   if (result)
     return result;
 
index 4df91be0a3af8dfc958e3bc201392208b07fd95e..aab0b85a2a07ec9e2f5948001c787a42a33be424 100644 (file)
@@ -1251,7 +1251,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
               if(data->set.include_header)
                 writetype |= CLIENTWRITE_BODY;
 
-              result = Curl_client_write(data, writetype, line_start, perline);
+              result = Curl_client_write(conn, writetype, line_start, perline);
               if(result)
                 return result;
 
index 63e136cb7c1d7b8582da9c55d138841c0d3fdabf..30112f2b8064c10611022afe80925908af687b82 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -190,7 +190,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
         case IDENTITY:
 #endif
           if(!k->ignorebody)
-            result = Curl_client_write(conn->data, CLIENTWRITE_BODY, datap,
+            result = Curl_client_write(conn, CLIENTWRITE_BODY, datap,
                                        piece);
 #ifdef HAVE_LIBZ
           break;
@@ -198,14 +198,14 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
         case DEFLATE:
           /* update conn->keep.str to point to the chunk data. */
           conn->keep.str = datap;
-          result = Curl_unencode_deflate_write(conn->data, &conn->keep,
+          result = Curl_unencode_deflate_write(conn, &conn->keep,
                                                (ssize_t)piece);
           break;
 
         case GZIP:
           /* update conn->keep.str to point to the chunk data. */
           conn->keep.str = datap;
-          result = Curl_unencode_gzip_write(conn->data, &conn->keep,
+          result = Curl_unencode_gzip_write(conn, &conn->keep,
                                             (ssize_t)piece);
           break;
 
@@ -303,7 +303,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
           return CHUNKE_STOP;
         }
         else {
-          Curl_client_write(conn->data, CLIENTWRITE_HEADER,
+          Curl_client_write(conn, CLIENTWRITE_HEADER,
                             conn->trailer, conn->trlPos);
         }
         ch->state = CHUNK_TRAILER;
index 7b92587d7eaf4e80ed045f36bc7c8095872e172d..32ef50675d29923e11db667931b99b7ff6d148da 100644 (file)
@@ -372,9 +372,9 @@ CURLcode Curl_ldap(struct connectdata *conn, bool *done)
     char  *dn = (*ldap_get_dn)(server, entryIterator);
     int i;
 
-    Curl_client_write(data, CLIENTWRITE_BODY, (char *)"DN: ", 4);
-    Curl_client_write(data, CLIENTWRITE_BODY, (char *)dn, 0);
-    Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
+    Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"DN: ", 4);
+    Curl_client_write(conn, CLIENTWRITE_BODY, (char *)dn, 0);
+    Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1);
 
     for (attribute = (*ldap_first_attribute)(server, entryIterator, &ber);
          attribute;
@@ -387,9 +387,9 @@ CURLcode Curl_ldap(struct connectdata *conn, bool *done)
       {
         for (i = 0; (vals[i] != NULL); i++)
         {
-          Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\t", 1);
-          Curl_client_write(data, CLIENTWRITE_BODY, (char *) attribute, 0);
-          Curl_client_write(data, CLIENTWRITE_BODY, (char *)": ", 2);
+          Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\t", 1);
+          Curl_client_write(conn, CLIENTWRITE_BODY, (char *) attribute, 0);
+          Curl_client_write(conn, CLIENTWRITE_BODY, (char *)": ", 2);
           if ((strlen(attribute) > 7) &&
               (strcmp(";binary",
                       (char *)attribute +
@@ -398,19 +398,19 @@ CURLcode Curl_ldap(struct connectdata *conn, bool *done)
             val_b64_sz = Curl_base64_encode(vals[i]->bv_val, vals[i]->bv_len,
                                             &val_b64);
             if (val_b64_sz > 0) {
-              Curl_client_write(data, CLIENTWRITE_BODY, val_b64, val_b64_sz);
+              Curl_client_write(conn, CLIENTWRITE_BODY, val_b64, val_b64_sz);
               free(val_b64);
             }
           } else
-            Curl_client_write(data, CLIENTWRITE_BODY, vals[i]->bv_val,
+            Curl_client_write(conn, CLIENTWRITE_BODY, vals[i]->bv_val,
                               vals[i]->bv_len);
-          Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 0);
+          Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 0);
         }
 
         /* Free memory used to store values */
         (*ldap_value_free_len)((void **)vals);
       }
-      Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
+      Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1);
 
       (*ldap_memfree)(attribute);
     }
index d598197bdc6711b8e47eb7a68f433b1a96a32fa6..b38415c3eff60839d45d9ae05b7e07ca57d5ef8d 100644 (file)
@@ -367,18 +367,19 @@ CURLcode Curl_write(struct connectdata *conn,
    The bit pattern defines to what "streams" to write to. Body and/or header.
    The defines are in sendf.h of course.
  */
-CURLcode Curl_client_write(struct SessionHandle *data,
+CURLcode Curl_client_write(struct connectdata *conn,
                            int type,
                            char *ptr,
                            size_t len)
 {
+  struct SessionHandle *data = conn->data;
   size_t wrote;
 
   if(0 == len)
     len = strlen(ptr);
 
   if(type & CLIENTWRITE_BODY) {
-    if(data->ftp_in_ascii_mode) {
+    if((conn->protocol&PROT_FTP) && conn->proto.ftp->transfertype == 'A') {
 #ifdef CURL_DOES_CONVERSIONS
       /* convert from the network encoding */
       size_t rc;
index ae96af3e07d1b0b39d09a731df4ba185d1411117..b556bd573eb84a97771e23423217b5d8f7955304 100644 (file)
@@ -47,7 +47,7 @@ void Curl_failf(struct SessionHandle *, const char *fmt, ...);
 #define CLIENTWRITE_HEADER 2
 #define CLIENTWRITE_BOTH   (CLIENTWRITE_BODY|CLIENTWRITE_HEADER)
 
-CURLcode Curl_client_write(struct SessionHandle *data, int type, char *ptr,
+CURLcode Curl_client_write(struct connectdata *conn, int type, char *ptr,
                            size_t len);
 
 /* internal read-function, does plain socket, SSL and krb4 */
index 5f94807df76bc01598eaa9e13321ab276e15d86b..8939dd1a698771ba6015f4ee606f8397326b8b62 100644 (file)
@@ -940,7 +940,7 @@ void telrcv(struct connectdata *conn,
           break;   /* Ignore \0 after CR */
         }
 
-        Curl_client_write(data, CLIENTWRITE_BODY, (char *)&c, 1);
+        Curl_client_write(conn, CLIENTWRITE_BODY, (char *)&c, 1);
         continue;
 
       case CURL_TS_DATA:
@@ -954,7 +954,7 @@ void telrcv(struct connectdata *conn,
           tn->telrcv_state = CURL_TS_CR;
         }
 
-        Curl_client_write(data, CLIENTWRITE_BODY, (char *)&c, 1);
+        Curl_client_write(conn, CLIENTWRITE_BODY, (char *)&c, 1);
         continue;
 
       case CURL_TS_IAC:
@@ -978,7 +978,7 @@ void telrcv(struct connectdata *conn,
           tn->telrcv_state = CURL_TS_SB;
           continue;
         case CURL_IAC:
-          Curl_client_write(data, CLIENTWRITE_BODY, (char *)&c, 1);
+          Curl_client_write(conn, CLIENTWRITE_BODY, (char *)&c, 1);
           break;
         case CURL_DM:
         case CURL_NOP:
index 1bf7281bbc248804c9fd60feb93e695191951ba0..61800cc3dfdc702343013d5887efb1c10e1b45e4 100644 (file)
@@ -261,7 +261,7 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
   CURLcode res = CURLE_OK;
 
   /* Set ascii mode if -B flag was used */
-  if(data->set.ftp_ascii)
+  if(data->set.prefer_ascii)
     mode = "netascii";
 
   switch(event) {
@@ -699,7 +699,7 @@ CURLcode Curl_tftp(struct connectdata *conn, bool *done)
           /* Don't pass to the client empty or retransmitted packets */
           if (state->rbytes > 4 &&
               ((state->block+1) == getrpacketblock(&state->rpacket))) {
-            code = Curl_client_write(data, CLIENTWRITE_BODY,
+            code = Curl_client_write(conn, CLIENTWRITE_BODY,
                                      (char *)&state->rpacket.data[4],
                                      state->rbytes-4);
             if(code)
index 814940f8ff31e3ebd897d978b605f3e3bf0b28c4..9cf9c292540bab62721671e7ebfc69fc8aa8a961 100644 (file)
@@ -531,7 +531,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
 
               headerlen = k->p - data->state.headerbuff;
 
-              result = Curl_client_write(data, writetype,
+              result = Curl_client_write(conn, writetype,
                                          data->state.headerbuff,
                                          headerlen);
               if(result)
@@ -990,7 +990,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
               Curl_debug(data, CURLINFO_HEADER_IN,
                          k->p, k->hbuflen, conn);
 
-            result = Curl_client_write(data, writetype, k->p, k->hbuflen);
+            result = Curl_client_write(conn, writetype, k->p, k->hbuflen);
             if(result)
               return result;
 
@@ -1144,7 +1144,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
             if(k->badheader && !k->ignorebody) {
               /* we parsed a piece of data wrongly assuming it was a header
                  and now we output it as body instead */
-              result = Curl_client_write(data, CLIENTWRITE_BODY,
+              result = Curl_client_write(conn, CLIENTWRITE_BODY,
                                          data->state.headerbuff,
                                          k->hbuflen);
               if(result)
@@ -1164,7 +1164,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
                    Content-Encoding header. See Curl_readwrite_init; the
                    memset() call initializes k->content_encoding to zero. */
                 if(!k->ignorebody)
-                  result = Curl_client_write(data, CLIENTWRITE_BODY, k->str,
+                  result = Curl_client_write(conn, CLIENTWRITE_BODY, k->str,
                                              nread);
 #ifdef HAVE_LIBZ
                 break;
@@ -1172,13 +1172,13 @@ CURLcode Curl_readwrite(struct connectdata *conn,
               case DEFLATE:
                 /* Assume CLIENTWRITE_BODY; headers are not encoded. */
                 if(!k->ignorebody)
-                  result = Curl_unencode_deflate_write(data, k, nread);
+                  result = Curl_unencode_deflate_write(conn, k, nread);
                 break;
 
               case GZIP:
                 /* Assume CLIENTWRITE_BODY; headers are not encoded. */
                 if(!k->ignorebody)
-                  result = Curl_unencode_gzip_write(data, k, nread);
+                  result = Curl_unencode_gzip_write(conn, k, nread);
                 break;
 
               case COMPRESS:
@@ -1283,7 +1283,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
           /* convert LF to CRLF if so asked */
 #ifdef CURL_DO_LINEEND_CONV
           /* always convert if we're FTPing in ASCII mode */
-          if ((data->set.crlf) || (data->ftp_in_ascii_mode)) {
+          if ((data->set.crlf) || (data->set.prefer_ascii)) {
 #else
           if (data->set.crlf) {
 #endif /* CURL_DO_LINEEND_CONV */
index 6b376faf7632a878213ad006ee10bbd1e124db75..c0641c78b801dc84194c45517a692ac72c5e66d9 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -612,7 +612,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
      *
      * Transfer using ASCII (instead of BINARY).
      */
-    data->set.ftp_ascii = va_arg(param, long)?TRUE:FALSE;
+    data->set.prefer_ascii = va_arg(param, long)?TRUE:FALSE;
     break;
   case CURLOPT_TIMECONDITION:
     /*
@@ -3125,15 +3125,15 @@ static CURLcode CreateConnection(struct SessionHandle *data,
       command = (char)toupper((int)type[6]);
       switch(command) {
       case 'A': /* ASCII mode */
-        data->set.ftp_ascii = 1;
+        data->set.prefer_ascii = TRUE;
         break;
       case 'D': /* directory mode */
-        data->set.ftp_list_only = 1;
+        data->set.ftp_list_only = TRUE;
         break;
       case 'I': /* binary mode */
       default:
         /* switch off ASCII */
-        data->set.ftp_ascii = 0;
+        data->set.prefer_ascii = FALSE;
         break;
       }
     }
@@ -3228,13 +3228,13 @@ static CURLcode CreateConnection(struct SessionHandle *data,
       switch(command) {
       case 'A': /* ASCII mode */
       case 'N': /* NETASCII mode */
-        data->set.ftp_ascii = 1;
+        data->set.prefer_ascii = TRUE;
         break;
       case 'O': /* octet mode */
       case 'I': /* binary mode */
       default:
         /* switch off ASCII */
-        data->set.ftp_ascii = 0;
+        data->set.prefer_ascii = FALSE;
         break;
       }
     }
index f1d14a6c088ae47314e98c0c75b849891366cdb5..33f7ee860201d3fd1190cdd655ae21d5fb7f104f 100644 (file)
@@ -362,6 +362,8 @@ struct FTP {
   bool cwdfail;     /* set TRUE if a CWD command fails, as then we must prevent
                        caching the current directory */
   char *prevpath;   /* conn->path from the previous transfer */
+  char transfertype; /* set by ftp_transfertype for use by Curl_client_write()a
+                        and others (A/I or zero) */
 
   size_t nread_resp; /* number of bytes currently read of a server response */
   char *linestart_resp; /* line start pointer for the FTP server response
@@ -1114,8 +1116,8 @@ struct UserDefined {
   bool printhost;       /* printing host name in debug info */
   bool get_filetime;
   bool tunnel_thru_httpproxy;
+  bool prefer_ascii;    /* ASCII rather than binary */
   bool ftp_append;
-  bool ftp_ascii;
   bool ftp_list_only;
   bool ftp_create_missing_dirs;
   bool ftp_use_port;
@@ -1184,8 +1186,6 @@ struct SessionHandle {
   struct UrlState state;       /* struct for fields used for state info and
                                   other dynamic purposes */
   struct PureInfo info;        /* stats, reports and info data */
-  /* set by ftp_transfertype for use by Curl_client_write and others */
-  bool ftp_in_ascii_mode;
 #if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
   iconv_t outbound_cd;         /* for translating to the network encoding */
   iconv_t inbound_cd;          /* for translating from the network encoding */
index 1de7f38d422da83c383fadb06f514ea85479ad02..2d1940bc8fe34ac93d71ea2ebbb642820f5f8903 100644 (file)
@@ -39,7 +39,6 @@ SIZE 146
 RETR 146\r
 CWD /nowhere/anywhere\r
 EPSV\r
-TYPE I\r
 SIZE 146\r
 RETR 146\r
 QUIT\r
index b42477b79edf29c10b0e862a4155c41543254ce8..9195e19a973149f7d33649341136429584d63d83 100644 (file)
@@ -37,7 +37,6 @@ STOR 148
 CWD /nowhere/anywhere\r
 CWD dir2\r
 EPSV\r
-TYPE I\r
 STOR 148\r
 QUIT\r
 </protocol>
index f42aaecf7bb13fcd31f28f4f7c9c0ad4ff429fd4..711a26ad1edb6cecd952493d84ce44869e73824a 100644 (file)
@@ -37,7 +37,6 @@ TYPE I
 SIZE 210\r
 RETR 210\r
 EPSV\r
-TYPE I\r
 SIZE 210\r
 RETR 210\r
 QUIT\r
index 76185286268bbd83bc5d164094f63bfb9b3a870c..18f4cb11e98c094350db08412b18d77ce223a86b 100644 (file)
@@ -39,7 +39,6 @@ TYPE I
 SIZE 211\r
 RETR 211\r
 PASV\r
-TYPE I\r
 SIZE 211\r
 RETR 211\r
 QUIT\r
index 3fac26bde10bbd5346ceaea962276dc90a37a78e..c5790df304db34c62610ac4bed0a37736905f491 100644 (file)
@@ -47,7 +47,6 @@ TYPE I
 SIZE 212\r
 RETR 212\r
 PORT 127,0,0,1,
-TYPE I\r
 SIZE 212\r
 RETR 212\r
 QUIT\r
index ac60618d98dc40dbefab0ca9b9a6adeceae03da5..6077feb8baf45f915633572fa43fb30feea158d2 100644 (file)
@@ -44,7 +44,6 @@ EPSV
 TYPE A\r
 LIST\r
 EPSV\r
-TYPE A\r
 LIST\r
 QUIT\r
 </protocol>
index 236364260039ed7831970881ce6e79da6b8d48c0..ba3d527206827c713a318cb059aaf13e33405699 100644 (file)
@@ -31,7 +31,6 @@ EPSV
 TYPE I\r
 STOR upload.216\r
 EPSV\r
-TYPE I\r
 STOR ..anotherup\r
 QUIT\r
 </protocol>