Welcome to mirror list, hosted at ThFree Co, Russian Federation.

_SmppPduBindBase.cs « SmppServerLib - github.com/ClusterM/smpp-sharp-lib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d64c798fd736085cc91101438928d4fef1dfc33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Flex.Cluster.Smpp
{
    public abstract class SmppPduBindBase : SmppPdu
    {
        abstract protected SmppCommandType GetCommandType();

        uint offsetSystemId, offsetPassword, offsetSystemType, offsetInterfaceVersion, offsetAddrTon, offsetAddrNpi, offsetAddrRange;

        public string SystemId
        {
            get { return ReadCString(offsetSystemId); }
        }
        public string Password
        {
            get { return ReadCString(offsetPassword); }
        }
        public string SystemType
        {
            get { return ReadCString(offsetSystemType); }
        }
        public byte InterfaceVersion
        {
            get { return ReadByte(offsetInterfaceVersion);}
        }
        public byte AddrTon
        {
            get { return ReadByte(offsetAddrTon); }
        }
        public byte AddrNpi
        {
            get { return ReadByte(offsetAddrNpi); }
        }
        public string AddrRange
        {
            get { return ReadCString(offsetAddrRange); }
        }

        public SmppPduBindBase(SmppCommandType commandType, string systemId, string password, string systemType, byte interfaceVersion, byte addrTon, byte addrNpi, string addrRange)
            : base(commandType)
        {
            if (commandType != GetCommandType()) throw new Exception("Invaid command ID");

            if (systemId.Length > 15) throw new ArgumentOutOfRangeException("systemId");
            offsetSystemId = CurrentOffset;
            WriteCString(systemId);

            if (password.Length > 8) throw new ArgumentOutOfRangeException("password");
            offsetPassword = CurrentOffset;
            WriteCString(password);

            if (systemType.Length > 12) throw new ArgumentOutOfRangeException("systemType");
            offsetSystemType = CurrentOffset;
            WriteCString(systemType);

            offsetInterfaceVersion = CurrentOffset;
            WriteByte(interfaceVersion);

            offsetAddrTon = CurrentOffset;
            WriteByte(addrTon);

            offsetAddrNpi = CurrentOffset;
            WriteByte(addrNpi);

            if (addrRange.Length > 40) throw new ArgumentOutOfRangeException("addressRange");
            offsetAddrRange = CurrentOffset;
            WriteCString(addrRange);
        }

        public SmppPduBindBase(byte[] bytes) : this(bytes, (uint)bytes.Length)
        {
        }
        public SmppPduBindBase(byte[] bytes, uint length)
            : base(bytes, length)
        {
            if (CommandId != GetCommandType()) throw new Exception("Invaid command ID");
            offsetSystemId = 12;
            offsetPassword = FindCStringEnd(offsetSystemId);
            offsetSystemType = FindCStringEnd(offsetPassword);
            offsetInterfaceVersion = FindCStringEnd(offsetSystemType);
            offsetAddrTon = offsetInterfaceVersion + 1;
            offsetAddrNpi = offsetAddrTon + 1;
            offsetAddrRange = offsetAddrNpi + 1;
        }
    }
}