Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 98504 invoked from network); 22 Dec 2004 04:41:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 22 Dec 2004 04:41:02 -0000 Received: (qmail 44961 invoked by uid 500); 22 Dec 2004 04:40:59 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 44943 invoked by uid 500); 22 Dec 2004 04:40:58 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 44925 invoked by uid 99); 22 Dec 2004 04:40:58 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of dakota.jack@gmail.com designates 64.233.184.196 as permitted sender) Received: from wproxy.gmail.com (HELO wproxy.gmail.com) (64.233.184.196) by apache.org (qpsmtpd/0.28) with ESMTP; Tue, 21 Dec 2004 20:40:55 -0800 Received: by wproxy.gmail.com with SMTP id 67so15711wri for ; Tue, 21 Dec 2004 20:40:52 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=W1sGMpJ6jz5paamaV+V5e0LpI7ML51S0swWlpW8o1TnOKVYfhcau8HV3tnZRfABTuTv4/9FEQzqfJkDSuCCocWOAk76QCgMr1wYyReE8kSv7gSLdPFPKsquuunEw0CdonU0IhubyM5qx0pDfXmm922IbdVSqDCaS9v6Dj2UncgU= Received: by 10.54.44.34 with SMTP id r34mr53298wrr; Tue, 21 Dec 2004 20:39:01 -0800 (PST) Received: by 10.54.48.44 with HTTP; Tue, 21 Dec 2004 20:39:01 -0800 (PST) Message-ID: Date: Tue, 21 Dec 2004 20:39:01 -0800 From: Dakota Jack Reply-To: Dakota Jack To: Jakarta Commons Users List Subject: Re: [fileupload] jsp mime type In-Reply-To: <41C8D4B0.3090906@ntsource.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <41C8D4B0.3090906@ntsource.com> X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N On Tue, 21 Dec 2004 19:58:08 -0600, Matt Bathje wrote: > Hey all - > > I posted this to the struts list a while back, but got no responses and > it is probably more appropriate here. > > I am working with the commons file uploader in struts to upload a JSP > file to my website. Being a security conscious developer, I am limiting > the available upload file types to text/plain and text/html hoping that > the JSP file would be sent as one of these types. > > Instead, it is sent as application/octet-stream - which is the same type > used for executables and binary type files - seems kind of weird to me. > > Does anybody know if there is a way to "force" jsp files to be of a > text/plain (or some other text type) instead of > application/octet-stream? I tried adding the following to my web.xml > file (Tomcat 5.0.x): > > > jsp > text/plain > > > But it didn't seem to make a difference. > > Thanks, > Matt This may not be helpful, Matt, but solutions in this area can tend to be complex. For example, peruse this code: package com.crackwillow.web.mime; import com.crackwillow.util.*; import java.io.*; import java.util.*; import javax.activation.DataSource; import javax.mail.MessagingException; import javax.mail.internet.*; import javax.servlet.http.HttpServletRequest; public class MimeParser { class HttpPostDataSource implements DataSource { private String type; private InputStream is; public String getContentType() { return type; } public InputStream getInputStream() { return is; } public OutputStream getOutputStream() { return null; } public String getName() { return "Http Post Data"; } private void close() { try { is.close(); } catch(Exception e) { if(MimeParser.isDebug) e.printStackTrace(); } } public HttpPostDataSource(HttpServletRequest req) throws IOException { super(); type = null; is = null; type = req.getContentType(); is = req.getInputStream(); } } MimeParser() { } private void printDebug(String s) { if(isDebug) System.out.println(s); } { AcceptMime.getInstance().setDebug(flag); sizeChecker.setDebug(flag); isDebug = true; } public static synchronized MimeParser getInstance() throws SimpleException, NestedException, NoPropertyFileException { if(isPrepared) return mp; start = System.currentTimeMillis(); mime_map_dic = MimeMapDic.getInstance(); String s = "MimeParser.properties"; ClassLoader classloader = Thread.currentThread().getContextClassLoader(); InputStream is = classloader.getResourceAsStream(s); if(is == null) { ClassLoader classloader1 = mp.getClass().getClassLoader(); is = classloader1.getResourceAsStream(s); } if(is == null) throw new NoPropertyFileException("Failed to load :" + s); try { TimeZone timezone = TimeZone.getTimeZone("Asia/Tokyo"); GregorianCalendar gregoriancalendar = new GregorianCalendar(timezone); gregoriancalendar.set(1, 2004); gregoriancalendar.set(2, 6); gregoriancalendar.set(5, 31); gregoriancalendar.set(10, 1); gregoriancalendar.set(12, 0); gregoriancalendar.set(9, 0); long l = gregoriancalendar.getTime().getTime(); long l1 = System.currentTimeMillis(); if(l < l1) throw new SimpleException("Sorry, but the trial period expired!"); PropertyResourceBundle prb = new PropertyResourceBundle(is); is.close(); String s1 = prb.getString("save_file"); if(s1.equalsIgnoreCase("true")) save_file = true; if(save_file) { file_root = prb.getString("file_root"); File file = new File(file_root); if(!file.exists()) { System.out.println("MimeParser getInstance: " + file_root + " does not exist! MimeParser will create it."); if(!file.mkdirs()) throw new SimpleException("Failed to create " + file_root); System.out.println("MimeParser getInstance: " + file_root + " is created by MimeParser."); } } charset = prb.getString("charset"); String s2 = prb.getString("max_file"); max_file = Integer.parseInt(s2); try { String s3 = prb.getString("max_request"); max_request = Integer.parseInt(s3); } catch(MissingResourceException mre) { } try { String s4 = prb.getString("checkBinary"); if(s4 != null && s4.equalsIgnoreCase("true")) { binChecker = BinaryCheckerDic.getInstance(); checkBinary = true; } } catch(MissingResourceException mre) { } try { sizeChecker = ImageSizeChecker.getInstance(); checkSize = true; String s5 = prb.getString("max_width"); max_width = Integer.parseInt(s5); String s7 = prb.getString("max_height"); max_height = Integer.parseInt(s7); } catch(NoPropertyFileException npfe) { } try { String s6 = prb.getString("isDebug"); if(s6.equalsIgnoreCase("true")) { isDebug = true; if(checkSize) sizeChecker.setDebug(true); } } catch(MissingResourceException mre) { } } catch(SimpleException se) { throw se; } catch(Exception e) { throw new NestedException(e); } isPrepared = true; return mp; } public String getFileRoot() { return file_root; } public int getDefaultMaximumFileSize() { return max_file; } public boolean isImageSizeChecked() { return checkSize; } public int getMaximumWidth() { if(checkSize) return max_width; else return 0; } public int getMaximumHeight() { if(checkSize) return max_height; else return 0; } public ParsedData parseAndSave(HttpServletRequest req, String s, String s1, int i) throws SimpleException, TooLargeFileException, NestedException, TooLargeBodyException { checkTrial(); checkSaveFile(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); return parse(req, s, s1, i); Object obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw new NestedException(((Throwable) (obj))); } /** * @deprecated Method parse is deprecated */ public ParsedData parse(HttpServletRequest req, String s, String s1, int i) throws IOException, MessagingException, ParseException, SimpleException, TooLargeFileException, MissingResourceException, ClassNotFoundException, TooLargeBodyException { checkTrial(); int j = req.getContentLength(); if(j > max_request) throw new TooLargeBodyException(j, max_request); if(!req.getContentType().toLowerCase().startsWith("multipart/form-data")) throw new SimpleException("Not the Multipart request!"); String s2 = s1; int k = i; HashMap hm = new HashMap(); HashMap hm1 = new HashMap(); HashMap hm2 = new HashMap(); HashMap hm3 = new HashMap(); HttpPostDataSource hpds = new HttpPostDataSource(req); MimeMultipart mmp = new MimeMultipart(hpds); int l = mmp.getCount(); for(int i1 = 0; i1 < l; i1++) { printDebug("Start to parse the " + (i1 + 1) + "th MimeBodyPart..."); javax.mail.BodyPart bp = mmp.getBodyPart(i1); if(bp instanceof MimeBodyPart) { MimeBodyPart mbp = (MimeBodyPart)bp; try { parseBodySaveFile(mbp, s2, k, hm, hm1, hm2, hm3, null); } catch(InvalidContentTypeException icte) { } catch(LargeImageException lie) { } } else { throw new SimpleException("Not MimeBodyPart!"); } } String s3 = s; if(s3 == null) s3 = charset; Object obj = hm.get("charset"); if(obj != null) { byte data0[][] = (byte[][])obj; byte data1[] = data0[0]; if(data1.length != 0) { s3 = new String(data1, "8859_1"); printDebug("Charset is found in the parameters. It is " + s3); } } String s4 = s3; HashMap hm4 = new HashMap(); Set set = hm.entrySet(); String s5; String as[]; for(Iterator iterator = set.iterator(); iterator.hasNext(); hm4.put(s5, as)) { java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next(); s5 = (String)entry.getKey(); byte data2[][] = (byte[][])entry.getValue(); as = new String[data2.length]; for(int j1 = 0; j1 < data2.length; j1++) { byte data3[] = data2[j1]; as[j1] = new String(data3, s4); } } return new ParsedData(hm4, null, hm1, s4, hm2, hm3); } public ParsedData parseAndSave(HttpServletRequest req, String s, String s1) throws SimpleException, TooLargeFileException, NestedException, TooLargeBodyException { checkTrial(); checkSaveFile(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); return parse(req, s, s1); Object obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw new NestedException(((Throwable) (obj))); } /** * @deprecated Method parse is deprecated */ public ParsedData parse(HttpServletRequest req, String s, String s1) throws IOException, MessagingException, ParseException, SimpleException, TooLargeFileException, MissingResourceException, ClassNotFoundException, TooLargeBodyException { checkTrial(); int i = req.getContentLength(); if(i > max_request) throw new TooLargeBodyException(i, max_request); if(!req.getContentType().toLowerCase().startsWith("multipart/form-data")) throw new SimpleException("Not the Multipart request!"); String s2 = s1; int j = max_file; HashMap hm = new HashMap(); HashMap hm1 = new HashMap(); HashMap hm2 = new HashMap(); HashMap hm3 = new HashMap(); HttpPostDataSource hpds = new HttpPostDataSource(req); MimeMultipart mmp = new MimeMultipart(hpds); int k = mmp.getCount(); for(int l = 0; l < k; l++) { printDebug("Start to parse the " + (l + 1) + "th MimeBodyPart..."); javax.mail.BodyPart bp = mmp.getBodyPart(l); if(bp instanceof MimeBodyPart) { MimeBodyPart mbp = (MimeBodyPart)bp; try { parseBodySaveFile(mbp, s2, j, hm, hm1, hm2, hm3, null); } catch(InvalidContentTypeException icte) { } catch(LargeImageException lie) { } } else { throw new SimpleException("Not MimeBodyPart!"); } } String s3 = s; if(s3 == null) s3 = charset; Object obj = hm.get("charset"); if(obj != null) { byte data0[][] = (byte[][])obj; byte data1[] = data0[0]; if(data1.length != 0) { s3 = new String(data1, "8859_1"); printDebug("Charset is found in the parameters. It is " + s3); } } String s4 = s3; HashMap hm4 = new HashMap(); Set set = hm.entrySet(); String s5; String as[]; for(Iterator iterator = set.iterator(); iterator.hasNext(); hm4.put(s5, as)) { java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next(); s5 = (String)entry.getKey(); byte data2[][] = (byte[][])entry.getValue(); as = new String[data2.length]; for(int i1 = 0; i1 < data2.length; i1++) { byte data3[] = data2[i1]; as[i1] = new String(data3, s4); } } return new ParsedData(hm4, null, hm1, s4, hm2, hm3); } public ParsedData parseAndSave(HttpServletRequest req, String s, String s1, int i, Set set) throws SimpleException, TooLargeFileException, InvalidContentTypeException, NestedException, TooLargeBodyException, LargeImageException { checkTrial(); checkSaveFile(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); return parse(req, s, s1, i, set); Object obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw new NestedException(((Throwable) (obj))); } private ParsedData parse(HttpServletRequest req, String s, String s1, int i, Set set) throws IOException, MessagingException, ParseException, SimpleException, TooLargeFileException, MissingResourceException, ClassNotFoundException, InvalidContentTypeException, TooLargeBodyException, LargeImageException { int j = req.getContentLength(); if(j > max_request) throw new TooLargeBodyException(j, max_request); if(!req.getContentType().toLowerCase().startsWith("multipart/form-data")) throw new SimpleException("Not the Multipart request!"); String s2 = s1; int k = i; HashMap hm = new HashMap(); HashMap hm1 = new HashMap(); HashMap hm2 = new HashMap(); HashMap hm3 = new HashMap(); HttpPostDataSource hpds = new HttpPostDataSource(req); MimeMultipart mmp = new MimeMultipart(hpds); int l = mmp.getCount(); for(int i1 = 0; i1 < l; i1++) { printDebug("Start to parse the " + (i1 + 1) + "th MimeBodyPart..."); javax.mail.BodyPart bp = mmp.getBodyPart(i1); if(bp instanceof MimeBodyPart) { MimeBodyPart mbp = (MimeBodyPart)bp; parseBodySaveFile(mbp, s2, k, hm, hm1, hm2, hm3, set); } else { throw new SimpleException("Not MimeBodyPart!"); } } String s3 = s; if(s3 == null) s3 = charset; Object obj = hm.get("charset"); if(obj != null) { byte data0[][] = (byte[][])obj; byte data1[] = data0[0]; if(data1.length != 0) { s3 = new String(data1, "8859_1"); printDebug("Charset is found in the parameters. It is " + s3); } } String s4 = s3; HashMap hm4 = new HashMap(); Set set1 = hm.entrySet(); String s5; String as[]; for(Iterator iterator = set1.iterator(); iterator.hasNext(); hm4.put(s5, as)) { java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next(); s5 = (String)entry.getKey(); byte data2[][] = (byte[][])entry.getValue(); as = new String[data2.length]; for(int j1 = 0; j1 < data2.length; j1++) { byte data3[] = data2[j1]; as[j1] = new String(data3, s4); } } return new ParsedData(hm4, null, hm1, s4, hm2, hm3); } public ParsedData parseAndSave(HttpServletRequest req, String s, String s1, Set set) throws SimpleException, TooLargeFileException, InvalidContentTypeException, NestedException, TooLargeBodyException, LargeImageException { checkTrial(); checkSaveFile(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); return parse(req, s, s1, set); Object obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw new NestedException(((Throwable) (obj))); } private ParsedData parse(HttpServletRequest req, String s, String s1, Set set) throws IOException, MessagingException, ParseException, SimpleException, TooLargeFileException, MissingResourceException, ClassNotFoundException, InvalidContentTypeException, TooLargeBodyException, LargeImageException { int i = req.getContentLength(); if(i > max_request) throw new TooLargeBodyException(i, max_request); if(!req.getContentType().toLowerCase().startsWith("multipart/form-data")) throw new SimpleException("Not the Multipart request!"); String s2 = s1; int j = max_file; HashMap hm = new HashMap(); HashMap hm1 = new HashMap(); HashMap hm2 = new HashMap(); HashMap hm3 = new HashMap(); HttpPostDataSource hpds = new HttpPostDataSource(req); MimeMultipart mmp = new MimeMultipart(hpds); int k = mmp.getCount(); for(int l = 0; l < k; l++) { printDebug("Start to parse the " + (l + 1) + "th MimeBodyPart..."); javax.mail.BodyPart bp = mmp.getBodyPart(l); if(bp instanceof MimeBodyPart) { MimeBodyPart mbp = (MimeBodyPart)bp; parseBodySaveFile(mbp, s2, j, hm, hm1, hm2, hm3, set); } else { throw new SimpleException("Not MimeBodyPart!"); } } String s3 = s; if(s3 == null) s3 = charset; Object obj = hm.get("charset"); if(obj != null) { byte data0[][] = (byte[][])obj; byte data1[] = data0[0]; if(data1.length != 0) { s3 = new String(data1, "8859_1"); printDebug("Charset is found in the parameters. It is " + s3); } } String s4 = s3; HashMap hm4 = new HashMap(); Set set1 = hm.entrySet(); String s5; String as[]; for(Iterator iterator = set1.iterator(); iterator.hasNext(); hm4.put(s5, as)) { java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next(); s5 = (String)entry.getKey(); byte data2[][] = (byte[][])entry.getValue(); as = new String[data2.length]; for(int i1 = 0; i1 < data2.length; i1++) { byte data3[] = data2[i1]; as[i1] = new String(data3, s4); } } return new ParsedData(hm4, null, hm1, s4, hm2, hm3); } private void parseBodySaveFile(MimeBodyPart mbp, String s, int i, Map map, Map map1, Map map2, Map map3, Set set) throws IOException, MessagingException, ParseException, SimpleException, TooLargeFileException, InvalidContentTypeException, LargeImageException { if(mbp.isMimeType("multipart/*")) throw new SimpleException("This MimeBodyPart is mime type of multipart/*."); String s1 = getKeyName(mbp); String s2 = getEncoding(mbp); int j = mbp.getSize(); if(j == 0) { printDebug("No value for " + s1 + ". (Size is 0)"); return; } if(!isFile(mbp)) { printDebug("Start to parse the text..."); InputStream is = mbp.getInputStream(); if(s2 != null) is = MimeUtility.decode(is, s2); byte data0[] = null; if(j >= 0) { data0 = new byte[j]; long l = is.read(data0); is.close(); if(l != (long)j) throw new SimpleException("Error reading stream!"); } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int k = 0; do { if(k == -1) break; byte data5[] = new byte[1]; k = is.read(data5); if(k != -1) baos.write(data5); } while(true); baos.flush(); baos.close(); is.close(); data0 = baos.toByteArray(); } if(map.containsKey(s1)) { byte data1[][] = (byte[][])map.get(s1); byte data4[][] = new byte[data1.length + 1][]; for(int j1 = 0; j1 < data1.length; j1++) data4[j1] = data1[j1]; data4[data1.length] = data0; map.put(s1, data4); } else { byte data2[][] = new byte[1][]; data2[0] = data0; map.put(s1, data2); } return; } printDebug("Start to parse file..."); String s3 = getFileName(mbp); String s4 = mime_map_dic.getMimeType(s3); if(set != null) { String s5 = s4.toLowerCase(); s5 = s5.trim(); if(!set.contains(s5)) { int i1 = s5.indexOf("; name="); if(i1 >= 0) { String s6 = s5.substring(0, i1); if(!set.contains(s6)) throw new InvalidContentTypeException(s3, s6, set); s4 = s6; } else { throw new InvalidContentTypeException(s3, s5, set); } } } if(j >= 0 && i > 0 && j > i) throw new TooLargeFileException(s3, j, i); byte data3[] = null; InputStream is1 = mbp.getInputStream(); if(s2 != null) is1 = MimeUtility.decode(is1, s2); if(j >= 0) { data3 = new byte[j]; long l1 = is1.read(data3); is1.close(); if(l1 != (long)j) throw new SimpleException("Error reading stream!"); } else { ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); int k1 = 0; int j2 = 0; while(k1 != -1) { byte data7[] = new byte[1]; k1 = is1.read(data7); if(k1 != -1) { baos1.write(data7); j2++; if(i > 0 && j2 > i) { baos1.flush(); baos1.close(); is1.close(); throw new TooLargeFileException(s3, j2, i); } } } baos1.flush(); baos1.close(); is1.close(); data3 = baos1.toByteArray(); } if(set != null) if(checkSize) { if(sizeChecker.shouldCheck(s4)) sizeChecker.checkImageSize(data3, s4, s3, max_width, max_height); else if(checkBinary && !binChecker.checkBinary(s4, data3)) throw new CorruptedBinaryContentsException(s3, s4); } else if(checkBinary && !binChecker.checkBinary(s4, data3)) throw new CorruptedBinaryContentsException(s3, s4); File file = null; if(s == null) { file = new File(file_root); if(!file.exists() && !file.mkdir()) throw new SimpleException("Failed to create " + file_root); if(!file.canWrite()) throw new SimpleException(file_root + " is not writable."); } else { int i2 = s.indexOf(".."); if(i2 >= 0) throw new SimpleException("Sub-directory name cannot contain .. !"); file = new File(file_root, s); if(!file.exists() && !file.mkdirs()) { String s7 = file.getCanonicalPath(); throw new SimpleException("Failed to create " + s7); } if(!file.canWrite()) { String s8 = file.getCanonicalPath(); throw new SimpleException(s8 + " is not writable."); } } printDebug("File will be saved to " + file.getCanonicalPath()); map2.put(s1, s4); map3.put(s1, s3); Object obj = map.get(s1); if(obj != null) { byte data6[][] = (byte[][])obj; byte data8[] = data6[0]; if(data8.length != 0) { s3 = new String(data8, "8859_1"); printDebug("File name is found in the parameters. It is " + s3); } } if(s3 == null) throw new SimpleException("Missing file name!"); int k2 = s3.indexOf(".."); if(k2 >= 0) { throw new SimpleException("File name cannot contain .. !"); } else { File file1 = new File(file, s3); FileOutputStream fos = new FileOutputStream(file1); fos.write(data3); fos.flush(); fos.close(); map1.put(s1, file1); return; } } public ParsedData parseOnly(HttpServletRequest req, String s, int i) throws SimpleException, TooLargeFileException, NestedException, TooLargeBodyException { checkTrial(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); return parse(req, s, i); Object obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw new NestedException(((Throwable) (obj))); } /** * @deprecated Method parse is deprecated */ public ParsedData parse(HttpServletRequest req, String s, int i) throws IOException, MessagingException, ParseException, SimpleException, TooLargeFileException, MissingResourceException, ClassNotFoundException, TooLargeBodyException { checkTrial(); int j = req.getContentLength(); if(j > max_request) throw new TooLargeBodyException(j, max_request); if(!req.getContentType().toLowerCase().startsWith("multipart/form-data")) throw new SimpleException("Not the Multipart request!"); int k = i; HashMap hm = new HashMap(); HashMap hm1 = new HashMap(); HashMap hm2 = new HashMap(); HashMap hm3 = new HashMap(); HttpPostDataSource hpds = new HttpPostDataSource(req); MimeMultipart mmp = new MimeMultipart(hpds); int l = mmp.getCount(); for(int i1 = 0; i1 < l; i1++) { printDebug("Start to parse the " + (i1 + 1) + "th MimeBodyPart..."); javax.mail.BodyPart bp = mmp.getBodyPart(i1); if(bp instanceof MimeBodyPart) { MimeBodyPart mbp = (MimeBodyPart)bp; try { parseBodyGetCont(mbp, k, hm, hm1, hm2, hm3, null); } catch(InvalidContentTypeException icte) { } catch(LargeImageException lie) { } } else { throw new SimpleException("Not MimeBodyPart!"); } } String s1 = s; if(s1 == null) s1 = charset; Object obj = hm.get("charset"); if(obj != null) { byte data0[][] = (byte[][])obj; byte data1[] = data0[0]; if(data1.length != 0) { s1 = new String(data1, "8859_1"); printDebug("Charset is found in the parameters. It is " + s1); } } String s2 = s1; HashMap hm4 = new HashMap(); Set set = hm.entrySet(); String s3; String as[]; for(Iterator iterator = set.iterator(); iterator.hasNext(); hm4.put(s3, as)) { java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next(); s3 = (String)entry.getKey(); byte data2[][] = (byte[][])entry.getValue(); as = new String[data2.length]; for(int j1 = 0; j1 < data2.length; j1++) { byte data3[] = data2[j1]; as[j1] = new String(data3, s2); } } return new ParsedData(hm4, hm1, null, s2, hm2, hm3); } public ParsedData parseOnly(HttpServletRequest req, String s) throws SimpleException, TooLargeFileException, NestedException, TooLargeBodyException { checkTrial(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); return parse(req, s); Object obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw new NestedException(((Throwable) (obj))); } /** * @deprecated Method parse is deprecated */ public ParsedData parse(HttpServletRequest req, String s) throws IOException, MessagingException, ParseException, SimpleException, TooLargeFileException, MissingResourceException, ClassNotFoundException, TooLargeBodyException { checkTrial(); int i = req.getContentLength(); if(i > max_request) throw new TooLargeBodyException(i, max_request); if(!req.getContentType().toLowerCase().startsWith("multipart/form-data")) throw new SimpleException("Not the Multipart request!"); int j = max_file; HashMap hm = new HashMap(); HashMap hm1 = new HashMap(); HashMap hm2 = new HashMap(); HashMap hm3 = new HashMap(); HttpPostDataSource hpds = new HttpPostDataSource(req); MimeMultipart mmp = new MimeMultipart(hpds); int k = mmp.getCount(); for(int l = 0; l < k; l++) { printDebug("Start to parse the " + (l + 1) + "th MimeBodyPart..."); javax.mail.BodyPart bp = mmp.getBodyPart(l); if(bp instanceof MimeBodyPart) { MimeBodyPart mbp = (MimeBodyPart)bp; try { parseBodyGetCont(mbp, j, hm, hm1, hm2, hm3, null); } catch(InvalidContentTypeException icte) { } catch(LargeImageException lie) { } } else { throw new SimpleException("Not MimeBodyPart!"); } } String s1 = s; if(s1 == null) s1 = charset; Object obj = hm.get("charset"); if(obj != null) { byte data0[][] = (byte[][])obj; byte data1[] = data0[0]; if(data1.length != 0) { s1 = new String(data1, "8859_1"); printDebug("Charset is found in the parameters. It is " + s1); } } String s2 = s1; HashMap hm4 = new HashMap(); Set set = hm.entrySet(); String s3; String as[]; for(Iterator iterator = set.iterator(); iterator.hasNext(); hm4.put(s3, as)) { java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next(); s3 = (String)entry.getKey(); byte data2[][] = (byte[][])entry.getValue(); as = new String[data2.length]; for(int i1 = 0; i1 < data2.length; i1++) { byte data3[] = data2[i1]; as[i1] = new String(data3, s2); } } return new ParsedData(hm4, hm1, null, s2, hm2, hm3); } public ParsedData parseOnly(HttpServletRequest req, String s, int i, Set set) throws SimpleException, TooLargeFileException, InvalidContentTypeException, NestedException, TooLargeBodyException, LargeImageException { checkTrial(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); return parse(req, s, i, set); Object obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw new NestedException(((Throwable) (obj))); } private ParsedData parse(HttpServletRequest req, String s, int i, Set set) throws IOException, MessagingException, ParseException, SimpleException, TooLargeFileException, MissingResourceException, ClassNotFoundException, InvalidContentTypeException, TooLargeBodyException, LargeImageException { int j = req.getContentLength(); if(j > max_request) throw new TooLargeBodyException(j, max_request); if(!req.getContentType().toLowerCase().startsWith("multipart/form-data")) throw new SimpleException("Not the Multipart request!"); int k = i; HashMap hm = new HashMap(); HashMap hm1 = new HashMap(); HashMap hm2 = new HashMap(); HashMap hm3 = new HashMap(); HttpPostDataSource hpds = new HttpPostDataSource(req); MimeMultipart mmp = new MimeMultipart(hpds); int l = mmp.getCount(); for(int i1 = 0; i1 < l; i1++) { printDebug("Start to parse the " + (i1 + 1) + "th MimeBodyPart..."); javax.mail.BodyPart bp = mmp.getBodyPart(i1); if(bp instanceof MimeBodyPart) { MimeBodyPart mbp = (MimeBodyPart)bp; parseBodyGetCont(mbp, k, hm, hm1, hm2, hm3, set); } else { throw new SimpleException("Not MimeBodyPart!"); } } String s1 = s; if(s1 == null) s1 = charset; Object obj = hm.get("charset"); if(obj != null) { byte data0[][] = (byte[][])obj; byte data1[] = data0[0]; if(data1.length != 0) { s1 = new String(data1, "8859_1"); printDebug("Charset is found in the parameters. It is " + s1); } } String s2 = s1; HashMap hm4 = new HashMap(); Set set1 = hm.entrySet(); String s3; String as[]; for(Iterator iterator = set1.iterator(); iterator.hasNext(); hm4.put(s3, as)) { java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next(); s3 = (String)entry.getKey(); byte data2[][] = (byte[][])entry.getValue(); as = new String[data2.length]; for(int j1 = 0; j1 < data2.length; j1++) { byte data3[] = data2[j1]; as[j1] = new String(data3, s2); } } return new ParsedData(hm4, hm1, null, s2, hm2, hm3); } public ParsedData parseOnly(HttpServletRequest req, String s, Set set) throws SimpleException, TooLargeFileException, InvalidContentTypeException, NestedException, TooLargeBodyException, LargeImageException { checkTrial(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); return parse(req, s, set); Object obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw obj; obj; throw new NestedException(((Throwable) (obj))); } private ParsedData parse(HttpServletRequest req, String s, Set set) throws IOException, MessagingException, ParseException, SimpleException, TooLargeFileException, MissingResourceException, ClassNotFoundException, InvalidContentTypeException, TooLargeBodyException, LargeImageException { int i = req.getContentLength(); if(i > max_request) throw new TooLargeBodyException(i, max_request); if(!req.getContentType().toLowerCase().startsWith("multipart/form-data")) throw new SimpleException("Not the Multipart request!"); int j = max_file; HashMap hm = new HashMap(); HashMap hm1 = new HashMap(); HashMap hm2 = new HashMap(); HashMap hm3 = new HashMap(); HttpPostDataSource hpds = new HttpPostDataSource(req); MimeMultipart mmp = new MimeMultipart(hpds); int k = mmp.getCount(); for(int l = 0; l < k; l++) { printDebug("Start to parse the " + (l + 1) + "th MimeBodyPart..."); javax.mail.BodyPart bp = mmp.getBodyPart(l); if(bp instanceof MimeBodyPart) { MimeBodyPart mbp = (MimeBodyPart)bp; parseBodyGetCont(mbp, j, hm, hm1, hm2, hm3, set); } else { throw new SimpleException("Not MimeBodyPart!"); } } String s1 = s; if(s1 == null) s1 = charset; Object obj = hm.get("charset"); if(obj != null) { byte data0[][] = (byte[][])obj; byte data1[] = data0[0]; if(data1.length != 0) { s1 = new String(data1, "8859_1"); printDebug("Charset is found in the parameters. It is " + s1); } } String s2 = s1; HashMap hm4 = new HashMap(); Set set1 = hm.entrySet(); String s3; String as[]; for(Iterator iterator = set1.iterator(); iterator.hasNext(); hm4.put(s3, as)) { java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next(); s3 = (String)entry.getKey(); byte data2[][] = (byte[][])entry.getValue(); as = new String[data2.length]; for(int i1 = 0; i1 < data2.length; i1++) { byte data3[] = data2[i1]; as[i1] = new String(data3, s2); } } return new ParsedData(hm4, hm1, null, s2, hm2, hm3); } private void parseBodyGetCont(MimeBodyPart mbp, int i, Map map, Map map1, Map map2, Map map3, Set set) throws IOException, MessagingException, ParseException, SimpleException, TooLargeFileException, InvalidContentTypeException, LargeImageException { if(mbp.isMimeType("multipart/*")) throw new SimpleException("This MimeBodyPart is mime type of multipart/*."); String s = getKeyName(mbp); String s1 = getEncoding(mbp); int j = mbp.getSize(); if(j == 0) { printDebug("No value for " + s + ". (Size is 0)"); return; } if(!isFile(mbp)) { printDebug("Start to parse the text..."); byte data0[] = null; InputStream is = mbp.getInputStream(); if(s1 != null) is = MimeUtility.decode(is, s1); if(j >= 0) { data0 = new byte[j]; long l = is.read(data0); is.close(); if(l != (long)j) throw new SimpleException("Error reading stream!"); } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int k = 0; do { if(k == -1) break; byte data5[] = new byte[1]; k = is.read(data5); if(k != -1) baos.write(data5); } while(true); baos.flush(); baos.close(); is.close(); data0 = baos.toByteArray(); } if(map.containsKey(s)) { byte data1[][] = (byte[][])map.get(s); byte data4[][] = new byte[data1.length + 1][]; for(int j1 = 0; j1 < data1.length; j1++) data4[j1] = data1[j1]; data4[data1.length] = data0; map.put(s, data4); } else { byte data2[][] = new byte[1][]; data2[0] = data0; map.put(s, data2); } return; } printDebug("Start to parse file..."); String s2 = getFileName(mbp); String s3 = mime_map_dic.getMimeType(s2); if(set != null) { String s4 = s3.toLowerCase(); s4 = s4.trim(); if(!set.contains(s4)) { int i1 = s4.indexOf("; name="); if(i1 >= 0) { String s5 = s4.substring(0, i1); if(!set.contains(s5)) throw new InvalidContentTypeException(s2, s5, set); s3 = s5; } else { throw new InvalidContentTypeException(s2, s4, set); } } } if(j >= 0 && i > 0 && j > i) throw new TooLargeFileException(s2, j, i); byte data3[] = null; InputStream is1 = mbp.getInputStream(); if(s1 != null) is1 = MimeUtility.decode(is1, s1); if(j >= 0) { data3 = new byte[j]; long l1 = is1.read(data3); is1.close(); if(l1 != (long)j) throw new SimpleException("Error reading stream!"); } else { ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); int k1 = 0; int i2 = 0; while(k1 != -1) { byte data6[] = new byte[1]; k1 = is1.read(data6); if(k1 != -1) { baos1.write(data6); i2++; if(i > 0 && i2 > i) { baos1.flush(); baos1.close(); is1.close(); throw new TooLargeFileException(s2, i2, i); } } } baos1.flush(); baos1.close(); is1.close(); data3 = baos1.toByteArray(); } if(set != null) if(checkSize) { if(sizeChecker.shouldCheck(s3)) sizeChecker.checkImageSize(data3, s3, s2, max_width, max_height); else if(checkBinary && !binChecker.checkBinary(s3, data3)) throw new CorruptedBinaryContentsException(s2, s3); } else if(checkBinary && !binChecker.checkBinary(s3, data3)) throw new CorruptedBinaryContentsException(s2, s3); map2.put(s, s3); map1.put(s, data3); map3.put(s, s2); } private String getKeyName(MimeBodyPart mbp) throws MessagingException, ParseException { String as[] = mbp.getHeader("Content-Disposition"); String s = null; int i = as[0].indexOf(" name="); if(i != -1) { int j = as[0].indexOf(";", i + 6); if(j == -1) s = as[0].substring(i + 6); else s = as[0].substring(i + 6, j); } else { return null; } s = s.trim(); if(s.charAt(0) == '"') { int k = s.length(); s = s.substring(1, k - 1); } return s; } private String getEncoding(MimeBodyPart mbp) throws MessagingException, ParseException { String as[] = mbp.getHeader("Content-Transfer-Encoding"); if(as == null) return null; else return as[0]; } private boolean isFile(MimeBodyPart mbp) throws MessagingException, ParseException { String as[] = mbp.getHeader("Content-Disposition"); int i = as[0].indexOf("filename="); return i != -1; } private String getFileName(MimeBodyPart mbp) throws MessagingException, ParseException { String as[]; as = mbp.getHeader("Content-Disposition"); Object obj = null; String s; int i = as[0].indexOf("filename="); if(i != -1) { int j = as[0].indexOf(";", i + 9); if(j == -1) s = as[0].substring(i + 9); else s = as[0].substring(i + 5, j); break MISSING_BLOCK_LABEL_79; } return null; int k; s = s.trim(); k = s.length(); if(k == 0) return null; try { s = s.substring(1, k - 1); int l = s.lastIndexOf("\\"); if(l == -1) l = s.lastIndexOf("/"); if(l != -1) s = s.substring(l + 1); } catch(Exception e) { return null; } return s; } public ParsedData parseAndSave(HttpServletRequest req, String s, int i) throws SimpleException, TooLargeFileException, NestedException, TooLargeBodyException { checkTrial(); checkSaveFile(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); else return parseAndSave(req, null, s, i); } public ParsedData parseAndSave(HttpServletRequest req, String s) throws SimpleException, TooLargeFileException, NestedException, TooLargeBodyException { checkTrial(); checkSaveFile(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); else return parseAndSave(req, null, s); } public ParsedData parseAndSave(HttpServletRequest req, String s, int i, Set set) throws SimpleException, TooLargeFileException, InvalidContentTypeException, NestedException, TooLargeBodyException, LargeImageException { checkTrial(); checkSaveFile(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); else return parseAndSave(req, null, s, i, set); } public ParsedData parseAndSave(HttpServletRequest req, String s, Set set) throws SimpleException, TooLargeFileException, InvalidContentTypeException, NestedException, TooLargeBodyException, LargeImageException { checkTrial(); checkSaveFile(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); else return parseAndSave(req, null, s, set); } public ParsedData parseOnly(HttpServletRequest req, int i) throws SimpleException, TooLargeFileException, NestedException, TooLargeBodyException { checkTrial(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); else return parseOnly(req, ((String) (null)), i); } public ParsedData parseOnly(HttpServletRequest req) throws SimpleException, TooLargeFileException, NestedException, TooLargeBodyException { checkTrial(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); else return parseOnly(req, DUMMY_STR); } public ParsedData parseOnly(HttpServletRequest req, int i, Set set) throws SimpleException, TooLargeFileException, InvalidContentTypeException, NestedException, TooLargeBodyException, LargeImageException { checkTrial(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); else return parseOnly(req, null, i, set); } public ParsedData parseOnly(HttpServletRequest req, Set set) throws SimpleException, TooLargeFileException, InvalidContentTypeException, NestedException, TooLargeBodyException, LargeImageException { checkTrial(); if(req.getMethod().equalsIgnoreCase("GET")) throw new GetRequestException(); else return parseOnly(req, ((String) (null)), set); } private void checkTrial() { if(System.currentTimeMillis() > start + 0x36ee80L) throw new TrialTimeExpiredException(); else return; } private void checkSaveFile() throws SimpleException { if(!save_file) throw new SimpleException("\"save_file\" is set to false in MimeParser.properties"); else return; } private static final long TRIAL = 0x36ee80L; private static long start = 0L; private static final boolean VERIFY = false; private static final String PASS = "rk83n62e"; private static final String PING = "http://voyager.oop-reserch.com/ping.html"; private static final String APPNAME = "mimetry"; private static final String VERIFY_URL = "http://voyager.oop-reserch.com/esd21/UserVerify"; private static final String IP_ADDRESS = "207.228.236.14"; private static final String ENCODING_MULTIPART = "multipart/form-data"; private static final String RESOURCE = "MimeParser"; private static final String MAX_REQUEST = "max_request"; private static final String MAX_FILE = "max_file"; private static final String FILE_ROOT = "file_root"; private static final String CHARSET = "charset"; private static final String USR = "user"; private static final String CHECK_BIN = "checkBinary"; private static final String SAVE_FILE = "save_file"; private static int max_request = 0x100000; private static int max_file = 0; private static String file_root = null; private static String charset = null; private static boolean checkBinary = false; private static BinaryCheckerDic binChecker = null; private static final MimeParser mp = new MimeParser(); private static boolean isPrepared = false; private static boolean isDebug = false; private static boolean checkSize = false; private static ImageSizeChecker sizeChecker = null; private static final String MAX_WIDTH = "max_width"; private static final String MAX_HEIGHT = "max_height"; private static int max_width = 0; private static int max_height = 0; private static final String DEBUG = "isDebug"; private static final String DUMMY_STR = null; private static MimeMapDic mime_map_dic = null; private static boolean save_file = false; } Jack -- "You can lead a horse to water but you cannot make it float on its back." ~Dakota Jack~ "You can't wake a person who is pretending to be asleep." ~Native Proverb~ "Each man is good in His sight. It is not necessary for eagles to be crows." ~Hunkesni (Sitting Bull), Hunkpapa Sioux~ ----------------------------------------------- "This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation." --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org