unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Sebastian Tennant <sebyte@smolny.plus.com>
To: guile-user@gnu.org
Subject: Re: Uploading Word documents, PDFs, PNG files etc
Date: Thu, 14 May 2009 12:49:14 +0000	[thread overview]
Message-ID: <iqk3eto5.fsf@vps203.linuxvps.org> (raw)
In-Reply-To: 200905140347.n4E3l6LB003384@fcs13.keithdiane.us

Quoth Keith Wright <kwright@keithdiane.us>:
>> > Restricting regexps to actual text is fine... until
>> > you need to grep binary data, or, as in this case,
>> > a combination of text and binary data.
>> 
>> > in cgi.scm that extracted the uploaded (possibly
>> > binary) file, because the pattern identifying the
>> > beginning of the file in the raw data string is
>> > simple ("\n\r\n\r") -
>> 
>> No, this sounds somehow broken.  If I remember correctly,
>> binary mime-parts should have a ConentLength header
>> so you can skip over them. If ContentLength is absent,
>> then the part should bee ascii-encoded (e.g. base64)
>> yeah, grapping large blocks of ascii sucks, which is
>> why the ContetnLength should be used.
>> 
>> -- linas
>
> If the spec says a length indication followed by
> a fixed length of arbitrary binary data, then it
> is not just sucky, but incorrect to apply either
> grep or regexp to the binary.  It will seem to
> work until it hits a binary data that "by
> accident" contains the string you are looking
> for.
>
> The only correct algorithm is to make a preliminary
> pass to somehow remove the binary data and
> pseudo-concatenate the remaining strings.

Multipart/form-data comes with a Content-Length header that describes
the length of any and all parts combined, making it possible to extract
a string that looks like this:

 -----------------------------1307099961880952181245320094\x0d
 Content-Disposition: form-data; name=\"TABLE\"\x0d
 \x0d
 \x0d
 -----------------------------1307099961880952181245320094\x0d
 Content-Disposition: form-data; name=\"File-Upload\"; filename=\"null-char.txt\"\x0d
 Content-Type: text/plain\x0d
 \x0d
 foo^@bar
 \x0d
 -----------------------------1307099961880952181245320094\x0d
 Content-Disposition: form-data; name=\"Button\"\x0d
 \x0d
 Upload\x0d
 -----------------------------1307099961880952181245320094--\x0d

The boundary can be obtained from the Content-Type header and the above
string can then be broken into parts but how can one extract the name,
filename, type and value of each part without using regexps?

cgi.scm currently uses the following patterns and I can't think of an
alternative way of doing it:

 (let ((name-rx     (make-regexp "name=\"([^\"]*)\""))
       (filename-rx (make-regexp "filename=\"*([^\"\r]*)\"*"))
       (type-rx     (make-regexp "Content-Type: ([^\r]*)\r\n" regexp/icase))
       (value-rx    (make-regexp "\r\n\r\n")))
   ...)

Seb
-- 
Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness.
http://home.gna.org/eap





  reply	other threads:[~2009-05-14 12:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-10 16:21 Uploading Word documents, PDFs, PNG files etc Sebastian Tennant
2009-05-11 15:11 ` Ludovic Courtès
2009-05-11 15:55   ` Thien-Thi Nguyen
2009-05-11 23:17     ` Ludovic Courtès
2009-05-12  3:15 ` Thien-Thi Nguyen
2009-05-12 10:15   ` Sebastian Tennant
2009-05-12 10:33     ` Ludovic Courtès
2009-05-12 11:16       ` Sebastian Tennant
2009-05-13 14:02   ` Sebastian Tennant
2009-05-13 15:02     ` Ludovic Courtès
2009-05-13 18:01       ` Sebastian Tennant
2009-05-13 19:09       ` Sebastian Tennant
2009-05-13 19:23         ` Linas Vepstas
2009-05-14  3:47           ` Keith Wright
2009-05-14 12:49             ` Sebastian Tennant [this message]
2009-05-14 13:13               ` Sebastian Tennant
2009-05-17 21:55               ` Ludovic Courtès
2009-05-19  4:48                 ` Sebastian Tennant
2009-05-19  4:59                   ` Sebastian Tennant
2009-05-19  7:50                   ` Ludovic Courtès
2009-05-21  5:22                     ` Sebastian Tennant
2009-05-21 10:47                       ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=iqk3eto5.fsf@vps203.linuxvps.org \
    --to=sebyte@smolny.plus.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).