Hi list,
There is a problem with Pike 7.4 and disp_params variable in MIME.Message. The following code from Caudium doesn't work with Pike 7.4. I tried to copy 7.2's MIME.pmod to Pike 7.4 MIME/module.pmod and then it was working.
The difference between two MIME version is that when it works I have part->disp_params=([ /* 1 element */ "name":"1" ]), part->getdata="Upload to attachments", part->headers=([ /* 1 element */ "content-disposition":"form-data; name="1"" ])
and when it doesn't work, this mapping is empty.
FYI, Here is the code (from protocols/http.pike and protocols/http2.pike):
case "multipart/form-data": // perror("Multipart/form-data post detected\n"); object messg = MIME.Message(data, request_headers); write("data=%O, request_headers=%O\n", data, request_headers); foreach(messg->body_parts||({}), object part) { write("part->disp_params=%O, part->getdata=%O, part->headers=%O\n", part->disp_params, part->getdata(), part->headers); if(part->disp_params->filename) { variables[part->disp_params->name]=part->getdata(); string fname=part->disp_params->filename; if( part->headers["content-disposition"] ) { array fntmp=part->headers["content-disposition"]/";"; if( sizeof(fntmp) >= 3 && search(fntmp[2],"=") != -1 ) { fname=((fntmp[2]/"=")[1]); fname=fname[1..(sizeof(fname)-2)]; }
} variables[part->disp_params->name+".filename"]=fname;
if(!misc->files) misc->files = ({ part->disp_params->name }); else misc->files += ({ part->disp_params->name }); } else { if(variables[part->disp_params->name]) variables[part->disp_params->name] += "\0" + part->getdata(); else variables[part->disp_params->name] = part->getdata(); } } break;
Thanks for your help.
Could you show us the input to MIME.Message in this case? If I test with a trivial message, I get the expected result:
Pike v7.4 release 13 running Hilfe v3.5 (Incremental Pike Frontend)
MIME.Message("Content-Disposition: form-data; name="1"\n\n")->disp_params;
(1) Result: ([ /* 1 element */ "name":"1" ])
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2003-02-01 18:27: Subject: MIME.Message problem with 7.4
Hi list,
There is a problem with Pike 7.4 and disp_params variable in MIME.Message. The following code from Caudium doesn't work with Pike 7.4. I tried to copy 7.2's MIME.pmod to Pike 7.4 MIME/module.pmod and then it was working.
The difference between two MIME version is that when it works I have part->disp_params=([ /* 1 element */ "name":"1" ]), part->getdata="Upload to attachments", part->headers=([ /* 1 element */ "content-disposition":"form-data; name="1"" ])
and when it doesn't work, this mapping is empty.
FYI, Here is the code (from protocols/http.pike and protocols/http2.pike):
case "multipart/form-data": // perror("Multipart/form-data post detected\n"); object messg = MIME.Message(data, request_headers); write("data=%O, request_headers=%O\n", data, request_headers); foreach(messg->body_parts||({}), object part) { write("part->disp_params=%O, part->getdata=%O, part->headers=%O\n", part->disp_params, part->getdata(), part->headers); if(part->disp_params->filename) { variables[part->disp_params->name]=part->getdata(); string fname=part->disp_params->filename; if( part->headers["content-disposition"] ) { array fntmp=part->headers["content-disposition"]/";"; if( sizeof(fntmp) >= 3 && search(fntmp[2],"=") != -1 ) { fname=((fntmp[2]/"=")[1]); fname=fname[1..(sizeof(fname)-2)]; }
} variables[part->disp_params->name+".filename"]=fname; if(!misc->files) misc->files = ({ part->disp_params->name }); else misc->files += ({ part->disp_params->name }); } else { if(variables[part->disp_params->name]) variables[part->disp_params->name] += "\0" + part->getdata(); else variables[part->disp_params->name] = part->getdata(); } } break;
Thanks for your help.
-- David Gourdelier
/ Brevbäraren
On Sat, 1 Feb 2003, Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum wrote:
Could you show us the input to MIME.Message in this case? If I test with a trivial message, I get the expected result:
Pike v7.4 release 13 running Hilfe v3.5 (Incremental Pike Frontend)
MIME.Message("Content-Disposition: form-data; name="1"\n\n")->disp_params;
(1) Result: ([ /* 1 element */ "name":"1" ])
Of course, here is the output from the different writes I put in the code:
data="-----------------------------15261807498418654551597658587\r\nContent-Disposition: form-data; name="CaudiumSID"\r\n\r\n5fu8|sOWwkVKE9O5M6anDpq|1ME-\r\n-----------------------------15261807498418654551597658587\r\nContent-Disposition: form-data; name="file"; filename="test"\r\nContent-Type: application/octet-stream\r\n\r\nContent-Type: multipart/form-data; boundary=---------------------------11479027812035015474368800899\nContent-Length: 493\n\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="CaudiumSID"\n\nnznqeZnskwxfTLoDPrWh2H3fg28-\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="file"; filename="test.txt"\nContent-Type: text/plain\n\nTest\n\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="1"\n\nUpload to attachments\n-----------------------------11479027812035015474368800899--\n\r\n-----------------------------15261807498418654551597658587\r\nContent-Disposition: form-data; name="1"\r\n\r\nUpload to attachments\r\n-----------------------------15261807498418654551597658587--\r\n", request_headers=([ /* 12 elements */
"accept":"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1", "accept-charset":"ISO-8859-1, utf-8;q=0.66, *;q=0.66", "accept-encoding":"gzip, deflate, compress;q=0.9", "accept-language":"fr-fr, en;q=0.50", "connection":"keep-alive", "content-length":"1099", "content-type":"multipart/form-data; boundary=---------------------------15261807498418654551597658587", "cookie":"SessionID=c1eb4ee22a64d74544d869342cb62a96; CaudiumSID=c4UUnZwf61tTTKO8zvJFU2_LDIg-", "host":"localhost:81", "keep-alive":"300", "referer":"http://localhost:81/tmp/test.html", "user-agent":"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021226 Debian/1.2.1-9" ]) part->disp_params=([ ]), part->getdata="Content-Disposition: form-data; name="CaudiumSID"\r\n\r\n5fu8|sOWwkVKE9O5M6anDpq|1ME-", part->headers=([ ]) part->disp_params=([ ]), part->getdata="Content-Disposition: form-data; name="file"; filename="test"\r\nContent-Type: application/octet-stream\r\n\r\nContent-Type: multipart/form-data; boundary=---------------------------11479027812035015474368800899\nContent-Length: 493\n\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="CaudiumSID"\n\nnznqeZnskwxfTLoDPrWh2H3fg28-\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="file"; filename="test.txt"\nContent-Type: text/plain\n\nTest\n\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="1"\n\nUpload to attachments\n-----------------------------11479027812035015474368800899--\n", part->headers=([ ]) part->disp_params=([ ]), part->getdata="Content-Disposition: form-data; name="1"\r\n\r\nUpload to attachments", part->headers=([ ])
-- David Gourdelier
Ok, problem located. There was a bug in the multipart splitter which previously was hidden by _another_ bug in the header parser. So when grubba fixed the header parser bug, multipart handling stopped working. (More precisly, it will fail if the boundary string is followed by \r\n, as the RFC specifices, but it will still work if it just followed by \n.)
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2003-02-01 20:21: Subject: Re: MIME.Message problem with 7.4
On Sat, 1 Feb 2003, Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum wrote:
Could you show us the input to MIME.Message in this case? If I test with a trivial message, I get the expected result:
Pike v7.4 release 13 running Hilfe v3.5 (Incremental Pike Frontend)
MIME.Message("Content-Disposition: form-data; name="1"\n\n")->disp_params;
(1) Result: ([ /* 1 element */ "name":"1" ])
Of course, here is the output from the different writes I put in the code:
data="-----------------------------15261807498418654551597658587\r\nContent-Disposition: form-data; name="CaudiumSID"\r\n\r\n5fu8|sOWwkVKE9O5M6anDpq|1ME-\r\n-----------------------------15261807498418654551597658587\r\nContent-Disposition: form-data; name="file"; filename="test"\r\nContent-Type: application/octet-stream\r\n\r\nContent-Type: multipart/form-data; boundary=---------------------------11479027812035015474368800899\nContent-Length: 493\n\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="CaudiumSID"\n\nnznqeZnskwxfTLoDPrWh2H3fg28-\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="file"; filename="test.txt"\nContent-Type: text/plain\n\nTest\n\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="1"\n\nUpload to attachments\n-----------------------------11479027812035015474368800899--\n\r\n-----------------------------15261807498418654551597658587\r\nContent-Disposition: form-data; name="1"\r\n\r\nUpload to attachments\r\n-----------------------------15261807498418654551597658587--\r\n", request_headers=([ /* 12 elements */
"accept":"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1", "accept-charset":"ISO-8859-1, utf-8;q=0.66, *;q=0.66", "accept-encoding":"gzip, deflate, compress;q=0.9", "accept-language":"fr-fr, en;q=0.50", "connection":"keep-alive", "content-length":"1099", "content-type":"multipart/form-data; boundary=---------------------------15261807498418654551597658587", "cookie":"SessionID=c1eb4ee22a64d74544d869342cb62a96; CaudiumSID=c4UUnZwf61tTTKO8zvJFU2_LDIg-", "host":"localhost:81", "keep-alive":"300", "referer":"http://localhost:81/tmp/test.html", "user-agent":"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021226 Debian/1.2.1-9" ]) part->disp_params=([ ]), part->getdata="Content-Disposition: form-data; name="CaudiumSID"\r\n\r\n5fu8|sOWwkVKE9O5M6anDpq|1ME-", part->headers=([ ]) part->disp_params=([ ]), part->getdata="Content-Disposition: form-data; name="file"; filename="test"\r\nContent-Type: application/octet-stream\r\n\r\nContent-Type: multipart/form-data; boundary=---------------------------11479027812035015474368800899\nContent-Length: 493\n\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="CaudiumSID"\n\nnznqeZnskwxfTLoDPrWh2H3fg28-\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="file"; filename="test.txt"\nContent-Type: text/plain\n\nTest\n\n-----------------------------11479027812035015474368800899\nContent-Disposition: form-data; name="1"\n\nUpload to attachments\n-----------------------------11479027812035015474368800899--\n", part->headers=([ ]) part->disp_params=([ ]), part->getdata="Content-Disposition: form-data; name="1"\r\n\r\nUpload to attachments", part->headers=([ ])
-- David Gourdelier
/ Brevbäraren
pike-devel@lists.lysator.liu.se