Search in sources :

Example 1 with SmppEncoding

use of org.restcomm.smpp.SmppEncoding in project smscgateway by RestComm.

the class RxSmppServerSbb method recodeShortMessage.

protected byte[] recodeShortMessage(int dataCoding, String msg, byte[] udhPart) {
    DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dataCoding);
    byte[] textPart;
    if (msg != null) {
        if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM8) {
            textPart = msg.getBytes(isoCharset);
        } else {
            SmppEncoding enc;
            if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7) {
                enc = smscPropertiesManagement.getSmppEncodingForGsm7();
            } else {
                enc = smscPropertiesManagement.getSmppEncodingForUCS2();
            }
            if (enc == SmppEncoding.Utf8) {
                textPart = msg.getBytes(utf8Charset);
            } else if (enc == SmppEncoding.Unicode) {
                textPart = msg.getBytes(ucs2Charset);
            } else {
                GSMCharsetEncoder encoder = (GSMCharsetEncoder) gsm7Charset.newEncoder();
                encoder.setGSMCharsetEncodingData(new GSMCharsetEncodingData(Gsm7EncodingStyle.bit8_smpp_style, null));
                ByteBuffer bb = null;
                try {
                    bb = encoder.encode(CharBuffer.wrap(msg));
                } catch (CharacterCodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                textPart = new byte[bb.limit()];
                bb.get(textPart);
            }
        }
    } else {
        textPart = new byte[0];
    }
    if (udhPart == null) {
        return textPart;
    } else {
        byte[] res = new byte[textPart.length + udhPart.length];
        System.arraycopy(udhPart, 0, res, 0, udhPart.length);
        System.arraycopy(textPart, 0, res, udhPart.length, textPart.length);
        return res;
    }
}
Also used : DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) GSMCharsetEncoder(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncoder) SmppEncoding(org.restcomm.smpp.SmppEncoding) CharacterCodingException(java.nio.charset.CharacterCodingException) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer) GSMCharsetEncodingData(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncodingData)

Example 2 with SmppEncoding

use of org.restcomm.smpp.SmppEncoding in project smscgateway by RestComm.

the class TxSmppServerSbb method parseShortMessageText.

private String parseShortMessageText(BaseSm event) {
    byte[] data = event.getShortMessage();
    if (event.getShortMessageLength() == 0) {
        // Probably the message_payload Optional Parameter is being used
        Tlv messagePaylod = event.getOptionalParameter(SmppConstants.TAG_MESSAGE_PAYLOAD);
        if (messagePaylod != null) {
            data = messagePaylod.getValue();
        }
    }
    if (data == null) {
        data = new byte[0];
    }
    boolean udhPresent = (event.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0;
    byte[] udhData;
    byte[] textPart;
    String msg;
    udhData = null;
    textPart = data;
    if (udhPresent && data.length > 2) {
        // UDH exists
        int udhLen = (textPart[0] & 0xFF) + 1;
        if (udhLen <= textPart.length) {
            textPart = new byte[textPart.length - udhLen];
            udhData = new byte[udhLen];
            System.arraycopy(data, udhLen, textPart, 0, textPart.length);
            System.arraycopy(data, 0, udhData, 0, udhLen);
        }
    }
    DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(event.getDataCoding());
    if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM8) {
        msg = new String(textPart, isoCharset);
    } else {
        SmppEncoding enc;
        if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7) {
            enc = smscPropertiesManagement.getSmppEncodingForGsm7();
        } else {
            enc = smscPropertiesManagement.getSmppEncodingForUCS2();
        }
        switch(enc) {
            case Utf8:
            default:
                msg = new String(textPart, utf8Charset);
                break;
            case Unicode:
                msg = new String(textPart, ucs2Charset);
                break;
            case Gsm7:
                GSMCharsetDecoder decoder = (GSMCharsetDecoder) gsm7Charset.newDecoder();
                decoder.setGSMCharsetDecodingData(new GSMCharsetDecodingData(Gsm7EncodingStyle.bit8_smpp_style, Integer.MAX_VALUE, 0));
                ByteBuffer bb = ByteBuffer.wrap(textPart);
                CharBuffer bf = null;
                try {
                    bf = decoder.decode(bb);
                } catch (CharacterCodingException e) {
                // this can not be
                }
                msg = bf.toString();
                break;
        }
    }
    return msg;
}
Also used : DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) CharBuffer(java.nio.CharBuffer) SmppEncoding(org.restcomm.smpp.SmppEncoding) CharacterCodingException(java.nio.charset.CharacterCodingException) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer) GSMCharsetDecoder(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetDecoder) GSMCharsetDecodingData(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetDecodingData) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 3 with SmppEncoding

use of org.restcomm.smpp.SmppEncoding in project smscgateway by RestComm.

the class RxSipServerSbb method recodeShortMessage.

private byte[] recodeShortMessage(int dataCoding, String msg, byte[] udhPart) {
    DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dataCoding);
    byte[] textPart;
    if (msg != null) {
        if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM8) {
            textPart = msg.getBytes(isoCharset);
        } else {
            SmppEncoding enc;
            if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7) {
                enc = smscPropertiesManagement.getSmppEncodingForGsm7();
            } else {
                enc = smscPropertiesManagement.getSmppEncodingForUCS2();
            }
            if (enc == SmppEncoding.Utf8) {
                textPart = msg.getBytes(utf8Charset);
            } else if (enc == SmppEncoding.Unicode) {
                textPart = msg.getBytes(ucs2Charset);
            } else {
                GSMCharsetEncoder encoder = (GSMCharsetEncoder) gsm7Charset.newEncoder();
                encoder.setGSMCharsetEncodingData(new GSMCharsetEncodingData(Gsm7EncodingStyle.bit8_smpp_style, null));
                ByteBuffer bb = null;
                try {
                    bb = encoder.encode(CharBuffer.wrap(msg));
                } catch (CharacterCodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                textPart = new byte[bb.limit()];
                bb.get(textPart);
            }
        }
    } else {
        textPart = new byte[0];
    }
    return textPart;
}
Also used : DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) GSMCharsetEncoder(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncoder) SmppEncoding(org.restcomm.smpp.SmppEncoding) CharacterCodingException(java.nio.charset.CharacterCodingException) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer) GSMCharsetEncodingData(org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncodingData)

Aggregations

ByteBuffer (java.nio.ByteBuffer)3 CharacterCodingException (java.nio.charset.CharacterCodingException)3 DataCodingScheme (org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme)3 DataCodingSchemeImpl (org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)3 SmppEncoding (org.restcomm.smpp.SmppEncoding)3 GSMCharsetEncoder (org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncoder)2 GSMCharsetEncodingData (org.mobicents.protocols.ss7.map.datacoding.GSMCharsetEncodingData)2 Tlv (com.cloudhopper.smpp.tlv.Tlv)1 CharBuffer (java.nio.CharBuffer)1 GSMCharsetDecoder (org.mobicents.protocols.ss7.map.datacoding.GSMCharsetDecoder)1 GSMCharsetDecodingData (org.mobicents.protocols.ss7.map.datacoding.GSMCharsetDecodingData)1