diff options
author | Damian Minkov <damencho@jitsi.org> | 2015-05-18 18:19:47 +0300 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2015-05-18 18:32:53 +0300 |
commit | 8a18fc3d27ee90df35e37c59e84f16b3696200d9 (patch) | |
tree | d956b0906b78c36bde239206071723c4224024d4 /src/net/java/sip/communicator/impl | |
parent | 71e875d90c48c8c23bf38db50fd143f0268b7205 (diff) | |
download | jitsi-8a18fc3d27ee90df35e37c59e84f16b3696200d9.zip jitsi-8a18fc3d27ee90df35e37c59e84f16b3696200d9.tar.gz jitsi-8a18fc3d27ee90df35e37c59e84f16b3696200d9.tar.bz2 |
Changes custom headers to use headers list in order to avoid combining multiple headers in one sip message. Adds from.userID parameter that can be processed in custom headers.
Diffstat (limited to 'src/net/java/sip/communicator/impl')
3 files changed, 154 insertions, 51 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ConfigHeaders.java b/src/net/java/sip/communicator/impl/protocol/sip/ConfigHeaders.java index c24e0ca..97e0633 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/ConfigHeaders.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/ConfigHeaders.java @@ -147,23 +147,7 @@ public class ConfigHeaders headerValues.get(ACC_PROPERTY_CONFIG_HEADER_VALUE), request); - Header customHeader; - - // use the custom header for those custom headers that has - // multiple values, as the factory will switch on the header - // parser for standard headers and will produce multiple headers - // that ends with an error creating/sending the request - if(value.contains(",")) - { - customHeader = new CustomHeader(name, value); - } - else - { - customHeader = protocolProvider.getHeaderFactory() - .createHeader(name, value); - } - - request.setHeader(customHeader); + request.addHeader(new CustomHeaderList(name, value)); } catch(Exception e) { @@ -194,6 +178,32 @@ public class ConfigHeaders } } + if(value.indexOf("${from.userID}") != -1) + { + FromHeader fromHeader + = (FromHeader)request.getHeader(FromHeader.NAME); + + if(fromHeader != null) + { + URI fromURI = fromHeader.getAddress().getURI(); + String fromAddr = fromURI.toString(); + + // strips sip: or sips: + if(fromURI.isSipURI()) + { + fromAddr + = fromAddr.replaceFirst(fromURI.getScheme() + ":", ""); + } + + // take the userID part + int index = fromAddr.indexOf('@'); + if ( index > -1 ) + fromAddr = fromAddr.substring(0, index); + + value = value.replace("${from.userID}", fromAddr); + } + } + if(value.indexOf("${to.address}") != -1) { ToHeader toHeader = @@ -234,38 +244,4 @@ public class ConfigHeaders return value; } - - /** - * Custom header to instert. Custom name and value. - */ - private static class CustomHeader - extends SIPHeader - { - /** - * The header value. - */ - private String value; - - /** - * Constructs header. - * @param name header name - * @param value header value - */ - CustomHeader(String name, String value) - { - super(name); - this.value = value; - } - - /** - * Just the encoded body of the header. - * @param buffer the insert result - * @return the string encoded header body. - */ - @Override - protected StringBuilder encodeBody(StringBuilder buffer) - { - return value != null ? buffer.append(value) : buffer.append(""); - } - } } diff --git a/src/net/java/sip/communicator/impl/protocol/sip/CustomHeader.java b/src/net/java/sip/communicator/impl/protocol/sip/CustomHeader.java new file mode 100644 index 0000000..76c10f4 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/sip/CustomHeader.java @@ -0,0 +1,53 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.sip; + +import gov.nist.javax.sip.header.*; + +/** + * Custom header to insert. Custom name and value. + * + * @author Damian Minkov + */ +public class CustomHeader + extends SIPHeader +{ + /** + * The header value. + */ + private String value; + + /** + * Constructs header. + * @param name header name + * @param value header value + */ + public CustomHeader(String name, String value) + { + super(name); + this.value = value; + } + + /** + * Just the encoded body of the header. + * @param buffer the insert result + * @return the string encoded header body. + */ + @Override + protected StringBuilder encodeBody(StringBuilder buffer) + { + return value != null ? buffer.append(value) : buffer.append(""); + } + + /** + * Clones this object. + */ + public Object clone() + { + return new CustomHeader(headerName, value); + } +} diff --git a/src/net/java/sip/communicator/impl/protocol/sip/CustomHeaderList.java b/src/net/java/sip/communicator/impl/protocol/sip/CustomHeaderList.java new file mode 100644 index 0000000..b9f7940 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/sip/CustomHeaderList.java @@ -0,0 +1,74 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.sip; + +import gov.nist.javax.sip.header.*; + +import java.util.*; + +/** + * Custom header to insert. Custom name and value. + * + * @author Damian Minkov + */ +public class CustomHeaderList + extends SIPHeaderList +{ + /** + * Constructs header. + * @param name header name + * @param value header value + */ + public CustomHeaderList(String name, String value) + { + super(CustomHeader.class, name); + add(new CustomHeader(name, value)); + } + + /** + * Constructs header list by name. + * @param hName the name of the header. + */ + public CustomHeaderList(String hName) { + super( CustomHeader.class, hName); + } + + /** + * Constructs header list. + */ + public CustomHeaderList() { + super(CustomHeader.class,null); + } + + /** + * Clones this list. + * @return the cloned list. + */ + public Object clone() { + CustomHeaderList retval = new CustomHeaderList(headerName); + retval.clonehlist(this.hlist); + return retval; + } + + /** + * Encodes the headers every header on separate line. Skip combining of + * headers. + * @param buffer the current message. + * @return the message with added headers. + */ + @Override + public StringBuilder encode(StringBuilder buffer) + { + ListIterator<SIPHeader> li = hlist.listIterator(); + while (li.hasNext()) + { + li.next().encode(buffer); + } + + return buffer; + } +}
\ No newline at end of file |