[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Uploading Word documents, PDFs, PNG files etc
From: |
Sebastian Tennant |
Subject: |
Re: Uploading Word documents, PDFs, PNG files etc |
Date: |
Thu, 14 May 2009 12:49:14 +0000 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/22.2 (gnu/linux) |
Quoth Keith Wright <address@hidden>:
>> > 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
address@hidden
\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
- Re: Uploading Word documents, PDFs, PNG files etc, (continued)
- Re: Uploading Word documents, PDFs, PNG files etc, Thien-Thi Nguyen, 2009/05/11
- Re: Uploading Word documents, PDFs, PNG files etc, Sebastian Tennant, 2009/05/13
- Re: Uploading Word documents, PDFs, PNG files etc, Ludovic Courtès, 2009/05/13
- Re: Uploading Word documents, PDFs, PNG files etc, Sebastian Tennant, 2009/05/13
- Re: Uploading Word documents, PDFs, PNG files etc, Sebastian Tennant, 2009/05/13
- Re: Uploading Word documents, PDFs, PNG files etc, Linas Vepstas, 2009/05/13
- Re: Uploading Word documents, PDFs, PNG files etc, Keith Wright, 2009/05/13
- Re: Uploading Word documents, PDFs, PNG files etc,
Sebastian Tennant <=
- Re: Uploading Word documents, PDFs, PNG files etc, Sebastian Tennant, 2009/05/14
- Re: Uploading Word documents, PDFs, PNG files etc, Ludovic Courtès, 2009/05/17
- Re: Uploading Word documents, PDFs, PNG files etc, Sebastian Tennant, 2009/05/19
- Re: Uploading Word documents, PDFs, PNG files etc, Sebastian Tennant, 2009/05/19
- Re: Uploading Word documents, PDFs, PNG files etc, Ludovic Courtès, 2009/05/19
- Re: Uploading Word documents, PDFs, PNG files etc, Sebastian Tennant, 2009/05/21
- Re: Uploading Word documents, PDFs, PNG files etc, Thien-Thi Nguyen, 2009/05/21