Changeset 37437da3


Ignore:
Timestamp:
Aug 20, 2009 10:22:07 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
cdc184c
Parents:
6d3a585
Message:
  • I2CP: Fix the SessionConfig? serializer in DataHelper?, so that UTF-8 tunnel names are not corrupted by I2CP and can be displayed on the console
  • Fix UTF-8 form submission on console and i2ptunnel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/jsp/edit.jsp

    r6d3a585 r37437da3  
     1<%@page pageEncoding="UTF-8"%>
    12<%@page contentType="text/html" import="net.i2p.i2ptunnel.web.EditBean" %><%
    23String tun = request.getParameter("tunnel");
  • apps/i2ptunnel/jsp/index.jsp

    r6d3a585 r37437da3  
     1<%
     2    // http://www.crazysquirrel.com/computing/general/form-encoding.jspx
     3    if (request.getCharacterEncoding() == null)
     4        request.setCharacterEncoding("UTF-8");
     5%>
     6<%@page pageEncoding="UTF-8"%>
    17<%@page contentType="text/html" import="net.i2p.i2ptunnel.web.IndexBean"%><?xml version="1.0" encoding="UTF-8"?>
    28<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     
    713    <title>I2P Tunnel Manager - List</title>
    814   
    9     <meta htt
    10 p-equiv="Content-Type" content="text/html; charset=UTF-8" />
     15    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    1116    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
     17    <link href="/themes/console/images/favicon.ico" type="image/x-icon" rel="shortcut icon" />
    1218   
    1319    <% if (indexBean.allowCSS()) {
    14   %><link href="/themes/console/images/favicon.ico" type="image/x-icon" rel="shortcut icon" />
    15     <link href="<%=indexBean.getTheme()%>default.css" rel="stylesheet" type="text/css" />
     20  %><link href="<%=indexBean.getTheme()%>default.css" rel="stylesheet" type="text/css" />
    1621    <link href="<%=indexBean.getTheme()%>i2ptunnel.css" rel="stylesheet" type="text/css" />
    1722    <% }
  • apps/routerconsole/jsp/css.jsp

    r6d3a585 r37437da3  
    66    * This is included almost 30 times, so keep whitespace etc. to a minimum.
    77    */
     8
     9   // http://www.crazysquirrel.com/computing/general/form-encoding.jspx
     10   if (request.getCharacterEncoding() == null)
     11       request.setCharacterEncoding("UTF-8");
    812
    913   response.setHeader("Pragma", "no-cache");
  • core/java/src/net/i2p/data/DataHelper.java

    r6d3a585 r37437da3  
    106106    public static void writeProperties(OutputStream rawStream, Properties props)
    107107            throws DataFormatException, IOException {
     108        writeProperties(rawStream, props, false);
     109    }
     110
     111    /**
     112     * jrandom disabled UTF-8 in mid-2004, for performance reasons,
     113     * i.e. slow foo.getBytes("UTF-8")
     114     * Re-enable it so we can pass UTF-8 tunnel names through the I2CP SessionConfig.
     115     *
     116     * Use utf8 = false for RouterAddress (fast, non UTF-8)
     117     * Use utf8 = true for SessionConfig (slow, UTF-8)
     118     */
     119    public static void writeProperties(OutputStream rawStream, Properties props, boolean utf8)
     120            throws DataFormatException, IOException {
    108121        if (props != null) {
    109122            OrderedProperties p = new OrderedProperties();
     
    113126                String key = (String) iter.next();
    114127                String val = p.getProperty(key);
    115                 // now make sure they're in UTF-8
    116                 //key = new String(key.getBytes(), "UTF-8");
    117                 //val = new String(val.getBytes(), "UTF-8");
    118                 writeString(baos, key);
     128                if (utf8)
     129                    writeStringUTF8(baos, key);
     130                else
     131                    writeString(baos, key);
    119132                baos.write(_equalBytes);
    120                 writeString(baos, val);
     133                if (utf8)
     134                    writeStringUTF8(baos, val);
     135                else
     136                    writeString(baos, val);
    121137                baos.write(_semicolonBytes);
    122138            }
     
    487503     * A string is 1 or more bytes where the first byte is the number of bytes (not characters!)
    488504     * in the string and the remaining 0-255 bytes are the non-null terminated UTF-8 encoded character array.
     505     *
    489506     * @param in stream to read from
    490507     * @throws DataFormatException if the stream doesn't contain a validly formatted string
     
    497514        int read = read(in, raw);
    498515        if (read != size) throw new DataFormatException("Not enough bytes to read the string");
    499         return new String(raw);
     516        // the following constructor throws an UnsupportedEncodingException which is an IOException,
     517        // but that's only if UTF-8 is not supported. Other encoding errors are not thrown.
     518        return new String(raw, "UTF-8");
    500519    }
    501520
    502521    /** Write out a string to the stream as specified by the I2P data structure spec.  Note that the max
    503522     * size for a string allowed by the spec is 255 bytes.
     523     *
     524     * WARNING - this method destroys the encoding
    504525     *
    505526     * @param out stream to write string
     
    521542            for (int i = 0; i < len; i++)
    522543                out.write((byte)(string.charAt(i) & 0xFF));
     544        }
     545    }
     546
     547    /** Write out a string to the stream as specified by the I2P data structure spec.  Note that the max
     548     * size for a string allowed by the spec is 255 bytes.
     549     *
     550     * This method correctly uses UTF-8
     551     *
     552     * @param out stream to write string
     553     * @param string UTF-8 string to write out: null strings are perfectly valid, but strings of excess length will
     554     *               cause a DataFormatException to be thrown
     555     * @throws DataFormatException if the string is not valid
     556     * @throws IOException if there is an IO error writing the string
     557     */
     558    private static void writeStringUTF8(OutputStream out, String string)
     559        throws DataFormatException, IOException {
     560        if (string == null) {
     561            writeLong(out, 1, 0);
     562        } else {
     563            // the following method throws an UnsupportedEncodingException which is an IOException,
     564            // but that's only if UTF-8 is not supported. Other encoding errors are not thrown.
     565            byte[] raw = string.getBytes("UTF-8");
     566            int len = raw.length;
     567            if (len > 255)
     568                throw new DataFormatException("The I2P data spec limits strings to 255 bytes or less, but this is "
     569                                              + string.length() + " [" + string + "]");
     570            writeLong(out, 1, len);
     571            out.write(raw);
    523572        }
    524573    }
  • core/java/src/net/i2p/data/i2cp/SessionConfig.java

    r6d3a585 r37437da3  
    174174            _log.debug("SigningKey size for destination: " + _destination.getSigningPublicKey().getData().length);
    175175            _destination.writeBytes(out);
    176             DataHelper.writeProperties(out, _options);
     176            DataHelper.writeProperties(out, _options, true);  // UTF-8
    177177            DataHelper.writeDate(out, _creationDate);
    178178        } catch (IOException ioe) {
     
    199199            throw new DataFormatException("Not enough data to create the session config");
    200200        _destination.writeBytes(out);
    201         DataHelper.writeProperties(out, _options);
     201        DataHelper.writeProperties(out, _options, true);  // UTF-8
    202202        DataHelper.writeDate(out, _creationDate);
    203203        _signature.writeBytes(out);
Note: See TracChangeset for help on using the changeset viewer.