When getting the SDP content of a SIP request or response, attempts (in CallPeerSipImpl for now) to correctly determine its charset instead of using the system one.

cusax-fix
Lyubomir Marinov 17 years ago
parent 9a0af16281
commit 5479640778

@ -388,6 +388,7 @@ public Contact getContact()
* web interface related to this peer or <tt>null</tt> if no such URL
* is available.
*/
@Override
public URL getCallInfoURL()
{
if (mediaHandler == null)
@ -403,6 +404,7 @@ public URL getCallInfoURL()
* @return <tt>true</tt> if an audio stream is being sent to this
* peer and it is currently mute; <tt>false</tt>, otherwise
*/
@Override
public boolean isMute()
{
return getMediaHandler().isMute();
@ -470,7 +472,7 @@ public void processReInvite(ServerTransaction serverTransaction)
ContentLengthHeader cl = invite.getContentLength();
if (cl != null && cl.getContentLength() > 0)
{
sdpOffer = new String(invite.getRawContent());
sdpOffer = SdpUtils.getContentAsString(invite);
}
Response response = null;
@ -698,6 +700,7 @@ public void processCancel(ServerTransaction serverTransaction)
*
* @param newMuteValue the new value of the mute property for this call peer
*/
@Override
public void setMute(boolean newMuteValue)
{
getMediaHandler().setMute(newMuteValue);
@ -732,7 +735,7 @@ public void processAck(ServerTransaction serverTransaction, Request ack)
try
{
getMediaHandler().processAnswer(
new String(ack.getRawContent()));
SdpUtils.getContentAsString(ack));
}
catch (Exception exc)
{
@ -784,7 +787,7 @@ public void processSessionProgress(ClientTransaction tran,
try
{
getMediaHandler().processAnswer(
new String(response.getRawContent()));
SdpUtils.getContentAsString(response));
}
catch (Exception exc)
{
@ -831,7 +834,8 @@ public void processInviteOK(ClientTransaction clientTransaction,
//Process SDP unless we've just had an answer in a 18X response
if (!CallPeerState.CONNECTING_WITH_EARLY_MEDIA.equals(getState()))
{
getMediaHandler().processAnswer(new String(ok.getRawContent()));
getMediaHandler()
.processAnswer(SdpUtils.getContentAsString(ok));
}
}
//at this point we have already sent our ack so in addition to logging
@ -1125,8 +1129,8 @@ public synchronized void answer()
ContentLengthHeader cl = invite.getContentLength();
if (cl != null && cl.getContentLength() > 0)
{
sdpOffer = new String(invite.getRawContent());
};
sdpOffer = SdpUtils.getContentAsString(invite);
}
String sdp;
// if the offer was in the invite create an sdp answer
@ -1400,6 +1404,7 @@ private CallPeerMediaHandler getMediaHandler()
* @param reason a reason phrase explaining the state (e.g. if newState
* indicates a failure) and that we pass to our predecessor.
*/
@Override
public void setState(CallPeerState newState, String reason)
{
super.setState(newState, reason);

@ -6,10 +6,12 @@
*/
package net.java.sip.communicator.impl.protocol.sip.sdp;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.sdp.*;
import javax.sip.header.ContentTypeHeader; // disambiguates MediaType
import net.java.sip.communicator.impl.protocol.sip.*;
import net.java.sip.communicator.service.neomedia.*;
@ -28,7 +30,7 @@ public class SdpUtils
/**
* Our class logger.
*/
private static Logger logger = Logger.getLogger(SdpUtils.class);
private static final Logger logger = Logger.getLogger(SdpUtils.class);
/**
* A reference to the currently valid SDP factory instance.
@ -318,7 +320,7 @@ public static List<MediaFormat> extractFormats(
MediaDescription mediaDesc,
DynamicPayloadTypeRegistry ptRegistry)
{
List<MediaFormat> mediaFmts = new ArrayList();
List<MediaFormat> mediaFmts = new ArrayList<MediaFormat>();
Vector<String> formatStrings = null;
try
@ -858,9 +860,9 @@ else if ( tokenCount == 4)
* @return one of the <tt>MediaDirection</tt> values indicating the
* direction of the media steam described by <tt>mediaDesc</tt>.
*/
@SuppressWarnings("unchecked")//legacy code from jain-sdp
public static MediaDirection getDirection( MediaDescription mediaDesc )
{
@SuppressWarnings("unchecked") // legacy code from jain-sdp
Vector<Attribute> attributes = mediaDesc.getAttributes(false);
//default
@ -1225,4 +1227,48 @@ public static Vector<MediaDescription> extractMediaDescriptions(
return remoteDescriptions;
}
/**
* Gets the content of the specified SIP <tt>Message</tt> in the form of a
* <tt>String</tt> value.
*
* @param message the SIP <tt>Message</tt> to get the content of
* @return a <tt>String</tt> value which represents the content of the
* specified SIP <tt>Message</tt>
*/
public static String getContentAsString(javax.sip.message.Message message)
{
byte[] rawContent = message.getRawContent();
/*
* If rawContent isn't in the default charset, its charset is in the
* Content-Type header.
*/
ContentTypeHeader contentTypeHeader
= (ContentTypeHeader) message.getHeader(ContentTypeHeader.NAME);
String charset = null;
if (contentTypeHeader != null)
charset = contentTypeHeader.getParameter("charset");
if (charset == null)
charset = "UTF-8"; // RFC 3261
try
{
return new String(rawContent, charset);
}
catch (UnsupportedEncodingException uee)
{
logger
.warn(
"SIP message with unsupported charset of its content",
uee);
/*
* We failed to do it the right way so just do what we used to do
* before.
*/
return new String(rawContent);
}
}
}

Loading…
Cancel
Save