diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-11-29 21:26:52 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-11-29 21:26:52 +0100 |
commit | 9671783d5bf7e2b8cf543b03b13fd292c2183614 (patch) | |
tree | 21ce9fd6ff1b22899c35ac60804123451d3c53d1 /src/main/java/de/pixart/messenger/utils/XmppUri.java | |
parent | 08b22e0461350b5a2a87cd6d14d8d657cdf15376 (diff) |
add support for body paramater in xmpp uri
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/XmppUri.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/XmppUri.java b/src/main/java/de/pixart/messenger/utils/XmppUri.java index 52d575feb..10fa0324b 100644 --- a/src/main/java/de/pixart/messenger/utils/XmppUri.java +++ b/src/main/java/de/pixart/messenger/utils/XmppUri.java @@ -17,6 +17,7 @@ public class XmppUri { protected boolean muc; protected String fingerprint; protected List<Fingerprint> fingerprints = new ArrayList<>(); + private String body; public static final String OMEMO_URI_PARAM = "omemo-sid-"; public static final String OTR_URI_PARAM = "otr-fingerprint"; @@ -60,13 +61,14 @@ public class XmppUri { muc = segments.size() > 1 && "j".equalsIgnoreCase(segments.get(0)); } else if ("xmpp".equalsIgnoreCase(scheme)) { // sample: xmpp:foo@bar.com - muc = "join".equalsIgnoreCase(uri.getQuery()); + muc = isMuc(uri.getQuery()); if (uri.getAuthority() != null) { jid = uri.getAuthority(); } else { jid = uri.getSchemeSpecificPart().split("\\?")[0]; } this.fingerprints = parseFingerprints(uri.getQuery()); + this.body = parseBody(uri.getQuery()); } else if ("imto".equalsIgnoreCase(scheme)) { // sample: imto://xmpp/foo@bar.com try { @@ -107,6 +109,30 @@ public class XmppUri { return fingerprints; } + protected String parseBody(String query) { + for(String pair : query == null ? new String[0] : query.split(";")) { + final String[] parts = pair.split("=",2); + if (parts.length == 2 && "body".equals(parts[0].toLowerCase(Locale.US))) { + try { + return URLDecoder.decode(parts[1],"UTF-8"); + } catch (UnsupportedEncodingException e) { + return null; + } + } + } + return null; + } + + protected boolean isMuc(String query) { + for(String pair : query == null ? new String[0] : query.split(";")) { + final String[] parts = pair.split("=",2); + if (parts.length == 1 && "join".equals(parts[0])) { + return true; + } + } + return false; + } + public Jid getJid() { try { return this.jid == null ? null : Jid.fromString(this.jid.toLowerCase()); @@ -115,6 +141,10 @@ public class XmppUri { } } + public String getBody() { + return body; + } + public List<Fingerprint> getFingerprints() { return this.fingerprints; } |