Beispiel #1
0
        /// <summary> Called to create a DataSmResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="submitSm"></param>
        /// <param name="commandStatus"></param>
        /// <param name="messageId"></param>
        /// <returns> DataSmResp </returns>
        public static SubmitSmResp Create(DataCodings defaultEncoding, SubmitSm submitSm, CommandStatus commandStatus, string messageId)
        {
            if (submitSm.DestAddr == string.Empty || submitSm.DestAddr == null)
            {
                commandStatus = CommandStatus.ESME_RINVDSTADR;
            }

            return(new SubmitSmResp(defaultEncoding, commandStatus, submitSm.Sequence, messageId));
        }
Beispiel #2
0
        /// <summary> Called to create a DataSmResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="submitSm"></param>
        /// <param name="commandStatus"></param>
        /// <param name="messageId"></param>
        /// <returns> DataSmResp </returns>
        public static SubmitSmResp Create(DataCodings defaultEncoding, SubmitSm submitSm, CommandStatus commandStatus, string messageId)
        {
            if (submitSm.DestAddr == string.Empty || submitSm.DestAddr == null)
            {
                commandStatus = CommandStatus.ESME_RINVDSTADR;
            }

            return new SubmitSmResp(defaultEncoding, commandStatus, submitSm.Sequence, messageId);
        }
Beispiel #3
0
        /// <summary> Called to create a SubmitSm object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> SubmitSm </returns>
        public static SubmitSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            SubmitSm submitSm = new SubmitSm(defaultEncoding);

            try
            {
                int start_offset = offset;

                buf.ExtractHeader(submitSm, ref offset);

                submitSm.ServiceType = buf.ExtractCString(ref offset);
                submitSm.SourceTon = buf.ExtractByte(ref offset);
                submitSm.SourceNpi = buf.ExtractByte(ref offset);
                submitSm.SourceAddr = buf.ExtractCString(ref offset);
                submitSm.DestTon = buf.ExtractByte(ref offset);
                submitSm.DestNpi = buf.ExtractByte(ref offset);
                submitSm.DestAddr = buf.ExtractCString(ref offset);
                submitSm.EsmClass = buf.ExtractByte(ref offset);
                submitSm.ProtocolId = buf.ExtractByte(ref offset);
                submitSm.PriorityFlag = buf.ExtractByte(ref offset);
                submitSm.ScheduleDeliveryTime = buf.ExtractCString(ref offset);
                submitSm.ValidityPeriod = buf.ExtractCString(ref offset);
                submitSm.RegisteredDelivery = buf.ExtractByte(ref offset);
                submitSm.ReplaceIfPresent = buf.ExtractByte(ref offset);
                submitSm.DataCoding = (DataCodings) buf.ExtractByte(ref offset);
                submitSm.DefaultMsgId = buf.ExtractByte(ref offset);
                submitSm.ShortMessageLength = buf.ExtractByte(ref offset);

                if (submitSm.ShortMessageLength > 0)
                {
                    submitSm.UserDataBuffer = new SmppBuffer(defaultEncoding, buf.ExtractByteArray(ref offset, submitSm.ShortMessageLength));
                }

                while (offset - start_offset < submitSm.Length)
                {
                    submitSm.Optional.Add(buf.ExtractTLV(ref offset));
                }

                if (submitSm.ShortMessageLength == 0)
                {
                    if (submitSm.Optional != null && submitSm.Optional.Count > 0)
                    {
                        TLV tlv_payload = submitSm.Optional[OptionalTags.MessagePayload];
                        if (tlv_payload != null)
                        {
                            submitSm.UserDataBuffer = new SmppBuffer(defaultEncoding, tlv_payload.Value);
                        }

                        TLV tlv_globalSeq = submitSm.Optional[OptionalTags.SarMsgRefNum];
                        if (tlv_globalSeq != null)
                        {
                            submitSm.MessageReferenceNumber = SmppBuffer.BytesToShort(tlv_globalSeq.Value, 0);
                        }

                        TLV tlv_pocketsNumber = submitSm.Optional[OptionalTags.SarTotalSegments];
                        if (tlv_pocketsNumber != null)
                        {
                            submitSm.TotalSegments = tlv_pocketsNumber.Value[0];
                        }

                        TLV tlv_localSeq = submitSm.Optional[OptionalTags.SarSegmentSeqnum];
                        if (tlv_localSeq != null)
                        {
                            submitSm.SeqmentNumber = tlv_localSeq.Value[0];
                        }
                    }
                }

                if (submitSm.UserDataBuffer != null && submitSm.UserDataBuffer.Length > 0)
                {
                    bool hasUDHI = submitSm.MessageFeature == GSMSpecificFeatures.UDHI || submitSm.MessageFeature == GSMSpecificFeatures.UDHIandReplyPath;
                    submitSm.UserData = UserData.Create(submitSm.UserDataBuffer, hasUDHI);

                    if (submitSm.UserData.Headers.Count > 0)
                    {
                        UserDataHeader udh = submitSm.UserData.Headers[InformationElementIdentifiers.ConcatenatedShortMessages8bit];
                        if (udh != null)
                        {
                            submitSm.MessageReferenceNumber = udh.Data[0];
                            submitSm.TotalSegments = udh.Data[1];
                            submitSm.SeqmentNumber = udh.Data[2];
                        }

                        udh = submitSm.UserData.Headers[InformationElementIdentifiers.ConcatenatedShortMessage16bit];
                        if (udh != null)
                        {
                            submitSm.MessageReferenceNumber = SmppBuffer.BytesToShort(udh.Data, 0);
                            submitSm.TotalSegments = udh.Data[2];
                            submitSm.SeqmentNumber = udh.Data[3];
                        }
                    }
                }
                else
                {
                    submitSm.UserData = UserData.Create();
                }
            }

            catch
            {
                submitSm = null;
            }

            return submitSm;
        }
Beispiel #4
0
        /// <summary> Called to send the message </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="serviceType"></param>
        /// <param name="destinationTon"></param>
        /// <param name="destinationNpi"></param>
        /// <param name="submitDataCoding"></param>
        /// <param name="encodeDataCoding"></param>
        /// <param name="message"></param>
        /// <param name="submitSm"></param>
        /// <param name="submitSmResp"></param>
        /// <returns> 0 - Successful / 1 - Failed / 2 - Not Connected </returns>
        public int SendMessage(string phoneNumber, string serviceType, Ton destinationTon, Npi destinationNpi, DataCodings submitDataCoding, DataCodings encodeDataCoding, string message, out SubmitSm submitSm, out SubmitSmResp submitSmResp)
        {
            int retVal = 1;

            submitSm = null;
            submitSmResp = null;

            try
            {
                if (Client.Status != ConnectionStatus.Bound)
                {
                    WriteLog("ESMEConnection : SendMessage : Warning : Not Connected To The SMPP Server");

                    return 2;
                }

                // The message to send
                string sendMessage = null;

                // Do we need to cut the message down
                if (encodeDataCoding == DataCodings.UCS2)
                {
                    // UCS2 only supports 140 bytes
                    if (message.Length > 70)
                    {
                        WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : WARNING : Truncating UCS2 message to 70 characters.");

                        // The default is Unicode so truncate the message
                        sendMessage = message.Substring(0, 70);
                    }
                }
                else
                {
                    if (message.Length > 160)
                    {
                        WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : WARNING : Truncating Default message to 160 characters.");

                        sendMessage = message.Substring(0, 160);
                    }
                }

                // Prepare the message, I have made sure there is only ever one message
                // with the trunacting above
                submitSm = Client.PrepareSubmit(
                    SubmitMode.ShortMessage,
                    serviceType,
                    (byte) Ton.NetworkSpecific,
                    (byte) Npi.Unknown,
                    ShortLongCode,
                    (byte) destinationTon,
                    (byte) destinationNpi,
                    phoneNumber,
                    submitDataCoding,
                    encodeDataCoding,
                    (sendMessage == null) ? message : sendMessage);

                // Send the message
                submitSmResp = Client.Submit(submitSm);

                // Log the send call
                WriteLog("ESMEConnection : SendMessage : Send : Sequence[{0}] Phone[{1}] Status[{2}]", submitSmResp.Sequence, phoneNumber, submitSmResp.Status);

                // Was it successful
                if (submitSmResp.Status != CommandStatus.ESME_ROK)
                {
                    WriteLog("ESMEConnection : SendMessage : ERROR : Failed For Unknown Reason");

                    retVal = 1;
                }

                // Success
                retVal = 0;
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : ERROR : {0}", exception.ToString());

                retVal = 1;
            }

            return retVal;
        }
Beispiel #5
0
        /// <summary> Called to send the message </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="serviceType"></param>
        /// <param name="sourceTon"></param>
        /// <param name="sourceNpi"></param>
        /// <param name="submitDataCoding"></param>
        /// <param name="encodeDataCoding"></param>
        /// <param name="message"></param>
        /// <param name="submitSm"></param>
        /// <param name="submitSmResp"></param>
        /// <returns> 1 - Successful / 0 - Failed </returns>
        public int SendMessage(string phoneNumber, string serviceType, Ton sourceTon, Npi sourceNpi, DataCodings submitDataCoding, DataCodings encodeDataCoding, string message, out SubmitSm submitSm, out SubmitSmResp submitSmResp)
        {
            int retVal = 0;

            submitSm     = null;
            submitSmResp = null;

            try
            {
                // Capture the next transmitter connection
                ESMEConnection smppConnection = NextTransmitterConnection();

                if (smppConnection == null)
                {
                    WriteLog("ESMEManager : SendMessage : Warning : Not Bound To The SMPP Server");

                    return(2);
                }

                // Send the message
                retVal = smppConnection.SendMessage(phoneNumber, serviceType, sourceTon, sourceNpi, submitDataCoding, encodeDataCoding, message, out submitSm, out submitSmResp);
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEManager : SendMessage : ERROR : {0}", exception.ToString());
            }

            return(retVal);
        }
Beispiel #6
0
        /// <summary> Called to send the message </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="serviceType"></param>
        /// <param name="sourceTon"></param>
        /// <param name="sourceNpi"></param>
        /// <param name="submitDataCoding"></param>
        /// <param name="encodeDataCoding"></param>
        /// <param name="message"></param>
        /// <param name="submitSm"></param>
        /// <param name="submitSmResp"></param>
        /// <returns> 1 - Successful / 0 - Failed </returns>
        public int SendMessage(string phoneNumber, string serviceType, Ton sourceTon, Npi sourceNpi, DataCodings submitDataCoding, DataCodings encodeDataCoding, string message,  out SubmitSm submitSm, out SubmitSmResp submitSmResp)
        {
            int retVal = 0;

            submitSm = null;
            submitSmResp = null;

            try
            {
                // Capture the next transmitter connection
                ESMEConnection smppConnection = NextTransmitterConnection();

                if (smppConnection == null)
                {
                    WriteLog("ESMEManager : SendMessage : Warning : Not Bound To The SMPP Server");

                    return 2;
                }

                // Send the message
                retVal = smppConnection.SendMessage(phoneNumber, serviceType, sourceTon, sourceNpi, submitDataCoding, encodeDataCoding, message, out submitSm, out submitSmResp);
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEManager : SendMessage : ERROR : {0}", exception.ToString());
            }

            return retVal;
        }
Beispiel #7
0
        /// <summary> Called to send the message </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="serviceType"></param>
        /// <param name="destinationTon"></param>
        /// <param name="destinationNpi"></param>
        /// <param name="submitDataCoding"></param>
        /// <param name="encodeDataCoding"></param>
        /// <param name="message"></param>
        /// <param name="submitSm"></param>
        /// <param name="submitSmResp"></param>
        /// <returns> 0 - Successful / 1 - Failed / 2 - Not Connected </returns>
        public int SendMessage(string phoneNumber, string serviceType, Ton destinationTon, Npi destinationNpi, DataCodings submitDataCoding, DataCodings encodeDataCoding, string message, out SubmitSm submitSm, out SubmitSmResp submitSmResp)
        {
            int retVal = 1;

            submitSm     = null;
            submitSmResp = null;

            try
            {
                if (Client.Status != ConnectionStatus.Bound)
                {
                    WriteLog("ESMEConnection : SendMessage : Warning : Not Connected To The SMPP Server");

                    return(2);
                }

                // The message to send
                string sendMessage = null;

                // Do we need to cut the message down
                if (encodeDataCoding == DataCodings.UCS2)
                {
                    // UCS2 only supports 140 bytes
                    if (message.Length > 70)
                    {
                        WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : WARNING : Truncating UCS2 message to 70 characters.");

                        // The default is Unicode so truncate the message
                        sendMessage = message.Substring(0, 70);
                    }
                }
                else
                {
                    if (message.Length > 160)
                    {
                        WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : WARNING : Truncating Default message to 160 characters.");

                        sendMessage = message.Substring(0, 160);
                    }
                }

                // Prepare the message, I have made sure there is only ever one message
                // with the trunacting above
                submitSm = Client.PrepareSubmit(
                    SubmitMode.ShortMessage,
                    serviceType,
                    (byte)Ton.NetworkSpecific,
                    (byte)Npi.Unknown,
                    ShortLongCode,
                    (byte)destinationTon,
                    (byte)destinationNpi,
                    phoneNumber,
                    submitDataCoding,
                    encodeDataCoding,
                    (sendMessage == null) ? message : sendMessage);

                // Send the message
                submitSmResp = Client.Submit(submitSm);

                // Log the send call
                WriteLog("ESMEConnection : SendMessage : Send : Sequence[{0}] Phone[{1}] Status[{2}]", submitSmResp.Sequence, phoneNumber, submitSmResp.Status);

                // Was it successful
                if (submitSmResp.Status != CommandStatus.ESME_ROK)
                {
                    WriteLog("ESMEConnection : SendMessage : ERROR : Failed For Unknown Reason");

                    retVal = 1;
                }

                // Success
                retVal = 0;
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : SendMessage : ERROR : {0}", exception.ToString());

                retVal = 1;
            }

            return(retVal);
        }
Beispiel #8
0
        /// <summary> Called to fire the submit pdu event </summary>
        /// <param name="data"></param>
        /// <param name="messageId"></param>
        /// <returns> CommandStatus </returns>
        internal CommandStatus OnSubmitSm(SubmitSm data, out string messageId)
        {
            CommandStatus commandStatus = CommandStatus.ESME_RSUBMITFAIL;
            messageId = null;

            try
            {
                if (SubmitSmEvent != null)
                {
                    commandStatus = SubmitSmEvent(this, data, out messageId);
                }
            }

            catch
            {
            }

            return commandStatus;
        }
Beispiel #9
0
        /// <summary> Submit a short message to the SMSC </summary>
        /// <param name="data"></param>
        /// <returns> A SubmitSmResp object </returns>
        public SubmitSmResp Submit(SubmitSm data)
        {
            SubmitSmResp submitSmResp = null;
            EventData eventData = null;

            if (_Status != ConnectionStatus.Bound)
            {
                return SubmitSmResp.Create(DefaultEncoding, CommandStatus.SMPPCLIENT_UNBOUND, data.Sequence);
            }

            try
            {
                // Request an event data object for the submit
                eventData = RequestEventData();

                // Add the event data object to the submit done list
                lock (SubmitDone)
                {
                    SubmitDone.Add(data.Sequence, eventData);
                }

                // Send the submit
                SendPacket(data);

                // Wait the response
                bool success = eventData.SignalEvent.WaitOne(5000);

                if (success == true)
                {
                    // Return the response
                    submitSmResp = (SubmitSmResp) eventData.ResponseObject;
                }
                else
                {
                    submitSmResp = SubmitSmResp.Create(DefaultEncoding, CommandStatus.SMPPCLIENT_RCVTIMEOUT, data.Sequence);
                }
            }

            catch (Exception exception)
            {
                OnError("Submit error : ", exception);

                submitSmResp = SubmitSmResp.Create(DefaultEncoding, CommandStatus.SMPPCLIENT_UNKNOWNERROR, data.Sequence);
            }

            // Remove the submit done object
            lock (SubmitDone)
            {
                SubmitDone.Remove(data.Sequence);
            }

            // Release the event data
            ReleaseEventData(eventData);

            return submitSmResp;
        }
Beispiel #10
0
        /// <summary> Called to create a SubmitSm object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> SubmitSm </returns>
        public static SubmitSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            SubmitSm submitSm = new SubmitSm(defaultEncoding);

            try
            {
                int start_offset = offset;

                buf.ExtractHeader(submitSm, ref offset);

                submitSm.ServiceType          = buf.ExtractCString(ref offset);
                submitSm.SourceTon            = buf.ExtractByte(ref offset);
                submitSm.SourceNpi            = buf.ExtractByte(ref offset);
                submitSm.SourceAddr           = buf.ExtractCString(ref offset);
                submitSm.DestTon              = buf.ExtractByte(ref offset);
                submitSm.DestNpi              = buf.ExtractByte(ref offset);
                submitSm.DestAddr             = buf.ExtractCString(ref offset);
                submitSm.EsmClass             = buf.ExtractByte(ref offset);
                submitSm.ProtocolId           = buf.ExtractByte(ref offset);
                submitSm.PriorityFlag         = buf.ExtractByte(ref offset);
                submitSm.ScheduleDeliveryTime = buf.ExtractCString(ref offset);
                submitSm.ValidityPeriod       = buf.ExtractCString(ref offset);
                submitSm.RegisteredDelivery   = buf.ExtractByte(ref offset);
                submitSm.ReplaceIfPresent     = buf.ExtractByte(ref offset);
                submitSm.DataCoding           = (DataCodings)buf.ExtractByte(ref offset);
                submitSm.DefaultMsgId         = buf.ExtractByte(ref offset);
                submitSm.ShortMessageLength   = buf.ExtractByte(ref offset);

                if (submitSm.ShortMessageLength > 0)
                {
                    submitSm.UserDataBuffer = new SmppBuffer(defaultEncoding, buf.ExtractByteArray(ref offset, submitSm.ShortMessageLength));
                }

                while (offset - start_offset < submitSm.Length)
                {
                    submitSm.Optional.Add(buf.ExtractTLV(ref offset));
                }

                if (submitSm.ShortMessageLength == 0)
                {
                    if (submitSm.Optional != null && submitSm.Optional.Count > 0)
                    {
                        TLV tlv_payload = submitSm.Optional[OptionalTags.MessagePayload];
                        if (tlv_payload != null)
                        {
                            submitSm.UserDataBuffer = new SmppBuffer(defaultEncoding, tlv_payload.Value);
                        }

                        TLV tlv_globalSeq = submitSm.Optional[OptionalTags.SarMsgRefNum];
                        if (tlv_globalSeq != null)
                        {
                            submitSm.MessageReferenceNumber = SmppBuffer.BytesToShort(tlv_globalSeq.Value, 0);
                        }

                        TLV tlv_pocketsNumber = submitSm.Optional[OptionalTags.SarTotalSegments];
                        if (tlv_pocketsNumber != null)
                        {
                            submitSm.TotalSegments = tlv_pocketsNumber.Value[0];
                        }

                        TLV tlv_localSeq = submitSm.Optional[OptionalTags.SarSegmentSeqnum];
                        if (tlv_localSeq != null)
                        {
                            submitSm.SeqmentNumber = tlv_localSeq.Value[0];
                        }
                    }
                }

                if (submitSm.UserDataBuffer != null && submitSm.UserDataBuffer.Length > 0)
                {
                    bool hasUDHI = submitSm.MessageFeature == GSMSpecificFeatures.UDHI || submitSm.MessageFeature == GSMSpecificFeatures.UDHIandReplyPath;
                    submitSm.UserData = UserData.Create(submitSm.UserDataBuffer, hasUDHI);

                    if (submitSm.UserData.Headers.Count > 0)
                    {
                        UserDataHeader udh = submitSm.UserData.Headers[InformationElementIdentifiers.ConcatenatedShortMessages8bit];
                        if (udh != null)
                        {
                            submitSm.MessageReferenceNumber = udh.Data[0];
                            submitSm.TotalSegments          = udh.Data[1];
                            submitSm.SeqmentNumber          = udh.Data[2];
                        }

                        udh = submitSm.UserData.Headers[InformationElementIdentifiers.ConcatenatedShortMessage16bit];
                        if (udh != null)
                        {
                            submitSm.MessageReferenceNumber = SmppBuffer.BytesToShort(udh.Data, 0);
                            submitSm.TotalSegments          = udh.Data[2];
                            submitSm.SeqmentNumber          = udh.Data[3];
                        }
                    }
                }
                else
                {
                    submitSm.UserData = UserData.Create();
                }
            }

            catch
            {
                submitSm = null;
            }

            return(submitSm);
        }