Search in sources :

Example 1 with DataCodingScheme

use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.

the class TxSmppServerSbb method createSmsEvent.

// *********
// General Sms creating and processing methods
protected Sms createSmsEvent(BaseSm event, Esme origEsme, TargetAddress ta, PersistenceRAInterface store) throws SmscProcessingException {
    Sms sms = new Sms();
    sms.setDbId(UUID.randomUUID());
    sms.setOriginationType(OriginationType.SMPP);
    // checking parameters first
    if (event.getSourceAddress() == null || event.getSourceAddress().getAddress() == null || event.getSourceAddress().getAddress().isEmpty()) {
        throw new SmscProcessingException("SourceAddress digits are absent", SmppConstants.STATUS_INVSRCADR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_SRC_ADDR_INVALID);
    }
    sms.setSourceAddr(event.getSourceAddress().getAddress());
    sms.setSourceAddrTon(event.getSourceAddress().getTon());
    sms.setSourceAddrNpi(event.getSourceAddress().getNpi());
    sms.setOrigNetworkId(origEsme.getNetworkId());
    int dcs = event.getDataCoding();
    String err = MessageUtil.checkDataCodingSchemeSupport(dcs);
    if (err != null) {
        throw new SmscProcessingException("TxSmpp DataCoding scheme does not supported: " + dcs + " - " + err, SmppExtraConstants.ESME_RINVDCS, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_DATA_CODING_INVALID);
    }
    // storing additional parameters
    ArrayList<Tlv> optionalParameters = event.getOptionalParameters();
    if (optionalParameters != null && optionalParameters.size() > 0) {
        for (Tlv tlv : optionalParameters) {
            if (tlv.getTag() != SmppConstants.TAG_MESSAGE_PAYLOAD) {
                sms.getTlvSet().addOptionalParameter(tlv);
            }
        }
    }
    DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dcs);
    sms.setDataCoding(dcs);
    sms.setOrigSystemId(origEsme.getSystemId());
    sms.setOrigEsmeName(origEsme.getName());
    sms.setSubmitDate(new Timestamp(System.currentTimeMillis()));
    sms.setServiceType(event.getServiceType());
    sms.setEsmClass(event.getEsmClass());
    sms.setProtocolId(event.getProtocolId());
    sms.setPriority(event.getPriority());
    sms.setRegisteredDelivery(event.getRegisteredDelivery());
    sms.setReplaceIfPresent(event.getReplaceIfPresent());
    sms.setDefaultMsgId(event.getDefaultMsgId());
    boolean udhPresent = (event.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0;
    Tlv sarMsgRefNum = event.getOptionalParameter(SmppConstants.TAG_SAR_MSG_REF_NUM);
    Tlv sarTotalSegments = event.getOptionalParameter(SmppConstants.TAG_SAR_TOTAL_SEGMENTS);
    Tlv sarSegmentSeqnum = event.getOptionalParameter(SmppConstants.TAG_SAR_SEGMENT_SEQNUM);
    boolean segmentTlvFlag = (sarMsgRefNum != null && sarTotalSegments != null && sarSegmentSeqnum != null);
    // short message data
    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];
    }
    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);
        }
    }
    msg = parseShortMessageText(event);
    sms.setShortMessageText(msg);
    sms.setShortMessageBin(udhData);
    // checking of min / max length
    if (origEsme.getMinMessageLength() >= 0 && msg.length() < origEsme.getMinMessageLength()) {
        SmscProcessingException e = new SmscProcessingException("Message length is less than a min length limit for ESME=" + origEsme.getName() + ", len=" + msg.length(), SmppConstants.STATUS_INVMSGLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_SHORT);
        e.setSkipErrorLogging(true);
        throw e;
    }
    if (origEsme.getMaxMessageLength() >= 0 && msg.length() > origEsme.getMaxMessageLength()) {
        SmscProcessingException e = new SmscProcessingException("Message length is more than a max length limit for ESME=" + origEsme.getName() + ", len=" + msg.length(), SmppConstants.STATUS_INVMSGLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_LONG);
        e.setSkipErrorLogging(true);
        throw e;
    }
    // checking max message length
    if (udhPresent || segmentTlvFlag) {
        // here splitting by SMSC is not supported
        UserDataHeader udh = null;
        int lenSolid = MessageUtil.getMaxSolidMessageBytesLength();
        if (udhPresent) {
            udh = new UserDataHeaderImpl(udhData);
        } else {
            udh = createNationalLanguageUdh(origEsme, dataCodingScheme);
            if (udh != null && udh.getNationalLanguageLockingShift() != null) {
                lenSolid -= 3;
                sms.setNationalLanguageLockingShift(udh.getNationalLanguageLockingShift().getNationalLanguageIdentifier().getCode());
            }
            if (udh != null && udh.getNationalLanguageSingleShift() != null) {
                lenSolid -= 3;
                sms.setNationalLanguageSingleShift(udh.getNationalLanguageSingleShift().getNationalLanguageIdentifier().getCode());
            }
        }
        int messageLen = MessageUtil.getMessageLengthInBytes(dataCodingScheme, msg, udh);
        if (udhData != null)
            lenSolid -= udhData.length;
        if (messageLen > lenSolid) {
            throw new SmscProcessingException("Message length in bytes is too big for solid message: " + messageLen + ">" + lenSolid, SmppConstants.STATUS_INVPARLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_LONG);
        }
    } else {
        // here splitting by SMSC is supported
        int lenSegmented = MessageUtil.getMaxSegmentedMessageBytesLength();
        UserDataHeader udh = createNationalLanguageUdh(origEsme, dataCodingScheme);
        if (msg.length() * 2 > (lenSegmented - 6) * 255) {
            // firstly draft length check
            int messageLen = MessageUtil.getMessageLengthInBytes(dataCodingScheme, msg, udh);
            if (udh != null) {
                if (udh.getNationalLanguageLockingShift() != null) {
                    lenSegmented -= 3;
                    sms.setNationalLanguageLockingShift(udh.getNationalLanguageLockingShift().getNationalLanguageIdentifier().getCode());
                }
                if (udh.getNationalLanguageSingleShift() != null) {
                    lenSegmented -= 3;
                    sms.setNationalLanguageSingleShift(udh.getNationalLanguageSingleShift().getNationalLanguageIdentifier().getCode());
                }
            }
            if (messageLen > lenSegmented * 255) {
                throw new SmscProcessingException("Message length in bytes is too big for segmented message: " + messageLen + ">" + lenSegmented, SmppConstants.STATUS_INVPARLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_LONG);
            }
        } else {
            if (udh != null) {
                if (udh.getNationalLanguageLockingShift() != null) {
                    sms.setNationalLanguageLockingShift(udh.getNationalLanguageLockingShift().getNationalLanguageIdentifier().getCode());
                }
                if (udh.getNationalLanguageSingleShift() != null) {
                    sms.setNationalLanguageSingleShift(udh.getNationalLanguageSingleShift().getNationalLanguageIdentifier().getCode());
                }
            }
        }
    }
    // ValidityPeriod processing
    Tlv tlvQosTimeToLive = event.getOptionalParameter(SmppConstants.TAG_QOS_TIME_TO_LIVE);
    Date validityPeriod;
    if (tlvQosTimeToLive != null) {
        long valTime;
        try {
            valTime = (new Date()).getTime() + tlvQosTimeToLive.getValueAsInt();
        } catch (TlvConvertException e) {
            throw new SmscProcessingException("TlvConvertException when getting TAG_QOS_TIME_TO_LIVE tlv field: " + e.getMessage(), SmppConstants.STATUS_INVOPTPARAMVAL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_VALIDITY_PERIOD_PARSING);
        }
        validityPeriod = new Date(valTime);
    } else {
        try {
            validityPeriod = MessageUtil.parseSmppDate(event.getValidityPeriod());
        } catch (ParseException e) {
            throw new SmscProcessingException("ParseException when parsing ValidityPeriod field: " + e.getMessage(), SmppConstants.STATUS_INVEXPIRY, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_VALIDITY_PERIOD_PARSING);
        }
    }
    MessageUtil.applyValidityPeriod(sms, validityPeriod, true, smscPropertiesManagement.getMaxValidityPeriodHours(), smscPropertiesManagement.getDefaultValidityPeriodHours());
    // ScheduleDeliveryTime processing
    Date scheduleDeliveryTime;
    try {
        scheduleDeliveryTime = MessageUtil.parseSmppDate(event.getScheduleDeliveryTime());
    } catch (ParseException e) {
        throw new SmscProcessingException("ParseException when parsing ScheduleDeliveryTime field: " + e.getMessage(), SmppConstants.STATUS_INVSCHED, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_SCHEDULER_DELIVERY_TIME_PARSING);
    }
    MessageUtil.applyScheduleDeliveryTime(sms, scheduleDeliveryTime);
    SmsSet smsSet;
    smsSet = new SmsSet();
    smsSet.setDestAddr(ta.getAddr());
    smsSet.setDestAddrNpi(ta.getAddrNpi());
    smsSet.setDestAddrTon(ta.getAddrTon());
    smsSet.setNetworkId(origEsme.getNetworkId());
    smsSet.addSms(sms);
    sms.setSmsSet(smsSet);
    long messageId = store.c2_getNextMessageId();
    SmscStatProvider.getInstance().setCurrentMessageId(messageId);
    sms.setMessageId(messageId);
    return sms;
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) TlvConvertException(com.cloudhopper.smpp.tlv.TlvConvertException) UserDataHeaderImpl(org.restcomm.protocols.ss7.map.smstpdu.UserDataHeaderImpl) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) Timestamp(java.sql.Timestamp) Date(java.util.Date) ParseException(java.text.ParseException) UserDataHeader(org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader) Tlv(com.cloudhopper.smpp.tlv.Tlv)

Example 2 with DataCodingScheme

use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.

the class TxSmppServerSbb method createNationalLanguageUdh.

private UserDataHeader createNationalLanguageUdh(Esme origEsme, DataCodingScheme dataCodingScheme) {
    UserDataHeader udh = null;
    int nationalLanguageSingleShift = 0;
    int nationalLanguageLockingShift = 0;
    if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7) {
        nationalLanguageSingleShift = origEsme.getNationalLanguageSingleShift();
        nationalLanguageLockingShift = origEsme.getNationalLanguageLockingShift();
        if (nationalLanguageSingleShift == -1)
            nationalLanguageSingleShift = smscPropertiesManagement.getNationalLanguageSingleShift();
        if (nationalLanguageLockingShift == -1)
            nationalLanguageLockingShift = smscPropertiesManagement.getNationalLanguageLockingShift();
    }
    return MessageUtil.getNationalLanguageIdentifierUdh(nationalLanguageLockingShift, nationalLanguageSingleShift);
}
Also used : UserDataHeader(org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)

Example 3 with DataCodingScheme

use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.

the class DBOperations method setSmsFields.

private void setSmsFields(Sms sms, long dueSlot, BoundStatement boundStatement, boolean archive, boolean shortMessageNewStringFormat, boolean addedCorrId, boolean addedNetworkId, boolean addedOrigNetworkId, boolean addedPacket1) throws PersistenceException {
    boundStatement.setUUID(Schema.COLUMN_ID, sms.getDbId());
    boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
    if (addedNetworkId) {
        boundStatement.setInt(Schema.COLUMN_NETWORK_ID, sms.getSmsSet().getNetworkId());
    }
    boundStatement.setLong(Schema.COLUMN_DUE_SLOT, dueSlot);
    boundStatement.setInt(Schema.COLUMN_IN_SYSTEM, IN_SYSTEM_UNSENT);
    boundStatement.setUUID(Schema.COLUMN_SMSC_UUID, emptyUuid);
    boundStatement.setString(Schema.COLUMN_ADDR_DST_DIGITS, sms.getSmsSet().getDestAddr());
    boundStatement.setInt(Schema.COLUMN_ADDR_DST_TON, sms.getSmsSet().getDestAddrTon());
    boundStatement.setInt(Schema.COLUMN_ADDR_DST_NPI, sms.getSmsSet().getDestAddrNpi());
    if (sms.getSourceAddr() != null) {
        boundStatement.setString(Schema.COLUMN_ADDR_SRC_DIGITS, sms.getSourceAddr());
    } else {
        boundStatement.setToNull(Schema.COLUMN_ADDR_SRC_DIGITS);
    }
    boundStatement.setInt(Schema.COLUMN_ADDR_SRC_TON, sms.getSourceAddrTon());
    boundStatement.setInt(Schema.COLUMN_ADDR_SRC_NPI, sms.getSourceAddrNpi());
    if (addedOrigNetworkId) {
        boundStatement.setInt(Schema.COLUMN_ORIG_NETWORK_ID, sms.getOrigNetworkId());
    }
    boundStatement.setInt(Schema.COLUMN_DUE_DELAY, sms.getSmsSet().getDueDelay());
    if (sms.getSmsSet().getStatus() != null)
        boundStatement.setInt(Schema.COLUMN_SM_STATUS, sms.getSmsSet().getStatus().getCode());
    else
        boundStatement.setToNull(Schema.COLUMN_SM_STATUS);
    boundStatement.setBool(Schema.COLUMN_ALERTING_SUPPORTED, sms.getSmsSet().isAlertingSupported());
    boundStatement.setLong(Schema.COLUMN_MESSAGE_ID, sms.getMessageId());
    boundStatement.setInt(Schema.COLUMN_MO_MESSAGE_REF, sms.getMoMessageRef());
    if (sms.getOrigEsmeName() != null) {
        boundStatement.setString(Schema.COLUMN_ORIG_ESME_NAME, sms.getOrigEsmeName());
    } else
        boundStatement.setToNull(Schema.COLUMN_ORIG_ESME_NAME);
    if (sms.getOrigSystemId() != null) {
        boundStatement.setString(Schema.COLUMN_ORIG_SYSTEM_ID, sms.getOrigSystemId());
    } else
        boundStatement.setToNull(Schema.COLUMN_ORIG_SYSTEM_ID);
    if (sms.getSubmitDate() != null) {
        setBoundStatementDate(boundStatement, Schema.COLUMN_SUBMIT_DATE, sms.getSubmitDate());
    } else
        boundStatement.setToNull(Schema.COLUMN_SUBMIT_DATE);
    if (sms.getDeliverDate() != null) {
        setBoundStatementDate(boundStatement, Schema.COLUMN_DELIVERY_DATE, sms.getDeliverDate());
    } else
        boundStatement.setToNull(Schema.COLUMN_DELIVERY_DATE);
    if (sms.getServiceType() != null) {
        boundStatement.setString(Schema.COLUMN_SERVICE_TYPE, sms.getServiceType());
    } else
        boundStatement.setToNull(Schema.COLUMN_SERVICE_TYPE);
    boundStatement.setInt(Schema.COLUMN_ESM_CLASS, sms.getEsmClass());
    boundStatement.setInt(Schema.COLUMN_PROTOCOL_ID, sms.getProtocolId());
    boundStatement.setInt(Schema.COLUMN_PRIORITY, sms.getPriority());
    boundStatement.setInt(Schema.COLUMN_REGISTERED_DELIVERY, sms.getRegisteredDelivery());
    boundStatement.setInt(Schema.COLUMN_REPLACE, sms.getReplaceIfPresent());
    boundStatement.setInt(Schema.COLUMN_DATA_CODING, sms.getDataCodingForDatabase());
    boundStatement.setInt(Schema.COLUMN_DEFAULT_MSG_ID, sms.getDefaultMsgId());
    if (shortMessageNewStringFormat) {
        if (sms.getShortMessageText() != null) {
            boundStatement.setString(Schema.COLUMN_MESSAGE_TEXT, sms.getShortMessageText());
        } else
            boundStatement.setToNull(Schema.COLUMN_MESSAGE_TEXT);
        if (sms.getShortMessageBin() != null) {
            boundStatement.setBytes(Schema.COLUMN_MESSAGE_BIN, ByteBuffer.wrap(sms.getShortMessageBin()));
        } else
            boundStatement.setToNull(Schema.COLUMN_MESSAGE_BIN);
        boundStatement.setToNull(Schema.COLUMN_MESSAGE);
    } else {
        // convert to an old format
        String msg = sms.getShortMessageText();
        byte[] udhData = sms.getShortMessageBin();
        byte[] textPart = null;
        DataCodingScheme dcs = new DataCodingSchemeImpl(sms.getDataCoding());
        switch(dcs.getCharacterSet()) {
            case GSM7:
                textPart = msg.getBytes();
                break;
            case UCS2:
                Charset ucs2Charset = Charset.forName("UTF-16BE");
                ByteBuffer bb = ucs2Charset.encode(msg);
                textPart = new byte[bb.limit()];
                bb.get(textPart);
                break;
            default:
                // we do not support this yet
                break;
        }
        byte[] data;
        if (textPart != null) {
            if (udhData != null) {
                data = new byte[textPart.length + udhData.length];
                System.arraycopy(udhData, 0, data, 0, udhData.length);
                System.arraycopy(textPart, 0, data, udhData.length, textPart.length);
            } else {
                data = textPart;
            }
        } else {
            if (udhData != null) {
                data = udhData;
            } else {
                data = new byte[0];
            }
        }
        boundStatement.setBytes(Schema.COLUMN_MESSAGE, ByteBuffer.wrap(data));
    }
    if (sms.getScheduleDeliveryTime() != null) {
        setBoundStatementDate(boundStatement, Schema.COLUMN_SCHEDULE_DELIVERY_TIME, sms.getScheduleDeliveryTime());
    } else
        boundStatement.setToNull(Schema.COLUMN_SCHEDULE_DELIVERY_TIME);
    if (sms.getValidityPeriod() != null) {
        setBoundStatementDate(boundStatement, Schema.COLUMN_VALIDITY_PERIOD, sms.getValidityPeriod());
    } else
        boundStatement.setToNull(Schema.COLUMN_VALIDITY_PERIOD);
    boundStatement.setInt(Schema.COLUMN_DELIVERY_COUNT, sms.getDeliveryCount());
    if (addedPacket1) {
        if (sms.getOriginatorSccpAddress() != null) {
            boundStatement.setString(Schema.COLUMN_ORIGINATOR_SCCP_ADDRESS, sms.getOriginatorSccpAddress());
        } else
            boundStatement.setToNull(Schema.COLUMN_ORIGINATOR_SCCP_ADDRESS);
        // TODO: extra columns for further usage
        boundStatement.setBool(Schema.COLUMN_STATUS_REPORT_REQUEST, sms.isStatusReportRequest());
        boundStatement.setInt(Schema.COLUMN_DELIVERY_ATTEMPT, sms.getDeliveryAttempt());
        if (sms.getUserData() != null) {
            boundStatement.setString(Schema.COLUMN_USER_DATA, sms.getUserData());
        } else
            boundStatement.setToNull(Schema.COLUMN_USER_DATA);
        String extraData = sms.getExtraData();
        if (extraData != null) {
            boundStatement.setString(Schema.COLUMN_EXTRA_DATA, extraData);
        } else
            boundStatement.setToNull(Schema.COLUMN_EXTRA_DATA);
        if (sms.getExtraData_2() != null) {
            boundStatement.setString(Schema.COLUMN_EXTRA_DATA_2, sms.getExtraData_2());
        } else
            boundStatement.setToNull(Schema.COLUMN_EXTRA_DATA_2);
        if (sms.getExtraData_3() != null) {
            boundStatement.setString(Schema.COLUMN_EXTRA_DATA_3, sms.getExtraData_3());
        } else
            boundStatement.setToNull(Schema.COLUMN_EXTRA_DATA_3);
        if (sms.getExtraData_4() != null) {
            boundStatement.setString(Schema.COLUMN_EXTRA_DATA_4, sms.getExtraData_4());
        } else
            boundStatement.setToNull(Schema.COLUMN_EXTRA_DATA_4);
    }
    if (sms.getTlvSet().getOptionalParameterCount() > 0) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLObjectWriter writer = XMLObjectWriter.newInstance(baos);
            writer.setIndentation("\t");
            writer.write(sms.getTlvSet(), TLV_SET, TlvSet.class);
            writer.close();
            byte[] rawData = baos.toByteArray();
            String serializedEvent = new String(rawData);
            boundStatement.setString(Schema.COLUMN_OPTIONAL_PARAMETERS, serializedEvent);
        } catch (XMLStreamException e) {
            String msg = "XMLStreamException when serializing optional parameters for '" + sms.getDbId() + "'!";
            throw new PersistenceException(msg, e);
        }
    } else {
        boundStatement.setToNull(Schema.COLUMN_OPTIONAL_PARAMETERS);
    }
    if (!archive) {
        if (addedCorrId) {
            boundStatement.setToNull(Schema.COLUMN_CORR_ID);
        }
        boundStatement.setToNull(Schema.COLUMN_IMSI);
        if (sms.getSmsSet().getCorrelationId() != null) {
            if (addedCorrId) {
                boundStatement.setString(Schema.COLUMN_CORR_ID, sms.getSmsSet().getCorrelationId());
            } else {
                boundStatement.setString(Schema.COLUMN_IMSI, sms.getSmsSet().getCorrelationId());
            }
        }
    } else {
        if (sms.getSmsSet().getLocationInfoWithLMSI() != null && sms.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber() != null) {
            boundStatement.setString(Schema.COLUMN_NNN_DIGITS, sms.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber().getAddress());
            boundStatement.setInt(Schema.COLUMN_NNN_AN, sms.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber().getAddressNature().getIndicator());
            boundStatement.setInt(Schema.COLUMN_NNN_NP, sms.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber().getNumberingPlan().getIndicator());
        } else {
            boundStatement.setToNull(Schema.COLUMN_NNN_DIGITS);
            boundStatement.setToNull(Schema.COLUMN_NNN_AN);
            boundStatement.setToNull(Schema.COLUMN_NNN_NP);
        }
        if (sms.getSmsSet().getType() != null) {
            boundStatement.setInt(Schema.COLUMN_SM_TYPE, sms.getSmsSet().getType().getCode());
        } else {
            boundStatement.setToNull(Schema.COLUMN_SM_TYPE);
        }
        if (addedCorrId) {
            boundStatement.setString(Schema.COLUMN_CORR_ID, sms.getSmsSet().getCorrelationId());
        }
        boundStatement.setString(Schema.COLUMN_IMSI, sms.getSmsSet().getImsi());
    }
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) XMLStreamException(javolution.xml.stream.XMLStreamException) Charset(java.nio.charset.Charset) XMLObjectWriter(javolution.xml.XMLObjectWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer)

Example 4 with DataCodingScheme

use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.

the class A2Text method testA3.

@Test
public void testA3() throws Exception {
    DataCodingScheme dcs = new DataCodingSchemeImpl(0xF1);
    String msg = "Welcome to [thiopien\nPrices in EUR\n\nLocal calls from 2.19/min\nIncoming calls 1.29/min\nCalls home from 1.99/min\n\nSMS from 1.29\nData from 19.99/mb\n\n--Lufth";
    UserDataHeader udh = new UserDataHeaderImpl();
    ConcatenatedShortMessagesIdentifierImpl udhe = new ConcatenatedShortMessagesIdentifierImpl(false, 227, 2, 1);
    udh.addInformationElement(udhe);
    int messageLen = MessageUtil.getMessageLengthInBytes(dcs, msg, udh);
    int i1 = 0;
    i1++;
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) ConcatenatedShortMessagesIdentifierImpl(org.restcomm.protocols.ss7.map.smstpdu.ConcatenatedShortMessagesIdentifierImpl) UserDataHeaderImpl(org.restcomm.protocols.ss7.map.smstpdu.UserDataHeaderImpl) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) UserDataHeader(org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader) Test(org.testng.annotations.Test)

Example 5 with DataCodingScheme

use of org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.

the class MessageUtil method calculateMsgParts.

public static int calculateMsgParts(String msg, DataCodingScheme dataCodingScheme, int nationalLanguageLockingShift, int nationalLanguageSingleShift) {
    int lenSolid = MessageUtil.getMaxSolidMessageCharsLength(dataCodingScheme);
    int lenSegmented = MessageUtil.getMaxSegmentedMessageCharsLength(dataCodingScheme);
    UserDataHeader udh = null;
    if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7 && (nationalLanguageLockingShift > 0 || nationalLanguageSingleShift > 0)) {
        udh = MessageUtil.getNationalLanguageIdentifierUdh(nationalLanguageLockingShift, nationalLanguageSingleShift);
        if (nationalLanguageLockingShift > 0) {
            lenSolid -= 3;
            lenSegmented -= 3;
        }
        if (nationalLanguageSingleShift > 0) {
            lenSolid -= 3;
            lenSegmented -= 3;
        }
    }
    int msgLenInChars = msg.length();
    if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7 && msgLenInChars * 2 > lenSolid) {
        // GSM7 data coding. We need to care if some characters occupy two char places
        msgLenInChars = UserDataImpl.checkEncodedDataLengthInChars(msg, udh);
    }
    if (msgLenInChars <= lenSolid) {
        return 1;
    } else {
        if (dataCodingScheme.getCharacterSet() == CharacterSet.GSM7) {
            String[] res = UserDataImpl.sliceString(msg, lenSegmented, udh);
            return res.length;
        } else {
            ArrayList<String> res = new ArrayList<String>();
            int segmCnt = (msg.length() - 1) / lenSegmented + 1;
            for (int i1 = 0; i1 < segmCnt; i1++) {
                if (i1 == segmCnt - 1) {
                    res.add(msg.substring(i1 * lenSegmented, msg.length()));
                } else {
                    res.add(msg.substring(i1 * lenSegmented, (i1 + 1) * lenSegmented));
                }
            }
            return res.size();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) UserDataHeader(org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)

Aggregations

DataCodingScheme (org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme)21 DataCodingSchemeImpl (org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)19 AddressString (org.restcomm.protocols.ss7.map.api.primitives.AddressString)18 ISDNAddressString (org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString)18 Sms (org.mobicents.smsc.library.Sms)17 Test (org.testng.annotations.Test)17 SmsSet (org.mobicents.smsc.library.SmsSet)16 SmsSignalInfo (org.restcomm.protocols.ss7.map.api.service.sms.SmsSignalInfo)16 UserDataHeader (org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)16 ArrayList (java.util.ArrayList)15 SM_RP_DA (org.restcomm.protocols.ss7.map.api.service.sms.SM_RP_DA)15 UserData (org.restcomm.protocols.ss7.map.api.smstpdu.UserData)15 MAPDialogSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy)14 MAPServiceSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy)14 ISDNAddressStringImpl (org.restcomm.protocols.ss7.map.primitives.ISDNAddressStringImpl)14 Date (java.util.Date)13 SM_RP_OA (org.restcomm.protocols.ss7.map.api.service.sms.SM_RP_OA)10 UUID (java.util.UUID)9 SmscPropertiesManagement (org.mobicents.smsc.domain.SmscPropertiesManagement)9 MAPTestEvent (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy.MAPTestEvent)9