changeset 557:c3d0eaf5460c

Fix PR1166: Embedded JNLP File is not supported in applet tag
author Saad Mohammad <smohammad@redhat.com>
date Tue, 13 Nov 2012 11:04:38 -0500
parents 19c14a4b76b4
children c61b2db7d32f
files ChangeLog NEWS configure.ac netx/net/sourceforge/jnlp/JNLPFile.java netx/net/sourceforge/jnlp/Parser.java netx/net/sourceforge/jnlp/PluginBridge.java
diffstat 6 files changed, 65 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Nov 13 10:55:19 2012 -0500
+++ b/ChangeLog	Tue Nov 13 11:04:38 2012 -0500
@@ -1,3 +1,18 @@
+2012-11-13  Saad Mohammad  <smohammad@redhat.com>
+
+	Fix PR1166: Embedded JNLP File is not supported in applet tag.
+	* configure.ac: Checks for sun.misc.BASE64Decoder.
+	* NEWS: Added entry for PR1166.
+	* netx/net/sourceforge/jnlp/JNLPFile.java (JNLPFile):
+	New constructor which accepts inputstream of jnlp file and a
+	specified codebase.
+	* netx/net/sourceforge/jnlp/Parser.java (Parser): If parsing of
+	codebase fails, it will overwrite the codebase with the one passed
+	in through parameters.
+	* netx/net/sourceforge/jnlp/PluginBridge.java:
+	(PluginBridge) Supports embedded jnlp file.
+	(decodeBase64String) Decodes Base64 strings to byte array.
+
 2012-11-13  Saad Mohammad  <smohammad@redhat.com>
 
 	Added unit tests for PR1166.
--- a/NEWS	Tue Nov 13 10:55:19 2012 -0500
+++ b/NEWS	Tue Nov 13 11:04:38 2012 -0500
@@ -18,6 +18,7 @@
   - PR1027: DownloadService is not supported by IcedTea-Web
 * Plugin
   - PR1106: Buffer overflow in plugin table-
+  - PR1166: Embedded JNLP File is not supported in applet tag
 * Common
   - PR1049: Extension jnlp's signed jar with the content of only META-INF/* is considered
   - PR955: regression: SweetHome3D fails to run
--- a/configure.ac	Tue Nov 13 10:55:19 2012 -0500
+++ b/configure.ac	Tue Nov 13 11:04:38 2012 -0500
@@ -77,6 +77,7 @@
 IT_CHECK_FOR_CLASS(SUN_NET_WWW_PROTOCOL_JAR_URLJARFILECALLBACK, [sun.net.www.protocol.jar.URLJarFileCallBack])
 IT_CHECK_FOR_CLASS(SUN_AWT_X11_XEMBEDDEDFRAME, [sun.awt.X11.XEmbeddedFrame])
 IT_CHECK_FOR_CLASS(SUN_MISC_REF, [sun.misc.Ref])
+IT_CHECK_FOR_CLASS(SUN_MISC_BASE64DECODER, [sun.misc.BASE64Decoder])
 IT_CHECK_FOR_CLASS(COM_SUN_JNDI_TOOLKIT_URL_URLUTIL, [com.sun.jndi.toolkit.url.UrlUtil])
 IT_CHECK_FOR_CLASS(SUN_APPLET_APPLETIMAGEREF, [sun.applet.AppletImageRef])
 IT_CHECK_FOR_APPLETVIEWERPANEL_HOLE
--- a/netx/net/sourceforge/jnlp/JNLPFile.java	Tue Nov 13 10:55:19 2012 -0500
+++ b/netx/net/sourceforge/jnlp/JNLPFile.java	Tue Nov 13 11:04:38 2012 -0500
@@ -251,7 +251,20 @@
      * @throws ParseException if the JNLP file was invalid
      */
     public JNLPFile(InputStream input, boolean strict) throws ParseException {
-        parse(Parser.getRootNode(input), strict, null, null);
+        this(input, null, strict);
+    }
+
+    /**
+     * Create a JNLPFile from an input stream.
+     *
+     * @param input input stream of JNLP file.
+     * @param codebase codebase to use if not specified in JNLP file..
+     * @param strict whether to enforce the spec rules
+     * @throws IOException if an IO exception occurred
+     * @throws ParseException if the JNLP file was invalid
+     */
+    public JNLPFile(InputStream input, URL codebase, boolean strict) throws ParseException {
+        parse(Parser.getRootNode(input), strict, null, codebase);
     }
 
     /**
--- a/netx/net/sourceforge/jnlp/Parser.java	Tue Nov 13 10:55:19 2012 -0500
+++ b/netx/net/sourceforge/jnlp/Parser.java	Tue Nov 13 11:04:38 2012 -0500
@@ -143,9 +143,16 @@
 
         // JNLP tag information
         this.spec = getVersion(root, "spec", "1.0+");
-        this.codebase = addSlash(getURL(root, "codebase", base));
-        if (this.codebase == null) // We only override it if it is not specified.
+
+        try {
+            this.codebase = addSlash(getURL(root, "codebase", base));
+        } catch (ParseException e) {
+            //If parsing fails, continue by overriding the codebase with the one passed in
+        }
+
+        if (this.codebase == null) // Codebase is overwritten if codebase was not specified in file or if parsing of it failed
             this.codebase = codebase;
+
         this.base = (this.codebase != null) ? this.codebase : base; // if codebase not specified use default codebase
         fileLocation = getURL(root, "href", this.base);
 
--- a/netx/net/sourceforge/jnlp/PluginBridge.java	Tue Nov 13 10:55:19 2012 -0500
+++ b/netx/net/sourceforge/jnlp/PluginBridge.java	Tue Nov 13 11:04:38 2012 -0500
@@ -22,7 +22,10 @@
 
 package net.sourceforge.jnlp;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 import java.net.MalformedURLException;
 import java.util.HashSet;
@@ -32,6 +35,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import sun.misc.BASE64Decoder;
+
 import net.sourceforge.jnlp.runtime.JNLPRuntime;
 
 /**
@@ -96,7 +101,18 @@
                 // Use codeBase as the context for the URL. If jnlp_href's
                 // value is a complete URL, it will replace codeBase's context.
                 URL jnlp = new URL(codeBase, atts.get("jnlp_href"));
-                JNLPFile jnlpFile = jnlpCreator.create(jnlp, null, false, JNLPRuntime.getDefaultUpdatePolicy(), codeBase);
+                JNLPFile jnlpFile = null;
+
+                if (atts.containsKey("jnlp_embedded")) {
+                    InputStream jnlpInputStream = new ByteArrayInputStream(decodeBase64String(atts.get("jnlp_embedded")));
+                    jnlpFile = new JNLPFile(jnlpInputStream, codeBase, false);
+                } else {
+                    jnlpFile = jnlpCreator.create(jnlp, null, false, JNLPRuntime.getDefaultUpdatePolicy(), codeBase);
+                }
+
+                if (jnlpFile.isApplet())
+                    main = jnlpFile.getApplet().getMainClass();
+
                 Map<String, String> jnlpParams = jnlpFile.getApplet().getParameters();
                 info = jnlpFile.info;
 
@@ -349,4 +365,12 @@
     public boolean isInstaller() {
         return false;
     }
+
+    /**
+     * Returns the decoded BASE64 string
+     */
+    static byte[] decodeBase64String(String encodedString) throws IOException {
+        BASE64Decoder base64 = new BASE64Decoder();
+        return base64.decodeBuffer(encodedString);
+    }
 }