Example #1
0
        /// <summary> Called to create a DataSmResp object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="dataSm"></param>
        /// <param name="commandStatus"></param>
        /// <param name="messageId"></param>
        /// <returns> DataSmResp </returns>
        public static DataSmResp Create(DataCodings defaultEncoding,
                                        DataSm dataSm,
                                        CommandStatus commandStatus,
                                        string messageId)
        {
            if (dataSm.SourceAddr == string.Empty || dataSm.SourceAddr == null)
            {
                commandStatus = CommandStatus.ESME_RINVSRCADR;
            }

            return(new DataSmResp(defaultEncoding,
                                  commandStatus,
                                  dataSm.Sequence,
                                  messageId));
        }
Example #2
0
        /// <summary> Called to create a DataSm object </summary>
        /// <param name="defaultEncoding"></param>
        /// <param name="buf"></param>
        /// <param name="offset"></param>
        /// <returns> DataSm </returns>
        public static DataSm Create(DataCodings defaultEncoding,
                                    SmppBuffer buf,
                                    ref int offset)
        {
            var dataSm = new DataSm(defaultEncoding);

            try
            {
                var start_offset = offset;

                buf.ExtractHeader(dataSm,
                                  ref offset);

                dataSm.ServiceType        = buf.ExtractCString(ref offset);
                dataSm.SourceTon          = buf.ExtractByte(ref offset);
                dataSm.SourceNpi          = buf.ExtractByte(ref offset);
                dataSm.SourceAddr         = buf.ExtractCString(ref offset);
                dataSm.DestTon            = buf.ExtractByte(ref offset);
                dataSm.DestNpi            = buf.ExtractByte(ref offset);
                dataSm.DestAddr           = buf.ExtractCString(ref offset);
                dataSm.EsmClass           = buf.ExtractByte(ref offset);
                dataSm.RegisteredDelivery = buf.ExtractByte(ref offset);
                dataSm.DataCoding         = (DataCodings)buf.ExtractByte(ref offset);

                if (offset - start_offset < dataSm.Length)
                {
                    if (dataSm.Optional == null)
                    {
                        dataSm.Optional = new TLVCollection();
                    }

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

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

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

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

                    var tlv_localSeq = dataSm.Optional[OptionalTags.SarSegmentSeqnum];
                    if (tlv_localSeq != null)
                    {
                        dataSm.SequenceNumber = tlv_localSeq.Value[0];
                    }
                }

                if (dataSm.UserDataBuffer != null && dataSm.UserDataBuffer.Length > 0)
                {
                    dataSm.UserData = UserData.Create(dataSm.UserDataBuffer,
                                                      dataSm.MessageFeature == GSMSpecificFeatures.UDHI);
                }
                else
                {
                    dataSm.UserData = UserData.Create();
                }
            }

            catch { dataSm = null; }

            return(dataSm);
        }