lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lynx-dev [PATCH 2.8.5-dev14] File upload


From: Ilya Zakharevich
Subject: lynx-dev [PATCH 2.8.5-dev14] File upload
Date: Mon, 17 Feb 2003 01:07:24 -0800
User-agent: Mutt/1.4i

This is a tiny bug fix for file upload.  By some strange reason (see
the check for MultipartContentType) correct headers were not inserted.

I also changed to logic for base64 to be used ONLY if \0 was found.
If a "strange" char is found, we just change "text/plain" to
"application/octet-stream".

[Of course, this is little relevant for files with \0, since no site I know
which accepts uploads will decode base64...]

Enjoy,
Ilya

--- ./src/GridText.c-pre        Tue Feb  4 18:00:16 2003
+++ ./src/GridText.c    Fri Feb 14 19:30:48 2003
@@ -9998,7 +9998,7 @@ PRIVATE BOOLEAN begin_submission_part AR
 
 #ifdef EXP_FILE_UPLOAD
 PRIVATE char * load_a_file ARGS2(
-    BOOLEAN *, use_mime,
+    int *,     use_mime,
     char *,    val_used)
 {
     char *escaped2 = NULL;
@@ -10009,7 +10009,7 @@ PRIVATE char * load_a_file ARGS2(
 
     CTRACE((tfp, "Ok, about to convert %s to mime/thingy\n", val_used));
 
-    *use_mime = FALSE;
+    *use_mime = 0;
 
     if ((fd = fopen(val_used, BIN_R)) == 0) {
        HTAlert(gettext("Can't open file for uploading"));
@@ -10019,17 +10019,20 @@ PRIVATE char * load_a_file ARGS2(
            buffer[bytes] = 0;
            for (n = 0; n < bytes; ++n) {
                int ch = UCH(buffer[n]);
-               if ((iscntrl(ch) && !isspace(ch))
-                || (!iscntrl(ch) && !isprint(ch))) {
-                   *use_mime = TRUE;
+
+               if (!ch) {
+                   *use_mime = 1;
                    break;
                }
+               else if ((iscntrl(ch) && !isspace(ch))
+                || (!iscntrl(ch) && !isprint(ch)))
+                   *use_mime = -1;
            }
-           if (*use_mime)
+           if (*use_mime > 0)
                break;
            StrAllocCat(escaped2, buffer);
        }
-       if (*use_mime) {
+       if (*use_mime > 0) {
            rewind(fd);
            StrAllocCopy(escaped2, "");
            while ((bytes = fread(buffer, sizeof(char), 45, fd)) != 0) {
@@ -10137,7 +10140,7 @@ PUBLIC int HText_SubmitForm ARGS4(
     int textarea_lineno = 0;
     unsigned form_is_special = 0;
 #ifdef EXP_FILE_UPLOAD
-    BOOLEAN use_mime;
+    int use_mime;
 #endif
 
     CTRACE((tfp, "SubmitForm\n  link_name=%s\n  link_value=%s\n", link_name, 
link_value));
@@ -10630,14 +10633,17 @@ PUBLIC int HText_SubmitForm ARGS4(
                if (PlainText) {
                    StrAllocCopy(escaped1, name_used);
                } else if (Boundary) {
+                   char *t = guess_content_type(val_used);
+
+                   if (use_mime && !strcmp(t, "text/plain"))
+                       t = "application/octet-stream";
                    StrAllocCopy(escaped1, "Content-Disposition: form-data");
                    HTSprintf(&escaped1, "; name=\"%s\"", name_used);
                    HTSprintf(&escaped1, "; filename=\"%s\"", val_used);
-                   if (MultipartContentType) {
-                       HTSprintf(&escaped1, MultipartContentType, 
guess_content_type(val_used));
-                       if (use_mime)
+                   /* Should we take into account the encoding? */
+                   HTSprintf(&escaped1, "\r\nContent-Type: %s", t);
+                   if (use_mime > 0)
                            StrAllocCat(escaped1, 
"\r\nContent-Transfer-Encoding: base64");
-                   }
                    StrAllocCat(escaped1, "\r\n\r\n");
                } else {
                    escaped1 = HTEscapeSP(name_used, URL_XALPHAS);

; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]