Since rev 1.176 TLS connections are also handled with stdio.  When
removing the ftp_printf wrapper I also removed the optional printing of
headers sent to the server.  The diff below reinstates ftp_printf
for !SMALL builds.  For ramdisks, ftp_printf is just a #define so size
doesn't change.

ok?


Index: fetch.c
===================================================================
--- fetch.c.orig
+++ fetch.c
@@ -78,6 +78,11 @@ static char  *recode_credentials(const ch
 static char    *ftp_readline(FILE *, size_t *);
 static void    ftp_close(FILE **, struct tls **, volatile int *);
 static const char *sockerror(struct tls *);
+#ifdef SMALL
+#define        ftp_printf(fp, ...) fprintf(fp, __VA_ARGS__)
+#else
+static int     ftp_printf(FILE *, const char *, ...);
+#endif /* SMALL */
 #ifndef NOSSL
 static int     proxy_connect(int, char *, char *);
 static int     stdio_tls_write_wrapper(void *, const char *, int);
@@ -695,14 +700,14 @@ noslash:
                 * the original URI (path).
                 */
                if (credentials)
-                       fprintf(fin, "GET %s HTTP/1.1\r\n"
+                       ftp_printf(fin, "GET %s HTTP/1.1\r\n"
                            "Connection: close\r\n"
                            "Proxy-Authorization: Basic %s\r\n"
                            "Host: %s\r\n%s%s\r\n\r\n",
                            epath, credentials,
                            proxyhost, buf ? buf : "", httpuseragent);
                else
-                       fprintf(fin, "GET %s HTTP/1.1\r\n"
+                       ftp_printf(fin, "GET %s HTTP/1.1\r\n"
                            "Connection: close\r\n"
                            "Host: %s\r\n%s%s\r\n\r\n",
                            epath, proxyhost, buf ? buf : "", httpuseragent);
@@ -721,7 +726,7 @@ noslash:
 #endif /* SMALL */
 #ifndef NOSSL
                if (credentials) {
-                       fprintf(fin,
+                       ftp_printf(fin,
                            "GET /%s HTTP/1.1\r\n"
                            "Connection: close\r\n"
                            "Authorization: Basic %s\r\n"
@@ -730,12 +735,12 @@ noslash:
                        credentials = NULL;
                } else
 #endif /* NOSSL */
-                       fprintf(fin,
+                       ftp_printf(fin,
                            "GET /%s HTTP/1.1\r\n"
                            "Connection: close\r\n"
                            "Host: ", epath);
                if (proxyhost) {
-                       fprintf(fin, "%s", proxyhost);
+                       ftp_printf(fin, "%s", proxyhost);
                        port = NULL;
                } else if (strchr(host, ':')) {
                        /*
@@ -747,10 +752,10 @@ noslash:
                                errx(1, "Can't allocate memory.");
                        if ((p = strchr(h, '%')) != NULL)
                                *p = '\0';
-                       fprintf(fin, "[%s]", h);
+                       ftp_printf(fin, "[%s]", h);
                        free(h);
                } else
-                       fprintf(fin, "%s", host);
+                       ftp_printf(fin, "%s", host);
 
                /*
                 * Send port number only if it's specified and does not equal
@@ -759,15 +764,15 @@ noslash:
                 */
 #ifndef NOSSL
                if (port && strcmp(port, (ishttpsurl ? "443" : "80")) != 0)
-                       fprintf(fin, ":%s", port);
+                       ftp_printf(fin, ":%s", port);
                if (restart_point)
-                       fprintf(fin, "\r\nRange: bytes=%lld-",
+                       ftp_printf(fin, "\r\nRange: bytes=%lld-",
                                (long long)restart_point);
 #else /* !NOSSL */
                if (port && strcmp(port, "80") != 0)
-                       fprintf(fin, ":%s", port);
+                       ftp_printf(fin, ":%s", port);
 #endif /* !NOSSL */
-               fprintf(fin, "\r\n%s%s\r\n\r\n",
+               ftp_printf(fin, "\r\n%s%s\r\n\r\n",
                    buf ? buf : "", httpuseragent);
        }
        free(epath);
@@ -1614,6 +1619,27 @@ ftp_readline(FILE *fp, size_t *lenp)
        return fparseln(fp, lenp, NULL, "\0\0\0", 0);
 }
 
+#ifndef SMALL
+static int
+ftp_printf(FILE *fp, const char *fmt, ...)
+{
+       va_list ap;
+       int     ret;
+
+       va_start(ap, fmt);
+       ret = vfprintf(fp, fmt, ap);
+       va_end(ap);
+
+       if (debug) {
+               va_start(ap, fmt);
+               vfprintf(ttyout, fmt, ap);
+               va_end(ap);
+       }
+
+       return ret;
+}
+#endif /* !SMALL */
+
 static void
 ftp_close(FILE **fin, struct tls **tls, volatile int *fd)
 {


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to