-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMPPTLV.cs
231 lines (216 loc) · 14.5 KB
/
SMPPTLV.cs
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using System;
using System.Collections.Generic;
using Jannesen.Protocol.SMPP.Internal;
namespace Jannesen.Protocol.SMPP
{
public class SMPPTLV
{
public OptionalTags Tag { get; }
public byte[] Value { get; set; }
public byte ValueByte
{
get {
if (Value.Length != 1)
throw new InvalidOperationException("Invalid byte value");
return Value[0];
}
set {
Value = new byte[1];
Value[0] = value;
}
}
public UInt16 ValueUInt16
{
get {
if (Value.Length != 2)
throw new InvalidOperationException("Invalid short value");
return (UInt16)((Value[0] << 8) | (Value[0]));
}
set {
Value = new byte[2];
Value[0] = (byte)(value >> 8);
Value[1] = (byte)(value );
}
}
public UInt32 ValueUInt32
{
get {
if (Value.Length != 4)
throw new InvalidOperationException("Invalid int value");
return (UInt32)((Value[0] << 24) | (Value[0] << 16) | (Value[0] << 8) | (Value[0]));
}
set {
Value = new byte[4];
Value[0] = (byte)(value >> 24);
Value[1] = (byte)(value >> 16);
Value[2] = (byte)(value >> 8);
Value[3] = (byte)(value );
}
}
public string ValueString
{
get {
var size = Value.Length;
if (size > 0 && Value[size - 1] == 0)
--size;
return System.Text.ASCIIEncoding.ASCII.GetString(Value, 0, size);
}
set {
Value = System.Text.ASCIIEncoding.ASCII.GetBytes(value + "\0");
}
}
internal SMPPTLV(OptionalTags tag)
{
Tag = tag;
}
internal SMPPTLV(PduReader reader)
{
Tag = (OptionalTags)(reader.ReadInteger16());
Value = reader.ReadBytes(reader.ReadInteger16());
}
}
public class SMPPTLVCollection: List<SMPPTLV>
{
public SMPPTLV this[OptionalTags tag]
{
get {
var tlv = Find(tag);
if (tlv == null)
base.Add(tlv = new SMPPTLV(tag));
return tlv;
}
}
public byte? DestAddrSubunit { get { return _getByte (OptionalTags.DestAddrSubunit); } set { _setByte (OptionalTags.DestAddrSubunit, value); } }
public byte? DestNetworkType { get { return _getByte (OptionalTags.DestNetworkType); } set { _setByte (OptionalTags.DestNetworkType, value); } }
public byte? DestBearerType { get { return _getByte (OptionalTags.DestBearerType); } set { _setByte (OptionalTags.DestBearerType, value); } }
public UInt16? DestTelematicsId { get { return _getUInt16(OptionalTags.DestTelematicsId); } set { _setUInt16(OptionalTags.DestTelematicsId, value); } }
public byte? SourceAddrSubunit { get { return _getByte (OptionalTags.SourceAddrSubunit); } set { _setByte (OptionalTags.SourceAddrSubunit, value); } }
public byte? SourceNetworkType { get { return _getByte (OptionalTags.SourceNetworkType); } set { _setByte (OptionalTags.SourceNetworkType, value); } }
public byte? SourceBearerType { get { return _getByte (OptionalTags.SourceBearerType); } set { _setByte (OptionalTags.SourceBearerType, value); } }
public byte? SourceTelematicsId { get { return _getByte (OptionalTags.SourceTelematicsId); } set { _setByte (OptionalTags.SourceTelematicsId, value); } }
public UInt32? QosTimeToLive { get { return _getUInt32(OptionalTags.QosTimeToLive); } set { _setUInt32(OptionalTags.QosTimeToLive, value); } }
public byte? PayloadType { get { return _getByte (OptionalTags.PayloadType); } set { _setByte(OptionalTags.PayloadType, value); } }
public string AdditionalStatusInfoText { get { return _getString(OptionalTags.AdditionalStatusInfoText); } set { _setString(OptionalTags.AdditionalStatusInfoText, value); } }
public string ReceiptedMessageId { get { return _getString(OptionalTags.ReceiptedMessageId); } set { _setString(OptionalTags.ReceiptedMessageId, value); } }
public byte? MsMsgWaitFacilities { get { return _getByte (OptionalTags.MsMsgWaitFacilities); } set { _setByte (OptionalTags.MsMsgWaitFacilities, value); } }
public byte? PrivacyIndicator { get { return _getByte (OptionalTags.PrivacyIndicator); } set { _setByte (OptionalTags.PrivacyIndicator, value); } }
public byte? SourceSubaddress { get { return _getByte (OptionalTags.SourceSubaddress); } set { _setByte (OptionalTags.SourceSubaddress, value); } }
public string DestSubaddress { get { return _getString(OptionalTags.DestSubaddress); } set { _setString(OptionalTags.DestSubaddress, value); } }
public UInt16? UserMessageReference { get { return _getUInt16(OptionalTags.UserMessageReference); } set { _setUInt16(OptionalTags.UserMessageReference, value); } }
public byte? UserResponseCode { get { return _getByte (OptionalTags.UserResponseCode); } set { _setByte (OptionalTags.UserResponseCode, value); } }
public UInt16? SourcePort { get { return _getUInt16(OptionalTags.SourcePort); } set { _setUInt16(OptionalTags.SourcePort, value); } }
public UInt16? DestinationPort { get { return _getUInt16(OptionalTags.DestinationPort); } set { _setUInt16(OptionalTags.DestinationPort, value); } }
public UInt16? SarMsgRefNum { get { return _getUInt16(OptionalTags.SarMsgRefNum); } set { _setUInt16(OptionalTags.SarMsgRefNum, value); } }
public byte? LanguageIndicator { get { return _getByte (OptionalTags.LanguageIndicator); } set { _setByte (OptionalTags.LanguageIndicator, value); } }
public byte? SarTotalSegments { get { return _getByte (OptionalTags.SarTotalSegments); } set { _setByte (OptionalTags.SarTotalSegments, value); } }
public byte? SarSegmentSeqnum { get { return _getByte (OptionalTags.SarSegmentSeqnum); } set { _setByte (OptionalTags.SarSegmentSeqnum, value); } }
public byte? SCInterfaceVersion { get { return _getByte (OptionalTags.SCInterfaceVersion); } set { _setByte (OptionalTags.SCInterfaceVersion, value); } }
public byte? CallbackNumPresInd { get { return _getByte (OptionalTags.CallbackNumPresInd); } set { _setByte (OptionalTags.CallbackNumPresInd, value); } }
public string CallbackNumAtag { get { return _getString(OptionalTags.CallbackNumAtag); } set { _setString(OptionalTags.CallbackNumAtag, value); } }
public byte? NumberOfMessages { get { return _getByte (OptionalTags.NumberOfMessages); } set { _setByte (OptionalTags.NumberOfMessages, value); } }
public string CallbackNum { get { return _getString(OptionalTags.CallbackNum); } set { _setString(OptionalTags.CallbackNum, value); } }
public byte? DpfResult { get { return _getByte (OptionalTags.DpfResult); } set { _setByte (OptionalTags.DpfResult, value); } }
public byte? SetDpf { get { return _getByte (OptionalTags.SetDpf); } set { _setByte (OptionalTags.SetDpf, value); } }
public byte? MsAvailabilityStatus { get { return _getByte (OptionalTags.MsAvailabilityStatus); } set { _setByte (OptionalTags.MsAvailabilityStatus, value); } }
public byte[] NetworkErrorCode { get { return _getBytes (OptionalTags.NetworkErrorCode); } set { _setBytes (OptionalTags.NetworkErrorCode, value); } }
public string MessagePayload { get { return _getString(OptionalTags.MessagePayload); } set { _setString(OptionalTags.MessagePayload, value); } }
public byte? DeliveryFailureReason { get { return _getByte (OptionalTags.DeliveryFailureReason); } set { _setByte (OptionalTags.DeliveryFailureReason, value); } }
public byte? MoreMessagesToSend { get { return _getByte (OptionalTags.MoreMessagesToSend); } set { _setByte (OptionalTags.MoreMessagesToSend, value); } }
public byte? MessageState { get { return _getByte (OptionalTags.MessageState); } set { _setByte (OptionalTags.MessageState, value); } }
public byte? UssdServiceOp { get { return _getByte (OptionalTags.UssdServiceOp); } set { _setByte (OptionalTags.UssdServiceOp, value); } }
public byte? DisplayTime { get { return _getByte (OptionalTags.DisplayTime); } set { _setByte (OptionalTags.DisplayTime, value); } }
public UInt16? SmsSignal { get { return _getUInt16(OptionalTags.SmsSignal); } set { _setUInt16(OptionalTags.SmsSignal, value); } }
public byte? MsValidity { get { return _getByte (OptionalTags.MsValidity); } set { _setByte (OptionalTags.MsValidity, value); } }
public bool AlertOnMessageDelivery { get { return _getBool (OptionalTags.AlertOnMessageDelivery); } set { _setBool (OptionalTags.AlertOnMessageDelivery, value); } }
public byte? ItsReplyType { get { return _getByte (OptionalTags.ItsReplyType); } set { _setByte (OptionalTags.ItsReplyType, value); } }
public UInt16? ItsSessionInfo { get { return _getUInt16(OptionalTags.ItsSessionInfo); } set { _setUInt16(OptionalTags.ItsSessionInfo, value); } }
public SMPPTLVCollection()
{
}
private SMPPTLV Find(OptionalTags tag)
{
for(var i = 0 ; i < base.Count ; ++i) {
if (base[i].Tag == tag)
return base[i];
}
return null;
}
private void Remove(OptionalTags tag)
{
for(var i = 0 ; i < base.Count ; ++i) {
if (base[i].Tag == tag)
base.RemoveAt(i);
}
}
private bool _getBool(OptionalTags tag)
{
var tlv = Find(tag);
return (tlv != null);
}
private byte? _getByte(OptionalTags tag)
{
var tlv = Find(tag);
return (tlv != null) ? (byte?)tlv.ValueByte : (byte?)null;
}
private UInt16? _getUInt16(OptionalTags tag)
{
var tlv = Find(tag);
return (tlv != null) ? (UInt16?)tlv.ValueUInt16 : (UInt16?)null;
}
private UInt32? _getUInt32(OptionalTags tag)
{
var tlv = Find(tag);
return (tlv != null) ? (UInt32?)tlv.ValueUInt32 : (UInt32?)null;
}
private string _getString(OptionalTags tag)
{
return Find(tag).ValueString;
}
private byte[] _getBytes(OptionalTags tag)
{
return Find(tag).Value;
}
private void _setBool(OptionalTags tag, bool value)
{
if (value)
this[tag].Value = null;
else
Remove(tag);
}
private void _setByte(OptionalTags tag, byte? value)
{
if (value.HasValue)
this[tag].ValueByte = value.Value;
else
Remove(tag);
}
private void _setUInt16(OptionalTags tag, UInt16? value)
{
if (value.HasValue)
this[tag].ValueUInt16 = value.Value;
else
Remove(tag);
}
private void _setUInt32(OptionalTags tag, UInt32? value)
{
if (value.HasValue)
this[tag].ValueUInt32 = value.Value;
else
Remove(tag);
}
private void _setString(OptionalTags tag, string value)
{
if (value != null)
this[tag].ValueString = value;
else
Remove(tag);
}
private void _setBytes(OptionalTags tag, byte[] value)
{
if (value != null)
this[tag].Value = value;
else
Remove(tag);
}
}
}