示例#1
0
        /// <summary> Called to create a DeliverSmResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="deliverSm"></param>
        /// <param name="commandStatus"></param>
        /// <returns> DeliverSmResp </returns>
        public static DeliverSmResp Create(DataCodings defaultEncoding, DeliverSm deliverSm, CommandStatus commandStatus)
        {
            if (deliverSm.SourceAddr == string.Empty || deliverSm.SourceAddr == null)
            {
                commandStatus = CommandStatus.ESME_RINVSRCADR;
            }

            return new DeliverSmResp(defaultEncoding, commandStatus, deliverSm.Sequence);
        }
示例#2
0
        /// <summary> Parses the smpp buffer to a DeliverSm object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> DeliverSm </returns>
        public static DeliverSm Create(DataCodings defaultEncoding, SmppBuffer buf, ref int offset)
        {
            DeliverSm deliverSm = new DeliverSm(defaultEncoding);

            try
            {
                int start_offset = offset;

                buf.ExtractHeader(deliverSm, ref offset);

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

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

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

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

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

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

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

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

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

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

            catch
            {
                deliverSm = null;
            }

            return deliverSm;
        }
示例#3
0
        /// <summary> Called to retrieve the full message </summary>
        /// <param name="data"></param>
        /// <returns> The message </returns>
        private string RetrieveFullMessage(DeliverSm data)
        {
            string message = null;

            try
            {
                SmppClient.UserDataControl userDataControl = null;
                string key = data.SourceAddr + data.MessageReferenceNumber;

                lock (Collector)
                {
                    if (Collector.ContainsKey(key))
                    {
                        userDataControl = Collector[key];

                        Collector.Remove(key);
                    }
                }

                if (userDataControl != null)
                {
                    message = userDataControl.UserData.ShortMessageText(data.DefaultEncoding, data.DataCoding);
                }
                else
                {
                    WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : RetrieveFullMessage : ERROR : No User Data Found");
                }
            }

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

            return message;
        }
示例#4
0
        /// <summary> Called to verify we received the last segment of data </summary>
        /// <param name="data"></param>
        /// <returns> True or False </returns>
        private bool IsLastSegment(DeliverSm data)
        {
            bool finished = false;

            try
            {
                SmppClient.UserDataControl userDataControl = null;
                string key = data.SourceAddr + data.MessageReferenceNumber;

                lock (Collector)
                {
                    if (Collector.ContainsKey(key))
                    {
                        userDataControl = Collector[key];
                    }
                }

                if (userDataControl != null)
                {
                    if (userDataControl.SegmentsLeftToReceived <= 0)
                    {
                        finished = true;
                    }
                }
                else
                {
                    WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : IsLastSegment : ERROR : No User Data Found");
                }
            }

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

            return finished;
        }
示例#5
0
        /// <summary> Called when a message is received from the SMPP server </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        private CommandStatus ClientEventDeliverSm(object sender, DeliverSm data)
        {
            WriteLog("ESMEConnection : ClientEventDeliverSm : Started : SegmentNumber[{0}]", data.SeqmentNumber);

            CommandStatus commandStatus = CommandStatus.ESME_ROK;

            try
            {
                string message = null;

                if (data.SeqmentNumber > 0)
                {
                    // There are more than 1 seqments to the outbound message

                    AddMessageSegmentToCollector(data);

                    string logMessage = string.Format("ServiceType[{0}] DestAddr[{1}] SourceAddr[{2}] MessageReferenceNumber[{3}] Sequence[{4}] SeqmentNumber[{5}] TotalSegments[{6}] DataCoding[{7}] MessageText[{8}]",
                        data.ServiceType,
                        data.DestAddr,
                        data.SourceAddr,
                        data.MessageReferenceNumber,
                        data.Sequence,
                        data.SeqmentNumber,
                        data.TotalSegments,
                        data.DataCoding,
                        data.UserData.ShortMessageText(data.DefaultEncoding, data.DataCoding));

                    WriteLog("ESMEConnection : ClientEventDeliverSm : Info : Partial Message : {0}", logMessage);

                    if (IsLastSegment(data))
                    {
                        message = RetrieveFullMessage(data);
                    }
                }
                else
                {
                    // There is only 1 seqment to the outbound message
                    message = data.UserData.ShortMessageText(data.DefaultEncoding, data.DataCoding);
                }

                if ((message != null) && (ReceivedMessageHandler != null))
                {
                    // Message has been received
                    ReceivedMessageHandler(LogKey, data.ServiceType, (Ton) data.SourceTon, (Npi) data.SourceNpi, ShortLongCode, DateTime.Now, data.SourceAddr, data.DataCoding, message);
                }
            }

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

            return commandStatus;
        }
示例#6
0
        /// <summary> Called to add the message segment to the collector dictionary </summary>
        /// <param name="data"></param>
        private void AddMessageSegmentToCollector(DeliverSm data)
        {
            try
            {
                SmppClient.UserDataControl userDataControl = null;
                string key = data.SourceAddr + data.MessageReferenceNumber;

                lock (Collector)
                {
                    if (Collector.ContainsKey(key))
                    {
                        userDataControl = Collector[key];
                    }
                    else
                    {
                        userDataControl = new SmppClient.UserDataControl(data.TotalSegments);
                        Collector.Add(key, userDataControl);
                    }
                }

                // Add the segment to the current
                userDataControl.UserData.Add(data.UserData);
                --userDataControl.SegmentsLeftToReceived;
            }

            catch (Exception exception)
            {
                WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : AddMessageSegmentToCollector : ERROR : {0}", exception.ToString());
            }
        }
示例#7
0
        /// <summary> Called to fire the deliver pdu event </summary>
        /// <param name="data"></param>
        /// <returns> CommandStatus </returns>
        internal CommandStatus OnDeliverSm(DeliverSm data)
        {
            CommandStatus commandStatus = CommandStatus.ESME_ROK;

            try
            {
                if (DeliverSmEvent != null)
                {

                    commandStatus = DeliverSmEvent(this, data);
                }
            }

            catch
            {
            }

            return commandStatus;
        }