</login>
<login id="scclient-2" password="clientpwd-2"
institution="UWOLS" />
- <login id="lpl-sc" password="1234" institution="LPL" encoding="ascii" />
+ <login id="lpl-sc" password="1234" institution="LPL" />
<login id="lpl-sc-beacock" password="xyzzy" location_code="WORKSTATION5"
delimiter="|" error-detect="enabled" institution="LPL" />
</accounts>
timeout="600" client_location_code="true"
retries="3" />
<relais_extensions_to_msg24 enabled="false" />
+ <encoding>ascii</encoding>
</institution>
<institution id="LPL" implementation="ILS">
+ <encoding>UTF-8</encoding>
</institution>
</institutions>
</acsconfig>
use English;
use Exporter;
use Encode;
+use Unicode::Normalize;
use Sys::Syslog qw(syslog);
use POSIX qw(strftime);
sub write_msg {
my ($self, $msg, $file, $encoding) = @_;
- $msg = encode($encoding, $msg) if ($encoding);
+ if ($encoding) {
+ # Use nomalization form D, because some conversion blow up
+ # without it.
+ $msg = NFD($msg);
+ if ($encoding eq 'ascii') {
+ # Try to maintain a reasonable version of the content by
+ # stripping diacritics from the text, given that the SIP client
+ # wants just plain ASCII. This is the base requirement according
+ # to the SIP2 specification.
+
+ # Stripping the combining characters converts ""béè♁ts"
+ # into "bee?ts" instead of "b???ts" - better, eh?
+ $msg =~ s/\pM+//og;
+ }
+ $msg = encode($encoding, $msg);
+ } else {
+ # Send an UTF-8 string. This makes the length call, below
+ # succeed and fixes LP 1628995.
+ $msg = encode_utf8($msg);
+ }
if ($error_detection) {
if (defined($self->{seqno})) {
$server->{policy} = $server->{institution}->{policy};
$server->{account}->{location} = $sc_loc if $sc_loc;
# Set the encoding for responses messages.
- $server->{encoding} = $server->{account}->{encoding} || $server->{institution}->{implementation_config}->{encoding};
+ $server->{encoding} = $server->{account}->{encoding}
+ || $server->{institution}->{encoding}
+ || $server->{institution}->{implementation_config}->{encoding}
+ || 'ascii'; # Use ascii if not set. The spec expects this.
+ # We shouldn't be looking at the implementation config here, but
+ # that's where the encoding lived for the longest time. So, we
+ # look there in the interest of backward compatibility. That
+ # should be officially deprecated at some point, and that check
+ # removed.
syslog("LOG_INFO", "Successful login for '%s' of '%s'", $server->{account}->{id}, $inst);
#