Update Codabar style and disable it as its causing too many false positives
[zxing.git] / zxingorg / src / com / google / zxing / web / DecodeServlet.java
index 936155d..8419c7a 100644 (file)
@@ -90,8 +90,8 @@ public final class DecodeServlet extends HttpServlet {
 
   // No real reason to let people upload more than a 2MB image
   private static final long MAX_IMAGE_SIZE = 2000000L;
-  // No real reason to deal with more than maybe 2.5 megapixels
-  private static final int MAX_PIXELS = 1 << 16;
+  // No real reason to deal with more than maybe 2 megapixels
+  private static final int MAX_PIXELS = 1 << 21;
 
   private static final Logger log = Logger.getLogger(DecodeServlet.class.getName());
 
@@ -101,13 +101,15 @@ public final class DecodeServlet extends HttpServlet {
   static {
     HINTS = new Hashtable<DecodeHintType, Object>(5);
     HINTS.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
-    Collection<BarcodeFormat> possibleFormats = new Vector<BarcodeFormat>();
+    Collection<BarcodeFormat> possibleFormats = new Vector<BarcodeFormat>(17);
     possibleFormats.add(BarcodeFormat.UPC_A);
     possibleFormats.add(BarcodeFormat.UPC_E);
     possibleFormats.add(BarcodeFormat.EAN_8);
     possibleFormats.add(BarcodeFormat.EAN_13);
     possibleFormats.add(BarcodeFormat.CODE_39);
+    possibleFormats.add(BarcodeFormat.CODE_93);    
     possibleFormats.add(BarcodeFormat.CODE_128);
+    //possibleFormats.add(BarcodeFormat.CODABAR);
     possibleFormats.add(BarcodeFormat.ITF);
     possibleFormats.add(BarcodeFormat.RSS14);    
     possibleFormats.add(BarcodeFormat.QR_CODE);
@@ -145,6 +147,7 @@ public final class DecodeServlet extends HttpServlet {
       throws ServletException, IOException {
     String imageURIString = request.getParameter("u");
     if (imageURIString == null || imageURIString.length() == 0) {
+      log.fine("URI was empty");
       response.sendRedirect("badurl.jspx");
       return;
     }
@@ -159,6 +162,7 @@ public final class DecodeServlet extends HttpServlet {
     try {
       imageURI = new URI(imageURIString);
     } catch (URISyntaxException urise) {
+      log.fine("URI was not valid: " + imageURIString);
       response.sendRedirect("badurl.jspx");
       return;
     }
@@ -176,6 +180,7 @@ public final class DecodeServlet extends HttpServlet {
         getResponse = client.execute(getRequest);
       } catch (IllegalArgumentException iae) {
         // Thrown if hostname is bad or null
+        log.fine(iae.toString());
         getRequest.abort();
         response.sendRedirect("badurl.jspx");
         return;
@@ -185,16 +190,19 @@ public final class DecodeServlet extends HttpServlet {
         //  javax.net.ssl.SSLPeerUnverifiedException,
         //  org.apache.http.NoHttpResponseException,
         //  org.apache.http.client.ClientProtocolException,
+        log.fine(ioe.toString());
         getRequest.abort();
         response.sendRedirect("badurl.jspx");
         return;
       }
 
       if (getResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
+        log.fine("Unsuccessful return code: " + getResponse.getStatusLine().getStatusCode());
         response.sendRedirect("badurl.jspx");
         return;
       }
       if (!isSizeOK(getResponse)) {
+        log.fine("Too large");
         response.sendRedirect("badimage.jspx");
         return;
       }
@@ -220,6 +228,7 @@ public final class DecodeServlet extends HttpServlet {
           throws ServletException, IOException {
 
     if (!ServletFileUpload.isMultipartContent(request)) {
+      log.fine("File upload was not multipart");
       response.sendRedirect("badimage.jspx");
       return;
     }
@@ -240,12 +249,14 @@ public final class DecodeServlet extends HttpServlet {
               is.close();
             }
           } else {
+            log.fine("Too large");
             response.sendRedirect("badimage.jspx");
           }
           break;
         }
       }
     } catch (FileUploadException fue) {
+      log.fine(fue.toString());
       response.sendRedirect("badimage.jspx");
     }
 
@@ -258,21 +269,28 @@ public final class DecodeServlet extends HttpServlet {
     try {
       image = ImageIO.read(is);
     } catch (IOException ioe) {
+      log.fine(ioe.toString());
       // Includes javax.imageio.IIOException
       response.sendRedirect("badimage.jspx");
       return;
     } catch (CMMException cmme) {
+      log.fine(cmme.toString());
       // Have seen this in logs
       response.sendRedirect("badimage.jspx");
       return;
     } catch (IllegalArgumentException iae) {
+      log.fine(iae.toString());
       // Have seen this in logs for some JPEGs
       response.sendRedirect("badimage.jspx");
       return;
     }
-    if (image == null ||
-        image.getHeight() <= 1 || image.getWidth() >= 1 ||
+    if (image == null) {
+      response.sendRedirect("badimage.jspx");
+      return;      
+    }
+    if (image.getHeight() <= 1 || image.getWidth() <= 1 ||
         image.getHeight() * image.getWidth() > MAX_PIXELS) {
+      log.fine("Dimensions too large: " + image.getWidth() + 'x' + image.getHeight());        
       response.sendRedirect("badimage.jspx");
       return;
     }